diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..c50384f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "trailingComma": "none", + "tabWidth": 2, + "semi": false, + "singleQuote": true +} diff --git a/LICENSE b/LICENSE index a1b18a6..e72bfdd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,674 @@ -Copyright 2024 Taha Shashtari + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 -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: + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + Preamble -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. + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/README.md b/README.md index c11f4f8..56d1470 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,21 @@ # Swapy -> A simple JavaScript tool for converting any layout you have to drag-to-swap layout +_A framework-agnostic tool that converts any layout into a drag-to-swap one with just a few lines of code._ + +Check out [swapy.tahazsh.com](https://swapy.tahazsh.com/) for complete docs and demos. ## Docs -https://swapy.tahazsh.com/ +Check out the full documentation with many demos at [swapy.tahazsh.com/docs/installation](https://swapy.tahazsh.com/docs/installation). + +## License + +### Commercial license + +If you plan to use Swapy for developing commercial sites, themes, projects, or applications, the Commercial license is the right choice. This license allows you to keep your source code proprietary. You can purchase the Swapy Commercial License at [swapy.tahazsh.com](https://swapy.tahazsh.com/license). + +### Open-source license + +If you're developing an open-source application with a license compatible with the [GNU GPL license v3](https://www.gnu.org/licenses/gpl-3.0.html), you can use Swapy under the terms of the GPLv3. + +[Read more about Swapy's license](https://swapy.tahazsh.com/license). diff --git a/dist/swapy.d.ts b/dist/swapy.d.ts deleted file mode 100644 index 82ea0af..0000000 --- a/dist/swapy.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -declare type AnimationType = 'dynamic' | 'spring' | 'none'; - -declare type Config = { - animation: AnimationType; - continuousMode: boolean; - manualSwap: boolean; - swapMode: SwapMode; - autoScrollOnDrag: boolean; -}; - -export declare function createSwapy(root: Element | null, userConfig?: Partial): Swapy; - -declare type RequireOnlyOne = Keys extends keyof T ? { - [K in Keys]: T[K]; -} & Partial, never>> : never; - -export declare type SlotItemMap = SwapEventArray; - -declare type SwapCallback = (event: SwapEventData) => void; - -declare type SwapData = RequireOnlyOne; - -declare type SwapEndCallback = (event: SwapEndEventData) => void; - -declare type SwapEndEventData = SwapEventData & { - hasChanged: boolean; -}; - -export declare type SwapEventArray = Array<{ - slotId: string; - itemId: string | null; -}>; - -declare interface SwapEventData { - data: SwapEventDataData; -} - -declare interface SwapEventDataData { - map: SwapEventMap; - array: SwapEventArray; - object: SwapEventObject; -} - -export declare type SwapEventMap = Map; - -export declare type SwapEventObject = Record; - -declare type SwapMode = 'hover' | 'stop' | 'drop'; - -declare type SwapStartCallback = () => void; - -export declare interface Swapy { - onSwap(callback: SwapCallback): void; - onSwapEnd(callback: SwapEndCallback): void; - onSwapStart(callback: SwapStartCallback): void; - enable(enabled: boolean): void; - destroy(): void; - setData(swapData: SwapData): void; -} - -export { } diff --git a/dist/swapy.js b/dist/swapy.js deleted file mode 100644 index c7d79ca..0000000 --- a/dist/swapy.js +++ /dev/null @@ -1,3221 +0,0 @@ -var Gt = Object.defineProperty; -var Zt = (r, t, e) => t in r ? Gt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e; -var P = (r, t, e) => Zt(r, typeof t != "symbol" ? t + "" : t, e); -function gt(r, t) { - if (r.size !== t.size) - return !1; - for (let [e, i] of r) - if (!t.has(e) || t.get(e) !== i) - return !1; - return !0; -} -let Jt = 0; -function Qt() { - return Jt++ + ""; -} -var te = Object.defineProperty, ee = (r, t, e) => t in r ? te(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, o = (r, t, e) => ee(r, typeof t != "symbol" ? t + "" : t, e); -class ot { - constructor(t) { - o(this, "x"), o(this, "y"), o(this, "target"), this.x = t.x, this.y = t.y, this.target = t.target; - } -} -class ft extends ot { -} -class lt extends ot { -} -class ht extends ot { -} -class ut extends ot { -} -class $t { - constructor(t) { - o(this, "pluginId"), o(this, "pluginName"), o(this, "viewName"), o(this, "dataName"), o(this, "dataValue"), this.event = t, this.pluginId = t.pluginId, this.pluginName = t.pluginName, this.viewName = t.viewName, this.dataName = t.dataName, this.dataValue = t.dataValue; - } -} -function ie(r) { - return r.replace(/(?:^\w|[A-Z]|\b\w)/g, function(t, e) { - return e === 0 ? t.toLowerCase() : t.toUpperCase(); - }).replace(/\s+/g, "").replace(/-+/g, ""); -} -function Lt(r) { - return r.split("").map((t, e) => t.toUpperCase() === t ? `${e !== 0 ? "-" : ""}${t.toLowerCase()}` : t).join(""); -} -class st { - constructor(t) { - o(this, "node"), this.node = t.node; - } -} -class pt { - constructor(t) { - o(this, "node"), this.node = t.node; - } -} -class se { - constructor(t) { - o(this, "_eventBus"), o(this, "_observer"), this._eventBus = t, this._observer = new MutationObserver(this._handler.bind(this)), this._observer.observe(document.body, { - childList: !0, - subtree: !0, - attributes: !0, - attributeOldValue: !0 - }); - } - _handler(t) { - t.forEach((e) => { - e.addedNodes.forEach((s) => { - if (!(s instanceof HTMLElement) || s.dataset.velViewId || s.parentElement && typeof s.parentElement.dataset.velAdded < "u") - return; - let n = s; - if (s.dataset.velView || (n = s.querySelector("[data-vel-view][data-vel-plugin]")), !n) return; - this._eventBus.emitEvent(st, { node: n }); - const a = n.querySelectorAll("[data-vel-plugin]"); - a.length && a.forEach((l) => { - this._eventBus.emitEvent(st, { node: l }); - }); - }), e.removedNodes.forEach((s) => { - if (!(s instanceof HTMLElement) || typeof s.dataset.velProcessing < "u") return; - const n = s.querySelectorAll("[data-vel-plugin]"); - n.length && n.forEach((a) => { - this._eventBus.emitEvent(pt, { node: a }); - }), this._eventBus.emitEvent(pt, { node: s }); - }); - const i = e.attributeName; - if (i === "data-vel-view" && this._eventBus.emitEvent(st, { - node: e.target - }), i && /data-vel-data-.+/gi.test(i)) { - const s = e.target, n = s.dataset.velPluginId || "", a = s.dataset.velPlugin || "", l = s.dataset.velView || "", h = s.getAttribute(i); - if (h && h !== e.oldValue) { - const g = ie( - i.replace("data-vel-data-", "") - ); - this._eventBus.emitEvent($t, { - pluginId: n, - pluginName: a, - viewName: l, - dataName: g, - dataValue: h - }); - } - } - }); - } -} -class ne { - execute(t) { - this.call(t); - } -} -class It extends ne { - constructor(t) { - super(), o(this, "_handler"), this._handler = t; - } - getHandler() { - return this._handler; - } - call(t) { - this._handler(t); - } -} -class _t { - constructor() { - o(this, "_listeners", /* @__PURE__ */ new Map()), o(this, "_keyedListeners", /* @__PURE__ */ new Map()); - } - subscribeToEvent(t, e, i) { - if (i) { - this._subscribeToKeyedEvent(t, e, i); - return; - } - let s = this._listeners.get(t); - s || (s = [], this._listeners.set(t, s)), s.push(new It(e)); - } - removeEventListener(t, e, i) { - if (i) { - this._removeKeyedEventListener(t, e, i); - return; - } - let s = this._listeners.get(t); - s && (s = s.filter( - (n) => n.getHandler() !== e - ), this._listeners.set(t, s)); - } - _subscribeToKeyedEvent(t, e, i) { - let s = this._keyedListeners.get(t); - s || (s = /* @__PURE__ */ new Map(), this._keyedListeners.set(t, s)); - let n = s.get(i); - n || (n = [], s.set(i, n)), n.push(new It(e)); - } - _removeKeyedEventListener(t, e, i) { - let s = this._keyedListeners.get(t); - if (!s) - return; - let n = s.get(i); - n && (n = n.filter( - (a) => a.getHandler() !== e - ), s.set(i, n)); - } - emitEvent(t, e, i) { - if (i) { - this._emitKeyedEvent(t, e, i); - return; - } - const s = this._listeners.get(t); - s && s.forEach((n) => { - n.execute(e); - }); - } - _emitKeyedEvent(t, e, i) { - const s = this._keyedListeners.get(t); - if (!s) return; - const n = s.get(i); - n && n.forEach((a) => { - a.execute(e); - }); - } - _convertListener(t) { - return (e) => t(e); - } - subscribeToPluginReadyEvent(t, e, i = !1) { - if (i) { - this.subscribeToEvent( - Dt, - this._convertListener(t), - e - ); - return; - } - this.subscribeToEvent( - zt, - this._convertListener(t), - e - ); - } - emitPluginReadyEvent(t, e, i = !1) { - if (i) { - this.emitEvent( - Dt, - e, - t - ); - return; - } - this.emitEvent( - zt, - e, - t - ); - } - reset() { - this._listeners.clear(); - } -} -let re = 0; -function Wt() { - return re++ + ""; -} -class qt { - constructor(t, e, i, s, n, a, l) { - o(this, "_registry"), o(this, "_eventBus"), o(this, "_appEventBus"), o(this, "_internalEventBus"), o(this, "_initialized", !1), o(this, "_config"), o(this, "_pluginFactory"), o(this, "_pluginName"), o(this, "_id"), o(this, "_pluginKey"), o(this, "_layoutIdViewMapWaitingToEnter"), o(this, "_apiData"), o(this, "_isReady", !1), this._id = Wt(), this._pluginFactory = t, this._pluginName = e, this._registry = i, this._eventBus = s, this._appEventBus = n, this._internalEventBus = new _t(), this._config = a, this._layoutIdViewMapWaitingToEnter = /* @__PURE__ */ new Map(), this._pluginKey = l, this._apiData = {}, this._appEventBus.subscribeToPluginReadyEvent( - () => { - this._isReady = !0; - }, - this._pluginName, - !0 - ); - } - get api() { - return this._apiData; - } - _setApi(t) { - this._apiData = t; - } - get pluginName() { - return this._pluginName; - } - get pluginFactory() { - return this._pluginFactory; - } - get pluginKey() { - return this._pluginKey; - } - get id() { - return this._id; - } - get config() { - return { ...this._config }; - } - getViews(t) { - return t ? this._registry.getViewsByNameForPlugin(this, t) : this._registry.getViewsForPlugin(this); - } - getView(t) { - return t ? this._registry.getViewsByNameForPlugin(this, t)[0] : this._registry.getViewsForPlugin(this)[0]; - } - getViewById(t) { - return this._registry.getViewById(t); - } - addView(t) { - this._registry.assignViewToPlugin(t, this); - } - setInternalEventBus(t) { - this._internalEventBus = t; - } - get internalBusEvent() { - return this._internalEventBus; - } - emit(t, e) { - this._internalEventBus.emitEvent(t, e, this.pluginKey); - } - on(t, e) { - this._internalEventBus.subscribeToEvent(t, e, this.pluginKey); - } - removeListener(t, e) { - this._internalEventBus.removeEventListener(t, e); - } - useEventPlugin(t, e = {}) { - const i = this._registry.createPlugin( - t, - this._eventBus, - e - ); - return this._registry.associateEventPluginWithPlugin(this.id, i.id), i; - } - notifyAboutDataChanged(t) { - this.onDataChanged(t); - } - // @ts-ignore - onDataChanged(t) { - } - removeView(t) { - t.onRemoveCallback ? this._invokeRemoveCallback(t) : this._deleteView(t), t.removeListeners(), this.onViewRemoved(t); - } - _invokeRemoveCallback(t) { - const e = this._createTemporaryView(t); - requestAnimationFrame(() => { - var i; - (i = e.onRemoveCallback) == null || i.call(e, e, () => { - var s, n; - if ((s = t.onAddCallbacks) != null && s.afterRemoved && t.layoutId) { - const a = this._layoutIdViewMapWaitingToEnter.get( - t.layoutId - ); - (n = a == null ? void 0 : a.onAddCallbacks) == null || n.afterEnter(a), this._layoutIdViewMapWaitingToEnter.delete(t.layoutId); - } - this._deleteView(e, !0), t.removeListeners(); - }), setTimeout(() => { - e.element.parentElement && (this._deleteView(e, !0), t.removeListeners()); - }, 1e4); - }); - } - _deleteView(t, e = !1) { - (e || !t.layoutId) && (this._registry.removeViewById(t.id, this.id), t.element.remove(), t.destroy()); - } - // This is a temporary view for deleted view. We need to create it - // to show it again so the user can animate it before it disappears. - _createTemporaryView(t) { - const e = t.previousRect.viewportOffset, i = t.previousRect.size, s = t.rotation.degrees < 0 ? 0 : Math.sin(t.rotation.radians) * i.height * t.scale.y, n = t.rotation.degrees > 0 ? 0 : Math.sin(t.rotation.radians) * i.width * t.scale.y, a = t.element.cloneNode(!0); - t.element.remove(), a.style.cssText = "", a.style.position = "absolute", a.style.left = `${e.left + s}px`, a.style.top = `${e.top - n}px`, a.style.width = `${i.width}px`, a.style.height = `${i.height}px`, a.style.transform = ` - scale3d(${t.scale.x}, ${t.scale.y}, 1) rotate(${t.rotation.degrees}deg) - `, a.style.pointerEvents = "none", a.dataset.velRemoved = "", document.body.appendChild(a); - const l = this._registry.createView(a, t.name); - return l.setAsTemporaryView(), l.styles.position = "absolute", l.styles.left = `${e.left + s}px`, l.styles.top = `${e.top - n}px`, l.rotation.setDegrees(t.rotation.degrees, !1), l.scale.set({ x: t.scale.x, y: t.scale.y }, !1), l.size.set( - { width: t._localWidth, height: t._localHeight }, - !1 - ), t._copyAnimatorsToAnotherView(l), t.onRemoveCallback && l.onRemove(t.onRemoveCallback), l; - } - // @ts-ignore - onViewRemoved(t) { - } - notifyAboutViewAdded(t) { - this.onViewAdded(t), this._invokeAddCallbacks(t); - } - _invokeAddCallbacks(t) { - var e, i, s; - !((e = t.onAddCallbacks) != null && e.onInitialLoad) && !this._initialized || ((i = t.onAddCallbacks) == null || i.beforeEnter(t), !((s = t.onAddCallbacks) != null && s.afterRemoved) || !this._initialized ? requestAnimationFrame(() => { - var n; - (n = t.onAddCallbacks) == null || n.afterEnter(t); - }) : t.layoutId && this._layoutIdViewMapWaitingToEnter.set(t.layoutId, t)); - } - // @ts-ignore - onViewAdded(t) { - } - init() { - !this._initialized && this._isReady && (this.setup(), this._initialized = !0); - } - setup() { - } - // @ts-ignore - subscribeToEvents(t) { - } -} -class ae extends qt { - isRenderable() { - return !0; - } - isInitialized() { - return this._initialized; - } - get initialized() { - return this._initialized; - } - // @ts-ignore - update(t, e) { - } - render() { - } - addView(t) { - t.setPluginId(this.id), super.addView(t); - } -} -class wt extends qt { - isRenderable() { - return !1; - } -} -class oe { - constructor(t) { - o(this, "_plugin"), this._plugin = t; - } - get initialized() { - return this._plugin.isInitialized(); - } - get config() { - return this._plugin.config; - } - setup(t) { - this._plugin.setup = t; - } - api(t) { - this._plugin._setApi(t); - } - update(t) { - this._plugin.update = t; - } - render(t) { - this._plugin.render = t; - } - getViews(t) { - return this._plugin.getViews(t); - } - getView(t) { - return this._plugin.getView(t); - } - getViewById(t) { - return this._plugin.getViewById(t); - } - useEventPlugin(t, e = {}) { - return this._plugin.useEventPlugin(t, e); - } - emit(t, e) { - this._plugin.emit(t, e); - } - on(t, e) { - this._plugin.on(t, e); - } - onDataChanged(t) { - this._plugin.onDataChanged = t; - } - onViewRemoved(t) { - this._plugin.onViewRemoved = t; - } - onViewAdded(t) { - this._plugin.onViewAdded = t; - } - subscribeToEvents(t) { - this._plugin.subscribeToEvents = t; - } -} -function dt(r, t, e, i, s, n) { - if (le(r)) - return new r( - r, - r.pluginName, - t, - e, - i, - s, - n - ); - const a = new ae( - r, - r.pluginName, - t, - e, - i, - s, - n - ), l = new oe(a); - return r(l), a; -} -function le(r) { - var t; - return ((t = r.prototype) == null ? void 0 : t.constructor.toString().indexOf("class ")) === 0; -} -class u { - constructor(t, e) { - o(this, "x"), o(this, "y"), this.x = t, this.y = e; - } - get magnitudeSquared() { - return this.x * this.x + this.y * this.y; - } - get magnitude() { - return Math.sqrt(this.x * this.x + this.y * this.y); - } - get unitVector() { - const t = new u(0, 0), e = this.magnitude; - return e !== 0 && (t.x = this.x / e, t.y = this.y / e), t; - } - add(t) { - this.x += t.x, this.y += t.y; - } - sub(t) { - this.x -= t.x, this.y -= t.y; - } - scale(t) { - this.x *= t, this.y *= t; - } - dot(t) { - return this.x * t.x + this.y * t.y; - } - equals(t) { - return this.x === t.x && this.y === t.y; - } - clone() { - return new u(this.x, this.y); - } - static scale(t, e) { - return new u(t.x * e, t.y * e); - } - static sub(t, e) { - return new u(t.x - e.x, t.y - e.y); - } - static add(t, e) { - return new u(t.x + e.x, t.y + e.y); - } -} -class he { - constructor(t) { - o(this, "_element"), o(this, "_callback"), o(this, "_windowScrollHandler"), o(this, "_windowResizeHandler"), o(this, "_parentElementScrollHandler"), this._element = t, this._observe(); - } - setElement(t) { - this._element = t, this._observe(); - } - _observe() { - var t; - const e = new MutationObserver(() => { - var n; - (n = this._callback) == null || n.call(this, !1); - }), i = { - attributes: !0, - childList: !0, - attributeOldValue: !0 - }; - e.observe(this._element, i), new ResizeObserver(() => { - var n; - (n = this._callback) == null || n.call(this, !0); - }).observe(this._element); - function s(n, a) { - let l, h = !0; - return function() { - h && (n(), h = !1), clearTimeout(l), l = setTimeout(() => { - n(), h = !0; - }, a); - }; - } - this._parentElementScrollHandler = s(() => { - var n; - (n = this._callback) == null || n.call(this, !0); - }, 30), (t = this._element.parentElement) == null || t.addEventListener( - "scroll", - this._parentElementScrollHandler - ), this._windowScrollHandler = s(() => { - var n; - (n = this._callback) == null || n.call(this, !0); - }, 30), window.addEventListener("scroll", this._windowScrollHandler), this._windowResizeHandler = s(() => { - var n; - (n = this._callback) == null || n.call(this, !0); - }, 30), window.addEventListener("resize", this._windowResizeHandler); - } - onChange(t) { - this._callback = t; - } - destroy() { - var t; - this._parentElementScrollHandler && ((t = this._element.parentElement) == null || t.removeEventListener( - "scroll", - this._parentElementScrollHandler - )), this._windowScrollHandler && window.removeEventListener("scroll", this._windowScrollHandler), this._windowResizeHandler && window.removeEventListener("resize", this._windowResizeHandler); - } -} -function ue(r) { - return new he(r); -} -function ce(r, t) { - const e = t.x - r.x, i = t.y - r.y; - return Math.sqrt(e * e + i * i); -} -function _(r, t) { - const e = r - t; - return Math.abs(e) <= 0.01; -} -function E(r) { - let t = r.match(/^([\d.]+)([a-zA-Z%]*)$/); - t || (t = "0px".match(/^([\d.]+)([a-zA-Z%]*)$/)); - const e = parseFloat(t[1]), i = t[2]; - return { value: e, unit: i, valueWithUnit: r }; -} -function de(r, t, e = !1) { - if (r === t) return !0; - if (r.length !== t.length) return !1; - for (let i = 0; i < r.length; i++) - if (e && !_(r[i].value, t[i].value) || r[i].value !== t[i].value) - return !1; - return !0; -} -function Mt(r, t) { - return de(r, t, !0); -} -class G { - constructor(t, e, i, s) { - o(this, "_topLeft"), o(this, "_topRight"), o(this, "_bottomLeft"), o(this, "_bottomRight"), this._topLeft = t, this._topRight = e, this._bottomLeft = i, this._bottomRight = s; - } - get value() { - return { - topLeft: this._topLeft, - topRight: this._topRight, - bottomRight: this._bottomRight, - bottomLeft: this._bottomLeft - }; - } - equals(t) { - return _(this.value.topLeft.value, t.value.topLeft.value) && _(this.value.topRight.value, t.value.topRight.value) && _(this.value.bottomRight.value, t.value.bottomRight.value) && _(this.value.bottomLeft.value, t.value.bottomLeft.value); - } - toCssPercentageForNewSize(t) { - const e = this._convertToPercentage(this._topLeft, t), i = this._convertToPercentage(this._topRight, t), s = this._convertToPercentage(this._bottomLeft, t), n = this._convertToPercentage(this._bottomRight, t); - return `${e.h} ${i.h} ${n.h} ${s.h} / ${e.v} ${i.v} ${n.v} ${s.v}`; - } - _convertToPercentage(t, e) { - if (t.unit === "%") - return { h: `${t.value}%`, v: `${t.value}%` }; - const i = t.value / e.width * 100, s = t.value / e.height * 100; - return { h: `${i}%`, v: `${s}%` }; - } -} -function mt(r) { - const t = r.split(" ").map((i) => E(i)), e = { - value: 0, - unit: "", - valueWithUnit: "0" - }; - switch (t.length) { - case 1: - return new G(t[0], t[0], t[0], t[0]); - case 2: - return new G(t[0], t[1], t[0], t[1]); - case 3: - return new G(t[0], t[1], t[2], t[1]); - case 4: - return new G(t[0], t[1], t[3], t[2]); - default: - return new G( - e, - e, - e, - e - ); - } -} -function ge(r, t) { - const e = a(r.topLeft, t), i = a(r.topRight, t), s = a(r.bottomLeft, t), n = a(r.bottomRight, t); - return { - v: { - topLeft: e.v, - topRight: i.v, - bottomRight: n.v, - bottomLeft: s.v - }, - h: { - topLeft: e.h, - topRight: i.h, - bottomRight: n.h, - bottomLeft: s.h - } - }; - function a(l, h) { - if (l.unit === "%") - return { - h: E(`${l.value}%`), - v: E(`${l.value}%`) - }; - const g = l.value / h.width * 100, c = l.value / h.height * 100; - return { h: E(`${g}%`), v: E(`${c}%`) }; - } -} -function Nt(r, t) { - return _(r.topLeft.value, t.topLeft.value) && _(r.topRight.value, t.topRight.value) && _(r.bottomRight.value, t.bottomRight.value) && _(r.bottomLeft.value, t.bottomLeft.value); -} -class pe { - constructor(t) { - o(this, "_value"), this._value = t; - } - get value() { - return this._value; - } - equals(t) { - return _(this.value, t.value); - } -} -function _e(r) { - return new pe(parseFloat(r)); -} -class me { - constructor(t, e) { - o(this, "_x"), o(this, "_y"), this._x = t, this._y = e; - } - get value() { - return new u(this._x, this._y); - } -} -function ve(r, t) { - const [e, i] = r.split(" "), s = E(e), n = E(i); - return new me( - s.value / t.width, - n.value / t.height - ); -} -function Bt(r, t) { - const e = fe(r), i = r.offsetWidth, s = r.offsetHeight; - return { - viewportOffset: { - left: Math.round(e.left), - top: Math.round(e.top), - right: Math.round(e.right), - bottom: Math.round(e.bottom) - }, - pageOffset: t.read({ - width: i, - height: s - }), - size: { - width: i, - height: s - } - }; -} -function fe(r) { - const t = r.getBoundingClientRect(); - return { - left: t.left, - top: t.top, - right: t.right, - bottom: t.bottom, - width: t.width, - height: t.height - }; -} -function Ft(r) { - let t = r, e = 0, i = 0; - for (; t; ) - e += t.offsetTop, i += t.offsetLeft, t = t.offsetParent; - return { top: e, left: i }; -} -class we { - constructor(t) { - o(this, "_currentPageRect"), o(this, "_view"), o(this, "_element"), o(this, "_offsetLeft"), o(this, "_offsetTop"), o(this, "_width"), o(this, "_height"), o(this, "_parentWidth"), o(this, "_parentHeight"), o(this, "_parentEl"), o(this, "_isSvg"), o(this, "_invalid"), o(this, "_windowResizeHandler"), this._invalid = !0, this._view = t, this._element = t.element, this._isSvg = !!this._element.closest("svg"), this._offsetLeft = 0, this._offsetTop = 0, this._width = 0, this._height = 0, this._parentWidth = 0, this._parentHeight = 0, this._offsetLeft = 0, this._parentEl = this._element.parentElement, this._windowResizeHandler = () => { - this.invalidate(); - }, window.addEventListener("resize", this._windowResizeHandler); - } - destroy() { - this._windowResizeHandler && window.removeEventListener("resize", this._windowResizeHandler); - } - invalidate() { - this._invalid = !0; - } - read(t) { - if (this._isSvg) - return this._currentPageRect || (this._currentPageRect = Ft(this._element)), this._currentPageRect; - const e = this._element.parentElement, i = this._element.offsetLeft, s = this._element.offsetTop, n = t.width, a = t.height, l = (e == null ? void 0 : e.offsetWidth) || 0, h = (e == null ? void 0 : e.offsetHeight) || 0; - return (this._offsetLeft !== i || this._offsetTop !== s || !_(this._width, n) || !_(this._height, a)) && this._view._children.forEach( - (g) => g.elementReader.invalidatePageRect() - ), !this._invalid && this._currentPageRect && this._offsetLeft === i && this._offsetTop === s && _(this._width, n) && _(this._height, a) && _(this._parentWidth, l) && _(this._parentHeight, h) && this._parentEl === e ? this._currentPageRect : (this._offsetLeft = i, this._offsetTop = s, this._width = n, this._height = a, this._parentWidth = l, this._parentHeight = h, this._parentEl = e, this._currentPageRect = Ft(this._element), this._invalid = !1, this._currentPageRect); - } -} -function ye(r) { - return new we(r); -} -class Ve { - constructor(t) { - o(this, "_element"), o(this, "_rect"), o(this, "_computedStyle"), o(this, "_pageRectReader"), o(this, "_scroll"), this._element = t.element, this._pageRectReader = ye(t), this._rect = Bt(this._element, this._pageRectReader), this._computedStyle = getComputedStyle(this._element), this._scroll = this._calculateScroll(); - } - destroy() { - this._pageRectReader.destroy(); - } - invalidatePageRect() { - this._pageRectReader.invalidate(); - } - update(t = !1) { - this._rect = Bt(this._element, this._pageRectReader), this._computedStyle = getComputedStyle(this._element), t && (this._scroll = this._calculateScroll()); - } - get rect() { - return this._rect; - } - get opacity() { - return _e(this._computedStyle.opacity); - } - get borderRadius() { - return mt(this._computedStyle.borderRadius); - } - get origin() { - return ve( - this._computedStyle.transformOrigin, - this._rect.size - ); - } - _calculateScroll() { - let t = this._element, e = 0, i = 0; - for (; t; ) - e += t.scrollTop, i += t.scrollLeft, t = t.offsetParent; - return i += window.scrollX, e += window.scrollY, { y: e, x: i }; - } - get scroll() { - return this._scroll; - } -} -function kt(r) { - return new Ve(r); -} -function vt(r, t) { - const e = { - set: (i, s, n) => (typeof i[s] == "object" && i[s] !== null ? i[s] = vt(n, t) : (t(), i[s] = n), !0), - get: (i, s) => typeof i[s] == "object" && i[s] !== null ? vt(i[s], t) : i[s] - }; - return new Proxy(r, e); -} -const rt = 0.01, yt = { - speed: 15 -}; -class Vt { - constructor(t) { - o(this, "name", "dynamic"), o(this, "_config"), this._config = t; - } - get config() { - return this._config; - } -} -class be extends Vt { - update({ animatorProp: t, current: e, target: i, dt: s }) { - const n = u.sub(i, e), a = u.scale(n, this._config.speed); - let l = u.add(e, u.scale(a, s)); - return this._shouldFinish(i, e, a) && (l = i, requestAnimationFrame(() => { - t.callCompleteCallback(); - })), t.callUpdateCallback(), l; - } - _shouldFinish(t, e, i) { - return u.sub(t, e).magnitude < rt && i.magnitude < rt; - } -} -class Pe extends Vt { - update({ animatorProp: t, current: e, target: i, dt: s }) { - const n = (i - e) * this._config.speed; - let a = e + n * s; - return _(a, i) && (a = i, requestAnimationFrame(() => { - t.callCompleteCallback(); - })), t.callUpdateCallback(), a; - } -} -class Ee extends Vt { - update({ animatorProp: t, current: e, target: i, dt: s }) { - return i.map((n, a) => { - const l = e[a], h = n.value === 0 ? l.unit : n.unit, g = (n.value - l.value) * this._config.speed, c = l.value + g * s; - let p = E(`${c}${h}`); - return this._shouldFinish(n.value, l.value, g) && (p = n, requestAnimationFrame(() => { - t.callCompleteCallback(); - })), t.callUpdateCallback(), p; - }); - } - _shouldFinish(t, e, i) { - return Math.abs(t - e) < rt && Math.abs(i) < rt; - } -} -class bt { - constructor() { - o(this, "name", "instant"), o(this, "_config", {}); - } - get config() { - return this._config; - } - update(t) { - return requestAnimationFrame(() => { - t.animatorProp.callCompleteCallback(); - }), t.target; - } -} -const Pt = { - stiffness: 0.5, - damping: 0.75, - speed: 10 -}, at = 0.01; -class Et { - constructor(t) { - o(this, "name", "spring"), o(this, "_config"), this._config = t; - } - get config() { - return this._config; - } -} -class Re extends Et { - constructor() { - super(...arguments), o(this, "_velocity", new u(0, 0)); - } - update({ animatorProp: t, current: e, target: i, dt: s }) { - const n = u.scale( - u.scale(u.sub(e, i), -1), - this._config.stiffness - ); - this._velocity = u.add(this._velocity, n), this._velocity = u.scale(this._velocity, this._config.damping); - let a = u.add( - e, - u.scale(this._velocity, s * this._config.speed) - ); - return this._shouldFinish(i, e) && (a = i, requestAnimationFrame(() => { - t.callCompleteCallback(); - })), a; - } - _shouldFinish(t, e) { - return u.sub(t, e).magnitude < at && this._velocity.magnitude < at; - } -} -class xe extends Et { - constructor() { - super(...arguments), o(this, "_velocity", 0); - } - update({ animatorProp: t, current: e, target: i, dt: s }) { - const n = -(e - i) * this._config.stiffness; - this._velocity += n, this._velocity *= this._config.damping; - let a = e + this._velocity * s * this._config.speed; - return _(a, i) && (a = i, requestAnimationFrame(() => { - t.callCompleteCallback(); - })), a; - } -} -class Ae extends Et { - constructor() { - super(...arguments), o(this, "_velocity", 0); - } - update({ animatorProp: t, current: e, target: i, dt: s }) { - return i.map((n, a) => { - const l = e[a], h = n.value === 0 ? l.unit : n.unit, g = -(l.value - n.value) * this._config.stiffness; - this._velocity += g, this._velocity *= this._config.damping; - const c = l.value + this._velocity * s * this._config.speed; - let p = E(`${c}${h}`); - return this._shouldFinish(n.value, l.value) && (p = n, requestAnimationFrame(() => { - t.callCompleteCallback(); - })), p; - }); - } - _shouldFinish(t, e) { - return Math.abs(t - e) < at && Math.abs(this._velocity) < at; - } -} -function Te(r) { - return r; -} -const Rt = { - duration: 350, - ease: Te -}; -class xt { - constructor(t) { - o(this, "name", "tween"), o(this, "_config"), o(this, "_startTime"), this._config = t; - } - get config() { - return this._config; - } - reset() { - this._startTime = void 0; - } -} -class Se extends xt { - update({ animatorProp: t, initial: e, target: i, ts: s }) { - this._startTime || (this._startTime = s); - const n = Math.min(1, (s - this._startTime) / this._config.duration); - return _(n, 1) ? (requestAnimationFrame(() => { - t.callCompleteCallback(); - }), i) : u.add( - e, - u.scale(u.sub(i, e), this._config.ease(n)) - ); - } -} -class Ce extends xt { - update({ animatorProp: t, initial: e, target: i, ts: s }) { - this._startTime || (this._startTime = s); - const n = Math.min(1, (s - this._startTime) / this._config.duration); - return _(n, 1) ? (requestAnimationFrame(() => { - t.callCompleteCallback(); - }), i) : e.map((a, l) => { - const h = i[l], g = h.value === 0 ? a.unit : h.unit, c = a.value + this._config.ease(n) * (i[l].value - a.value); - return E(`${c}${g}`); - }); - } -} -class Le extends xt { - update({ animatorProp: t, initial: e, target: i, ts: s }) { - this._startTime || (this._startTime = s); - const n = Math.min(1, (s - this._startTime) / this._config.duration); - return _(n, 1) ? (requestAnimationFrame(() => { - t.callCompleteCallback(); - }), i) : e + (i - e) * this._config.ease(n); - } -} -class At { - createAnimatorByName(t, e) { - switch (t) { - case "instant": - return this.createInstantAnimator(); - case "dynamic": - return this.createDynamicAnimator(e); - case "tween": - return this.createTweenAnimator(e); - case "spring": - return this.createSpringAnimator(e); - } - return this.createInstantAnimator(); - } -} -class it extends At { - createInstantAnimator() { - return new bt(); - } - createTweenAnimator(t) { - return new Se({ ...Rt, ...t }); - } - createDynamicAnimator(t) { - return new be({ ...yt, ...t }); - } - createSpringAnimator(t) { - return new Re({ ...Pt, ...t }); - } -} -class Ie extends At { - createInstantAnimator() { - return new bt(); - } - createTweenAnimator(t) { - return new Ce({ ...Rt, ...t }); - } - createDynamicAnimator(t) { - return new Ee({ - ...yt, - ...t - }); - } - createSpringAnimator(t) { - return new Ae({ ...Pt, ...t }); - } -} -class Ot extends At { - createInstantAnimator() { - return new bt(); - } - createDynamicAnimator(t) { - return new Pe({ ...yt, ...t }); - } - createTweenAnimator(t) { - return new Le({ ...Rt, ...t }); - } - createSpringAnimator(t) { - return new xe({ ...Pt, ...t }); - } -} -function Z(r) { - return structuredClone(r); -} -class Me { - constructor(t) { - o(this, "_viewProp"), o(this, "_completeCallback"), o(this, "_updateCallback"), o(this, "_isAnimating"), this._viewProp = t, this._isAnimating = !1; - } - set(t, e) { - this._viewProp.setAnimator(t, e); - } - get name() { - return this._viewProp.getAnimator().name; - } - onComplete(t) { - this._completeCallback = t; - } - get isAnimating() { - return this._isAnimating; - } - markAsAnimating() { - this._isAnimating = !0; - } - callCompleteCallback() { - var t; - (t = this._completeCallback) == null || t.call(this), this._isAnimating = !1; - } - onUpdate(t) { - this._updateCallback = t; - } - callUpdateCallback() { - var t; - (t = this._updateCallback) == null || t.call(this); - } -} -class k { - constructor(t, e, i) { - o(this, "_animatorProp"), o(this, "_animator"), o(this, "_initialValue"), o(this, "_previousValue"), o(this, "_targetValue"), o(this, "_currentValue"), o(this, "_hasChanged"), o(this, "_view"), o(this, "_animatorFactory"), o(this, "_previousRenderValue"), this._animatorProp = new Me(this), this._animatorFactory = t, this._initialValue = Z(e), this._previousValue = Z(e), this._targetValue = Z(e), this._currentValue = Z(e), this._hasChanged = !1, this._previousRenderValue = void 0, this._view = i, this._animator = this._animatorFactory.createInstantAnimator(); - } - get shouldRender() { - return !0; - } - get isAnimating() { - return this.animator.isAnimating; - } - getAnimator() { - return this._animator; - } - get animator() { - return this._animatorProp; - } - get _rect() { - return this._view.rect; - } - get _previousRect() { - return this._view.previousRect; - } - setAnimator(t, e) { - this._animator = this._animatorFactory.createAnimatorByName( - t, - e - ); - } - _setTarget(t, e = !0) { - var i, s; - this._previousValue = Z(this._currentValue), this._targetValue = t, e ? ((s = (i = this._animator).reset) == null || s.call(i), this.animator.markAsAnimating()) : this._currentValue = t, this._hasChanged = !0; - } - hasChanged() { - return this._hasChanged; - } - destroy() { - this._hasChanged = !1; - } - // @ts-ignore - update(t, e) { - } -} -class Ne extends k { - constructor() { - super(...arguments), o(this, "_invertedBorderRadius"), o(this, "_forceStyleUpdateThisFrame", !1), o(this, "_updateWithScale", !1); - } - setFromElementPropValue(t) { - this._setTarget( - [ - t.value.topLeft, - t.value.topRight, - t.value.bottomRight, - t.value.bottomLeft - ], - !0 - ); - } - enableUpdateWithScale() { - this._updateWithScale = !0; - } - disableUpdateWithScale() { - this._updateWithScale = !1; - } - get value() { - return { - topLeft: this._currentValue[0], - topRight: this._currentValue[1], - bottomRight: this._currentValue[2], - bottomLeft: this._currentValue[3] - }; - } - get invertedBorderRadius() { - return this._invertedBorderRadius; - } - set(t, e = !0) { - let i; - if (typeof t == "string") { - const h = mt(t.trim()); - i = { - topLeft: h.value.topLeft.valueWithUnit, - topRight: h.value.topRight.valueWithUnit, - bottomRight: h.value.bottomRight.valueWithUnit, - bottomLeft: h.value.bottomLeft.valueWithUnit - }; - } else - i = t; - const s = i.topLeft ? E(i.topLeft) : this._currentValue[0], n = i.topRight ? E(i.topRight) : this._currentValue[1], a = i.bottomRight ? E(i.bottomRight) : this._currentValue[2], l = i.bottomLeft ? E(i.bottomLeft) : this._currentValue[3]; - this._setTarget([s, n, a, l], e); - } - reset(t = !0) { - this._setTarget(this._initialValue, t); - } - update(t, e) { - if (this._forceStyleUpdateThisFrame) - this._hasChanged = !0, this._forceStyleUpdateThisFrame = !1; - else if (this._view.scale.isAnimating && this._updateWithScale) - this._hasChanged = !0; - else if (Mt(this._targetValue, this._currentValue)) { - this._hasChanged = !Mt( - this._targetValue, - this._initialValue - ); - return; - } - this._currentValue = this._animator.update({ - animatorProp: this._animatorProp, - current: this._currentValue, - target: this._targetValue, - initial: this._previousValue, - ts: t, - dt: e - }), this._updateWithScale && this._applyScaleInverse(); - } - applyScaleInverse() { - this._updateWithScale && (this._forceStyleUpdateThisFrame = !0); - } - _applyScaleInverse() { - if (_(this._view.scale.x, 1) && _(this._view.scale.y, 1)) - return; - const t = this._rect.size.width * this._view.scale.x, e = this._rect.size.height * this._view.scale.y; - this._invertedBorderRadius = ge( - mt( - `${this._currentValue[0].valueWithUnit} ${this._currentValue[1].valueWithUnit} ${this._currentValue[2].valueWithUnit} ${this._currentValue[3].valueWithUnit}` - ).value, - { - width: t, - height: e - } - ); - } - get shouldRender() { - return this._hasChanged ? this._previousRenderValue ? !(Nt( - this.renderValue.v, - this._previousRenderValue.v - ) && Nt(this.renderValue.h, this._previousRenderValue.h)) : !0 : !1; - } - get renderValue() { - return this.invertedBorderRadius ? { - v: { - topLeft: this.invertedBorderRadius.v.topLeft, - topRight: this.invertedBorderRadius.v.topRight, - bottomLeft: this.invertedBorderRadius.v.bottomLeft, - bottomRight: this.invertedBorderRadius.v.bottomRight - }, - h: { - topLeft: this.invertedBorderRadius.h.topLeft, - topRight: this.invertedBorderRadius.h.topRight, - bottomLeft: this.invertedBorderRadius.h.bottomLeft, - bottomRight: this.invertedBorderRadius.h.bottomRight - } - } : { - v: { - topLeft: this.value.topLeft, - topRight: this.value.topRight, - bottomLeft: this.value.bottomLeft, - bottomRight: this.value.bottomRight - }, - h: { - topLeft: this.value.topLeft, - topRight: this.value.topRight, - bottomLeft: this.value.bottomLeft, - bottomRight: this.value.bottomRight - } - }; - } - projectStyles() { - const t = this.renderValue, e = `border-radius: ${t.h.topLeft.valueWithUnit} ${t.h.topRight.valueWithUnit} ${t.h.bottomRight.valueWithUnit} ${t.h.bottomLeft.valueWithUnit} / ${t.v.topLeft.valueWithUnit} ${t.v.topRight.valueWithUnit} ${t.v.bottomRight.valueWithUnit} ${t.v.bottomLeft.valueWithUnit};`; - return this._previousRenderValue = t, e; - } - isTransform() { - return !1; - } -} -class Be extends k { - setFromElementPropValue(t) { - this._setTarget(t.value, !0); - } - get value() { - return this._currentValue; - } - set(t, e = !0) { - this._setTarget(t, e); - } - reset(t = !0) { - this._setTarget(1, t); - } - update(t, e) { - if (_(this._targetValue, this._currentValue)) { - this._hasChanged = !_(this._targetValue, this._initialValue); - return; - } - this._currentValue = this._animator.update({ - animatorProp: this._animatorProp, - current: this._currentValue, - target: this._targetValue, - initial: this._previousValue, - ts: t, - dt: e - }); - } - get shouldRender() { - return this._hasChanged ? typeof this._previousRenderValue > "u" ? !0 : this.renderValue !== this._previousRenderValue : !1; - } - get renderValue() { - return this.value; - } - projectStyles() { - const t = this.renderValue, e = `opacity: ${t};`; - return this._previousRenderValue = t, e; - } - isTransform() { - return !1; - } -} -class Fe extends k { - get x() { - return this._currentValue.x; - } - get y() { - return this._currentValue.y; - } - set(t) { - const e = { x: this.x, y: this.y, ...t }; - if (e.x < 0 || e.x > 1) { - console.log( - `%c WARNING: ${this._view.name}.origin.x property can only be a value from 0 to 1`, - "background: #885500" - ); - return; - } - if (e.y < 0 || e.y > 1) { - console.log( - `%c WARNING: ${this._view.name}.origin.y property can only be a value from 0 to 1`, - "background: #885500" - ); - return; - } - this._setTarget(new u(e.x, e.y), !1); - } - reset() { - this._setTarget(this._initialValue, !1); - } - get shouldRender() { - if (!this._hasChanged) - return !1; - if (!this._previousRenderValue) - return !0; - const t = this.renderValue; - return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y)); - } - get renderValue() { - return new u(this.x * 100, this.y * 100); - } - projectStyles() { - const t = this.renderValue, e = `transform-origin: ${t.x}% ${t.y}%;`; - return this._previousRenderValue = t, e; - } - isTransform() { - return !1; - } -} -class ke extends k { - constructor() { - super(...arguments), o(this, "_animateLayoutUpdateNextFrame", !1), o(this, "_parentScaleInverse", new u(1, 1)); - } - get _parentDiff() { - let t = this._view._parent, e = 0, i = 0; - if (t) { - const s = t.rect.pageOffset, n = t.getScroll(), a = { - left: t.previousRect.viewportOffset.left + n.x, - top: t.previousRect.viewportOffset.top + n.y - }; - e = a.left - s.left, i = a.top - s.top; - } - return { parentDx: e, parentDy: i }; - } - get x() { - return this._currentValue.x + this._rect.pageOffset.left + this._parentDiff.parentDx; - } - get y() { - return this._currentValue.y + this._rect.pageOffset.top + this._parentDiff.parentDy; - } - get initialX() { - return this._rect.pageOffset.left; - } - get initialY() { - return this._rect.pageOffset.top; - } - progressTo(t) { - const e = typeof t.x > "u" ? this.initialX : t.x, i = typeof t.y > "u" ? this.initialY : t.y, s = new u(e, i), n = new u(this.initialX, this.initialY), a = new u(this.x, this.y), l = u.sub(a, n), h = u.sub(s, n); - return 1 - u.sub(h, l).magnitude / h.magnitude; - } - set(t, e = !0) { - const i = { x: this.x, y: this.y, ...t }; - this._setTarget( - new u( - i.x - this._rect.pageOffset.left, - i.y - this._rect.pageOffset.top - ), - e - ); - } - reset(t = !0) { - this._setTarget(new u(0, 0), t); - } - update(t, e) { - if ((this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && !this._view.isTemporaryView && this._runLayoutTransition(), this._view.isInverseEffectEnabled) { - const h = this._view._parent, g = h ? h.scale.x : 1, c = h ? h.scale.y : 1; - this._parentScaleInverse = new u(1 / g, 1 / c), this._parentScaleInverse.equals(new u(1, 1)) || (this._hasChanged = !0); - } - if (this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y) - return; - const i = this._view._parent, s = i ? i.scale.x : 1, n = i ? i.scale.y : 1, a = i ? i.scale._previousValue.x : 1, l = i ? i.scale._previousValue.y : 1; - this._currentValue = this._animator.update({ - animatorProp: this._animatorProp, - current: new u( - this._currentValue.x * s, - this._currentValue.y * n - ), - target: this._targetValue, - initial: new u( - this._previousValue.x * a, - this._previousValue.y * l - ), - ts: t, - dt: e - }), this._currentValue = new u( - this._currentValue.x / s, - this._currentValue.y / n - ); - } - _runLayoutTransition() { - const t = !(this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y), e = !(this._view.scale._targetValue.x === this._view.scale._currentValue.x && this._view.scale._targetValue.y === this._view.scale._currentValue.y), i = t || e, s = this._rect.pageOffset.left - this._previousRect.pageOffset.left, n = this._rect.pageOffset.top - this._previousRect.pageOffset.top, a = this._previousRect.size.width / this._rect.size.width, l = this._previousRect.size.height / this._rect.size.height; - let h = !1; - if (s !== 0 || n !== 0 || !Number.isNaN(a) && a !== 1 || !Number.isNaN(l) && l !== 1 ? h = !0 : h = (() => { - const g = this._view._parents; - for (let c = 0; c < g.length; c++) { - const p = g[c], f = p.previousRect.size.width / p.rect.size.width, V = p.previousRect.size.height / p.rect.size.height; - if (f !== 1 || V !== 1) - return !0; - } - return !1; - })(), h) { - if (this._currentValue.x !== 0 || this._currentValue.y !== 0 || this._view.scale._currentValue.x !== 1 || this._view.scale._currentValue.y !== 1) { - if (!i) { - const B = this._rect.pageOffset.left - this._previousRect.pageOffset.left, M = this._rect.pageOffset.top - this._previousRect.pageOffset.top; - this._setTarget( - new u(this._currentValue.x - B, this._currentValue.y - M), - !1 - ); - return; - } - const x = this._view._parent, I = this._rect.pageOffset, O = this._view.getScroll(), S = { - left: this._previousRect.viewportOffset.left + O.x, - top: this._previousRect.viewportOffset.top + O.y - }, z = S.left - I.left, D = S.top - I.top; - let U = 0, Y = 0, X = 0, et = 0; - if (x) { - const B = x.rect.pageOffset, M = x.getScroll(), $ = { - left: x.previousRect.viewportOffset.left + M.x, - top: x.previousRect.viewportOffset.top + M.y - }; - U = $.left - B.left, Y = $.top - B.top; - const d = S.top - $.top, m = S.left - $.left, v = x.scale.y * d; - X = (d - v) / x.scale.y; - const j = x.scale.x * m; - et = (m - j) / x.scale.x; - } - this._setTarget( - new u(z - U + et, D - Y + X), - !1 - ), i && (this._animateLayoutUpdateNextFrame = !0); - return; - } - this._animateLayoutUpdateNextFrame = !0; - const g = this._previousRect, c = this._rect, p = this._view._parent; - let f = 0, V = 0; - p && (f = p.previousRect.viewportOffset.left - p.rect.viewportOffset.left), p && (V = p.previousRect.viewportOffset.top - p.rect.viewportOffset.top); - let w = 1, b = 1; - p && (w = p.previousRect.size.width / p.rect.size.width, b = p.previousRect.size.height / p.rect.size.height); - const T = p ? p.previousRect.viewportOffset.left : 0, C = p ? p.previousRect.viewportOffset.top : 0, H = g.viewportOffset.left - T, R = g.viewportOffset.top - C, Q = H / w - H, tt = R / b - R; - let A = g.viewportOffset.left - c.viewportOffset.left - f + Q, L = g.viewportOffset.top - c.viewportOffset.top - V + tt; - A = Number.isFinite(A) ? A : 0, L = Number.isFinite(L) ? L : 0, this._setTarget(new u(A, L), !1); - } else this._animateLayoutUpdateNextFrame && (this._setTarget(this._initialValue, !0), this._animateLayoutUpdateNextFrame = !1); - } - get shouldRender() { - if (!this._hasChanged) - return !1; - if (!this._previousRenderValue) - return !0; - const t = this.renderValue; - return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y)); - } - get renderValue() { - let t = 0, e = 0; - return (this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && (t = (this._rect.size.width * this._parentScaleInverse.x * this._view.scale.x - this._rect.size.width) * this._view.origin.x, e = (this._rect.size.height * this._parentScaleInverse.y * this._view.scale.y - this._rect.size.height) * this._view.origin.y), new u( - this._currentValue.x + t, - this._currentValue.y + e - ); - } - projectStyles() { - const t = this.renderValue, e = `translate3d(${t.x}px, ${t.y}px, 0px)`; - return this._previousRenderValue = t, e; - } - isTransform() { - return !0; - } -} -class Oe extends k { - constructor() { - super(...arguments), o(this, "_unit", "deg"); - } - get degrees() { - let t = this._currentValue; - return this._unit === "rad" && (t = t * (180 / Math.PI)), t; - } - get radians() { - let t = this._currentValue; - return this._unit === "deg" && (t = t * (Math.PI / 180)), t; - } - setDegrees(t, e = !0) { - this._unit = "deg", this._setTarget(t, e); - } - setRadians(t, e = !0) { - this._unit = "rad", this._setTarget(t, e); - } - reset(t = !0) { - this._setTarget(0, t); - } - update(t, e) { - this._targetValue !== this._currentValue && (this._currentValue = this._animator.update({ - animatorProp: this._animatorProp, - current: this._currentValue, - target: this._targetValue, - initial: this._previousValue, - ts: t, - dt: e - })); - } - get shouldRender() { - if (!this._hasChanged) - return !1; - if (typeof this._previousRenderValue > "u") - return !0; - const t = this.renderValue; - return !_(t, this._previousRenderValue); - } - get renderValue() { - return this._currentValue; - } - projectStyles() { - const t = this.renderValue, e = `rotate(${t}${this._unit})`; - return this._previousRenderValue = t, e; - } - isTransform() { - return !0; - } -} -class ze extends k { - constructor() { - super(...arguments), o(this, "_animateLayoutUpdateNextFrame", !1); - } - get x() { - return this._currentValue.x; - } - get y() { - return this._currentValue.y; - } - set(t, e = !0) { - const i = { x: this._currentValue.x, y: this._currentValue.y, ...typeof t == "number" ? { x: t, y: t } : t }; - this._setTarget(new u(i.x, i.y), e); - } - setWithSize(t, e = !0) { - let i = this._currentValue.x, s = this._currentValue.y; - t.width && (i = t.width / this._rect.size.width), t.height && (s = t.height / this._rect.size.height), !t.width && t.height && (i = s), !t.height && t.width && (s = i); - const n = { x: i, y: s }; - this._setTarget(new u(n.x, n.y), e); - } - reset(t = !0) { - this._setTarget(new u(1, 1), t); - } - update(t, e) { - if (this._view.layoutOption !== "position") { - if ((this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && !this._view.isTemporaryView && this._runLayoutTransition(), this._view.isInverseEffectEnabled) { - const i = this._view._parent, s = i ? i.scale.x : 1, n = i ? i.scale.y : 1; - this._hasChanged = s !== 1 || n !== 1; - } - this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y || (this._currentValue = this._animator.update({ - animatorProp: this._animatorProp, - current: this._currentValue, - target: this._targetValue, - initial: new u(this._previousValue.x, this._previousValue.y), - ts: t, - dt: e - })); - } - } - _runLayoutTransition() { - const t = !(this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y), e = this._previousRect.size.width / this._rect.size.width, i = this._previousRect.size.height / this._rect.size.height; - let s = !1; - if ((!Number.isNaN(e) && e !== 1 || !Number.isNaN(i) && i !== 1) && (s = !0), s) { - if (this._currentValue.x !== 1 || this._currentValue.y !== 1) { - const g = this._view.previousRect.size.width / this._view.rect.size.width, c = this._view.previousRect.size.height / this._view.rect.size.height; - this._setTarget( - new u(this._currentValue.x * g, this._currentValue.y * c), - !1 - ), t && (this._animateLayoutUpdateNextFrame = !0); - return; - } - const n = this._previousRect.size.width / this._rect.size.width, a = this._previousRect.size.height / this._rect.size.height, l = n, h = a; - this._view.viewProps.borderRadius.applyScaleInverse(), this._setTarget(new u(l, h), !1), this._animateLayoutUpdateNextFrame = !0; - } else this._animateLayoutUpdateNextFrame && (this._setTarget(this._initialValue, !0), this._animateLayoutUpdateNextFrame = !1); - } - get shouldRender() { - if (!this._hasChanged) - return !1; - if (!this._previousRenderValue) - return !0; - const t = this.renderValue; - return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y)); - } - get renderValue() { - const t = this._view._parent ? this._view._parent.scale.x : 1, e = this._view._parent ? this._view._parent.scale.y : 1, i = this._currentValue.x / t, s = this._currentValue.y / e; - return new u(i, s); - } - projectStyles() { - const t = this.renderValue, e = `scale3d(${t.x}, ${t.y}, 1)`; - return this._previousRenderValue = t, e; - } - isTransform() { - return !0; - } -} -class De extends k { - get width() { - return this._view.rect.size.width; - } - get height() { - return this._view.rect.size.height; - } - get localWidth() { - return this._currentValue.x; - } - get localHeight() { - return this._currentValue.y; - } - get widthAfterScale() { - const t = this._view.scale.x; - return this.localWidth * t; - } - get heightAfterScale() { - const t = this._view.scale.y; - return this.localHeight * t; - } - get initialWidth() { - return this._initialValue.x; - } - get initialHeight() { - return this._initialValue.y; - } - set(t, e = !0) { - const i = { width: this._currentValue.x, height: this._currentValue.y, ...t }; - this._setTarget(new u(i.width, i.height), e); - } - setWidth(t, e = !0) { - const i = { width: this._currentValue.x, height: this._currentValue.y, width: t }; - this._setTarget(new u(i.width, i.height), e); - } - setHeight(t, e = !0) { - const i = { width: this._currentValue.x, height: this._currentValue.y, height: t }; - this._setTarget(new u(i.width, i.height), e); - } - reset(t = !0) { - this._setTarget( - new u(this.initialWidth, this.initialHeight), - t - ); - } - update(t, e) { - this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y || (this._currentValue = this._animator.update({ - animatorProp: this._animatorProp, - current: this._currentValue, - target: this._targetValue, - initial: this._previousValue, - ts: t, - dt: e - })); - } - get shouldRender() { - if (!this._hasChanged) - return !1; - if (!this._previousRenderValue) - return !0; - const t = this.renderValue; - return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y)); - } - get renderValue() { - return new u(this._currentValue.x, this._currentValue.y); - } - projectStyles() { - const t = this.renderValue, e = `width: ${t.x}px; height: ${t.y}px;`; - return this._previousRenderValue = t, e; - } - isTransform() { - return !1; - } -} -class $e { - constructor(t) { - o(this, "_props", /* @__PURE__ */ new Map()), this._props.set( - "position", - new ke(new it(), new u(0, 0), t) - ), this._props.set( - "scale", - new ze(new it(), new u(1, 1), t) - ), this._props.set( - "rotation", - new Oe(new Ot(), 0, t) - ), this._props.set( - "size", - new De( - new it(), - new u(t.rect.size.width, t.rect.size.height), - t - ) - ), this._props.set( - "opacity", - new Be( - new Ot(), - t.elementReader.opacity.value, - t - ) - ), this._props.set( - "borderRadius", - new Ne( - new Ie(), - [ - t.elementReader.borderRadius.value.topLeft, - t.elementReader.borderRadius.value.topRight, - t.elementReader.borderRadius.value.bottomRight, - t.elementReader.borderRadius.value.bottomLeft - ], - t - ) - ), this._props.set( - "origin", - new Fe( - new it(), - t.elementReader.origin.value, - t - ) - ); - } - allProps() { - return Array.from(this._props.values()); - } - allPropNames() { - return Array.from(this._props.keys()); - } - getPropByName(t) { - return this._props.get(t); - } - get position() { - return this._props.get("position"); - } - get scale() { - return this._props.get("scale"); - } - get rotation() { - return this._props.get("rotation"); - } - get size() { - return this._props.get("size"); - } - get opacity() { - return this._props.get("opacity"); - } - get borderRadius() { - return this._props.get("borderRadius"); - } - get origin() { - return this._props.get("origin"); - } -} -class We { - constructor(t, e, i, s) { - o(this, "id"), o(this, "name"), o(this, "element"), o(this, "styles", {}), o(this, "_viewProps"), o(this, "_previousRect"), o(this, "_onAddCallbacks"), o(this, "_onRemoveCallback"), o(this, "_skipFirstRenderFrame"), o(this, "_layoutTransition"), o(this, "_registry"), o(this, "_layoutId"), o(this, "_elementReader"), o(this, "_viewParents"), o(this, "_temporaryView"), o(this, "_inverseEffect"), o(this, "_renderNextTick"), o(this, "_layoutOption"), o(this, "_elementObserver"), o(this, "_hasReadElement"), o(this, "_shouldReadRect"), o(this, "_readWithScroll"), o(this, "_externalUserStyles"), this._registry = i, this.id = Wt(), this.name = e, this.element = t, this.element.dataset.velViewId = this.id, this._elementReader = kt(this), this._viewParents = this._getParents(), this._previousRect = this._elementReader.rect, this._viewProps = new $e(this), this._skipFirstRenderFrame = !0, this._layoutId = s, this._layoutTransition = !1, this._temporaryView = !1, this.styles = vt(this.styles, () => { - this._renderNextTick = !0; - }), this._externalUserStyles = this._getExternalUserStyles(), this._renderNextTick = !1, this._layoutOption = this._getLayoutOption(), this._hasReadElement = !1, this._shouldReadRect = !1, this._readWithScroll = !1, this._elementObserver = ue(t), this._elementObserver.onChange((n) => { - if (this._hasReadElement) { - this._shouldReadRect = !1; - return; - } - this._externalUserStyles = this._getExternalUserStyles(), this._shouldReadRect = !0, this._readWithScroll = n; - }); - } - removeListeners() { - this._elementObserver.destroy(), this._elementReader.destroy(); - } - destroy() { - this.removeListeners(), this._viewProps.allProps().forEach((t) => t.destroy()), this.element.removeAttribute("data-vel-view-id"), this.element.removeAttribute("data-vel-plugin-id"), this._renderNextTick = !0; - } - get elementReader() { - return this._elementReader; - } - get layoutOption() { - return this._layoutOption; - } - _getLayoutOption() { - return this.element.closest("[data-vel-layout-position]") ? "position" : this.element.closest("[data-vel-layout-size]") ? "size" : "all"; - } - setElement(t) { - this.element = t, this._elementReader = kt(this), this.element.dataset.velViewId = this.id, this._elementObserver.setElement(t), this._viewParents = this._getParents(); - } - get layoutId() { - return this._layoutId; - } - get position() { - return this._viewProps.position; - } - get scale() { - return this._viewProps.scale; - } - get _children() { - const t = this.element.querySelectorAll("*"); - return Array.from(t).map((e) => e.dataset.velViewId).filter((e) => e && typeof e == "string").map((e) => this._registry.getViewById(e)).filter((e) => !!e); - } - get _parent() { - return this._parents[0]; - } - get _parents() { - return this._viewParents; - } - _getParents() { - var t; - const e = []; - let i = this.element.parentElement; - if (!i) return e; - for (i = i.closest("[data-vel-view-id]"); i; ) { - const s = i.dataset.velViewId; - if (s) { - const n = this._registry.getViewById(s); - n && e.push(n); - } - i = (t = i.parentElement) == null ? void 0 : t.closest( - "[data-vel-view-id]" - ); - } - return e; - } - get rotation() { - return this._viewProps.rotation; - } - get size() { - return this._viewProps.size; - } - get _localWidth() { - return this._viewProps.size.localWidth; - } - get _localHeight() { - return this._viewProps.size.localHeight; - } - get opacity() { - return this._viewProps.opacity; - } - get borderRadius() { - return this._viewProps.borderRadius; - } - get origin() { - return this._viewProps.origin; - } - get data() { - const t = this.element.dataset; - return Object.keys(t).filter((e) => e.includes("velData")).map((e) => e.replace("velData", "")).map((e) => `${e[0].toLowerCase()}${e.slice(1)}`).reduce((e, i) => { - const s = t[`velData${i[0].toUpperCase()}${i.slice(1)}`]; - return !e[i] && s && (e[i] = s), e; - }, {}); - } - get onAddCallbacks() { - return this._onAddCallbacks; - } - get onRemoveCallback() { - return this._onRemoveCallback; - } - get isLayoutTransitionEnabled() { - return this._layoutTransition; - } - get hasLayoutTransitionEnabledForParents() { - return this._parents.some((t) => t.isLayoutTransitionEnabled); - } - get isInverseEffectEnabled() { - let t = !1; - for (let e = 0; e < this._parents.length; e++) { - const i = this._parents[e]; - if (typeof i._inverseEffect < "u") { - t = i._inverseEffect; - break; - } - } - return t; - } - layoutTransition(t) { - this._layoutTransition = t, this.inverseEffect(t); - } - inverseEffect(t) { - this._inverseEffect = t, t && this._children.forEach((e) => { - if (e.position.animator.name === "instant") { - const i = this.viewProps.position.getAnimator(); - e.position.setAnimator( - i.name, - i.config - ); - } - if (e.scale.animator.name === "instant") { - const i = this.viewProps.scale.getAnimator(); - e.scale.setAnimator(i.name, i.config); - } - }); - } - setAnimatorsFromParent() { - let t = this._parent; - for (; t && !t._inverseEffect; ) - t = t._parent; - if (t) { - if (this.position.animator.name === "instant") { - const e = t.viewProps.position.getAnimator(); - this.position.setAnimator(e.name, e.config); - } - if (this.scale.animator.name === "instant") { - const e = t.viewProps.scale.getAnimator(); - this.scale.setAnimator(e.name, e.config); - } - } - } - get _isRemoved() { - return !this._registry.getViewById(this.id); - } - setPluginId(t) { - this.element.dataset.velPluginId = t; - } - hasElement(t) { - return this.element.contains(t); - } - getScroll() { - return this._elementReader.scroll; - } - intersects(t, e) { - const i = this.element.getBoundingClientRect(), s = { - x: i.left, - y: i.top - }; - return t >= s.x && t <= s.x + i.width && e >= s.y && e <= s.y + i.height; - } - // Using AABB collision detection - overlapsWith(t) { - const e = t._localWidth * t.scale.x, i = t._localHeight * t.scale.y, s = this._localWidth * this.scale.x, n = this._localHeight * this.scale.y; - return this.position.x < t.position.x + e && this.position.x + s > t.position.x && this.position.y < t.position.y + i && this.position.y + n > t.position.y; - } - distanceTo(t) { - const e = new u(this.position.x, this.position.y), i = new u(t.position.x, t.position.y); - return u.sub(i, e).magnitude; - } - read() { - this._shouldReadRect && (this._elementReader.update(this._readWithScroll), this._children.forEach((t) => { - t.setHasReadElement(!0), t.elementReader.update(this._readWithScroll); - }), this._shouldReadRect = !1, this._readWithScroll = !1), this.setHasReadElement(!1); - } - setHasReadElement(t) { - this._hasReadElement = t; - } - get rect() { - return this._elementReader.rect; - } - get previousRect() { - return this._previousRect; - } - update(t, e) { - this._viewProps.allProps().forEach((i) => i.update(t, e)); - } - _updatePreviousRect() { - this._previousRect = this._elementReader.rect; - } - setAsTemporaryView() { - this._temporaryView = !0; - } - get isTemporaryView() { - return this._temporaryView; - } - get shouldRender() { - return this._renderNextTick || this._viewProps.allProps().some((t) => t.shouldRender); - } - _cleanCssText(t) { - const e = /* @__PURE__ */ new Map(), i = /([-\w]+)\s*:\s*([^;]+)\s*;?/g; - let s; - for (; (s = i.exec(t)) !== null; ) { - const [n, a, l] = s; - if (!l.trim()) continue; - const h = a.replace(/^-\w+-/, ""); - (!e.has(h) || !a.startsWith("-")) && e.set( - h, - `${h}: ${l.trim()}` - ); - } - return Array.from(e.values()).join("; "); - } - render() { - if (!this.shouldRender) - return; - if (this._isRemoved && this._skipFirstRenderFrame) { - this._skipFirstRenderFrame = !1; - return; - } - let t = ""; - const e = this._viewProps.allProps(), i = e.filter((n) => n.isTransform()), s = e.filter((n) => !n.isTransform()); - if (i.some((n) => n.hasChanged())) { - const n = i.reduce((a, l, h) => (a += l.projectStyles(), h < i.length - 1 && (a += " "), h === i.length - 1 && (a += ";"), a), "transform: "); - t += n; - } - s.forEach((n) => { - n.hasChanged() && (t += n.projectStyles()); - }), t += this._getUserStyles(), this._cleanCssText(this.element.style.cssText) !== this._cleanCssText(t) && (this.element.style.cssText = t), this._renderNextTick = !1; - } - _getExternalUserStyles() { - const t = this.element.style.cssText, e = this.styles; - if (t.length === 0) - return ""; - const i = [ - "transform", - "transform-origin", - "opacity", - "width", - "height", - "border-radius" - ], s = {}; - for (const n in e) - e.hasOwnProperty(n) && (s[Lt(n)] = e[n]); - return t.split(";").map((n) => n.trim()).filter(Boolean).filter((n) => { - const a = n.indexOf(":"); - if (a === -1) return !1; - const l = n.slice(0, a).trim(); - return !s.hasOwnProperty(l) && !i.includes(l); - }).join("; "); - } - _getUserStyles() { - return Object.keys(this.styles).reduce((t, e) => { - if (!e) return t; - const i = Lt(e).replace("webkit", "-webkit").replace("moz", "-moz"); - return t + `${i}: ${this.styles[e]}; `; - }, this._externalUserStyles); - } - markAsAdded() { - delete this.element.dataset.velProcessing; - } - onAdd(t) { - this._onAddCallbacks = t; - } - onRemove(t) { - this._onRemoveCallback = t; - } - get viewProps() { - return this._viewProps; - } - getPropByName(t) { - return this._viewProps.getPropByName(t); - } - _copyAnimatorsToAnotherView(t) { - t.viewProps.allPropNames().forEach((e) => { - var i, s; - const n = (i = this.viewProps.getPropByName(e)) == null ? void 0 : i.getAnimator(); - n && ((s = t.viewProps.getPropByName(e)) == null || s.setAnimator(n.name, n.config)); - }); - } - getChildren(t) { - const e = this.element.querySelectorAll("*"), i = Array.from(e).filter((s) => { - const n = s; - return typeof n.dataset.velViewId < "u" && n.dataset.velView === t; - }).map((s) => s.dataset.velViewId); - return this._registry.getViewsById(i); - } - getChild(t) { - return this.getChildren(t)[0]; - } - getParent(t) { - const e = this.element.closest( - `[data-vel-view="${t}"]` - ); - if (!e) return; - const i = e.dataset.velViewId; - if (i) - return this._registry.getViewById(i); - } -} -class qe { - constructor(t, e) { - o(this, "_appEventBus"), o(this, "_eventBus"), o(this, "_plugins", []), o(this, "_views", []), o(this, "_viewsPerPlugin", /* @__PURE__ */ new Map()), o(this, "_viewsToBeCreated", []), o(this, "_viewsToBeRemoved", []), o(this, "_viewsCreatedInPreviousFrame", []), o(this, "_layoutIdToViewMap", /* @__PURE__ */ new Map()), o(this, "_eventPluginsPerPlugin", /* @__PURE__ */ new Map()), o(this, "_pluginNameToPluginFactoryMap", /* @__PURE__ */ new Map()), o(this, "_pluginNameToPluginConfigMap", /* @__PURE__ */ new Map()), this._appEventBus = t, this._eventBus = e; - } - update() { - this._handleRemovedViews(), this._handleAddedViews(); - } - associateEventPluginWithPlugin(t, e) { - let i = this._eventPluginsPerPlugin.get(t); - i || (i = [], this._eventPluginsPerPlugin.set(t, i)), i.push(e); - } - _handleRemovedViews() { - const t = this._viewsToBeRemoved.filter((e) => e.dataset.velViewId); - t.length && (t.forEach((e) => { - const i = e.dataset.velViewId; - i && (this._handleRemoveView(i), e.querySelectorAll("*").forEach((s) => { - const n = s.dataset.velViewId; - n && this._plugins.forEach((a) => { - if (!this._viewsPerPlugin.get(a.id)) return; - const l = this._getPluginViewById(a, n); - l && l.removeListeners(); - }); - })); - }), this._viewsToBeRemoved = []); - } - _getPluginNameForElement(t) { - const e = t.dataset.velPlugin; - if (e && e.length > 0) return e; - const i = t.closest("[data-vel-plugin]"); - if (i) - return i.dataset.velPlugin; - } - _getPluginIdForElement(t) { - const e = this._getPluginNameForElement(t); - if (!e) - return; - const i = t.closest("[data-vel-plugin-id]"); - if (i) - return i.dataset.velPluginId; - const s = this.getPluginByName(e); - if (s) - return s.id; - } - _isScopedElement(t) { - const e = this._getPluginNameForElement(t); - if (!e) - return !1; - const i = this._pluginNameToPluginFactoryMap.get(e), s = i == null ? void 0 : i.scope; - return t.dataset.velView === s; - } - _removeElementsWithParent(t) { - const e = new Set(t); - return t.filter((i) => { - let s = i.parentElement; - for (; s; ) { - if (e.has(s)) - return !1; - s = s.parentElement; - } - return !0; - }); - } - _handleAddedViews() { - this._viewsCreatedInPreviousFrame.forEach((n) => { - n.markAsAdded(); - }), this._viewsCreatedInPreviousFrame = []; - const t = this._removeElementsWithParent( - this._viewsToBeCreated - ), e = Array.from( - new Set( - t.filter( - (n) => this._isScopedElement(n) && !this._isElementIgnored(n) - ) - ) - ), i = t.filter( - (n) => !this._isScopedElement(n) && !this._isElementIgnored(n) - ); - this._viewsToBeCreated = [], e.forEach((n) => { - const a = this._getPluginNameForElement(n), l = this._pluginNameToPluginFactoryMap.get(a), h = this._pluginNameToPluginConfigMap.get(a), g = n.dataset.velPluginKey, c = dt( - l, - this, - this._eventBus, - this._appEventBus, - h, - g - ); - this._plugins.push(c); - const p = n.dataset.velView, f = this._createNewView(n, p, c); - f.isInverseEffectEnabled && f.setAnimatorsFromParent(), c.notifyAboutViewAdded(f); - }); - const s = i.filter((n) => !!this._getPluginIdForElement(n)); - s.length !== 0 && s.forEach((n) => { - const a = this._getPluginIdForElement(n), l = n.dataset.velView; - if (!l || !a) return; - const h = this._getPluginById(a); - if (!h) - return; - const g = this._getLayoutIdForElement(n, h); - let c; - g && this._layoutIdToViewMap.has(g) ? (c = this._layoutIdToViewMap.get(g), c.setElement(n), c.setPluginId(h.id), this._createChildrenForView(c, h)) : c = this._createNewView(n, l, h), c.isInverseEffectEnabled && c.setAnimatorsFromParent(), h.notifyAboutViewAdded(c); - }); - } - _getLayoutIdForElement(t, e) { - const i = t.dataset.velLayoutId; - if (i) - return `${i}-${e.id}`; - } - _createNewView(t, e, i) { - const s = this._getLayoutIdForElement(t, i), n = this.createView(t, e, s); - return i.addView(n), n.layoutId && this._layoutIdToViewMap.set(n.layoutId, n), this._createChildrenForView(n, i), this._appEventBus.emitPluginReadyEvent(i.pluginName, i.api, !0), requestAnimationFrame(() => { - requestAnimationFrame(() => { - this._appEventBus.emitPluginReadyEvent(i.pluginName, i.api); - }); - }), n; - } - _createChildrenForView(t, e) { - const i = t.element.querySelectorAll("*"); - if (i.length) { - if (Array.from(i).some( - (s) => this._getPluginNameForElement(s) !== e.pluginName - )) { - console.log( - `%c WARNING: The plugin "${e.pluginName}" has view(s) created for a different plugin. Make sure all views inside that plugin don't have data-vel-plugin set or the pluginName is set to "${e.pluginName}"`, - "background: #885500" - ); - return; - } - Array.from(i).filter((s) => !this._isElementIgnored(s)).forEach((s) => { - const n = s, a = n.dataset.velView ? n.dataset.velView : `${t.name}-child`, l = this._getLayoutIdForElement(n, e); - let h; - l && this._layoutIdToViewMap.has(l) ? (h = this._layoutIdToViewMap.get(l), h.setElement(n), h.setPluginId(e.id)) : h = this.createView(n, a, l), l && !this._layoutIdToViewMap.has(l) && this._layoutIdToViewMap.set(l, h), e.addView(h), e.notifyAboutViewAdded(h); - }); - } - } - _handleRemoveView(t) { - this._plugins.forEach((e) => { - if (!this._viewsPerPlugin.get(e.id)) return; - const i = this._getPluginViewById(e, t); - i && e.removeView(i); - }); - } - removeViewById(t, e) { - this._unassignViewFromPlugin(t, e), this._views = this._views.filter((i) => i.id !== t); - } - _unassignViewFromPlugin(t, e) { - const i = this._viewsPerPlugin.get(e); - if (!i) return; - const s = i.indexOf(t); - s !== -1 && i.splice(s, 1); - } - getViewById(t) { - return this._views.find((e) => e.id === t); - } - getViewsById(t) { - return this._views.filter((e) => t.includes(e.id)); - } - _getPluginById(t) { - return this._plugins.find((e) => e.id === t); - } - _getPluginViewById(t, e) { - return this.getViewsForPlugin(t).find((i) => i.id === e); - } - destroy(t, e) { - if (!t) { - this._destroyAll(e); - return; - } - let i = []; - if (t && t.length > 0) { - const s = this.getPluginByName(t); - if (s) { - const n = (this._eventPluginsPerPlugin.get(s.id) || []).map((a) => this._getPluginById(a)).filter((a) => typeof a < "u"); - i.push(s), i.push(...n); - } - } else - i = this._plugins; - i.forEach((s) => { - this._destroyPlugin(s); - }), requestAnimationFrame(() => { - e == null || e(); - }); - } - _destroyPlugin(t) { - const e = this.getViewsForPlugin(t); - e.forEach((i) => { - i.layoutId && this._layoutIdToViewMap.delete(i.layoutId), i.destroy(); - }), this._views = this._views.filter( - (i) => !e.find((s) => s.id === i.id) - ), this._viewsPerPlugin.delete(t.id), this._plugins = this._plugins.filter((i) => i.id !== t.id); - } - _destroyAll(t) { - this._views.forEach((e) => e.destroy()), requestAnimationFrame(() => { - this._plugins = [], this._views = [], this._viewsPerPlugin.clear(), this._viewsToBeCreated = [], this._viewsToBeRemoved = [], this._viewsCreatedInPreviousFrame = [], this._layoutIdToViewMap.clear(), this._eventPluginsPerPlugin.clear(), t == null || t(); - }); - } - reset(t, e) { - let i = []; - if (t && t.length > 0) { - const s = this.getPluginByName(t); - if (s) { - const n = (this._eventPluginsPerPlugin.get(s.id) || []).map((a) => this._getPluginById(a)).filter((a) => typeof a < "u"); - i.push(s), i.push(...n); - } - } else - i = this._plugins; - requestAnimationFrame(() => { - i.forEach((s) => { - this._resetPlugin(s); - }), requestAnimationFrame(() => { - e == null || e(); - }); - }); - } - _resetPlugin(t) { - const e = t.config, i = t.pluginFactory, s = t.internalBusEvent, n = !t.isRenderable(), a = this.getViewsForPlugin(t); - a.forEach((l) => { - l.layoutId && this._layoutIdToViewMap.delete(l.layoutId), l.destroy(); - }), this._views = this._views.filter( - (l) => !a.find((h) => h.id === l.id) - ), this._viewsPerPlugin.delete(t.id), this._plugins = this._plugins.filter((l) => l.id !== t.id), n || requestAnimationFrame(() => { - this.createPlugin( - i, - this._eventBus, - e - ).setInternalEventBus(s); - }); - } - queueNodeToBeCreated(t) { - this._viewsToBeCreated.push(t); - } - queueNodeToBeRemoved(t) { - this._viewsToBeRemoved.push(t); - } - notifyPluginAboutDataChange(t) { - const e = this._plugins.filter( - (i) => i.id === t.pluginId - ); - !e || !e.length || e.forEach((i) => { - i.notifyAboutDataChanged({ - dataName: t.dataName, - dataValue: t.dataValue, - viewName: t.viewName - }); - }); - } - getPlugins() { - return this._plugins; - } - getRenderablePlugins() { - function t(e) { - return e.isRenderable(); - } - return this._plugins.filter(t); - } - getPluginByName(t, e) { - return this._plugins.find((i) => e ? i.pluginKey === e && i.pluginName === t : i.pluginName === t); - } - getPluginsByName(t, e) { - return this._plugins.filter((i) => e ? i.pluginKey === e && i.pluginName === t : i.pluginName === t); - } - hasPlugin(t) { - return t.pluginName ? !!this.getPluginByName(t.pluginName) : !1; - } - createPlugin(t, e, i = {}, s = !1) { - if (!t.pluginName) - throw Error( - `Plugin ${t.name} must contain a pluginName field` - ); - let n = []; - if (t.scope) { - const h = s ? `[data-vel-plugin=${t.pluginName}][data-vel-view=${t.scope}]:not([data-vel-plugin-id])` : `[data-vel-plugin=${t.pluginName}][data-vel-view=${t.scope}]`, g = document.querySelectorAll(h); - this._pluginNameToPluginFactoryMap.has(t.pluginName) || this._pluginNameToPluginFactoryMap.set( - t.pluginName, - t - ), this._pluginNameToPluginConfigMap.has(t.pluginName) || this._pluginNameToPluginConfigMap.set(t.pluginName, i), g ? n = Array.from(g) : n = [document.documentElement]; - } else - n = [document.documentElement]; - const a = n.map((h) => { - const g = h.dataset.velPluginKey, c = dt( - t, - this, - e, - this._appEventBus, - i, - g - ); - this._plugins.push(c); - let p = []; - h !== document.documentElement && p.push(h); - const f = h.querySelectorAll( - `[data-vel-plugin=${c.pluginName}]` - ); - p = [...p, ...f]; - const V = p.filter((w) => { - if (this._isElementIgnored(w)) - return !1; - if (!w.parentElement) - return !0; - const b = this._getPluginNameForElement(w.parentElement); - return !(b && b.length > 0); - }); - return V.length && V.forEach((w) => { - const b = w.dataset.velView; - if (!b) return; - const T = this._createNewView(w, b, c); - c.notifyAboutViewAdded(T); - }), c; - }); - if (a && a.length > 0) - return a[0]; - const l = dt( - t, - this, - e, - this._appEventBus, - i - ); - return t.scope || console.log( - `%c WARNING: The plugin "${l.pluginName}" is created but there are no elements using it on the page`, - "background: #885500" - ), l; - } - updatePlugin(t, e, i = {}) { - return this.createPlugin(t, e, i, !0); - } - getViews() { - return this._views; - } - createView(t, e, i) { - const s = new We(t, e, this, i); - return this._views.push(s), this._viewsCreatedInPreviousFrame.push(s), s; - } - _isElementIgnored(t) { - return t.closest("[data-vel-ignore]"); - } - assignViewToPlugin(t, e) { - this._viewsPerPlugin.has(e.id) || this._viewsPerPlugin.set(e.id, []); - const i = this._viewsPerPlugin.get(e.id); - i.includes(t.id) || i.push(t.id); - } - getViewsForPlugin(t) { - const e = this._viewsPerPlugin.get(t.id); - return e ? e.map((i) => this._views.find((s) => s.id === i)).filter((i) => !!i) : []; - } - getViewsByNameForPlugin(t, e) { - return this.getViewsForPlugin(t).filter( - (i) => i.name === e - ); - } -} -class zt { - constructor(t) { - o(this, "pluginApi"), this.pluginApi = t.pluginApi; - } -} -class Dt { - constructor(t) { - o(this, "pluginApi"), this.pluginApi = t.pluginApi; - } -} -class Tt { - constructor() { - o(this, "previousTime", 0), o(this, "registry"), o(this, "eventBus"), o(this, "appEventBus"), this.eventBus = new _t(), this.appEventBus = new _t(), this.registry = new qe(this.appEventBus, this.eventBus), new se(this.eventBus); - } - static create() { - return new Tt(); - } - addPlugin(t, e = {}) { - this.registry.hasPlugin(t) || this.registry.createPlugin(t, this.eventBus, e); - } - updatePlugin(t, e = {}) { - this.registry.hasPlugin(t) && this.registry.updatePlugin(t, this.eventBus, e); - } - reset(t, e) { - this.registry.reset(t, e); - } - destroy(t, e) { - this.registry.destroy(t, e); - } - getPlugin(t, e) { - let i = typeof t == "string" ? t : t.pluginName; - const s = this.registry.getPluginByName(i, e); - if (!s) - throw new Error( - `You can't call getPlugin for ${i} with key: ${e} because it does not exist in your app` - ); - return s.api; - } - getPlugins(t, e) { - let i = typeof t == "string" ? t : t.pluginName; - const s = this.registry.getPluginsByName(i, e); - if (s.length === 0) - throw new Error( - `You can't call getPlugins for ${i} with key: ${e} because they don't exist in your app` - ); - return s.map((n) => n.api); - } - onPluginEvent(t, e, i, s) { - requestAnimationFrame(() => { - const n = this.registry.getPluginByName( - t.pluginName, - s - ); - n && n.on(e, i); - }); - } - removePluginEventListener(t, e, i) { - const s = this.registry.getPluginByName(t.pluginName); - s && s.removeListener(e, i); - } - run() { - document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", this.start.bind(this)) : this.start(); - } - start() { - this.setup(), requestAnimationFrame(this.tick.bind(this)); - } - setup() { - this.listenToNativeEvents(), this.subscribeToEvents(); - } - listenToNativeEvents() { - document.addEventListener("click", (t) => { - this.eventBus.emitEvent(ft, { - x: t.clientX, - y: t.clientY, - target: t.target - }); - }), document.addEventListener("pointermove", (t) => { - this.eventBus.emitEvent(lt, { - x: t.clientX, - y: t.clientY, - target: t.target - }); - }), document.addEventListener("pointerdown", (t) => { - this.eventBus.emitEvent(ht, { - x: t.clientX, - y: t.clientY, - target: t.target - }); - }), document.addEventListener("pointerup", (t) => { - this.eventBus.emitEvent(ut, { - x: t.clientX, - y: t.clientY, - target: t.target - }); - }); - } - tick(t) { - let e = (t - this.previousTime) / 1e3; - e > 0.016 && (e = 1 / 60), this.previousTime = t, this.eventBus.reset(), this.subscribeToEvents(), this.read(), this.update(t, e), this.render(), requestAnimationFrame(this.tick.bind(this)); - } - subscribeToEvents() { - this.eventBus.subscribeToEvent(st, this.onNodeAdded.bind(this)), this.eventBus.subscribeToEvent( - pt, - this.onNodeRemoved.bind(this) - ), this.eventBus.subscribeToEvent( - $t, - this.onDataChanged.bind(this) - ), this.registry.getPlugins().forEach((t) => { - t.subscribeToEvents(this.eventBus); - }); - } - onNodeAdded({ node: t }) { - this.registry.queueNodeToBeCreated(t); - } - onNodeRemoved({ node: t }) { - this.registry.queueNodeToBeRemoved(t); - } - onDataChanged(t) { - this.registry.notifyPluginAboutDataChange(t); - } - read() { - this.registry.getViews().forEach((t) => { - t.read(); - }); - } - update(t, e) { - this.registry.update(), this.registry.getPlugins().slice().reverse().forEach((i) => { - i.init(); - }), this.registry.getRenderablePlugins().forEach((i) => { - i.update(t, e); - }), this.registry.getViews().forEach((i) => { - i.update(t, e); - }), this.registry.getViews().forEach((i) => { - i._updatePreviousRect(); - }); - } - render() { - this.registry.getRenderablePlugins().forEach((t) => { - t.render(); - }), this.registry.getViews().forEach((t) => { - t.render(); - }); - } -} -function He() { - return Tt.create(); -} -class Ht { - constructor(t) { - o(this, "view"), o(this, "previousX"), o(this, "previousY"), o(this, "x"), o(this, "y"), o(this, "pointerX"), o(this, "pointerY"), o(this, "isDragging"), o(this, "target"), o(this, "directions", []), o(this, "width"), o(this, "height"), o(this, "distance"), o(this, "stopped"), o(this, "hasMoved"), this.props = t, this.previousX = t.previousX, this.previousY = t.previousY, this.x = t.x, this.y = t.y, this.pointerX = t.pointerX, this.pointerY = t.pointerY, this.width = t.width, this.height = t.height, this.distance = t.distance, this.view = t.view, this.isDragging = t.isDragging, this.stopped = t.stopped, this.target = t.target, this.directions = t.directions, this.hasMoved = t.hasMoved; - } -} -class Ut extends wt { - constructor() { - super(...arguments), o(this, "_pointerX", 0), o(this, "_pointerY", 0), o(this, "_initialPointer", new u(0, 0)), o(this, "_initialPointerPerView", /* @__PURE__ */ new Map()), o(this, "_pointerDownPerView", /* @__PURE__ */ new Map()), o(this, "_viewPointerPositionLog", /* @__PURE__ */ new Map()), o(this, "_stopTimer", 0); - } - setup() { - document.addEventListener("selectstart", this.onSelect.bind(this)); - } - onSelect(t) { - this._isDragging && t.preventDefault(); - } - get _isDragging() { - return Array.from(this._pointerDownPerView.values()).some( - (t) => !!t - ); - } - subscribeToEvents(t) { - t.subscribeToEvent(ht, ({ x: e, y: i }) => { - this._initialPointer = new u(e, i), this.getViews().forEach((s) => { - this._pointerDownPerView.set(s.id, s.intersects(e, i)); - const n = s.isLayoutTransitionEnabled ? s.position.initialX : s.position.x, a = s.isLayoutTransitionEnabled ? s.position.initialY : s.position.y, l = new u(e - n, i - a); - this._pointerX = e, this._pointerY = i, this._initialPointerPerView.set(s.id, l); - }); - }), t.subscribeToEvent(ut, () => { - this.getViews().forEach((e) => { - this._pointerDownPerView.get(e.id) && this._initialPointerPerView.get(e.id) && (this._pointerDownPerView.set(e.id, !1), this._emitEvent(e, [])); - }); - }), t.subscribeToEvent(lt, ({ x: e, y: i }) => { - this._pointerX = e, this._pointerY = i, this.getViews().forEach((s) => { - if (this._pointerDownPerView.get(s.id) && this._initialPointerPerView.get(s.id)) { - this._viewPointerPositionLog.has(s.id) || this._viewPointerPositionLog.set(s.id, []); - const n = new u(e, i), a = this._viewPointerPositionLog.get(s.id); - a && a.push(new u(e, i)); - const l = a && a.length >= 2 ? a[a.length - 2] : n.clone(), h = this._calculateDirections( - l, - n - ); - this._emitEvent(s, h), clearTimeout(this._stopTimer), this._stopTimer = setTimeout(() => { - this._pointerDownPerView.get(s.id) === !0 && this._emitEvent(s, h, !0); - }, 120); - } - }); - }); - } - _emitEvent(t, e, i = !1) { - const s = this._viewPointerPositionLog.get(t.id), n = !(typeof s > "u" || s.length <= 1), a = s && s.length >= 2 ? s[s.length - 2] : null, l = this._pointerX - this._initialPointerPerView.get(t.id).x, h = this._pointerY - this._initialPointerPerView.get(t.id).y, g = this._pointerX, c = this._pointerY, p = a ? a.x - this._initialPointerPerView.get(t.id).x : l, f = a ? a.y - this._initialPointerPerView.get(t.id).y : h, V = this._pointerY - this._initialPointer.y, w = this._pointerX - this._initialPointer.x, b = ce(this._initialPointer, { - x: this._pointerX, - y: this._pointerY - }), T = this._pointerDownPerView.get(t.id) === !0; - T || this._viewPointerPositionLog.clear(); - const C = { - view: t, - target: t.element, - previousX: p, - previousY: f, - x: l, - y: h, - pointerX: g, - pointerY: c, - distance: b, - width: w, - height: V, - isDragging: T, - directions: e, - stopped: i, - hasMoved: n - }; - this.emit(Ht, C); - } - _calculateDirections(t, e) { - const i = { - up: u.sub(new u(t.x, t.y - 1), t), - down: u.sub(new u(t.x, t.y + 1), t), - left: u.sub(new u(t.x - 1, t.y), t), - right: u.sub(new u(t.x + 1, t.y), t) - }, s = u.sub(e, t).unitVector; - return [ - { direction: "up", projection: s.dot(i.up) }, - { - direction: "down", - projection: s.dot(i.down) - }, - { - direction: "left", - projection: s.dot(i.left) - }, - { - direction: "right", - projection: s.dot(i.right) - } - ].filter( - (n) => n.projection > 0 - ).map( - (n) => n.direction - ); - } -} -o(Ut, "pluginName", "DragEventPlugin"); -class Ue { - constructor(t) { - o(this, "view"), o(this, "direction"), this.props = t, this.view = t.view, this.direction = t.direction; - } -} -class Ye extends wt { - constructor() { - super(...arguments), o(this, "_viewIsPointerDownMap", /* @__PURE__ */ new Map()), o(this, "_viewPointerPositionLog", /* @__PURE__ */ new Map()), o(this, "_targetPerView", /* @__PURE__ */ new Map()); - } - subscribeToEvents(t) { - t.subscribeToEvent(ht, ({ x: e, y: i, target: s }) => { - this.getViews().forEach((n) => { - this._targetPerView.set(n.id, s), n.intersects(e, i) && this._viewIsPointerDownMap.set(n.id, !0); - }); - }), t.subscribeToEvent(lt, ({ x: e, y: i }) => { - this.getViews().forEach((s) => { - this._viewIsPointerDownMap.get(s.id) && (this._viewPointerPositionLog.has(s.id) || this._viewPointerPositionLog.set(s.id, []), this._viewPointerPositionLog.get(s.id).push(new u(e, i))); - }); - }), t.subscribeToEvent(ut, ({ x: e, y: i }) => { - this.getViews().forEach((n) => { - if (!this._viewIsPointerDownMap.get(n.id) || !this._viewPointerPositionLog.has(n.id)) - return; - const a = new u(e, i), l = this._viewPointerPositionLog.get(n.id), h = l[l.length - 2] || a.clone(), g = this._targetPerView.get(n.id), c = s(h, a); - g && n.hasElement(g) && c.hasSwiped && this.emit(Ue, { - view: n, - direction: c.direction - }), this._viewPointerPositionLog.set(n.id, []), this._viewIsPointerDownMap.set(n.id, !1); - }); - function s(n, a) { - const l = { - up: u.sub(new u(n.x, n.y - 1), n), - down: u.sub(new u(n.x, n.y + 1), n), - left: u.sub(new u(n.x - 1, n.y), n), - right: u.sub(new u(n.x + 1, n.y), n) - }, h = u.sub(a, n).unitVector, g = [ - "up", - "down", - "left", - "right" - ], c = [ - h.dot(l.up), - h.dot(l.down), - h.dot(l.left), - h.dot(l.right) - ], p = Math.max(...c), f = c.indexOf(p), V = g[f], w = u.sub(a, n).magnitude; - return { - hasSwiped: h.dot(l[V]) * w > 30, - direction: V - }; - } - }); - } -} -o(Ye, "pluginName", "SwipeEventPlugin"); -class Xe { - constructor(t) { - o(this, "view"), this.props = t, this.view = t.view; - } -} -class je extends wt { - subscribeToEvents(t) { - t.subscribeToEvent(ft, ({ x: e, y: i, target: s }) => { - this.getViews().forEach((n) => { - const a = s, l = n.element === a || n.element.contains(a); - n.intersects(e, i) && l && this.emit(Xe, { - view: n - }); - }); - }); - } -} -o(je, "pluginName", "ClickEventPlugin"); -const Ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ - __proto__: null, - PointerClickEvent: ft, - PointerDownEvent: ht, - PointerMoveEvent: lt, - PointerUpEvent: ut -}, Symbol.toStringTag, { value: "Module" })); -function Ge(r) { - let t = Yt(r) || window; - t === document.body && (t = window); - let e = 0, i = 0, s = !1, n = () => { - }; - return t.addEventListener("scroll", () => { - s && n(); - }), { - container: t, - onScroll(a) { - n = a; - }, - startScrollTracking() { - s || (e = t instanceof Element ? t.scrollTop : t.scrollY, i = t instanceof Element ? t.scrollLeft : t.scrollX, s = !0); - }, - getScrollOffset() { - const a = t instanceof Element ? t.scrollTop : t.scrollY; - return { - x: (t instanceof Element ? t.scrollLeft : t.scrollX) - i, - y: a - e - }; - }, - endScrollTracking() { - e = 0, i = 0, s = !1; - }, - width: t instanceof Element ? t.clientWidth : t.innerWidth, - height: t instanceof Element ? t.clientHeight : t.innerHeight - }; -} -function Yt(r) { - const e = r instanceof HTMLElement && window.getComputedStyle(r).overflowY, i = e !== "visible" && e !== "hidden"; - if (r) { - if (i && r.scrollHeight >= r.clientHeight) - return r; - } else return null; - return Yt(r.parentNode) || document.body; -} -class nt { - constructor(t) { - P(this, "data"); - this.data = t.data; - } -} -class Xt { - constructor(t) { - P(this, "data"); - P(this, "hasChanged"); - this.data = t.data, this.hasChanged = t.hasChanged; - } -} -class jt { -} -class Kt { - constructor(t) { - P(this, "data"); - this.data = t.data; - } -} -function J(r) { - return { - map: new Map(r), - array: Array.from(r).map(([e, i]) => ({ slotId: e, itemId: i })), - object: Array.from(r).reduce( - (e, [i, s]) => (e[i] = s, e), - {} - ) - }; -} -function Ze(r) { - if (r.map) - return { - map: new Map(r.map), - array: Array.from(r.map).map(([e, i]) => ({ - slotId: e, - itemId: i - })), - object: Array.from(r.map).reduce( - (e, [i, s]) => (e[i] = s, e), - {} - ) - }; - if (r.object) { - const t = { ...r.object }; - return { - map: new Map(Object.entries(t)), - array: Object.entries(t).map(([e, i]) => ({ - slotId: e, - itemId: i - })), - object: t - }; - } else { - const t = [...r.array]; - return { - map: new Map(t.map(({ slotId: e, itemId: i }) => [e, i])), - array: t, - object: t.reduce((e, { slotId: i, itemId: s }) => (e[i] = s, e), {}) - }; - } -} -const N = (r) => { - const t = r.useEventPlugin(Ut); - t.on(Ht, $); - const e = 20, i = 100; - let s, n, a, l, h, g = null, c = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), f, V, w = null, b = null, T, C, H = !0, R, Q, tt, A, L = !1, x = !1, I = () => { - }, O = !1, S = 0, z = 0; - r.api({ - setEnabled(d) { - H = d; - }, - setData(d) { - const m = Ze(d); - c = new Map(m.map), p = new Map(c); - }, - setAutoScrollOnDrag(d) { - O = d; - } - }); - function D() { - return { - animation: s.data.configAnimation, - continuousMode: typeof s.data.configContinuousMode < "u", - manualSwap: typeof s.data.configManualSwap < "u", - swapMode: s.data.configSwapMode, - autoScrollOnDrag: O - }; - } - function U() { - const d = D().animation; - return d === "dynamic" ? { - animator: "dynamic", - config: {} - } : d === "spring" ? { - animator: "spring", - config: { - damping: 0.7, - stiffness: 0.62 - } - } : d === "none" ? { - animator: "instant", - config: {} - } : { - animator: "instant", - config: {} - }; - } - function Y(d) { - return () => { - c = d, p = new Map(c); - }; - } - r.setup(() => { - s = r.getView("root"), a = r.getViews("slot"), l = r.getViews("item"), n = Ge(l[0].element), n.onScroll(() => { - M(); - }), Q = D().continuousMode, tt = D().manualSwap, a.forEach((d) => { - X(d); - }), B(), p = new Map(c), requestAnimationFrame(() => { - r.emit(Kt, { data: J(c) }); - }); - }); - function X(d) { - const m = d.getChild("item"); - m && et(m), c.set( - d.element.dataset.swapySlot, - m ? m.element.dataset.swapyItem : null - ); - } - function et(d) { - const m = U(); - d.styles.position = "relative", d.styles.userSelect = "none", d.styles.webkitUserSelect = "none", d.position.setAnimator(m.animator, m.config), d.scale.setAnimator(m.animator, m.config), d.layoutTransition(!0), requestAnimationFrame(() => { - const v = d.getChild("handle"); - v ? (t.addView(v), v.styles.touchAction = "none") : (t.addView(d), d.styles.touchAction = "none"); - }); - } - r.onViewAdded((d) => { - if (r.initialized) - if (d.name === "item") { - l = r.getViews("item"); - const m = d.getParent("slot"); - X(m), B(), p = new Map(c), r.emit(nt, { data: J(c) }); - } else d.name === "slot" && (a = r.getViews("slot")); - }); - function B() { - const d = U(); - r.getViews("root-child").forEach((v) => { - v.position.setAnimator(d.animator, d.config), v.scale.setAnimator(d.animator, d.config), v.layoutTransition(!0); - }); - } - function M() { - if (!R) return; - if (!f || !V) { - const K = h.getScroll(); - f = R.pointerX - h.position.x + K.x, V = R.pointerY - h.position.y + K.y; - } - (!T || !C) && (T = h.size.width, C = h.size.height); - const d = h.size.width / T, m = h.size.height / C, v = f * (d - 1), j = V * (m - 1), { x: y, y: W } = n.getScrollOffset(); - h.position.set( - { - x: R.x - v - (w || 0) + y, - y: R.y - j - (b || 0) + W - }, - h.scale.x !== 1 || h.scale.y !== 1 - ); - } - r.subscribeToEvents((d) => { - d.subscribeToEvent(Ke.PointerMoveEvent, ({ x: m, y: v }) => { - n && (n.height - v <= i ? S = Math.max( - 0, - e * (1 - Math.min(n.height - v, i) / i) - ) : v <= i ? S = -1 * Math.max( - 0, - e * (1 - Math.min(v, i) / i) - ) : S = 0, n.width - m <= i ? z = Math.max( - 0, - e * (1 - Math.min(n.width - m, i) / i) - ) : m <= i ? z = -1 * Math.max( - 0, - e * (1 - Math.min(m, i) / i) - ) : z = 0); - }); - }), r.update(() => { - R != null && R.isDragging && O && n.container.scrollBy({ top: S, left: z }); - }); - function $(d) { - if (!H || !d.hasMoved) return; - const m = D().swapMode, v = d.view.name === "handle"; - if (h = v ? d.view.getParent("item") : d.view, A || (A = h.getParent("slot")), w === null && b === null) { - const y = v ? d.view.position.initialX - d.view.position.x : 0, W = v ? d.view.position.initialY - d.view.position.y : 0; - w = d.view.position.x - h.position.x - y, b = d.view.position.y - h.position.y - W; - } - const j = a.some( - (y) => y.intersects(d.pointerX, d.pointerY) - ); - d.isDragging ? (n.startScrollTracking(), L || (L = !0, r.emit(jt, {})), g === null && (g = new Map(c)), R = d, M(), a.forEach((y) => { - var Ct; - if (!y.intersects(d.pointerX, d.pointerY)) { - y !== A && y.element.removeAttribute("data-swapy-highlighted"); - return; - } - if (typeof y.element.dataset.swapyHighlighted > "u" && (y.element.dataset.swapyHighlighted = ""), !A || (m === "stop" || m !== "drop" && !Q) && !d.stopped) - return; - const W = y.element.dataset.swapySlot, K = (Ct = y.getChild("item")) == null ? void 0 : Ct.element.dataset.swapyItem, ct = A.element.dataset.swapySlot, St = h.element.dataset.swapyItem; - if (!W || !ct || !St) - return; - const q = new Map(c); - q.set(W, St), K ? q.set(ct, K) : q.set(ct, null), I = Y(new Map(q)), gt(q, p) || (!tt && m !== "drop" && I(), A = null, m !== "drop" && r.emit(nt, { data: J(q) })); - }), l.forEach((y) => { - y.styles.zIndex = y === h ? "2" : ""; - })) : (a.forEach((y) => { - y.element.removeAttribute("data-swapy-highlighted"); - }), h.position.reset(), A = null, f = null, V = null, T = null, C = null, R = null, w = null, b = null, L = !1, m === "drop" && (j || (I = Y(new Map(c))), I(), r.emit(nt, { data: J(c) })), I = () => { - }, x = !gt(c, g), r.emit(Xt, { - data: J(c), - hasChanged: x - }), x = !1, g = null, n.endScrollTracking()), requestAnimationFrame(() => { - M(); - }); - } -}; -N.pluginName = "Swapy"; -N.scope = "root"; -let F; -function Je() { - return F ? (F.updatePlugin(N), F) : (F = He(), F.addPlugin(N), F.run(), F); -} -const Qe = { - animation: "dynamic", - continuousMode: !0, - manualSwap: !1, - swapMode: "hover", - autoScrollOnDrag: !1 -}; -function ti(r) { - let t = !0; - const e = r.querySelectorAll("[data-swapy-slot]"); - return e.length === 0 && (console.error("There are no slots defined in your root element:", r), t = !1), e.forEach((i) => { - const s = i, n = s.dataset.swapySlot; - (!n || n.length === 0) && (console.error(i, "does not contain a slotId using data-swapy-slot"), t = !1); - const a = s.children; - a.length > 1 && (console.error( - "slot:", - `"${n}"`, - "cannot contain more than one element" - ), t = !1); - const l = a[0]; - l && (!l.dataset.swapyItem || l.dataset.swapyItem.length === 0) && (console.error( - "slot:", - `"${n}"`, - "does not contain an element with item id using data-swapy-item" - ), t = !1); - }), t; -} -function ei(r, t = {}) { - const e = Qt(); - return r.dataset.velPluginKey = e, r.dataset.velPlugin = "Swapy", r.dataset.velView = "root", r.dataset.velDataConfigAnimation = t.animation, r.dataset.velDataConfigSwapMode = t.swapMode, t.continuousMode && (r.dataset.velDataConfigContinuousMode = "true"), t.manualSwap && (r.dataset.velDataConfigManualSwap = "true"), Array.from( - r.querySelectorAll("[data-swapy-slot]") - ).forEach((l) => { - l.dataset.velView = "slot"; - }), Array.from( - r.querySelectorAll("[data-swapy-item]") - ).forEach((l) => { - l.dataset.velView = "item", l.dataset.velLayoutId = l.dataset.swapyItem; - const h = l.querySelector("[data-swapy-handle]"); - h && (h.dataset.velView = "handle"); - }), Array.from( - r.querySelectorAll("[data-swapy-text]") - ).forEach((l) => { - l.dataset.velLayoutPosition = ""; - }), Array.from( - r.querySelectorAll("[data-swapy-exclude]") - ).forEach((l) => { - l.dataset.velIgnore = ""; - }), e; -} -function ii(r) { - const t = Array.from( - r.querySelectorAll("[data-swapy-slot]:not([data-vel-view])") - ); - t.forEach((i) => { - i.dataset.velView = "slot"; - }); - const e = Array.from( - r.querySelectorAll("[data-swapy-item]:not([data-vel-view])") - ); - return e.forEach((i) => { - i.dataset.velView = "item", i.dataset.velLayoutId = i.dataset.swapyItem; - const s = i.querySelector("[data-swapy-handle]"); - s && (s.dataset.velView = "handle"), Array.from( - i.querySelectorAll("[data-swapy-text]") - ).forEach((l) => { - l.dataset.velLayoutPosition = ""; - }), Array.from( - i.querySelectorAll("[data-swapy-exclude]") - ).forEach((l) => { - l.dataset.velIgnore = ""; - }); - }), e.length > 0 || t.length > 0; -} -function ri(r, t = {}) { - if (!r) - throw new Error( - "Cannot create a Swapy instance because the element you provided does not exist on the page!" - ); - const e = { ...Qe, ...t }, i = r; - if (!ti(i)) - throw new Error( - "Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!" - ); - const s = ei(i, e), n = new si(i, s, e); - return { - onSwap(a) { - n.setSwapCallback(a); - }, - onSwapEnd(a) { - n.setSwapEndCallback(a); - }, - onSwapStart(a) { - n.setSwapStartCallback(a); - }, - enable(a) { - n.setEnabled(a); - }, - destroy() { - n.destroy(); - }, - setData(a) { - n.setData(a); - } - }; -} -class si { - constructor(t, e, i) { - P(this, "_rootEl"); - P(this, "_veloxiApp"); - P(this, "_slotElMap"); - P(this, "_itemElMap"); - P(this, "_swapCallback"); - P(this, "_swapEndCallback"); - P(this, "_swapStartCallback"); - P(this, "_previousMap"); - P(this, "_pluginKey"); - this._rootEl = t, this._veloxiApp = Je(), this._slotElMap = this._createSlotElMap(), this._itemElMap = this._createItemElMap(), this.setAutoScrollOnDrag(i.autoScrollOnDrag), this._pluginKey = e, this._veloxiApp.onPluginEvent( - N, - Kt, - ({ data: s }) => { - this._previousMap = s.map; - }, - e - ), this._veloxiApp.onPluginEvent( - N, - nt, - (s) => { - var n; - this._previousMap && gt(this._previousMap, s.data.map) || (i.manualSwap || this._applyOrder(s.data.map), this._previousMap = s.data.map, (n = this._swapCallback) == null || n.call(this, s)); - }, - e - ), this._veloxiApp.onPluginEvent( - N, - Xt, - (s) => { - var n; - (n = this._swapEndCallback) == null || n.call(this, s); - }, - e - ), this._veloxiApp.onPluginEvent( - N, - jt, - () => { - var s; - (s = this._swapStartCallback) == null || s.call(this); - }, - e - ), this.setupMutationObserver(); - } - setupMutationObserver() { - new MutationObserver((e) => { - e.some((i) => i.type === "childList") && ii(this._rootEl) && (this._slotElMap = this._createSlotElMap(), this._itemElMap = this._createItemElMap()); - }).observe(this._rootEl, { - childList: !0, - subtree: !0 - }); - } - setData(t) { - try { - this._veloxiApp.getPlugin( - "Swapy", - this._pluginKey - ).setData(t); - } catch { - } - } - destroy() { - this._veloxiApp.destroy("Swapy"); - } - setEnabled(t) { - requestAnimationFrame(() => { - try { - this._veloxiApp.getPlugin( - "Swapy", - this._pluginKey - ).setEnabled(t); - } catch { - } - }); - } - setAutoScrollOnDrag(t) { - requestAnimationFrame(() => { - try { - this._veloxiApp.getPlugin( - "Swapy", - this._pluginKey - ).setAutoScrollOnDrag(t); - } catch { - } - }); - } - setSwapCallback(t) { - this._swapCallback = t; - } - setSwapEndCallback(t) { - this._swapEndCallback = t; - } - setSwapStartCallback(t) { - this._swapStartCallback = t; - } - _applyOrder(t) { - Array.from(t.keys()).forEach((e) => { - var a; - if (t.get(e) === ((a = this._previousMap) == null ? void 0 : a.get(e))) - return; - const i = t.get(e); - if (!i) return; - const s = this._slotElMap.get(e), n = this._itemElMap.get(i); - !s || !n || (s.innerHTML = "", s.appendChild(n)); - }); - } - _createSlotElMap() { - return Array.from( - this._rootEl.querySelectorAll("[data-swapy-slot]") - ).reduce((t, e) => (t.set(e.dataset.swapySlot, e), t), /* @__PURE__ */ new Map()); - } - _createItemElMap() { - return Array.from( - this._rootEl.querySelectorAll("[data-swapy-item]") - ).reduce((t, e) => (t.set(e.dataset.swapyItem, e), t), /* @__PURE__ */ new Map()); - } -} -export { - ri as createSwapy -}; diff --git a/dist/swapy.min.js b/dist/swapy.min.js deleted file mode 100644 index 79b44e2..0000000 --- a/dist/swapy.min.js +++ /dev/null @@ -1,3 +0,0 @@ -(function(T,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(T=typeof globalThis<"u"?globalThis:T||self,b(T.Swapy={}))})(this,function(T){"use strict";var ni=Object.defineProperty;var ri=(T,b,D)=>b in T?ni(T,b,{enumerable:!0,configurable:!0,writable:!0,value:D}):T[b]=D;var R=(T,b,D)=>ri(T,typeof b!="symbol"?b+"":b,D);function b(r,t){if(r.size!==t.size)return!1;for(let[e,i]of r)if(!t.has(e)||t.get(e)!==i)return!1;return!0}let D=0;function Jt(){return D+++""}var Qt=Object.defineProperty,te=(r,t,e)=>t in r?Qt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,a=(r,t,e)=>te(r,typeof t!="symbol"?t+"":t,e);class it{constructor(t){a(this,"x"),a(this,"y"),a(this,"target"),this.x=t.x,this.y=t.y,this.target=t.target}}class pt extends it{}class st extends it{}class nt extends it{}class rt extends it{}class Lt{constructor(t){a(this,"pluginId"),a(this,"pluginName"),a(this,"viewName"),a(this,"dataName"),a(this,"dataValue"),this.event=t,this.pluginId=t.pluginId,this.pluginName=t.pluginName,this.viewName=t.viewName,this.dataName=t.dataName,this.dataValue=t.dataValue}}function ee(r){return r.replace(/(?:^\w|[A-Z]|\b\w)/g,function(t,e){return e===0?t.toLowerCase():t.toUpperCase()}).replace(/\s+/g,"").replace(/-+/g,"")}function It(r){return r.split("").map((t,e)=>t.toUpperCase()===t?`${e!==0?"-":""}${t.toLowerCase()}`:t).join("")}class at{constructor(t){a(this,"node"),this.node=t.node}}class _t{constructor(t){a(this,"node"),this.node=t.node}}class ie{constructor(t){a(this,"_eventBus"),a(this,"_observer"),this._eventBus=t,this._observer=new MutationObserver(this._handler.bind(this)),this._observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0})}_handler(t){t.forEach(e=>{e.addedNodes.forEach(s=>{if(!(s instanceof HTMLElement)||s.dataset.velViewId||s.parentElement&&typeof s.parentElement.dataset.velAdded<"u")return;let n=s;if(s.dataset.velView||(n=s.querySelector("[data-vel-view][data-vel-plugin]")),!n)return;this._eventBus.emitEvent(at,{node:n});const o=n.querySelectorAll("[data-vel-plugin]");o.length&&o.forEach(l=>{this._eventBus.emitEvent(at,{node:l})})}),e.removedNodes.forEach(s=>{if(!(s instanceof HTMLElement)||typeof s.dataset.velProcessing<"u")return;const n=s.querySelectorAll("[data-vel-plugin]");n.length&&n.forEach(o=>{this._eventBus.emitEvent(_t,{node:o})}),this._eventBus.emitEvent(_t,{node:s})});const i=e.attributeName;if(i==="data-vel-view"&&this._eventBus.emitEvent(at,{node:e.target}),i&&/data-vel-data-.+/gi.test(i)){const s=e.target,n=s.dataset.velPluginId||"",o=s.dataset.velPlugin||"",l=s.dataset.velView||"",h=s.getAttribute(i);if(h&&h!==e.oldValue){const g=ee(i.replace("data-vel-data-",""));this._eventBus.emitEvent(Lt,{pluginId:n,pluginName:o,viewName:l,dataName:g,dataValue:h})}}})}}class se{execute(t){this.call(t)}}class Mt extends se{constructor(t){super(),a(this,"_handler"),this._handler=t}getHandler(){return this._handler}call(t){this._handler(t)}}class mt{constructor(){a(this,"_listeners",new Map),a(this,"_keyedListeners",new Map)}subscribeToEvent(t,e,i){if(i){this._subscribeToKeyedEvent(t,e,i);return}let s=this._listeners.get(t);s||(s=[],this._listeners.set(t,s)),s.push(new Mt(e))}removeEventListener(t,e,i){if(i){this._removeKeyedEventListener(t,e,i);return}let s=this._listeners.get(t);s&&(s=s.filter(n=>n.getHandler()!==e),this._listeners.set(t,s))}_subscribeToKeyedEvent(t,e,i){let s=this._keyedListeners.get(t);s||(s=new Map,this._keyedListeners.set(t,s));let n=s.get(i);n||(n=[],s.set(i,n)),n.push(new Mt(e))}_removeKeyedEventListener(t,e,i){let s=this._keyedListeners.get(t);if(!s)return;let n=s.get(i);n&&(n=n.filter(o=>o.getHandler()!==e),s.set(i,n))}emitEvent(t,e,i){if(i){this._emitKeyedEvent(t,e,i);return}const s=this._listeners.get(t);s&&s.forEach(n=>{n.execute(e)})}_emitKeyedEvent(t,e,i){const s=this._keyedListeners.get(t);if(!s)return;const n=s.get(i);n&&n.forEach(o=>{o.execute(e)})}_convertListener(t){return e=>t(e)}subscribeToPluginReadyEvent(t,e,i=!1){if(i){this.subscribeToEvent(qt,this._convertListener(t),e);return}this.subscribeToEvent(Wt,this._convertListener(t),e)}emitPluginReadyEvent(t,e,i=!1){if(i){this.emitEvent(qt,e,t);return}this.emitEvent(Wt,e,t)}reset(){this._listeners.clear()}}let ne=0;function Nt(){return ne+++""}class Bt{constructor(t,e,i,s,n,o,l){a(this,"_registry"),a(this,"_eventBus"),a(this,"_appEventBus"),a(this,"_internalEventBus"),a(this,"_initialized",!1),a(this,"_config"),a(this,"_pluginFactory"),a(this,"_pluginName"),a(this,"_id"),a(this,"_pluginKey"),a(this,"_layoutIdViewMapWaitingToEnter"),a(this,"_apiData"),a(this,"_isReady",!1),this._id=Nt(),this._pluginFactory=t,this._pluginName=e,this._registry=i,this._eventBus=s,this._appEventBus=n,this._internalEventBus=new mt,this._config=o,this._layoutIdViewMapWaitingToEnter=new Map,this._pluginKey=l,this._apiData={},this._appEventBus.subscribeToPluginReadyEvent(()=>{this._isReady=!0},this._pluginName,!0)}get api(){return this._apiData}_setApi(t){this._apiData=t}get pluginName(){return this._pluginName}get pluginFactory(){return this._pluginFactory}get pluginKey(){return this._pluginKey}get id(){return this._id}get config(){return{...this._config}}getViews(t){return t?this._registry.getViewsByNameForPlugin(this,t):this._registry.getViewsForPlugin(this)}getView(t){return t?this._registry.getViewsByNameForPlugin(this,t)[0]:this._registry.getViewsForPlugin(this)[0]}getViewById(t){return this._registry.getViewById(t)}addView(t){this._registry.assignViewToPlugin(t,this)}setInternalEventBus(t){this._internalEventBus=t}get internalBusEvent(){return this._internalEventBus}emit(t,e){this._internalEventBus.emitEvent(t,e,this.pluginKey)}on(t,e){this._internalEventBus.subscribeToEvent(t,e,this.pluginKey)}removeListener(t,e){this._internalEventBus.removeEventListener(t,e)}useEventPlugin(t,e={}){const i=this._registry.createPlugin(t,this._eventBus,e);return this._registry.associateEventPluginWithPlugin(this.id,i.id),i}notifyAboutDataChanged(t){this.onDataChanged(t)}onDataChanged(t){}removeView(t){t.onRemoveCallback?this._invokeRemoveCallback(t):this._deleteView(t),t.removeListeners(),this.onViewRemoved(t)}_invokeRemoveCallback(t){const e=this._createTemporaryView(t);requestAnimationFrame(()=>{var i;(i=e.onRemoveCallback)==null||i.call(e,e,()=>{var s,n;if((s=t.onAddCallbacks)!=null&&s.afterRemoved&&t.layoutId){const o=this._layoutIdViewMapWaitingToEnter.get(t.layoutId);(n=o==null?void 0:o.onAddCallbacks)==null||n.afterEnter(o),this._layoutIdViewMapWaitingToEnter.delete(t.layoutId)}this._deleteView(e,!0),t.removeListeners()}),setTimeout(()=>{e.element.parentElement&&(this._deleteView(e,!0),t.removeListeners())},1e4)})}_deleteView(t,e=!1){(e||!t.layoutId)&&(this._registry.removeViewById(t.id,this.id),t.element.remove(),t.destroy())}_createTemporaryView(t){const e=t.previousRect.viewportOffset,i=t.previousRect.size,s=t.rotation.degrees<0?0:Math.sin(t.rotation.radians)*i.height*t.scale.y,n=t.rotation.degrees>0?0:Math.sin(t.rotation.radians)*i.width*t.scale.y,o=t.element.cloneNode(!0);t.element.remove(),o.style.cssText="",o.style.position="absolute",o.style.left=`${e.left+s}px`,o.style.top=`${e.top-n}px`,o.style.width=`${i.width}px`,o.style.height=`${i.height}px`,o.style.transform=` - scale3d(${t.scale.x}, ${t.scale.y}, 1) rotate(${t.rotation.degrees}deg) - `,o.style.pointerEvents="none",o.dataset.velRemoved="",document.body.appendChild(o);const l=this._registry.createView(o,t.name);return l.setAsTemporaryView(),l.styles.position="absolute",l.styles.left=`${e.left+s}px`,l.styles.top=`${e.top-n}px`,l.rotation.setDegrees(t.rotation.degrees,!1),l.scale.set({x:t.scale.x,y:t.scale.y},!1),l.size.set({width:t._localWidth,height:t._localHeight},!1),t._copyAnimatorsToAnotherView(l),t.onRemoveCallback&&l.onRemove(t.onRemoveCallback),l}onViewRemoved(t){}notifyAboutViewAdded(t){this.onViewAdded(t),this._invokeAddCallbacks(t)}_invokeAddCallbacks(t){var e,i,s;!((e=t.onAddCallbacks)!=null&&e.onInitialLoad)&&!this._initialized||((i=t.onAddCallbacks)==null||i.beforeEnter(t),!((s=t.onAddCallbacks)!=null&&s.afterRemoved)||!this._initialized?requestAnimationFrame(()=>{var n;(n=t.onAddCallbacks)==null||n.afterEnter(t)}):t.layoutId&&this._layoutIdViewMapWaitingToEnter.set(t.layoutId,t))}onViewAdded(t){}init(){!this._initialized&&this._isReady&&(this.setup(),this._initialized=!0)}setup(){}subscribeToEvents(t){}}class re extends Bt{isRenderable(){return!0}isInitialized(){return this._initialized}get initialized(){return this._initialized}update(t,e){}render(){}addView(t){t.setPluginId(this.id),super.addView(t)}}class vt extends Bt{isRenderable(){return!1}}class ae{constructor(t){a(this,"_plugin"),this._plugin=t}get initialized(){return this._plugin.isInitialized()}get config(){return this._plugin.config}setup(t){this._plugin.setup=t}api(t){this._plugin._setApi(t)}update(t){this._plugin.update=t}render(t){this._plugin.render=t}getViews(t){return this._plugin.getViews(t)}getView(t){return this._plugin.getView(t)}getViewById(t){return this._plugin.getViewById(t)}useEventPlugin(t,e={}){return this._plugin.useEventPlugin(t,e)}emit(t,e){this._plugin.emit(t,e)}on(t,e){this._plugin.on(t,e)}onDataChanged(t){this._plugin.onDataChanged=t}onViewRemoved(t){this._plugin.onViewRemoved=t}onViewAdded(t){this._plugin.onViewAdded=t}subscribeToEvents(t){this._plugin.subscribeToEvents=t}}function ft(r,t,e,i,s,n){if(oe(r))return new r(r,r.pluginName,t,e,i,s,n);const o=new re(r,r.pluginName,t,e,i,s,n),l=new ae(o);return r(l),o}function oe(r){var t;return((t=r.prototype)==null?void 0:t.constructor.toString().indexOf("class "))===0}class u{constructor(t,e){a(this,"x"),a(this,"y"),this.x=t,this.y=e}get magnitudeSquared(){return this.x*this.x+this.y*this.y}get magnitude(){return Math.sqrt(this.x*this.x+this.y*this.y)}get unitVector(){const t=new u(0,0),e=this.magnitude;return e!==0&&(t.x=this.x/e,t.y=this.y/e),t}add(t){this.x+=t.x,this.y+=t.y}sub(t){this.x-=t.x,this.y-=t.y}scale(t){this.x*=t,this.y*=t}dot(t){return this.x*t.x+this.y*t.y}equals(t){return this.x===t.x&&this.y===t.y}clone(){return new u(this.x,this.y)}static scale(t,e){return new u(t.x*e,t.y*e)}static sub(t,e){return new u(t.x-e.x,t.y-e.y)}static add(t,e){return new u(t.x+e.x,t.y+e.y)}}class le{constructor(t){a(this,"_element"),a(this,"_callback"),a(this,"_windowScrollHandler"),a(this,"_windowResizeHandler"),a(this,"_parentElementScrollHandler"),this._element=t,this._observe()}setElement(t){this._element=t,this._observe()}_observe(){var t;const e=new MutationObserver(()=>{var n;(n=this._callback)==null||n.call(this,!1)}),i={attributes:!0,childList:!0,attributeOldValue:!0};e.observe(this._element,i),new ResizeObserver(()=>{var n;(n=this._callback)==null||n.call(this,!0)}).observe(this._element);function s(n,o){let l,h=!0;return function(){h&&(n(),h=!1),clearTimeout(l),l=setTimeout(()=>{n(),h=!0},o)}}this._parentElementScrollHandler=s(()=>{var n;(n=this._callback)==null||n.call(this,!0)},30),(t=this._element.parentElement)==null||t.addEventListener("scroll",this._parentElementScrollHandler),this._windowScrollHandler=s(()=>{var n;(n=this._callback)==null||n.call(this,!0)},30),window.addEventListener("scroll",this._windowScrollHandler),this._windowResizeHandler=s(()=>{var n;(n=this._callback)==null||n.call(this,!0)},30),window.addEventListener("resize",this._windowResizeHandler)}onChange(t){this._callback=t}destroy(){var t;this._parentElementScrollHandler&&((t=this._element.parentElement)==null||t.removeEventListener("scroll",this._parentElementScrollHandler)),this._windowScrollHandler&&window.removeEventListener("scroll",this._windowScrollHandler),this._windowResizeHandler&&window.removeEventListener("resize",this._windowResizeHandler)}}function he(r){return new le(r)}function ue(r,t){const e=t.x-r.x,i=t.y-r.y;return Math.sqrt(e*e+i*i)}function _(r,t){const e=r-t;return Math.abs(e)<=.01}function E(r){let t=r.match(/^([\d.]+)([a-zA-Z%]*)$/);t||(t="0px".match(/^([\d.]+)([a-zA-Z%]*)$/));const e=parseFloat(t[1]),i=t[2];return{value:e,unit:i,valueWithUnit:r}}function ce(r,t,e=!1){if(r===t)return!0;if(r.length!==t.length)return!1;for(let i=0;iE(i)),e={value:0,unit:"",valueWithUnit:"0"};switch(t.length){case 1:return new X(t[0],t[0],t[0],t[0]);case 2:return new X(t[0],t[1],t[0],t[1]);case 3:return new X(t[0],t[1],t[2],t[1]);case 4:return new X(t[0],t[1],t[3],t[2]);default:return new X(e,e,e,e)}}function de(r,t){const e=o(r.topLeft,t),i=o(r.topRight,t),s=o(r.bottomLeft,t),n=o(r.bottomRight,t);return{v:{topLeft:e.v,topRight:i.v,bottomRight:n.v,bottomLeft:s.v},h:{topLeft:e.h,topRight:i.h,bottomRight:n.h,bottomLeft:s.h}};function o(l,h){if(l.unit==="%")return{h:E(`${l.value}%`),v:E(`${l.value}%`)};const g=l.value/h.width*100,c=l.value/h.height*100;return{h:E(`${g}%`),v:E(`${c}%`)}}}function kt(r,t){return _(r.topLeft.value,t.topLeft.value)&&_(r.topRight.value,t.topRight.value)&&_(r.bottomRight.value,t.bottomRight.value)&&_(r.bottomLeft.value,t.bottomLeft.value)}class ge{constructor(t){a(this,"_value"),this._value=t}get value(){return this._value}equals(t){return _(this.value,t.value)}}function pe(r){return new ge(parseFloat(r))}class _e{constructor(t,e){a(this,"_x"),a(this,"_y"),this._x=t,this._y=e}get value(){return new u(this._x,this._y)}}function me(r,t){const[e,i]=r.split(" "),s=E(e),n=E(i);return new _e(s.value/t.width,n.value/t.height)}function Ot(r,t){const e=ve(r),i=r.offsetWidth,s=r.offsetHeight;return{viewportOffset:{left:Math.round(e.left),top:Math.round(e.top),right:Math.round(e.right),bottom:Math.round(e.bottom)},pageOffset:t.read({width:i,height:s}),size:{width:i,height:s}}}function ve(r){const t=r.getBoundingClientRect();return{left:t.left,top:t.top,right:t.right,bottom:t.bottom,width:t.width,height:t.height}}function zt(r){let t=r,e=0,i=0;for(;t;)e+=t.offsetTop,i+=t.offsetLeft,t=t.offsetParent;return{top:e,left:i}}class fe{constructor(t){a(this,"_currentPageRect"),a(this,"_view"),a(this,"_element"),a(this,"_offsetLeft"),a(this,"_offsetTop"),a(this,"_width"),a(this,"_height"),a(this,"_parentWidth"),a(this,"_parentHeight"),a(this,"_parentEl"),a(this,"_isSvg"),a(this,"_invalid"),a(this,"_windowResizeHandler"),this._invalid=!0,this._view=t,this._element=t.element,this._isSvg=!!this._element.closest("svg"),this._offsetLeft=0,this._offsetTop=0,this._width=0,this._height=0,this._parentWidth=0,this._parentHeight=0,this._offsetLeft=0,this._parentEl=this._element.parentElement,this._windowResizeHandler=()=>{this.invalidate()},window.addEventListener("resize",this._windowResizeHandler)}destroy(){this._windowResizeHandler&&window.removeEventListener("resize",this._windowResizeHandler)}invalidate(){this._invalid=!0}read(t){if(this._isSvg)return this._currentPageRect||(this._currentPageRect=zt(this._element)),this._currentPageRect;const e=this._element.parentElement,i=this._element.offsetLeft,s=this._element.offsetTop,n=t.width,o=t.height,l=(e==null?void 0:e.offsetWidth)||0,h=(e==null?void 0:e.offsetHeight)||0;return(this._offsetLeft!==i||this._offsetTop!==s||!_(this._width,n)||!_(this._height,o))&&this._view._children.forEach(g=>g.elementReader.invalidatePageRect()),!this._invalid&&this._currentPageRect&&this._offsetLeft===i&&this._offsetTop===s&&_(this._width,n)&&_(this._height,o)&&_(this._parentWidth,l)&&_(this._parentHeight,h)&&this._parentEl===e?this._currentPageRect:(this._offsetLeft=i,this._offsetTop=s,this._width=n,this._height=o,this._parentWidth=l,this._parentHeight=h,this._parentEl=e,this._currentPageRect=zt(this._element),this._invalid=!1,this._currentPageRect)}}function we(r){return new fe(r)}class ye{constructor(t){a(this,"_element"),a(this,"_rect"),a(this,"_computedStyle"),a(this,"_pageRectReader"),a(this,"_scroll"),this._element=t.element,this._pageRectReader=we(t),this._rect=Ot(this._element,this._pageRectReader),this._computedStyle=getComputedStyle(this._element),this._scroll=this._calculateScroll()}destroy(){this._pageRectReader.destroy()}invalidatePageRect(){this._pageRectReader.invalidate()}update(t=!1){this._rect=Ot(this._element,this._pageRectReader),this._computedStyle=getComputedStyle(this._element),t&&(this._scroll=this._calculateScroll())}get rect(){return this._rect}get opacity(){return pe(this._computedStyle.opacity)}get borderRadius(){return wt(this._computedStyle.borderRadius)}get origin(){return me(this._computedStyle.transformOrigin,this._rect.size)}_calculateScroll(){let t=this._element,e=0,i=0;for(;t;)e+=t.scrollTop,i+=t.scrollLeft,t=t.offsetParent;return i+=window.scrollX,e+=window.scrollY,{y:e,x:i}}get scroll(){return this._scroll}}function Dt(r){return new ye(r)}function yt(r,t){const e={set:(i,s,n)=>(typeof i[s]=="object"&&i[s]!==null?i[s]=yt(n,t):(t(),i[s]=n),!0),get:(i,s)=>typeof i[s]=="object"&&i[s]!==null?yt(i[s],t):i[s]};return new Proxy(r,e)}const ot=.01,Vt={speed:15};class bt{constructor(t){a(this,"name","dynamic"),a(this,"_config"),this._config=t}get config(){return this._config}}class Ve extends bt{update({animatorProp:t,current:e,target:i,dt:s}){const n=u.sub(i,e),o=u.scale(n,this._config.speed);let l=u.add(e,u.scale(o,s));return this._shouldFinish(i,e,o)&&(l=i,requestAnimationFrame(()=>{t.callCompleteCallback()})),t.callUpdateCallback(),l}_shouldFinish(t,e,i){return u.sub(t,e).magnitude{t.callCompleteCallback()})),t.callUpdateCallback(),o}}class Pe extends bt{update({animatorProp:t,current:e,target:i,dt:s}){return i.map((n,o)=>{const l=e[o],h=n.value===0?l.unit:n.unit,g=(n.value-l.value)*this._config.speed,c=l.value+g*s;let p=E(`${c}${h}`);return this._shouldFinish(n.value,l.value,g)&&(p=n,requestAnimationFrame(()=>{t.callCompleteCallback()})),t.callUpdateCallback(),p})}_shouldFinish(t,e,i){return Math.abs(t-e){t.animatorProp.callCompleteCallback()}),t.target}}const Et={stiffness:.5,damping:.75,speed:10},lt=.01;class Rt{constructor(t){a(this,"name","spring"),a(this,"_config"),this._config=t}get config(){return this._config}}class Ee extends Rt{constructor(){super(...arguments),a(this,"_velocity",new u(0,0))}update({animatorProp:t,current:e,target:i,dt:s}){const n=u.scale(u.scale(u.sub(e,i),-1),this._config.stiffness);this._velocity=u.add(this._velocity,n),this._velocity=u.scale(this._velocity,this._config.damping);let o=u.add(e,u.scale(this._velocity,s*this._config.speed));return this._shouldFinish(i,e)&&(o=i,requestAnimationFrame(()=>{t.callCompleteCallback()})),o}_shouldFinish(t,e){return u.sub(t,e).magnitude{t.callCompleteCallback()})),o}}class xe extends Rt{constructor(){super(...arguments),a(this,"_velocity",0)}update({animatorProp:t,current:e,target:i,dt:s}){return i.map((n,o)=>{const l=e[o],h=n.value===0?l.unit:n.unit,g=-(l.value-n.value)*this._config.stiffness;this._velocity+=g,this._velocity*=this._config.damping;const c=l.value+this._velocity*s*this._config.speed;let p=E(`${c}${h}`);return this._shouldFinish(n.value,l.value)&&(p=n,requestAnimationFrame(()=>{t.callCompleteCallback()})),p})}_shouldFinish(t,e){return Math.abs(t-e){t.callCompleteCallback()}),i):u.add(e,u.scale(u.sub(i,e),this._config.ease(n)))}}class Se extends At{update({animatorProp:t,initial:e,target:i,ts:s}){this._startTime||(this._startTime=s);const n=Math.min(1,(s-this._startTime)/this._config.duration);return _(n,1)?(requestAnimationFrame(()=>{t.callCompleteCallback()}),i):e.map((o,l)=>{const h=i[l],g=h.value===0?o.unit:h.unit,c=o.value+this._config.ease(n)*(i[l].value-o.value);return E(`${c}${g}`)})}}class Ce extends At{update({animatorProp:t,initial:e,target:i,ts:s}){this._startTime||(this._startTime=s);const n=Math.min(1,(s-this._startTime)/this._config.duration);return _(n,1)?(requestAnimationFrame(()=>{t.callCompleteCallback()}),i):e+(i-e)*this._config.ease(n)}}class Tt{createAnimatorByName(t,e){switch(t){case"instant":return this.createInstantAnimator();case"dynamic":return this.createDynamicAnimator(e);case"tween":return this.createTweenAnimator(e);case"spring":return this.createSpringAnimator(e)}return this.createInstantAnimator()}}class ht extends Tt{createInstantAnimator(){return new Pt}createTweenAnimator(t){return new Te({...xt,...t})}createDynamicAnimator(t){return new Ve({...Vt,...t})}createSpringAnimator(t){return new Ee({...Et,...t})}}class Le extends Tt{createInstantAnimator(){return new Pt}createTweenAnimator(t){return new Se({...xt,...t})}createDynamicAnimator(t){return new Pe({...Vt,...t})}createSpringAnimator(t){return new xe({...Et,...t})}}class $t extends Tt{createInstantAnimator(){return new Pt}createDynamicAnimator(t){return new be({...Vt,...t})}createTweenAnimator(t){return new Ce({...xt,...t})}createSpringAnimator(t){return new Re({...Et,...t})}}function j(r){return structuredClone(r)}class Ie{constructor(t){a(this,"_viewProp"),a(this,"_completeCallback"),a(this,"_updateCallback"),a(this,"_isAnimating"),this._viewProp=t,this._isAnimating=!1}set(t,e){this._viewProp.setAnimator(t,e)}get name(){return this._viewProp.getAnimator().name}onComplete(t){this._completeCallback=t}get isAnimating(){return this._isAnimating}markAsAnimating(){this._isAnimating=!0}callCompleteCallback(){var t;(t=this._completeCallback)==null||t.call(this),this._isAnimating=!1}onUpdate(t){this._updateCallback=t}callUpdateCallback(){var t;(t=this._updateCallback)==null||t.call(this)}}class k{constructor(t,e,i){a(this,"_animatorProp"),a(this,"_animator"),a(this,"_initialValue"),a(this,"_previousValue"),a(this,"_targetValue"),a(this,"_currentValue"),a(this,"_hasChanged"),a(this,"_view"),a(this,"_animatorFactory"),a(this,"_previousRenderValue"),this._animatorProp=new Ie(this),this._animatorFactory=t,this._initialValue=j(e),this._previousValue=j(e),this._targetValue=j(e),this._currentValue=j(e),this._hasChanged=!1,this._previousRenderValue=void 0,this._view=i,this._animator=this._animatorFactory.createInstantAnimator()}get shouldRender(){return!0}get isAnimating(){return this.animator.isAnimating}getAnimator(){return this._animator}get animator(){return this._animatorProp}get _rect(){return this._view.rect}get _previousRect(){return this._view.previousRect}setAnimator(t,e){this._animator=this._animatorFactory.createAnimatorByName(t,e)}_setTarget(t,e=!0){var i,s;this._previousValue=j(this._currentValue),this._targetValue=t,e?((s=(i=this._animator).reset)==null||s.call(i),this.animator.markAsAnimating()):this._currentValue=t,this._hasChanged=!0}hasChanged(){return this._hasChanged}destroy(){this._hasChanged=!1}update(t,e){}}class Me extends k{constructor(){super(...arguments),a(this,"_invertedBorderRadius"),a(this,"_forceStyleUpdateThisFrame",!1),a(this,"_updateWithScale",!1)}setFromElementPropValue(t){this._setTarget([t.value.topLeft,t.value.topRight,t.value.bottomRight,t.value.bottomLeft],!0)}enableUpdateWithScale(){this._updateWithScale=!0}disableUpdateWithScale(){this._updateWithScale=!1}get value(){return{topLeft:this._currentValue[0],topRight:this._currentValue[1],bottomRight:this._currentValue[2],bottomLeft:this._currentValue[3]}}get invertedBorderRadius(){return this._invertedBorderRadius}set(t,e=!0){let i;if(typeof t=="string"){const h=wt(t.trim());i={topLeft:h.value.topLeft.valueWithUnit,topRight:h.value.topRight.valueWithUnit,bottomRight:h.value.bottomRight.valueWithUnit,bottomLeft:h.value.bottomLeft.valueWithUnit}}else i=t;const s=i.topLeft?E(i.topLeft):this._currentValue[0],n=i.topRight?E(i.topRight):this._currentValue[1],o=i.bottomRight?E(i.bottomRight):this._currentValue[2],l=i.bottomLeft?E(i.bottomLeft):this._currentValue[3];this._setTarget([s,n,o,l],e)}reset(t=!0){this._setTarget(this._initialValue,t)}update(t,e){if(this._forceStyleUpdateThisFrame)this._hasChanged=!0,this._forceStyleUpdateThisFrame=!1;else if(this._view.scale.isAnimating&&this._updateWithScale)this._hasChanged=!0;else if(Ft(this._targetValue,this._currentValue)){this._hasChanged=!Ft(this._targetValue,this._initialValue);return}this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:t,dt:e}),this._updateWithScale&&this._applyScaleInverse()}applyScaleInverse(){this._updateWithScale&&(this._forceStyleUpdateThisFrame=!0)}_applyScaleInverse(){if(_(this._view.scale.x,1)&&_(this._view.scale.y,1))return;const t=this._rect.size.width*this._view.scale.x,e=this._rect.size.height*this._view.scale.y;this._invertedBorderRadius=de(wt(`${this._currentValue[0].valueWithUnit} ${this._currentValue[1].valueWithUnit} ${this._currentValue[2].valueWithUnit} ${this._currentValue[3].valueWithUnit}`).value,{width:t,height:e})}get shouldRender(){return this._hasChanged?this._previousRenderValue?!(kt(this.renderValue.v,this._previousRenderValue.v)&&kt(this.renderValue.h,this._previousRenderValue.h)):!0:!1}get renderValue(){return this.invertedBorderRadius?{v:{topLeft:this.invertedBorderRadius.v.topLeft,topRight:this.invertedBorderRadius.v.topRight,bottomLeft:this.invertedBorderRadius.v.bottomLeft,bottomRight:this.invertedBorderRadius.v.bottomRight},h:{topLeft:this.invertedBorderRadius.h.topLeft,topRight:this.invertedBorderRadius.h.topRight,bottomLeft:this.invertedBorderRadius.h.bottomLeft,bottomRight:this.invertedBorderRadius.h.bottomRight}}:{v:{topLeft:this.value.topLeft,topRight:this.value.topRight,bottomLeft:this.value.bottomLeft,bottomRight:this.value.bottomRight},h:{topLeft:this.value.topLeft,topRight:this.value.topRight,bottomLeft:this.value.bottomLeft,bottomRight:this.value.bottomRight}}}projectStyles(){const t=this.renderValue,e=`border-radius: ${t.h.topLeft.valueWithUnit} ${t.h.topRight.valueWithUnit} ${t.h.bottomRight.valueWithUnit} ${t.h.bottomLeft.valueWithUnit} / ${t.v.topLeft.valueWithUnit} ${t.v.topRight.valueWithUnit} ${t.v.bottomRight.valueWithUnit} ${t.v.bottomLeft.valueWithUnit};`;return this._previousRenderValue=t,e}isTransform(){return!1}}class Ne extends k{setFromElementPropValue(t){this._setTarget(t.value,!0)}get value(){return this._currentValue}set(t,e=!0){this._setTarget(t,e)}reset(t=!0){this._setTarget(1,t)}update(t,e){if(_(this._targetValue,this._currentValue)){this._hasChanged=!_(this._targetValue,this._initialValue);return}this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:t,dt:e})}get shouldRender(){return this._hasChanged?typeof this._previousRenderValue>"u"?!0:this.renderValue!==this._previousRenderValue:!1}get renderValue(){return this.value}projectStyles(){const t=this.renderValue,e=`opacity: ${t};`;return this._previousRenderValue=t,e}isTransform(){return!1}}class Be extends k{get x(){return this._currentValue.x}get y(){return this._currentValue.y}set(t){const e={x:this.x,y:this.y,...t};if(e.x<0||e.x>1){console.log(`%c WARNING: ${this._view.name}.origin.x property can only be a value from 0 to 1`,"background: #885500");return}if(e.y<0||e.y>1){console.log(`%c WARNING: ${this._view.name}.origin.y property can only be a value from 0 to 1`,"background: #885500");return}this._setTarget(new u(e.x,e.y),!1)}reset(){this._setTarget(this._initialValue,!1)}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const t=this.renderValue;return!(_(t.x,this._previousRenderValue.x)&&_(t.y,this._previousRenderValue.y))}get renderValue(){return new u(this.x*100,this.y*100)}projectStyles(){const t=this.renderValue,e=`transform-origin: ${t.x}% ${t.y}%;`;return this._previousRenderValue=t,e}isTransform(){return!1}}class Fe extends k{constructor(){super(...arguments),a(this,"_animateLayoutUpdateNextFrame",!1),a(this,"_parentScaleInverse",new u(1,1))}get _parentDiff(){let t=this._view._parent,e=0,i=0;if(t){const s=t.rect.pageOffset,n=t.getScroll(),o={left:t.previousRect.viewportOffset.left+n.x,top:t.previousRect.viewportOffset.top+n.y};e=o.left-s.left,i=o.top-s.top}return{parentDx:e,parentDy:i}}get x(){return this._currentValue.x+this._rect.pageOffset.left+this._parentDiff.parentDx}get y(){return this._currentValue.y+this._rect.pageOffset.top+this._parentDiff.parentDy}get initialX(){return this._rect.pageOffset.left}get initialY(){return this._rect.pageOffset.top}progressTo(t){const e=typeof t.x>"u"?this.initialX:t.x,i=typeof t.y>"u"?this.initialY:t.y,s=new u(e,i),n=new u(this.initialX,this.initialY),o=new u(this.x,this.y),l=u.sub(o,n),h=u.sub(s,n);return 1-u.sub(h,l).magnitude/h.magnitude}set(t,e=!0){const i={x:this.x,y:this.y,...t};this._setTarget(new u(i.x-this._rect.pageOffset.left,i.y-this._rect.pageOffset.top),e)}reset(t=!0){this._setTarget(new u(0,0),t)}update(t,e){if((this._view.isInverseEffectEnabled||this._view.isLayoutTransitionEnabled)&&!this._view.isTemporaryView&&this._runLayoutTransition(),this._view.isInverseEffectEnabled){const h=this._view._parent,g=h?h.scale.x:1,c=h?h.scale.y:1;this._parentScaleInverse=new u(1/g,1/c),this._parentScaleInverse.equals(new u(1,1))||(this._hasChanged=!0)}if(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y)return;const i=this._view._parent,s=i?i.scale.x:1,n=i?i.scale.y:1,o=i?i.scale._previousValue.x:1,l=i?i.scale._previousValue.y:1;this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:new u(this._currentValue.x*s,this._currentValue.y*n),target:this._targetValue,initial:new u(this._previousValue.x*o,this._previousValue.y*l),ts:t,dt:e}),this._currentValue=new u(this._currentValue.x/s,this._currentValue.y/n)}_runLayoutTransition(){const t=!(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y),e=!(this._view.scale._targetValue.x===this._view.scale._currentValue.x&&this._view.scale._targetValue.y===this._view.scale._currentValue.y),i=t||e,s=this._rect.pageOffset.left-this._previousRect.pageOffset.left,n=this._rect.pageOffset.top-this._previousRect.pageOffset.top,o=this._previousRect.size.width/this._rect.size.width,l=this._previousRect.size.height/this._rect.size.height;let h=!1;if(s!==0||n!==0||!Number.isNaN(o)&&o!==1||!Number.isNaN(l)&&l!==1?h=!0:h=(()=>{const g=this._view._parents;for(let c=0;c"u")return!0;const t=this.renderValue;return!_(t,this._previousRenderValue)}get renderValue(){return this._currentValue}projectStyles(){const t=this.renderValue,e=`rotate(${t}${this._unit})`;return this._previousRenderValue=t,e}isTransform(){return!0}}class Oe extends k{constructor(){super(...arguments),a(this,"_animateLayoutUpdateNextFrame",!1)}get x(){return this._currentValue.x}get y(){return this._currentValue.y}set(t,e=!0){const i={x:this._currentValue.x,y:this._currentValue.y,...typeof t=="number"?{x:t,y:t}:t};this._setTarget(new u(i.x,i.y),e)}setWithSize(t,e=!0){let i=this._currentValue.x,s=this._currentValue.y;t.width&&(i=t.width/this._rect.size.width),t.height&&(s=t.height/this._rect.size.height),!t.width&&t.height&&(i=s),!t.height&&t.width&&(s=i);const n={x:i,y:s};this._setTarget(new u(n.x,n.y),e)}reset(t=!0){this._setTarget(new u(1,1),t)}update(t,e){if(this._view.layoutOption!=="position"){if((this._view.isInverseEffectEnabled||this._view.isLayoutTransitionEnabled)&&!this._view.isTemporaryView&&this._runLayoutTransition(),this._view.isInverseEffectEnabled){const i=this._view._parent,s=i?i.scale.x:1,n=i?i.scale.y:1;this._hasChanged=s!==1||n!==1}this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y||(this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:new u(this._previousValue.x,this._previousValue.y),ts:t,dt:e}))}}_runLayoutTransition(){const t=!(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y),e=this._previousRect.size.width/this._rect.size.width,i=this._previousRect.size.height/this._rect.size.height;let s=!1;if((!Number.isNaN(e)&&e!==1||!Number.isNaN(i)&&i!==1)&&(s=!0),s){if(this._currentValue.x!==1||this._currentValue.y!==1){const g=this._view.previousRect.size.width/this._view.rect.size.width,c=this._view.previousRect.size.height/this._view.rect.size.height;this._setTarget(new u(this._currentValue.x*g,this._currentValue.y*c),!1),t&&(this._animateLayoutUpdateNextFrame=!0);return}const n=this._previousRect.size.width/this._rect.size.width,o=this._previousRect.size.height/this._rect.size.height,l=n,h=o;this._view.viewProps.borderRadius.applyScaleInverse(),this._setTarget(new u(l,h),!1),this._animateLayoutUpdateNextFrame=!0}else this._animateLayoutUpdateNextFrame&&(this._setTarget(this._initialValue,!0),this._animateLayoutUpdateNextFrame=!1)}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const t=this.renderValue;return!(_(t.x,this._previousRenderValue.x)&&_(t.y,this._previousRenderValue.y))}get renderValue(){const t=this._view._parent?this._view._parent.scale.x:1,e=this._view._parent?this._view._parent.scale.y:1,i=this._currentValue.x/t,s=this._currentValue.y/e;return new u(i,s)}projectStyles(){const t=this.renderValue,e=`scale3d(${t.x}, ${t.y}, 1)`;return this._previousRenderValue=t,e}isTransform(){return!0}}class ze extends k{get width(){return this._view.rect.size.width}get height(){return this._view.rect.size.height}get localWidth(){return this._currentValue.x}get localHeight(){return this._currentValue.y}get widthAfterScale(){const t=this._view.scale.x;return this.localWidth*t}get heightAfterScale(){const t=this._view.scale.y;return this.localHeight*t}get initialWidth(){return this._initialValue.x}get initialHeight(){return this._initialValue.y}set(t,e=!0){const i={width:this._currentValue.x,height:this._currentValue.y,...t};this._setTarget(new u(i.width,i.height),e)}setWidth(t,e=!0){const i={width:this._currentValue.x,height:this._currentValue.y,width:t};this._setTarget(new u(i.width,i.height),e)}setHeight(t,e=!0){const i={width:this._currentValue.x,height:this._currentValue.y,height:t};this._setTarget(new u(i.width,i.height),e)}reset(t=!0){this._setTarget(new u(this.initialWidth,this.initialHeight),t)}update(t,e){this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y||(this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:t,dt:e}))}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const t=this.renderValue;return!(_(t.x,this._previousRenderValue.x)&&_(t.y,this._previousRenderValue.y))}get renderValue(){return new u(this._currentValue.x,this._currentValue.y)}projectStyles(){const t=this.renderValue,e=`width: ${t.x}px; height: ${t.y}px;`;return this._previousRenderValue=t,e}isTransform(){return!1}}class De{constructor(t){a(this,"_props",new Map),this._props.set("position",new Fe(new ht,new u(0,0),t)),this._props.set("scale",new Oe(new ht,new u(1,1),t)),this._props.set("rotation",new ke(new $t,0,t)),this._props.set("size",new ze(new ht,new u(t.rect.size.width,t.rect.size.height),t)),this._props.set("opacity",new Ne(new $t,t.elementReader.opacity.value,t)),this._props.set("borderRadius",new Me(new Le,[t.elementReader.borderRadius.value.topLeft,t.elementReader.borderRadius.value.topRight,t.elementReader.borderRadius.value.bottomRight,t.elementReader.borderRadius.value.bottomLeft],t)),this._props.set("origin",new Be(new ht,t.elementReader.origin.value,t))}allProps(){return Array.from(this._props.values())}allPropNames(){return Array.from(this._props.keys())}getPropByName(t){return this._props.get(t)}get position(){return this._props.get("position")}get scale(){return this._props.get("scale")}get rotation(){return this._props.get("rotation")}get size(){return this._props.get("size")}get opacity(){return this._props.get("opacity")}get borderRadius(){return this._props.get("borderRadius")}get origin(){return this._props.get("origin")}}class $e{constructor(t,e,i,s){a(this,"id"),a(this,"name"),a(this,"element"),a(this,"styles",{}),a(this,"_viewProps"),a(this,"_previousRect"),a(this,"_onAddCallbacks"),a(this,"_onRemoveCallback"),a(this,"_skipFirstRenderFrame"),a(this,"_layoutTransition"),a(this,"_registry"),a(this,"_layoutId"),a(this,"_elementReader"),a(this,"_viewParents"),a(this,"_temporaryView"),a(this,"_inverseEffect"),a(this,"_renderNextTick"),a(this,"_layoutOption"),a(this,"_elementObserver"),a(this,"_hasReadElement"),a(this,"_shouldReadRect"),a(this,"_readWithScroll"),a(this,"_externalUserStyles"),this._registry=i,this.id=Nt(),this.name=e,this.element=t,this.element.dataset.velViewId=this.id,this._elementReader=Dt(this),this._viewParents=this._getParents(),this._previousRect=this._elementReader.rect,this._viewProps=new De(this),this._skipFirstRenderFrame=!0,this._layoutId=s,this._layoutTransition=!1,this._temporaryView=!1,this.styles=yt(this.styles,()=>{this._renderNextTick=!0}),this._externalUserStyles=this._getExternalUserStyles(),this._renderNextTick=!1,this._layoutOption=this._getLayoutOption(),this._hasReadElement=!1,this._shouldReadRect=!1,this._readWithScroll=!1,this._elementObserver=he(t),this._elementObserver.onChange(n=>{if(this._hasReadElement){this._shouldReadRect=!1;return}this._externalUserStyles=this._getExternalUserStyles(),this._shouldReadRect=!0,this._readWithScroll=n})}removeListeners(){this._elementObserver.destroy(),this._elementReader.destroy()}destroy(){this.removeListeners(),this._viewProps.allProps().forEach(t=>t.destroy()),this.element.removeAttribute("data-vel-view-id"),this.element.removeAttribute("data-vel-plugin-id"),this._renderNextTick=!0}get elementReader(){return this._elementReader}get layoutOption(){return this._layoutOption}_getLayoutOption(){return this.element.closest("[data-vel-layout-position]")?"position":this.element.closest("[data-vel-layout-size]")?"size":"all"}setElement(t){this.element=t,this._elementReader=Dt(this),this.element.dataset.velViewId=this.id,this._elementObserver.setElement(t),this._viewParents=this._getParents()}get layoutId(){return this._layoutId}get position(){return this._viewProps.position}get scale(){return this._viewProps.scale}get _children(){const t=this.element.querySelectorAll("*");return Array.from(t).map(e=>e.dataset.velViewId).filter(e=>e&&typeof e=="string").map(e=>this._registry.getViewById(e)).filter(e=>!!e)}get _parent(){return this._parents[0]}get _parents(){return this._viewParents}_getParents(){var t;const e=[];let i=this.element.parentElement;if(!i)return e;for(i=i.closest("[data-vel-view-id]");i;){const s=i.dataset.velViewId;if(s){const n=this._registry.getViewById(s);n&&e.push(n)}i=(t=i.parentElement)==null?void 0:t.closest("[data-vel-view-id]")}return e}get rotation(){return this._viewProps.rotation}get size(){return this._viewProps.size}get _localWidth(){return this._viewProps.size.localWidth}get _localHeight(){return this._viewProps.size.localHeight}get opacity(){return this._viewProps.opacity}get borderRadius(){return this._viewProps.borderRadius}get origin(){return this._viewProps.origin}get data(){const t=this.element.dataset;return Object.keys(t).filter(e=>e.includes("velData")).map(e=>e.replace("velData","")).map(e=>`${e[0].toLowerCase()}${e.slice(1)}`).reduce((e,i)=>{const s=t[`velData${i[0].toUpperCase()}${i.slice(1)}`];return!e[i]&&s&&(e[i]=s),e},{})}get onAddCallbacks(){return this._onAddCallbacks}get onRemoveCallback(){return this._onRemoveCallback}get isLayoutTransitionEnabled(){return this._layoutTransition}get hasLayoutTransitionEnabledForParents(){return this._parents.some(t=>t.isLayoutTransitionEnabled)}get isInverseEffectEnabled(){let t=!1;for(let e=0;e{if(e.position.animator.name==="instant"){const i=this.viewProps.position.getAnimator();e.position.setAnimator(i.name,i.config)}if(e.scale.animator.name==="instant"){const i=this.viewProps.scale.getAnimator();e.scale.setAnimator(i.name,i.config)}})}setAnimatorsFromParent(){let t=this._parent;for(;t&&!t._inverseEffect;)t=t._parent;if(t){if(this.position.animator.name==="instant"){const e=t.viewProps.position.getAnimator();this.position.setAnimator(e.name,e.config)}if(this.scale.animator.name==="instant"){const e=t.viewProps.scale.getAnimator();this.scale.setAnimator(e.name,e.config)}}}get _isRemoved(){return!this._registry.getViewById(this.id)}setPluginId(t){this.element.dataset.velPluginId=t}hasElement(t){return this.element.contains(t)}getScroll(){return this._elementReader.scroll}intersects(t,e){const i=this.element.getBoundingClientRect(),s={x:i.left,y:i.top};return t>=s.x&&t<=s.x+i.width&&e>=s.y&&e<=s.y+i.height}overlapsWith(t){const e=t._localWidth*t.scale.x,i=t._localHeight*t.scale.y,s=this._localWidth*this.scale.x,n=this._localHeight*this.scale.y;return this.position.xt.position.x&&this.position.yt.position.y}distanceTo(t){const e=new u(this.position.x,this.position.y),i=new u(t.position.x,t.position.y);return u.sub(i,e).magnitude}read(){this._shouldReadRect&&(this._elementReader.update(this._readWithScroll),this._children.forEach(t=>{t.setHasReadElement(!0),t.elementReader.update(this._readWithScroll)}),this._shouldReadRect=!1,this._readWithScroll=!1),this.setHasReadElement(!1)}setHasReadElement(t){this._hasReadElement=t}get rect(){return this._elementReader.rect}get previousRect(){return this._previousRect}update(t,e){this._viewProps.allProps().forEach(i=>i.update(t,e))}_updatePreviousRect(){this._previousRect=this._elementReader.rect}setAsTemporaryView(){this._temporaryView=!0}get isTemporaryView(){return this._temporaryView}get shouldRender(){return this._renderNextTick||this._viewProps.allProps().some(t=>t.shouldRender)}_cleanCssText(t){const e=new Map,i=/([-\w]+)\s*:\s*([^;]+)\s*;?/g;let s;for(;(s=i.exec(t))!==null;){const[n,o,l]=s;if(!l.trim())continue;const h=o.replace(/^-\w+-/,"");(!e.has(h)||!o.startsWith("-"))&&e.set(h,`${h}: ${l.trim()}`)}return Array.from(e.values()).join("; ")}render(){if(!this.shouldRender)return;if(this._isRemoved&&this._skipFirstRenderFrame){this._skipFirstRenderFrame=!1;return}let t="";const e=this._viewProps.allProps(),i=e.filter(n=>n.isTransform()),s=e.filter(n=>!n.isTransform());if(i.some(n=>n.hasChanged())){const n=i.reduce((o,l,h)=>(o+=l.projectStyles(),h{n.hasChanged()&&(t+=n.projectStyles())}),t+=this._getUserStyles(),this._cleanCssText(this.element.style.cssText)!==this._cleanCssText(t)&&(this.element.style.cssText=t),this._renderNextTick=!1}_getExternalUserStyles(){const t=this.element.style.cssText,e=this.styles;if(t.length===0)return"";const i=["transform","transform-origin","opacity","width","height","border-radius"],s={};for(const n in e)e.hasOwnProperty(n)&&(s[It(n)]=e[n]);return t.split(";").map(n=>n.trim()).filter(Boolean).filter(n=>{const o=n.indexOf(":");if(o===-1)return!1;const l=n.slice(0,o).trim();return!s.hasOwnProperty(l)&&!i.includes(l)}).join("; ")}_getUserStyles(){return Object.keys(this.styles).reduce((t,e)=>{if(!e)return t;const i=It(e).replace("webkit","-webkit").replace("moz","-moz");return t+`${i}: ${this.styles[e]}; `},this._externalUserStyles)}markAsAdded(){delete this.element.dataset.velProcessing}onAdd(t){this._onAddCallbacks=t}onRemove(t){this._onRemoveCallback=t}get viewProps(){return this._viewProps}getPropByName(t){return this._viewProps.getPropByName(t)}_copyAnimatorsToAnotherView(t){t.viewProps.allPropNames().forEach(e=>{var i,s;const n=(i=this.viewProps.getPropByName(e))==null?void 0:i.getAnimator();n&&((s=t.viewProps.getPropByName(e))==null||s.setAnimator(n.name,n.config))})}getChildren(t){const e=this.element.querySelectorAll("*"),i=Array.from(e).filter(s=>{const n=s;return typeof n.dataset.velViewId<"u"&&n.dataset.velView===t}).map(s=>s.dataset.velViewId);return this._registry.getViewsById(i)}getChild(t){return this.getChildren(t)[0]}getParent(t){const e=this.element.closest(`[data-vel-view="${t}"]`);if(!e)return;const i=e.dataset.velViewId;if(i)return this._registry.getViewById(i)}}class We{constructor(t,e){a(this,"_appEventBus"),a(this,"_eventBus"),a(this,"_plugins",[]),a(this,"_views",[]),a(this,"_viewsPerPlugin",new Map),a(this,"_viewsToBeCreated",[]),a(this,"_viewsToBeRemoved",[]),a(this,"_viewsCreatedInPreviousFrame",[]),a(this,"_layoutIdToViewMap",new Map),a(this,"_eventPluginsPerPlugin",new Map),a(this,"_pluginNameToPluginFactoryMap",new Map),a(this,"_pluginNameToPluginConfigMap",new Map),this._appEventBus=t,this._eventBus=e}update(){this._handleRemovedViews(),this._handleAddedViews()}associateEventPluginWithPlugin(t,e){let i=this._eventPluginsPerPlugin.get(t);i||(i=[],this._eventPluginsPerPlugin.set(t,i)),i.push(e)}_handleRemovedViews(){const t=this._viewsToBeRemoved.filter(e=>e.dataset.velViewId);t.length&&(t.forEach(e=>{const i=e.dataset.velViewId;i&&(this._handleRemoveView(i),e.querySelectorAll("*").forEach(s=>{const n=s.dataset.velViewId;n&&this._plugins.forEach(o=>{if(!this._viewsPerPlugin.get(o.id))return;const l=this._getPluginViewById(o,n);l&&l.removeListeners()})}))}),this._viewsToBeRemoved=[])}_getPluginNameForElement(t){const e=t.dataset.velPlugin;if(e&&e.length>0)return e;const i=t.closest("[data-vel-plugin]");if(i)return i.dataset.velPlugin}_getPluginIdForElement(t){const e=this._getPluginNameForElement(t);if(!e)return;const i=t.closest("[data-vel-plugin-id]");if(i)return i.dataset.velPluginId;const s=this.getPluginByName(e);if(s)return s.id}_isScopedElement(t){const e=this._getPluginNameForElement(t);if(!e)return!1;const i=this._pluginNameToPluginFactoryMap.get(e),s=i==null?void 0:i.scope;return t.dataset.velView===s}_removeElementsWithParent(t){const e=new Set(t);return t.filter(i=>{let s=i.parentElement;for(;s;){if(e.has(s))return!1;s=s.parentElement}return!0})}_handleAddedViews(){this._viewsCreatedInPreviousFrame.forEach(n=>{n.markAsAdded()}),this._viewsCreatedInPreviousFrame=[];const t=this._removeElementsWithParent(this._viewsToBeCreated),e=Array.from(new Set(t.filter(n=>this._isScopedElement(n)&&!this._isElementIgnored(n)))),i=t.filter(n=>!this._isScopedElement(n)&&!this._isElementIgnored(n));this._viewsToBeCreated=[],e.forEach(n=>{const o=this._getPluginNameForElement(n),l=this._pluginNameToPluginFactoryMap.get(o),h=this._pluginNameToPluginConfigMap.get(o),g=n.dataset.velPluginKey,c=ft(l,this,this._eventBus,this._appEventBus,h,g);this._plugins.push(c);const p=n.dataset.velView,f=this._createNewView(n,p,c);f.isInverseEffectEnabled&&f.setAnimatorsFromParent(),c.notifyAboutViewAdded(f)});const s=i.filter(n=>!!this._getPluginIdForElement(n));s.length!==0&&s.forEach(n=>{const o=this._getPluginIdForElement(n),l=n.dataset.velView;if(!l||!o)return;const h=this._getPluginById(o);if(!h)return;const g=this._getLayoutIdForElement(n,h);let c;g&&this._layoutIdToViewMap.has(g)?(c=this._layoutIdToViewMap.get(g),c.setElement(n),c.setPluginId(h.id),this._createChildrenForView(c,h)):c=this._createNewView(n,l,h),c.isInverseEffectEnabled&&c.setAnimatorsFromParent(),h.notifyAboutViewAdded(c)})}_getLayoutIdForElement(t,e){const i=t.dataset.velLayoutId;if(i)return`${i}-${e.id}`}_createNewView(t,e,i){const s=this._getLayoutIdForElement(t,i),n=this.createView(t,e,s);return i.addView(n),n.layoutId&&this._layoutIdToViewMap.set(n.layoutId,n),this._createChildrenForView(n,i),this._appEventBus.emitPluginReadyEvent(i.pluginName,i.api,!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._appEventBus.emitPluginReadyEvent(i.pluginName,i.api)})}),n}_createChildrenForView(t,e){const i=t.element.querySelectorAll("*");if(i.length){if(Array.from(i).some(s=>this._getPluginNameForElement(s)!==e.pluginName)){console.log(`%c WARNING: The plugin "${e.pluginName}" has view(s) created for a different plugin. Make sure all views inside that plugin don't have data-vel-plugin set or the pluginName is set to "${e.pluginName}"`,"background: #885500");return}Array.from(i).filter(s=>!this._isElementIgnored(s)).forEach(s=>{const n=s,o=n.dataset.velView?n.dataset.velView:`${t.name}-child`,l=this._getLayoutIdForElement(n,e);let h;l&&this._layoutIdToViewMap.has(l)?(h=this._layoutIdToViewMap.get(l),h.setElement(n),h.setPluginId(e.id)):h=this.createView(n,o,l),l&&!this._layoutIdToViewMap.has(l)&&this._layoutIdToViewMap.set(l,h),e.addView(h),e.notifyAboutViewAdded(h)})}}_handleRemoveView(t){this._plugins.forEach(e=>{if(!this._viewsPerPlugin.get(e.id))return;const i=this._getPluginViewById(e,t);i&&e.removeView(i)})}removeViewById(t,e){this._unassignViewFromPlugin(t,e),this._views=this._views.filter(i=>i.id!==t)}_unassignViewFromPlugin(t,e){const i=this._viewsPerPlugin.get(e);if(!i)return;const s=i.indexOf(t);s!==-1&&i.splice(s,1)}getViewById(t){return this._views.find(e=>e.id===t)}getViewsById(t){return this._views.filter(e=>t.includes(e.id))}_getPluginById(t){return this._plugins.find(e=>e.id===t)}_getPluginViewById(t,e){return this.getViewsForPlugin(t).find(i=>i.id===e)}destroy(t,e){if(!t){this._destroyAll(e);return}let i=[];if(t&&t.length>0){const s=this.getPluginByName(t);if(s){const n=(this._eventPluginsPerPlugin.get(s.id)||[]).map(o=>this._getPluginById(o)).filter(o=>typeof o<"u");i.push(s),i.push(...n)}}else i=this._plugins;i.forEach(s=>{this._destroyPlugin(s)}),requestAnimationFrame(()=>{e==null||e()})}_destroyPlugin(t){const e=this.getViewsForPlugin(t);e.forEach(i=>{i.layoutId&&this._layoutIdToViewMap.delete(i.layoutId),i.destroy()}),this._views=this._views.filter(i=>!e.find(s=>s.id===i.id)),this._viewsPerPlugin.delete(t.id),this._plugins=this._plugins.filter(i=>i.id!==t.id)}_destroyAll(t){this._views.forEach(e=>e.destroy()),requestAnimationFrame(()=>{this._plugins=[],this._views=[],this._viewsPerPlugin.clear(),this._viewsToBeCreated=[],this._viewsToBeRemoved=[],this._viewsCreatedInPreviousFrame=[],this._layoutIdToViewMap.clear(),this._eventPluginsPerPlugin.clear(),t==null||t()})}reset(t,e){let i=[];if(t&&t.length>0){const s=this.getPluginByName(t);if(s){const n=(this._eventPluginsPerPlugin.get(s.id)||[]).map(o=>this._getPluginById(o)).filter(o=>typeof o<"u");i.push(s),i.push(...n)}}else i=this._plugins;requestAnimationFrame(()=>{i.forEach(s=>{this._resetPlugin(s)}),requestAnimationFrame(()=>{e==null||e()})})}_resetPlugin(t){const e=t.config,i=t.pluginFactory,s=t.internalBusEvent,n=!t.isRenderable(),o=this.getViewsForPlugin(t);o.forEach(l=>{l.layoutId&&this._layoutIdToViewMap.delete(l.layoutId),l.destroy()}),this._views=this._views.filter(l=>!o.find(h=>h.id===l.id)),this._viewsPerPlugin.delete(t.id),this._plugins=this._plugins.filter(l=>l.id!==t.id),n||requestAnimationFrame(()=>{this.createPlugin(i,this._eventBus,e).setInternalEventBus(s)})}queueNodeToBeCreated(t){this._viewsToBeCreated.push(t)}queueNodeToBeRemoved(t){this._viewsToBeRemoved.push(t)}notifyPluginAboutDataChange(t){const e=this._plugins.filter(i=>i.id===t.pluginId);!e||!e.length||e.forEach(i=>{i.notifyAboutDataChanged({dataName:t.dataName,dataValue:t.dataValue,viewName:t.viewName})})}getPlugins(){return this._plugins}getRenderablePlugins(){function t(e){return e.isRenderable()}return this._plugins.filter(t)}getPluginByName(t,e){return this._plugins.find(i=>e?i.pluginKey===e&&i.pluginName===t:i.pluginName===t)}getPluginsByName(t,e){return this._plugins.filter(i=>e?i.pluginKey===e&&i.pluginName===t:i.pluginName===t)}hasPlugin(t){return t.pluginName?!!this.getPluginByName(t.pluginName):!1}createPlugin(t,e,i={},s=!1){if(!t.pluginName)throw Error(`Plugin ${t.name} must contain a pluginName field`);let n=[];if(t.scope){const h=s?`[data-vel-plugin=${t.pluginName}][data-vel-view=${t.scope}]:not([data-vel-plugin-id])`:`[data-vel-plugin=${t.pluginName}][data-vel-view=${t.scope}]`,g=document.querySelectorAll(h);this._pluginNameToPluginFactoryMap.has(t.pluginName)||this._pluginNameToPluginFactoryMap.set(t.pluginName,t),this._pluginNameToPluginConfigMap.has(t.pluginName)||this._pluginNameToPluginConfigMap.set(t.pluginName,i),g?n=Array.from(g):n=[document.documentElement]}else n=[document.documentElement];const o=n.map(h=>{const g=h.dataset.velPluginKey,c=ft(t,this,e,this._appEventBus,i,g);this._plugins.push(c);let p=[];h!==document.documentElement&&p.push(h);const f=h.querySelectorAll(`[data-vel-plugin=${c.pluginName}]`);p=[...p,...f];const V=p.filter(w=>{if(this._isElementIgnored(w))return!1;if(!w.parentElement)return!0;const P=this._getPluginNameForElement(w.parentElement);return!(P&&P.length>0)});return V.length&&V.forEach(w=>{const P=w.dataset.velView;if(!P)return;const C=this._createNewView(w,P,c);c.notifyAboutViewAdded(C)}),c});if(o&&o.length>0)return o[0];const l=ft(t,this,e,this._appEventBus,i);return t.scope||console.log(`%c WARNING: The plugin "${l.pluginName}" is created but there are no elements using it on the page`,"background: #885500"),l}updatePlugin(t,e,i={}){return this.createPlugin(t,e,i,!0)}getViews(){return this._views}createView(t,e,i){const s=new $e(t,e,this,i);return this._views.push(s),this._viewsCreatedInPreviousFrame.push(s),s}_isElementIgnored(t){return t.closest("[data-vel-ignore]")}assignViewToPlugin(t,e){this._viewsPerPlugin.has(e.id)||this._viewsPerPlugin.set(e.id,[]);const i=this._viewsPerPlugin.get(e.id);i.includes(t.id)||i.push(t.id)}getViewsForPlugin(t){const e=this._viewsPerPlugin.get(t.id);return e?e.map(i=>this._views.find(s=>s.id===i)).filter(i=>!!i):[]}getViewsByNameForPlugin(t,e){return this.getViewsForPlugin(t).filter(i=>i.name===e)}}class Wt{constructor(t){a(this,"pluginApi"),this.pluginApi=t.pluginApi}}class qt{constructor(t){a(this,"pluginApi"),this.pluginApi=t.pluginApi}}class St{constructor(){a(this,"previousTime",0),a(this,"registry"),a(this,"eventBus"),a(this,"appEventBus"),this.eventBus=new mt,this.appEventBus=new mt,this.registry=new We(this.appEventBus,this.eventBus),new ie(this.eventBus)}static create(){return new St}addPlugin(t,e={}){this.registry.hasPlugin(t)||this.registry.createPlugin(t,this.eventBus,e)}updatePlugin(t,e={}){this.registry.hasPlugin(t)&&this.registry.updatePlugin(t,this.eventBus,e)}reset(t,e){this.registry.reset(t,e)}destroy(t,e){this.registry.destroy(t,e)}getPlugin(t,e){let i=typeof t=="string"?t:t.pluginName;const s=this.registry.getPluginByName(i,e);if(!s)throw new Error(`You can't call getPlugin for ${i} with key: ${e} because it does not exist in your app`);return s.api}getPlugins(t,e){let i=typeof t=="string"?t:t.pluginName;const s=this.registry.getPluginsByName(i,e);if(s.length===0)throw new Error(`You can't call getPlugins for ${i} with key: ${e} because they don't exist in your app`);return s.map(n=>n.api)}onPluginEvent(t,e,i,s){requestAnimationFrame(()=>{const n=this.registry.getPluginByName(t.pluginName,s);n&&n.on(e,i)})}removePluginEventListener(t,e,i){const s=this.registry.getPluginByName(t.pluginName);s&&s.removeListener(e,i)}run(){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",this.start.bind(this)):this.start()}start(){this.setup(),requestAnimationFrame(this.tick.bind(this))}setup(){this.listenToNativeEvents(),this.subscribeToEvents()}listenToNativeEvents(){document.addEventListener("click",t=>{this.eventBus.emitEvent(pt,{x:t.clientX,y:t.clientY,target:t.target})}),document.addEventListener("pointermove",t=>{this.eventBus.emitEvent(st,{x:t.clientX,y:t.clientY,target:t.target})}),document.addEventListener("pointerdown",t=>{this.eventBus.emitEvent(nt,{x:t.clientX,y:t.clientY,target:t.target})}),document.addEventListener("pointerup",t=>{this.eventBus.emitEvent(rt,{x:t.clientX,y:t.clientY,target:t.target})})}tick(t){let e=(t-this.previousTime)/1e3;e>.016&&(e=1/60),this.previousTime=t,this.eventBus.reset(),this.subscribeToEvents(),this.read(),this.update(t,e),this.render(),requestAnimationFrame(this.tick.bind(this))}subscribeToEvents(){this.eventBus.subscribeToEvent(at,this.onNodeAdded.bind(this)),this.eventBus.subscribeToEvent(_t,this.onNodeRemoved.bind(this)),this.eventBus.subscribeToEvent(Lt,this.onDataChanged.bind(this)),this.registry.getPlugins().forEach(t=>{t.subscribeToEvents(this.eventBus)})}onNodeAdded({node:t}){this.registry.queueNodeToBeCreated(t)}onNodeRemoved({node:t}){this.registry.queueNodeToBeRemoved(t)}onDataChanged(t){this.registry.notifyPluginAboutDataChange(t)}read(){this.registry.getViews().forEach(t=>{t.read()})}update(t,e){this.registry.update(),this.registry.getPlugins().slice().reverse().forEach(i=>{i.init()}),this.registry.getRenderablePlugins().forEach(i=>{i.update(t,e)}),this.registry.getViews().forEach(i=>{i.update(t,e)}),this.registry.getViews().forEach(i=>{i._updatePreviousRect()})}render(){this.registry.getRenderablePlugins().forEach(t=>{t.render()}),this.registry.getViews().forEach(t=>{t.render()})}}function qe(){return St.create()}class Ht{constructor(t){a(this,"view"),a(this,"previousX"),a(this,"previousY"),a(this,"x"),a(this,"y"),a(this,"pointerX"),a(this,"pointerY"),a(this,"isDragging"),a(this,"target"),a(this,"directions",[]),a(this,"width"),a(this,"height"),a(this,"distance"),a(this,"stopped"),a(this,"hasMoved"),this.props=t,this.previousX=t.previousX,this.previousY=t.previousY,this.x=t.x,this.y=t.y,this.pointerX=t.pointerX,this.pointerY=t.pointerY,this.width=t.width,this.height=t.height,this.distance=t.distance,this.view=t.view,this.isDragging=t.isDragging,this.stopped=t.stopped,this.target=t.target,this.directions=t.directions,this.hasMoved=t.hasMoved}}class Ut extends vt{constructor(){super(...arguments),a(this,"_pointerX",0),a(this,"_pointerY",0),a(this,"_initialPointer",new u(0,0)),a(this,"_initialPointerPerView",new Map),a(this,"_pointerDownPerView",new Map),a(this,"_viewPointerPositionLog",new Map),a(this,"_stopTimer",0)}setup(){document.addEventListener("selectstart",this.onSelect.bind(this))}onSelect(t){this._isDragging&&t.preventDefault()}get _isDragging(){return Array.from(this._pointerDownPerView.values()).some(t=>!!t)}subscribeToEvents(t){t.subscribeToEvent(nt,({x:e,y:i})=>{this._initialPointer=new u(e,i),this.getViews().forEach(s=>{this._pointerDownPerView.set(s.id,s.intersects(e,i));const n=s.isLayoutTransitionEnabled?s.position.initialX:s.position.x,o=s.isLayoutTransitionEnabled?s.position.initialY:s.position.y,l=new u(e-n,i-o);this._pointerX=e,this._pointerY=i,this._initialPointerPerView.set(s.id,l)})}),t.subscribeToEvent(rt,()=>{this.getViews().forEach(e=>{this._pointerDownPerView.get(e.id)&&this._initialPointerPerView.get(e.id)&&(this._pointerDownPerView.set(e.id,!1),this._emitEvent(e,[]))})}),t.subscribeToEvent(st,({x:e,y:i})=>{this._pointerX=e,this._pointerY=i,this.getViews().forEach(s=>{if(this._pointerDownPerView.get(s.id)&&this._initialPointerPerView.get(s.id)){this._viewPointerPositionLog.has(s.id)||this._viewPointerPositionLog.set(s.id,[]);const n=new u(e,i),o=this._viewPointerPositionLog.get(s.id);o&&o.push(new u(e,i));const l=o&&o.length>=2?o[o.length-2]:n.clone(),h=this._calculateDirections(l,n);this._emitEvent(s,h),clearTimeout(this._stopTimer),this._stopTimer=setTimeout(()=>{this._pointerDownPerView.get(s.id)===!0&&this._emitEvent(s,h,!0)},120)}})})}_emitEvent(t,e,i=!1){const s=this._viewPointerPositionLog.get(t.id),n=!(typeof s>"u"||s.length<=1),o=s&&s.length>=2?s[s.length-2]:null,l=this._pointerX-this._initialPointerPerView.get(t.id).x,h=this._pointerY-this._initialPointerPerView.get(t.id).y,g=this._pointerX,c=this._pointerY,p=o?o.x-this._initialPointerPerView.get(t.id).x:l,f=o?o.y-this._initialPointerPerView.get(t.id).y:h,V=this._pointerY-this._initialPointer.y,w=this._pointerX-this._initialPointer.x,P=ue(this._initialPointer,{x:this._pointerX,y:this._pointerY}),C=this._pointerDownPerView.get(t.id)===!0;C||this._viewPointerPositionLog.clear();const M={view:t,target:t.element,previousX:p,previousY:f,x:l,y:h,pointerX:g,pointerY:c,distance:P,width:w,height:V,isDragging:C,directions:e,stopped:i,hasMoved:n};this.emit(Ht,M)}_calculateDirections(t,e){const i={up:u.sub(new u(t.x,t.y-1),t),down:u.sub(new u(t.x,t.y+1),t),left:u.sub(new u(t.x-1,t.y),t),right:u.sub(new u(t.x+1,t.y),t)},s=u.sub(e,t).unitVector;return[{direction:"up",projection:s.dot(i.up)},{direction:"down",projection:s.dot(i.down)},{direction:"left",projection:s.dot(i.left)},{direction:"right",projection:s.dot(i.right)}].filter(n=>n.projection>0).map(n=>n.direction)}}a(Ut,"pluginName","DragEventPlugin");class He{constructor(t){a(this,"view"),a(this,"direction"),this.props=t,this.view=t.view,this.direction=t.direction}}class Ue extends vt{constructor(){super(...arguments),a(this,"_viewIsPointerDownMap",new Map),a(this,"_viewPointerPositionLog",new Map),a(this,"_targetPerView",new Map)}subscribeToEvents(t){t.subscribeToEvent(nt,({x:e,y:i,target:s})=>{this.getViews().forEach(n=>{this._targetPerView.set(n.id,s),n.intersects(e,i)&&this._viewIsPointerDownMap.set(n.id,!0)})}),t.subscribeToEvent(st,({x:e,y:i})=>{this.getViews().forEach(s=>{this._viewIsPointerDownMap.get(s.id)&&(this._viewPointerPositionLog.has(s.id)||this._viewPointerPositionLog.set(s.id,[]),this._viewPointerPositionLog.get(s.id).push(new u(e,i)))})}),t.subscribeToEvent(rt,({x:e,y:i})=>{this.getViews().forEach(n=>{if(!this._viewIsPointerDownMap.get(n.id)||!this._viewPointerPositionLog.has(n.id))return;const o=new u(e,i),l=this._viewPointerPositionLog.get(n.id),h=l[l.length-2]||o.clone(),g=this._targetPerView.get(n.id),c=s(h,o);g&&n.hasElement(g)&&c.hasSwiped&&this.emit(He,{view:n,direction:c.direction}),this._viewPointerPositionLog.set(n.id,[]),this._viewIsPointerDownMap.set(n.id,!1)});function s(n,o){const l={up:u.sub(new u(n.x,n.y-1),n),down:u.sub(new u(n.x,n.y+1),n),left:u.sub(new u(n.x-1,n.y),n),right:u.sub(new u(n.x+1,n.y),n)},h=u.sub(o,n).unitVector,g=["up","down","left","right"],c=[h.dot(l.up),h.dot(l.down),h.dot(l.left),h.dot(l.right)],p=Math.max(...c),f=c.indexOf(p),V=g[f],w=u.sub(o,n).magnitude;return{hasSwiped:h.dot(l[V])*w>30,direction:V}}})}}a(Ue,"pluginName","SwipeEventPlugin");class Ye{constructor(t){a(this,"view"),this.props=t,this.view=t.view}}class Xe extends vt{subscribeToEvents(t){t.subscribeToEvent(pt,({x:e,y:i,target:s})=>{this.getViews().forEach(n=>{const o=s,l=n.element===o||n.element.contains(o);n.intersects(e,i)&&l&&this.emit(Ye,{view:n})})})}}a(Xe,"pluginName","ClickEventPlugin");const je=Object.freeze(Object.defineProperty({__proto__:null,PointerClickEvent:pt,PointerDownEvent:nt,PointerMoveEvent:st,PointerUpEvent:rt},Symbol.toStringTag,{value:"Module"}));function Ke(r){let t=Yt(r)||window;t===document.body&&(t=window);let e=0,i=0,s=!1,n=()=>{};return t.addEventListener("scroll",()=>{s&&n()}),{container:t,onScroll(o){n=o},startScrollTracking(){s||(e=t instanceof Element?t.scrollTop:t.scrollY,i=t instanceof Element?t.scrollLeft:t.scrollX,s=!0)},getScrollOffset(){const o=t instanceof Element?t.scrollTop:t.scrollY;return{x:(t instanceof Element?t.scrollLeft:t.scrollX)-i,y:o-e}},endScrollTracking(){e=0,i=0,s=!1},width:t instanceof Element?t.clientWidth:t.innerWidth,height:t instanceof Element?t.clientHeight:t.innerHeight}}function Yt(r){const e=r instanceof HTMLElement&&window.getComputedStyle(r).overflowY,i=e!=="visible"&&e!=="hidden";if(r){if(i&&r.scrollHeight>=r.clientHeight)return r}else return null;return Yt(r.parentNode)||document.body}class ut{constructor(t){R(this,"data");this.data=t.data}}class Xt{constructor(t){R(this,"data");R(this,"hasChanged");this.data=t.data,this.hasChanged=t.hasChanged}}class jt{}class Kt{constructor(t){R(this,"data");this.data=t.data}}function K(r){return{map:new Map(r),array:Array.from(r).map(([e,i])=>({slotId:e,itemId:i})),object:Array.from(r).reduce((e,[i,s])=>(e[i]=s,e),{})}}function Ge(r){if(r.map)return{map:new Map(r.map),array:Array.from(r.map).map(([e,i])=>({slotId:e,itemId:i})),object:Array.from(r.map).reduce((e,[i,s])=>(e[i]=s,e),{})};if(r.object){const t={...r.object};return{map:new Map(Object.entries(t)),array:Object.entries(t).map(([e,i])=>({slotId:e,itemId:i})),object:t}}else{const t=[...r.array];return{map:new Map(t.map(({slotId:e,itemId:i})=>[e,i])),array:t,object:t.reduce((e,{slotId:i,itemId:s})=>(e[i]=s,e),{})}}}const I=r=>{const t=r.useEventPlugin(Ut);t.on(Ht,H);const e=20,i=100;let s,n,o,l,h,g=null,c=new Map,p=new Map,f,V,w=null,P=null,C,M,G=!0,x,ct,dt,S,N=!1,A=!1,B=()=>{},$=!1,L=0,W=0;r.api({setEnabled(d){G=d},setData(d){const m=Ge(d);c=new Map(m.map),p=new Map(c)},setAutoScrollOnDrag(d){$=d}});function q(){return{animation:s.data.configAnimation,continuousMode:typeof s.data.configContinuousMode<"u",manualSwap:typeof s.data.configManualSwap<"u",swapMode:s.data.configSwapMode,autoScrollOnDrag:$}}function Z(){const d=q().animation;return d==="dynamic"?{animator:"dynamic",config:{}}:d==="spring"?{animator:"spring",config:{damping:.7,stiffness:.62}}:d==="none"?{animator:"instant",config:{}}:{animator:"instant",config:{}}}function J(d){return()=>{c=d,p=new Map(c)}}r.setup(()=>{s=r.getView("root"),o=r.getViews("slot"),l=r.getViews("item"),n=Ke(l[0].element),n.onScroll(()=>{F()}),ct=q().continuousMode,dt=q().manualSwap,o.forEach(d=>{Q(d)}),z(),p=new Map(c),requestAnimationFrame(()=>{r.emit(Kt,{data:K(c)})})});function Q(d){const m=d.getChild("item");m&>(m),c.set(d.element.dataset.swapySlot,m?m.element.dataset.swapyItem:null)}function gt(d){const m=Z();d.styles.position="relative",d.styles.userSelect="none",d.styles.webkitUserSelect="none",d.position.setAnimator(m.animator,m.config),d.scale.setAnimator(m.animator,m.config),d.layoutTransition(!0),requestAnimationFrame(()=>{const v=d.getChild("handle");v?(t.addView(v),v.styles.touchAction="none"):(t.addView(d),d.styles.touchAction="none")})}r.onViewAdded(d=>{if(r.initialized)if(d.name==="item"){l=r.getViews("item");const m=d.getParent("slot");Q(m),z(),p=new Map(c),r.emit(ut,{data:K(c)})}else d.name==="slot"&&(o=r.getViews("slot"))});function z(){const d=Z();r.getViews("root-child").forEach(v=>{v.position.setAnimator(d.animator,d.config),v.scale.setAnimator(d.animator,d.config),v.layoutTransition(!0)})}function F(){if(!x)return;if(!f||!V){const et=h.getScroll();f=x.pointerX-h.position.x+et.x,V=x.pointerY-h.position.y+et.y}(!C||!M)&&(C=h.size.width,M=h.size.height);const d=h.size.width/C,m=h.size.height/M,v=f*(d-1),tt=V*(m-1),{x:y,y:U}=n.getScrollOffset();h.position.set({x:x.x-v-(w||0)+y,y:x.y-tt-(P||0)+U},h.scale.x!==1||h.scale.y!==1)}r.subscribeToEvents(d=>{d.subscribeToEvent(je.PointerMoveEvent,({x:m,y:v})=>{n&&(n.height-v<=i?L=Math.max(0,e*(1-Math.min(n.height-v,i)/i)):v<=i?L=-1*Math.max(0,e*(1-Math.min(v,i)/i)):L=0,n.width-m<=i?W=Math.max(0,e*(1-Math.min(n.width-m,i)/i)):m<=i?W=-1*Math.max(0,e*(1-Math.min(m,i)/i)):W=0)})}),r.update(()=>{x!=null&&x.isDragging&&$&&n.container.scrollBy({top:L,left:W})});function H(d){if(!G||!d.hasMoved)return;const m=q().swapMode,v=d.view.name==="handle";if(h=v?d.view.getParent("item"):d.view,S||(S=h.getParent("slot")),w===null&&P===null){const y=v?d.view.position.initialX-d.view.position.x:0,U=v?d.view.position.initialY-d.view.position.y:0;w=d.view.position.x-h.position.x-y,P=d.view.position.y-h.position.y-U}const tt=o.some(y=>y.intersects(d.pointerX,d.pointerY));d.isDragging?(n.startScrollTracking(),N||(N=!0,r.emit(jt,{})),g===null&&(g=new Map(c)),x=d,F(),o.forEach(y=>{var Zt;if(!y.intersects(d.pointerX,d.pointerY)){y!==S&&y.element.removeAttribute("data-swapy-highlighted");return}if(typeof y.element.dataset.swapyHighlighted>"u"&&(y.element.dataset.swapyHighlighted=""),!S||(m==="stop"||m!=="drop"&&!ct)&&!d.stopped)return;const U=y.element.dataset.swapySlot,et=(Zt=y.getChild("item"))==null?void 0:Zt.element.dataset.swapyItem,Ct=S.element.dataset.swapySlot,Gt=h.element.dataset.swapyItem;if(!U||!Ct||!Gt)return;const Y=new Map(c);Y.set(U,Gt),et?Y.set(Ct,et):Y.set(Ct,null),B=J(new Map(Y)),b(Y,p)||(!dt&&m!=="drop"&&B(),S=null,m!=="drop"&&r.emit(ut,{data:K(Y)}))}),l.forEach(y=>{y.styles.zIndex=y===h?"2":""})):(o.forEach(y=>{y.element.removeAttribute("data-swapy-highlighted")}),h.position.reset(),S=null,f=null,V=null,C=null,M=null,x=null,w=null,P=null,N=!1,m==="drop"&&(tt||(B=J(new Map(c))),B(),r.emit(ut,{data:K(c)})),B=()=>{},A=!b(c,g),r.emit(Xt,{data:K(c),hasChanged:A}),A=!1,g=null,n.endScrollTracking()),requestAnimationFrame(()=>{F()})}};I.pluginName="Swapy",I.scope="root";let O;function Ze(){return O?(O.updatePlugin(I),O):(O=qe(),O.addPlugin(I),O.run(),O)}const Je={animation:"dynamic",continuousMode:!0,manualSwap:!1,swapMode:"hover",autoScrollOnDrag:!1};function Qe(r){let t=!0;const e=r.querySelectorAll("[data-swapy-slot]");return e.length===0&&(console.error("There are no slots defined in your root element:",r),t=!1),e.forEach(i=>{const s=i,n=s.dataset.swapySlot;(!n||n.length===0)&&(console.error(i,"does not contain a slotId using data-swapy-slot"),t=!1);const o=s.children;o.length>1&&(console.error("slot:",`"${n}"`,"cannot contain more than one element"),t=!1);const l=o[0];l&&(!l.dataset.swapyItem||l.dataset.swapyItem.length===0)&&(console.error("slot:",`"${n}"`,"does not contain an element with item id using data-swapy-item"),t=!1)}),t}function ti(r,t={}){const e=Jt();return r.dataset.velPluginKey=e,r.dataset.velPlugin="Swapy",r.dataset.velView="root",r.dataset.velDataConfigAnimation=t.animation,r.dataset.velDataConfigSwapMode=t.swapMode,t.continuousMode&&(r.dataset.velDataConfigContinuousMode="true"),t.manualSwap&&(r.dataset.velDataConfigManualSwap="true"),Array.from(r.querySelectorAll("[data-swapy-slot]")).forEach(l=>{l.dataset.velView="slot"}),Array.from(r.querySelectorAll("[data-swapy-item]")).forEach(l=>{l.dataset.velView="item",l.dataset.velLayoutId=l.dataset.swapyItem;const h=l.querySelector("[data-swapy-handle]");h&&(h.dataset.velView="handle")}),Array.from(r.querySelectorAll("[data-swapy-text]")).forEach(l=>{l.dataset.velLayoutPosition=""}),Array.from(r.querySelectorAll("[data-swapy-exclude]")).forEach(l=>{l.dataset.velIgnore=""}),e}function ei(r){const t=Array.from(r.querySelectorAll("[data-swapy-slot]:not([data-vel-view])"));t.forEach(i=>{i.dataset.velView="slot"});const e=Array.from(r.querySelectorAll("[data-swapy-item]:not([data-vel-view])"));return e.forEach(i=>{i.dataset.velView="item",i.dataset.velLayoutId=i.dataset.swapyItem;const s=i.querySelector("[data-swapy-handle]");s&&(s.dataset.velView="handle"),Array.from(i.querySelectorAll("[data-swapy-text]")).forEach(l=>{l.dataset.velLayoutPosition=""}),Array.from(i.querySelectorAll("[data-swapy-exclude]")).forEach(l=>{l.dataset.velIgnore=""})}),e.length>0||t.length>0}function ii(r,t={}){if(!r)throw new Error("Cannot create a Swapy instance because the element you provided does not exist on the page!");const e={...Je,...t},i=r;if(!Qe(i))throw new Error("Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!");const s=ti(i,e),n=new si(i,s,e);return{onSwap(o){n.setSwapCallback(o)},onSwapEnd(o){n.setSwapEndCallback(o)},onSwapStart(o){n.setSwapStartCallback(o)},enable(o){n.setEnabled(o)},destroy(){n.destroy()},setData(o){n.setData(o)}}}class si{constructor(t,e,i){R(this,"_rootEl");R(this,"_veloxiApp");R(this,"_slotElMap");R(this,"_itemElMap");R(this,"_swapCallback");R(this,"_swapEndCallback");R(this,"_swapStartCallback");R(this,"_previousMap");R(this,"_pluginKey");this._rootEl=t,this._veloxiApp=Ze(),this._slotElMap=this._createSlotElMap(),this._itemElMap=this._createItemElMap(),this.setAutoScrollOnDrag(i.autoScrollOnDrag),this._pluginKey=e,this._veloxiApp.onPluginEvent(I,Kt,({data:s})=>{this._previousMap=s.map},e),this._veloxiApp.onPluginEvent(I,ut,s=>{var n;this._previousMap&&b(this._previousMap,s.data.map)||(i.manualSwap||this._applyOrder(s.data.map),this._previousMap=s.data.map,(n=this._swapCallback)==null||n.call(this,s))},e),this._veloxiApp.onPluginEvent(I,Xt,s=>{var n;(n=this._swapEndCallback)==null||n.call(this,s)},e),this._veloxiApp.onPluginEvent(I,jt,()=>{var s;(s=this._swapStartCallback)==null||s.call(this)},e),this.setupMutationObserver()}setupMutationObserver(){new MutationObserver(e=>{e.some(i=>i.type==="childList")&&ei(this._rootEl)&&(this._slotElMap=this._createSlotElMap(),this._itemElMap=this._createItemElMap())}).observe(this._rootEl,{childList:!0,subtree:!0})}setData(t){try{this._veloxiApp.getPlugin("Swapy",this._pluginKey).setData(t)}catch{}}destroy(){this._veloxiApp.destroy("Swapy")}setEnabled(t){requestAnimationFrame(()=>{try{this._veloxiApp.getPlugin("Swapy",this._pluginKey).setEnabled(t)}catch{}})}setAutoScrollOnDrag(t){requestAnimationFrame(()=>{try{this._veloxiApp.getPlugin("Swapy",this._pluginKey).setAutoScrollOnDrag(t)}catch{}})}setSwapCallback(t){this._swapCallback=t}setSwapEndCallback(t){this._swapEndCallback=t}setSwapStartCallback(t){this._swapStartCallback=t}_applyOrder(t){Array.from(t.keys()).forEach(e=>{var o;if(t.get(e)===((o=this._previousMap)==null?void 0:o.get(e)))return;const i=t.get(e);if(!i)return;const s=this._slotElMap.get(e),n=this._itemElMap.get(i);!s||!n||(s.innerHTML="",s.appendChild(n))})}_createSlotElMap(){return Array.from(this._rootEl.querySelectorAll("[data-swapy-slot]")).reduce((t,e)=>(t.set(e.dataset.swapySlot,e),t),new Map)}_createItemElMap(){return Array.from(this._rootEl.querySelectorAll("[data-swapy-item]")).reduce((t,e)=>(t.set(e.dataset.swapyItem,e),t),new Map)}}T.createSwapy=ii,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}); diff --git a/examples/basic/index.html b/examples/basic/index.html deleted file mode 100644 index 81d406e..0000000 --- a/examples/basic/index.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - Basic Swapy Example - - -
- -
-
-
-
-
-
A
-
-
-
-
- -
-
-
-
C
-
-
-
-
-
-
D
-
-
-
-
-
-
-
-
A
-
-
-
-
- -
-
-
-
C
-
-
-
-
-
-
D
-
-
-
- - - diff --git a/examples/basic/main.ts b/examples/basic/main.ts deleted file mode 100644 index c2957ab..0000000 --- a/examples/basic/main.ts +++ /dev/null @@ -1,46 +0,0 @@ -import './style.css' -import { createSwapy } from '../../src' - -const container = document.querySelector('.container-1')! -const container2 = document.querySelector('.container-2')! -const enableInput = document.querySelector('#enable')! as HTMLInputElement - -const swapy = createSwapy(container, { - animation: 'dynamic', - swapMode: 'drop' -}) - -const swapy2 = createSwapy(container2, { - animation: 'spring' -}) - -swapy2.onSwap((event) => { - console.log('swapy2 event', event.data) -}) - -swapy2.onSwapStart(() => { - console.log('SWAP2 STARTED') -}) - -swapy2.onSwapEnd((event) => { - console.log('SWAP2 END', event) -}) - -swapy.enable(false) -swapy.onSwap((event) => { - console.log('event.map', event.data.map) - console.log('event.object', event.data.object) - console.log('event.array', event.data.array) -}) - -swapy.onSwapStart(() => { - console.log('SWAP STARTED') -}) - -swapy.onSwapEnd((event) => { - console.log('SWAP END', event) -}) - -enableInput.addEventListener('input', () => { - swapy.enable(enableInput.checked) -}) diff --git a/examples/basic/style.css b/examples/basic/style.css deleted file mode 100644 index 438e490..0000000 --- a/examples/basic/style.css +++ /dev/null @@ -1,106 +0,0 @@ -* { - box-sizing: border-box; -} - -:root { - background: #242424; -} - -body { - font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, - Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; - width: 100%; - min-height: 150dvh; - display: flex; - justify-content: center; - align-items: center; - padding: 0; - margin: 0; -} - -.container { - display: flex; - flex-direction: column; - gap: 5px; - width: 100%; - max-width: 500px; - padding: 10px; -} - -.second-row { - display: flex; - gap: 5px; -} - -.slot { - background: #111; - flex: 1; -} - -.slot.a { - flex-basis: 150px; - height: 150px; -} - -.slot.b { - flex: 2; -} - -.second-row { - height: 100px; -} - -.slot.d { - flex-basis: 120px; - height: 120px; -} - -.item { - position: relative; - width: 100%; - height: 100%; - display: flex; - align-items: center; - justify-content: center; - color: white; - font-size: 40px; - cursor: pointer; - user-select: none; - -webkit-user-select: none; -} - -.item.a { - background: #b95050; -} - -.item.b { - background: #50b97f; -} - -.item.c { - background: #508db9; -} - -.item.d { - background: #b95096; -} - -[data-swapy-highlighted] { - background: #444; -} - -.handle { - position: absolute; - left: 0; - top: 0; - width: 20px; - height: 100%; - background: rgba(0, 0, 0, 0.5); -} - -.enable-input { - position: fixed; - top: 0; - left: 0; - padding: 10px; -} diff --git a/examples/react-dynamic/App.tsx b/examples/react-dynamic/App.tsx index 1165cae..a537b14 100644 --- a/examples/react-dynamic/App.tsx +++ b/examples/react-dynamic/App.tsx @@ -1,115 +1,73 @@ -import { useEffect } from 'react' +import { useEffect, useMemo, useRef, useState } from 'react' import './style.css' -import { createSwapy, SlotItemMap, Swapy } from '../../src/index' -import { useState } from 'react' -import { useMemo } from 'react' -import { useRef } from 'react' +import { SlotItemMapArray, Swapy, utils } from '../../src' +import { createSwapy } from '../../src' -function App() { - const swapyRef = useRef(null) - - // Your items. - const [items, setItems] = useState([ - { id: '1', title: 'A' }, - { id: '2', title: 'B' }, - { id: '3', title: 'C' }, - ]) - - // Define a state for maintain the mapping between slots and items. - const [slotItemsMap, setSlotItemsMap] = useState([...items.map(item => ({ - slotId: item.id, - itemId: item.id - })), - // Defining an empty slot by setting itemId to null. - { slotId: `${Math.round(Math.random() * 99999)}`, itemId: null } - ]) - - // This is what you'll use to display your items. - const slottedItems = useMemo(() => slotItemsMap.map(({ slotId, itemId }) => ({ - slotId, - itemId, - item: items.find(item => item.id === itemId) - })), [items, slotItemsMap]) +type Item = { + id: string + title: string +} - useEffect(() => { - // Get the newly added items and convert them to slotItem objects - const newItems = items.filter(item => !slotItemsMap.some(slotItem => slotItem.itemId === item.id)).map(item => ({ - slotId: item.id, - itemId: item.id - })) +const initialItems: Item[] = [ + { id: '1', title: '1' }, + { id: '2', title: '2' }, + { id: '3', title: '3' }, +] - // Remove items from slotItemsMap if they no longer exist in items - const withoutRemovedItems = slotItemsMap.filter(slotItem => - items.some(item => item.id === slotItem.itemId) || !slotItem.itemId - ) +let id = 4 - /******* Below is how you would remove items and keep their slots empty ******/ - // const withoutRemovedItems = slotItemsMap.map(slotItem => { - // if (!items.some(item => item.id === slotItem.itemId)) { - // return { slotId: slotItem.slotId, itemId: null } - // } - // return slotItem - // }) +function App() { + const [items, setItems] = useState(initialItems) + const [slotItemMap, setSlotItemMap] = useState(utils.initSlotItemMap(items, 'id')) + const slottedItems = useMemo(() => utils.toSlottedItems(items, 'id', slotItemMap), [items, slotItemMap]) + const swapyRef = useRef(null) - const updatedSlotItemsMap = [...withoutRemovedItems, ...newItems] + const containerRef = useRef(null) - setSlotItemsMap(updatedSlotItemsMap) - swapyRef.current?.setData({ array: updatedSlotItemsMap }) - }, [items]) + useEffect(() => utils.dynamicSwapy(swapyRef.current, items, 'id', slotItemMap, setSlotItemMap), [items]) useEffect(() => { - const container = document.querySelector('.container')! - swapyRef.current = createSwapy(container, { + swapyRef.current = createSwapy(containerRef.current!, { manualSwap: true, - swapMode: 'hover', - autoScrollOnDrag: true + // animation: 'dynamic' + // autoScrollOnDrag: true, + // swapMode: 'drop', + // enabled: true, + // dragAxis: 'x', + // dragOnHold: true }) - swapyRef.current.onSwap(({ data }) => { - // You need to call setData because it's a manualSwap instance - swapyRef.current?.setData({ array: data.array }) - setSlotItemsMap(data.array) + swapyRef.current.onSwap((event) => { + setSlotItemMap(event.newSlotItemMap.asArray) }) return () => { swapyRef.current?.destroy() } }, []) - return ( -
- - {/* ADD BUTTON */} - - -
- {slottedItems.map(({ itemId, slotId, item }) => ( -
- - {/* ITEM */} - {item ? +
+
+ {slottedItems.map(({ slotId, itemId, item }) => ( +
+ {item &&
-
-
{item.title}
- - {/* DELETE ITEM BUTTON */} - - + {item.title} + { + setItems(items.filter(i => i.id !== item.id)) + }}>
- : null} + }
))}
+
{ + const newItem: Item = { id: `${id}`, title: `${id}` } + setItems([...items, newItem]) + id++ + }}>+
) } -export default App +export default App \ No newline at end of file diff --git a/examples/react-dynamic/delete.svg b/examples/react-dynamic/delete.svg new file mode 100644 index 0000000..3db803f --- /dev/null +++ b/examples/react-dynamic/delete.svg @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/examples/react-dynamic/handle.svg b/examples/react-dynamic/handle.svg new file mode 100644 index 0000000..0577114 --- /dev/null +++ b/examples/react-dynamic/handle.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/examples/react-dynamic/index.html b/examples/react-dynamic/index.html index eb5be82..a01f4d5 100644 --- a/examples/react-dynamic/index.html +++ b/examples/react-dynamic/index.html @@ -3,11 +3,7 @@ - React Swapy Example - + React (Dynamic) Swapy Example
diff --git a/examples/react-dynamic/main.tsx b/examples/react-dynamic/main.tsx index a6dcfdc..bc1beb5 100644 --- a/examples/react-dynamic/main.tsx +++ b/examples/react-dynamic/main.tsx @@ -6,4 +6,4 @@ createRoot(document.getElementById('app')!).render( , -) +) \ No newline at end of file diff --git a/examples/react-dynamic/style.css b/examples/react-dynamic/style.css index b7b148f..815a063 100644 --- a/examples/react-dynamic/style.css +++ b/examples/react-dynamic/style.css @@ -2,99 +2,112 @@ box-sizing: border-box; } -:root { - background: #242424; +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; } -body, -#app { - font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, - Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; - width: 100%; - min-height: 100dvh; +body { + background: #02040f; display: flex; + flex-direction: column; justify-content: center; align-items: center; - padding: 0; - margin: 0; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; } -.app { +#app { width: 100%; - max-width: 600px; } .container { + max-width: 800px; + width: 100%; display: flex; flex-direction: column; - gap: 5px; - width: 100%; - max-width: 500px; - padding: 10px; + gap: 10px; + margin: 0 auto; } -.second-row { - display: flex; - gap: 5px; +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; + height: 100px; } -.slot { - background: #111; - flex: 1; - flex-basis: 80px; - height: 80px; +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); +} + +.items { + display: grid; + grid-template-columns: 2fr 1fr; + gap: 10px; } .item { - width: 100%; - height: 100%; + position: relative; display: flex; + flex-direction: column; align-items: center; justify-content: center; - color: white; - font-size: 40px; - user-select: none; - -webkit-user-select: none; - position: relative; - background: #508db9; + background: #4338ca; + padding: 20px 0; + border-radius: 10px; + width: 100%; + height: 100%; } -[data-swapy-highlighted] { - background: #444; +/* .item-2 { + height: 50px; +} */ + +.item:has(.handle) { + position: relative; } .handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; position: absolute; - left: 0; - top: 0; - width: 40px; - height: 100%; - background: rgba(0, 0, 0, 0.5); - cursor: pointer; + top: 14px; + left: 10px; } -.add { - position: fixed; - top: 10px; - left: 10px; - border-radius: 5px; - background: white; - width: 100px; - padding: 5px 0; +.item.item--add { + background: transparent; + border: 4px solid #4338ca; cursor: pointer; + user-select: none; +} + +.item.item--add:hover { + background: #4338cacc; } .delete { - color: #222; - background: rgba(255, 255, 255, 0.5); - width: 30px; - height: 30px; - font-size: 18px; - border-radius: 50%; + background-color: hsl(244.5, 57.9%, 45.6%); position: absolute; + right: 20px; top: 10px; - right: 10px; - display: flex; - align-items: center; - justify-content: center; + height: 38px; + width: 38px; + border-radius: 50%; + background-image: url(./delete.svg); + background-size: 22px 22px; + background-position: 50% 50%; + background-repeat: no-repeat; + cursor: pointer; +} + +.delete:hover { + background-color: hsl(244.5, 57.9%, 40.6%); } diff --git a/examples/react/App.tsx b/examples/react/App.tsx index 77c8503..0716aa2 100644 --- a/examples/react/App.tsx +++ b/examples/react/App.tsx @@ -1,97 +1,72 @@ -import { useEffect } from 'react' +import { useEffect, useRef } from 'react' import './style.css' -import { createSwapy } from '../../src/index' - -const DEFAULT = { - '1': 'a', - '3': 'c', - '4': 'd', - '2': null -} - - -function A() { - return ( -
-
-
A
-
- ) -} - -function C() { - return ( -
-
C
-
- ) -} - -function D() { - return ( -
-
D
-
- ) -} - -function getItemById(itemId: 'a' | 'c' | 'd' | null) { - switch (itemId) { - case 'a': - return - case 'c': - return - case 'd': - return - } -} - +import { Swapy } from '../../src' +import { createSwapy } from '../../src' function App() { - const slotItems: Record = localStorage.getItem('slotItem') ? JSON.parse(localStorage.getItem('slotItem')!) : DEFAULT + const swapyRef = useRef(null) + const containerRef = useRef(null) useEffect(() => { - const container = document.querySelector('.container')! - const swapy = createSwapy(container, { - swapMode: 'hover' - }) - swapy.onSwap(({ data }) => { - console.log('swap', data); - localStorage.setItem('slotItem', JSON.stringify(data.object)) - }) + if (containerRef.current) { + swapyRef.current = createSwapy(containerRef.current, { + // animation: 'dynamic' + // swapMode: 'drop', + // autoScrollOnDrag: true, + // enabled: true, + // dragAxis: 'x', + // dragOnHold: true + }) - swapy.onSwapEnd(({ data, hasChanged }) => { - console.log(hasChanged); - console.log('end', data); - }) + // swapyRef.current.enable(false) + // swapyRef.current.destroy() + // console.log(swapyRef.current.slotItemMap()) - swapy.onSwapStart(() => { - console.log('start') - }) + swapyRef.current.onBeforeSwap((event) => { + console.log('beforeSwap', event) + // This is for dynamically enabling and disabling swapping. + // Return true to allow swapping, and return false to prevent swapping. + return true + }) + swapyRef.current.onSwapStart((event) => { + console.log('start', event); + }) + swapyRef.current.onSwap((event) => { + console.log('swap', event); + }) + swapyRef.current.onSwapEnd((event) => { + console.log('end', event); + }) + } return () => { - swapy.destroy() + swapyRef.current?.destroy() } }, []) - return ( -
-
- {getItemById(slotItems['1'])} +
+
+
+
A
+
-
-
- {getItemById(slotItems['2'])} +
+
+
+
+
B
+
-
- {getItemById(slotItems['3'])} +
-
- {getItemById(slotItems['4'])} +
+
+
D
+
) } -export default App +export default App \ No newline at end of file diff --git a/examples/react/handle.svg b/examples/react/handle.svg new file mode 100644 index 0000000..0577114 --- /dev/null +++ b/examples/react/handle.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/examples/react/index.html b/examples/react/index.html index eb5be82..719382e 100644 --- a/examples/react/index.html +++ b/examples/react/index.html @@ -4,10 +4,6 @@ React Swapy Example -
diff --git a/examples/react/main.tsx b/examples/react/main.tsx index f6c7f06..bc1beb5 100644 --- a/examples/react/main.tsx +++ b/examples/react/main.tsx @@ -1,5 +1,9 @@ import { createRoot } from 'react-dom/client' import App from './App' +import { StrictMode } from 'react' -const root = createRoot(document.getElementById('app')!) -root.render() +createRoot(document.getElementById('app')!).render( + + + , +) \ No newline at end of file diff --git a/examples/react/style.css b/examples/react/style.css index a6683bd..7c1efa3 100644 --- a/examples/react/style.css +++ b/examples/react/style.css @@ -2,106 +2,114 @@ box-sizing: border-box; } -:root { - background: #242424; +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; } -body, #app { - font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, - Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; width: 100%; - min-height: 100dvh; +} + +body { + background: #02040f; display: flex; + flex-direction: column; justify-content: center; align-items: center; - padding: 0; - margin: 0; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; } .container { + max-width: 800px; + width: 100%; display: flex; flex-direction: column; - gap: 5px; - width: 100%; - max-width: 500px; - padding: 10px; + gap: 10px; + margin: 0 auto; } -.second-row { - display: flex; - gap: 5px; +.slot.top { + height: 200px; } -.slot { - background: #111; - flex: 1; +.middle { + height: 250px; + display: flex; + gap: 10px; } -.slot.a { - flex-basis: 150px; - height: 150px; +.slot.middle-left { + height: 100%; + flex: 1; } -.slot.b { +.slot.middle-right { + height: 100%; flex: 2; } -.second-row { - height: 100px; +.slot.bottom { + height: 150px; } -.slot.d { - flex-basis: 120px; - height: 120px; +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; +} +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); } .item { - width: 100%; - height: 100%; display: flex; + flex-direction: column; align-items: center; justify-content: center; - color: white; - font-size: 40px; - cursor: pointer; - user-select: none; - -webkit-user-select: none; - position: relative; } -.item.a { - background: #b95050; +.item { + border-radius: 10px; + width: 100%; + height: 100%; } -.item.b { - background: #50b97f; +.item-a { + background: #10b981; } -.item.c { - background: #508db9; +.item-b { + background: #be123c; } -.item.d { - background: #b95096; +.item-c { + background: #4338ca; } -[data-swapy-highlighted] { - background: #444; +.item-d { + background: #7e22ce; +} + +.item:has(.handle) { + position: relative; } .handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; position: absolute; - left: 0; - top: 0; - width: 20px; - height: 100%; - background: rgba(0, 0, 0, 0.5); + top: 14px; + left: 10px; } -.enable-input { - position: fixed; - top: 0; - left: 0; - padding: 10px; -} +/* .item[data-swapy-dragging] { + opacity: 0.8; +} */ diff --git a/examples/svelte-dynamic/App.svelte b/examples/svelte-dynamic/App.svelte new file mode 100644 index 0000000..7b6218f --- /dev/null +++ b/examples/svelte-dynamic/App.svelte @@ -0,0 +1,108 @@ + + +
+
+ {#each slottedItems as { slotId, itemId, item }} + {#key slotId} +
+ {#if item} + {#key itemId} +
+ {item.title} + +
+ {/key} + {/if} +
+ {/key} + {/each} +
+ +
diff --git a/examples/svelte-dynamic/delete.svg b/examples/svelte-dynamic/delete.svg new file mode 100644 index 0000000..3db803f --- /dev/null +++ b/examples/svelte-dynamic/delete.svg @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/examples/svelte-dynamic/handle.svg b/examples/svelte-dynamic/handle.svg new file mode 100644 index 0000000..0577114 --- /dev/null +++ b/examples/svelte-dynamic/handle.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/examples/svelte-dynamic/index.html b/examples/svelte-dynamic/index.html new file mode 100644 index 0000000..f253869 --- /dev/null +++ b/examples/svelte-dynamic/index.html @@ -0,0 +1,12 @@ + + + + + + Svelte (Dynamic) Swapy Example + + +
+ + + diff --git a/examples/svelte-dynamic/main.ts b/examples/svelte-dynamic/main.ts new file mode 100644 index 0000000..21f24e7 --- /dev/null +++ b/examples/svelte-dynamic/main.ts @@ -0,0 +1,8 @@ +import { mount } from 'svelte' +import App from './App.svelte' + +const app = mount(App, { + target: document.getElementById('app')! +}) + +export default app diff --git a/examples/svelte-dynamic/style.css b/examples/svelte-dynamic/style.css new file mode 100644 index 0000000..9450074 --- /dev/null +++ b/examples/svelte-dynamic/style.css @@ -0,0 +1,116 @@ +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; +} + +body { + background: #02040f; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; +} + +#app { + width: 100%; +} + +.container { + max-width: 800px; + width: 100%; + display: flex; + flex-direction: column; + gap: 10px; + margin: 0 auto; +} + +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; + height: 100px; +} + +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); +} + +.items { + display: grid; + grid-template-columns: 2fr 1fr; + gap: 10px; +} + +.item { + position: relative; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + background: #4338ca; + padding: 20px 0; + border-radius: 10px; + width: 100%; + height: 100%; +} + +/* .item-2 { + height: 50px; +} */ + +.item:has(.handle) { + position: relative; +} + +.handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; + position: absolute; + top: 14px; + left: 10px; +} + +.item.item--add { + background: transparent; + border: 4px solid #4338ca; + cursor: pointer; + user-select: none; + color: white; + font-size: 50px; +} + +.item.item--add:hover { + background: #4338cacc; +} + +.delete { + background-color: hsl(244.5, 57.9%, 45.6%); + border: none; + position: absolute; + right: 20px; + top: 10px; + height: 38px; + width: 38px; + border-radius: 50%; + background-image: url(./delete.svg); + background-size: 22px 22px; + background-position: 50% 50%; + background-repeat: no-repeat; + cursor: pointer; +} + +.delete:hover { + background-color: hsl(244.5, 57.9%, 40.6%); +} diff --git a/examples/svelte/A.svelte b/examples/svelte/A.svelte deleted file mode 100644 index 907a415..0000000 --- a/examples/svelte/A.svelte +++ /dev/null @@ -1,4 +0,0 @@ -
-
-
A
-
diff --git a/examples/svelte/App.svelte b/examples/svelte/App.svelte index bf7cf38..01950ea 100644 --- a/examples/svelte/App.svelte +++ b/examples/svelte/App.svelte @@ -1,57 +1,69 @@ -
-
- -
-
-
- +
+
+
A
-
- +
+
+
+
+
+
B
+
+
-
- +
+
+
D
+
diff --git a/examples/svelte/C.svelte b/examples/svelte/C.svelte deleted file mode 100644 index 0a64133..0000000 --- a/examples/svelte/C.svelte +++ /dev/null @@ -1,3 +0,0 @@ -
-
C
-
diff --git a/examples/svelte/D.svelte b/examples/svelte/D.svelte deleted file mode 100644 index 00191d4..0000000 --- a/examples/svelte/D.svelte +++ /dev/null @@ -1,3 +0,0 @@ -
-
D
-
diff --git a/examples/svelte/handle.svg b/examples/svelte/handle.svg new file mode 100644 index 0000000..0577114 --- /dev/null +++ b/examples/svelte/handle.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/examples/svelte/index.html b/examples/svelte/index.html index df822ff..e0feb28 100644 --- a/examples/svelte/index.html +++ b/examples/svelte/index.html @@ -4,10 +4,6 @@ Svelte Swapy Example -
diff --git a/examples/svelte/main.ts b/examples/svelte/main.ts index 59f7db3..21f24e7 100644 --- a/examples/svelte/main.ts +++ b/examples/svelte/main.ts @@ -1,6 +1,7 @@ +import { mount } from 'svelte' import App from './App.svelte' -const app = new App({ +const app = mount(App, { target: document.getElementById('app')! }) diff --git a/examples/svelte/style.css b/examples/svelte/style.css index a6683bd..598285a 100644 --- a/examples/svelte/style.css +++ b/examples/svelte/style.css @@ -2,106 +2,114 @@ box-sizing: border-box; } -:root { - background: #242424; +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; } -body, -#app { - font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, - Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; - width: 100%; - min-height: 100dvh; +body { + background: #02040f; display: flex; + flex-direction: column; justify-content: center; align-items: center; - padding: 0; - margin: 0; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; +} + +#app { + width: 100%; } .container { + max-width: 800px; + width: 100%; display: flex; flex-direction: column; - gap: 5px; - width: 100%; - max-width: 500px; - padding: 10px; + gap: 10px; + margin: 0 auto; } -.second-row { - display: flex; - gap: 5px; +.slot.top { + height: 200px; } -.slot { - background: #111; - flex: 1; +.middle { + height: 250px; + display: flex; + gap: 10px; } -.slot.a { - flex-basis: 150px; - height: 150px; +.slot.middle-left { + height: 100%; + flex: 1; } -.slot.b { +.slot.middle-right { + height: 100%; flex: 2; } -.second-row { - height: 100px; +.slot.bottom { + height: 150px; } -.slot.d { - flex-basis: 120px; - height: 120px; +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; +} +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); } .item { - width: 100%; - height: 100%; display: flex; + flex-direction: column; align-items: center; justify-content: center; - color: white; - font-size: 40px; - cursor: pointer; - user-select: none; - -webkit-user-select: none; - position: relative; } -.item.a { - background: #b95050; +.item { + border-radius: 10px; + width: 100%; + height: 100%; +} + +.item-a { + background: #10b981; } -.item.b { - background: #50b97f; +.item-b { + background: #be123c; } -.item.c { - background: #508db9; +.item-c { + background: #4338ca; } -.item.d { - background: #b95096; +.item-d { + background: #7e22ce; } -[data-swapy-highlighted] { - background: #444; +.item:has(.handle) { + position: relative; } .handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; position: absolute; - left: 0; - top: 0; - width: 20px; - height: 100%; - background: rgba(0, 0, 0, 0.5); + top: 14px; + left: 10px; } -.enable-input { - position: fixed; - top: 0; - left: 0; - padding: 10px; -} +/* .item[data-swapy-dragging] { + opacity: 0.8; +} */ diff --git a/examples/vanilla-dynamic/delete.svg b/examples/vanilla-dynamic/delete.svg new file mode 100644 index 0000000..3db803f --- /dev/null +++ b/examples/vanilla-dynamic/delete.svg @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/examples/vanilla-dynamic/handle.svg b/examples/vanilla-dynamic/handle.svg new file mode 100644 index 0000000..2340d4c --- /dev/null +++ b/examples/vanilla-dynamic/handle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/vanilla-dynamic/index.html b/examples/vanilla-dynamic/index.html new file mode 100644 index 0000000..90f1458 --- /dev/null +++ b/examples/vanilla-dynamic/index.html @@ -0,0 +1,40 @@ + + + + + + Vanilla JS Dynamic + + + +
+
+
+
+ 1 + +
+
+
+
+ 2 +
+
+
+
+ 3 +
+
+
+
+ 4 +
+
+
+ +
+
+
+ + + + diff --git a/examples/vanilla-dynamic/main.ts b/examples/vanilla-dynamic/main.ts new file mode 100644 index 0000000..1a7ae9d --- /dev/null +++ b/examples/vanilla-dynamic/main.ts @@ -0,0 +1,60 @@ +import { createSwapy } from '../../src' + +const container = document.querySelector('.container') as HTMLElement + +const swapy = createSwapy(container, { + animation: 'spring' + // swapMode: 'drop', + // autoScrollOnDrag: true, + // enabled: true, + // dragAxis: 'x', + // dragOnHold: true +}) + +swapy.onSwapStart((event) => { + console.log('start', event) +}) + +swapy.onSwap((event) => { + console.log('swap', event) +}) + +swapy.onSwapEnd((event) => { + console.log('swap end:', event) +}) + +let id = 5 + +const items = document.querySelector('.items')! + +const addButton = document.querySelector('.item--add')! +addButton.addEventListener('click', () => { + const newSlot = document.createElement('div') + newSlot.classList.add('slot') + newSlot.dataset.swapySlot = `${id}` + + const newItem = document.createElement('div') + newItem.classList.add('item') + newItem.dataset.swapyItem = `${id}` + const span = document.createElement('span') + span.textContent = `${id}` + newItem.appendChild(span) + const deleteItem = document.createElement('span') + deleteItem.classList.add('delete') + deleteItem.dataset.swapyNoDrag = '' + newItem.appendChild(deleteItem) + + newSlot.appendChild(newItem) + items.appendChild(newSlot) + id++ + + swapy.update() +}) + +document.body.addEventListener('click', (e) => { + const target = e.target as HTMLElement + if (target.classList.contains('delete')) { + const slot = target.closest('.slot') as HTMLElement + slot.remove() + } +}) diff --git a/examples/vanilla-dynamic/style.css b/examples/vanilla-dynamic/style.css new file mode 100644 index 0000000..44741cb --- /dev/null +++ b/examples/vanilla-dynamic/style.css @@ -0,0 +1,116 @@ +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; +} + +body { + background: #02040f; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; +} + +.container-container { + max-width: 100%; + width: 500px; + height: 400px; + overflow: auto; + border: red 1px solid; +} + +.container { + max-width: 800px; + width: 100%; + display: flex; + flex-direction: column; + gap: 10px; + margin: 0 auto; +} + +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; +} + +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); +} + +.items { + display: grid; + grid-template-columns: 2fr 1fr; + gap: 10px; +} + +.item { + position: relative; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + background: #4338ca; + padding: 20px 0; + border-radius: 10px; + width: 100%; + height: 100%; +} + +/* .item-2 { + height: 50px; +} */ + +.item:has(.handle) { + position: relative; +} + +.handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; + position: absolute; + top: 14px; + left: 10px; +} + +.item.item--add { + background: transparent; + border: 4px solid #4338ca; + cursor: pointer; + user-select: none; +} + +.item.item--add:hover { + background: #4338cacc; +} + +.delete { + background-color: hsl(244.5, 57.9%, 45.6%); + position: absolute; + right: 20px; + top: 10px; + height: 38px; + width: 38px; + border-radius: 50%; + background-image: url(./delete.svg) ; + background-size: 22px 22px; + background-position: 50% 50%; + background-repeat: no-repeat; + cursor: pointer; +} + +.delete:hover { + background-color: hsl(244.5, 57.9%, 40.6%); +} diff --git a/examples/vanilla/handle.svg b/examples/vanilla/handle.svg new file mode 100644 index 0000000..2340d4c --- /dev/null +++ b/examples/vanilla/handle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/vanilla/index.html b/examples/vanilla/index.html new file mode 100644 index 0000000..f27b3c4 --- /dev/null +++ b/examples/vanilla/index.html @@ -0,0 +1,34 @@ + + + + + + Vanilla JS + + + +
+
+
+
A
+
+
+
+
+
+
+
B
+
+
+
+
+
+
+
D
+
+
+
+ + + + diff --git a/examples/vanilla/main.ts b/examples/vanilla/main.ts new file mode 100644 index 0000000..a39bb9a --- /dev/null +++ b/examples/vanilla/main.ts @@ -0,0 +1,35 @@ +import { createSwapy } from '../../src' + +const container = document.querySelector('.container') as HTMLElement + +const swapy = createSwapy(container, { + animation: 'dynamic' + // swapMode: 'drop', + // autoScrollOnDrag: true, + // enabled: true, + // dragAxis: 'x', + // dragOnHold: true +}) + +// swapy.enable(false) +// swapy.destroy() +// console.log(swapy.slotItemMap()) + +swapy.onBeforeSwap((event) => { + console.log('beforeSwap', event) + // This is for dynamically enabling and disabling swapping. + // Return true to allow swapping, and return false to prevent swapping. + return true +}) + +swapy.onSwapStart((event) => { + console.log('start', event) +}) + +swapy.onSwap((event) => { + console.log('swap', event) +}) + +swapy.onSwapEnd((event) => { + console.log('swap end:', event) +}) diff --git a/examples/vanilla/style.css b/examples/vanilla/style.css new file mode 100644 index 0000000..2730911 --- /dev/null +++ b/examples/vanilla/style.css @@ -0,0 +1,124 @@ +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; +} + +body { + background: #02040f; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; +} + +.container { + max-width: 800px; + width: 100%; + display: flex; + flex-direction: column; + gap: 10px; + margin: 0 auto; +} + +.slot.top { + height: 200px; +} + +.middle { + height: 250px; + display: flex; + gap: 10px; +} + +.slot.middle-left { + height: 100%; + flex: 1; +} + +.slot.middle-right { + height: 100%; + flex: 2; +} + +.slot.bottom { + height: 150px; +} + +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; +} +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); +} + +.item { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} + +.item { + border-radius: 10px; + width: 100%; + height: 100%; +} + +.item-a { + background: rgba(255, 0, 0, 0.5); +} + +.card { + width: 100%; + height: 100%; + border-radius: 10px; + display: flex; + align-items: center; + justify-content: center; +} + +.item-a { + background: #10b981; +} + +.item-b { + background: #be123c; +} + +.item-c { + background: #4338ca; +} + +.item-d { + background: #7e22ce; +} + +.item:has(.handle) { + position: relative; +} + +.handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; + position: absolute; + top: 14px; + left: 10px; +} + +/* .item[data-swapy-dragging] { + opacity: 0.8; +} */ diff --git a/examples/vue-dynamic/App.vue b/examples/vue-dynamic/App.vue new file mode 100644 index 0000000..8de3a20 --- /dev/null +++ b/examples/vue-dynamic/App.vue @@ -0,0 +1,82 @@ + + + diff --git a/examples/vue-dynamic/delete.svg b/examples/vue-dynamic/delete.svg new file mode 100644 index 0000000..3db803f --- /dev/null +++ b/examples/vue-dynamic/delete.svg @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/examples/vue-dynamic/handle.svg b/examples/vue-dynamic/handle.svg new file mode 100644 index 0000000..0577114 --- /dev/null +++ b/examples/vue-dynamic/handle.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/examples/vue-dynamic/index.html b/examples/vue-dynamic/index.html new file mode 100644 index 0000000..5f38354 --- /dev/null +++ b/examples/vue-dynamic/index.html @@ -0,0 +1,12 @@ + + + + + + Vue (Dynamic) Swapy Example + + +
+ + + diff --git a/examples/vue-dynamic/main.ts b/examples/vue-dynamic/main.ts new file mode 100644 index 0000000..01433bc --- /dev/null +++ b/examples/vue-dynamic/main.ts @@ -0,0 +1,4 @@ +import { createApp } from 'vue' +import App from './App.vue' + +createApp(App).mount('#app') diff --git a/examples/vue-dynamic/style.css b/examples/vue-dynamic/style.css new file mode 100644 index 0000000..815a063 --- /dev/null +++ b/examples/vue-dynamic/style.css @@ -0,0 +1,113 @@ +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; +} + +body { + background: #02040f; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; +} + +#app { + width: 100%; +} + +.container { + max-width: 800px; + width: 100%; + display: flex; + flex-direction: column; + gap: 10px; + margin: 0 auto; +} + +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; + height: 100px; +} + +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); +} + +.items { + display: grid; + grid-template-columns: 2fr 1fr; + gap: 10px; +} + +.item { + position: relative; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + background: #4338ca; + padding: 20px 0; + border-radius: 10px; + width: 100%; + height: 100%; +} + +/* .item-2 { + height: 50px; +} */ + +.item:has(.handle) { + position: relative; +} + +.handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; + position: absolute; + top: 14px; + left: 10px; +} + +.item.item--add { + background: transparent; + border: 4px solid #4338ca; + cursor: pointer; + user-select: none; +} + +.item.item--add:hover { + background: #4338cacc; +} + +.delete { + background-color: hsl(244.5, 57.9%, 45.6%); + position: absolute; + right: 20px; + top: 10px; + height: 38px; + width: 38px; + border-radius: 50%; + background-image: url(./delete.svg); + background-size: 22px 22px; + background-position: 50% 50%; + background-repeat: no-repeat; + cursor: pointer; +} + +.delete:hover { + background-color: hsl(244.5, 57.9%, 40.6%); +} diff --git a/examples/vue/A.vue b/examples/vue/A.vue deleted file mode 100644 index 5c0bc45..0000000 --- a/examples/vue/A.vue +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/examples/vue/App.vue b/examples/vue/App.vue index d470014..6b56a54 100644 --- a/examples/vue/App.vue +++ b/examples/vue/App.vue @@ -1,62 +1,82 @@ - diff --git a/examples/vue/C.vue b/examples/vue/C.vue deleted file mode 100644 index e260627..0000000 --- a/examples/vue/C.vue +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/examples/vue/D.vue b/examples/vue/D.vue deleted file mode 100644 index e9527b7..0000000 --- a/examples/vue/D.vue +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/examples/vue/handle.svg b/examples/vue/handle.svg new file mode 100644 index 0000000..0577114 --- /dev/null +++ b/examples/vue/handle.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/examples/vue/index.html b/examples/vue/index.html index 14ab3ee..848c30e 100644 --- a/examples/vue/index.html +++ b/examples/vue/index.html @@ -4,10 +4,6 @@ Vue Swapy Example -
diff --git a/examples/vue/style.css b/examples/vue/style.css index a6683bd..598285a 100644 --- a/examples/vue/style.css +++ b/examples/vue/style.css @@ -2,106 +2,114 @@ box-sizing: border-box; } -:root { - background: #242424; +html, +body { + margin: 0; + padding: 0; + min-height: 150vh; } -body, -#app { - font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, - Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; - width: 100%; - min-height: 100dvh; +body { + background: #02040f; display: flex; + flex-direction: column; justify-content: center; align-items: center; - padding: 0; - margin: 0; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, + Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + color: white; + font-size: 50px; +} + +#app { + width: 100%; } .container { + max-width: 800px; + width: 100%; display: flex; flex-direction: column; - gap: 5px; - width: 100%; - max-width: 500px; - padding: 10px; + gap: 10px; + margin: 0 auto; } -.second-row { - display: flex; - gap: 5px; +.slot.top { + height: 200px; } -.slot { - background: #111; - flex: 1; +.middle { + height: 250px; + display: flex; + gap: 10px; } -.slot.a { - flex-basis: 150px; - height: 150px; +.slot.middle-left { + height: 100%; + flex: 1; } -.slot.b { +.slot.middle-right { + height: 100%; flex: 2; } -.second-row { - height: 100px; +.slot.bottom { + height: 150px; } -.slot.d { - flex-basis: 120px; - height: 120px; +.slot { + transition: background 0.2s ease-out; + border-radius: 10px; +} +.slot[data-swapy-highlighted] { + background: rgba(255, 255, 255, 0.2); } .item { - width: 100%; - height: 100%; display: flex; + flex-direction: column; align-items: center; justify-content: center; - color: white; - font-size: 40px; - cursor: pointer; - user-select: none; - -webkit-user-select: none; - position: relative; } -.item.a { - background: #b95050; +.item { + border-radius: 10px; + width: 100%; + height: 100%; +} + +.item-a { + background: #10b981; } -.item.b { - background: #50b97f; +.item-b { + background: #be123c; } -.item.c { - background: #508db9; +.item-c { + background: #4338ca; } -.item.d { - background: #b95096; +.item-d { + background: #7e22ce; } -[data-swapy-highlighted] { - background: #444; +.item:has(.handle) { + position: relative; } .handle { + cursor: grab; + width: 24px; + height: 24px; + background-image: url(./handle.svg); + opacity: 0.5; position: absolute; - left: 0; - top: 0; - width: 20px; - height: 100%; - background: rgba(0, 0, 0, 0.5); + top: 14px; + left: 10px; } -.enable-input { - position: fixed; - top: 0; - left: 0; - padding: 10px; -} +/* .item[data-swapy-dragging] { + opacity: 0.8; +} */ diff --git a/package.json b/package.json index bf7f1a6..ede8740 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "swapy", "author": "Taha Shashtari (taha@tahazsh.com)", "private": false, - "version": "0.4.2", + "version": "1.0.0", "type": "module", "main": "./dist/swapy.min.js", "module": "./dist/swapy.js", @@ -19,26 +19,23 @@ "scripts": { "dev": "vite", "tsc": "tsc --noEmit", - "build": "tsc && vite build", + "build": "tsc -p tsconfig.build.json && vite build", "preview": "vite preview" }, "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^3.1.2", - "@tsconfig/svelte": "^5.0.4", - "@types/react": "^18.3.11", - "@types/react-dom": "^18.3.0", - "@vitejs/plugin-react": "^4.3.2", - "@vitejs/plugin-vue": "^5.1.4", + "@sveltejs/vite-plugin-svelte": "^4.0.1", + "@types/node": "^22.9.0", + "@types/react": "^18.3.12", + "@types/react-dom": "^18.3.1", + "@vitejs/plugin-react": "^4.3.3", + "@vitejs/plugin-vue": "^5.2.0", "react": "^18.3.1", "react-dom": "^18.3.1", - "svelte": "^4.2.19", - "svelte-check": "^4.0.4", - "typescript": "^5.6.2", - "veloxi": "^0.15.3", - "vite": "^5.4.8", - "vite-plugin-dts": "4.2.3", - "vue": "^3.5.11", - "vue-tsc": "^2.1.6" + "svelte": "^5.2.7", + "typescript": "^5.6.3", + "vite": "^5.4.10", + "vite-plugin-dts": "^4.3.0", + "vue": "^3.5.13" }, "keywords": [ "swap", @@ -47,5 +44,6 @@ "smooth", "animation" ], - "license": "MIT" + "license": "GPL-3.0", + "homepage": "https://swapy.tahazsh.com/" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4541356..cd6eb37 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,23 +9,23 @@ importers: .: devDependencies: '@sveltejs/vite-plugin-svelte': - specifier: ^3.1.2 - version: 3.1.2(svelte@4.2.19)(vite@5.4.8) - '@tsconfig/svelte': - specifier: ^5.0.4 - version: 5.0.4 + specifier: ^4.0.1 + version: 4.0.1(svelte@5.2.7)(vite@5.4.10(@types/node@22.9.0)) + '@types/node': + specifier: ^22.9.0 + version: 22.9.0 '@types/react': - specifier: ^18.3.11 - version: 18.3.11 + specifier: ^18.3.12 + version: 18.3.12 '@types/react-dom': - specifier: ^18.3.0 - version: 18.3.0 + specifier: ^18.3.1 + version: 18.3.1 '@vitejs/plugin-react': - specifier: ^4.3.2 - version: 4.3.2(vite@5.4.8) + specifier: ^4.3.3 + version: 4.3.3(vite@5.4.10(@types/node@22.9.0)) '@vitejs/plugin-vue': - specifier: ^5.1.4 - version: 5.1.4(vite@5.4.8)(vue@3.5.11(typescript@5.6.2)) + specifier: ^5.2.0 + version: 5.2.0(vite@5.4.10(@types/node@22.9.0))(vue@3.5.13(typescript@5.6.3)) react: specifier: ^18.3.1 version: 18.3.1 @@ -33,29 +33,20 @@ importers: specifier: ^18.3.1 version: 18.3.1(react@18.3.1) svelte: - specifier: ^4.2.19 - version: 4.2.19 - svelte-check: - specifier: ^4.0.4 - version: 4.0.4(svelte@4.2.19)(typescript@5.6.2) + specifier: ^5.2.7 + version: 5.2.7 typescript: - specifier: ^5.6.2 - version: 5.6.2 - veloxi: - specifier: ^0.15.3 - version: 0.15.3 + specifier: ^5.6.3 + version: 5.6.3 vite: - specifier: ^5.4.8 - version: 5.4.8 + specifier: ^5.4.10 + version: 5.4.10(@types/node@22.9.0) vite-plugin-dts: - specifier: 4.2.3 - version: 4.2.3(rollup@4.24.0)(typescript@5.6.2)(vite@5.4.8) + specifier: ^4.3.0 + version: 4.3.0(@types/node@22.9.0)(rollup@4.24.4)(typescript@5.6.3)(vite@5.4.10(@types/node@22.9.0)) vue: - specifier: ^3.5.11 - version: 3.5.11(typescript@5.6.2) - vue-tsc: - specifier: ^2.1.6 - version: 2.1.6(typescript@5.6.2) + specifier: ^3.5.13 + version: 3.5.13(typescript@5.6.3) packages: @@ -63,91 +54,83 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} - '@babel/code-frame@7.25.7': - resolution: {integrity: sha512-0xZJFNE5XMpENsgfHYTw8FbX4kv53mFLn2i3XPoq69LyhYSCBJtitaHx9QnsVTrsogI4Z3+HtEfZ2/GFPOtf5g==} + '@babel/code-frame@7.26.2': + resolution: {integrity: sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==} engines: {node: '>=6.9.0'} - '@babel/compat-data@7.25.7': - resolution: {integrity: sha512-9ickoLz+hcXCeh7jrcin+/SLWm+GkxE2kTvoYyp38p4WkdFXfQJxDFGWp/YHjiKLPx06z2A7W8XKuqbReXDzsw==} + '@babel/compat-data@7.26.2': + resolution: {integrity: sha512-Z0WgzSEa+aUcdiJuCIqgujCshpMWgUpgOxXotrYPSA53hA3qopNaqcJpyr0hVb1FeWdnqFA35/fUtXgBK8srQg==} engines: {node: '>=6.9.0'} - '@babel/core@7.25.7': - resolution: {integrity: sha512-yJ474Zv3cwiSOO9nXJuqzvwEeM+chDuQ8GJirw+pZ91sCGCyOZ3dJkVE09fTV0VEVzXyLWhh3G/AolYTPX7Mow==} + '@babel/core@7.26.0': + resolution: {integrity: sha512-i1SLeK+DzNnQ3LL/CswPCa/E5u4lh1k6IAEphON8F+cXt0t9euTshDru0q7/IqMa1PMPz5RnHuHscF8/ZJsStg==} engines: {node: '>=6.9.0'} - '@babel/generator@7.25.7': - resolution: {integrity: sha512-5Dqpl5fyV9pIAD62yK9P7fcA768uVPUyrQmqpqstHWgMma4feF1x/oFysBCVZLY5wJ2GkMUCdsNDnGZrPoR6rA==} + '@babel/generator@7.26.2': + resolution: {integrity: sha512-zevQbhbau95nkoxSq3f/DC/SC+EEOUZd3DYqfSkMhY2/wfSeaHV1Ew4vk8e+x8lja31IbyuUa2uQ3JONqKbysw==} engines: {node: '>=6.9.0'} - '@babel/helper-compilation-targets@7.25.7': - resolution: {integrity: sha512-DniTEax0sv6isaw6qSQSfV4gVRNtw2rte8HHM45t9ZR0xILaufBRNkpMifCRiAPyvL4ACD6v0gfCwCmtOQaV4A==} + '@babel/helper-compilation-targets@7.25.9': + resolution: {integrity: sha512-j9Db8Suy6yV/VHa4qzrj9yZfZxhLWQdVnRlXxmKLYlhWUVB1sB2G5sxuWYXk/whHD9iW76PmNzxZ4UCnTQTVEQ==} engines: {node: '>=6.9.0'} - '@babel/helper-module-imports@7.25.7': - resolution: {integrity: sha512-o0xCgpNmRohmnoWKQ0Ij8IdddjyBFE4T2kagL/x6M3+4zUgc+4qTOUBoNe4XxDskt1HPKO007ZPiMgLDq2s7Kw==} + '@babel/helper-module-imports@7.25.9': + resolution: {integrity: sha512-tnUA4RsrmflIM6W6RFTLFSXITtl0wKjgpnLgXyowocVPrbYrLUXSBXDgTs8BlbmIzIdlBySRQjINYs2BAkiLtw==} engines: {node: '>=6.9.0'} - '@babel/helper-module-transforms@7.25.7': - resolution: {integrity: sha512-k/6f8dKG3yDz/qCwSM+RKovjMix563SLxQFo0UhRNo239SP6n9u5/eLtKD6EAjwta2JHJ49CsD8pms2HdNiMMQ==} + '@babel/helper-module-transforms@7.26.0': + resolution: {integrity: sha512-xO+xu6B5K2czEnQye6BHA7DolFFmS3LB7stHZFaOLb1pAwO1HWLS8fXA+eh0A2yIvltPVmx3eNNDBJA2SLHXFw==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 - '@babel/helper-plugin-utils@7.25.7': - resolution: {integrity: sha512-eaPZai0PiqCi09pPs3pAFfl/zYgGaE6IdXtYvmf0qlcDTd3WCtO7JWCcRd64e0EQrcYgiHibEZnOGsSY4QSgaw==} - engines: {node: '>=6.9.0'} - - '@babel/helper-simple-access@7.25.7': - resolution: {integrity: sha512-FPGAkJmyoChQeM+ruBGIDyrT2tKfZJO8NcxdC+CWNJi7N8/rZpSxK7yvBJ5O/nF1gfu5KzN7VKG3YVSLFfRSxQ==} + '@babel/helper-plugin-utils@7.25.9': + resolution: {integrity: sha512-kSMlyUVdWe25rEsRGviIgOWnoT/nfABVWlqt9N19/dIPWViAOW2s9wznP5tURbs/IDuNk4gPy3YdYRgH3uxhBw==} engines: {node: '>=6.9.0'} - '@babel/helper-string-parser@7.25.7': - resolution: {integrity: sha512-CbkjYdsJNHFk8uqpEkpCvRs3YRp9tY6FmFY7wLMSYuGYkrdUi7r2lc4/wqsvlHoMznX3WJ9IP8giGPq68T/Y6g==} + '@babel/helper-string-parser@7.25.9': + resolution: {integrity: sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==} engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.25.7': - resolution: {integrity: sha512-AM6TzwYqGChO45oiuPqwL2t20/HdMC1rTPAesnBCgPCSF1x3oN9MVUwQV2iyz4xqWrctwK5RNC8LV22kaQCNYg==} + '@babel/helper-validator-identifier@7.25.9': + resolution: {integrity: sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==} engines: {node: '>=6.9.0'} - '@babel/helper-validator-option@7.25.7': - resolution: {integrity: sha512-ytbPLsm+GjArDYXJ8Ydr1c/KJuutjF2besPNbIZnZ6MKUxi/uTA22t2ymmA4WFjZFpjiAMO0xuuJPqK2nvDVfQ==} + '@babel/helper-validator-option@7.25.9': + resolution: {integrity: sha512-e/zv1co8pp55dNdEcCynfj9X7nyUKUXoUEwfXqaZt0omVOmDe9oOTdKStH4GmAw6zxMFs50ZayuMfHDKlO7Tfw==} engines: {node: '>=6.9.0'} - '@babel/helpers@7.25.7': - resolution: {integrity: sha512-Sv6pASx7Esm38KQpF/U/OXLwPPrdGHNKoeblRxgZRLXnAtnkEe4ptJPDtAZM7fBLadbc1Q07kQpSiGQ0Jg6tRA==} + '@babel/helpers@7.26.0': + resolution: {integrity: sha512-tbhNuIxNcVb21pInl3ZSjksLCvgdZy9KwJ8brv993QtIVKJBBkYXz4q4ZbAv31GdnC+R90np23L5FbEBlthAEw==} engines: {node: '>=6.9.0'} - '@babel/highlight@7.25.7': - resolution: {integrity: sha512-iYyACpW3iW8Fw+ZybQK+drQre+ns/tKpXbNESfrhNnPLIklLbXr7MYJ6gPEd0iETGLOK+SxMjVvKb/ffmk+FEw==} - engines: {node: '>=6.9.0'} - - '@babel/parser@7.25.7': - resolution: {integrity: sha512-aZn7ETtQsjjGG5HruveUK06cU3Hljuhd9Iojm4M8WWv3wLE6OkE5PWbDUkItmMgegmccaITudyuW5RPYrYlgWw==} + '@babel/parser@7.26.2': + resolution: {integrity: sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==} engines: {node: '>=6.0.0'} hasBin: true - '@babel/plugin-transform-react-jsx-self@7.25.7': - resolution: {integrity: sha512-JD9MUnLbPL0WdVK8AWC7F7tTG2OS6u/AKKnsK+NdRhUiVdnzyR1S3kKQCaRLOiaULvUiqK6Z4JQE635VgtCFeg==} + '@babel/plugin-transform-react-jsx-self@7.25.9': + resolution: {integrity: sha512-y8quW6p0WHkEhmErnfe58r7x0A70uKphQm8Sp8cV7tjNQwK56sNVK0M73LK3WuYmsuyrftut4xAkjjgU0twaMg==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 - '@babel/plugin-transform-react-jsx-source@7.25.7': - resolution: {integrity: sha512-S/JXG/KrbIY06iyJPKfxr0qRxnhNOdkNXYBl/rmwgDd72cQLH9tEGkDm/yJPGvcSIUoikzfjMios9i+xT/uv9w==} + '@babel/plugin-transform-react-jsx-source@7.25.9': + resolution: {integrity: sha512-+iqjT8xmXhhYv4/uiYd8FNQsraMFZIfxVSqxxVSZP0WbbSAWvBXAul0m/zu+7Vv4O/3WtApy9pmaTMiumEZgfg==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 - '@babel/template@7.25.7': - resolution: {integrity: sha512-wRwtAgI3bAS+JGU2upWNL9lSlDcRCqD05BZ1n3X2ONLH1WilFP6O1otQjeMK/1g0pvYcXC7b/qVUB1keofjtZA==} + '@babel/template@7.25.9': + resolution: {integrity: sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==} engines: {node: '>=6.9.0'} - '@babel/traverse@7.25.7': - resolution: {integrity: sha512-jatJPT1Zjqvh/1FyJs6qAHL+Dzb7sTb+xr7Q+gM1b+1oBsMsQQ4FkVKb6dFlJvLlVssqkRzV05Jzervt9yhnzg==} + '@babel/traverse@7.25.9': + resolution: {integrity: sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==} engines: {node: '>=6.9.0'} - '@babel/types@7.25.7': - resolution: {integrity: sha512-vwIVdXG+j+FOpkwqHRcBgHLYNL7XMkufrlaFvL9o6Ai9sJn9+PdyIL5qa0XzTZw084c+u9LOls53eoZWP/W5WQ==} + '@babel/types@7.26.0': + resolution: {integrity: sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA==} engines: {node: '>=6.9.0'} '@esbuild/aix-ppc64@0.21.5': @@ -306,11 +289,11 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} - '@microsoft/api-extractor-model@7.29.6': - resolution: {integrity: sha512-gC0KGtrZvxzf/Rt9oMYD2dHvtN/1KPEYsrQPyMKhLHnlVuO/f4AFN3E4toqZzD2pt4LhkKoYmL2H9tX3yCOyRw==} + '@microsoft/api-extractor-model@7.29.8': + resolution: {integrity: sha512-t3Z/xcO6TRbMcnKGVMs4uMzv/gd5j0NhMiJIGjD4cJMeFJ1Hf8wnLSx37vxlRlL0GWlGJhnFgxvnaL6JlS+73g==} - '@microsoft/api-extractor@7.47.7': - resolution: {integrity: sha512-fNiD3G55ZJGhPOBPMKD/enozj8yxJSYyVJWxRWdcUtw842rvthDHJgUWq9gXQTensFlMHv2wGuCjjivPv53j0A==} + '@microsoft/api-extractor@7.47.11': + resolution: {integrity: sha512-lrudfbPub5wzBhymfFtgZKuBvXxoSIAdrvS2UbHjoMT2TjIEddq6Z13pcve7A03BAouw0x8sW8G4txdgfiSwpQ==} hasBin: true '@microsoft/tsdoc-config@0.17.0': @@ -319,8 +302,8 @@ packages: '@microsoft/tsdoc@0.15.0': resolution: {integrity: sha512-HZpPoABogPvjeJOdzCOSJsXeL/SMCBgBZMVC3X3d7YYp2gf31MfxhUoYUNwf1ERPJOnQc0wkFn9trqI6ZEdZuA==} - '@rollup/pluginutils@5.1.2': - resolution: {integrity: sha512-/FIdS3PyZ39bjZlwqFnWqCOVnW7o963LtKMwQOD0NhQqw22gSr2YY1afu3FxRip4ZCZNsD5jq6Aaz6QV3D/Njw==} + '@rollup/pluginutils@5.1.3': + resolution: {integrity: sha512-Pnsb6f32CD2W3uCaLZIzDmeFyQ2b8UWMFI7xtwUezpcGBDVDW6y9XgAWIlARiGAo6eNF5FK5aQTr0LFyNyqq5A==} engines: {node: '>=14.0.0'} peerDependencies: rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 @@ -328,88 +311,98 @@ packages: rollup: optional: true - '@rollup/rollup-android-arm-eabi@4.24.0': - resolution: {integrity: sha512-Q6HJd7Y6xdB48x8ZNVDOqsbh2uByBhgK8PiQgPhwkIw/HC/YX5Ghq2mQY5sRMZWHb3VsFkWooUVOZHKr7DmDIA==} + '@rollup/rollup-android-arm-eabi@4.24.4': + resolution: {integrity: sha512-jfUJrFct/hTA0XDM5p/htWKoNNTbDLY0KRwEt6pyOA6k2fmk0WVwl65PdUdJZgzGEHWx+49LilkcSaumQRyNQw==} cpu: [arm] os: [android] - '@rollup/rollup-android-arm64@4.24.0': - resolution: {integrity: sha512-ijLnS1qFId8xhKjT81uBHuuJp2lU4x2yxa4ctFPtG+MqEE6+C5f/+X/bStmxapgmwLwiL3ih122xv8kVARNAZA==} + '@rollup/rollup-android-arm64@4.24.4': + resolution: {integrity: sha512-j4nrEO6nHU1nZUuCfRKoCcvh7PIywQPUCBa2UsootTHvTHIoIu2BzueInGJhhvQO/2FTRdNYpf63xsgEqH9IhA==} cpu: [arm64] os: [android] - '@rollup/rollup-darwin-arm64@4.24.0': - resolution: {integrity: sha512-bIv+X9xeSs1XCk6DVvkO+S/z8/2AMt/2lMqdQbMrmVpgFvXlmde9mLcbQpztXm1tajC3raFDqegsH18HQPMYtA==} + '@rollup/rollup-darwin-arm64@4.24.4': + resolution: {integrity: sha512-GmU/QgGtBTeraKyldC7cDVVvAJEOr3dFLKneez/n7BvX57UdhOqDsVwzU7UOnYA7AAOt+Xb26lk79PldDHgMIQ==} cpu: [arm64] os: [darwin] - '@rollup/rollup-darwin-x64@4.24.0': - resolution: {integrity: sha512-X6/nOwoFN7RT2svEQWUsW/5C/fYMBe4fnLK9DQk4SX4mgVBiTA9h64kjUYPvGQ0F/9xwJ5U5UfTbl6BEjaQdBQ==} + '@rollup/rollup-darwin-x64@4.24.4': + resolution: {integrity: sha512-N6oDBiZCBKlwYcsEPXGDE4g9RoxZLK6vT98M8111cW7VsVJFpNEqvJeIPfsCzbf0XEakPslh72X0gnlMi4Ddgg==} cpu: [x64] os: [darwin] - '@rollup/rollup-linux-arm-gnueabihf@4.24.0': - resolution: {integrity: sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==} + '@rollup/rollup-freebsd-arm64@4.24.4': + resolution: {integrity: sha512-py5oNShCCjCyjWXCZNrRGRpjWsF0ic8f4ieBNra5buQz0O/U6mMXCpC1LvrHuhJsNPgRt36tSYMidGzZiJF6mw==} + cpu: [arm64] + os: [freebsd] + + '@rollup/rollup-freebsd-x64@4.24.4': + resolution: {integrity: sha512-L7VVVW9FCnTTp4i7KrmHeDsDvjB4++KOBENYtNYAiYl96jeBThFfhP6HVxL74v4SiZEVDH/1ILscR5U9S4ms4g==} + cpu: [x64] + os: [freebsd] + + '@rollup/rollup-linux-arm-gnueabihf@4.24.4': + resolution: {integrity: sha512-10ICosOwYChROdQoQo589N5idQIisxjaFE/PAnX2i0Zr84mY0k9zul1ArH0rnJ/fpgiqfu13TFZR5A5YJLOYZA==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm-musleabihf@4.24.0': - resolution: {integrity: sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==} + '@rollup/rollup-linux-arm-musleabihf@4.24.4': + resolution: {integrity: sha512-ySAfWs69LYC7QhRDZNKqNhz2UKN8LDfbKSMAEtoEI0jitwfAG2iZwVqGACJT+kfYvvz3/JgsLlcBP+WWoKCLcw==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm64-gnu@4.24.0': - resolution: {integrity: sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==} + '@rollup/rollup-linux-arm64-gnu@4.24.4': + resolution: {integrity: sha512-uHYJ0HNOI6pGEeZ/5mgm5arNVTI0nLlmrbdph+pGXpC9tFHFDQmDMOEqkmUObRfosJqpU8RliYoGz06qSdtcjg==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-arm64-musl@4.24.0': - resolution: {integrity: sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==} + '@rollup/rollup-linux-arm64-musl@4.24.4': + resolution: {integrity: sha512-38yiWLemQf7aLHDgTg85fh3hW9stJ0Muk7+s6tIkSUOMmi4Xbv5pH/5Bofnsb6spIwD5FJiR+jg71f0CH5OzoA==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-powerpc64le-gnu@4.24.0': - resolution: {integrity: sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==} + '@rollup/rollup-linux-powerpc64le-gnu@4.24.4': + resolution: {integrity: sha512-q73XUPnkwt9ZNF2xRS4fvneSuaHw2BXuV5rI4cw0fWYVIWIBeDZX7c7FWhFQPNTnE24172K30I+dViWRVD9TwA==} cpu: [ppc64] os: [linux] - '@rollup/rollup-linux-riscv64-gnu@4.24.0': - resolution: {integrity: sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==} + '@rollup/rollup-linux-riscv64-gnu@4.24.4': + resolution: {integrity: sha512-Aie/TbmQi6UXokJqDZdmTJuZBCU3QBDA8oTKRGtd4ABi/nHgXICulfg1KI6n9/koDsiDbvHAiQO3YAUNa/7BCw==} cpu: [riscv64] os: [linux] - '@rollup/rollup-linux-s390x-gnu@4.24.0': - resolution: {integrity: sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==} + '@rollup/rollup-linux-s390x-gnu@4.24.4': + resolution: {integrity: sha512-P8MPErVO/y8ohWSP9JY7lLQ8+YMHfTI4bAdtCi3pC2hTeqFJco2jYspzOzTUB8hwUWIIu1xwOrJE11nP+0JFAQ==} cpu: [s390x] os: [linux] - '@rollup/rollup-linux-x64-gnu@4.24.0': - resolution: {integrity: sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==} + '@rollup/rollup-linux-x64-gnu@4.24.4': + resolution: {integrity: sha512-K03TljaaoPK5FOyNMZAAEmhlyO49LaE4qCsr0lYHUKyb6QacTNF9pnfPpXnFlFD3TXuFbFbz7tJ51FujUXkXYA==} cpu: [x64] os: [linux] - '@rollup/rollup-linux-x64-musl@4.24.0': - resolution: {integrity: sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==} + '@rollup/rollup-linux-x64-musl@4.24.4': + resolution: {integrity: sha512-VJYl4xSl/wqG2D5xTYncVWW+26ICV4wubwN9Gs5NrqhJtayikwCXzPL8GDsLnaLU3WwhQ8W02IinYSFJfyo34Q==} cpu: [x64] os: [linux] - '@rollup/rollup-win32-arm64-msvc@4.24.0': - resolution: {integrity: sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==} + '@rollup/rollup-win32-arm64-msvc@4.24.4': + resolution: {integrity: sha512-ku2GvtPwQfCqoPFIJCqZ8o7bJcj+Y54cZSr43hHca6jLwAiCbZdBUOrqE6y29QFajNAzzpIOwsckaTFmN6/8TA==} cpu: [arm64] os: [win32] - '@rollup/rollup-win32-ia32-msvc@4.24.0': - resolution: {integrity: sha512-xrNcGDU0OxVcPTH/8n/ShH4UevZxKIO6HJFK0e15XItZP2UcaiLFd5kiX7hJnqCbSztUF8Qot+JWBC/QXRPYWQ==} + '@rollup/rollup-win32-ia32-msvc@4.24.4': + resolution: {integrity: sha512-V3nCe+eTt/W6UYNr/wGvO1fLpHUrnlirlypZfKCT1fG6hWfqhPgQV/K/mRBXBpxc0eKLIF18pIOFVPh0mqHjlg==} cpu: [ia32] os: [win32] - '@rollup/rollup-win32-x64-msvc@4.24.0': - resolution: {integrity: sha512-fbMkAF7fufku0N2dE5TBXcNlg0pt0cJue4xBRE2Qc5Vqikxr4VCgKj/ht6SMdFcOacVA9rqF70APJ8RN/4vMJw==} + '@rollup/rollup-win32-x64-msvc@4.24.4': + resolution: {integrity: sha512-LTw1Dfd0mBIEqUVCxbvTE/LLo+9ZxVC9k99v1v4ahg9Aak6FpqOfNu5kRkeTAn0wphoC4JU7No1/rL+bBCEwhg==} cpu: [x64] os: [win32] - '@rushstack/node-core-library@5.7.0': - resolution: {integrity: sha512-Ff9Cz/YlWu9ce4dmqNBZpA45AEya04XaBFIjV7xTVeEf+y/kTjEasmozqFELXlNG4ROdevss75JrrZ5WgufDkQ==} + '@rushstack/node-core-library@5.9.0': + resolution: {integrity: sha512-MMsshEWkTbXqxqFxD4gcIUWQOCeBChlGczdZbHfqmNZQFLHB3yWxDFSMHFUdu2/OB9NUk7Awn5qRL+rws4HQNg==} peerDependencies: '@types/node': '*' peerDependenciesMeta: @@ -419,35 +412,32 @@ packages: '@rushstack/rig-package@0.5.3': resolution: {integrity: sha512-olzSSjYrvCNxUFZowevC3uz8gvKr3WTpHQ7BkpjtRpA3wK+T0ybep/SRUMfr195gBzJm5gaXw0ZMgjIyHqJUow==} - '@rushstack/terminal@0.14.0': - resolution: {integrity: sha512-juTKMAMpTIJKudeFkG5slD8Z/LHwNwGZLtU441l/u82XdTBfsP+LbGKJLCNwP5se+DMCT55GB8x9p6+C4UL7jw==} + '@rushstack/terminal@0.14.2': + resolution: {integrity: sha512-2fC1wqu1VCExKC0/L+0noVcFQEXEnoBOtCIex1TOjBzEDWcw8KzJjjj7aTP6mLxepG0XIyn9OufeFb6SFsa+sg==} peerDependencies: '@types/node': '*' peerDependenciesMeta: '@types/node': optional: true - '@rushstack/ts-command-line@4.22.6': - resolution: {integrity: sha512-QSRqHT/IfoC5nk9zn6+fgyqOPXHME0BfchII9EUPR19pocsNp/xSbeBCbD3PIR2Lg+Q5qk7OFqk1VhWPMdKHJg==} + '@rushstack/ts-command-line@4.23.0': + resolution: {integrity: sha512-jYREBtsxduPV6ptNq8jOKp9+yx0ld1Tb/Tkdnlj8gTjazl1sF3DwX2VbluyYrNd0meWIL0bNeer7WDf5tKFjaQ==} - '@sveltejs/vite-plugin-svelte-inspector@2.1.0': - resolution: {integrity: sha512-9QX28IymvBlSCqsCll5t0kQVxipsfhFFL+L2t3nTWfXnddYwxBuAEtTtlaVQpRz9c37BhJjltSeY4AJSC03SSg==} - engines: {node: ^18.0.0 || >=20} + '@sveltejs/vite-plugin-svelte-inspector@3.0.1': + resolution: {integrity: sha512-2CKypmj1sM4GE7HjllT7UKmo4Q6L5xFRd7VMGEWhYnZ+wc6AUVU01IBd7yUi6WnFndEwWoMNOd6e8UjoN0nbvQ==} + engines: {node: ^18.0.0 || ^20.0.0 || >=22} peerDependencies: - '@sveltejs/vite-plugin-svelte': ^3.0.0 - svelte: ^4.0.0 || ^5.0.0-next.0 + '@sveltejs/vite-plugin-svelte': ^4.0.0-next.0||^4.0.0 + svelte: ^5.0.0-next.96 || ^5.0.0 vite: ^5.0.0 - '@sveltejs/vite-plugin-svelte@3.1.2': - resolution: {integrity: sha512-Txsm1tJvtiYeLUVRNqxZGKR/mI+CzuIQuc2gn+YCs9rMTowpNZ2Nqt53JdL8KF9bLhAf2ruR/dr9eZCwdTriRA==} - engines: {node: ^18.0.0 || >=20} + '@sveltejs/vite-plugin-svelte@4.0.1': + resolution: {integrity: sha512-prXoAE/GleD2C4pKgHa9vkdjpzdYwCSw/kmjw6adIyu0vk5YKCfqIztkLg10m+kOYnzZu3bb0NaPTxlWre2a9Q==} + engines: {node: ^18.0.0 || ^20.0.0 || >=22} peerDependencies: - svelte: ^4.0.0 || ^5.0.0-next.0 + svelte: ^5.0.0-next.96 || ^5.0.0 vite: ^5.0.0 - '@tsconfig/svelte@5.0.4': - resolution: {integrity: sha512-BV9NplVgLmSi4mwKzD8BD/NQ8erOY/nUE/GpgWe2ckx+wIQF5RyRirn/QsSSCPeulVpc3RA/iJt6DpfTIZps0Q==} - '@types/argparse@1.0.38': resolution: {integrity: sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==} @@ -466,48 +456,57 @@ packages: '@types/estree@1.0.6': resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} + '@types/node@22.9.0': + resolution: {integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==} + '@types/prop-types@15.7.13': resolution: {integrity: sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==} - '@types/react-dom@18.3.0': - resolution: {integrity: sha512-EhwApuTmMBmXuFOikhQLIBUn6uFg81SwLMOAUgodJF14SOBOCMdU04gDoYi0WOJJHD144TL32z4yDqCW3dnkQg==} + '@types/react-dom@18.3.1': + resolution: {integrity: sha512-qW1Mfv8taImTthu4KoXgDfLuk4bydU6Q/TkADnDWWHwi4NX4BR+LWfTp2sVmTqRrsHvyDDTelgelxJ+SsejKKQ==} - '@types/react@18.3.11': - resolution: {integrity: sha512-r6QZ069rFTjrEYgFdOck1gK7FLVsgJE7tTz0pQBczlBNUhBNk0MQH4UbnFSwjpQLMkLzgqvBBa+qGpLje16eTQ==} + '@types/react@18.3.12': + resolution: {integrity: sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw==} - '@vitejs/plugin-react@4.3.2': - resolution: {integrity: sha512-hieu+o05v4glEBucTcKMK3dlES0OeJlD9YVOAPraVMOInBCwzumaIFiUjr4bHK7NPgnAHgiskUoceKercrN8vg==} + '@vitejs/plugin-react@4.3.3': + resolution: {integrity: sha512-NooDe9GpHGqNns1i8XDERg0Vsg5SSYRhRxxyTGogUdkdNt47jal+fbuYi+Yfq6pzRCKXyoPcWisfxE6RIM3GKA==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: vite: ^4.2.0 || ^5.0.0 - '@vitejs/plugin-vue@5.1.4': - resolution: {integrity: sha512-N2XSI2n3sQqp5w7Y/AN/L2XDjBIRGqXko+eDp42sydYSBeJuSm5a1sLf8zakmo8u7tA8NmBgoDLA1HeOESjp9A==} + '@vitejs/plugin-vue@5.2.0': + resolution: {integrity: sha512-7n7KdUEtx/7Yl7I/WVAMZ1bEb0eVvXF3ummWTeLcs/9gvo9pJhuLdouSXGjdZ/MKD1acf1I272+X0RMua4/R3g==} engines: {node: ^18.0.0 || >=20.0.0} peerDependencies: vite: ^5.0.0 vue: ^3.2.25 - '@volar/language-core@2.4.6': - resolution: {integrity: sha512-FxUfxaB8sCqvY46YjyAAV6c3mMIq/NWQMVvJ+uS4yxr1KzOvyg61gAuOnNvgCvO4TZ7HcLExBEsWcDu4+K4E8A==} + '@volar/language-core@2.4.8': + resolution: {integrity: sha512-K/GxMOXGq997bO00cdFhTNuR85xPxj0BEEAy+BaqqayTmy9Tmhfgmq2wpJcVspRhcwfgPoE2/mEJa26emUhG/g==} + + '@volar/source-map@2.4.8': + resolution: {integrity: sha512-jeWJBkC/WivdelMwxKkpFL811uH/jJ1kVxa+c7OvG48DXc3VrP7pplSWPP2W1dLMqBxD+awRlg55FQQfiup4cA==} - '@volar/source-map@2.4.6': - resolution: {integrity: sha512-Nsh7UW2ruK+uURIPzjJgF0YRGP5CX9nQHypA2OMqdM2FKy7rh+uv3XgPnWPw30JADbKvZ5HuBzG4gSbVDYVtiw==} + '@volar/typescript@2.4.8': + resolution: {integrity: sha512-6xkIYJ5xxghVBhVywMoPMidDDAFT1OoQeXwa27HSgJ6AiIKRe61RXLoik+14Z7r0JvnblXVsjsRLmCr42SGzqg==} - '@volar/typescript@2.4.6': - resolution: {integrity: sha512-NMIrA7y5OOqddL9VtngPWYmdQU03htNKFtAYidbYfWA0TOhyGVd9tfcP4TsLWQ+RBWDZCbBqsr8xzU0ZOxYTCQ==} + '@vue/compiler-core@3.5.12': + resolution: {integrity: sha512-ISyBTRMmMYagUxhcpyEH0hpXRd/KqDU4ymofPgl2XAkY9ZhQ+h0ovEZJIiPop13UmR/54oA2cgMDjgroRelaEw==} - '@vue/compiler-core@3.5.11': - resolution: {integrity: sha512-PwAdxs7/9Hc3ieBO12tXzmTD+Ln4qhT/56S+8DvrrZ4kLDn4Z/AMUr8tXJD0axiJBS0RKIoNaR0yMuQB9v9Udg==} + '@vue/compiler-core@3.5.13': + resolution: {integrity: sha512-oOdAkwqUfW1WqpwSYJce06wvt6HljgY3fGeM9NcVA1HaYOij3mZG9Rkysn0OHuyUAGMbEbARIpsG+LPVlBJ5/Q==} - '@vue/compiler-dom@3.5.11': - resolution: {integrity: sha512-pyGf8zdbDDRkBrEzf8p7BQlMKNNF5Fk/Cf/fQ6PiUz9at4OaUfyXW0dGJTo2Vl1f5U9jSLCNf0EZJEogLXoeew==} + '@vue/compiler-dom@3.5.12': + resolution: {integrity: sha512-9G6PbJ03uwxLHKQ3P42cMTi85lDRvGLB2rSGOiQqtXELat6uI4n8cNz9yjfVHRPIu+MsK6TE418Giruvgptckg==} - '@vue/compiler-sfc@3.5.11': - resolution: {integrity: sha512-gsbBtT4N9ANXXepprle+X9YLg2htQk1sqH/qGJ/EApl+dgpUBdTv3yP7YlR535uHZY3n6XaR0/bKo0BgwwDniw==} + '@vue/compiler-dom@3.5.13': + resolution: {integrity: sha512-ZOJ46sMOKUjO3e94wPdCzQ6P1Lx/vhp2RSvfaab88Ajexs0AHeV0uasYhi99WPaogmBlRHNRuly8xV75cNTMDA==} - '@vue/compiler-ssr@3.5.11': - resolution: {integrity: sha512-P4+GPjOuC2aFTk1Z4WANvEhyOykcvEd5bIj2KVNGKGfM745LaXGr++5njpdBTzVz5pZifdlR1kpYSJJpIlSePA==} + '@vue/compiler-sfc@3.5.13': + resolution: {integrity: sha512-6VdaljMpD82w6c2749Zhf5T9u5uLBWKnVue6XWxprDobftnletJ8+oel7sexFfM3qIxNmVE7LSFGTpv6obNyaQ==} + + '@vue/compiler-ssr@3.5.13': + resolution: {integrity: sha512-wMH6vrYHxQl/IybKJagqbquvxpWCuVYpoUJfCqFZwa/JY1GdATAQ+TgVtgrwwMZ0D07QhA99rs/EAAWfvG6KpA==} '@vue/compiler-vue2@2.7.16': resolution: {integrity: sha512-qYC3Psj9S/mfu9uVi5WvNZIzq+xnXMhOwbTFKKDD7b1lhpnn71jXSFdTQ+WsIEk0ONCd7VV2IMm7ONl6tbQ86A==} @@ -520,25 +519,33 @@ packages: typescript: optional: true - '@vue/reactivity@3.5.11': - resolution: {integrity: sha512-Nqo5VZEn8MJWlCce8XoyVqHZbd5P2NH+yuAaFzuNSR96I+y1cnuUiq7xfSG+kyvLSiWmaHTKP1r3OZY4mMD50w==} + '@vue/reactivity@3.5.13': + resolution: {integrity: sha512-NaCwtw8o48B9I6L1zl2p41OHo/2Z4wqYGGIK1Khu5T7yxrn+ATOixn/Udn2m+6kZKB/J7cuT9DbWWhRxqixACg==} - '@vue/runtime-core@3.5.11': - resolution: {integrity: sha512-7PsxFGqwfDhfhh0OcDWBG1DaIQIVOLgkwA5q6MtkPiDFjp5gohVnJEahSktwSFLq7R5PtxDKy6WKURVN1UDbzA==} + '@vue/runtime-core@3.5.13': + resolution: {integrity: sha512-Fj4YRQ3Az0WTZw1sFe+QDb0aXCerigEpw418pw1HBUKFtnQHWzwojaukAs2X/c9DQz4MQ4bsXTGlcpGxU/RCIw==} - '@vue/runtime-dom@3.5.11': - resolution: {integrity: sha512-GNghjecT6IrGf0UhuYmpgaOlN7kxzQBhxWEn08c/SQDxv1yy4IXI1bn81JgEpQ4IXjRxWtPyI8x0/7TF5rPfYQ==} + '@vue/runtime-dom@3.5.13': + resolution: {integrity: sha512-dLaj94s93NYLqjLiyFzVs9X6dWhTdAlEAciC3Moq7gzAc13VJUdCnjjRurNM6uTLFATRHexHCTu/Xp3eW6yoog==} - '@vue/server-renderer@3.5.11': - resolution: {integrity: sha512-cVOwYBxR7Wb1B1FoxYvtjJD8X/9E5nlH4VSkJy2uMA1MzYNdzAAB//l8nrmN9py/4aP+3NjWukf9PZ3TeWULaA==} + '@vue/server-renderer@3.5.13': + resolution: {integrity: sha512-wAi4IRJV/2SAW3htkTlB+dHeRmpTiVIK1OGLWV1yeStVSebSQQOwGwIq0D3ZIoBj2C2qpgz5+vX9iEBkTdk5YA==} peerDependencies: - vue: 3.5.11 + vue: 3.5.13 + + '@vue/shared@3.5.12': + resolution: {integrity: sha512-L2RPSAwUFbgZH20etwrXyVyCBu9OxRSi8T/38QsvnkJyvq2LufW2lDCOzm7t/U9C1mkhJGWYfCuFBCmIuNivrg==} - '@vue/shared@3.5.11': - resolution: {integrity: sha512-W8GgysJVnFo81FthhzurdRAWP/byq3q2qIw70e0JWblzVhjgOMiC2GyovXrZTFQJnFVryYaKGP3Tc9vYzYm6PQ==} + '@vue/shared@3.5.13': + resolution: {integrity: sha512-/hnE/qP5ZoGpol0a5mDi45bOd7t3tjYJBjsgCsivow7D48cJeV5l05RD82lPqi7gRiphZM37rnhW1l6ZoCNNnQ==} - acorn@8.12.1: - resolution: {integrity: sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==} + acorn-typescript@1.4.13: + resolution: {integrity: sha512-xsc9Xv0xlVfwp2o7sQ+GCQ1PgbkdcpWdTzrwXxO3xDMTAywVS3oXVOcOHuRjAPkS4P9b+yc/qNF15460v+jp4Q==} + peerDependencies: + acorn: '>=8.9.0' + + acorn@8.14.0: + resolution: {integrity: sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==} engines: {node: '>=0.4.0'} hasBin: true @@ -564,10 +571,6 @@ packages: ajv@8.13.0: resolution: {integrity: sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==} - ansi-styles@3.2.1: - resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==} - engines: {node: '>=4'} - argparse@1.0.10: resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==} @@ -588,30 +591,13 @@ packages: brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} - browserslist@4.24.0: - resolution: {integrity: sha512-Rmb62sR1Zpjql25eSanFGEhAxcFwfA1K0GuQcLoaJBAcENegrQut3hYdhXFF1obQfiDyqIW/cLM5HSJ/9k884A==} + browserslist@4.24.2: + resolution: {integrity: sha512-ZIc+Q62revdMcqC6aChtW4jz3My3klmCO1fEmINZY/8J3EpBg5/A/D0AKmBveUh6pgoeycoMkVMko84tuYS+Gg==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true - caniuse-lite@1.0.30001667: - resolution: {integrity: sha512-7LTwJjcRkzKFmtqGsibMeuXmvFDfZq/nzIjnmgCGzKKRVzjD72selLDK1oPF/Oxzmt4fNcPvTDvGqSDG4tCALw==} - - chalk@2.4.2: - resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} - engines: {node: '>=4'} - - chokidar@4.0.1: - resolution: {integrity: sha512-n8enUVCED/KVRQlab1hr3MVpcVMvxtZjmEa956u+4YijlmQED223XMSYj2tLuKvr4jcCTzNNMpQDUer72MMmzA==} - engines: {node: '>= 14.16.0'} - - code-red@1.0.4: - resolution: {integrity: sha512-7qJWqItLA8/VPVlKJlFXU+NBlo/qyfs39aJcuMT/2ere32ZqvF5OSxgdM5xOfJJ7O429gg2HM47y8v9P+9wrNw==} - - color-convert@1.9.3: - resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} - - color-name@1.1.3: - resolution: {integrity: sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==} + caniuse-lite@1.0.30001680: + resolution: {integrity: sha512-rPQy70G6AGUMnbwS1z6Xg+RkHYPAi18ihs47GH0jcxIG7wArmPgY3XbS2sRdBbxJljp3thdT8BIqv9ccCypiPA==} compare-versions@6.1.1: resolution: {integrity: sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg==} @@ -628,10 +614,6 @@ packages: convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} - css-tree@2.3.1: - resolution: {integrity: sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==} - engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0} - csstype@3.1.3: resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} @@ -651,8 +633,8 @@ packages: resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} engines: {node: '>=0.10.0'} - electron-to-chromium@1.5.33: - resolution: {integrity: sha512-+cYTcFB1QqD4j4LegwLfpCNxifb6dDFUAwk6RsLusCwIaZI6or2f+q8rs5tTB2YC53HhOlIbEaqHMAAC8IOIwA==} + electron-to-chromium@1.5.62: + resolution: {integrity: sha512-t8c+zLmJHa9dJy96yBZRXGQYoiCEnHYgFwn1asvSPZSUdVxnB62A4RASd7k41ytG3ErFBA0TpHlKg9D9SQBmLg==} entities@4.5.0: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} @@ -667,27 +649,18 @@ packages: resolution: {integrity: sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==} engines: {node: '>=6'} - escape-string-regexp@1.0.5: - resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==} - engines: {node: '>=0.8.0'} + esm-env@1.1.4: + resolution: {integrity: sha512-oO82nKPHKkzIj/hbtuDYy/JHqBHFlMIW36SDiPCVsj87ntDLcWN+sJ1erdVryd4NxODacFTsdrIE3b7IamqbOg==} + + esrap@1.2.2: + resolution: {integrity: sha512-F2pSJklxx1BlQIQgooczXCPHmcWpn6EsP5oo73LQfonG9fIlIENQ8vMmfGXeojP9MrkzUNAfyU5vdFlR9shHAw==} estree-walker@2.0.2: resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} - estree-walker@3.0.3: - resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} - fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} - fdir@6.4.0: - resolution: {integrity: sha512-3oB133prH1o4j/L5lLW7uOCF1PlD+/It2L0eL/iAqWMB91RBbqTewABqxhj0ibBd90EEmWZq7ntIWzVaWcXTGQ==} - peerDependencies: - picomatch: ^3 || ^4 - peerDependenciesMeta: - picomatch: - optional: true - fs-extra@7.0.1: resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==} engines: {node: '>=6 <7 || >=8'} @@ -711,10 +684,6 @@ packages: graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} - has-flag@3.0.0: - resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==} - engines: {node: '>=4'} - has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} @@ -735,8 +704,8 @@ packages: resolution: {integrity: sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==} engines: {node: '>= 0.4'} - is-reference@3.0.2: - resolution: {integrity: sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==} + is-reference@3.0.3: + resolution: {integrity: sha512-ixkJoqQvAP88E6wLydLGGqCJsrFUnqoH6HnaczB8XmDH1oaWU+xxdptvikTgaEhtZ53Ky6YXiBuUI2WXLMCwjw==} jju@1.4.0: resolution: {integrity: sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==} @@ -788,11 +757,8 @@ packages: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} engines: {node: '>=10'} - magic-string@0.30.11: - resolution: {integrity: sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==} - - mdn-data@2.0.30: - resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==} + magic-string@0.30.12: + resolution: {integrity: sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==} minimatch@3.0.8: resolution: {integrity: sha512-6FsRAQsxQ61mw+qP1ZzbL9Bc78x2p5OqNgNpnoAFLTrX8n5Kxph0CsnhmKKNXTWjXqU5L0pGPR7hYk+XWZr60Q==} @@ -804,10 +770,6 @@ packages: mlly@1.7.2: resolution: {integrity: sha512-tN3dvVHYVz4DhSXinXIk7u9syPYaJvio118uomkovAtWBT+RdbP6Lfh/5Lvo519YMmwBafwlh20IPTXIStscpA==} - mri@1.2.0: - resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} - engines: {node: '>=4'} - ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} @@ -831,15 +793,12 @@ packages: pathe@1.1.2: resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==} - periscopic@3.1.0: - resolution: {integrity: sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==} - - picocolors@1.1.0: - resolution: {integrity: sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==} + picocolors@1.1.1: + resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} - picomatch@2.3.1: - resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} - engines: {node: '>=8.6'} + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} + engines: {node: '>=12'} pkg-types@1.2.1: resolution: {integrity: sha512-sQoqa8alT3nHjGuTjuKgOnvjo4cljkufdtLMnO2LBP/wRwuDlo1tkaEdMxCRhyGRPacv/ztlZgDPm2b7FAmEvw==} @@ -848,6 +807,10 @@ packages: resolution: {integrity: sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==} engines: {node: ^10 || ^12 || >=14} + postcss@8.4.49: + resolution: {integrity: sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA==} + engines: {node: ^10 || ^12 || >=14} + punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -865,10 +828,6 @@ packages: resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} engines: {node: '>=0.10.0'} - readdirp@4.0.2: - resolution: {integrity: sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==} - engines: {node: '>= 14.16.0'} - require-from-string@2.0.2: resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} engines: {node: '>=0.10.0'} @@ -877,15 +836,11 @@ packages: resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} hasBin: true - rollup@4.24.0: - resolution: {integrity: sha512-DOmrlGSXNk1DM0ljiQA+i+o0rSLhtii1je5wgk60j49d1jHT5YYttBv1iWOnYSTG+fZZESUOSNiAl89SIet+Cg==} + rollup@4.24.4: + resolution: {integrity: sha512-vGorVWIsWfX3xbcyAS+I047kFKapHYivmkaT63Smj77XwvLSJos6M1xGqZnBPFQFBRZDOcG1QnYEIxAvTr/HjA==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true - sade@1.8.1: - resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==} - engines: {node: '>=6'} - scheduler@0.23.2: resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} @@ -898,11 +853,6 @@ packages: engines: {node: '>=10'} hasBin: true - semver@7.6.3: - resolution: {integrity: sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==} - engines: {node: '>=10'} - hasBin: true - source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -922,10 +872,6 @@ packages: resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} engines: {node: '>=8'} - supports-color@5.5.0: - resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==} - engines: {node: '>=4'} - supports-color@8.1.1: resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==} engines: {node: '>=10'} @@ -934,41 +880,26 @@ packages: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} - svelte-check@4.0.4: - resolution: {integrity: sha512-AcHWIPuZb1mh/jKoIrww0ebBPpAvwWd1bfXCnwC2dx4OkydNMaiG//+Xnry91RJMHFH7CiE+6Y2p332DRIaOXQ==} - engines: {node: '>= 18.0.0'} - hasBin: true - peerDependencies: - svelte: ^4.0.0 || ^5.0.0-next.0 - typescript: '>=5.0.0' - - svelte-hmr@0.16.0: - resolution: {integrity: sha512-Gyc7cOS3VJzLlfj7wKS0ZnzDVdv3Pn2IuVeJPk9m2skfhcu5bq3wtIZyQGggr7/Iim5rH5cncyQft/kRLupcnA==} - engines: {node: ^12.20 || ^14.13.1 || >= 16} - peerDependencies: - svelte: ^3.19.0 || ^4.0.0 - - svelte@4.2.19: - resolution: {integrity: sha512-IY1rnGr6izd10B0A8LqsBfmlT5OILVuZ7XsI0vdGPEvuonFV7NYEUK4dAkm9Zg2q0Um92kYjTpS1CAP3Nh/KWw==} - engines: {node: '>=16'} - - to-fast-properties@2.0.0: - resolution: {integrity: sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==} - engines: {node: '>=4'} + svelte@5.2.7: + resolution: {integrity: sha512-cEhPGuLHiH2+Z8B1FwQgiZJgA39uUmJR4516TKrM5zrp0/cuwJkfhUfcTxhAkznanAF5fXUKzvYR4o+Ksx3ZCQ==} + engines: {node: '>=18'} typescript@5.4.2: resolution: {integrity: sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==} engines: {node: '>=14.17'} hasBin: true - typescript@5.6.2: - resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} + typescript@5.6.3: + resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==} engines: {node: '>=14.17'} hasBin: true ufo@1.5.4: resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==} + undici-types@6.19.8: + resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} + universalify@0.1.2: resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} engines: {node: '>= 4.0.0'} @@ -982,11 +913,8 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} - veloxi@0.15.3: - resolution: {integrity: sha512-J7wc4cY6rb/9OTRIyJI16uWwjvgMhoqlSFEi+KdVIVZF9e5KfMAvSlRavyeqFGCl+fxd3lrIELFMexGWglbNIQ==} - - vite-plugin-dts@4.2.3: - resolution: {integrity: sha512-O5NalzHANQRwVw1xj8KQun3Bv8OSDAlNJXrnqoAz10BOuW8FVvY5g4ygj+DlJZL5mtSPuMu9vd3OfrdW5d4k6w==} + vite-plugin-dts@4.3.0: + resolution: {integrity: sha512-LkBJh9IbLwL6/rxh0C1/bOurDrIEmRE7joC+jFdOEEciAFPbpEKOLSAr5nNh5R7CJ45cMbksTrFfy52szzC5eA==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -995,8 +923,8 @@ packages: vite: optional: true - vite@5.4.8: - resolution: {integrity: sha512-FqrItQ4DT1NC4zCUqMB4c4AZORMKIa0m8/URVCZ77OZ/QSNeJ54bU1vrFADbDsuwfIPcgknRkmqakQcgnL4GiQ==} + vite@5.4.10: + resolution: {integrity: sha512-1hvaPshuPUtxeQ0hsVH3Mud0ZanOLwVTneA1EgbAM5LhaZEqyPWGRQ7BtaMvUrTDeEaC8pxtj6a6jku3x4z6SQ==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: @@ -1026,10 +954,10 @@ packages: terser: optional: true - vitefu@0.2.5: - resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} + vitefu@1.0.3: + resolution: {integrity: sha512-iKKfOMBHob2WxEJbqbJjHAkmYgvFDPhuqrO82om83S8RLk+17FtyMBfcyeH8GqD0ihShtkMW/zzJgiA51hCNCQ==} peerDependencies: - vite: ^3.0.0 || ^4.0.0 || ^5.0.0 + vite: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0-beta.0 peerDependenciesMeta: vite: optional: true @@ -1037,14 +965,8 @@ packages: vscode-uri@3.0.8: resolution: {integrity: sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw==} - vue-tsc@2.1.6: - resolution: {integrity: sha512-f98dyZp5FOukcYmbFpuSCJ4Z0vHSOSmxGttZJCsFeX0M4w/Rsq0s4uKXjcSRsZqsRgQa6z7SfuO+y0HVICE57Q==} - hasBin: true - peerDependencies: - typescript: '>=5.0.0' - - vue@3.5.11: - resolution: {integrity: sha512-/8Wurrd9J3lb72FTQS7gRMNQD4nztTtKPmuDuPuhqXmmpD6+skVjAeahNpVzsuky6Sy9gy7wn8UadqPtt9SQIg==} + vue@3.5.13: + resolution: {integrity: sha512-wmeiSMxkZCSc+PM2w2VRsOYAZC8GdipNFRTsLSfodVqI9mbejKeXEGr8SckuLnrQPGe3oJN5c3K0vpoU9q/wCQ==} peerDependencies: typescript: '*' peerDependenciesMeta: @@ -1057,6 +979,9 @@ packages: yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} + zimmerframe@1.1.2: + resolution: {integrity: sha512-rAbqEGa8ovJy4pyBxZM70hg4pE6gDgaQ0Sl9M3enG3I0d6H4XSAM3GeNGLKnsBpuijUow064sf7ww1nutC5/3w==} + snapshots: '@ampproject/remapping@2.3.0': @@ -1064,25 +989,26 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 - '@babel/code-frame@7.25.7': + '@babel/code-frame@7.26.2': dependencies: - '@babel/highlight': 7.25.7 - picocolors: 1.1.0 + '@babel/helper-validator-identifier': 7.25.9 + js-tokens: 4.0.0 + picocolors: 1.1.1 - '@babel/compat-data@7.25.7': {} + '@babel/compat-data@7.26.2': {} - '@babel/core@7.25.7': + '@babel/core@7.26.0': dependencies: '@ampproject/remapping': 2.3.0 - '@babel/code-frame': 7.25.7 - '@babel/generator': 7.25.7 - '@babel/helper-compilation-targets': 7.25.7 - '@babel/helper-module-transforms': 7.25.7(@babel/core@7.25.7) - '@babel/helpers': 7.25.7 - '@babel/parser': 7.25.7 - '@babel/template': 7.25.7 - '@babel/traverse': 7.25.7 - '@babel/types': 7.25.7 + '@babel/code-frame': 7.26.2 + '@babel/generator': 7.26.2 + '@babel/helper-compilation-targets': 7.25.9 + '@babel/helper-module-transforms': 7.26.0(@babel/core@7.26.0) + '@babel/helpers': 7.26.0 + '@babel/parser': 7.26.2 + '@babel/template': 7.25.9 + '@babel/traverse': 7.25.9 + '@babel/types': 7.26.0 convert-source-map: 2.0.0 debug: 4.3.7 gensync: 1.0.0-beta.2 @@ -1091,102 +1017,87 @@ snapshots: transitivePeerDependencies: - supports-color - '@babel/generator@7.25.7': + '@babel/generator@7.26.2': dependencies: - '@babel/types': 7.25.7 + '@babel/parser': 7.26.2 + '@babel/types': 7.26.0 '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 jsesc: 3.0.2 - '@babel/helper-compilation-targets@7.25.7': + '@babel/helper-compilation-targets@7.25.9': dependencies: - '@babel/compat-data': 7.25.7 - '@babel/helper-validator-option': 7.25.7 - browserslist: 4.24.0 + '@babel/compat-data': 7.26.2 + '@babel/helper-validator-option': 7.25.9 + browserslist: 4.24.2 lru-cache: 5.1.1 semver: 6.3.1 - '@babel/helper-module-imports@7.25.7': + '@babel/helper-module-imports@7.25.9': dependencies: - '@babel/traverse': 7.25.7 - '@babel/types': 7.25.7 + '@babel/traverse': 7.25.9 + '@babel/types': 7.26.0 transitivePeerDependencies: - supports-color - '@babel/helper-module-transforms@7.25.7(@babel/core@7.25.7)': + '@babel/helper-module-transforms@7.26.0(@babel/core@7.26.0)': dependencies: - '@babel/core': 7.25.7 - '@babel/helper-module-imports': 7.25.7 - '@babel/helper-simple-access': 7.25.7 - '@babel/helper-validator-identifier': 7.25.7 - '@babel/traverse': 7.25.7 + '@babel/core': 7.26.0 + '@babel/helper-module-imports': 7.25.9 + '@babel/helper-validator-identifier': 7.25.9 + '@babel/traverse': 7.25.9 transitivePeerDependencies: - supports-color - '@babel/helper-plugin-utils@7.25.7': {} + '@babel/helper-plugin-utils@7.25.9': {} - '@babel/helper-simple-access@7.25.7': - dependencies: - '@babel/traverse': 7.25.7 - '@babel/types': 7.25.7 - transitivePeerDependencies: - - supports-color - - '@babel/helper-string-parser@7.25.7': {} + '@babel/helper-string-parser@7.25.9': {} - '@babel/helper-validator-identifier@7.25.7': {} + '@babel/helper-validator-identifier@7.25.9': {} - '@babel/helper-validator-option@7.25.7': {} - - '@babel/helpers@7.25.7': - dependencies: - '@babel/template': 7.25.7 - '@babel/types': 7.25.7 + '@babel/helper-validator-option@7.25.9': {} - '@babel/highlight@7.25.7': + '@babel/helpers@7.26.0': dependencies: - '@babel/helper-validator-identifier': 7.25.7 - chalk: 2.4.2 - js-tokens: 4.0.0 - picocolors: 1.1.0 + '@babel/template': 7.25.9 + '@babel/types': 7.26.0 - '@babel/parser@7.25.7': + '@babel/parser@7.26.2': dependencies: - '@babel/types': 7.25.7 + '@babel/types': 7.26.0 - '@babel/plugin-transform-react-jsx-self@7.25.7(@babel/core@7.25.7)': + '@babel/plugin-transform-react-jsx-self@7.25.9(@babel/core@7.26.0)': dependencies: - '@babel/core': 7.25.7 - '@babel/helper-plugin-utils': 7.25.7 + '@babel/core': 7.26.0 + '@babel/helper-plugin-utils': 7.25.9 - '@babel/plugin-transform-react-jsx-source@7.25.7(@babel/core@7.25.7)': + '@babel/plugin-transform-react-jsx-source@7.25.9(@babel/core@7.26.0)': dependencies: - '@babel/core': 7.25.7 - '@babel/helper-plugin-utils': 7.25.7 + '@babel/core': 7.26.0 + '@babel/helper-plugin-utils': 7.25.9 - '@babel/template@7.25.7': + '@babel/template@7.25.9': dependencies: - '@babel/code-frame': 7.25.7 - '@babel/parser': 7.25.7 - '@babel/types': 7.25.7 + '@babel/code-frame': 7.26.2 + '@babel/parser': 7.26.2 + '@babel/types': 7.26.0 - '@babel/traverse@7.25.7': + '@babel/traverse@7.25.9': dependencies: - '@babel/code-frame': 7.25.7 - '@babel/generator': 7.25.7 - '@babel/parser': 7.25.7 - '@babel/template': 7.25.7 - '@babel/types': 7.25.7 + '@babel/code-frame': 7.26.2 + '@babel/generator': 7.26.2 + '@babel/parser': 7.26.2 + '@babel/template': 7.25.9 + '@babel/types': 7.26.0 debug: 4.3.7 globals: 11.12.0 transitivePeerDependencies: - supports-color - '@babel/types@7.25.7': + '@babel/types@7.26.0': dependencies: - '@babel/helper-string-parser': 7.25.7 - '@babel/helper-validator-identifier': 7.25.7 - to-fast-properties: 2.0.0 + '@babel/helper-string-parser': 7.25.9 + '@babel/helper-validator-identifier': 7.25.9 '@esbuild/aix-ppc64@0.21.5': optional: true @@ -1274,23 +1185,23 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 - '@microsoft/api-extractor-model@7.29.6': + '@microsoft/api-extractor-model@7.29.8(@types/node@22.9.0)': dependencies: '@microsoft/tsdoc': 0.15.0 '@microsoft/tsdoc-config': 0.17.0 - '@rushstack/node-core-library': 5.7.0 + '@rushstack/node-core-library': 5.9.0(@types/node@22.9.0) transitivePeerDependencies: - '@types/node' - '@microsoft/api-extractor@7.47.7': + '@microsoft/api-extractor@7.47.11(@types/node@22.9.0)': dependencies: - '@microsoft/api-extractor-model': 7.29.6 + '@microsoft/api-extractor-model': 7.29.8(@types/node@22.9.0) '@microsoft/tsdoc': 0.15.0 '@microsoft/tsdoc-config': 0.17.0 - '@rushstack/node-core-library': 5.7.0 + '@rushstack/node-core-library': 5.9.0(@types/node@22.9.0) '@rushstack/rig-package': 0.5.3 - '@rushstack/terminal': 0.14.0 - '@rushstack/ts-command-line': 4.22.6 + '@rushstack/terminal': 0.14.2(@types/node@22.9.0) + '@rushstack/ts-command-line': 4.23.0(@types/node@22.9.0) lodash: 4.17.21 minimatch: 3.0.8 resolve: 1.22.8 @@ -1309,63 +1220,69 @@ snapshots: '@microsoft/tsdoc@0.15.0': {} - '@rollup/pluginutils@5.1.2(rollup@4.24.0)': + '@rollup/pluginutils@5.1.3(rollup@4.24.4)': dependencies: '@types/estree': 1.0.6 estree-walker: 2.0.2 - picomatch: 2.3.1 + picomatch: 4.0.2 optionalDependencies: - rollup: 4.24.0 + rollup: 4.24.4 + + '@rollup/rollup-android-arm-eabi@4.24.4': + optional: true + + '@rollup/rollup-android-arm64@4.24.4': + optional: true - '@rollup/rollup-android-arm-eabi@4.24.0': + '@rollup/rollup-darwin-arm64@4.24.4': optional: true - '@rollup/rollup-android-arm64@4.24.0': + '@rollup/rollup-darwin-x64@4.24.4': optional: true - '@rollup/rollup-darwin-arm64@4.24.0': + '@rollup/rollup-freebsd-arm64@4.24.4': optional: true - '@rollup/rollup-darwin-x64@4.24.0': + '@rollup/rollup-freebsd-x64@4.24.4': optional: true - '@rollup/rollup-linux-arm-gnueabihf@4.24.0': + '@rollup/rollup-linux-arm-gnueabihf@4.24.4': optional: true - '@rollup/rollup-linux-arm-musleabihf@4.24.0': + '@rollup/rollup-linux-arm-musleabihf@4.24.4': optional: true - '@rollup/rollup-linux-arm64-gnu@4.24.0': + '@rollup/rollup-linux-arm64-gnu@4.24.4': optional: true - '@rollup/rollup-linux-arm64-musl@4.24.0': + '@rollup/rollup-linux-arm64-musl@4.24.4': optional: true - '@rollup/rollup-linux-powerpc64le-gnu@4.24.0': + '@rollup/rollup-linux-powerpc64le-gnu@4.24.4': optional: true - '@rollup/rollup-linux-riscv64-gnu@4.24.0': + '@rollup/rollup-linux-riscv64-gnu@4.24.4': optional: true - '@rollup/rollup-linux-s390x-gnu@4.24.0': + '@rollup/rollup-linux-s390x-gnu@4.24.4': optional: true - '@rollup/rollup-linux-x64-gnu@4.24.0': + '@rollup/rollup-linux-x64-gnu@4.24.4': optional: true - '@rollup/rollup-linux-x64-musl@4.24.0': + '@rollup/rollup-linux-x64-musl@4.24.4': optional: true - '@rollup/rollup-win32-arm64-msvc@4.24.0': + '@rollup/rollup-win32-arm64-msvc@4.24.4': optional: true - '@rollup/rollup-win32-ia32-msvc@4.24.0': + '@rollup/rollup-win32-ia32-msvc@4.24.4': optional: true - '@rollup/rollup-win32-x64-msvc@4.24.0': + '@rollup/rollup-win32-x64-msvc@4.24.4': optional: true - '@rushstack/node-core-library@5.7.0': + '@rushstack/node-core-library@5.9.0(@types/node@22.9.0)': dependencies: ajv: 8.13.0 ajv-draft-04: 1.0.0(ajv@8.13.0) @@ -1375,188 +1292,212 @@ snapshots: jju: 1.4.0 resolve: 1.22.8 semver: 7.5.4 + optionalDependencies: + '@types/node': 22.9.0 '@rushstack/rig-package@0.5.3': dependencies: resolve: 1.22.8 strip-json-comments: 3.1.1 - '@rushstack/terminal@0.14.0': + '@rushstack/terminal@0.14.2(@types/node@22.9.0)': dependencies: - '@rushstack/node-core-library': 5.7.0 + '@rushstack/node-core-library': 5.9.0(@types/node@22.9.0) supports-color: 8.1.1 + optionalDependencies: + '@types/node': 22.9.0 - '@rushstack/ts-command-line@4.22.6': + '@rushstack/ts-command-line@4.23.0(@types/node@22.9.0)': dependencies: - '@rushstack/terminal': 0.14.0 + '@rushstack/terminal': 0.14.2(@types/node@22.9.0) '@types/argparse': 1.0.38 argparse: 1.0.10 string-argv: 0.3.2 transitivePeerDependencies: - '@types/node' - '@sveltejs/vite-plugin-svelte-inspector@2.1.0(@sveltejs/vite-plugin-svelte@3.1.2(svelte@4.2.19)(vite@5.4.8))(svelte@4.2.19)(vite@5.4.8)': + '@sveltejs/vite-plugin-svelte-inspector@3.0.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.4.10(@types/node@22.9.0)))(svelte@5.2.7)(vite@5.4.10(@types/node@22.9.0))': dependencies: - '@sveltejs/vite-plugin-svelte': 3.1.2(svelte@4.2.19)(vite@5.4.8) + '@sveltejs/vite-plugin-svelte': 4.0.1(svelte@5.2.7)(vite@5.4.10(@types/node@22.9.0)) debug: 4.3.7 - svelte: 4.2.19 - vite: 5.4.8 + svelte: 5.2.7 + vite: 5.4.10(@types/node@22.9.0) transitivePeerDependencies: - supports-color - '@sveltejs/vite-plugin-svelte@3.1.2(svelte@4.2.19)(vite@5.4.8)': + '@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.4.10(@types/node@22.9.0))': dependencies: - '@sveltejs/vite-plugin-svelte-inspector': 2.1.0(@sveltejs/vite-plugin-svelte@3.1.2(svelte@4.2.19)(vite@5.4.8))(svelte@4.2.19)(vite@5.4.8) + '@sveltejs/vite-plugin-svelte-inspector': 3.0.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.4.10(@types/node@22.9.0)))(svelte@5.2.7)(vite@5.4.10(@types/node@22.9.0)) debug: 4.3.7 deepmerge: 4.3.1 kleur: 4.1.5 - magic-string: 0.30.11 - svelte: 4.2.19 - svelte-hmr: 0.16.0(svelte@4.2.19) - vite: 5.4.8 - vitefu: 0.2.5(vite@5.4.8) + magic-string: 0.30.12 + svelte: 5.2.7 + vite: 5.4.10(@types/node@22.9.0) + vitefu: 1.0.3(vite@5.4.10(@types/node@22.9.0)) transitivePeerDependencies: - supports-color - '@tsconfig/svelte@5.0.4': {} - '@types/argparse@1.0.38': {} '@types/babel__core@7.20.5': dependencies: - '@babel/parser': 7.25.7 - '@babel/types': 7.25.7 + '@babel/parser': 7.26.2 + '@babel/types': 7.26.0 '@types/babel__generator': 7.6.8 '@types/babel__template': 7.4.4 '@types/babel__traverse': 7.20.6 '@types/babel__generator@7.6.8': dependencies: - '@babel/types': 7.25.7 + '@babel/types': 7.26.0 '@types/babel__template@7.4.4': dependencies: - '@babel/parser': 7.25.7 - '@babel/types': 7.25.7 + '@babel/parser': 7.26.2 + '@babel/types': 7.26.0 '@types/babel__traverse@7.20.6': dependencies: - '@babel/types': 7.25.7 + '@babel/types': 7.26.0 '@types/estree@1.0.6': {} + '@types/node@22.9.0': + dependencies: + undici-types: 6.19.8 + '@types/prop-types@15.7.13': {} - '@types/react-dom@18.3.0': + '@types/react-dom@18.3.1': dependencies: - '@types/react': 18.3.11 + '@types/react': 18.3.12 - '@types/react@18.3.11': + '@types/react@18.3.12': dependencies: '@types/prop-types': 15.7.13 csstype: 3.1.3 - '@vitejs/plugin-react@4.3.2(vite@5.4.8)': + '@vitejs/plugin-react@4.3.3(vite@5.4.10(@types/node@22.9.0))': dependencies: - '@babel/core': 7.25.7 - '@babel/plugin-transform-react-jsx-self': 7.25.7(@babel/core@7.25.7) - '@babel/plugin-transform-react-jsx-source': 7.25.7(@babel/core@7.25.7) + '@babel/core': 7.26.0 + '@babel/plugin-transform-react-jsx-self': 7.25.9(@babel/core@7.26.0) + '@babel/plugin-transform-react-jsx-source': 7.25.9(@babel/core@7.26.0) '@types/babel__core': 7.20.5 react-refresh: 0.14.2 - vite: 5.4.8 + vite: 5.4.10(@types/node@22.9.0) transitivePeerDependencies: - supports-color - '@vitejs/plugin-vue@5.1.4(vite@5.4.8)(vue@3.5.11(typescript@5.6.2))': + '@vitejs/plugin-vue@5.2.0(vite@5.4.10(@types/node@22.9.0))(vue@3.5.13(typescript@5.6.3))': dependencies: - vite: 5.4.8 - vue: 3.5.11(typescript@5.6.2) + vite: 5.4.10(@types/node@22.9.0) + vue: 3.5.13(typescript@5.6.3) - '@volar/language-core@2.4.6': + '@volar/language-core@2.4.8': dependencies: - '@volar/source-map': 2.4.6 + '@volar/source-map': 2.4.8 - '@volar/source-map@2.4.6': {} + '@volar/source-map@2.4.8': {} - '@volar/typescript@2.4.6': + '@volar/typescript@2.4.8': dependencies: - '@volar/language-core': 2.4.6 + '@volar/language-core': 2.4.8 path-browserify: 1.0.1 vscode-uri: 3.0.8 - '@vue/compiler-core@3.5.11': + '@vue/compiler-core@3.5.12': dependencies: - '@babel/parser': 7.25.7 - '@vue/shared': 3.5.11 + '@babel/parser': 7.26.2 + '@vue/shared': 3.5.12 entities: 4.5.0 estree-walker: 2.0.2 source-map-js: 1.2.1 - '@vue/compiler-dom@3.5.11': + '@vue/compiler-core@3.5.13': dependencies: - '@vue/compiler-core': 3.5.11 - '@vue/shared': 3.5.11 + '@babel/parser': 7.26.2 + '@vue/shared': 3.5.13 + entities: 4.5.0 + estree-walker: 2.0.2 + source-map-js: 1.2.1 - '@vue/compiler-sfc@3.5.11': + '@vue/compiler-dom@3.5.12': dependencies: - '@babel/parser': 7.25.7 - '@vue/compiler-core': 3.5.11 - '@vue/compiler-dom': 3.5.11 - '@vue/compiler-ssr': 3.5.11 - '@vue/shared': 3.5.11 + '@vue/compiler-core': 3.5.12 + '@vue/shared': 3.5.12 + + '@vue/compiler-dom@3.5.13': + dependencies: + '@vue/compiler-core': 3.5.13 + '@vue/shared': 3.5.13 + + '@vue/compiler-sfc@3.5.13': + dependencies: + '@babel/parser': 7.26.2 + '@vue/compiler-core': 3.5.13 + '@vue/compiler-dom': 3.5.13 + '@vue/compiler-ssr': 3.5.13 + '@vue/shared': 3.5.13 estree-walker: 2.0.2 - magic-string: 0.30.11 - postcss: 8.4.47 + magic-string: 0.30.12 + postcss: 8.4.49 source-map-js: 1.2.1 - '@vue/compiler-ssr@3.5.11': + '@vue/compiler-ssr@3.5.13': dependencies: - '@vue/compiler-dom': 3.5.11 - '@vue/shared': 3.5.11 + '@vue/compiler-dom': 3.5.13 + '@vue/shared': 3.5.13 '@vue/compiler-vue2@2.7.16': dependencies: de-indent: 1.0.2 he: 1.2.0 - '@vue/language-core@2.1.6(typescript@5.6.2)': + '@vue/language-core@2.1.6(typescript@5.6.3)': dependencies: - '@volar/language-core': 2.4.6 - '@vue/compiler-dom': 3.5.11 + '@volar/language-core': 2.4.8 + '@vue/compiler-dom': 3.5.12 '@vue/compiler-vue2': 2.7.16 - '@vue/shared': 3.5.11 + '@vue/shared': 3.5.12 computeds: 0.0.1 minimatch: 9.0.5 muggle-string: 0.4.1 path-browserify: 1.0.1 optionalDependencies: - typescript: 5.6.2 + typescript: 5.6.3 - '@vue/reactivity@3.5.11': + '@vue/reactivity@3.5.13': dependencies: - '@vue/shared': 3.5.11 + '@vue/shared': 3.5.13 - '@vue/runtime-core@3.5.11': + '@vue/runtime-core@3.5.13': dependencies: - '@vue/reactivity': 3.5.11 - '@vue/shared': 3.5.11 + '@vue/reactivity': 3.5.13 + '@vue/shared': 3.5.13 - '@vue/runtime-dom@3.5.11': + '@vue/runtime-dom@3.5.13': dependencies: - '@vue/reactivity': 3.5.11 - '@vue/runtime-core': 3.5.11 - '@vue/shared': 3.5.11 + '@vue/reactivity': 3.5.13 + '@vue/runtime-core': 3.5.13 + '@vue/shared': 3.5.13 csstype: 3.1.3 - '@vue/server-renderer@3.5.11(vue@3.5.11(typescript@5.6.2))': + '@vue/server-renderer@3.5.13(vue@3.5.13(typescript@5.6.3))': dependencies: - '@vue/compiler-ssr': 3.5.11 - '@vue/shared': 3.5.11 - vue: 3.5.11(typescript@5.6.2) + '@vue/compiler-ssr': 3.5.13 + '@vue/shared': 3.5.13 + vue: 3.5.13(typescript@5.6.3) - '@vue/shared@3.5.11': {} + '@vue/shared@3.5.12': {} - acorn@8.12.1: {} + '@vue/shared@3.5.13': {} + + acorn-typescript@1.4.13(acorn@8.14.0): + dependencies: + acorn: 8.14.0 + + acorn@8.14.0: {} ajv-draft-04@1.0.0(ajv@8.13.0): optionalDependencies: @@ -1580,10 +1521,6 @@ snapshots: require-from-string: 2.0.2 uri-js: 4.4.1 - ansi-styles@3.2.1: - dependencies: - color-convert: 1.9.3 - argparse@1.0.10: dependencies: sprintf-js: 1.0.3 @@ -1603,38 +1540,14 @@ snapshots: dependencies: balanced-match: 1.0.2 - browserslist@4.24.0: + browserslist@4.24.2: dependencies: - caniuse-lite: 1.0.30001667 - electron-to-chromium: 1.5.33 + caniuse-lite: 1.0.30001680 + electron-to-chromium: 1.5.62 node-releases: 2.0.18 - update-browserslist-db: 1.1.1(browserslist@4.24.0) - - caniuse-lite@1.0.30001667: {} - - chalk@2.4.2: - dependencies: - ansi-styles: 3.2.1 - escape-string-regexp: 1.0.5 - supports-color: 5.5.0 - - chokidar@4.0.1: - dependencies: - readdirp: 4.0.2 + update-browserslist-db: 1.1.1(browserslist@4.24.2) - code-red@1.0.4: - dependencies: - '@jridgewell/sourcemap-codec': 1.5.0 - '@types/estree': 1.0.6 - acorn: 8.12.1 - estree-walker: 3.0.3 - periscopic: 3.1.0 - - color-convert@1.9.3: - dependencies: - color-name: 1.1.3 - - color-name@1.1.3: {} + caniuse-lite@1.0.30001680: {} compare-versions@6.1.1: {} @@ -1646,11 +1559,6 @@ snapshots: convert-source-map@2.0.0: {} - css-tree@2.3.1: - dependencies: - mdn-data: 2.0.30 - source-map-js: 1.2.1 - csstype@3.1.3: {} de-indent@1.0.2: {} @@ -1661,7 +1569,7 @@ snapshots: deepmerge@4.3.1: {} - electron-to-chromium@1.5.33: {} + electron-to-chromium@1.5.62: {} entities@4.5.0: {} @@ -1693,17 +1601,16 @@ snapshots: escalade@3.2.0: {} - escape-string-regexp@1.0.5: {} - - estree-walker@2.0.2: {} + esm-env@1.1.4: {} - estree-walker@3.0.3: + esrap@1.2.2: dependencies: + '@jridgewell/sourcemap-codec': 1.5.0 '@types/estree': 1.0.6 - fast-deep-equal@3.1.3: {} + estree-walker@2.0.2: {} - fdir@6.4.0: {} + fast-deep-equal@3.1.3: {} fs-extra@7.0.1: dependencies: @@ -1722,8 +1629,6 @@ snapshots: graceful-fs@4.2.11: {} - has-flag@3.0.0: {} - has-flag@4.0.0: {} hasown@2.0.2: @@ -1738,7 +1643,7 @@ snapshots: dependencies: hasown: 2.0.2 - is-reference@3.0.2: + is-reference@3.0.3: dependencies: '@types/estree': 1.0.6 @@ -1781,12 +1686,10 @@ snapshots: dependencies: yallist: 4.0.0 - magic-string@0.30.11: + magic-string@0.30.12: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 - mdn-data@2.0.30: {} - minimatch@3.0.8: dependencies: brace-expansion: 1.1.11 @@ -1797,13 +1700,11 @@ snapshots: mlly@1.7.2: dependencies: - acorn: 8.12.1 + acorn: 8.14.0 pathe: 1.1.2 pkg-types: 1.2.1 ufo: 1.5.4 - mri@1.2.0: {} - ms@2.1.3: {} muggle-string@0.4.1: {} @@ -1818,15 +1719,9 @@ snapshots: pathe@1.1.2: {} - periscopic@3.1.0: - dependencies: - '@types/estree': 1.0.6 - estree-walker: 3.0.3 - is-reference: 3.0.2 + picocolors@1.1.1: {} - picocolors@1.1.0: {} - - picomatch@2.3.1: {} + picomatch@4.0.2: {} pkg-types@1.2.1: dependencies: @@ -1837,7 +1732,13 @@ snapshots: postcss@8.4.47: dependencies: nanoid: 3.3.7 - picocolors: 1.1.0 + picocolors: 1.1.1 + source-map-js: 1.2.1 + + postcss@8.4.49: + dependencies: + nanoid: 3.3.7 + picocolors: 1.1.1 source-map-js: 1.2.1 punycode@2.3.1: {} @@ -1854,8 +1755,6 @@ snapshots: dependencies: loose-envify: 1.4.0 - readdirp@4.0.2: {} - require-from-string@2.0.2: {} resolve@1.22.8: @@ -1864,32 +1763,30 @@ snapshots: path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 - rollup@4.24.0: + rollup@4.24.4: dependencies: '@types/estree': 1.0.6 optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.24.0 - '@rollup/rollup-android-arm64': 4.24.0 - '@rollup/rollup-darwin-arm64': 4.24.0 - '@rollup/rollup-darwin-x64': 4.24.0 - '@rollup/rollup-linux-arm-gnueabihf': 4.24.0 - '@rollup/rollup-linux-arm-musleabihf': 4.24.0 - '@rollup/rollup-linux-arm64-gnu': 4.24.0 - '@rollup/rollup-linux-arm64-musl': 4.24.0 - '@rollup/rollup-linux-powerpc64le-gnu': 4.24.0 - '@rollup/rollup-linux-riscv64-gnu': 4.24.0 - '@rollup/rollup-linux-s390x-gnu': 4.24.0 - '@rollup/rollup-linux-x64-gnu': 4.24.0 - '@rollup/rollup-linux-x64-musl': 4.24.0 - '@rollup/rollup-win32-arm64-msvc': 4.24.0 - '@rollup/rollup-win32-ia32-msvc': 4.24.0 - '@rollup/rollup-win32-x64-msvc': 4.24.0 + '@rollup/rollup-android-arm-eabi': 4.24.4 + '@rollup/rollup-android-arm64': 4.24.4 + '@rollup/rollup-darwin-arm64': 4.24.4 + '@rollup/rollup-darwin-x64': 4.24.4 + '@rollup/rollup-freebsd-arm64': 4.24.4 + '@rollup/rollup-freebsd-x64': 4.24.4 + '@rollup/rollup-linux-arm-gnueabihf': 4.24.4 + '@rollup/rollup-linux-arm-musleabihf': 4.24.4 + '@rollup/rollup-linux-arm64-gnu': 4.24.4 + '@rollup/rollup-linux-arm64-musl': 4.24.4 + '@rollup/rollup-linux-powerpc64le-gnu': 4.24.4 + '@rollup/rollup-linux-riscv64-gnu': 4.24.4 + '@rollup/rollup-linux-s390x-gnu': 4.24.4 + '@rollup/rollup-linux-x64-gnu': 4.24.4 + '@rollup/rollup-linux-x64-musl': 4.24.4 + '@rollup/rollup-win32-arm64-msvc': 4.24.4 + '@rollup/rollup-win32-ia32-msvc': 4.24.4 + '@rollup/rollup-win32-x64-msvc': 4.24.4 fsevents: 2.3.3 - sade@1.8.1: - dependencies: - mri: 1.2.0 - scheduler@0.23.2: dependencies: loose-envify: 1.4.0 @@ -1900,8 +1797,6 @@ snapshots: dependencies: lru-cache: 6.0.0 - semver@7.6.3: {} - source-map-js@1.2.1: {} source-map@0.6.1: {} @@ -1912,121 +1807,94 @@ snapshots: strip-json-comments@3.1.1: {} - supports-color@5.5.0: - dependencies: - has-flag: 3.0.0 - supports-color@8.1.1: dependencies: has-flag: 4.0.0 supports-preserve-symlinks-flag@1.0.0: {} - svelte-check@4.0.4(svelte@4.2.19)(typescript@5.6.2): - dependencies: - '@jridgewell/trace-mapping': 0.3.25 - chokidar: 4.0.1 - fdir: 6.4.0 - picocolors: 1.1.0 - sade: 1.8.1 - svelte: 4.2.19 - typescript: 5.6.2 - transitivePeerDependencies: - - picomatch - - svelte-hmr@0.16.0(svelte@4.2.19): - dependencies: - svelte: 4.2.19 - - svelte@4.2.19: + svelte@5.2.7: dependencies: '@ampproject/remapping': 2.3.0 '@jridgewell/sourcemap-codec': 1.5.0 - '@jridgewell/trace-mapping': 0.3.25 '@types/estree': 1.0.6 - acorn: 8.12.1 + acorn: 8.14.0 + acorn-typescript: 1.4.13(acorn@8.14.0) aria-query: 5.3.2 axobject-query: 4.1.0 - code-red: 1.0.4 - css-tree: 2.3.1 - estree-walker: 3.0.3 - is-reference: 3.0.2 + esm-env: 1.1.4 + esrap: 1.2.2 + is-reference: 3.0.3 locate-character: 3.0.0 - magic-string: 0.30.11 - periscopic: 3.1.0 - - to-fast-properties@2.0.0: {} + magic-string: 0.30.12 + zimmerframe: 1.1.2 typescript@5.4.2: {} - typescript@5.6.2: {} + typescript@5.6.3: {} ufo@1.5.4: {} + undici-types@6.19.8: {} + universalify@0.1.2: {} - update-browserslist-db@1.1.1(browserslist@4.24.0): + update-browserslist-db@1.1.1(browserslist@4.24.2): dependencies: - browserslist: 4.24.0 + browserslist: 4.24.2 escalade: 3.2.0 - picocolors: 1.1.0 + picocolors: 1.1.1 uri-js@4.4.1: dependencies: punycode: 2.3.1 - veloxi@0.15.3: {} - - vite-plugin-dts@4.2.3(rollup@4.24.0)(typescript@5.6.2)(vite@5.4.8): + vite-plugin-dts@4.3.0(@types/node@22.9.0)(rollup@4.24.4)(typescript@5.6.3)(vite@5.4.10(@types/node@22.9.0)): dependencies: - '@microsoft/api-extractor': 7.47.7 - '@rollup/pluginutils': 5.1.2(rollup@4.24.0) - '@volar/typescript': 2.4.6 - '@vue/language-core': 2.1.6(typescript@5.6.2) + '@microsoft/api-extractor': 7.47.11(@types/node@22.9.0) + '@rollup/pluginutils': 5.1.3(rollup@4.24.4) + '@volar/typescript': 2.4.8 + '@vue/language-core': 2.1.6(typescript@5.6.3) compare-versions: 6.1.1 debug: 4.3.7 kolorist: 1.8.0 local-pkg: 0.5.0 - magic-string: 0.30.11 - typescript: 5.6.2 + magic-string: 0.30.12 + typescript: 5.6.3 optionalDependencies: - vite: 5.4.8 + vite: 5.4.10(@types/node@22.9.0) transitivePeerDependencies: - '@types/node' - rollup - supports-color - vite@5.4.8: + vite@5.4.10(@types/node@22.9.0): dependencies: esbuild: 0.21.5 postcss: 8.4.47 - rollup: 4.24.0 + rollup: 4.24.4 optionalDependencies: + '@types/node': 22.9.0 fsevents: 2.3.3 - vitefu@0.2.5(vite@5.4.8): + vitefu@1.0.3(vite@5.4.10(@types/node@22.9.0)): optionalDependencies: - vite: 5.4.8 + vite: 5.4.10(@types/node@22.9.0) vscode-uri@3.0.8: {} - vue-tsc@2.1.6(typescript@5.6.2): - dependencies: - '@volar/typescript': 2.4.6 - '@vue/language-core': 2.1.6(typescript@5.6.2) - semver: 7.6.3 - typescript: 5.6.2 - - vue@3.5.11(typescript@5.6.2): + vue@3.5.13(typescript@5.6.3): dependencies: - '@vue/compiler-dom': 3.5.11 - '@vue/compiler-sfc': 3.5.11 - '@vue/runtime-dom': 3.5.11 - '@vue/server-renderer': 3.5.11(vue@3.5.11(typescript@5.6.2)) - '@vue/shared': 3.5.11 + '@vue/compiler-dom': 3.5.13 + '@vue/compiler-sfc': 3.5.13 + '@vue/runtime-dom': 3.5.13 + '@vue/server-renderer': 3.5.13(vue@3.5.13(typescript@5.6.3)) + '@vue/shared': 3.5.13 optionalDependencies: - typescript: 5.6.2 + typescript: 5.6.3 yallist@3.1.1: {} yallist@4.0.0: {} + + zimmerframe@1.1.2: {} diff --git a/src/ScrollContainer.ts b/src/ScrollContainer.ts deleted file mode 100644 index 0860dc2..0000000 --- a/src/ScrollContainer.ts +++ /dev/null @@ -1,89 +0,0 @@ -export interface ScrollContainer { - container: Element | Window - width: number - height: number - - startScrollTracking: () => void - endScrollTracking: () => void - getScrollOffset: () => { x: number; y: number } - onScroll: (cb: () => void) => void -} - -export function getScrollContainer(el: Element): ScrollContainer { - let scrollParent = getScrollParent(el) || window - if (scrollParent === document.body) { - scrollParent = window - } - let scrollStartY = 0 - let scrollStartX = 0 - let startedTracking = false - let scrollCallback: () => void = () => {} - - scrollParent.addEventListener('scroll', () => { - if (startedTracking) { - scrollCallback() - } - }) - - return { - container: scrollParent, - onScroll(cb) { - scrollCallback = cb - }, - startScrollTracking() { - if (startedTracking) { - return - } - scrollStartY = - scrollParent instanceof Element - ? scrollParent.scrollTop - : scrollParent.scrollY - scrollStartX = - scrollParent instanceof Element - ? scrollParent.scrollLeft - : scrollParent.scrollX - startedTracking = true - }, - getScrollOffset(): { x: number; y: number } { - const scrollCurrentY = - scrollParent instanceof Element - ? scrollParent.scrollTop - : scrollParent.scrollY - const scrollCurrentX = - scrollParent instanceof Element - ? scrollParent.scrollLeft - : scrollParent.scrollX - return { - x: scrollCurrentX - scrollStartX, - y: scrollCurrentY - scrollStartY - } - }, - endScrollTracking() { - scrollStartY = 0 - scrollStartX = 0 - startedTracking = false - }, - width: - scrollParent instanceof Element - ? scrollParent.clientWidth - : scrollParent.innerWidth, - height: - scrollParent instanceof Element - ? scrollParent.clientHeight - : scrollParent.innerHeight - } -} - -function getScrollParent(node: Element): Element | null { - const isElement = node instanceof HTMLElement - const overflowY = isElement && window.getComputedStyle(node).overflowY - const isScrollable = overflowY !== 'visible' && overflowY !== 'hidden' - - if (!node) { - return null - } else if (isScrollable && node.scrollHeight >= node.clientHeight) { - return node - } - - return getScrollParent(node.parentNode as Element) || document.body -} diff --git a/src/animators.ts b/src/animators.ts new file mode 100644 index 0000000..a981ace --- /dev/null +++ b/src/animators.ts @@ -0,0 +1,74 @@ +import { BorderRadius, isBorderRadius } from './borderRadius' +import { clamp, lerp, lerpBorderRadius, lerpVectors } from './math' +import { isVec2, Vec2 } from './vector' + +export type AnimateConfig = { + duration: number + easing: (t: number) => number +} + +export type CancelFunction = () => void + +const DEFAULT_CONFIG: AnimateConfig = { + duration: 350, + easing: (t) => t +} + +type AnimateProps = Record + +export function animate

( + from: P, + to: { [K in keyof P]: P[K] }, + cb: (value: P, done: boolean, progress: number) => void, + config?: Partial +): CancelFunction { + let canceled = false + const cancel = () => { + canceled = true + } + const mergedConfig = { ...DEFAULT_CONFIG, ...config } + let start: number + function update(ts: number) { + if (start === undefined) { + start = ts + } + const elapsed = ts - start + const t = clamp(elapsed / mergedConfig.duration, 0, 1) + const names = Object.keys(from) as Array + const toKeys = Object.keys(to) as Array + if (!names.every((name) => toKeys.includes(name))) { + console.error('animate Error: `from` keys are different than `to`') + return + } + + const result = {} as P + + names.forEach((name) => { + if (typeof from[name] === 'number' && typeof to[name] === 'number') { + result[name] = lerp( + from[name], + to[name], + mergedConfig.easing(t) + ) as P[keyof P] + } else if (isBorderRadius(from[name]) && isBorderRadius(to[name])) { + result[name] = lerpBorderRadius( + from[name], + to[name], + mergedConfig.easing(t) + ) as P[keyof P] + } else if (isVec2(from[name]) && isVec2(to[name])) { + result[name] = lerpVectors( + from[name], + to[name], + mergedConfig.easing(t) + ) as P[keyof P] + } + }) + cb(result, t >= 1, t) + if (t < 1 && !canceled) { + requestAnimationFrame(update) + } + } + requestAnimationFrame(update) + return cancel +} diff --git a/src/borderRadius.ts b/src/borderRadius.ts new file mode 100644 index 0000000..516ff8a --- /dev/null +++ b/src/borderRadius.ts @@ -0,0 +1,123 @@ +export type BorderRadius = { + x: { + topLeft: number + topRight: number + bottomRight: number + bottomLeft: number + } + y: { + topLeft: number + topRight: number + bottomRight: number + bottomLeft: number + } + unit: string +} + +export function isBorderRadius( + borderRadius: any +): borderRadius is BorderRadius { + return ( + typeof borderRadius === 'object' && + borderRadius !== null && + 'x' in borderRadius && + 'y' in borderRadius && + 'unit' in borderRadius && + typeof borderRadius.unit === 'string' && + typeof borderRadius.x === 'object' && + typeof borderRadius.y === 'object' && + 'topLeft' in borderRadius.x && + 'topRight' in borderRadius.x && + 'bottomRight' in borderRadius.x && + 'bottomLeft' in borderRadius.x && + 'topLeft' in borderRadius.y && + 'topRight' in borderRadius.y && + 'bottomRight' in borderRadius.y && + 'bottomLeft' in borderRadius.y + ) +} + +export function parseBorderRadius(borderRadius: string): BorderRadius { + // Regular expression to match numbers with units (e.g., 6px, 10%) + const match = borderRadius.match(/(\d+(?:\.\d+)?)(px|%)/g) + + if (!match) { + return { + x: { topLeft: 0, topRight: 0, bottomRight: 0, bottomLeft: 0 }, + y: { topLeft: 0, topRight: 0, bottomRight: 0, bottomLeft: 0 }, + unit: 'px' + } + } + + // Parse each matched value with its unit + const values = match.map((value) => { + const [_, num, unit] = value.match(/(\d+(?:\.\d+)?)(px|%)/) ?? [] + return { value: parseFloat(num), unit } + }) + + // Ensure all units are consistent + const unit = values[0]?.unit || 'px' + if (values.some((v) => v.unit !== unit)) { + throw new Error('Inconsistent units in border-radius string.') + } + + // Handle 1 to 4 values + const [v1, v2, v3, v4] = values.map((v) => v.value) + const result = { + topLeft: v1 ?? 0, + topRight: v2 ?? v1 ?? 0, + bottomRight: v3 ?? v1 ?? 0, + bottomLeft: v4 ?? v2 ?? v1 ?? 0 + } + return { + x: { ...result }, + y: { ...result }, + unit + } +} + +export function calculateBorderRadiusInverse( + { x, y, unit }: BorderRadius, + scaleX: number, + scaleY: number +): BorderRadius { + if (unit === 'px') { + const RadiusXInverse = { + topLeft: x.topLeft / scaleX, + topRight: x.topRight / scaleX, + bottomLeft: x.bottomLeft / scaleX, + bottomRight: x.bottomRight / scaleX + } + const RadiusYInverse = { + topLeft: y.topLeft / scaleY, + topRight: y.topRight / scaleY, + bottomLeft: y.bottomLeft / scaleY, + bottomRight: y.bottomRight / scaleY + } + return { x: RadiusXInverse, y: RadiusYInverse, unit: 'px' } + } else if (unit === '%') { + return { x, y, unit: '%' } + } + return { x, y, unit } +} + +export function borderRadiusToString(borderRadius: BorderRadius): string { + return ` + ${borderRadius.x.topLeft}${borderRadius.unit} ${borderRadius.x.topRight}${borderRadius.unit} ${borderRadius.x.bottomRight}${borderRadius.unit} ${borderRadius.x.bottomLeft}${borderRadius.unit} + / + ${borderRadius.y.topLeft}${borderRadius.unit} ${borderRadius.y.topRight}${borderRadius.unit} ${borderRadius.y.bottomRight}${borderRadius.unit} ${borderRadius.y.bottomLeft}${borderRadius.unit} + ` +} + +export function isBorderRadiusNone(borderRadius: BorderRadius) { + return ( + borderRadius.x.topLeft === 0 && + borderRadius.x.topRight === 0 && + borderRadius.x.bottomRight === 0 && + borderRadius.x.bottomLeft === 0 && + borderRadius.y.topLeft === 0 && + borderRadius.y.topRight === 0 && + borderRadius.y.bottomRight === 0 && + borderRadius.y.bottomLeft === 0 + ) +} diff --git a/src/draggable.ts b/src/draggable.ts new file mode 100644 index 0000000..d5c32e8 --- /dev/null +++ b/src/draggable.ts @@ -0,0 +1,212 @@ +import { View, ViewPlugin } from './view' + +interface Draggable { + onDrag(handler: OnDragListener): void + onDrop(handler: OnDropListener): void + onHold(handler: OnHoldListener): void + onRelease(handler: OnReleaseListener): void + destroy(): void + readjust(): void +} + +export type DraggablePlugin = Draggable & ViewPlugin + +export type DragEvent = { + x: number + y: number + width: number + height: number + pointerX: number + pointerY: number + relativeX: number + relativeY: number + el: HTMLElement +} + +export type OnDragListener = (dragEvent: DragEvent) => void +export type OnDropListener = (dragEvent: DragEvent) => void +export type OnHoldListener = ({ el }: { el: HTMLElement }) => void +export type OnReleaseListener = ({ el }: { el: HTMLElement }) => void + +export type DraggableConfig = { + startDelay: number +} + +const DEFAULT_CONFIG: DraggableConfig = { + startDelay: 0 +} + +export function makeDraggable( + view: View, + userConfig?: Partial +): DraggablePlugin { + const config: DraggableConfig = { ...DEFAULT_CONFIG, ...userConfig } + + let el = view.el() + let isPointerDown = false + let dragListener: OnDragListener | null = null + let dropListener: OnDropListener | null = null + let holdListener: OnHoldListener | null = null + let releaseListener: OnReleaseListener | null = null + let initialX = 0 + let initialY = 0 + let lastX = 0 + let lastY = 0 + let layoutLeft = 0 + let layoutTop = 0 + let initialClientX = 0 + let initialClientY = 0 + let relativeX = 0 + let relativeY = 0 + let draggingEl: HTMLElement | null = null + let timer: NodeJS.Timeout | null + + el.addEventListener('pointerdown', onPointerDown) + document.body.addEventListener('pointerup', onPointerUp) + document.body.addEventListener('pointermove', onPointerMove) + document.body.addEventListener('touchmove', onTouchMove, { passive: false }) + + function onPointerDown(e: PointerEvent) { + if (isPointerDown) return + if (!e.isPrimary) return + if (config.startDelay > 0) { + holdListener?.({ el: e.target as HTMLElement }) + timer = setTimeout(() => { + start() + }, config.startDelay) + } else { + start() + } + + function start() { + draggingEl = e.target as HTMLElement + e.preventDefault() + const rect = view.boundingRect() + const layout = view.layoutRect() + layoutLeft = layout.x + layoutTop = layout.y + lastX = rect.x - layoutLeft + lastY = rect.y - layoutTop + initialX = e.clientX - lastX + initialY = e.clientY - lastY + initialClientX = e.clientX + initialClientY = e.clientY + relativeX = (e.clientX - rect.x) / rect.width + relativeY = (e.clientY - rect.y) / rect.height + isPointerDown = true + onPointerMove(e) + } + } + + function readjust() { + const layout = view.layoutRect() + initialX -= layoutLeft - layout.x + initialY -= layoutTop - layout.y + layoutLeft = layout.x + layoutTop = layout.y + } + + function onPointerUp(e: PointerEvent) { + if (!isPointerDown) { + if (timer) { + clearTimeout(timer) + timer = null + releaseListener?.({ el: e.target as HTMLElement }) + } + return + } + if (!e.isPrimary) return + isPointerDown = false + const width = e.clientX - initialClientX + const height = e.clientY - initialClientY + dropListener?.({ + x: lastX, + y: lastY, + pointerX: e.clientX, + pointerY: e.clientY, + width, + height, + relativeX, + relativeY, + el: draggingEl! + }) + draggingEl = null + } + + function onPointerMove(e: PointerEvent) { + if (!isPointerDown) { + if (timer) { + clearTimeout(timer) + timer = null + releaseListener?.({ el: e.target as HTMLElement }) + } + return + } + if (!e.isPrimary) return + + e.preventDefault() + const width = e.clientX - initialClientX + const height = e.clientY - initialClientY + const dx = (lastX = e.clientX - initialX) + const dy = (lastY = e.clientY - initialY) + dragListener?.({ + width, + height, + x: dx, + y: dy, + pointerX: e.clientX, + pointerY: e.clientY, + relativeX, + relativeY, + el: draggingEl! + }) + } + + function onTouchMove(e: TouchEvent) { + if (!isPointerDown) return true + e.preventDefault() + } + + function onDrag(listener: OnDragListener) { + dragListener = listener + } + + function onDrop(listener: OnDropListener) { + dropListener = listener + } + + function onHold(listener: OnHoldListener) { + holdListener = listener + } + + function onRelease(listener: OnReleaseListener) { + releaseListener = listener + } + + function onElementUpdate() { + el.removeEventListener('pointerdown', onPointerDown) + el = view.el() + el.addEventListener('pointerdown', onPointerDown) + } + + function destroy() { + view.el().removeEventListener('pointerdown', onPointerDown) + document.body.removeEventListener('pointerup', onPointerUp) + document.body.removeEventListener('pointermove', onPointerMove) + document.body.removeEventListener('touchmove', onTouchMove) + dragListener = null + dropListener = null + holdListener = null + releaseListener = null + } + + return { + onDrag, + onDrop, + onHold, + onRelease, + onElementUpdate, + destroy, + readjust + } +} diff --git a/src/easings.ts b/src/easings.ts new file mode 100644 index 0000000..a2ca7f2 --- /dev/null +++ b/src/easings.ts @@ -0,0 +1,10 @@ +export function easeOutBack(x: number): number { + const c1 = 1.70158 + const c3 = c1 + 1 + + return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2) +} + +export function easeOutCubic(x: number): number { + return 1 - Math.pow(1 - x, 3) +} diff --git a/src/flip.ts b/src/flip.ts new file mode 100644 index 0000000..1136213 --- /dev/null +++ b/src/flip.ts @@ -0,0 +1,275 @@ +import { + BorderRadius, + borderRadiusToString, + calculateBorderRadiusInverse, + parseBorderRadius +} from './borderRadius' +import { + createRectFromBoundingRect, + getLayoutRect, + getScrollOffset, + Rect +} from './rect' +import { vec2, Vec2 } from './vector' +import { Transform, View } from './view' + +type TransitionValue = { + width: number + height: number + translate: Vec2 + scale: Vec2 + borderRadius: BorderRadius +} + +type FlipTransitionValues = { from: TransitionValue; to: TransitionValue } + +type FlipChildTransitionData = { + el: HTMLElement + fromTranslate: Vec2 + fromScale: Vec2 + fromBorderRadius: BorderRadius + toBorderRadius: BorderRadius + parentScale: Vec2 +} + +type ElementFlipRect = { el: HTMLElement; initialRect: Rect; finalRect?: Rect } + +type ParentChildrenTreeData = Array<{ + parent: ElementFlipRect + children: Array +}> + +type ChildElement = HTMLElement & { originalBorderRadius: string } + +export interface Flip { + readInitial(): void + readFinalAndReverse(): void + transitionValues(): FlipTransitionValues + childrenTransitionData(): Array +} + +export function flipView(view: View): Flip { + let state: 'unread' | 'readInitial' | 'readFinal' = 'unread' + + let current: Transform + let parentInitialRect: Rect + let scrollOffset: Vec2 + + let parentDx: number + let parentDy: number + let parentDw: number + let parentDh: number + let parentInverseBorderRadius: BorderRadius + let parentFinalRect: Rect + + let childrenData: Array + + let parentChildrenTreeData: ParentChildrenTreeData + + function readInitial() { + current = view.currentTransform() + parentInitialRect = view.boundingRect() + scrollOffset = getScrollOffset(view.el()) + + const tree = getParentChildTree(view.el()) + parentChildrenTreeData = tree.map(({ parent, children }) => ({ + parent: { + el: parent, + initialRect: createRectFromBoundingRect(parent.getBoundingClientRect()) + }, + children: children.map((child) => { + const childEl = child as ChildElement + if (!childEl.originalBorderRadius) { + childEl.originalBorderRadius = getComputedStyle(child).borderRadius + } + return { + el: child, + borderRadius: parseBorderRadius(childEl.originalBorderRadius), + initialRect: createRectFromBoundingRect(child.getBoundingClientRect()) + } + }) + })) + + state = 'readInitial' + } + + function readFinalAndReverse() { + if (state !== 'readInitial') { + throw new Error( + 'FlipView: Cannot read final values before reading initial values' + ) + } + parentFinalRect = view.layoutRect() + parentDw = parentInitialRect.width / parentFinalRect.width + parentDh = parentInitialRect.height / parentFinalRect.height + parentDx = + parentInitialRect.x - parentFinalRect.x - current.dragX + scrollOffset.x + parentDy = + parentInitialRect.y - parentFinalRect.y - current.dragY + scrollOffset.y + + parentInverseBorderRadius = calculateBorderRadiusInverse( + view.borderRadius(), + parentDw, + parentDh + ) + + const tree = getParentChildTree(view.el()) + + parentChildrenTreeData = parentChildrenTreeData.map( + ({ parent, children }, i) => { + const parentEl = tree[i].parent + return { + parent: { + ...parent, + el: parentEl, + finalRect: getLayoutRect(parentEl) + }, + children: children.map((child, j) => { + const childEl = tree[i].children[j] + let finalRect = getLayoutRect(childEl) + if (childEl.hasAttribute('data-swapy-text')) { + finalRect = { + ...finalRect, + width: child.initialRect.width, + height: child.initialRect.height + } + } + return { + ...child, + el: childEl, + finalRect + } + }) + } + } + ) + + const targetTransform: Omit = { + translateX: parentDx, + translateY: parentDy, + scaleX: parentDw, + scaleY: parentDh + } + + view.el().style.transformOrigin = '0 0' + view.el().style.borderRadius = borderRadiusToString( + parentInverseBorderRadius + ) + view.setTransform(targetTransform) + + childrenData = [] + parentChildrenTreeData.forEach(({ parent, children }) => { + const childData = children.map( + ({ el, initialRect, finalRect, borderRadius }) => + calculateChildData( + el, + initialRect, + finalRect!, + borderRadius, + parent.initialRect, + parent.finalRect! + ) + ) + childrenData.push(...childData) + }) + + state = 'readFinal' + } + + function transitionValues(): FlipTransitionValues { + if (state !== 'readFinal') { + throw new Error('FlipView: Cannot get transition values before reading') + } + return { + from: { + width: parentInitialRect.width, + height: parentInitialRect.height, + translate: vec2(parentDx, parentDy), + scale: vec2(parentDw, parentDh), + borderRadius: parentInverseBorderRadius + }, + to: { + width: parentFinalRect.width, + height: parentFinalRect.height, + translate: vec2(0, 0), + scale: vec2(1, 1), + borderRadius: view.borderRadius() + } + } + } + + function childrenTransitionData(): Array { + if (state !== 'readFinal') { + throw new Error( + 'FlipView: Cannot get children transition values before reading' + ) + } + return childrenData + } + + return { + readInitial, + readFinalAndReverse, + transitionValues, + childrenTransitionData + } +} + +function calculateChildData( + childEl: HTMLElement, + childInitialRect: Rect, + childFinalRect: Rect, + childBorderRadius: BorderRadius, + parentInitialRect: Rect, + parentFinalRect: Rect +): FlipChildTransitionData { + childEl.style.transformOrigin = '0 0' + const parentDw = parentInitialRect.width / parentFinalRect.width + const parentDh = parentInitialRect.height / parentFinalRect.height + const dw = childInitialRect.width / childFinalRect.width + const dh = childInitialRect.height / childFinalRect.height + const fromBorderRadius = calculateBorderRadiusInverse( + childBorderRadius, + dw, + dh + ) + const initialX = childInitialRect.x - parentInitialRect.x + const finalX = childFinalRect.x - parentFinalRect.x + const initialY = childInitialRect.y - parentInitialRect.y + const finalY = childFinalRect.y - parentFinalRect.y + const fromTranslateX = (initialX - finalX * parentDw) / parentDw + const fromTranslateY = (initialY - finalY * parentDh) / parentDh + childEl.style.transform = `translate(${fromTranslateX}px, ${fromTranslateY}px) scale(${ + dw / parentDw + }, ${dh / parentDh})` + childEl.style.borderRadius = borderRadiusToString(fromBorderRadius) + + return { + el: childEl, + fromTranslate: vec2(fromTranslateX, fromTranslateY), + fromScale: vec2(dw, dh), + fromBorderRadius, + toBorderRadius: childBorderRadius, + parentScale: { x: parentDw, y: parentDh } + } +} + +function getParentChildTree( + element: HTMLElement +): { parent: HTMLElement; children: HTMLElement[] }[] { + const result: { parent: HTMLElement; children: HTMLElement[] }[] = [] + + function traverse(parent: HTMLElement) { + const children = Array.from(parent.children) as HTMLElement[] + if (children.length > 0) { + result.push({ + parent: parent, + children: children + }) + children.forEach((child) => traverse(child)) + } + } + + traverse(element) + return result +} diff --git a/src/index.ts b/src/index.ts index bc63e81..71836b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,1428 @@ -export { createSwapy, type Swapy, type SlotItemMap } from './instance' -export { - type SwapEventObject, - type SwapEventArray, - type SwapEventMap -} from './veloxi-plugin/SwapyPlugin' +import { animate, AnimateConfig, CancelFunction } from './animators' +import { borderRadiusToString, isBorderRadiusNone } from './borderRadius' +import { + DragEvent, + DraggableConfig, + DraggablePlugin, + makeDraggable, + OnDragListener, + OnDropListener, + OnHoldListener, + OnReleaseListener +} from './draggable' +import { easeOutBack, easeOutCubic } from './easings' +import { Flip, flipView } from './flip' +import { clamp, lerp, lerpBorderRadius, remap } from './math' +import { + createRectFromBoundingRect, + pointIntersectsWithRect, + Rect +} from './rect' +import { Vec2, vec2 } from './vector' +import { createView, View } from './view' + +export * as utils from './utils' + +export interface Swapy { + enable(enabled: boolean): void + onSwapStart(handler: SwapStartEventHandler): void + onSwap(handler: SwapEventHandler): void + onSwapEnd(handler: SwapEndEventHandler): void + onBeforeSwap(handler: BeforeSwapHandler): void + slotItemMap(): SlotItemMap + update(): void + destroy(): void +} + +export type SwapStartEvent = { + slotItemMap: SlotItemMap + draggingItem: string + fromSlot: string +} +export type SwapStartEventHandler = (event: SwapStartEvent) => void + +export type SwapEvent = { + oldSlotItemMap: SlotItemMap + newSlotItemMap: SlotItemMap + fromSlot: string + toSlot: string + draggingItem: string + swappedWithItem: string +} +export type SwapEventHandler = (event: SwapEvent) => void + +export type SwapEndEvent = { + slotItemMap: SlotItemMap + hasChanged: boolean +} +export type SwapEndEventHandler = (event: SwapEndEvent) => void + +export type BeforeSwapEvent = { + fromSlot: string + toSlot: string + draggingItem: string + swapWithItem: string +} +export type BeforeSwapHandler = (event: BeforeSwapEvent) => boolean + +interface Slot { + id(): string + item(): Item | undefined + view(): View + itemId(): string | null + rect(): Rect + highlight(): void + unhighlightAllSlots(): void + isHighlighted(): boolean + destroy(): void +} + +interface Item { + id(): string + slot(): Slot + view(): View + slotId(): string + store(): Store + onDrag(handler: OnDragListener): void + onDrop(handler: OnDropListener): void + onHold(handler: OnHoldListener): void + onRelease(handler: OnReleaseListener): void + isDragging(): boolean + destroy(): void + cancelAnimation(): ItemCancelAnimation + dragEvent(): DragEvent | null + continuousDrag(): boolean + setContinuousDrag(value: boolean): void +} + +type ItemCancelAnimation = Record< + 'drop' | 'moveToSlot', + CancelFunction | undefined +> + +type ScrollHandler = (e: Event) => void + +interface Store { + items(): Array + slots(): Array + setItems(items: Array): void + setSlots(slots: Array): void + itemById(id: string): Item | undefined + slotById(id: string): Slot | undefined + config(): Config + zIndex(inc?: boolean): number + resetZIndex(): void + eventHandlers(): { + onSwapStart: SwapStartEventHandler + onSwap: SwapEventHandler + onSwapEnd: SwapEndEventHandler + onBeforeSwap: BeforeSwapHandler + } + syncSlotItemMap(): void + slotItemMap(): SlotItemMap + onScroll(handler: ScrollHandler | null): void + swapItems(item: Item, toSlot: Slot): void + destroy(): void +} + +export type AnimationType = 'dynamic' | 'spring' | 'none' + +export type SlotItemMapObject = Record +export type SlotItemMapMap = Map +export type SlotItemMapArray = Array<{ slot: string; item: string }> + +export type SlotItemMap = { + asObject: SlotItemMapObject + asMap: SlotItemMapMap + asArray: SlotItemMapArray +} + +type DragAxis = 'x' | 'y' | 'both' + +export type Config = { + animation: AnimationType + enabled: boolean + swapMode: 'hover' | 'drop' + dragOnHold: boolean + autoScrollOnDrag: boolean + dragAxis: DragAxis + manualSwap: boolean +} + +const DEFAULT_CONFIG: Config = { + animation: 'dynamic', + enabled: true, + swapMode: 'hover', + dragOnHold: false, + autoScrollOnDrag: false, + dragAxis: 'both', + manualSwap: false +} + +function getAnimateConfig(animationType: AnimationType): AnimateConfig { + switch (animationType) { + case 'dynamic': + return { easing: easeOutCubic, duration: 300 } + case 'spring': + return { easing: easeOutBack, duration: 350 } + case 'none': + return { easing: (t: number) => t, duration: 1 } + } +} + +export function createSwapy( + container: HTMLElement, + config?: Partial +): Swapy { + const userConfig = { ...DEFAULT_CONFIG, ...config } + const store = createStore({ slots: [], items: [], config: userConfig }) + let slots: Array = [] + let items: Array = [] + + init() + + function init() { + if (!isContainerValid(container)) { + throw new Error( + 'Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!' + ) + } + + slots = Array.from(container.querySelectorAll('[data-swapy-slot]')).map( + (slotEl) => createSlot(slotEl as HTMLElement, store) + ) + store.setSlots(slots) + items = Array.from(container.querySelectorAll('[data-swapy-item]')).map( + (itemEl) => createItem(itemEl as HTMLElement, store) + ) + store.setItems(items) + + store.syncSlotItemMap() + + items.forEach((item) => { + item.onDrag(({ pointerX, pointerY }) => { + disableDefaultSelectAndDrag() + + let intersected = false + slots.forEach((slot) => { + const rect = slot.rect() + if (pointIntersectsWithRect({ x: pointerX, y: pointerY }, rect)) { + intersected = true + if (!slot.isHighlighted()) { + slot.highlight() + } + } + }) + if (!intersected && store.config().swapMode === 'drop') { + item.slot().highlight() + } + + if (userConfig.swapMode === 'hover') { + swapWithPointer(item, { pointerX, pointerY }) + } + }) + item.onDrop(({ pointerX, pointerY }) => { + enableDefaultSelectAndDrag() + if (userConfig.swapMode === 'drop') { + swapWithPointer(item, { pointerX, pointerY }) + } + }) + item.onHold(() => { + disableDefaultSelectAndDrag() + }) + item.onRelease(() => { + enableDefaultSelectAndDrag() + }) + }) + } + + function swapWithPointer( + item: Item, + { pointerX, pointerY }: Pick + ) { + slots.forEach((slot) => { + const rect = slot.rect() + if (pointIntersectsWithRect({ x: pointerX, y: pointerY }, rect)) { + if (item.id() === slot.itemId()) return + if (store.config().swapMode === 'hover') { + item.setContinuousDrag(true) + } + const fromSlot = item.slot() + const slotItem = slot.item() + + if ( + !store.eventHandlers().onBeforeSwap({ + fromSlot: fromSlot.id(), + toSlot: slot.id(), + draggingItem: item.id(), + swapWithItem: slotItem?.id() || '' + }) + ) { + return + } + + if (store.config().manualSwap) { + const oldSlotItemMap = structuredClone(store.slotItemMap()) + store.swapItems(item, slot) + const newSlotItemMap = store.slotItemMap() + const draggingFlip = flipView(item.view()) + draggingFlip.readInitial() + const swappedFlip: Flip | null = slotItem + ? flipView(slotItem.view()) + : null + swappedFlip?.readInitial() + + // ------------------------------------------------------------ + // Store current scroll position (before swap) + // ------------------------------------------------------------ + let scrollYBeforeSwap = 0 + let scrollXBeforeSwap = 0 + const scrollContainer = getClosestScrollableContainer( + item.view().el() + ) + if (scrollContainer instanceof Window) { + scrollYBeforeSwap = scrollContainer.scrollY + scrollXBeforeSwap = scrollContainer.scrollX + } else { + scrollYBeforeSwap = scrollContainer.scrollTop + scrollXBeforeSwap = scrollContainer.scrollLeft + } + + // ------------------------------------------------------------ + // Framework should swap elements in onSwap event + // ------------------------------------------------------------ + store.eventHandlers().onSwap({ + oldSlotItemMap, + newSlotItemMap, + fromSlot: fromSlot.id(), + toSlot: slot.id(), + draggingItem: item.id(), + swappedWithItem: slotItem?.id() || '' + }) + requestAnimationFrame(() => { + const itemEls = container.querySelectorAll('[data-swapy-item]') + store.items().forEach((item) => { + const itemEl = Array.from(itemEls).find( + (el) => (el as HTMLElement).dataset.swapyItem === item.id() + ) as HTMLElement + item.view().updateElement(itemEl) + }) + + store.syncSlotItemMap() + + draggingFlip.readFinalAndReverse() + swappedFlip?.readFinalAndReverse() + + animateFlippedItem(item, draggingFlip) + if (slotItem && swappedFlip) { + animateFlippedItem(slotItem, swappedFlip) + } + + // Restore scroll position before swap + scrollContainer.scrollTo({ + left: scrollXBeforeSwap, + top: scrollYBeforeSwap + }) + }) + } else { + let scrollYBeforeSwap = 0 + let scrollXBeforeSwap = 0 + const scrollContainer = getClosestScrollableContainer( + item.view().el() + ) + if (scrollContainer instanceof Window) { + scrollYBeforeSwap = scrollContainer.scrollY + scrollXBeforeSwap = scrollContainer.scrollX + } else { + scrollYBeforeSwap = scrollContainer.scrollTop + scrollXBeforeSwap = scrollContainer.scrollLeft + } + moveItemToSlot(item, slot, true) + if (slotItem) { + moveItemToSlot(slotItem, fromSlot) + } + scrollContainer.scrollTo({ + left: scrollXBeforeSwap, + top: scrollYBeforeSwap + }) + const oldSlotItemMap = store.slotItemMap() + store.syncSlotItemMap() + const newSlotItemMap = store.slotItemMap() + store.eventHandlers().onSwap({ + oldSlotItemMap, + newSlotItemMap, + fromSlot: fromSlot.id(), + toSlot: slot.id(), + draggingItem: item.id(), + swappedWithItem: slotItem?.id() || '' + }) + } + } + }) + } + + function disableDefaultSelectAndDrag() { + container.querySelectorAll('img').forEach((img) => { + img.style.pointerEvents = 'none' + }) + container.style.userSelect = 'none' + container.style.webkitUserSelect = 'none' + } + + function enableDefaultSelectAndDrag() { + container.querySelectorAll('img').forEach((img) => { + img.style.pointerEvents = '' + }) + container.style.userSelect = '' + container.style.webkitUserSelect = '' + } + + function enable(enabled: boolean) { + store.config().enabled = enabled + } + + function onSwapStart(handler: SwapStartEventHandler) { + store.eventHandlers().onSwapStart = handler + } + + function onSwap(handler: SwapEventHandler) { + store.eventHandlers().onSwap = handler + } + + function onSwapEnd(handler: SwapEndEventHandler) { + store.eventHandlers().onSwapEnd = handler + } + + function onBeforeSwap(handler: BeforeSwapHandler) { + store.eventHandlers().onBeforeSwap = handler + } + + function update(): void { + destroy() + requestAnimationFrame(() => { + init() + }) + } + + function destroy(): void { + items.forEach((item) => item.destroy()) + slots.forEach((slot) => slot.destroy()) + store.destroy() + items = [] + slots = [] + } + + return { + enable, + slotItemMap: () => store.slotItemMap(), + onSwapStart, + onSwap, + onSwapEnd, + onBeforeSwap, + update, + destroy + } +} + +function createStore({ + slots, + items, + config +}: { + slots: Array + items: Array + config: Config +}): Store { + const initialStore = { + slots, + items, + config, + slotItemMap: { asObject: {}, asMap: new Map(), asArray: [] } as SlotItemMap, + zIndexCount: 1, + eventHandlers: { + onSwapStart: () => {}, + onSwap: () => {}, + onSwapEnd: () => {}, + onBeforeSwap: () => true + }, + scrollOffsetWhileDragging: { x: 0, y: 0 } as Vec2, + scrollHandler: null as ScrollHandler | null + } + let store = { + ...initialStore + } + + const scrollHandler = (e: Event) => { + store.scrollHandler?.(e) + } + + window.addEventListener('scroll', scrollHandler) + + function slotById(id: string): Slot | undefined { + return store.slots.find((slot) => slot.id() === id) + } + + function itemById(id: string): Item | undefined { + return store.items.find((item) => item.id() === id) + } + + function syncSlotItemMap() { + const asObject: SlotItemMapObject = {} + const asMap: SlotItemMapMap = new Map() + const asArray: SlotItemMapArray = [] + + store.slots.forEach((slot) => { + const slotId = slot.id() + const itemId = slot.item()?.id() || '' + asObject[slotId] = itemId + asMap.set(slotId, itemId) + asArray.push({ slot: slotId, item: itemId }) + }) + + store.slotItemMap = { asObject, asMap, asArray } + } + + /** + * Only used for manualSwap + */ + function swapItems(item: Item, toSlot: Slot) { + const currentSlotItemMap = store.slotItemMap + const sourceItemId = item.id() + const targetItemId = toSlot.item()?.id() || '' + const toSlotId = toSlot.id() + const fromSlotId = item.slot().id() + + currentSlotItemMap.asObject[toSlotId] = sourceItemId + currentSlotItemMap.asObject[fromSlotId] = targetItemId + currentSlotItemMap.asMap.set(toSlotId, sourceItemId) + currentSlotItemMap.asMap.set(fromSlotId, targetItemId) + const toSlotIndex = currentSlotItemMap.asArray.findIndex( + (slotItem) => slotItem.slot === toSlotId + ) + const fromSlotIndex = currentSlotItemMap.asArray.findIndex( + (slotItem) => slotItem.slot === fromSlotId + ) + currentSlotItemMap.asArray[toSlotIndex].item = sourceItemId + currentSlotItemMap.asArray[fromSlotIndex].item = targetItemId + } + + function destroy() { + window.removeEventListener('scroll', scrollHandler) + store = { ...initialStore } + } + + return { + slots: () => store.slots, + items: () => store.items, + config: () => config, + setItems: (items) => (store.items = items), + setSlots: (slots) => (store.slots = slots), + slotById, + itemById, + zIndex: (inc = false) => { + if (inc) { + return ++store.zIndexCount + } + return store.zIndexCount + }, + resetZIndex: () => { + store.zIndexCount = 1 + }, + eventHandlers: () => store.eventHandlers, + syncSlotItemMap, + slotItemMap: () => store.slotItemMap, + onScroll: (handler: ScrollHandler | null) => { + store.scrollHandler = handler + }, + swapItems, + destroy + } +} + +function createSlot(slotEl: HTMLElement, store: Store): Slot { + const view = createView(slotEl) + + function id(): string { + return view.el().dataset.swapySlot! + } + + function itemId(): string | null { + const itemEl = view.el().children[0] as HTMLElement | null + return itemEl?.dataset.swapyItem || null + } + + function rect(): Rect { + return createRectFromBoundingRect(view.el().getBoundingClientRect()) + } + + function item(): Item | undefined { + const itemEl = view.el().children[0] as HTMLElement + if (itemEl) { + return store.itemById(itemEl.dataset.swapyItem!) + } + } + + function unhighlightAllSlots() { + store.slots().forEach((slot) => { + slot.view().el().removeAttribute('data-swapy-highlighted') + }) + } + + function highlight() { + unhighlightAllSlots() + view.el().setAttribute('data-swapy-highlighted', '') + } + + function destroy() {} + + return { + id, + view: () => view, + itemId, + rect, + item, + highlight, + unhighlightAllSlots, + isHighlighted: () => view.el().hasAttribute('data-swapy-highlighted'), + destroy + } +} + +function createItem(itemEl: HTMLElement, store: Store): Item { + const view = createView(itemEl) + const cancelAnimation: ItemCancelAnimation = {} as ItemCancelAnimation + let autoScroller: AutoScroller | null = null + let slotItemMapSessionStart: SlotItemMap | null = null + + // ------------------------------------------------------------ + // Variables for dragging + // ------------------------------------------------------------ + let dragging = false + let continuousDrag = true + let currentDragEvent: DragEvent | null + const dragSyncUpdate = createSyncUpdate() + let dragListener: OnDragListener | null = () => {} + let dropListener: OnDropListener | null = () => {} + let holdListener: OnHoldListener | null = () => {} + let releaseListener: OnReleaseListener | null = () => {} + const { onDrag, onDrop, onHold, onRelease } = view.usePlugin< + DraggablePlugin, + DraggableConfig + >(makeDraggable, { + startDelay: store.config().dragOnHold ? 400 : 0 + }) + + // ------------------------------------------------------------ + // Variables for handling scrolling while dragging + // ------------------------------------------------------------ + const lastScroll = vec2(0, 0) + const containerLastScroll = vec2(0, 0) + const scrollOffset = vec2(0, 0) + const containerScrollOffset = vec2(0, 0) + let scrollContainer: HTMLElement | Window | null = null + let scrollContainerHandler: ScrollHandler | null = null + + // ------------------------------------------------------------ + // Run only when dragOnHold is enabled. + // Executed the moment the user clicks on the element and holds + // without moving the pointer. + // ------------------------------------------------------------ + onHold((e) => { + if (!store.config().enabled) { + return + } + if (hasHandle() && !isHandleEl(e.el)) { + return + } + if (hasNoDrag() && isNoDrag(e.el)) { + return + } + holdListener?.(e) + }) + + // ------------------------------------------------------------ + // Run only when dragOnHold is enabled. + // Executed when the user releases the pointer (pointerUp) + // before the startDelay passes. + // + // Use case: the user has to click and hold for a few hundered + // milliseconds before the drag is activated, but the user + // releases the pointer before that, cancelling the drag. + // ------------------------------------------------------------ + onRelease((e) => { + if (!store.config().enabled) { + return + } + if (hasHandle() && !isHandleEl(e.el)) { + return + } + if (hasNoDrag() && isNoDrag(e.el)) { + return + } + releaseListener?.(e) + }) + + function onDragStart(dragEvent: DragEvent) { + markAsDragging() + slot().highlight() + cancelAnimation.drop?.() + + store.slots().forEach((slot) => { + const rect = slot.view().boundingRect() + slot.view().el().style.width = `${rect.width}px` + slot.view().el().style.flexShrink = '0' + slot.view().el().style.height = `${rect.height}px` + }) + + const slotItemMap = store.slotItemMap() + store.eventHandlers().onSwapStart({ + draggingItem: id(), + fromSlot: slotId(), + slotItemMap + }) + slotItemMapSessionStart = slotItemMap + view.el().style.position = 'relative' + view.el().style.zIndex = `${store.zIndex(true)}` + + scrollContainer = getClosestScrollableContainer(dragEvent.el) + + if (store.config().autoScrollOnDrag) { + autoScroller = createAutoScroller( + scrollContainer, + store.config().dragAxis + ) + autoScroller.updatePointer({ + x: dragEvent.pointerX, + y: dragEvent.pointerY + }) + } + + // ------------------------------------------------------------ + // Handling scrolling while dragging + // ------------------------------------------------------------ + lastScroll.x = window.scrollX + lastScroll.y = window.scrollY + scrollOffset.x = 0 + scrollOffset.y = 0 + + // When the scrollContainer is not the window + if (scrollContainer instanceof HTMLElement) { + containerLastScroll.x = scrollContainer.scrollLeft + containerLastScroll.y = scrollContainer.scrollTop + // Handler for scrolling the closest scroll container + scrollContainerHandler = () => { + containerScrollOffset.x = + (scrollContainer as HTMLElement).scrollLeft - containerLastScroll.x + containerScrollOffset.y = + (scrollContainer as HTMLElement).scrollTop - containerLastScroll.y + view.setTransform({ + dragX: + (currentDragEvent?.width || 0) + + scrollOffset.x + + containerScrollOffset.x, + dragY: + (currentDragEvent?.height || 0) + + scrollOffset.y + + containerScrollOffset.y + }) + } + scrollContainer.addEventListener('scroll', scrollContainerHandler) + } + + // When scrolling the window + store.onScroll(() => { + scrollOffset.x = window.scrollX - lastScroll.x + scrollOffset.y = window.scrollY - lastScroll.y + const containerOffsetX = containerScrollOffset.x || 0 + const containerOffsetY = containerScrollOffset.y || 0 + view.setTransform({ + dragX: + (currentDragEvent?.width || 0) + scrollOffset.x + containerOffsetX, + dragY: + (currentDragEvent?.height || 0) + scrollOffset.y + containerOffsetY + }) + }) + } + + onDrag((dragEvent) => { + if (!store.config().enabled) { + return + } + // On drag start + if (!dragging) { + if (hasHandle() && !isHandleEl(dragEvent.el)) { + return + } + if (hasNoDrag() && isNoDrag(dragEvent.el)) { + return + } + onDragStart(dragEvent) + } + dragging = true + if (autoScroller) { + autoScroller.updatePointer({ + x: dragEvent.pointerX, + y: dragEvent.pointerY + }) + } + currentDragEvent = dragEvent + cancelAnimation.drop?.() + dragSyncUpdate(() => { + view.el().style.position = 'relative' + const dragX = dragEvent.width + scrollOffset.x + containerScrollOffset.x + const dragY = dragEvent.height + scrollOffset.y + containerScrollOffset.y + if (store.config().dragAxis === 'y') { + view.setTransform({ + dragY + }) + } else if (store.config().dragAxis === 'x') { + view.setTransform({ + dragX + }) + } else { + view.setTransform({ + dragX, + dragY + }) + } + dragListener?.(dragEvent) + }) + }) + + onDrop((dragEvent) => { + if (!dragging) return + unmarkAsDragging() + dragging = false + continuousDrag = false + currentDragEvent = null + if (scrollContainer) { + scrollContainer.removeEventListener('scroll', scrollContainerHandler!) + scrollContainerHandler = null + } + scrollContainer = null + containerScrollOffset.x = 0 + containerScrollOffset.y = 0 + scrollOffset.x = 0 + scrollOffset.y = 0 + if (autoScroller) { + autoScroller.destroy() + autoScroller = null + } + slot().unhighlightAllSlots() + dropListener?.(dragEvent) + store.eventHandlers().onSwapEnd({ + slotItemMap: store.slotItemMap(), + hasChanged: slotItemMapSessionStart?.asMap + ? !areMapsEqual( + slotItemMapSessionStart?.asMap, + store.slotItemMap().asMap + ) + : false + }) + slotItemMapSessionStart = null + store.onScroll(null) + store.slots().forEach((slot) => { + slot.view().el().style.width = '' + slot.view().el().style.flexShrink = '' + slot.view().el().style.height = '' + }) + if (store.config().manualSwap && store.config().swapMode === 'drop') { + requestAnimationFrame(animateDrop) + } else { + animateDrop() + } + function animateDrop() { + const current = view.currentTransform() + const currentX = current.dragX + current.translateX + const currentY = current.dragY + current.translateY + cancelAnimation.drop = animate( + { translate: vec2(currentX, currentY) }, + { translate: vec2(0, 0) }, + ({ translate }, done) => { + if (done) { + if (!dragging) { + view.clearTransform() + view.el().style.transformOrigin = '' + } + } else { + view.setTransform({ + dragX: 0, + dragY: 0, + translateX: translate.x, + translateY: translate.y + }) + } + if (done) { + store.items().forEach((item) => { + if (!item.isDragging()) { + item.view().el().style.zIndex = '' + } + }) + store.resetZIndex() + view.el().style.position = '' + continuousDrag = true + } + }, + getAnimateConfig(store.config().animation) + ) + } + }) + + function onItemDrag(listener: OnDragListener) { + dragListener = listener + } + + function onItemDrop(listener: OnDropListener) { + dropListener = listener + } + + function onItemHold(listener: OnHoldListener) { + holdListener = listener + } + + function onItemRelease(listener: OnReleaseListener) { + releaseListener = listener + } + + function handle(): HTMLElement | null { + return view.el().querySelector('[data-swapy-handle]') + } + + function isHandleEl(el: HTMLElement): boolean { + const handleEl = handle() + if (!handleEl) { + return false + } + return handleEl === el || handleEl.contains(el) + } + + function hasHandle(): boolean { + return handle() !== null + } + + function noDragEls(): Array { + return Array.from(view.el().querySelectorAll('[data-swapy-no-drag]')) + } + + function isNoDrag(el: HTMLElement): boolean { + const noDragElements = noDragEls() + if (!noDragElements || noDragElements.length === 0) { + return false + } + return ( + noDragElements.includes(el) || + noDragElements.some((noDragEl) => noDragEl.contains(el)) + ) + } + + function hasNoDrag(): boolean { + return noDragEls().length > 0 + } + + function markAsDragging() { + view.el().setAttribute('data-swapy-dragging', '') + } + + function unmarkAsDragging() { + view.el().removeAttribute('data-swapy-dragging') + } + + function destroy() { + dragListener = null + dropListener = null + holdListener = null + releaseListener = null + currentDragEvent = null + slotItemMapSessionStart = null + if (autoScroller) { + autoScroller.destroy() + autoScroller = null + } + if (scrollContainer && scrollContainerHandler) { + scrollContainer.removeEventListener('scroll', scrollContainerHandler) + } + view.destroy() + } + + function id(): string { + return view.el().dataset.swapyItem! + } + + function slot(): Slot { + return store.slotById(view.el().parentElement!.dataset.swapySlot!)! + } + + function slotId(): string { + return view.el().parentElement!.dataset.swapySlot! + } + + return { + id, + view: () => view, + slot, + slotId, + onDrag: onItemDrag, + onDrop: onItemDrop, + onHold: onItemHold, + onRelease: onItemRelease, + destroy, + isDragging: () => dragging, + cancelAnimation: () => cancelAnimation, + dragEvent: () => currentDragEvent, + store: () => store, + continuousDrag: () => continuousDrag, + setContinuousDrag: (value: boolean) => (continuousDrag = value) + } +} + +function moveItemToSlot(item: Item, slot: Slot, from = false) { + if (from) { + const targetItem = slot.item() + if (targetItem) { + slot.view().el().style.position = 'relative' + targetItem.view().el().style.position = 'absolute' + } + } else { + const slotOfItem = item.slot() + slotOfItem.view().el().style.position = '' + item.view().el().style.position = '' + } + if (!item) { + return + } + + const flip = flipView(item.view()) + flip.readInitial() + slot.view().el().appendChild(item.view().el()) + flip.readFinalAndReverse() + animateFlippedItem(item, flip) +} + +function createSyncUpdate() { + let isUpdating = false + return (cb: () => void) => { + if (isUpdating) return + isUpdating = true + requestAnimationFrame(() => { + cb() + isUpdating = false + }) + } +} + +function animateFlippedItem(item: Item, flip: Flip) { + item.cancelAnimation().moveToSlot?.() + item.cancelAnimation().drop?.() + const animateConfig = getAnimateConfig(item.store().config().animation) + + const transitionValues = flip.transitionValues() + + let current = item.view().currentTransform() + let lastProgress = 0 + let draggedAfterDrop = false + item.cancelAnimation().moveToSlot = animate( + { + translate: transitionValues.from.translate, + scale: transitionValues.from.scale, + borderRadius: transitionValues.from.borderRadius + }, + { + translate: transitionValues.to.translate, + scale: transitionValues.to.scale, + borderRadius: transitionValues.to.borderRadius + }, + ({ translate, scale, borderRadius }, done, progress) => { + if (item.isDragging()) { + if (lastProgress !== 0) { + draggedAfterDrop = true + } + const relativeX = item.dragEvent()!.relativeX + const relativeY = item.dragEvent()!.relativeY + /** + * ContinuousDrag means the user didn't drop the item + * and dragged it again quickly before it reaches final position on drop. + * This might not be possible if the animation is very quick. + * We need this to avoid updating translateX and translateY for non-continuousDrag. + * We update them to adjust the item position based on cursor position when scaling, + * for example scaling from left if holding the item from the right edge + * (similar to transform-origin). + * If we update translateX and translateY for non-continuousDrag, we'll see some + * animation issues, like the item sliding while dragging again. Subtle, but important. + */ + if (item.continuousDrag()) { + item.view().setTransform({ + translateX: lerp( + current.translateX, + current.translateX + + (transitionValues.from.width - transitionValues.to.width) * + relativeX, + animateConfig.easing(progress - lastProgress) + ), + translateY: lerp( + current.translateY, + current.translateY + + (transitionValues.from.height - transitionValues.to.height) * + relativeY, + animateConfig.easing(progress - lastProgress) + ), + scaleX: scale.x, + scaleY: scale.y + }) + } else { + item.view().setTransform({ scaleX: scale.x, scaleY: scale.y }) + } + } else { + current = item.view().currentTransform() + lastProgress = progress + // If the user dragged the item while it was moving to new slot, + // we just need to animate the scale, because the translate animation + // will now be handled by the dropping animation when the user drop it. + if (draggedAfterDrop) { + item.view().setTransform({ + scaleX: scale.x, + scaleY: scale.y + }) + } else { + item.view().setTransform({ + dragX: 0, + dragY: 0, + translateX: translate.x, + translateY: translate.y, + scaleX: scale.x, + scaleY: scale.y + }) + } + } + const children = flip.childrenTransitionData() + children.forEach( + ({ + el, + fromTranslate, + fromScale, + fromBorderRadius, + toBorderRadius, + parentScale + }) => { + const parentScaleX = lerp( + parentScale.x, + 1, + animateConfig.easing(progress) + ) + const parentScaleY = lerp( + parentScale.y, + 1, + animateConfig.easing(progress) + ) + el.style.transform = `translate(${ + fromTranslate.x + + (0 - fromTranslate.x / parentScaleX) * + animateConfig.easing(progress) + }px, ${ + fromTranslate.y + + (0 - fromTranslate.y / parentScaleY) * + animateConfig.easing(progress) + }px) scale(${lerp( + fromScale.x / parentScaleX, + 1 / parentScaleX, + animateConfig.easing(progress) + )}, ${lerp( + fromScale.y / parentScaleY, + 1 / parentScaleY, + animateConfig.easing(progress) + )})` + + if (!isBorderRadiusNone(fromBorderRadius)) { + el.style.borderRadius = borderRadiusToString( + lerpBorderRadius( + fromBorderRadius, + toBorderRadius, + animateConfig.easing(progress) + ) + ) + } + } + ) + if (!isBorderRadiusNone(borderRadius)) { + item.view().el().style.borderRadius = borderRadiusToString(borderRadius) + } + if (done) { + if (!item.isDragging()) { + item.view().el().style.transformOrigin = '' + item.view().clearTransform() + } + item.view().el().style.borderRadius = '' + + children.forEach(({ el }) => { + el.style.transform = '' + el.style.transformOrigin = '' + el.style.borderRadius = '' + }) + } + }, + animateConfig + ) +} + +function logError(...args: unknown[]) { + console.error('Swapy Error:', ...args) +} + +function isContainerValid(container: Element) { + const containerEl = container as HTMLElement + let isValid = true + const slotEls = containerEl.querySelectorAll('[data-swapy-slot]') + + if (!containerEl) { + logError('container passed to createSwapy() is undefined or null') + isValid = false + } + + slotEls.forEach((_slotEl) => { + const slotEl = _slotEl as HTMLElement + const slotId = slotEl.dataset.swapySlot + const slotChildren = slotEl.children + const slotFirstChild = slotChildren[0] as HTMLElement + + if (!slotId || slotId.length === 0) { + logError(slotEl, 'does not contain a slotId using data-swapy-slot') + isValid = false + } + + if (slotChildren.length > 1) { + logError('slot:', `"${slotId}"`, 'cannot contain more than one element') + isValid = false + } + + if ( + slotFirstChild && + (!slotFirstChild.dataset.swapyItem || + slotFirstChild.dataset.swapyItem.length === 0) + ) { + logError( + 'slot', + `"${slotId}"`, + 'does not contain an element with an item id using data-swapy-item' + ) + isValid = false + } + }) + + const slotIds = Array.from(slotEls).map( + (slotEl) => (slotEl as HTMLElement).dataset.swapySlot + ) + + const itemEls = containerEl.querySelectorAll('[data-swapy-item]') + + const itemIds = Array.from(itemEls).map( + (itemEl) => (itemEl as HTMLElement).dataset.swapyItem + ) + + if (hasDuplicates(slotIds)) { + const duplicates = findDuplicates(slotIds) + logError( + 'your container has duplicate slot ids', + `(${duplicates.join(', ')})` + ) + isValid = false + } + + if (hasDuplicates(itemIds)) { + const duplicates = findDuplicates(itemIds) + logError( + 'your container has duplicate item ids', + `(${duplicates.join(', ')})` + ) + isValid = false + } + + return isValid +} + +function hasDuplicates(array: Array): boolean { + return new Set(array).size !== array.length +} + +function findDuplicates(array: T[]): T[] { + const seen = new Set() + const duplicates = new Set() + + for (const item of array) { + if (seen.has(item)) { + duplicates.add(item) + } else { + seen.add(item) + } + } + + return Array.from(duplicates) +} + +function areMapsEqual( + map1: Map, + map2: Map +): boolean { + if (map1.size !== map2.size) return false + for (const [key, value] of map1) { + if (map2.get(key) !== value) return false + } + return true +} + +export function getClosestScrollableContainer( + element: HTMLElement +): HTMLElement | Window { + let current: HTMLElement | null = element + + while (current) { + const computedStyle = window.getComputedStyle(current) + const overflowY = computedStyle.overflowY + const overflowX = computedStyle.overflowX + + if ( + ((overflowY === 'auto' || overflowY === 'scroll') && + current.scrollHeight > current.clientHeight) || + ((overflowX === 'auto' || overflowX === 'scroll') && + current.scrollWidth > current.clientWidth) + ) { + return current + } + + current = current.parentElement + } + + return window +} + +interface AutoScroller { + updatePointer(pointer: Vec2): void + destroy(): void +} + +function createAutoScroller( + container: HTMLElement | Window, + dragAxis: DragAxis +): AutoScroller { + const MAX_DISTANCE = 100 + const MAX_SPEED = 5 + let scrolling = false + let rect: Rect + let maxScrollY = 0 + let maxScrollX = 0 + let currentScrollY = 0 + let currentScrollX = 0 + let scrollTopBy = 0 + let scrollLeftBy = 0 + let raf: number | null = null + + if (container instanceof HTMLElement) { + rect = createRectFromBoundingRect(container.getBoundingClientRect()) + maxScrollY = container.scrollHeight - rect.height + maxScrollX = container.scrollWidth - rect.width + } else { + rect = { + x: 0, + y: 0, + width: window.innerWidth, + height: window.innerHeight + } + maxScrollY = document.documentElement.scrollHeight - window.innerHeight + maxScrollX = document.documentElement.scrollWidth - window.innerWidth + } + + function updateCurrentScroll() { + if (container instanceof HTMLElement) { + currentScrollY = container.scrollTop + currentScrollX = container.scrollLeft + } else { + currentScrollY = window.scrollY + currentScrollX = window.scrollX + } + } + + function updatePointer(pointer: Vec2) { + scrolling = false + const rectTop = rect.y + const rectBottom = rect.y + rect.height + const rectLeft = rect.x + const rectRight = rect.x + rect.width + + const closerToTop = + Math.abs(rectTop - pointer.y) < Math.abs(rectBottom - pointer.y) + const closerToLeft = + Math.abs(rectLeft - pointer.x) < Math.abs(rectRight - pointer.x) + + updateCurrentScroll() + + if (dragAxis !== 'x') { + if (closerToTop) { + const distanceToTop = rectTop - pointer.y + if (distanceToTop >= -MAX_DISTANCE) { + const v = clamp(distanceToTop, -MAX_DISTANCE, 0) + const scrollAmount = remap(-MAX_DISTANCE, 0, 0, MAX_SPEED, v) + scrollTopBy = -scrollAmount + scrolling = true + } + } else { + const distanceToBottom = rectBottom - pointer.y + if (distanceToBottom <= MAX_DISTANCE) { + const v = clamp(distanceToBottom, 0, MAX_DISTANCE) + const scrollAmount = remap(MAX_DISTANCE, 0, 0, MAX_SPEED, v) + scrollTopBy = scrollAmount + scrolling = true + } + } + } + + if (dragAxis !== 'y') { + if (closerToLeft) { + const distanceToLeft = rectLeft - pointer.x + if (distanceToLeft >= -MAX_DISTANCE) { + const v = clamp(distanceToLeft, -MAX_DISTANCE, 0) + const scrollAmount = remap(-MAX_DISTANCE, 0, 0, MAX_SPEED, v) + scrollLeftBy = -scrollAmount + scrolling = true + } + } else { + const distanceToRight = rectRight - pointer.x + if (distanceToRight <= MAX_DISTANCE) { + const v = clamp(distanceToRight, 0, MAX_DISTANCE) + const scrollAmount = remap(MAX_DISTANCE, 0, 0, MAX_SPEED, v) + scrollLeftBy = scrollAmount + scrolling = true + } + } + } + + if (scrolling) { + if (raf) { + cancelAnimationFrame(raf) + } + scroll() + } + } + + function scroll() { + updateCurrentScroll() + if (dragAxis !== 'x') { + scrollTopBy = currentScrollY + scrollTopBy >= maxScrollY ? 0 : scrollTopBy + } + if (dragAxis !== 'y') { + scrollLeftBy = + currentScrollX + scrollLeftBy >= maxScrollX ? 0 : scrollLeftBy + } + + container.scrollBy({ top: scrollTopBy, left: scrollLeftBy }) + if (scrolling) { + raf = requestAnimationFrame(scroll) + } + } + + function destroy() { + scrolling = false + } + + return { + updatePointer, + destroy + } +} diff --git a/src/instance.ts b/src/instance.ts deleted file mode 100644 index 26709c4..0000000 --- a/src/instance.ts +++ /dev/null @@ -1,386 +0,0 @@ -import { getUniqueId, mapsAreEqual } from './utils' -import { installPlugin } from './veloxi-plugin' -import { - InitEvent, - SwapData, - SwapEndEvent, - SwapEndEventData, - SwapEvent, - SwapEventArray, - SwapEventData, - SwapStartEvent, - SwapyPlugin, - SwapyPluginApi -} from './veloxi-plugin/SwapyPlugin' - -type SwapCallback = (event: SwapEventData) => void -type SwapEndCallback = (event: SwapEndEventData) => void -type SwapStartCallback = () => void - -export interface Swapy { - onSwap(callback: SwapCallback): void - onSwapEnd(callback: SwapEndCallback): void - onSwapStart(callback: SwapStartCallback): void - enable(enabled: boolean): void - destroy(): void - setData(swapData: SwapData): void -} - -export type SlotItemMap = SwapEventArray - -export type AnimationType = 'dynamic' | 'spring' | 'none' -export type SwapMode = 'hover' | 'stop' | 'drop' - -export type Config = { - animation: AnimationType - continuousMode: boolean - manualSwap: boolean - swapMode: SwapMode - autoScrollOnDrag: boolean -} - -const DEFAULT_CONFIG: Config = { - animation: 'dynamic', - continuousMode: true, - manualSwap: false, - swapMode: 'hover', - autoScrollOnDrag: false -} - -function validate(root: HTMLElement): boolean { - let isValid = true - const slotElements = root.querySelectorAll('[data-swapy-slot]') - if (slotElements.length === 0) { - console.error('There are no slots defined in your root element:', root) - isValid = false - } - slotElements.forEach((slot) => { - const slotEl = slot as HTMLElement - const slotId = slotEl.dataset.swapySlot - if (!slotId || slotId.length === 0) { - console.error(slot, 'does not contain a slotId using data-swapy-slot') - isValid = false - } - const slotChildren = slotEl.children - if (slotChildren.length > 1) { - console.error( - 'slot:', - `"${slotId}"`, - 'cannot contain more than one element' - ) - isValid = false - } - const slotChild = slotChildren[0] as HTMLElement - if ( - slotChild && - (!slotChild.dataset.swapyItem || slotChild.dataset.swapyItem.length === 0) - ) { - console.error( - 'slot:', - `"${slotId}"`, - 'does not contain an element with item id using data-swapy-item' - ) - isValid = false - } - }) - return isValid -} - -function addVeloxiDataAttributes( - root: HTMLElement, - config = {} as Config -): string { - const pluginKey = getUniqueId() - root.dataset.velPluginKey = pluginKey - root.dataset.velPlugin = 'Swapy' - root.dataset.velView = 'root' - root.dataset.velDataConfigAnimation = config.animation - root.dataset.velDataConfigSwapMode = config.swapMode - if (config.continuousMode) { - root.dataset.velDataConfigContinuousMode = 'true' - } - if (config.manualSwap) { - root.dataset.velDataConfigManualSwap = 'true' - } - const slots = Array.from( - root.querySelectorAll('[data-swapy-slot]') - ) as HTMLElement[] - slots.forEach((slot) => { - slot.dataset.velView = 'slot' - }) - - const items = Array.from( - root.querySelectorAll('[data-swapy-item]') - ) as HTMLElement[] - items.forEach((item) => { - item.dataset.velView = 'item' - item.dataset.velLayoutId = item.dataset.swapyItem - const handle = item.querySelector('[data-swapy-handle]') as HTMLElement - if (handle) { - handle.dataset.velView = 'handle' - } - }) - - const textElements = Array.from( - root.querySelectorAll('[data-swapy-text]') - ) as HTMLElement[] - textElements.forEach((el) => { - el.dataset.velLayoutPosition = '' - }) - - const excludedElements = Array.from( - root.querySelectorAll('[data-swapy-exclude]') - ) as HTMLElement[] - excludedElements.forEach((el) => { - el.dataset.velIgnore = '' - }) - - return pluginKey -} - -function resyncItems(root: HTMLElement): boolean { - const slots = Array.from( - root.querySelectorAll('[data-swapy-slot]:not([data-vel-view])') - ) as HTMLElement[] - slots.forEach((slot) => { - slot.dataset.velView = 'slot' - }) - const items = Array.from( - root.querySelectorAll('[data-swapy-item]:not([data-vel-view])') - ) as HTMLElement[] - items.forEach((item) => { - item.dataset.velView = 'item' - item.dataset.velLayoutId = item.dataset.swapyItem - const handle = item.querySelector('[data-swapy-handle]') as HTMLElement - if (handle) { - handle.dataset.velView = 'handle' - } - - const textElements = Array.from( - item.querySelectorAll('[data-swapy-text]') - ) as HTMLElement[] - textElements.forEach((el) => { - el.dataset.velLayoutPosition = '' - }) - - const excludedElements = Array.from( - item.querySelectorAll('[data-swapy-exclude]') - ) as HTMLElement[] - excludedElements.forEach((el) => { - el.dataset.velIgnore = '' - }) - }) - return items.length > 0 || slots.length > 0 -} - -function createSwapy( - root: Element | null, - userConfig: Partial = {} as Partial -): Swapy { - if (!root) { - throw new Error( - 'Cannot create a Swapy instance because the element you provided does not exist on the page!' - ) - } - const config = { ...DEFAULT_CONFIG, ...userConfig } - const rootEl = root as HTMLElement - if (!validate(rootEl)) { - throw new Error( - 'Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!' - ) - } - const pluginKey = addVeloxiDataAttributes(rootEl, config) - - const swapy = new SwapyInstance(rootEl, pluginKey, config) - return { - onSwap(callback) { - swapy.setSwapCallback(callback) - }, - onSwapEnd(callback) { - swapy.setSwapEndCallback(callback) - }, - onSwapStart(callback) { - swapy.setSwapStartCallback(callback) - }, - enable(enabled) { - swapy.setEnabled(enabled) - }, - destroy() { - swapy.destroy() - }, - setData(swapData) { - swapy.setData(swapData) - } - } -} - -class SwapyInstance { - private _rootEl: HTMLElement - private _veloxiApp - private _slotElMap: Map - private _itemElMap: Map - private _swapCallback?: SwapCallback - private _swapEndCallback?: SwapEndCallback - private _swapStartCallback?: SwapStartCallback - private _previousMap?: Map - private _pluginKey: string - constructor(rootEl: HTMLElement, pluginKey: string, config: Partial) { - this._rootEl = rootEl - this._veloxiApp = installPlugin() - this._slotElMap = this._createSlotElMap() - this._itemElMap = this._createItemElMap() - this.setAutoScrollOnDrag(config.autoScrollOnDrag!) - this._pluginKey = pluginKey - this._veloxiApp.onPluginEvent( - SwapyPlugin, - InitEvent, - ({ data }) => { - this._previousMap = data.map - }, - pluginKey - ) - - this._veloxiApp.onPluginEvent( - SwapyPlugin, - SwapEvent, - (event) => { - if ( - this._previousMap && - mapsAreEqual(this._previousMap, event.data.map) - ) { - return - } - if (!config.manualSwap) { - this._applyOrder(event.data.map) - } - this._previousMap = event.data.map - this._swapCallback?.(event) - }, - pluginKey - ) - - this._veloxiApp.onPluginEvent( - SwapyPlugin, - SwapEndEvent, - (event) => { - this._swapEndCallback?.(event) - }, - pluginKey - ) - - this._veloxiApp.onPluginEvent( - SwapyPlugin, - SwapStartEvent, - () => { - this._swapStartCallback?.() - }, - pluginKey - ) - - this.setupMutationObserver() - } - - private setupMutationObserver() { - const observer = new MutationObserver((mutations) => { - if (mutations.some((mutation) => mutation.type === 'childList')) { - if (resyncItems(this._rootEl)) { - this._slotElMap = this._createSlotElMap() - this._itemElMap = this._createItemElMap() - } - } - }) - observer.observe(this._rootEl, { - childList: true, - subtree: true - }) - } - - setData(swapData: SwapData) { - try { - const plugin = this._veloxiApp.getPlugin( - 'Swapy', - this._pluginKey - ) - plugin.setData(swapData) - } catch (e) {} - } - - destroy() { - this._veloxiApp.destroy('Swapy') - } - - setEnabled(enabledValue: boolean) { - requestAnimationFrame(() => { - try { - const plugin = this._veloxiApp.getPlugin( - 'Swapy', - this._pluginKey - ) - plugin.setEnabled(enabledValue) - } catch (e) {} - }) - } - - private setAutoScrollOnDrag(autoScrollOnDrag: boolean) { - requestAnimationFrame(() => { - try { - const plugin = this._veloxiApp.getPlugin( - 'Swapy', - this._pluginKey - ) - plugin.setAutoScrollOnDrag(autoScrollOnDrag) - } catch (e) {} - }) - } - - setSwapCallback(callback: SwapCallback) { - this._swapCallback = callback - } - - setSwapEndCallback(callback: SwapEndCallback) { - this._swapEndCallback = callback - } - - setSwapStartCallback(callback: SwapStartCallback) { - this._swapStartCallback = callback - } - - private _applyOrder(map: Map) { - Array.from(map.keys()).forEach((slotName) => { - if (map.get(slotName) === this._previousMap?.get(slotName)) { - return - } - const itemName = map.get(slotName) - if (!itemName) return - const slot = this._slotElMap.get(slotName) - const item = this._itemElMap.get(itemName) - if (!slot || !item) return - slot.innerHTML = '' - slot.appendChild(item) - }) - } - - private _createSlotElMap() { - return ( - Array.from( - this._rootEl.querySelectorAll('[data-swapy-slot]') - ) as HTMLElement[] - ).reduce((map, el) => { - map.set(el.dataset.swapySlot, el) - return map - }, new Map()) - } - - private _createItemElMap() { - return ( - Array.from( - this._rootEl.querySelectorAll('[data-swapy-item]') - ) as HTMLElement[] - ).reduce((map, el) => { - map.set(el.dataset.swapyItem, el) - return map - }, new Map()) - } -} - -export { createSwapy } diff --git a/src/math.ts b/src/math.ts new file mode 100644 index 0000000..c4a86a4 --- /dev/null +++ b/src/math.ts @@ -0,0 +1,50 @@ +import { BorderRadius } from './borderRadius' +import { Vec2, vec2Add, vec2Scale, vec2Sub } from './vector' + +export function lerp(a: number, b: number, t: number): number { + return a + (b - a) * t +} + +export function lerpVectors(v1: Vec2, v2: Vec2, t: number): Vec2 { + return vec2Add(v1, vec2Scale(vec2Sub(v2, v1), t)) +} + +export function lerpBorderRadius( + b1: BorderRadius, + b2: BorderRadius, + t: number +): BorderRadius { + return { + x: { + topLeft: lerp(b1.x.topLeft, b2.x.topLeft, t), + topRight: lerp(b1.x.topRight, b2.x.topRight, t), + bottomRight: lerp(b1.x.bottomRight, b2.x.bottomRight, t), + bottomLeft: lerp(b1.x.bottomLeft, b2.x.bottomLeft, t) + }, + y: { + topLeft: lerp(b1.y.topLeft, b2.y.topLeft, t), + topRight: lerp(b1.y.topRight, b2.y.topRight, t), + bottomRight: lerp(b1.y.bottomRight, b2.y.bottomRight, t), + bottomLeft: lerp(b1.y.bottomLeft, b2.y.bottomLeft, t) + }, + unit: b1.unit + } +} + +export function inverseLerp(min: number, max: number, value: number) { + return clamp((value - min) / (max - min), 0, 1) +} + +export function remap( + a: number, + b: number, + c: number, + d: number, + value: number +) { + return lerp(c, d, inverseLerp(a, b, value)) +} + +export function clamp(value: number, min: number, max: number) { + return Math.min(Math.max(value, min), max) +} diff --git a/src/rect.ts b/src/rect.ts new file mode 100644 index 0000000..0f560ac --- /dev/null +++ b/src/rect.ts @@ -0,0 +1,76 @@ +import { Vec2 } from './vector' + +export type Position = { x: number; y: number } +export type Size = { width: number; height: number } + +export type Rect = Position & Size + +export function createRectFromBoundingRect(rect: DOMRect): Rect { + return { + x: rect.x, + y: rect.y, + width: rect.width, + height: rect.height + } +} + +export function getLayoutRect(el: HTMLElement): Rect { + let current = el + let top = 0 + let left = 0 + + while (current) { + top += current.offsetTop + left += current.offsetLeft + current = current.offsetParent as HTMLElement + } + + return { + x: left, + y: top, + width: el.offsetWidth, + height: el.offsetHeight + } +} + +export function pointIntersectsWithRect(point: Position, rect: Rect) { + return ( + point.x >= rect.x && + point.x <= rect.x + rect.width && + point.y >= rect.y && + point.y <= rect.y + rect.height + ) +} + +export function getScrollOffset(el: HTMLElement): Vec2 { + let current: HTMLElement | null = el + let y = 0 + let x = 0 + + while (current) { + // Check if the current element is scrollable + const isScrollable = (node: HTMLElement) => { + const style = getComputedStyle(node) + return /(auto|scroll)/.test( + style.overflow + style.overflowY + style.overflowX + ) + } + + // If scrollable, add its scroll offsets + if (current === document.body) { + // Use window scroll for the element + x += window.scrollX + y += window.scrollY + break + } + + if (isScrollable(current)) { + x += current.scrollLeft + y += current.scrollTop + } + + current = current.parentElement + } + + return { x, y } +} diff --git a/src/utils.ts b/src/utils.ts index b010488..43a47c4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,17 +1,84 @@ -export function mapsAreEqual(map1: Map, map2: Map) { - if (map1.size !== map2.size) { - return false - } +import { SlotItemMapArray, Swapy } from '.' - for (let [key, value] of map1) { - if (!map2.has(key) || map2.get(key) !== value) { - return false - } - } - return true +export type SlottedItems = Array<{ + slotId: string + itemId: string + item: Item | null +}> + +export function toSlottedItems( + items: Array, + idField: keyof Item, + slotItemMap: SlotItemMapArray +): SlottedItems { + return slotItemMap.map((slotItem) => ({ + slotId: slotItem.slot, + itemId: slotItem.item, + item: + slotItem.item === '' + ? null + : items.find((item) => slotItem.item === item[idField])! + })) } -let id = 0 -export function getUniqueId() { - return id++ + '' +export function initSlotItemMap( + items: Array, + idField: keyof Item +): SlotItemMapArray { + return items.map((item) => ({ + item: item[idField] as string, + slot: item[idField] as string + })) +} + +export function dynamicSwapy( + swapy: Swapy | null, + items: Array, + idField: keyof Item, + slotItemMap: SlotItemMapArray, + setSlotItemMap: (slotItemMap: SlotItemMapArray) => void, + removeItemOnly = false +) { + // Get the newly added items and convert them to slotItem objects + const newItems: SlotItemMapArray = items + .filter( + (item) => !slotItemMap.some((slotItem) => slotItem.item === item[idField]) + ) + .map((item) => ({ + slot: item[idField] as string, + item: item[idField] as string + })) + + let withoutRemovedItems: SlotItemMapArray + + // Remove slot and item + if (!removeItemOnly) { + withoutRemovedItems = slotItemMap.filter( + (slotItem) => + items.some((item) => item[idField] === slotItem.item) || !slotItem.item + ) + } else { + withoutRemovedItems = slotItemMap.map((slotItem) => { + if (!items.some((item) => item[idField] === slotItem.item)) { + return { slot: slotItem.slot as string, item: '' } + } + return slotItem + }) + } + + const updatedSlotItemsMap: SlotItemMapArray = [ + ...withoutRemovedItems, + ...newItems + ] + + setSlotItemMap(updatedSlotItemsMap) + + if ( + newItems.length > 0 || + withoutRemovedItems.length !== slotItemMap.length + ) { + requestAnimationFrame(() => { + swapy?.update() + }) + } } diff --git a/src/vector.ts b/src/vector.ts new file mode 100644 index 0000000..d6a0d73 --- /dev/null +++ b/src/vector.ts @@ -0,0 +1,21 @@ +export type Vec2 = { x: number; y: number } + +export function isVec2(v: any): v is Vec2 { + return typeof v === 'object' && 'x' in v && 'y' in v +} + +export function vec2(x: number, y: number): Vec2 { + return { x, y } +} + +export function vec2Add(v1: Vec2, v2: Vec2): Vec2 { + return vec2(v1.x + v2.x, v1.y + v2.y) +} + +export function vec2Sub(v1: Vec2, v2: Vec2): Vec2 { + return vec2(v1.x - v2.x, v1.y - v2.y) +} + +export function vec2Scale(v: Vec2, a: number): Vec2 { + return vec2(v.x * a, v.y * a) +} diff --git a/src/veloxi-plugin/SwapyPlugin.ts b/src/veloxi-plugin/SwapyPlugin.ts deleted file mode 100644 index 461887b..0000000 --- a/src/veloxi-plugin/SwapyPlugin.ts +++ /dev/null @@ -1,516 +0,0 @@ -import { - DragEvent, - DragEventPlugin, - EventBus, - Events, - PluginFactory, - View -} from 'veloxi' -import { AnimationType, Config, SwapMode } from '../instance' -import { mapsAreEqual } from '../utils' -import { getScrollContainer, ScrollContainer } from '../ScrollContainer' - -export type SwapEventArray = Array<{ slotId: string; itemId: string | null }> -export type SwapEventMap = Map -export type SwapEventObject = Record - -interface SwapEventDataData { - map: SwapEventMap - array: SwapEventArray - object: SwapEventObject -} - -type RequireOnlyOne = Keys extends keyof T - ? { [K in Keys]: T[K] } & Partial, never>> - : never - -export type SwapData = RequireOnlyOne< - SwapEventDataData, - 'map' | 'array' | 'object' -> -export interface SwapEventData { - data: SwapEventDataData -} - -export type SwapEndEventData = SwapEventData & { hasChanged: boolean } - -export interface SwapyConfig { - animation: 'dynamic' | 'spring' | 'none' -} - -export interface SwapyPluginApi { - setEnabled(isEnabled: boolean): void - setData(data: SwapData): void - setAutoScrollOnDrag(autoScrollOnDrag: boolean): void -} - -export class SwapEvent { - data: SwapEventDataData - constructor(props: SwapEventData) { - this.data = props.data - } -} - -export class SwapEndEvent { - data: SwapEventDataData - hasChanged: boolean - constructor(props: SwapEndEventData) { - this.data = props.data - this.hasChanged = props.hasChanged - } -} - -export class SwapStartEvent {} - -export class InitEvent { - data: SwapEventDataData - constructor(props: SwapEventData) { - this.data = props.data - } -} - -function createEventData(eventMap: SwapEventMap): SwapEventDataData { - const map = new Map(eventMap) - return { - map, - array: Array.from(eventMap).map(([slotId, itemId]) => ({ slotId, itemId })), - object: Array.from(eventMap).reduce( - (result, [slot, item]) => { - result[slot] = item - return result - }, - {} - ) - } -} - -function createEventDataFromAny(data: SwapData): SwapEventDataData { - if (data.map) { - const map = new Map(data.map) - return { - map, - array: Array.from(data.map).map(([slotId, itemId]) => ({ - slotId, - itemId - })), - object: Array.from(data.map).reduce( - (result, [slot, item]) => { - result[slot] = item - return result - }, - {} - ) - } - } else if (data.object) { - const object = { ...data.object } - return { - map: new Map(Object.entries(object)), - array: Object.entries(object).map(([slotId, itemId]) => ({ - slotId, - itemId - })), - object - } - } else { - const array = [...data.array] - return { - map: new Map(array.map(({ slotId, itemId }) => [slotId, itemId])), - array, - object: array.reduce((result, { slotId, itemId }) => { - result[slotId] = itemId - return result - }, {}) - } - } -} - -export const SwapyPlugin: PluginFactory = ( - context -) => { - const dragEventPlugin = context.useEventPlugin(DragEventPlugin) - dragEventPlugin.on(DragEvent, onDrag) - - const MAX_SCROLL_SPEED = 20 - const MAX_SCROLL_THRESHOLD = 100 - - let root: View - let scrollContainer: ScrollContainer - let slots: View[] - let items: View[] - let draggingItem: View - let slotItemMapOnDragStart: SwapEventMap | null = null - let slotItemMap: SwapEventMap = new Map() - let previousSlotItemMap: SwapEventMap = new Map() - let offsetX: number | null - let offsetY: number | null - let handleOffsetX: number | null = null - let handleOffsetY: number | null = null - let initialWidth: number | null - let initialHeight: number | null - let enabled = true - let draggingEvent: DragEvent | null - let isContinuousMode: boolean - let isManualSwap: boolean - let draggingSlot: View | null - let startedDragging: boolean = false - let hasSwapped: boolean = false - let triggerSwap = () => {} - let shouldAutoScrollOnDrag = false - let scrollDY = 0 - let scrollDX = 0 - - context.api({ - setEnabled(isEnabled) { - enabled = isEnabled - }, - setData(data: SwapData) { - const eventData = createEventDataFromAny(data) - slotItemMap = new Map(eventData.map) - previousSlotItemMap = new Map(slotItemMap) - }, - setAutoScrollOnDrag(autoScrollOnDrag) { - shouldAutoScrollOnDrag = autoScrollOnDrag - } - }) - - function getConfig(): Config { - return { - animation: root.data.configAnimation as AnimationType, - continuousMode: typeof root.data.configContinuousMode !== 'undefined', - manualSwap: typeof root.data.configManualSwap !== 'undefined', - swapMode: root.data.configSwapMode as SwapMode, - autoScrollOnDrag: shouldAutoScrollOnDrag - } - } - - function getAnimation(): { - animator: 'dynamic' | 'spring' | 'instant' - config: any - } { - const animationConfig = getConfig().animation - if (animationConfig === 'dynamic') { - return { - animator: 'dynamic', - config: {} - } - } else if (animationConfig === 'spring') { - return { - animator: 'spring', - config: { - damping: 0.7, - stiffness: 0.62 - } - } - } else if (animationConfig === 'none') { - return { - animator: 'instant', - config: {} - } - } - return { - animator: 'instant', - config: {} - } - } - - function prepareSwap(newSlotItemMap: SwapEventMap) { - return () => { - slotItemMap = newSlotItemMap - previousSlotItemMap = new Map(slotItemMap) - } - } - - context.setup(() => { - root = context.getView('root')! - slots = context.getViews('slot') - items = context.getViews('item') - scrollContainer = getScrollContainer(items[0].element) - scrollContainer.onScroll(() => { - updateDraggingPosition() - }) - isContinuousMode = getConfig().continuousMode - isManualSwap = getConfig().manualSwap - - slots.forEach((slot) => { - setupSlot(slot) - }) - - setupRemainingChildren() - - previousSlotItemMap = new Map(slotItemMap) - requestAnimationFrame(() => { - context.emit(InitEvent, { data: createEventData(slotItemMap) }) - }) - }) - - function setupSlot(slot: View) { - const item = slot.getChild('item') - if (item) { - setupItem(item) - } - slotItemMap.set( - slot.element.dataset.swapySlot!, - item ? item.element.dataset.swapyItem! : null - ) - } - - function setupItem(item: View) { - const animation = getAnimation() - item.styles.position = 'relative' - item.styles.userSelect = 'none' - item.styles.webkitUserSelect = 'none' - item.position.setAnimator(animation.animator, animation.config) - item.scale.setAnimator(animation.animator, animation.config) - item.layoutTransition(true) - - requestAnimationFrame(() => { - const handle = item.getChild('handle') - if (handle) { - dragEventPlugin.addView(handle) - handle.styles.touchAction = 'none' - } else { - dragEventPlugin.addView(item) - item.styles.touchAction = 'none' - } - }) - } - - context.onViewAdded((view) => { - if (context.initialized) { - if (view.name === 'item') { - items = context.getViews('item') - const slot = view.getParent('slot')! - setupSlot(slot) - setupRemainingChildren() - previousSlotItemMap = new Map(slotItemMap) - context.emit(SwapEvent, { data: createEventData(slotItemMap) }) - } else if (view.name === 'slot') { - slots = context.getViews('slot') - } - } - }) - - function setupRemainingChildren() { - const animation = getAnimation() - const remainingChildren = context.getViews('root-child') - remainingChildren.forEach((child) => { - child.position.setAnimator(animation.animator, animation.config) - child.scale.setAnimator(animation.animator, animation.config) - child.layoutTransition(true) - }) - } - - function updateDraggingPosition() { - if (!draggingEvent) return - if (!offsetX || !offsetY) { - const draggingItemScrollOffset = draggingItem.getScroll() - offsetX = - draggingEvent.pointerX - - draggingItem.position.x + - draggingItemScrollOffset.x - offsetY = - draggingEvent.pointerY - - draggingItem.position.y + - draggingItemScrollOffset.y - } - if (!initialWidth || !initialHeight) { - initialWidth = draggingItem.size.width - initialHeight = draggingItem.size.height - } - const scaleX = draggingItem.size.width / initialWidth - const scaleY = draggingItem.size.height / initialHeight - const newOffsetX = offsetX * (scaleX - 1) - const newOffsetY = offsetY * (scaleY - 1) - const { x: scrollOffsetX, y: scrollOffsetY } = - scrollContainer.getScrollOffset() - draggingItem.position.set( - { - x: draggingEvent.x - newOffsetX - (handleOffsetX || 0) + scrollOffsetX, - y: draggingEvent.y - newOffsetY - (handleOffsetY || 0) + scrollOffsetY - }, - draggingItem.scale.x !== 1 || draggingItem.scale.y !== 1 - ) - } - - context.subscribeToEvents((eventBus: EventBus) => { - eventBus.subscribeToEvent(Events.PointerMoveEvent, ({ x, y }) => { - if (!scrollContainer) { - return - } - if (scrollContainer.height - y <= MAX_SCROLL_THRESHOLD) { - scrollDY = Math.max( - 0, - MAX_SCROLL_SPEED * - (1 - - Math.min(scrollContainer.height - y, MAX_SCROLL_THRESHOLD) / - MAX_SCROLL_THRESHOLD) - ) - } else if (y <= MAX_SCROLL_THRESHOLD) { - scrollDY = - -1 * - Math.max( - 0, - MAX_SCROLL_SPEED * - (1 - Math.min(y, MAX_SCROLL_THRESHOLD) / MAX_SCROLL_THRESHOLD) - ) - } else { - scrollDY = 0 - } - - if (scrollContainer.width - x <= MAX_SCROLL_THRESHOLD) { - scrollDX = Math.max( - 0, - MAX_SCROLL_SPEED * - (1 - - Math.min(scrollContainer.width - x, MAX_SCROLL_THRESHOLD) / - MAX_SCROLL_THRESHOLD) - ) - } else if (x <= MAX_SCROLL_THRESHOLD) { - scrollDX = - -1 * - Math.max( - 0, - MAX_SCROLL_SPEED * - (1 - Math.min(x, MAX_SCROLL_THRESHOLD) / MAX_SCROLL_THRESHOLD) - ) - } else { - scrollDX = 0 - } - }) - }) - - context.update(() => { - if (draggingEvent?.isDragging && shouldAutoScrollOnDrag) { - scrollContainer.container.scrollBy({ top: scrollDY, left: scrollDX }) - } - }) - - function onDrag(event: DragEvent) { - if (!enabled || !event.hasMoved) return - const swapMode = getConfig().swapMode - const withHandle = event.view.name === 'handle' - draggingItem = withHandle ? event.view.getParent('item')! : event.view - if (!draggingSlot) { - draggingSlot = draggingItem.getParent('slot')! - } - if (handleOffsetX === null && handleOffsetY === null) { - const resetHandleX = withHandle - ? event.view.position.initialX - event.view.position.x - : 0 - const resetHandleY = withHandle - ? event.view.position.initialY - event.view.position.y - : 0 - handleOffsetX = - event.view.position.x - draggingItem.position.x - resetHandleX - handleOffsetY = - event.view.position.y - draggingItem.position.y - resetHandleY - } - const hoveringOverASlot = slots.some((slot) => - slot.intersects(event.pointerX, event.pointerY) - ) - if (event.isDragging) { - scrollContainer.startScrollTracking() - if (!startedDragging) { - startedDragging = true - context.emit(SwapStartEvent, {}) - } - if (slotItemMapOnDragStart === null) { - slotItemMapOnDragStart = new Map(slotItemMap) - } - draggingEvent = event - updateDraggingPosition() - slots.forEach((slot) => { - if (!slot.intersects(event.pointerX, event.pointerY)) { - if (slot !== draggingSlot) { - slot.element.removeAttribute('data-swapy-highlighted') - } - return - } - - if (typeof slot.element.dataset.swapyHighlighted === 'undefined') { - slot.element.dataset.swapyHighlighted = '' - } - - if (!draggingSlot) { - return - } - - if ( - (swapMode === 'stop' || (swapMode !== 'drop' && !isContinuousMode)) && - !event.stopped - ) { - return - } - const targetSlotName = slot.element.dataset.swapySlot - const targetItemName = slot.getChild('item')?.element.dataset.swapyItem - const draggingSlotName = draggingSlot!.element.dataset.swapySlot - const draggingItemName = draggingItem.element.dataset.swapyItem - - if (!targetSlotName || !draggingSlotName || !draggingItemName) { - return - } - const newSlotItemMap = new Map(slotItemMap) - newSlotItemMap.set(targetSlotName, draggingItemName) - if (targetItemName) { - newSlotItemMap.set(draggingSlotName, targetItemName) - } else { - newSlotItemMap.set(draggingSlotName, null) - } - triggerSwap = prepareSwap(new Map(newSlotItemMap)) - if (!mapsAreEqual(newSlotItemMap, previousSlotItemMap)) { - if (!isManualSwap && swapMode !== 'drop') { - triggerSwap() - } - draggingSlot = null - if (swapMode !== 'drop') { - context.emit(SwapEvent, { data: createEventData(newSlotItemMap) }) - } - } - }) - - items.forEach((item) => { - item.styles.zIndex = item === draggingItem ? '2' : '' - }) - } else { - slots.forEach((slot) => { - slot.element.removeAttribute('data-swapy-highlighted') - }) - draggingItem.position.reset() - draggingSlot = null - offsetX = null - offsetY = null - initialWidth = null - initialHeight = null - draggingEvent = null - handleOffsetX = null - handleOffsetY = null - startedDragging = false - - if (swapMode === 'drop') { - if (!hoveringOverASlot) { - triggerSwap = prepareSwap(new Map(slotItemMap)) - } - triggerSwap() - context.emit(SwapEvent, { data: createEventData(slotItemMap) }) - } - triggerSwap = () => {} - - hasSwapped = !mapsAreEqual(slotItemMap, slotItemMapOnDragStart!) - - context.emit(SwapEndEvent, { - data: createEventData(slotItemMap), - hasChanged: hasSwapped - }) - - hasSwapped = false - slotItemMapOnDragStart = null - scrollContainer.endScrollTracking() - } - requestAnimationFrame(() => { - updateDraggingPosition() - }) - } -} - -SwapyPlugin.pluginName = 'Swapy' -SwapyPlugin.scope = 'root' diff --git a/src/veloxi-plugin/index.ts b/src/veloxi-plugin/index.ts deleted file mode 100644 index 5ce5d40..0000000 --- a/src/veloxi-plugin/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { createApp, type VeloxiApp } from 'veloxi' -import { SwapyConfig, SwapyPlugin, SwapyPluginApi } from './SwapyPlugin' - -let app: VeloxiApp -function installPlugin() { - if (app) { - app.updatePlugin(SwapyPlugin) - return app - } - app = createApp() - app.addPlugin(SwapyPlugin) - app.run() - return app -} - -export { installPlugin } diff --git a/src/view.ts b/src/view.ts new file mode 100644 index 0000000..734011a --- /dev/null +++ b/src/view.ts @@ -0,0 +1,120 @@ +import { BorderRadius, parseBorderRadius } from './borderRadius' +import { createRectFromBoundingRect, getLayoutRect, Rect } from './rect' + +export interface View { + el(): HTMLElement + setTransform(transform: Partial): void + clearTransform(): void + currentTransform: () => Transform + borderRadius: () => BorderRadius + layoutRect(): Rect + boundingRect(): Rect + usePlugin

( + pluginFactory: (v: View, config: C) => P, + config: C + ): P + updateElement(el: HTMLElement): void + destroy(): void +} + +export interface ViewPlugin { + onElementUpdate(): void + destroy(): void +} + +export type Transform = { + dragX: number + dragY: number + translateX: number + translateY: number + scaleX: number + scaleY: number +} + +export function createView(el: HTMLElement): View { + const plugins: Array = [] + let element = el + let currentTransform: Transform = { + dragX: 0, + dragY: 0, + translateX: 0, + translateY: 0, + scaleX: 1, + scaleY: 1 + } + const borderRadius = parseBorderRadius( + window.getComputedStyle(element).borderRadius + ) + const thisView = { + el: () => element, + setTransform, + clearTransform, + currentTransform: () => currentTransform, + borderRadius: () => borderRadius, + layoutRect: () => getLayoutRect(element), + boundingRect: () => + createRectFromBoundingRect(element.getBoundingClientRect()), + usePlugin, + destroy, + updateElement + } + + function setTransform(newTransform: Partial) { + currentTransform = { ...currentTransform, ...newTransform } + renderTransform() + } + + function clearTransform() { + currentTransform = { + dragX: 0, + dragY: 0, + translateX: 0, + translateY: 0, + scaleX: 1, + scaleY: 1 + } + renderTransform() + } + + function renderTransform() { + const { dragX, dragY, translateX, translateY, scaleX, scaleY } = + currentTransform + if ( + dragX === 0 && + dragY === 0 && + translateX === 0 && + translateY === 0 && + scaleX === 1 && + scaleY === 1 + ) { + element.style.transform = '' + } else { + element.style.transform = `translate(${dragX + translateX}px, ${ + dragY + translateY + }px) scale(${scaleX}, ${scaleY})` + } + } + + function usePlugin

( + pluginFactory: (v: View, config: C) => P, + config: C + ) { + const plugin = pluginFactory(thisView, config) + plugins.push(plugin) + return plugin + } + + function destroy() { + plugins.forEach((plugin) => plugin.destroy()) + } + + function updateElement(el: HTMLElement) { + if (!el) return + const previousStyles = element.style.cssText + element = el + element.style.cssText = previousStyles + plugins.forEach((plugin) => plugin.onElementUpdate()) + } + + return thisView +} diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 4078e74..11f02fe 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,2 +1 @@ -/// /// diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..e9041fd --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src"] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 27e7a52..1e0d5a4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,9 +7,8 @@ "skipLibCheck": true, /* Bundler mode */ - "moduleResolution": "bundler", + "moduleResolution": "Bundler", "allowImportingTsExtensions": true, - "resolveJsonModule": true, "isolatedModules": true, "moduleDetection": "force", "noEmit": true, @@ -21,6 +20,5 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["src", "examples/**/*.ts", "examples/**/*.tsx"], - "exclude": ["examples/vue"] + "include": ["src", "examples/**/*.ts", "examples/**/*.tsx", "examples/**/*.svelte", "examples/**/*.vue"] } diff --git a/vite.config.js b/vite.config.ts similarity index 100% rename from vite.config.js rename to vite.config.ts