Compare commits
104 Commits
feature/la
...
ce69598175
| Author | SHA1 | Date | |
|---|---|---|---|
| ce69598175 | |||
| 49af17c0e3 | |||
| bade5cec0c | |||
| 0b78c406ec | |||
| 4d64bf8aa3 | |||
| 422642b407 | |||
| d46b1451fe | |||
| 009f8810e0 | |||
| cabc1f747f | |||
| 62aac7291e | |||
| bc9ce86d10 | |||
| 68d15721ea | |||
| 79f9e3f7b2 | |||
| b7f90e69a1 | |||
| 9cac4e6fd8 | |||
| e51cb4b334 | |||
| 04f88dd878 | |||
| 3e117c8f5a | |||
| b442eac69b | |||
| 934b6cba9b | |||
| a314721a60 | |||
| 65bdc2974f | |||
| 221dcb7072 | |||
| 9e19237311 | |||
| 7e51896d00 | |||
| 8e1b5fa77c | |||
| dc3e535955 | |||
| 1f9fc4d5bb | |||
| 281a37fa7e | |||
| 4b270b83e9 | |||
| ab939c202e | |||
| e916c80d00 | |||
| 37feb62a56 | |||
| 721fc20e1e | |||
| 5f220102e2 | |||
| 89d369598f | |||
| 784c95555f | |||
| b5e105b127 | |||
| 3120edb43b | |||
| 0e88199e6e | |||
| 012448df3e | |||
| bcd6dc43c7 | |||
| 6fe90c6af9 | |||
| 3aa01dd044 | |||
| c738f28867 | |||
| a381900356 | |||
| 883c93b7ff | |||
| b255acce40 | |||
| f52530d058 | |||
| bf95f4fbee | |||
| c4a0024ec0 | |||
| 8a86ae3e98 | |||
| 233aab5350 | |||
| cfef7d30aa | |||
| 04ab97b15c | |||
| 14dbb17ba2 | |||
| 75e24eac42 | |||
| 0942ce5d51 | |||
| fd43c7b515 | |||
| 2d4a7e3765 | |||
| 84428b3196 | |||
| c448a4c267 | |||
| 80787719e6 | |||
| b801cd4c99 | |||
| accea99408 | |||
| 09c77f5414 | |||
| d38ba85f4f | |||
| 54ef9121c7 | |||
| 7152482687 | |||
| 107caef54d | |||
| 5ca0a0ea78 | |||
| f9986b319d | |||
| df6758d112 | |||
| 00cee9e593 | |||
| 70090f3a6c | |||
| 4bbe797d9b | |||
| 9717ab9575 | |||
| 386393e507 | |||
| b2f9e7d5b9 | |||
| 044c819a09 | |||
| 8505e98947 | |||
| 19d0f3584c | |||
| 452711a6f9 | |||
| caef8003fa | |||
| 2586a0a0bc | |||
| a76c0bd04d | |||
| 551d7a027f | |||
| 6b0c82a630 | |||
| a0d2b2994b | |||
| 7f8e26255f | |||
| 4ec82317ea | |||
| fed578441a | |||
| 62205ed069 | |||
| 6ae8dd37dc | |||
| 77a1b22faf | |||
| 8b1ea0f5b4 | |||
| 9a2bf6b2db | |||
| 2c25157621 | |||
| 9fa2bbd15d | |||
| b3f530870e | |||
| 56858701ef | |||
| f8b4e98f9c | |||
| 69fc4c4a7e | |||
| d35ae69265 |
1
.env.example
Normal file
1
.env.example
Normal file
@@ -0,0 +1 @@
|
|||||||
|
VITE_POCKETBASE_URL=https://pb1.adhd.sh
|
||||||
24
Caddyfile
24
Caddyfile
@@ -1,16 +1,28 @@
|
|||||||
http://spritesheetgenerator.online:1337 {
|
http://spritesheetgenerator.online:1337 {
|
||||||
root * ./dist
|
root * ./dist
|
||||||
encode gzip
|
encode zstd gzip
|
||||||
|
|
||||||
|
# Aggressive caching for static assets
|
||||||
|
@static path *.js *.css *.png *.jpg *.jpeg *.gif *.webp *.svg *.woff *.woff2 *.ico
|
||||||
|
header @static Cache-Control "public, max-age=31536000, immutable"
|
||||||
|
|
||||||
|
# Short cache for HTML (for SPA updates)
|
||||||
|
@html path *.html /
|
||||||
|
header @html Cache-Control "no-cache, must-revalidate"
|
||||||
|
|
||||||
|
# Default cache for everything else
|
||||||
|
header ?Cache-Control "max-age=1800"
|
||||||
|
|
||||||
try_files {path} /index.html
|
try_files {path} /index.html
|
||||||
|
file_server {
|
||||||
file_server
|
precompressed zstd gzip
|
||||||
|
}
|
||||||
|
|
||||||
log {
|
log {
|
||||||
output file /var/log/caddy/spritesheetgenerator.online.log
|
output file /var/log/caddy/spritesheetgenerator.online.log
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
header {
|
:1338 {
|
||||||
?Cache-Control "max-age=1800"
|
redir https://spritesheetgenerator.online{uri} permanent
|
||||||
}
|
|
||||||
}
|
}
|
||||||
636
LICENSE.md
Normal file
636
LICENSE.md
Normal file
@@ -0,0 +1,636 @@
|
|||||||
|
# GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 [Free Software Foundation, Inc.](http://fsf.org/)
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies of this license
|
||||||
|
document, but changing it is not allowed.
|
||||||
|
|
||||||
|
## Preamble
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
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
|
||||||
|
[http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
|
||||||
|
|
||||||
|
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
|
||||||
|
[http://www.gnu.org/philosophy/why-not-lgpl.html](http://www.gnu.org/philosophy/why-not-lgpl.html).
|
||||||
30
index.html
30
index.html
@@ -2,36 +2,45 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
<!-- Preconnect to external domains for performance -->
|
||||||
|
<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin>
|
||||||
|
<link rel="dns-prefetch" href="https://cdnjs.cloudflare.com">
|
||||||
|
<link rel="preconnect" href="https://a.adhd.sh" crossorigin>
|
||||||
|
<link rel="dns-prefetch" href="https://a.adhd.sh">
|
||||||
|
<link rel="preconnect" href="https://pagead2.googlesyndication.com" crossorigin>
|
||||||
|
<link rel="dns-prefetch" href="https://pagead2.googlesyndication.com">
|
||||||
|
|
||||||
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
|
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
<link rel="shortcut icon" href="/favicon.ico" />
|
<link rel="shortcut icon" href="/favicon.ico" />
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
||||||
<meta name="apple-mobile-web-app-title" content="MyWebSite" />
|
<meta name="apple-mobile-web-app-title" content="Spritesheet Generator" />
|
||||||
<link rel="manifest" href="/site.webmanifest" />
|
<link rel="manifest" href="/site.webmanifest" />
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
|
|
||||||
<!-- Primary Meta Tags -->
|
<!-- Primary Meta Tags -->
|
||||||
<title>Spritesheet Generator - Create Game Spritesheets Online</title>
|
<title>Spritesheet generator - Create Game Spritesheets Online</title>
|
||||||
<meta name="title" content="Spritesheet Generator - Create Game Spritesheets Online">
|
<meta name="title" content="Spritesheet generator - Create Game Spritesheets Online">
|
||||||
<meta name="description" content="Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.">
|
<meta name="description" content="Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.">
|
||||||
<meta name="keywords" content="spritesheet generator, sprite sheet maker, game development, pixel art, sprite animation, game assets, 2D game tools">
|
<meta name="keywords" content="Spritesheet generator, sprite sheet maker, game development, pixel art, sprite animation, game assets, 2D game tools">
|
||||||
<meta name="author" content="nu11ed">
|
<meta name="author" content="streetshadow">
|
||||||
<meta name="robots" content="index, follow">
|
<meta name="robots" content="index, follow">
|
||||||
|
<link rel="canonical" href="https://spritesheetgenerator.online/">
|
||||||
|
|
||||||
<!-- Open Graph / Facebook -->
|
<!-- Open Graph / Facebook -->
|
||||||
<meta property="og:type" content="website">
|
<meta property="og:type" content="website">
|
||||||
<meta property="og:url" content="https://spritesheetgenerator.online/">
|
<meta property="og:url" content="https://spritesheetgenerator.online/">
|
||||||
<meta property="og:title" content="Spritesheet Generator - Create Game Spritesheets Online">
|
<meta property="og:title" content="Spritesheet generator - Create Game Spritesheets Online">
|
||||||
<meta property="og:description" content="Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.">
|
<meta property="og:description" content="Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.">
|
||||||
<meta property="og:image" content="/og-image.png">
|
<meta property="og:image" content="/og-image.png">
|
||||||
|
|
||||||
<!-- Twitter -->
|
<!-- Twitter -->
|
||||||
<meta property="twitter:card" content="summary_large_image">
|
<meta property="twitter:card" content="summary_large_image">
|
||||||
<meta property="twitter:url" content="https://spritesheetgenerator.online/">
|
<meta property="twitter:url" content="https://spritesheetgenerator.online/">
|
||||||
<meta property="twitter:title" content="Spritesheet Generator - Create Game Spritesheets Online">
|
<meta property="twitter:title" content="Spritesheet generator - Create Game Spritesheets Online">
|
||||||
<meta property="twitter:description" content="Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.">
|
<meta property="twitter:description" content="Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.">
|
||||||
<meta property="twitter:image" content="/og-image.png">
|
<meta property="twitter:image" content="/og-image.png">
|
||||||
|
|
||||||
@@ -39,8 +48,6 @@
|
|||||||
<meta name="theme-color" content="#0096ff" media="(prefers-color-scheme: light)">
|
<meta name="theme-color" content="#0096ff" media="(prefers-color-scheme: light)">
|
||||||
<meta name="theme-color" content="#111827" media="(prefers-color-scheme: dark)">
|
<meta name="theme-color" content="#111827" media="(prefers-color-scheme: dark)">
|
||||||
|
|
||||||
<title>Spritesheet generator</title>
|
|
||||||
|
|
||||||
<script
|
<script
|
||||||
src="https://a.adhd.sh/api/script.js"
|
src="https://a.adhd.sh/api/script.js"
|
||||||
data-site-id="7"
|
data-site-id="7"
|
||||||
@@ -48,9 +55,6 @@
|
|||||||
data-session-replay="true"
|
data-session-replay="true"
|
||||||
defer
|
defer
|
||||||
></script>
|
></script>
|
||||||
|
|
||||||
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3715260871588949"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
1061
package-lock.json
generated
1061
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -13,18 +13,23 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindcss/vite": "^4.1.1",
|
"@tailwindcss/vite": "^4.1.1",
|
||||||
|
"@vueuse/head": "^2.0.0",
|
||||||
|
"buffer": "^6.0.3",
|
||||||
"gif.js": "^0.2.0",
|
"gif.js": "^0.2.0",
|
||||||
|
"gray-matter": "^4.0.3",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"marked": "^15.0.7",
|
"marked": "^15.0.7",
|
||||||
"pinia": "^3.0.1",
|
"pinia": "^3.0.1",
|
||||||
"pocketbase": "^0.26.2",
|
"pocketbase": "^0.26.2",
|
||||||
"vue": "^3.5.13"
|
"vue": "^3.5.13",
|
||||||
|
"vue-router": "^4.6.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
|
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
|
||||||
|
"@tailwindcss/typography": "^0.5.19",
|
||||||
"@tsconfig/node22": "^22.0.1",
|
"@tsconfig/node22": "^22.0.1",
|
||||||
"@types/gif.js": "^0.2.5",
|
"@types/gif.js": "^0.2.5",
|
||||||
"@types/node": "^22.13.14",
|
"@types/node": "^22.19.1",
|
||||||
"@vitejs/plugin-vue": "^5.2.3",
|
"@vitejs/plugin-vue": "^5.2.3",
|
||||||
"@vue/tsconfig": "^0.7.0",
|
"@vue/tsconfig": "^0.7.0",
|
||||||
"autoprefixer": "^10.4.21",
|
"autoprefixer": "^10.4.21",
|
||||||
|
|||||||
@@ -1,5 +1,30 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [2.3.0] - 2026-01-01
|
||||||
|
- Add authentication
|
||||||
|
- You can now save projects and open them
|
||||||
|
|
||||||
|
## [2.2.0] - 2026-01-01
|
||||||
|
- Add move sprite with arrow keys in preview
|
||||||
|
- Add replace sprite to context menu
|
||||||
|
- Add copy sprite to frame to context menu
|
||||||
|
|
||||||
|
## [2.1.0] - 2026-01-01
|
||||||
|
- Improved the whole UI. Happy new year!
|
||||||
|
|
||||||
|
## [2.0.0] - 2025-12-17
|
||||||
|
- Add rotate sprite to context menu
|
||||||
|
- Add flip sprite to context menu
|
||||||
|
- Add multi select for sprite removal
|
||||||
|
- Add drag and drop in file area when sprite is open
|
||||||
|
|
||||||
|
## [1.9.0] - 2025-12-14
|
||||||
|
- You can now share spritesheets to edit them later or share them with others
|
||||||
|
|
||||||
|
## [1.8.0] - 2025-11-23
|
||||||
|
- Fix context menu location
|
||||||
|
- You can now reposition all sprites in current frame
|
||||||
|
|
||||||
## [1.7.0] - 2025-11-22
|
## [1.7.0] - 2025-11-22
|
||||||
- Add layer support
|
- Add layer support
|
||||||
- Add background color picker
|
- Add background color picker
|
||||||
|
|||||||
BIN
public/blog/1.png
Normal file
BIN
public/blog/1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 758 KiB |
BIN
public/blog/2.jpg
Normal file
BIN
public/blog/2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
3
public/robots.txt
Normal file
3
public/robots.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
User-agent: *
|
||||||
|
Allow: /
|
||||||
|
Sitemap: https://spritesheetgenerator.online/sitemap.xml
|
||||||
42
public/sitemap.xml
Normal file
42
public/sitemap.xml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<urlset
|
||||||
|
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
|
||||||
|
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
||||||
|
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/</loc>
|
||||||
|
<lastmod>2025-11-26T15:50:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/about</loc>
|
||||||
|
<lastmod>2025-11-26T15:50:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/contact</loc>
|
||||||
|
<lastmod>2025-11-26T15:50:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/privacy-policy</loc>
|
||||||
|
<lastmod>2025-11-26T15:50:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/blog</loc>
|
||||||
|
<lastmod>2025-11-26T15:50:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/blog/why-pixel-art</loc>
|
||||||
|
<lastmod>2025-11-26T15:50:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/blog/welcome</loc>
|
||||||
|
<lastmod>2025-11-26T15:50:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://spritesheetgenerator.online/faq</loc>
|
||||||
|
<lastmod>2025-11-26T19:37:00+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
|
||||||
|
|
||||||
|
</urlset>
|
||||||
300
src/App.vue
300
src/App.vue
@@ -1,160 +1,35 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="min-h-screen p-3 sm:p-6 bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 transition-colors duration-300">
|
<div class="min-h-screen flex flex-col bg-gray-50 dark:bg-gray-950 transition-colors duration-300 font-sans" :class="{ 'lg:h-screen': $route.name === 'editor' }">
|
||||||
<div class="max-w-7xl mx-auto">
|
<!-- Navbar -->
|
||||||
<div class="flex flex-col sm:flex-row justify-between items-center mb-4 sm:mb-8 gap-2">
|
<Navbar @open-help="openHelpModal" />
|
||||||
<h1 class="text-2xl sm:text-4xl font-bold text-gray-900 dark:text-white tracking-tight text-center sm:text-left">Spritesheet generator</h1>
|
|
||||||
<dark-mode-toggle />
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-wrap justify-center gap-4 mb-4 sm:mb-8">
|
|
||||||
<a href="https://gitea.adhd.sh/root/spritesheet-generator" target="_blank" class="text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 transition-colors" data-rybbit-event="source-link"> <i class="fab fa-github"></i> Source </a>
|
|
||||||
<a href="https://discord.gg/JTev3nzeDa" target="_blank" class="text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 transition-colors" data-rybbit-event="discord-link"> <i class="fab fa-discord"></i> Discord </a>
|
|
||||||
<a href="#" @click.prevent="openHelpModal" class="text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 transition-colors" data-rybbit-event="help-link"> <i class="fas fa-question-circle"></i> Help </a>
|
|
||||||
<a href="#" @click.prevent="openFeedbackModal" class="text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300 transition-colors" data-rybbit-event="feedback-link"> <i class="fas fa-comment-dots"></i> Feedback </a>
|
|
||||||
</div>
|
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-2xl shadow-soft dark:shadow-gray-900/30 p-4 sm:p-8 transition-colors duration-300">
|
|
||||||
<div class="flex flex-col sm:flex-row justify-between items-center mb-4 sm:mb-6 gap-3">
|
|
||||||
<h2 class="text-xl font-semibold text-gray-800 dark:text-gray-100">Upload sprites</h2>
|
|
||||||
<button
|
|
||||||
@click="openJSONImportDialog"
|
|
||||||
class="w-full sm:w-auto px-4 py-2 bg-indigo-500 hover:bg-indigo-600 dark:bg-indigo-600 dark:hover:bg-indigo-700 text-white font-medium rounded-lg transition-colors flex items-center justify-center sm:justify-start space-x-2"
|
|
||||||
data-rybbit-event="import-json"
|
|
||||||
>
|
|
||||||
<i class="fas fa-file-import"></i>
|
|
||||||
<span>Import JSON</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<file-uploader @upload-sprites="handleSpritesUpload" />
|
|
||||||
<input ref="jsonFileInput" type="file" accept=".json,application/json" class="hidden" @change="handleJSONFileChange" />
|
|
||||||
<div v-if="!visibleLayers.some(l => l.sprites.length)" class="mt-8">
|
|
||||||
<div class="mt-2 leading-relaxed space-y-2">
|
|
||||||
<p>Create spritesheets for your game development and animation projects with our completely free, open-source spritesheet generator.</p>
|
|
||||||
<p>This powerful online tool lets you upload individual sprite images and automatically arrange them into optimized sprite sheets with customizable layouts - perfect for indie developers, animators, and studios of any size.</p>
|
|
||||||
<p class="font-bold text-2xl pb-3 pt-2">How it works:</p>
|
|
||||||
<video controls playsinline class="w-full h-full object-contain rounded-lg shadow-md" title="Spritesheet generator tutorial" aria-label="Spritesheet generator tutorial">
|
|
||||||
<source src="@/assets/tut2.mp4" type="video/mp4" />
|
|
||||||
</video>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="visibleLayers.some(l => l.sprites.length)" class="mt-8">
|
<div class="flex flex-col flex-1 relative z-10 p-4 sm:p-6 lg:p-8 pt-6" :class="{ 'lg:overflow-hidden': $route.name === 'editor' }">
|
||||||
<div class="flex flex-col gap-3 mb-4">
|
<Breadcrumbs class="mb-6" />
|
||||||
<div class="flex items-center gap-2 flex-wrap">
|
|
||||||
<span class="text-gray-700 dark:text-gray-200 font-medium">Layers</span>
|
|
||||||
<button @click="addLayer()" class="px-3 py-1.5 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-100 rounded">Add</button>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-wrap gap-2">
|
|
||||||
<div v-for="layer in layers" :key="layer.id" class="flex items-center gap-2 px-2 py-1 rounded border border-gray-200 dark:border-gray-600" :class="{ 'ring-2 ring-blue-500': layer.id === activeLayerId }">
|
|
||||||
<button @click="activeLayerId = layer.id" class="px-2 py-0.5 rounded bg-blue-50 dark:bg-blue-900/30 text-blue-800 dark:text-blue-200">{{ layer.name }}</button>
|
|
||||||
<label class="flex items-center gap-1 text-xs text-gray-600 dark:text-gray-300"> <input type="checkbox" v-model="layer.visible" /> Visible </label>
|
|
||||||
<button @click="moveLayer(layer.id, 'up')" class="text-xs px-1.5 py-0.5 bg-gray-100 dark:bg-gray-700 rounded">↑</button>
|
|
||||||
<button @click="moveLayer(layer.id, 'down')" class="text-xs px-1.5 py-0.5 bg-gray-100 dark:bg-gray-700 rounded">↓</button>
|
|
||||||
<button v-if="layers.length > 1" @click="removeLayer(layer.id)" class="text-xs px-1.5 py-0.5 bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-200 rounded">Remove</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-wrap items-center justify-center sm:justify-start gap-3 sm:gap-6 mb-6 sm:mb-8">
|
|
||||||
<div class="flex items-center space-x-1">
|
|
||||||
<label for="columns" class="text-gray-700 dark:text-gray-200 font-medium">Columns:</label>
|
|
||||||
<input
|
|
||||||
id="columns"
|
|
||||||
type="number"
|
|
||||||
v-model.number="columns"
|
|
||||||
min="1"
|
|
||||||
max="10"
|
|
||||||
class="w-20 px-3 py-2 border border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 rounded-lg focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent outline-none transition-all text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex items-center space-x-1">
|
<router-view v-slot="{ Component }">
|
||||||
<span class="text-gray-700 dark:text-gray-200 font-medium">Cell size:</span>
|
<component :is="Component" />
|
||||||
<span class="text-gray-600 dark:text-gray-300">{{ cellSize.width }} × {{ cellSize.height }}px</span>
|
</router-view>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add mass position buttons -->
|
|
||||||
<div class="flex flex-wrap items-center justify-center gap-2">
|
|
||||||
<button @click="alignSprites('left')" class="p-3 sm:p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors" title="Align Left" data-rybbit-event="align-left">
|
|
||||||
<i class="fas fa-arrow-left"></i>
|
|
||||||
</button>
|
|
||||||
<button @click="alignSprites('center')" class="p-3 sm:p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors" title="Align Center" data-rybbit-event="align-center">
|
|
||||||
<i class="fas fa-arrows-left-right"></i>
|
|
||||||
</button>
|
|
||||||
<button @click="alignSprites('right')" class="p-3 sm:p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors" title="Align Right" data-rybbit-event="align-right">
|
|
||||||
<i class="fas fa-arrow-right"></i>
|
|
||||||
</button>
|
|
||||||
<button @click="alignSprites('top')" class="p-3 sm:p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors" title="Align Top" data-rybbit-event="align-top">
|
|
||||||
<i class="fas fa-arrow-up"></i>
|
|
||||||
</button>
|
|
||||||
<button @click="alignSprites('middle')" class="p-3 sm:p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors" title="Align Middle" data-rybbit-event="align-middle">
|
|
||||||
<i class="fas fa-arrows-up-down"></i>
|
|
||||||
</button>
|
|
||||||
<button @click="alignSprites('bottom')" class="p-3 sm:p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors" title="Align Bottom" data-rybbit-event="align-bottom">
|
|
||||||
<i class="fas fa-arrow-down"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button @click="downloadSpritesheet" class="w-full sm:w-auto px-6 py-3 sm:py-2.5 bg-blue-500 hover:bg-blue-600 dark:bg-blue-600 dark:hover:bg-blue-700 text-white font-medium rounded-lg transition-colors flex items-center justify-center space-x-2" data-rybbit-event="download-spritesheet">
|
|
||||||
<i class="fas fa-download"></i>
|
|
||||||
<span>Download spritesheet</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
@click="exportSpritesheetJSON"
|
|
||||||
class="w-full sm:w-auto px-6 py-3 sm:py-2.5 bg-purple-500 hover:bg-purple-600 dark:bg-purple-600 dark:hover:bg-purple-700 text-white font-medium rounded-lg transition-colors flex items-center justify-center space-x-2"
|
|
||||||
data-rybbit-event="export-json"
|
|
||||||
>
|
|
||||||
<i class="fas fa-file-code"></i>
|
|
||||||
<span>Export as JSON</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button @click="openGifFpsModal" class="w-full sm:w-auto px-6 py-3 sm:py-2.5 bg-amber-500 hover:bg-amber-600 dark:bg-amber-600 dark:hover:bg-amber-700 text-white font-medium rounded-lg transition-colors flex items-center justify-center space-x-2" data-rybbit-event="download-gif">
|
|
||||||
<i class="fas fa-film"></i>
|
|
||||||
<span>Download as GIF</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button @click="downloadAsZip" class="w-full sm:w-auto px-6 py-3 sm:py-2.5 bg-teal-500 hover:bg-teal-600 dark:bg-teal-600 dark:hover:bg-teal-700 text-white font-medium rounded-lg transition-colors flex items-center justify-center space-x-2" data-rybbit-event="download-zip">
|
|
||||||
<i class="fas fa-file-archive"></i>
|
|
||||||
<span>Download as ZIP</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button @click="openPreviewModal" class="w-full sm:w-auto px-6 py-3 sm:py-2.5 bg-green-500 hover:bg-green-600 dark:bg-green-600 dark:hover:bg-green-700 text-white font-medium rounded-lg transition-colors flex items-center justify-center space-x-2" data-rybbit-event="preview-animation">
|
|
||||||
<i class="fas fa-play"></i>
|
|
||||||
<span>Preview animation</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<sprite-canvas
|
|
||||||
:layers="layers"
|
|
||||||
:active-layer-id="activeLayerId"
|
|
||||||
:columns="columns"
|
|
||||||
@update-sprite="updateSpritePosition"
|
|
||||||
@update-sprite-cell="updateSpriteCell"
|
|
||||||
@remove-sprite="removeSprite"
|
|
||||||
@replace-sprite="replaceSprite"
|
|
||||||
@add-sprite="addSprite"
|
|
||||||
@add-sprite-with-resize="addSpriteWithResize"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Modal :is-open="isPreviewModalOpen" @close="closePreviewModal" title="Animation preview">
|
|
||||||
<sprite-preview :layers="layers" :active-layer-id="activeLayerId" :columns="columns" @update-sprite="updateSpritePosition" />
|
|
||||||
</Modal>
|
|
||||||
|
|
||||||
<HelpModal :is-open="isHelpModalOpen" @close="closeHelpModal" />
|
<HelpModal :is-open="isHelpModalOpen" @close="closeHelpModal" />
|
||||||
<FeedbackModal :is-open="isFeedbackModalOpen" @close="closeFeedbackModal" />
|
<FeedbackModal :is-open="isFeedbackModalOpen" @close="closeFeedbackModal" />
|
||||||
<SpritesheetSplitter :is-open="isSpritesheetSplitterOpen" :image-url="spritesheetImageUrl" :image-file="spritesheetImageFile" @close="closeSpritesheetSplitter" @split="handleSplitSpritesheet" />
|
<ToastContainer />
|
||||||
<GifFpsModal :is-open="isGifFpsModalOpen" @close="closeGifFpsModal" @confirm="downloadAsGif" :default-fps="10" />
|
|
||||||
|
|
||||||
<!-- One-time feedback popup -->
|
<!-- One-time feedback popup -->
|
||||||
<div v-if="showFeedbackPopup" class="fixed inset-0 backdrop-blur-sm flex items-center justify-center z-50">
|
<div v-if="showFeedbackPopup" class="fixed bottom-6 right-6 z-50 flex items-center justify-center">
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-xl p-6 max-w-md mx-4 shadow-xl border border-gray-600">
|
<div class="max-w-sm p-4 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl shadow-2xl glass-panel relative">
|
||||||
<div class="text-center">
|
<button @click="handleFeedbackPopupResponse(false)" class="absolute top-2 right-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200" title="Close">
|
||||||
<div class="text-4xl mb-4">💬</div>
|
<i class="fas fa-times text-sm"></i>
|
||||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-3">Help us improve!</h3>
|
</button>
|
||||||
<p class="text-gray-600 dark:text-gray-300 mb-6">We'd love to hear your thoughts about the spritesheet generator. Would you like to share your feedback?</p>
|
<div class="flex gap-4">
|
||||||
<div class="flex gap-3 justify-center">
|
<div class="text-3xl">💬</div>
|
||||||
<button @click="handleFeedbackPopupResponse(false)" class="px-4 py-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors">Maybe later</button>
|
<div>
|
||||||
<button @click="handleFeedbackPopupResponse(true)" class="px-6 py-2 bg-blue-500 hover:bg-blue-600 text-white font-medium rounded-lg transition-colors">Share feedback</button>
|
<h3 class="text-sm font-bold text-gray-900 dark:text-gray-100 mb-1">Help us improve!</h3>
|
||||||
|
<p class="text-xs text-gray-600 dark:text-gray-300 mb-3 leading-relaxed">Enjoying Spritesheet Generator? We'd love your feedback.</p>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<button @click="handleFeedbackPopupResponse(true)" class="px-3 py-1.5 text-xs font-medium text-white bg-indigo-600 hover:bg-indigo-700 rounded-lg transition-colors shadow-sm">Share feedback</button>
|
||||||
|
<button @click="handleFeedbackPopupResponse(false)" class="px-3 py-1.5 text-xs font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors">No thanks</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -163,92 +38,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, toRef, computed } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import FileUploader from './components/FileUploader.vue';
|
import { RouterView } from 'vue-router';
|
||||||
import SpriteCanvas from './components/SpriteCanvas.vue';
|
import Navbar from './components/layout/Navbar.vue';
|
||||||
import Modal from './components/utilities/Modal.vue';
|
|
||||||
import SpritePreview from './components/SpritePreview.vue';
|
|
||||||
import HelpModal from './components/HelpModal.vue';
|
import HelpModal from './components/HelpModal.vue';
|
||||||
import FeedbackModal from './components/FeedbackModal.vue';
|
import FeedbackModal from './components/FeedbackModal.vue';
|
||||||
import SpritesheetSplitter from './components/SpritesheetSplitter.vue';
|
import Breadcrumbs from './components/Breadcrumbs.vue';
|
||||||
import GifFpsModal from './components/GifFpsModal.vue';
|
import ToastContainer from './components/utilities/ToastContainer.vue';
|
||||||
import DarkModeToggle from './components/utilities/DarkModeToggle.vue';
|
|
||||||
import { useExportLayers } from './composables/useExportLayers';
|
|
||||||
import { useLayers } from './composables/useLayers';
|
|
||||||
import { getMaxDimensionsAcrossLayers } from './composables/useLayers';
|
|
||||||
import { useSettingsStore } from './stores/useSettingsStore';
|
|
||||||
import { calculateNegativeSpacing } from './composables/useNegativeSpacing';
|
|
||||||
import type { SpriteFile } from './types/sprites';
|
|
||||||
|
|
||||||
const settingsStore = useSettingsStore();
|
|
||||||
const { layers, visibleLayers, activeLayer, activeLayerId, columns, updateSpritePosition, updateSpriteCell, removeSprite, replaceSprite, addSprite, addSpriteWithResize, processImageFiles, alignSprites, addLayer, removeLayer, moveLayer } = useLayers();
|
|
||||||
|
|
||||||
const { downloadSpritesheet, exportSpritesheetJSON, importSpritesheetJSON, downloadAsGif, downloadAsZip } = useExportLayers(layers, columns, toRef(settingsStore, 'negativeSpacingEnabled'), activeLayerId, toRef(settingsStore, 'backgroundColor'));
|
|
||||||
|
|
||||||
const cellSize = computed(() => {
|
|
||||||
if (!layers.value.length) return { width: 0, height: 0 };
|
|
||||||
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers.value);
|
|
||||||
const allSprites = visibleLayers.value.flatMap(l => l.sprites);
|
|
||||||
const negativeSpacing = calculateNegativeSpacing(allSprites, settingsStore.negativeSpacingEnabled);
|
|
||||||
return { width: maxWidth + negativeSpacing, height: maxHeight + negativeSpacing };
|
|
||||||
});
|
|
||||||
const isPreviewModalOpen = ref(false);
|
|
||||||
const isHelpModalOpen = ref(false);
|
const isHelpModalOpen = ref(false);
|
||||||
const isFeedbackModalOpen = ref(false);
|
const isFeedbackModalOpen = ref(false);
|
||||||
const isSpritesheetSplitterOpen = ref(false);
|
|
||||||
const isGifFpsModalOpen = ref(false);
|
|
||||||
const jsonFileInput = ref<HTMLInputElement | null>(null);
|
|
||||||
const spritesheetImageUrl = ref('');
|
|
||||||
const spritesheetImageFile = ref<File | null>(null);
|
|
||||||
const showFeedbackPopup = ref(false);
|
const showFeedbackPopup = ref(false);
|
||||||
|
|
||||||
const handleSpritesUpload = async (files: File[]) => {
|
|
||||||
const jsonFile = files.find(file => file.type === 'application/json' || file.name.endsWith('.json'));
|
|
||||||
|
|
||||||
if (jsonFile) {
|
|
||||||
try {
|
|
||||||
await importSpritesheetJSON(jsonFile);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error importing JSON:', error);
|
|
||||||
alert('Failed to import JSON file. Please check the file format.');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (files.length === 1 && files[0].type.startsWith('image/')) {
|
|
||||||
const file = files[0];
|
|
||||||
const url = URL.createObjectURL(file);
|
|
||||||
|
|
||||||
const img = new Image();
|
|
||||||
img.onload = () => {
|
|
||||||
if (confirm('This looks like it might be a spritesheet. Would you like to split it into individual sprites?')) {
|
|
||||||
spritesheetImageUrl.value = url;
|
|
||||||
spritesheetImageFile.value = file;
|
|
||||||
isSpritesheetSplitterOpen.value = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
processImageFiles([file]);
|
|
||||||
};
|
|
||||||
img.src = url;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
processImageFiles(files);
|
|
||||||
};
|
|
||||||
|
|
||||||
const openPreviewModal = () => {
|
|
||||||
if (!visibleLayers.value.some(l => l.sprites.length > 0)) {
|
|
||||||
alert('Please upload or import sprites to preview an animation.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
isPreviewModalOpen.value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const closePreviewModal = () => {
|
|
||||||
isPreviewModalOpen.value = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const openHelpModal = () => {
|
const openHelpModal = () => {
|
||||||
isHelpModalOpen.value = true;
|
isHelpModalOpen.value = true;
|
||||||
};
|
};
|
||||||
@@ -265,55 +66,12 @@
|
|||||||
isFeedbackModalOpen.value = false;
|
isFeedbackModalOpen.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeSpritesheetSplitter = () => {
|
|
||||||
isSpritesheetSplitterOpen.value = false;
|
|
||||||
if (spritesheetImageUrl.value) {
|
|
||||||
URL.revokeObjectURL(spritesheetImageUrl.value);
|
|
||||||
spritesheetImageUrl.value = '';
|
|
||||||
}
|
|
||||||
spritesheetImageFile.value = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const openGifFpsModal = () => {
|
|
||||||
if (!visibleLayers.value.some(l => l.sprites.length > 0)) {
|
|
||||||
alert('Please upload or import sprites before generating a GIF.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
isGifFpsModalOpen.value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const closeGifFpsModal = () => {
|
|
||||||
isGifFpsModalOpen.value = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSplitSpritesheet = (spriteFiles: SpriteFile[]) => {
|
|
||||||
processImageFiles(spriteFiles.map(s => s.file));
|
|
||||||
};
|
|
||||||
|
|
||||||
const openJSONImportDialog = () => {
|
|
||||||
jsonFileInput.value?.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleJSONFileChange = async (event: Event) => {
|
|
||||||
const input = event.target as HTMLInputElement;
|
|
||||||
if (input.files && input.files.length > 0) {
|
|
||||||
const jsonFile = input.files[0];
|
|
||||||
try {
|
|
||||||
await importSpritesheetJSON(jsonFile);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error importing JSON:', error);
|
|
||||||
alert('Failed to import JSON file. Please check the file format.');
|
|
||||||
}
|
|
||||||
if (jsonFileInput.value) jsonFileInput.value.value = '';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const hasShownFeedbackPopup = localStorage.getItem('hasShownFeedbackPopup');
|
const hasShownFeedbackPopup = localStorage.getItem('hasShownFeedbackPopup');
|
||||||
if (!hasShownFeedbackPopup) {
|
if (!hasShownFeedbackPopup) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showFeedbackPopup.value = true;
|
showFeedbackPopup.value = true;
|
||||||
}, 3000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
BIN
src/assets/demo.mp4
Normal file
BIN
src/assets/demo.mp4
Normal file
Binary file not shown.
@@ -1,25 +1,23 @@
|
|||||||
@import 'tailwindcss';
|
@import 'tailwindcss';
|
||||||
|
|
||||||
|
/* Tailwind v4: Use .dark class for dark mode instead of prefers-color-scheme */
|
||||||
@custom-variant dark (&:where(.dark, .dark *));
|
@custom-variant dark (&:where(.dark, .dark *));
|
||||||
|
|
||||||
/* Dark mode transition */
|
/* Global Resets & Transitions */
|
||||||
html,
|
html {
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
transition:
|
@apply bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-100 antialiased font-sans;
|
||||||
background-color 0.3s ease,
|
min-height: 100vh;
|
||||||
color 0.3s ease;
|
|
||||||
-webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html.theme-transition * {
|
html.theme-transition * {
|
||||||
transition: none !important;
|
transition: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Additional dark mode styles */
|
|
||||||
body.dark-mode {
|
|
||||||
background-color: #111827;
|
|
||||||
color: #e5e7eb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Force dark mode styles */
|
/* Force dark mode styles */
|
||||||
html.dark {
|
html.dark {
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
@@ -30,10 +28,130 @@ html.dark {
|
|||||||
input,
|
input,
|
||||||
select,
|
select,
|
||||||
button {
|
button {
|
||||||
font-size: 16px !important; /* Prevent iOS zoom on focus */
|
font-size: 16px !important;
|
||||||
|
}
|
||||||
|
.touch-manipulation {
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.touch-manipulation {
|
/* Global Button Styles */
|
||||||
touch-action: manipulation; /* Improve touch responsiveness */
|
button,
|
||||||
|
[type='button'],
|
||||||
|
[type='reset'],
|
||||||
|
[type='submit'] {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:disabled,
|
||||||
|
[type='button']:disabled,
|
||||||
|
[type='reset']:disabled,
|
||||||
|
[type='submit']:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Premium Utilities */
|
||||||
|
@layer utilities {
|
||||||
|
.glass {
|
||||||
|
@apply bg-white/70 dark:bg-gray-900/70 backdrop-blur-md border border-white/20 dark:border-gray-800/50;
|
||||||
|
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-panel {
|
||||||
|
@apply bg-white/80 dark:bg-gray-900/80 backdrop-blur-lg border border-gray-200/50 dark:border-gray-700/50;
|
||||||
|
box-shadow:
|
||||||
|
0 2px 15px -3px rgba(0, 0, 0, 0.07),
|
||||||
|
0 10px 20px -2px rgba(0, 0, 0, 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Custom Scrollbar */
|
||||||
|
.scrollbar-thin {
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
@apply bg-transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
@apply bg-gray-300 dark:bg-gray-700 rounded-full transition-colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
@apply bg-gray-400 dark:bg-gray-600;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@layer components {
|
||||||
|
/* Buttons */
|
||||||
|
.btn {
|
||||||
|
@apply inline-flex items-center justify-center gap-2 px-4 py-2 text-sm rounded-lg transition-all duration-200 cursor-pointer font-medium
|
||||||
|
focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed active:scale-[0.98];
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
@apply bg-gray-900 text-white hover:bg-black shadow-lg shadow-gray-900/20
|
||||||
|
dark:bg-gray-100 dark:text-gray-950 dark:hover:bg-white dark:shadow-gray-100/10 border border-transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
@apply bg-white text-gray-700 border border-gray-200 hover:bg-gray-50 hover:border-gray-300 shadow-sm
|
||||||
|
dark:bg-gray-800 dark:text-gray-200 dark:border-gray-700 dark:hover:bg-gray-700/80 dark:hover:border-gray-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-ghost {
|
||||||
|
@apply text-gray-600 hover:bg-gray-100/80 hover:text-gray-900
|
||||||
|
dark:text-gray-400 dark:hover:bg-gray-800/50 dark:hover:text-gray-200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-danger {
|
||||||
|
@apply text-red-600 hover:bg-red-50 hover:text-red-700
|
||||||
|
dark:text-red-400 dark:hover:bg-red-900/20 dark:hover:text-red-300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-sm {
|
||||||
|
@apply px-3 py-1.5 text-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-md {
|
||||||
|
@apply px-4 py-2 text-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-icon {
|
||||||
|
@apply p-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-field {
|
||||||
|
@apply px-3 py-2 text-sm bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-700
|
||||||
|
rounded-lg outline-none transition-shadow focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500
|
||||||
|
placeholder:text-gray-400 dark:placeholder:text-gray-500 dark:text-gray-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
@apply bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700/60 rounded-xl shadow-sm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Typography Overrides (Prose) */
|
||||||
|
.prose {
|
||||||
|
@apply text-gray-600 dark:text-gray-300 max-w-none;
|
||||||
|
}
|
||||||
|
.prose h1,
|
||||||
|
.prose h2,
|
||||||
|
.prose h3 {
|
||||||
|
@apply text-gray-900 dark:text-gray-50 font-bold tracking-tight;
|
||||||
|
}
|
||||||
|
.prose a {
|
||||||
|
@apply text-indigo-600 dark:text-indigo-400 no-underline hover:underline font-medium;
|
||||||
|
}
|
||||||
|
.prose code {
|
||||||
|
@apply bg-gray-100 dark:bg-gray-800 rounded px-1.5 py-0.5 text-sm text-indigo-600 dark:text-indigo-300 font-mono font-medium before:content-[''] after:content-[''];
|
||||||
|
}
|
||||||
|
.prose pre {
|
||||||
|
@apply bg-gray-900 dark:bg-gray-950/50 border border-gray-200 dark:border-gray-800 rounded-xl shadow-lg;
|
||||||
|
}
|
||||||
|
|||||||
23
src/blog/welcome.md
Normal file
23
src/blog/welcome.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
title: 'Welcome to the Spritesheet generator blog'
|
||||||
|
date: '2025-11-26'
|
||||||
|
description: 'This is the first post on our new blog. Learn about how we built this tool.'
|
||||||
|
image: '/blog/1.png'
|
||||||
|
---
|
||||||
|
|
||||||
|
## Welcome!
|
||||||
|
|
||||||
|
We are excited to launch our new blog. Here we will share updates, tutorials, and tips on how to get the most out of the Sprite Sheet Generator.
|
||||||
|
|
||||||
|
### What is this tool?
|
||||||
|
|
||||||
|
This tool allows you to easily combine multiple images into a single sprite sheet. It's perfect for game developers and web designers.
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- Drag and drop interface
|
||||||
|
- Customizable grid size
|
||||||
|
- Export to PNG and JSON
|
||||||
|
- Dark mode support
|
||||||
|
|
||||||
|
Stay tuned for more updates!
|
||||||
97
src/blog/why-pixel-art.md
Normal file
97
src/blog/why-pixel-art.md
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
---
|
||||||
|
title: 'Why pixel art without proper spritesheet tools is holding you back'
|
||||||
|
date: '2025-11-26'
|
||||||
|
description: 'Pixel art is already challenging. Why make it harder?'
|
||||||
|
image: '/blog/2.jpg'
|
||||||
|
---
|
||||||
|
|
||||||
|
If you've worked on game projects with pixel art, you know the pain: managing dozens of individual sprite files, keeping track of animation frames, and organizing everything into a format your game engine can use. It's tedious, error-prone, and kills your creative flow.
|
||||||
|
|
||||||
|
## The pixel art workflow nightmare
|
||||||
|
|
||||||
|
### The zoom dance problem
|
||||||
|
|
||||||
|
Pixel artists constantly switch between magnified and unmagnified views. At 500% zoom, you place individual pixels. At 100%, you check if they create the intended effect. You need to see both the micro details and the macro picture—but you can't do both at once.
|
||||||
|
|
||||||
|
This back-and-forth is exhausting, especially when you discover a single shade-too-dark pixel throws off your entire composition.
|
||||||
|
|
||||||
|
### File management chaos
|
||||||
|
|
||||||
|
Creating a character with idle, walking, running, jumping, and attacking animations? Each with 8-12 frames? That's 40-60+ individual image files for one character.
|
||||||
|
|
||||||
|
Managing these manually means:
|
||||||
|
|
||||||
|
- Tracking which file belongs to which animation
|
||||||
|
- Ensuring consistent sizing across all frames
|
||||||
|
- Organizing files in the right sequence
|
||||||
|
- Exporting each frame separately
|
||||||
|
- Hoping you didn't skip or misname anything
|
||||||
|
|
||||||
|
### The multi-tool trap
|
||||||
|
|
||||||
|
Many developers juggle multiple applications:
|
||||||
|
|
||||||
|
1. Sketch in a drawing program
|
||||||
|
2. Refine in a pixel art editor
|
||||||
|
3. Export individual frames
|
||||||
|
4. Resize in an image editor
|
||||||
|
5. Manually arrange in another tool
|
||||||
|
6. Export as a spritesheet
|
||||||
|
7. Create data files for your game engine
|
||||||
|
8. Find an error in frame 23
|
||||||
|
9. Start over
|
||||||
|
|
||||||
|
One developer described the frustration: the feedback loop was too long. They couldn't see what the finished art would look like until after going through multiple tools. Details that looked great in high-res turned sloppy after conversion.
|
||||||
|
|
||||||
|
## Why spritesheets matter
|
||||||
|
|
||||||
|
Sprite sheets aren't optional—they're essential for game development:
|
||||||
|
|
||||||
|
- **Better performance**: One file instead of 50+ individual image requests
|
||||||
|
- **Simpler management**: One file instead of dozens
|
||||||
|
- **Proper animation**: Frame data embedded or easily referenced
|
||||||
|
- **Optimized memory**: Better texture packing, less wasted space
|
||||||
|
|
||||||
|
But creating them manually is painful. You need to calculate optimal layouts, ensure consistent spacing, maintain pixel-perfect alignment, and generate metadata. One mistake breaks your animations.
|
||||||
|
|
||||||
|
## The solution: dedicated spritesheet generators
|
||||||
|
|
||||||
|
This is where [spritesheetgenerator.online](https://spritesheetgenerator.online) changes everything.
|
||||||
|
|
||||||
|
Instead of the multi-tool nightmare, you get:
|
||||||
|
|
||||||
|
1. **Upload sprites**: Drag and drop your images
|
||||||
|
2. **Automatic arrangement**: Intelligent optimal layout
|
||||||
|
3. **Preview animations**: See your work in real-time
|
||||||
|
4. **Export everything**: Spritesheet image and data files ready to use
|
||||||
|
|
||||||
|
### Why this matters
|
||||||
|
|
||||||
|
**Faster iteration**: Change frame 7? Re-upload and regenerate in seconds instead of minutes.
|
||||||
|
|
||||||
|
**Consistent results**: No more alignment worries. The tool handles technical details.
|
||||||
|
|
||||||
|
**Immediate preview**: See frames flow together, check light-blending in motion, verify timing—all before exporting.
|
||||||
|
|
||||||
|
**Professional output**: Properly formatted spritesheets that drop right into your game engine.
|
||||||
|
|
||||||
|
### Free and accessible
|
||||||
|
|
||||||
|
Being browser-based means:
|
||||||
|
|
||||||
|
- No installation required
|
||||||
|
- Works on any device
|
||||||
|
- No subscriptions or licenses
|
||||||
|
- Access from anywhere
|
||||||
|
|
||||||
|
For indie developers, hobbyists, or students with limited budgets, this is game-changing.
|
||||||
|
|
||||||
|
## The bottom line
|
||||||
|
|
||||||
|
Pixel art requires precision and patience. That's part of what makes it rewarding. But there's no reason to add unnecessary complexity with manual file management and multi-tool workflows.
|
||||||
|
|
||||||
|
Your creative energy should go into placing pixels with intention and crafting smooth animations—not file wrangling.
|
||||||
|
|
||||||
|
Using a proper spritesheet generator doesn't make you less of an artist. It makes you a smarter one.
|
||||||
|
|
||||||
|
The pixel art is hard enough. The workflow doesn't have to be.
|
||||||
63
src/components/Breadcrumbs.vue
Normal file
63
src/components/Breadcrumbs.vue
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
import { RouterLink } from 'vue-router';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
|
interface BreadcrumbItem {
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const breadcrumbs = computed<BreadcrumbItem[]>(() => {
|
||||||
|
const items: BreadcrumbItem[] = [{ name: 'Home', path: '/' }];
|
||||||
|
|
||||||
|
// Map route names to breadcrumb labels
|
||||||
|
const routeLabels: Record<string, string> = {
|
||||||
|
'blog-overview': 'Blog',
|
||||||
|
'blog-detail': 'Blog',
|
||||||
|
about: 'About Us',
|
||||||
|
contact: 'Contact',
|
||||||
|
'privacy-policy': 'Privacy Policy',
|
||||||
|
faq: 'FAQ',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (route.name && route.name !== 'home') {
|
||||||
|
const routeName = route.name.toString();
|
||||||
|
|
||||||
|
if (routeName === 'blog-detail') {
|
||||||
|
// For blog detail pages, add Blog first, then the post title
|
||||||
|
items.push({ name: 'Blog', path: '/blog' });
|
||||||
|
|
||||||
|
// Get the post title from route meta or params if available
|
||||||
|
const postTitle = (route.meta.title as string) || 'Article';
|
||||||
|
items.push({ name: postTitle, path: route.path });
|
||||||
|
} else if (routeLabels[routeName]) {
|
||||||
|
items.push({ name: routeLabels[routeName], path: route.path });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
});
|
||||||
|
|
||||||
|
const shouldShowBreadcrumbs = computed(() => {
|
||||||
|
return breadcrumbs.value.length > 1 && route.name !== 'home';
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<nav v-if="shouldShowBreadcrumbs" aria-label="Breadcrumb" class="mb-4">
|
||||||
|
<ol class="flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400">
|
||||||
|
<li v-for="(item, index) in breadcrumbs" :key="item.path" class="flex items-center gap-2">
|
||||||
|
<RouterLink v-if="index < breadcrumbs.length - 1" :to="item.path" class="hover:text-gray-900 dark:hover:text-white transition-colors" :aria-label="`Navigate to ${item.name}`">
|
||||||
|
{{ item.name }}
|
||||||
|
</RouterLink>
|
||||||
|
<span v-else class="font-medium text-gray-900 dark:text-white" aria-current="page">
|
||||||
|
{{ item.name }}
|
||||||
|
</span>
|
||||||
|
<i v-if="index < breadcrumbs.length - 1" class="fas fa-chevron-right text-xs text-gray-400"></i>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</template>
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch('https://pb1.adhd.sh/api/collections/feedback/records', {
|
const res = await fetch(`${import.meta.env.VITE_POCKETBASE_URL}/api/collections/feedback/records`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="border-2 border-dashed rounded-xl p-4 sm:p-8 text-center transition-all duration-200"
|
class="relative border-3 border-dashed rounded-2xl p-8 sm:p-12 text-center cursor-pointer group overflow-hidden"
|
||||||
:class="{
|
:class="{
|
||||||
'border-blue-300 bg-blue-50 dark:border-blue-500 dark:bg-blue-900/30': isDragging,
|
'border-blue-400 bg-blue-50 dark:border-blue-400 dark:bg-blue-900/40': isDragging,
|
||||||
'border-gray-200 hover:border-blue-300 hover:bg-gray-50 dark:border-gray-600 dark:hover:border-blue-500 dark:hover:bg-gray-700/50': !isDragging,
|
'border-gray-300 bg-gray-50/50 hover:border-blue-400 hover:bg-blue-50/80 dark:border-gray-600 dark:bg-gray-800/30 dark:hover:border-blue-400 dark:hover:bg-blue-900/30': !isDragging,
|
||||||
}"
|
}"
|
||||||
@dragenter.prevent="isDragging = true"
|
@dragenter.prevent="isDragging = true"
|
||||||
@dragleave.prevent="isDragging = false"
|
@dragleave.prevent="isDragging = false"
|
||||||
@@ -12,20 +12,36 @@
|
|||||||
@click="openFileDialog"
|
@click="openFileDialog"
|
||||||
data-rybbit-event="file-upload-area"
|
data-rybbit-event="file-upload-area"
|
||||||
>
|
>
|
||||||
|
<div class="absolute inset-0 bg-blue-400/0 group-hover:bg-blue-400/5"></div>
|
||||||
|
|
||||||
<input ref="fileInput" type="file" multiple accept="image/*,.json" class="hidden" @change="handleFileChange" />
|
<input ref="fileInput" type="file" multiple accept="image/*,.json" class="hidden" @change="handleFileChange" />
|
||||||
|
|
||||||
<div class="mb-4 sm:mb-6">
|
<div class="relative z-10">
|
||||||
<img src="@/assets/images/file.svg" alt="File upload" class="w-16 h-16 sm:w-20 sm:h-20 mx-auto mb-2 sm:mb-4 opacity-75 dark:invert" />
|
<div class="mb-6" :class="isDragging ? 'scale-110' : ''">
|
||||||
|
<div class="w-20 h-20 sm:w-24 sm:h-24 mx-auto mb-4 bg-blue-100 dark:bg-blue-900/50 rounded-2xl flex items-center justify-center shadow-lg">
|
||||||
|
<i class="fas fa-cloud-upload-alt text-4xl sm:text-5xl text-blue-600 dark:text-blue-400"></i>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="text-lg sm:text-xl font-medium text-gray-700 dark:text-gray-200 mb-2">Drag and drop your sprite images or JSON file here</p>
|
<span class="text-xl sm:text-2xl font-bold text-gray-800 dark:text-gray-100">
|
||||||
<p class="text-sm text-gray-500 dark:text-gray-400 mb-4 sm:mb-6">or</p>
|
<span v-if="isDragging">Drop your files here</span>
|
||||||
|
<span v-else>Upload your sprites</span>
|
||||||
|
</span>
|
||||||
|
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 mb-2">Drag and drop sprite images or JSON files</p>
|
||||||
|
<p class="text-sm text-gray-500 dark:text-gray-400 mb-8">Supports PNG, JPG, GIF, and JSON</p>
|
||||||
|
|
||||||
<button class="w-full sm:w-auto px-6 py-3 sm:py-2.5 bg-blue-500 hover:bg-blue-600 text-white font-medium rounded-lg transition-colors flex sm:inline-flex items-center justify-center space-x-2 cursor-pointer" data-rybbit-event="select-files">
|
<div class="flex items-center justify-center gap-4 mb-6">
|
||||||
<i class="fas fa-folder-open"></i>
|
<div class="h-px flex-1 bg-gray-300 dark:bg-gray-600"></div>
|
||||||
<span>Select files</span>
|
<span class="text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase">or</span>
|
||||||
|
<div class="h-px flex-1 bg-gray-300 dark:bg-gray-600"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="px-8 py-3.5 bg-blue-500 hover:bg-blue-600 dark:bg-blue-600 dark:hover:bg-blue-700 text-white font-semibold rounded-xl shadow-lg hover:shadow-xl flex items-center justify-center gap-3 mx-auto" data-rybbit-event="select-files">
|
||||||
|
<i class="fas fa-folder-open text-lg"></i>
|
||||||
|
<span>Browse files</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<div class="max-w-none text-gray-700 dark:text-gray-300">
|
<div class="max-w-none text-gray-700 dark:text-gray-300">
|
||||||
<p class="mb-4 text-base leading-relaxed">Spritesheet generator is a free, open-source tool for creating spritesheets for game development and animation projects. This tool allows you to upload individual sprite images and arrange them into a spritesheet with customizable layout.</p>
|
<p class="mb-4 text-base leading-relaxed">Spritesheet generator is a free, open-source tool for creating spritesheets for game development and animation projects. This tool allows you to upload individual sprite images and arrange them into a spritesheet with customizable layout.</p>
|
||||||
<p class="mb-4 text-base leading-relaxed">Matrix: root@adhd.sh, Discord: nu11ed</p>
|
<p class="mb-4 text-base leading-relaxed">Matrix: root@adhd.sh, Discord: streetshadow</p>
|
||||||
<h4 class="mt-6 mb-3 text-lg font-medium text-gray-900 dark:text-gray-100">How to use:</h4>
|
<h4 class="mt-6 mb-3 text-lg font-medium text-gray-900 dark:text-gray-100">How to use:</h4>
|
||||||
<ol class="list-decimal pl-6 space-y-2 mb-4">
|
<ol class="list-decimal pl-6 space-y-2 mb-4">
|
||||||
<li>Upload your sprite images by dragging and dropping them or clicking the upload area</li>
|
<li>Upload your sprite images by dragging and dropping them or clicking the upload area</li>
|
||||||
@@ -56,6 +56,16 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
|
<!-- Ko-fi -->
|
||||||
|
<div class="p-4 bg-gray-50 dark:bg-gray-700 rounded-lg border border-gray-200 dark:border-gray-600">
|
||||||
|
<div class="flex items-center mb-3">
|
||||||
|
<h4 class="text-md font-medium">Ko-fi</h4>
|
||||||
|
</div>
|
||||||
|
<a href="https://ko-fi.com/X8X416D44P" target="_blank" rel="noopener noreferrer" data-rybbit-event="open-kofi">
|
||||||
|
<img height="36" style="border: 0px; height: 36px" src="https://storage.ko-fi.com/cdn/kofi6.png?v=6" alt="Buy Me a Coffee at ko-fi.com" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- PayPal -->
|
<!-- PayPal -->
|
||||||
<div class="p-4 bg-gray-50 dark:bg-gray-700 rounded-lg border border-gray-200 dark:border-gray-600">
|
<div class="p-4 bg-gray-50 dark:bg-gray-700 rounded-lg border border-gray-200 dark:border-gray-600">
|
||||||
<div class="flex items-center mb-3">
|
<div class="flex items-center mb-3">
|
||||||
|
|||||||
119
src/components/ShareModal.vue
Normal file
119
src/components/ShareModal.vue
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<template>
|
||||||
|
<Modal :is-open="isOpen" @close="close" title="Share spritesheet" :initialWidth="500" :initialHeight="280">
|
||||||
|
<div class="h-full flex flex-col">
|
||||||
|
<div class="flex-1 overflow-auto p-4 space-y-4 dark:bg-gray-800">
|
||||||
|
<!-- Loading state -->
|
||||||
|
<div v-if="loading" class="flex flex-col items-center justify-center py-8">
|
||||||
|
<i class="fas fa-circle-notch fa-spin text-3xl text-gray-400 dark:text-gray-500 mb-3"></i>
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-300">Uploading spritesheet...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Success state -->
|
||||||
|
<div v-else-if="shareUrl" class="space-y-4">
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-300">Your spritesheet is ready to share! Copy the link below:</p>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<input type="text" :value="shareUrl" readonly class="flex-1 px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 text-sm font-mono" @focus="($event.target as HTMLInputElement).select()" />
|
||||||
|
<button @click="copyToClipboard" class="px-4 py-2 rounded-lg bg-blue-500 hover:bg-blue-600 text-white text-sm font-medium transition-colors" :title="copied ? 'Copied!' : 'Copy to clipboard'">
|
||||||
|
<i :class="copied ? 'fas fa-check' : 'fas fa-copy'"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="copied" class="text-sm text-green-600 dark:text-green-400">Link copied to clipboard!</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error state -->
|
||||||
|
<div v-else-if="error" class="space-y-4">
|
||||||
|
<p class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||||
|
<button @click="retry" class="px-4 py-2 rounded-lg bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-100 text-sm font-medium transition-colors"><i class="fas fa-redo mr-2"></i>Try again</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Initial state (shouldn't normally be visible) -->
|
||||||
|
<div v-else class="flex flex-col items-center justify-center py-8">
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-300">Preparing to share...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="border-t border-gray-200 dark:border-gray-700 p-3 flex justify-end">
|
||||||
|
<button type="button" class="px-4 py-2 rounded-lg bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-100" @click="close">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
import Modal from './utilities/Modal.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
isOpen: boolean;
|
||||||
|
shareFunction: () => Promise<{ id: string; url: string }>;
|
||||||
|
}>();
|
||||||
|
const emit = defineEmits<{ (e: 'close'): void }>();
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const shareUrl = ref('');
|
||||||
|
const error = ref('');
|
||||||
|
const copied = ref(false);
|
||||||
|
|
||||||
|
const close = () => emit('close');
|
||||||
|
|
||||||
|
const performShare = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
error.value = '';
|
||||||
|
shareUrl.value = '';
|
||||||
|
copied.value = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await props.shareFunction();
|
||||||
|
shareUrl.value = result.url;
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error('Failed to share spritesheet:', e);
|
||||||
|
error.value = 'Failed to share spritesheet. Please try again later.';
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const retry = () => {
|
||||||
|
performShare();
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyToClipboard = async () => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(shareUrl.value);
|
||||||
|
copied.value = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
copied.value = false;
|
||||||
|
}, 2000);
|
||||||
|
} catch {
|
||||||
|
// Fallback for older browsers
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.value = shareUrl.value;
|
||||||
|
document.body.appendChild(input);
|
||||||
|
input.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(input);
|
||||||
|
copied.value = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
copied.value = false;
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Start sharing when modal opens
|
||||||
|
watch(
|
||||||
|
() => props.isOpen,
|
||||||
|
isOpen => {
|
||||||
|
if (isOpen) {
|
||||||
|
performShare();
|
||||||
|
} else {
|
||||||
|
// Reset state when closing
|
||||||
|
loading.value = false;
|
||||||
|
shareUrl.value = '';
|
||||||
|
error.value = '';
|
||||||
|
copied.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
@@ -1,60 +1,54 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="p-2 bg-cyan-600 rounded w-full my-4">
|
<Teleport to="body">
|
||||||
<p>Developer's tip: Right click a sprite to open the context menu and add, replace or remove sprites.</p>
|
<div v-if="showContextMenu" @click.stop class="fixed bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-xl z-50 py-1 min-w-[160px] overflow-hidden" :style="{ left: contextMenuX + 'px', top: contextMenuY + 'px' }">
|
||||||
</div>
|
<button @click="addSprite" class="w-full px-3 py-1.5 text-left hover:bg-blue-50 dark:hover:bg-blue-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
<div class="space-y-4">
|
<i class="fas fa-plus text-blue-600 dark:text-blue-400 text-xs w-4"></i>
|
||||||
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 sm:gap-0">
|
<span>Add sprite</span>
|
||||||
<div class="flex flex-col sm:flex-row items-start sm:items-center gap-3 sm:gap-4 w-full sm:w-auto">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<input id="pixel-perfect" type="checkbox" v-model="settingsStore.pixelPerfect" class="mr-2 w-4 h-4" @change="requestDraw" />
|
|
||||||
<label for="pixel-perfect" class="dark:text-gray-200 text-sm sm:text-base">Pixel perfect rendering</label>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center">
|
|
||||||
<input id="allow-cell-swap" type="checkbox" v-model="allowCellSwap" class="mr-2 w-4 h-4" />
|
|
||||||
<label for="allow-cell-swap" class="dark:text-gray-200 text-sm sm:text-base">Allow moving between cells</label>
|
|
||||||
</div>
|
|
||||||
<!-- Add new checkbox for showing all sprites -->
|
|
||||||
<div class="flex items-center">
|
|
||||||
<input id="show-all-sprites" type="checkbox" v-model="showAllSprites" class="mr-2" />
|
|
||||||
<label for="show-all-sprites" class="dark:text-gray-200">Compare sprites</label>
|
|
||||||
</div>
|
|
||||||
<!-- Negative spacing control -->
|
|
||||||
<div class="flex items-center">
|
|
||||||
<input id="negative-spacing" type="checkbox" v-model="settingsStore.negativeSpacingEnabled" class="mr-2 w-4 h-4" />
|
|
||||||
<label for="negative-spacing" class="dark:text-gray-200 text-sm sm:text-base">Negative spacing</label>
|
|
||||||
</div>
|
|
||||||
<!-- Background color picker -->
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<label for="bg-color" class="dark:text-gray-200 text-sm sm:text-base">Background:</label>
|
|
||||||
<select id="bg-color" v-model="settingsStore.backgroundColor" class="px-2 py-1 border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 dark:text-gray-200 text-sm">
|
|
||||||
<option value="transparent">Transparent</option>
|
|
||||||
<option value="#ffffff">White</option>
|
|
||||||
<option value="#000000">Black</option>
|
|
||||||
<option value="#f9fafb">Light Gray</option>
|
|
||||||
<option value="custom">Custom...</option>
|
|
||||||
</select>
|
|
||||||
<input v-if="settingsStore.backgroundColor === 'custom'" type="color" v-model="customColor" @input="settingsStore.setBackgroundColor(customColor)" class="w-8 h-8 border border-gray-300 dark:border-gray-600 rounded cursor-pointer" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="relative border border-gray-300 dark:border-gray-600 rounded-lg overflow-auto">
|
|
||||||
<!-- Zoom controls - visible on all screen sizes and positioned outside cells -->
|
|
||||||
<div class="relative flex space-x-2 bg-white/90 dark:bg-gray-800/90 p-2 rounded-lg shadow-md z-20">
|
|
||||||
<button @click="zoomIn" class="p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors">
|
|
||||||
<i class="fas fa-plus"></i>
|
|
||||||
</button>
|
</button>
|
||||||
<button @click="zoomOut" class="p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors">
|
<button v-if="contextMenuSpriteId" @click="rotateSpriteInMenu(90)" class="w-full px-3 py-1.5 text-left hover:bg-green-50 dark:hover:bg-green-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
<i class="fas fa-minus"></i>
|
<i class="fas fa-redo text-green-600 dark:text-green-400 text-xs w-4"></i>
|
||||||
|
<span>Rotate +90°</span>
|
||||||
</button>
|
</button>
|
||||||
<button @click="resetZoom" class="p-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-100 rounded-lg transition-colors">
|
<button v-if="contextMenuSpriteId" @click="flipSpriteInMenu('horizontal')" class="w-full px-3 py-1.5 text-left hover:bg-orange-50 dark:hover:bg-orange-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
<i class="fas fa-expand"></i>
|
<i class="fas fa-arrows-alt-h text-orange-600 dark:text-orange-400 text-xs w-4"></i>
|
||||||
|
<span>Flip horizontal</span>
|
||||||
|
</button>
|
||||||
|
<button v-if="contextMenuSpriteId" @click="flipSpriteInMenu('vertical')" class="w-full px-3 py-1.5 text-left hover:bg-orange-50 dark:hover:bg-orange-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
|
<i class="fas fa-arrows-alt-v text-orange-600 dark:text-orange-400 text-xs w-4"></i>
|
||||||
|
<span>Flip vertical</span>
|
||||||
|
</button>
|
||||||
|
<button v-if="contextMenuSpriteId" @click="replaceSprite" class="w-full px-3 py-1.5 text-left hover:bg-purple-50 dark:hover:bg-purple-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
|
<i class="fas fa-exchange-alt text-purple-600 dark:text-purple-400 text-xs w-4"></i>
|
||||||
|
<span>Replace sprite</span>
|
||||||
|
</button>
|
||||||
|
<button v-if="contextMenuSpriteId" @click="openCopyToFrameModal" class="w-full px-3 py-1.5 text-left hover:bg-cyan-50 dark:hover:bg-cyan-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
|
<i class="fas fa-copy text-cyan-600 dark:text-cyan-400 text-xs w-4"></i>
|
||||||
|
<span>Copy to frame...</span>
|
||||||
|
</button>
|
||||||
|
<div v-if="contextMenuSpriteId" class="h-px bg-gray-200 dark:bg-gray-600 my-1"></div>
|
||||||
|
<button v-if="contextMenuSpriteId" @click="removeSprite" class="w-full px-3 py-1.5 text-left hover:bg-red-50 dark:hover:bg-red-900/30 text-red-600 dark:text-red-400 flex items-center gap-2 transition-colors text-sm">
|
||||||
|
<i class="fas fa-trash text-xs w-4"></i>
|
||||||
|
<span>{{ selectedSpriteIds.size > 1 ? `Remove ${selectedSpriteIds.size} sprites` : 'Remove sprite' }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="canvas-container touch-manipulation relative" :style="{ transform: `scale(${zoom})`, transformOrigin: 'top left' }">
|
<!-- Copy to Frame Modal -->
|
||||||
<canvas
|
<CopyToFrameModal :is-open="showCopyToFrameModal" :layers="props.layers" :initial-layer-id="copyTargetLayerId" @close="closeCopyToFrameModal" @copy="confirmCopyToFrame" />
|
||||||
ref="canvasRef"
|
</Teleport>
|
||||||
|
|
||||||
|
<div class="h-full w-full flex flex-col">
|
||||||
|
<div class="relative bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm overflow-auto h-full w-full">
|
||||||
|
<div class="canvas-container touch-manipulation relative inline-block min-w-full">
|
||||||
|
<div
|
||||||
|
ref="gridContainerRef"
|
||||||
|
:style="{
|
||||||
|
transform: `scale(${props.zoom})`,
|
||||||
|
transformOrigin: 'top left',
|
||||||
|
width: `${gridDimensions.width}px`,
|
||||||
|
height: `${gridDimensions.height}px`,
|
||||||
|
position: 'relative',
|
||||||
|
}"
|
||||||
|
class="inline-block"
|
||||||
@mousedown="startDrag"
|
@mousedown="startDrag"
|
||||||
@mousemove="drag"
|
@mousemove="drag"
|
||||||
@mouseup="stopDrag"
|
@mouseup="stopDrag"
|
||||||
@@ -67,20 +61,119 @@
|
|||||||
@dragenter="handleDragEnter"
|
@dragenter="handleDragEnter"
|
||||||
@dragleave="onDragLeave"
|
@dragleave="onDragLeave"
|
||||||
@drop="handleDrop"
|
@drop="handleDrop"
|
||||||
class="w-full transition-all"
|
|
||||||
:class="{ 'ring-4 ring-blue-500 ring-opacity-50': isDragOver }"
|
:class="{ 'ring-4 ring-blue-500 ring-opacity-50': isDragOver }"
|
||||||
:style="settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}"
|
>
|
||||||
></canvas>
|
<!-- Grid cells -->
|
||||||
|
|
||||||
<!-- Offset labels in corners -->
|
|
||||||
<div v-if="canvasRef" class="absolute inset-0 pointer-events-none">
|
|
||||||
<div
|
<div
|
||||||
v-for="position in spritePositions"
|
v-for="cellIndex in totalCells"
|
||||||
:key="position.id"
|
:key="`cell-${cellIndex - 1}`"
|
||||||
class="absolute text-[23px] leading-none font-mono text-cyan-600 dark:text-cyan-400 bg-white/90 dark:bg-gray-900/90 px-1 py-0.5 rounded-sm"
|
class="absolute"
|
||||||
:style="{
|
:style="{
|
||||||
left: `calc(${(position.cellX / canvasRef.width) * 100}% + ${(position.maxWidth / canvasRef.width) * 100}% - 2px)`,
|
left: `${Math.round(getCellPosition(cellIndex - 1).x)}px`,
|
||||||
top: `calc(${(position.cellY / canvasRef.height) * 100}% + ${(position.maxHeight / canvasRef.height) * 100}% - 2px)`,
|
top: `${Math.round(getCellPosition(cellIndex - 1).y)}px`,
|
||||||
|
width: `${Math.round(gridMetrics.maxWidth)}px`,
|
||||||
|
height: `${Math.round(gridMetrics.maxHeight)}px`,
|
||||||
|
backgroundColor: getCellBackground(),
|
||||||
|
backgroundImage: getCellBackgroundImage(),
|
||||||
|
backgroundSize: getCellBackgroundSize(),
|
||||||
|
backgroundPosition: getCellBackgroundPosition(),
|
||||||
|
border: `1px solid ${settingsStore.darkMode ? '#4b5563' : '#e5e7eb'}`,
|
||||||
|
}"
|
||||||
|
:class="{
|
||||||
|
'bg-blue-500 bg-opacity-20': highlightCell && highlightCell.col === (cellIndex - 1) % columns && highlightCell.row === Math.floor((cellIndex - 1) / columns),
|
||||||
|
}"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<!-- Background sprites (for compare mode) -->
|
||||||
|
<template v-if="showAllSprites">
|
||||||
|
<template v-for="layer in visibleLayers" :key="`bg-layer-${layer.id}`">
|
||||||
|
<template v-for="(sprite, spriteIndex) in layer.sprites" :key="`bg-${sprite.id}`">
|
||||||
|
<template v-for="cellIndex in totalCells" :key="`bg-${sprite.id}-${cellIndex}`">
|
||||||
|
<img
|
||||||
|
v-if="spriteIndex !== cellIndex - 1 && !(activeSpriteId === sprite.id && ghostSprite)"
|
||||||
|
:src="sprite.url"
|
||||||
|
class="absolute pointer-events-none"
|
||||||
|
:style="{
|
||||||
|
left: `${Math.round(getCellPosition(cellIndex - 1).x + gridMetrics.negativeSpacing + sprite.x)}px`,
|
||||||
|
top: `${Math.round(getCellPosition(cellIndex - 1).y + gridMetrics.negativeSpacing + sprite.y)}px`,
|
||||||
|
width: `${Math.round(sprite.width)}px`,
|
||||||
|
height: `${Math.round(sprite.height)}px`,
|
||||||
|
opacity: '0.25',
|
||||||
|
imageRendering: settingsStore.pixelPerfect ? 'pixelated' : 'auto',
|
||||||
|
}"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Layer sprites -->
|
||||||
|
<template v-for="layer in layers" :key="layer.id">
|
||||||
|
<template v-if="layer.visible">
|
||||||
|
<template v-for="(sprite, index) in layer.sprites" :key="sprite.id">
|
||||||
|
<img
|
||||||
|
v-if="!(activeSpriteId === sprite.id && ghostSprite)"
|
||||||
|
:src="sprite.url"
|
||||||
|
class="absolute cursor-move transition-transform duration-200"
|
||||||
|
:class="{ 'ring-2 ring-blue-500 ring-offset-1 dark:ring-offset-gray-900': showActiveBorder && selectedSpriteIds.has(sprite.id) }"
|
||||||
|
:style="{
|
||||||
|
left: `${Math.round(getCellPosition(index).x + gridMetrics.negativeSpacing + sprite.x)}px`,
|
||||||
|
top: `${Math.round(getCellPosition(index).y + gridMetrics.negativeSpacing + sprite.y)}px`,
|
||||||
|
width: `${Math.round(sprite.width)}px`,
|
||||||
|
height: `${Math.round(sprite.height)}px`,
|
||||||
|
opacity: layer.id === activeLayerId ? '1' : '0.85',
|
||||||
|
imageRendering: settingsStore.pixelPerfect ? 'pixelated' : 'auto',
|
||||||
|
transform: `rotate(${sprite.rotation}deg) scale(${sprite.flipX ? -1 : 1}, ${sprite.flipY ? -1 : 1})`,
|
||||||
|
}"
|
||||||
|
:data-sprite-id="sprite.id"
|
||||||
|
:data-layer-id="layer.id"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Ghost sprite (while dragging) -->
|
||||||
|
<img
|
||||||
|
v-if="ghostSprite && activeSpriteId"
|
||||||
|
:src="activeSpriteSprite?.url"
|
||||||
|
class="absolute pointer-events-none"
|
||||||
|
:style="{
|
||||||
|
left: `${Math.round(ghostSprite.x)}px`,
|
||||||
|
top: `${Math.round(ghostSprite.y)}px`,
|
||||||
|
width: `${Math.round(activeSpriteSprite?.width || 0)}px`,
|
||||||
|
height: `${Math.round(activeSpriteSprite?.height || 0)}px`,
|
||||||
|
opacity: '0.6',
|
||||||
|
imageRendering: settingsStore.pixelPerfect ? 'pixelated' : 'auto',
|
||||||
|
transform: `rotate(${activeSpriteSprite?.rotation || 0}deg) scale(${activeSpriteSprite?.flipX ? -1 : 1}, ${activeSpriteSprite?.flipY ? -1 : 1})`,
|
||||||
|
}"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Frame IDs -->
|
||||||
|
<div
|
||||||
|
v-if="showFrameIds"
|
||||||
|
v-for="cellIndex in totalCells"
|
||||||
|
:key="`frame-id-${cellIndex}`"
|
||||||
|
class="absolute pointer-events-none font-mono text-[10px] leading-none text-gray-500 dark:text-gray-400 bg-white/80 dark:bg-gray-800/90 px-1.5 py-1 rounded-br-lg border-r border-b border-gray-200 dark:border-gray-600 shadow-sm z-0"
|
||||||
|
:style="{
|
||||||
|
left: `${Math.round(getCellPosition(cellIndex - 1).x)}px`,
|
||||||
|
top: `${Math.round(getCellPosition(cellIndex - 1).y)}px`,
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ cellIndex - 1 }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Offset labels (Coordinates) -->
|
||||||
|
<div
|
||||||
|
v-if="showOffsetLabels"
|
||||||
|
v-for="position in spritePositions"
|
||||||
|
:key="`label-${position.id}`"
|
||||||
|
class="absolute text-[10px] sm:text-xs leading-none font-mono font-medium text-indigo-600 dark:text-indigo-400 bg-white/95 dark:bg-gray-900/95 px-1.5 py-0.5 rounded shadow-sm border border-indigo-200 dark:border-indigo-900 pointer-events-none z-10"
|
||||||
|
:style="{
|
||||||
|
left: `${Math.round(position.cellX + position.maxWidth)}px`,
|
||||||
|
top: `${Math.round(position.cellY + position.maxHeight)}px`,
|
||||||
transform: 'translate(-100%, -100%)',
|
transform: 'translate(-100%, -100%)',
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
@@ -90,35 +183,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Context Menu -->
|
|
||||||
<div v-if="showContextMenu" class="fixed bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg shadow-lg z-50 py-1" :style="{ left: contextMenuX + 'px', top: contextMenuY + 'px' }">
|
|
||||||
<button @click="addSprite" class="w-full px-4 py-2 text-left hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200 flex items-center gap-2">
|
|
||||||
<i class="fas fa-plus"></i>
|
|
||||||
Add sprite
|
|
||||||
</button>
|
|
||||||
<button v-if="contextMenuSpriteId" @click="replaceSprite" class="w-full px-4 py-2 text-left hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200 flex items-center gap-2">
|
|
||||||
<i class="fas fa-exchange-alt"></i>
|
|
||||||
Replace sprite
|
|
||||||
</button>
|
|
||||||
<button v-if="contextMenuSpriteId" @click="removeSprite" class="w-full px-4 py-2 text-left hover:bg-gray-100 dark:hover:bg-gray-700 text-red-600 dark:text-red-400 flex items-center gap-2">
|
|
||||||
<i class="fas fa-trash"></i>
|
|
||||||
Remove sprite
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Hidden file input for replace functionality -->
|
|
||||||
<input ref="fileInput" type="file" accept="image/*" class="hidden" @change="handleFileChange" />
|
<input ref="fileInput" type="file" accept="image/*" class="hidden" @change="handleFileChange" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, watch, onUnmounted, toRef, computed } from 'vue';
|
import { ref, onMounted, watch, onUnmounted, toRef, computed, nextTick } from 'vue';
|
||||||
import { useSettingsStore } from '@/stores/useSettingsStore';
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
import type { Sprite } from '@/types/sprites';
|
import type { Sprite } from '@/types/sprites';
|
||||||
import { useCanvas2D } from '@/composables/useCanvas2D';
|
|
||||||
import { useZoom } from '@/composables/useZoom';
|
|
||||||
import { useDragSprite } from '@/composables/useDragSprite';
|
import { useDragSprite } from '@/composables/useDragSprite';
|
||||||
import { useFileDrop } from '@/composables/useFileDrop';
|
import { useFileDrop } from '@/composables/useFileDrop';
|
||||||
|
import { useGridMetrics } from '@/composables/useGridMetrics';
|
||||||
|
import { useBackgroundStyles } from '@/composables/useBackgroundStyles';
|
||||||
|
import CopyToFrameModal from './utilities/CopyToFrameModal.vue';
|
||||||
|
|
||||||
import type { Layer } from '@/types/sprites';
|
import type { Layer } from '@/types/sprites';
|
||||||
|
|
||||||
@@ -126,49 +203,44 @@
|
|||||||
layers: Layer[];
|
layers: Layer[];
|
||||||
activeLayerId: string;
|
activeLayerId: string;
|
||||||
columns: number;
|
columns: number;
|
||||||
|
zoom: number;
|
||||||
|
isMultiSelectMode: boolean;
|
||||||
|
showActiveBorder: boolean;
|
||||||
|
allowCellSwap: boolean;
|
||||||
|
showAllSprites: boolean;
|
||||||
|
showOffsetLabels: boolean;
|
||||||
|
showFrameIds: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'updateSprite', id: string, x: number, y: number): void;
|
(e: 'updateSprite', id: string, x: number, y: number): void;
|
||||||
(e: 'updateSpriteCell', id: string, newIndex: number): void;
|
(e: 'updateSpriteCell', id: string, newIndex: number): void;
|
||||||
(e: 'removeSprite', id: string): void;
|
(e: 'removeSprite', id: string): void;
|
||||||
|
(e: 'removeSprites', ids: string[]): void;
|
||||||
(e: 'replaceSprite', id: string, file: File): void;
|
(e: 'replaceSprite', id: string, file: File): void;
|
||||||
(e: 'addSprite', file: File): void;
|
(e: 'addSprite', file: File, index?: number): void;
|
||||||
(e: 'addSpriteWithResize', file: File): void;
|
(e: 'addSpriteWithResize', file: File): void;
|
||||||
|
(e: 'rotateSprite', id: string, angle: number): void;
|
||||||
|
(e: 'flipSprite', id: string, direction: 'horizontal' | 'vertical'): void;
|
||||||
|
(e: 'copySpriteToFrame', spriteId: string, targetLayerId: string, targetFrameIndex: number): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// Get settings from store
|
// Get settings from store
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
const canvasRef = ref<HTMLCanvasElement | null>(null);
|
const gridContainerRef = ref<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
// rAF-based draw scheduler to coalesce multiple draw requests into a single frame
|
const getMousePosition = (event: MouseEvent, z?: number) => {
|
||||||
// Define before usage to avoid TDZ issues when passing into composables during setup
|
if (!gridContainerRef.value) return null;
|
||||||
let rafId: number | null = null;
|
const currentZoom = z ?? props.zoom;
|
||||||
function requestDraw() {
|
const rect = gridContainerRef.value.getBoundingClientRect();
|
||||||
if (rafId !== null) return;
|
const scaleX = gridContainerRef.value.offsetWidth / (rect.width / currentZoom);
|
||||||
rafId = requestAnimationFrame(() => {
|
const scaleY = gridContainerRef.value.offsetHeight / (rect.height / currentZoom);
|
||||||
rafId = null;
|
return {
|
||||||
drawCanvas();
|
x: ((event.clientX - rect.left) / currentZoom) * scaleX,
|
||||||
});
|
y: ((event.clientY - rect.top) / currentZoom) * scaleY,
|
||||||
}
|
};
|
||||||
|
};
|
||||||
// Initialize composables
|
|
||||||
const canvas2D = useCanvas2D(canvasRef);
|
|
||||||
|
|
||||||
const {
|
|
||||||
zoom,
|
|
||||||
increase: zoomIn,
|
|
||||||
decrease: zoomOut,
|
|
||||||
reset: resetZoom,
|
|
||||||
} = useZoom({
|
|
||||||
min: 0.5,
|
|
||||||
max: 3,
|
|
||||||
step: 0.25,
|
|
||||||
initial: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
const allowCellSwap = ref(false);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isDragging,
|
isDragging,
|
||||||
@@ -182,20 +254,27 @@
|
|||||||
handleTouchStart,
|
handleTouchStart,
|
||||||
handleTouchMove,
|
handleTouchMove,
|
||||||
findSpriteAtPosition,
|
findSpriteAtPosition,
|
||||||
|
findCellAtPosition,
|
||||||
calculateMaxDimensions,
|
calculateMaxDimensions,
|
||||||
} = useDragSprite({
|
} = useDragSprite({
|
||||||
sprites: computed(() => props.layers.find(l => l.id === props.activeLayerId)?.sprites ?? []),
|
sprites: computed(() => props.layers.find(l => l.id === props.activeLayerId)?.sprites ?? []),
|
||||||
|
layers: toRef(props, 'layers'),
|
||||||
columns: toRef(props, 'columns'),
|
columns: toRef(props, 'columns'),
|
||||||
zoom,
|
zoom: toRef(props, 'zoom'),
|
||||||
allowCellSwap,
|
allowCellSwap: toRef(props, 'allowCellSwap'),
|
||||||
negativeSpacingEnabled: toRef(settingsStore, 'negativeSpacingEnabled'),
|
negativeSpacingEnabled: toRef(settingsStore, 'negativeSpacingEnabled'),
|
||||||
getMousePosition: (event, z) => canvas2D.getMousePosition(event, z),
|
manualCellSizeEnabled: toRef(settingsStore, 'manualCellSizeEnabled'),
|
||||||
|
manualCellWidth: toRef(settingsStore, 'manualCellWidth'),
|
||||||
|
manualCellHeight: toRef(settingsStore, 'manualCellHeight'),
|
||||||
|
getMousePosition,
|
||||||
onUpdateSprite: (id, x, y) => emit('updateSprite', id, x, y),
|
onUpdateSprite: (id, x, y) => emit('updateSprite', id, x, y),
|
||||||
onUpdateSpriteCell: (id, newIndex) => emit('updateSpriteCell', id, newIndex),
|
onUpdateSpriteCell: (id, newIndex) => emit('updateSpriteCell', id, newIndex),
|
||||||
onDraw: requestDraw,
|
onDraw: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeSprites = computed(() => props.layers.find(l => l.id === props.activeLayerId)?.sprites ?? []);
|
const activeSprites = computed(() => props.layers.find(l => l.id === props.activeLayerId)?.sprites ?? []);
|
||||||
|
const visibleLayers = computed(() => props.layers.filter(l => l.visible));
|
||||||
|
const activeSpriteSprite = computed(() => activeSprites.value.find(s => s.id === activeSpriteId.value));
|
||||||
|
|
||||||
const { isDragOver, handleDragOver, handleDragEnter, handleDragLeave, handleDrop } = useFileDrop({
|
const { isDragOver, handleDragOver, handleDragEnter, handleDragLeave, handleDrop } = useFileDrop({
|
||||||
sprites: activeSprites,
|
sprites: activeSprites,
|
||||||
@@ -203,17 +282,83 @@
|
|||||||
onAddSpriteWithResize: file => emit('addSpriteWithResize', file),
|
onAddSpriteWithResize: file => emit('addSpriteWithResize', file),
|
||||||
});
|
});
|
||||||
|
|
||||||
const showAllSprites = ref(false);
|
|
||||||
const showContextMenu = ref(false);
|
const showContextMenu = ref(false);
|
||||||
const contextMenuX = ref(0);
|
const contextMenuX = ref(0);
|
||||||
const contextMenuY = ref(0);
|
const contextMenuY = ref(0);
|
||||||
|
const contextMenuIndex = ref<number | null>(null);
|
||||||
const contextMenuSpriteId = ref<string | null>(null);
|
const contextMenuSpriteId = ref<string | null>(null);
|
||||||
|
const selectedSpriteIds = ref<Set<string>>(new Set());
|
||||||
const replacingSpriteId = ref<string | null>(null);
|
const replacingSpriteId = ref<string | null>(null);
|
||||||
const fileInput = ref<HTMLInputElement | null>(null);
|
const fileInput = ref<HTMLInputElement | null>(null);
|
||||||
const customColor = ref('#ffffff');
|
|
||||||
|
// Copy to frame modal state
|
||||||
|
const showCopyToFrameModal = ref(false);
|
||||||
|
const copyTargetLayerId = ref(props.activeLayerId);
|
||||||
|
const copySpriteId = ref<string | null>(null);
|
||||||
|
|
||||||
|
// Clear selection when toggling multi-select mode
|
||||||
|
watch(
|
||||||
|
() => props.isMultiSelectMode,
|
||||||
|
() => {
|
||||||
|
selectedSpriteIds.value.clear();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Use the new useGridMetrics composable for consistent calculations
|
||||||
|
const { gridMetrics: gridMetricsRef, getCellPosition: getCellPositionHelper } = useGridMetrics({
|
||||||
|
layers: toRef(props, 'layers'),
|
||||||
|
negativeSpacingEnabled: toRef(settingsStore, 'negativeSpacingEnabled'),
|
||||||
|
manualCellSizeEnabled: toRef(settingsStore, 'manualCellSizeEnabled'),
|
||||||
|
manualCellWidth: toRef(settingsStore, 'manualCellWidth'),
|
||||||
|
manualCellHeight: toRef(settingsStore, 'manualCellHeight'),
|
||||||
|
});
|
||||||
|
|
||||||
|
const gridMetrics = gridMetricsRef;
|
||||||
|
|
||||||
|
const totalCells = computed(() => {
|
||||||
|
// Use all layers regardless of visibility to keep canvas size stable
|
||||||
|
const maxLen = Math.max(1, ...props.layers.map(l => l.sprites.length));
|
||||||
|
return Math.max(1, Math.ceil(maxLen / props.columns)) * props.columns;
|
||||||
|
});
|
||||||
|
|
||||||
|
const gridDimensions = computed(() => {
|
||||||
|
// Use all layers regardless of visibility to keep canvas size stable
|
||||||
|
const maxLen = Math.max(1, ...props.layers.map(l => l.sprites.length));
|
||||||
|
const rows = Math.max(1, Math.ceil(maxLen / props.columns));
|
||||||
|
return {
|
||||||
|
width: Math.round(gridMetrics.value.maxWidth * props.columns),
|
||||||
|
height: Math.round(gridMetrics.value.maxHeight * rows),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const getCellPosition = (index: number) => {
|
||||||
|
return getCellPositionHelper(index, props.columns, gridMetrics.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use the new useBackgroundStyles composable for consistent background styling
|
||||||
|
const {
|
||||||
|
backgroundColor: cellBackgroundColor,
|
||||||
|
backgroundImage: cellBackgroundImage,
|
||||||
|
backgroundSize: cellBackgroundSize,
|
||||||
|
backgroundPosition: cellBackgroundPosition,
|
||||||
|
} = useBackgroundStyles({
|
||||||
|
backgroundColor: toRef(settingsStore, 'backgroundColor'),
|
||||||
|
checkerboardEnabled: toRef(settingsStore, 'checkerboardEnabled'),
|
||||||
|
darkMode: toRef(settingsStore, 'darkMode'),
|
||||||
|
});
|
||||||
|
|
||||||
|
const getCellBackground = () => cellBackgroundColor.value;
|
||||||
|
const getCellBackgroundImage = () => cellBackgroundImage.value;
|
||||||
|
const getCellBackgroundSize = () => cellBackgroundSize.value;
|
||||||
|
const getCellBackgroundPosition = () => cellBackgroundPosition.value;
|
||||||
|
|
||||||
const startDrag = (event: MouseEvent) => {
|
const startDrag = (event: MouseEvent) => {
|
||||||
if (!canvasRef.value) return;
|
// If the click originated from an interactive element (button, link, input), ignore drag handling
|
||||||
|
const target = event.target as HTMLElement;
|
||||||
|
if (target && target.closest('button, a, input, select, textarea')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!gridContainerRef.value) return;
|
||||||
|
|
||||||
// Hide context menu if open
|
// Hide context menu if open
|
||||||
showContextMenu.value = false;
|
showContextMenu.value = false;
|
||||||
@@ -221,43 +366,135 @@
|
|||||||
// Handle right-click for context menu
|
// Handle right-click for context menu
|
||||||
if ('button' in event && (event as MouseEvent).button === 2) {
|
if ('button' in event && (event as MouseEvent).button === 2) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const pos = canvas2D.getMousePosition(event, zoom.value);
|
const pos = getMousePosition(event, props.zoom);
|
||||||
if (!pos) return;
|
if (!pos) return;
|
||||||
|
|
||||||
const clickedSprite = findSpriteAtPosition(pos.x, pos.y);
|
const clickedSprite = findSpriteAtPosition(pos.x, pos.y);
|
||||||
|
contextMenuIndex.value = findCellAtPosition(pos.x, pos.y)?.index ?? null;
|
||||||
contextMenuSpriteId.value = clickedSprite?.id || null;
|
contextMenuSpriteId.value = clickedSprite?.id || null;
|
||||||
|
|
||||||
|
if (clickedSprite) {
|
||||||
|
// If the right-clicked sprite is not in the selection, clear selection and select just this one
|
||||||
|
if (!selectedSpriteIds.value.has(clickedSprite.id)) {
|
||||||
|
selectedSpriteIds.value.clear();
|
||||||
|
selectedSpriteIds.value.add(clickedSprite.id);
|
||||||
|
}
|
||||||
|
// If it IS in the selection, keep the current selection (so we can apply action to all)
|
||||||
|
} else {
|
||||||
|
// Right click on empty space
|
||||||
|
selectedSpriteIds.value.clear();
|
||||||
|
}
|
||||||
|
|
||||||
contextMenuX.value = event.clientX;
|
contextMenuX.value = event.clientX;
|
||||||
contextMenuY.value = event.clientY;
|
contextMenuY.value = event.clientY;
|
||||||
|
|
||||||
showContextMenu.value = true;
|
showContextMenu.value = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore non-left mouse buttons (but allow touch-generated events without a button prop)
|
// Ignore non-left mouse buttons
|
||||||
if ('button' in event && (event as MouseEvent).button !== 0) return;
|
if ('button' in event && (event as MouseEvent).button !== 0) return;
|
||||||
|
|
||||||
|
// Handle selection logic for left click
|
||||||
|
const pos = getMousePosition(event, props.zoom);
|
||||||
|
if (pos) {
|
||||||
|
const clickedSprite = findSpriteAtPosition(pos.x, pos.y);
|
||||||
|
if (clickedSprite) {
|
||||||
|
// Selection logic with multi-select mode check
|
||||||
|
if (event.ctrlKey || event.metaKey || props.isMultiSelectMode) {
|
||||||
|
// Toggle selection
|
||||||
|
if (selectedSpriteIds.value.has(clickedSprite.id)) {
|
||||||
|
selectedSpriteIds.value.delete(clickedSprite.id);
|
||||||
|
} else {
|
||||||
|
selectedSpriteIds.value.add(clickedSprite.id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Single select (but don't clear if dragging starts immediately?
|
||||||
|
// Usually standard behavior is to clear others unless shift/ctrl held)
|
||||||
|
if (!selectedSpriteIds.value.has(clickedSprite.id)) {
|
||||||
|
selectedSpriteIds.value.clear();
|
||||||
|
selectedSpriteIds.value.add(clickedSprite.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Clicked on empty space
|
||||||
|
selectedSpriteIds.value.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Delegate to composable for actual drag handling
|
// Delegate to composable for actual drag handling
|
||||||
dragStart(event);
|
dragStart(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wrapper for drag move
|
const pendingDrag = ref(false);
|
||||||
|
const latestEvent = ref<MouseEvent | null>(null);
|
||||||
|
|
||||||
const drag = (event: MouseEvent) => {
|
const drag = (event: MouseEvent) => {
|
||||||
dragMove(event);
|
// Store the latest event and schedule a single animation frame update
|
||||||
|
latestEvent.value = event;
|
||||||
|
if (!pendingDrag.value) {
|
||||||
|
pendingDrag.value = true;
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (latestEvent.value) {
|
||||||
|
dragMove(latestEvent.value);
|
||||||
|
}
|
||||||
|
pendingDrag.value = false;
|
||||||
|
latestEvent.value = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeSprite = () => {
|
const removeSprite = () => {
|
||||||
if (contextMenuSpriteId.value) {
|
if (selectedSpriteIds.value.size > 0) {
|
||||||
|
emit('removeSprites', Array.from(selectedSpriteIds.value));
|
||||||
|
selectedSpriteIds.value.clear();
|
||||||
|
showContextMenu.value = false;
|
||||||
|
contextMenuSpriteId.value = null;
|
||||||
|
} else if (contextMenuSpriteId.value) {
|
||||||
emit('removeSprite', contextMenuSpriteId.value);
|
emit('removeSprite', contextMenuSpriteId.value);
|
||||||
showContextMenu.value = false;
|
showContextMenu.value = false;
|
||||||
contextMenuSpriteId.value = null;
|
contextMenuSpriteId.value = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const rotateSpriteInMenu = (angle: number) => {
|
||||||
|
if (selectedSpriteIds.value.size > 0) {
|
||||||
|
selectedSpriteIds.value.forEach(id => {
|
||||||
|
emit('rotateSprite', id, angle);
|
||||||
|
});
|
||||||
|
} else if (contextMenuSpriteId.value) {
|
||||||
|
emit('rotateSprite', contextMenuSpriteId.value, angle);
|
||||||
|
}
|
||||||
|
showContextMenu.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const flipSpriteInMenu = (direction: 'horizontal' | 'vertical') => {
|
||||||
|
if (selectedSpriteIds.value.size > 0) {
|
||||||
|
selectedSpriteIds.value.forEach(id => {
|
||||||
|
emit('flipSprite', id, direction);
|
||||||
|
});
|
||||||
|
} else if (contextMenuSpriteId.value) {
|
||||||
|
emit('flipSprite', contextMenuSpriteId.value, direction);
|
||||||
|
}
|
||||||
|
showContextMenu.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Delete' || event.key === 'Backspace') {
|
||||||
|
// Don't delete if editing text/input
|
||||||
|
if (document.activeElement?.tagName === 'INPUT' || document.activeElement?.tagName === 'TEXTAREA') return;
|
||||||
|
|
||||||
|
if (selectedSpriteIds.value.size > 0) {
|
||||||
|
emit('removeSprites', Array.from(selectedSpriteIds.value));
|
||||||
|
selectedSpriteIds.value.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const replaceSprite = () => {
|
const replaceSprite = () => {
|
||||||
if (contextMenuSpriteId.value && fileInput.value) {
|
if (contextMenuSpriteId.value && fileInput.value) {
|
||||||
// Store the sprite ID separately so it persists after context menu closes
|
|
||||||
replacingSpriteId.value = contextMenuSpriteId.value;
|
replacingSpriteId.value = contextMenuSpriteId.value;
|
||||||
fileInput.value.click();
|
fileInput.value.click();
|
||||||
// Hide context menu immediately since we've stored the ID
|
|
||||||
showContextMenu.value = false;
|
showContextMenu.value = false;
|
||||||
contextMenuSpriteId.value = null;
|
contextMenuSpriteId.value = null;
|
||||||
}
|
}
|
||||||
@@ -266,7 +503,6 @@
|
|||||||
const addSprite = () => {
|
const addSprite = () => {
|
||||||
if (fileInput.value) {
|
if (fileInput.value) {
|
||||||
fileInput.value.click();
|
fileInput.value.click();
|
||||||
// Hide context menu immediately
|
|
||||||
showContextMenu.value = false;
|
showContextMenu.value = false;
|
||||||
contextMenuSpriteId.value = null;
|
contextMenuSpriteId.value = null;
|
||||||
}
|
}
|
||||||
@@ -281,15 +517,18 @@
|
|||||||
if (replacingSpriteId.value) {
|
if (replacingSpriteId.value) {
|
||||||
emit('replaceSprite', replacingSpriteId.value, file);
|
emit('replaceSprite', replacingSpriteId.value, file);
|
||||||
} else {
|
} else {
|
||||||
// Adding new sprite
|
if (contextMenuIndex.value !== null) {
|
||||||
|
emit('addSprite', file, contextMenuIndex.value);
|
||||||
|
} else {
|
||||||
emit('addSprite', file);
|
emit('addSprite', file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
alert('Please select an image file.');
|
alert('Please select an image file.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Clean up after file selection
|
|
||||||
replacingSpriteId.value = null;
|
replacingSpriteId.value = null;
|
||||||
|
contextMenuIndex.value = null;
|
||||||
input.value = '';
|
input.value = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -298,146 +537,42 @@
|
|||||||
contextMenuSpriteId.value = null;
|
contextMenuSpriteId.value = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wrapper for drag leave to pass canvasRef
|
const openCopyToFrameModal = () => {
|
||||||
const onDragLeave = (event: DragEvent) => {
|
if (contextMenuSpriteId.value) {
|
||||||
handleDragLeave(event, canvasRef.value);
|
copySpriteId.value = contextMenuSpriteId.value;
|
||||||
|
copyTargetLayerId.value = props.activeLayerId;
|
||||||
|
showCopyToFrameModal.value = true;
|
||||||
|
showContextMenu.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function drawCanvas() {
|
const closeCopyToFrameModal = () => {
|
||||||
if (!canvasRef.value || !canvas2D.ctx.value) return;
|
showCopyToFrameModal.value = false;
|
||||||
|
copySpriteId.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
const { maxWidth, maxHeight, negativeSpacing } = calculateMaxDimensions();
|
const confirmCopyToFrame = (targetLayerId: string, targetFrameIndex: number) => {
|
||||||
|
if (copySpriteId.value) {
|
||||||
// Set canvas size
|
emit('copySpriteToFrame', copySpriteId.value, targetLayerId, targetFrameIndex);
|
||||||
const maxLen = Math.max(1, ...props.layers.map(l => (l.visible ? l.sprites.length : 1)));
|
closeCopyToFrameModal();
|
||||||
const rows = Math.max(1, Math.ceil(maxLen / props.columns));
|
|
||||||
canvas2D.setCanvasSize(maxWidth * props.columns, maxHeight * rows);
|
|
||||||
|
|
||||||
// Clear canvas
|
|
||||||
canvas2D.clear();
|
|
||||||
|
|
||||||
// Apply pixel art optimization
|
|
||||||
canvas2D.applySmoothing();
|
|
||||||
|
|
||||||
// Draw background for each cell
|
|
||||||
for (let col = 0; col < props.columns; col++) {
|
|
||||||
for (let row = 0; row < rows; row++) {
|
|
||||||
const cellX = Math.floor(col * maxWidth);
|
|
||||||
const cellY = Math.floor(row * maxHeight);
|
|
||||||
|
|
||||||
// Draw cell background
|
|
||||||
canvas2D.fillCellBackground(cellX, cellY, maxWidth, maxHeight);
|
|
||||||
|
|
||||||
// Highlight the target cell if specified
|
|
||||||
if (highlightCell.value && highlightCell.value.col === col && highlightCell.value.row === row) {
|
|
||||||
canvas2D.fillRect(cellX, cellY, maxWidth, maxHeight, 'rgba(59, 130, 246, 0.2)');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// If showing all sprites, draw all sprites with transparency in each cell
|
const onDragLeave = (event: DragEvent) => {
|
||||||
if (showAllSprites.value) {
|
handleDragLeave(event, gridContainerRef.value);
|
||||||
const total = Math.max(...props.layers.map(l => (l.visible ? l.sprites.length : 0)));
|
|
||||||
for (let cellIndex = 0; cellIndex < total; cellIndex++) {
|
|
||||||
const cellCol = cellIndex % props.columns;
|
|
||||||
const cellRow = Math.floor(cellIndex / props.columns);
|
|
||||||
const cellX = Math.floor(cellCol * maxWidth);
|
|
||||||
const cellY = Math.floor(cellRow * maxHeight);
|
|
||||||
|
|
||||||
props.layers.forEach(layer => {
|
|
||||||
if (!layer.visible) return;
|
|
||||||
const sprite = layer.sprites[cellIndex];
|
|
||||||
if (sprite) canvas2D.drawImage(sprite.img, cellX + negativeSpacing + sprite.x, cellY + negativeSpacing + sprite.y, 0.35);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw layers in order; active layer will be interactable
|
|
||||||
props.layers.forEach(layer => {
|
|
||||||
if (!layer.visible) return;
|
|
||||||
layer.sprites.forEach((sprite, index) => {
|
|
||||||
// Skip the active sprite if we're showing a ghost instead
|
|
||||||
if (activeSpriteId.value === sprite.id && ghostSprite.value) return;
|
|
||||||
|
|
||||||
const col = index % props.columns;
|
|
||||||
const row = Math.floor(index / props.columns);
|
|
||||||
|
|
||||||
const cellX = Math.floor(col * maxWidth);
|
|
||||||
const cellY = Math.floor(row * maxHeight);
|
|
||||||
|
|
||||||
const alpha = layer.id === props.activeLayerId ? 1 : 0.85;
|
|
||||||
canvas2D.drawImage(sprite.img, cellX + negativeSpacing + sprite.x, cellY + negativeSpacing + sprite.y, alpha);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Draw ghost sprite if we're dragging between cells
|
|
||||||
if (ghostSprite.value && activeSpriteId.value) {
|
|
||||||
const sprite = activeSprites.value.find(s => s.id === activeSpriteId.value);
|
|
||||||
if (sprite) {
|
|
||||||
canvas2D.drawImage(sprite.img, ghostSprite.value.x, ghostSprite.value.y, 0.6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw grid lines on top of everything
|
|
||||||
for (let col = 0; col < props.columns; col++) {
|
|
||||||
for (let row = 0; row < rows; row++) {
|
|
||||||
const cellX = Math.floor(col * maxWidth);
|
|
||||||
const cellY = Math.floor(row * maxHeight);
|
|
||||||
canvas2D.strokeGridCell(cellX, cellY, maxWidth, maxHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track which images already have listeners
|
|
||||||
const imagesWithListeners = new WeakSet<HTMLImageElement>();
|
|
||||||
|
|
||||||
const attachImageListeners = () => {
|
|
||||||
const sprites = props.layers.flatMap(l => l.sprites);
|
|
||||||
canvas2D.attachImageListeners(sprites, handleForceRedraw, imagesWithListeners);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
canvas2D.initContext();
|
document.addEventListener('mouseup', stopDrag);
|
||||||
requestDraw();
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
// Attach listeners for current sprites
|
|
||||||
attachImageListeners();
|
|
||||||
|
|
||||||
// Listen for forceRedraw event from App.vue
|
|
||||||
window.addEventListener('forceRedraw', handleForceRedraw);
|
|
||||||
|
|
||||||
// Hide context menu when clicking elsewhere
|
|
||||||
document.addEventListener('click', hideContextMenu);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener('forceRedraw', handleForceRedraw);
|
document.removeEventListener('mouseup', stopDrag);
|
||||||
document.removeEventListener('click', hideContextMenu);
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handler for force redraw event
|
// Watch for background color changes
|
||||||
const handleForceRedraw = () => {
|
|
||||||
// Ensure integer positioning for crisp rendering on the active layer
|
|
||||||
canvas2D.ensureIntegerPositions(activeSprites.value);
|
|
||||||
canvas2D.applySmoothing();
|
|
||||||
requestDraw();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Re-attach listeners and redraw whenever layers/sprites change
|
|
||||||
watch(
|
|
||||||
() => props.layers,
|
|
||||||
() => {
|
|
||||||
attachImageListeners();
|
|
||||||
requestDraw();
|
|
||||||
},
|
|
||||||
{ deep: true }
|
|
||||||
);
|
|
||||||
watch(() => props.columns, requestDraw);
|
|
||||||
watch(() => settingsStore.pixelPerfect, requestDraw);
|
|
||||||
watch(() => settingsStore.darkMode, requestDraw);
|
|
||||||
watch(() => settingsStore.negativeSpacingEnabled, requestDraw);
|
|
||||||
watch(() => settingsStore.backgroundColor, requestDraw);
|
|
||||||
watch(showAllSprites, requestDraw);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
|||||||
@@ -1,24 +1,108 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="spritesheet-preview w-full">
|
<Teleport to="body">
|
||||||
<!-- Main Layout: Canvas Left, Controls Right -->
|
<div v-if="showContextMenu" @click.stop class="fixed bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-xl z-50 py-1 min-w-[160px] overflow-hidden" :style="{ left: contextMenuX + 'px', top: contextMenuY + 'px' }">
|
||||||
<div class="flex flex-col lg:flex-row gap-4">
|
<button @click="rotateSpriteInMenu(90)" class="w-full px-3 py-1.5 text-left hover:bg-green-50 dark:hover:bg-green-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
<!-- Canvas Area (Left/Main) -->
|
<i class="fas fa-redo text-green-600 dark:text-green-400 text-xs w-4"></i>
|
||||||
<div class="flex-1 min-w-0">
|
<span>Rotate +90°</span>
|
||||||
<div class="relative bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded-lg overflow-auto min-h-[300px] sm:min-h-[520px] shadow-sm hover:shadow-md transition-shadow duration-200">
|
</button>
|
||||||
<canvas
|
<button @click="flipSpriteInMenu('horizontal')" class="w-full px-3 py-1.5 text-left hover:bg-orange-50 dark:hover:bg-orange-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
ref="previewCanvasRef"
|
<i class="fas fa-arrows-alt-h text-orange-600 dark:text-orange-400 text-xs w-4"></i>
|
||||||
@mousedown="startDrag"
|
<span>Flip Horizontal</span>
|
||||||
|
</button>
|
||||||
|
<button @click="flipSpriteInMenu('vertical')" class="w-full px-3 py-1.5 text-left hover:bg-orange-50 dark:hover:bg-orange-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
|
<i class="fas fa-arrows-alt-v text-orange-600 dark:text-orange-400 text-xs w-4"></i>
|
||||||
|
<span>Flip Vertical</span>
|
||||||
|
</button>
|
||||||
|
<button @click="replaceSprite" class="w-full px-3 py-1.5 text-left hover:bg-purple-50 dark:hover:bg-purple-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
|
<i class="fas fa-exchange-alt text-purple-600 dark:text-purple-400 text-xs w-4"></i>
|
||||||
|
<span>Replace Sprite</span>
|
||||||
|
</button>
|
||||||
|
<button @click="openCopyToFrameModal" class="w-full px-3 py-1.5 text-left hover:bg-cyan-50 dark:hover:bg-cyan-900/30 text-gray-700 dark:text-gray-200 flex items-center gap-2 transition-colors text-sm">
|
||||||
|
<i class="fas fa-copy text-cyan-600 dark:text-cyan-400 text-xs w-4"></i>
|
||||||
|
<span>Copy to Frame...</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Copy to Frame Modal -->
|
||||||
|
<CopyToFrameModal :is-open="showCopyToFrameModal" :layers="props.layers" :initial-layer-id="copyTargetLayerId" @close="closeCopyToFrameModal" @copy="confirmCopyToFrame" />
|
||||||
|
</Teleport>
|
||||||
|
|
||||||
|
<div class="spritesheet-preview w-full h-full" @click="hideContextMenu">
|
||||||
|
<div class="flex flex-col lg:flex-row gap-4 h-full min-h-0">
|
||||||
|
<div class="flex-1 min-w-0 flex flex-col min-h-0">
|
||||||
|
<div
|
||||||
|
class="relative bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded-lg overflow-auto flex-1 min-h-[200px] sm:min-h-[300px] max-h-[50vh] lg:max-h-none shadow-sm hover:shadow-md transition-shadow duration-200"
|
||||||
@mousemove="drag"
|
@mousemove="drag"
|
||||||
@mouseup="stopDrag"
|
@mouseup="stopDrag"
|
||||||
@mouseleave="stopDrag"
|
@mouseleave="stopDrag"
|
||||||
@touchstart="handleTouchStart"
|
|
||||||
@touchmove="handleTouchMove"
|
@touchmove="handleTouchMove"
|
||||||
@touchend="stopDrag"
|
@touchend="stopDrag"
|
||||||
class="block touch-manipulation"
|
|
||||||
:class="{ 'cursor-move': isDraggable }"
|
|
||||||
:style="{ transform: `scale(${zoom})`, transformOrigin: 'top left', ...(settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}) }"
|
|
||||||
>
|
>
|
||||||
</canvas>
|
<div
|
||||||
|
ref="previewContainerRef"
|
||||||
|
class="relative touch-manipulation inline-block"
|
||||||
|
:class="{ 'ring-2 ring-blue-500 ring-offset-2': isDragOver }"
|
||||||
|
:style="{
|
||||||
|
transform: `scale(${zoom})`,
|
||||||
|
transformOrigin: 'top left',
|
||||||
|
width: `${cellDimensions.cellWidth}px`,
|
||||||
|
height: `${cellDimensions.cellHeight}px`,
|
||||||
|
backgroundColor: settingsStore.backgroundColor === 'transparent' ? '#f9fafb' : settingsStore.backgroundColor,
|
||||||
|
backgroundImage: previewBackgroundImage,
|
||||||
|
backgroundSize: previewBackgroundSize,
|
||||||
|
backgroundPosition: previewBackgroundPosition,
|
||||||
|
}"
|
||||||
|
@dragover.prevent="onDragOver"
|
||||||
|
@dragleave="onDragLeave"
|
||||||
|
@drop.prevent="onDrop"
|
||||||
|
>
|
||||||
|
<!-- Background sprites (dimmed for comparison) -->
|
||||||
|
<template v-if="showAllSprites">
|
||||||
|
<template v-for="i in maxFrames()" :key="`bg-${i - 1}`">
|
||||||
|
<template v-if="i - 1 !== currentFrameIndex && !hiddenFrames.includes(i - 1)">
|
||||||
|
<template v-for="layer in getVisibleLayers()" :key="`${layer.id}-${i - 1}`">
|
||||||
|
<img
|
||||||
|
v-if="layer.sprites[i - 1]"
|
||||||
|
:src="layer.sprites[i - 1].url"
|
||||||
|
class="absolute pointer-events-none"
|
||||||
|
:style="{
|
||||||
|
left: `${Math.round(getCellPosition(0).x + gridMetrics.negativeSpacing + layer.sprites[i - 1].x)}px`,
|
||||||
|
top: `${Math.round(getCellPosition(0).y + gridMetrics.negativeSpacing + layer.sprites[i - 1].y)}px`,
|
||||||
|
width: `${Math.round(layer.sprites[i - 1].width)}px`,
|
||||||
|
height: `${Math.round(layer.sprites[i - 1].height)}px`,
|
||||||
|
opacity: '0.3',
|
||||||
|
imageRendering: settingsStore.pixelPerfect ? 'pixelated' : 'auto',
|
||||||
|
transform: `rotate(${layer.sprites[i - 1].rotation || 0}deg) scale(${layer.sprites[i - 1].flipX ? -1 : 1}, ${layer.sprites[i - 1].flipY ? -1 : 1})`,
|
||||||
|
}"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Current frame sprites -->
|
||||||
|
<template v-for="layer in getVisibleLayers()" :key="layer.id">
|
||||||
|
<img
|
||||||
|
v-if="layer.sprites[currentFrameIndex]"
|
||||||
|
:src="layer.sprites[currentFrameIndex].url"
|
||||||
|
class="absolute"
|
||||||
|
:class="{ 'cursor-move': isDraggable }"
|
||||||
|
:style="{
|
||||||
|
left: `${Math.round(getCellPosition(0).x + gridMetrics.negativeSpacing + layer.sprites[currentFrameIndex].x)}px`,
|
||||||
|
top: `${Math.round(getCellPosition(0).y + gridMetrics.negativeSpacing + layer.sprites[currentFrameIndex].y)}px`,
|
||||||
|
width: `${Math.round(layer.sprites[currentFrameIndex].width)}px`,
|
||||||
|
height: `${Math.round(layer.sprites[currentFrameIndex].height)}px`,
|
||||||
|
imageRendering: settingsStore.pixelPerfect ? 'pixelated' : 'auto',
|
||||||
|
transform: `rotate(${layer.sprites[currentFrameIndex].rotation || 0}deg) scale(${layer.sprites[currentFrameIndex].flipX ? -1 : 1}, ${layer.sprites[currentFrameIndex].flipY ? -1 : 1})`,
|
||||||
|
}"
|
||||||
|
@mousedown="startDrag($event, layer.sprites[currentFrameIndex], layer.id)"
|
||||||
|
@touchstart="handleTouchStart($event, layer.sprites[currentFrameIndex], layer.id)"
|
||||||
|
@contextmenu.prevent="openContextMenu($event, layer.sprites[currentFrameIndex], layer.id)"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Mobile zoom controls -->
|
<!-- Mobile zoom controls -->
|
||||||
<div class="absolute bottom-3 right-3 flex space-x-2 lg:hidden bg-white/80 dark:bg-gray-800/80 p-2 rounded-lg shadow-md">
|
<div class="absolute bottom-3 right-3 flex space-x-2 lg:hidden bg-white/80 dark:bg-gray-800/80 p-2 rounded-lg shadow-md">
|
||||||
@@ -29,122 +113,155 @@
|
|||||||
<i class="fas fa-minus"></i>
|
<i class="fas fa-minus"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Drop zone overlay -->
|
||||||
|
<div v-if="isDragOver" class="absolute inset-0 bg-blue-500/20 flex items-center justify-center pointer-events-none z-10 rounded-lg">
|
||||||
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg px-4 py-3 flex items-center gap-2 border border-blue-300 dark:border-blue-600">
|
||||||
|
<i class="fas fa-plus-circle text-blue-500"></i>
|
||||||
|
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">Drop to add sprite at frame {{ currentFrameIndex + 1 }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Controls Sidebar (Right) -->
|
<div class="lg:w-80 xl:w-96 flex-shrink-0 lg:h-full lg:min-h-0 flex flex-col">
|
||||||
<div class="lg:w-80 xl:w-96 flex-shrink-0">
|
<div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm overflow-hidden flex-1 flex flex-col lg:overflow-y-auto">
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4 space-y-4">
|
|
||||||
<!-- Playback Controls -->
|
<!-- Playback Controls -->
|
||||||
<div class="space-y-3">
|
<div class="p-4 border-b border-gray-100 dark:border-gray-700 flex-shrink-0">
|
||||||
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 uppercase tracking-wide">Playback</h3>
|
<h3 class="text-xs font-bold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-3">Playback</h3>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<button @click="togglePlayback" class="flex items-center justify-center gap-1.5 bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-md transition-colors cursor-pointer flex-1">
|
<button @click="togglePlayback" class="flex items-center justify-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 h-10 rounded-lg transition-all cursor-pointer flex-1 shadow-sm active:scale-95">
|
||||||
<span v-if="isPlaying" class="flex items-center gap-1.5">
|
<span v-if="isPlaying" class="flex items-center gap-2 font-medium">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-5 h-5">
|
<i class="fas fa-pause"></i>
|
||||||
<path fill-rule="evenodd" d="M6.75 5.25a.75.75 0 01.75-.75H9a.75.75 0 01.75.75v13.5a.75.75 0 01-.75.75H7.5a.75.75 0 01-.75-.75V5.25zm7.5 0A.75.75 0 0115 4.5h1.5a.75.75 0 01.75.75v13.5a.75.75 0 01-.75.75H15a.75.75 0 01-.75-.75V5.25z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
Pause
|
Pause
|
||||||
</span>
|
</span>
|
||||||
<span v-else class="flex items-center gap-1.5">
|
<span v-else class="flex items-center gap-2 font-medium">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-5 h-5">
|
<i class="fas fa-play"></i>
|
||||||
<path fill-rule="evenodd" d="M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
Play
|
Play
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<button @click="previousFrame" class="bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 p-2 rounded-md transition-colors duration-200 cursor-pointer" :disabled="isPlaying" :class="{ 'opacity-50 cursor-not-allowed': isPlaying }">
|
<button @click="previousFrame" class="btn btn-secondary rounded-lg h-10 w-10" :disabled="isPlaying" :class="{ 'opacity-50 cursor-not-allowed': isPlaying }">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-5 h-5 dark:text-gray-200">
|
<i class="fas fa-step-backward"></i>
|
||||||
<path fill-rule="evenodd" d="M11.78 5.22a.75.75 0 01.75.75v12.06l4.72-4.72a.75.75 0 111.06 1.06l-6 6a.75.75 0 01-1.06 0l-6-6a.75.75 0 011.06-1.06l4.72 4.72V5.97a.75.75 0 01.75-.75z" clip-rule="evenodd" transform="rotate(90 12 12)" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
</button>
|
||||||
<button @click="nextFrame" class="bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 p-2 rounded-md transition-colors duration-200 cursor-pointer" :disabled="isPlaying" :class="{ 'opacity-50 cursor-not-allowed': isPlaying }">
|
<button @click="nextFrame" class="btn btn-secondary rounded-lg h-10 w-10" :disabled="isPlaying" :class="{ 'opacity-50 cursor-not-allowed': isPlaying }">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-5 h-5 dark:text-gray-200">
|
<i class="fas fa-step-forward"></i>
|
||||||
<path fill-rule="evenodd" d="M11.78 5.22a.75.75 0 01.75.75v12.06l4.72-4.72a.75.75 0 111.06 1.06l-6 6a.75.75 0 01-1.06 0l-6-6a.75.75 0 011.06-1.06l4.72 4.72V5.97a.75.75 0 01.75-.75z" clip-rule="evenodd" transform="rotate(-90 12 12)" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Sliders -->
|
<!-- Animation Settings -->
|
||||||
<div class="space-y-3">
|
<div class="p-4 border-b border-gray-100 dark:border-gray-700 space-y-5 flex-shrink-0">
|
||||||
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 uppercase tracking-wide">Controls</h3>
|
<h3 class="text-xs font-bold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-1">Animation</h3>
|
||||||
|
|
||||||
<!-- Frame Navigation -->
|
<!-- Frame Navigation -->
|
||||||
<div class="space-y-1">
|
<div class="space-y-2">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="text-xs font-medium text-gray-600 dark:text-gray-400">Frame</span>
|
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">Frame</span>
|
||||||
<span class="text-xs font-mono text-gray-700 dark:text-gray-300">{{ visibleFrameNumber }}/{{ visibleFramesCount }}</span>
|
<span class="text-xs font-mono text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 px-2 py-0.5 rounded">{{ visibleFrameNumber }} / {{ visibleFramesCount }}</span>
|
||||||
</div>
|
</div>
|
||||||
<input type="range" min="0" :max="visibleFrames.length - 1" :value="visibleFrameIndex" @input="handleSliderInput" class="w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-500" :disabled="isPlaying" :class="{ 'opacity-50': isPlaying }" />
|
<input type="range" min="0" :max="visibleFrames.length - 1" :value="visibleFrameIndex" @input="handleSliderInput" class="w-full h-1.5 bg-gray-200 dark:bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-600" :disabled="isPlaying" :class="{ 'opacity-50': isPlaying }" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- FPS Control -->
|
<!-- FPS Control -->
|
||||||
<div class="space-y-1">
|
<div class="space-y-2">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="text-xs font-medium text-gray-600 dark:text-gray-400">FPS</span>
|
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">Speed (FPS)</span>
|
||||||
<span class="text-xs font-mono text-gray-700 dark:text-gray-300">{{ fps }}</span>
|
<span class="text-xs font-mono text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 px-2 py-0.5 rounded">{{ fps }}</span>
|
||||||
</div>
|
</div>
|
||||||
<input type="range" min="1" max="60" v-model.number="fps" class="w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-500" />
|
<input type="range" min="1" max="60" v-model.number="fps" class="w-full h-1.5 bg-gray-200 dark:bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-600" />
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- View Options -->
|
||||||
|
<div class="p-4 space-y-5 flex-1">
|
||||||
|
<h3 class="text-xs font-bold text-gray-400 dark:text-gray-500 uppercase tracking-wider mb-1">View Options</h3>
|
||||||
|
|
||||||
<!-- Zoom Control -->
|
<!-- Zoom Control -->
|
||||||
<div class="space-y-1">
|
|
||||||
<div class="flex justify-between items-center">
|
|
||||||
<span class="text-xs font-medium text-gray-600 dark:text-gray-400">Zoom</span>
|
|
||||||
<span class="text-xs font-mono text-gray-700 dark:text-gray-300">{{ Math.round(zoom * 100) }}%</span>
|
|
||||||
</div>
|
|
||||||
<input type="range" min="0.5" max="5" step="0.1" v-model.number="zoom" class="w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-500" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Options -->
|
|
||||||
<div class="space-y-3">
|
|
||||||
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 uppercase tracking-wide">Options</h3>
|
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<label class="flex items-center gap-2 cursor-pointer">
|
<div class="flex justify-between items-center">
|
||||||
<input type="checkbox" v-model="isDraggable" class="w-4 h-4 text-blue-500 focus:ring-blue-400 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700" />
|
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">Zoom</span>
|
||||||
<span class="text-sm dark:text-gray-200">Reposition</span>
|
<span class="text-xs font-mono text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 px-2 py-0.5 rounded">{{ Math.round(zoom * 100) }}%</span>
|
||||||
|
</div>
|
||||||
|
<input type="range" min="0.5" max="5" step="0.1" v-model.number="zoom" class="w-full h-1.5 bg-gray-200 dark:bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-600" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Toggles -->
|
||||||
|
<div class="space-y-3 pt-2">
|
||||||
|
<label class="flex items-center justify-between cursor-pointer group">
|
||||||
|
<span class="text-sm text-gray-700 dark:text-gray-300 group-hover:text-gray-900 dark:group-hover:text-gray-100 transition-colors">Pixel perfect</span>
|
||||||
|
<div class="relative inline-flex items-center cursor-pointer">
|
||||||
|
<input type="checkbox" v-model="settingsStore.pixelPerfect" class="sr-only peer" />
|
||||||
|
<div
|
||||||
|
class="w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label class="flex items-center gap-2 cursor-pointer">
|
<label class="flex items-center justify-between cursor-pointer group">
|
||||||
<input type="checkbox" v-model="showAllSprites" class="w-4 h-4 text-blue-500 focus:ring-blue-400 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700" />
|
<span class="text-sm text-gray-700 dark:text-gray-300 group-hover:text-gray-900 dark:group-hover:text-gray-100 transition-colors">Reposition mode</span>
|
||||||
<span class="text-sm dark:text-gray-200">Compare sprites</span>
|
<div class="relative inline-flex items-center cursor-pointer">
|
||||||
|
<input type="checkbox" v-model="isDraggable" class="sr-only peer" />
|
||||||
|
<div
|
||||||
|
class="w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label class="flex items-center gap-2 cursor-pointer">
|
<div class="pl-4 border-l-2 border-gray-100 dark:border-gray-700 transition-all space-y-2" :class="{ 'opacity-50 pointer-events-none': !isDraggable }">
|
||||||
<input type="checkbox" v-model="settingsStore.pixelPerfect" class="w-4 h-4 text-blue-500 focus:ring-blue-400 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700" @change="drawPreviewCanvas" />
|
<label class="flex items-center justify-between cursor-pointer group">
|
||||||
<span class="text-sm dark:text-gray-200">Pixel perfect</span>
|
<span class="text-sm text-gray-600 dark:text-gray-400 group-hover:text-gray-800 dark:group-hover:text-gray-200 transition-colors">Apply to all layers</span>
|
||||||
|
<input type="checkbox" v-model="repositionAllLayers" class="w-4 h-4 text-blue-600 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" :disabled="!isDraggable" />
|
||||||
|
</label>
|
||||||
|
<label class="flex items-center justify-between cursor-pointer group">
|
||||||
|
<span class="text-sm text-gray-600 dark:text-gray-400 group-hover:text-gray-800 dark:group-hover:text-gray-200 transition-colors">Arrow key movement</span>
|
||||||
|
<input type="checkbox" v-model="arrowKeyMovement" class="w-4 h-4 text-blue-600 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" :disabled="!isDraggable" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label class="flex items-center justify-between cursor-pointer group">
|
||||||
|
<span class="text-sm text-gray-700 dark:text-gray-300 group-hover:text-gray-900 dark:group-hover:text-gray-100 transition-colors">Compare sprites</span>
|
||||||
|
<div class="relative inline-flex items-center cursor-pointer">
|
||||||
|
<input type="checkbox" v-model="showAllSprites" class="sr-only peer" />
|
||||||
|
<div
|
||||||
|
class="w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Current frame offset display -->
|
<!-- Current frame offset display -->
|
||||||
<div v-if="currentFrameSprite" class="p-2 bg-gray-100 dark:bg-gray-700 rounded-md border border-gray-200 dark:border-gray-600">
|
<div v-if="currentFrameSprite" class="px-4 pb-4 flex-shrink-0">
|
||||||
<div class="flex items-center justify-between">
|
<div class="p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg border border-gray-100 dark:border-gray-700 flex items-center justify-between">
|
||||||
<span class="text-xs font-medium text-gray-600 dark:text-gray-400">Offset</span>
|
<span class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide">Offset</span>
|
||||||
<span class="text-xs font-mono font-semibold text-cyan-600 dark:text-cyan-400">x: {{ currentFrameSprite.x }}, y: {{ currentFrameSprite.y }}</span>
|
<span class="text-xs font-mono font-bold text-gray-700 dark:text-gray-200">X: {{ currentFrameSprite.x }} <span class="text-gray-300 dark:text-gray-600 mx-1">|</span> Y: {{ currentFrameSprite.y }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Frame Selection (when Compare sprites is enabled) -->
|
<!-- Frame Selection (when Compare sprites is enabled) -->
|
||||||
<div v-if="showAllSprites" class="space-y-2">
|
<div v-if="showAllSprites" class="border-t border-gray-100 dark:border-gray-700 p-4 flex-shrink-0">
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between mb-3">
|
||||||
<h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 uppercase tracking-wide">Frames</h3>
|
<h3 class="text-xs font-bold text-gray-400 dark:text-gray-500 uppercase tracking-wider">Visible Frames</h3>
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<button @click="showAllFrames" class="px-2 py-1 text-xs bg-blue-500 hover:bg-blue-600 text-white rounded transition-colors">All</button>
|
<button @click="showAllFrames" class="px-2 py-1 text-[10px] font-medium bg-blue-50 text-blue-600 hover:bg-blue-100 dark:bg-blue-900/30 dark:text-blue-300 dark:hover:bg-blue-900/50 rounded transition-colors">All</button>
|
||||||
<button @click="hideAllFrames" class="px-2 py-1 text-xs bg-gray-500 hover:bg-gray-600 text-white rounded transition-colors">None</button>
|
<button @click="hideAllFrames" class="px-2 py-1 text-[10px] font-medium bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600 rounded transition-colors">None</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="rounded-md border border-gray-300 dark:border-gray-600 dark:bg-gray-800">
|
<div class="bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700 p-2">
|
||||||
<div class="max-h-[180px] overflow-y-auto">
|
<div class="max-h-[150px] overflow-y-auto pr-1 custom-scrollbar">
|
||||||
<div class="space-y-0.5 p-1">
|
<div class="space-y-1">
|
||||||
<div v-for="(sprite, index) in compositeFrames" :key="sprite.id" class="flex items-center gap-2 px-2 py-1.5 hover:bg-gray-50 dark:hover:bg-gray-700 cursor-pointer rounded" @click="toggleHiddenFrame(index)">
|
<div v-for="(sprite, index) in compositeFrames" :key="sprite.id" class="flex items-center gap-3 px-2 py-1.5 hover:bg-white dark:hover:bg-gray-700 cursor-pointer rounded-md transition-colors group" @click="toggleHiddenFrame(index)">
|
||||||
<input type="checkbox" :checked="!hiddenFrames.includes(index)" class="w-3.5 h-3.5 text-blue-500 focus:ring-blue-400 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700" @click.stop @change="toggleHiddenFrame(index)" />
|
<input
|
||||||
<div class="w-8 h-8 bg-gray-100 dark:bg-gray-700 rounded flex items-center justify-center overflow-hidden flex-shrink-0">
|
type="checkbox"
|
||||||
<img :src="sprite.img.src" class="max-w-full max-h-full object-contain" :style="settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}" />
|
:checked="!hiddenFrames.includes(index)"
|
||||||
|
class="w-4 h-4 text-blue-600 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
|
||||||
|
@click.stop
|
||||||
|
@change="toggleHiddenFrame(index)"
|
||||||
|
/>
|
||||||
|
<div class="w-8 h-8 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded flex items-center justify-center overflow-hidden flex-shrink-0 shadow-sm">
|
||||||
|
<img :src="sprite.url" class="max-w-full max-h-full object-contain" :style="{ ...(settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}), transform: `rotate(${sprite.rotation || 0}deg) scale(${sprite.flipX ? -1 : 1}, ${sprite.flipY ? -1 : 1})` }" />
|
||||||
</div>
|
</div>
|
||||||
<span class="text-xs dark:text-gray-200">{{ index + 1 }}</span>
|
<span class="text-xs font-mono text-gray-600 dark:text-gray-300 group-hover:text-gray-900 dark:group-hover:text-gray-100">Frame {{ index + 1 }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -153,18 +270,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<input ref="fileInput" type="file" accept="image/*" class="hidden" @change="handleFileChange" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, watch, onUnmounted, computed } from 'vue';
|
import { ref, onMounted, watch, onUnmounted, computed, toRef } from 'vue';
|
||||||
import { useSettingsStore } from '@/stores/useSettingsStore';
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
import type { Layer, Sprite } from '@/types/sprites';
|
import type { Layer, Sprite } from '@/types/sprites';
|
||||||
import { getMaxDimensionsAcrossLayers } from '@/composables/useLayers';
|
|
||||||
import { useCanvas2D } from '@/composables/useCanvas2D';
|
|
||||||
import { useZoom } from '@/composables/useZoom';
|
import { useZoom } from '@/composables/useZoom';
|
||||||
import { useAnimationFrames } from '@/composables/useAnimationFrames';
|
import { useAnimationFrames } from '@/composables/useAnimationFrames';
|
||||||
import { calculateNegativeSpacing } from '@/composables/useNegativeSpacing';
|
import { useGridMetrics } from '@/composables/useGridMetrics';
|
||||||
|
import { useBackgroundStyles } from '@/composables/useBackgroundStyles';
|
||||||
|
import CopyToFrameModal from './utilities/CopyToFrameModal.vue';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
layers: Layer[];
|
layers: Layer[];
|
||||||
@@ -174,16 +293,19 @@
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'updateSprite', id: string, x: number, y: number): void;
|
(e: 'updateSprite', id: string, x: number, y: number): void;
|
||||||
|
(e: 'updateSpriteInLayer', layerId: string, spriteId: string, x: number, y: number): void;
|
||||||
|
(e: 'dropSprite', layerId: string, frameIndex: number, files: File[]): void;
|
||||||
|
(e: 'rotateSprite', id: string, angle: number): void;
|
||||||
|
(e: 'flipSprite', id: string, direction: 'horizontal' | 'vertical'): void;
|
||||||
|
(e: 'copySpriteToFrame', spriteId: string, targetLayerId: string, targetFrameIndex: number): void;
|
||||||
|
(e: 'replaceSprite', id: string, file: File): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const previewCanvasRef = ref<HTMLCanvasElement | null>(null);
|
const previewContainerRef = ref<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
// Get settings from store
|
// Get settings from store
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
// Initialize composables
|
|
||||||
const canvas2D = useCanvas2D(previewCanvasRef);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
zoom,
|
zoom,
|
||||||
increase: increaseZoom,
|
increase: increaseZoom,
|
||||||
@@ -206,14 +328,55 @@
|
|||||||
}
|
}
|
||||||
return frames;
|
return frames;
|
||||||
},
|
},
|
||||||
onDraw: drawPreviewCanvas,
|
onDraw: () => {}, // No longer needed for canvas drawing
|
||||||
});
|
});
|
||||||
|
|
||||||
// Preview state
|
// Preview state
|
||||||
const isDraggable = ref(false);
|
const isDraggable = ref(false);
|
||||||
|
const repositionAllLayers = ref(false);
|
||||||
|
const arrowKeyMovement = ref(false);
|
||||||
const showAllSprites = ref(false);
|
const showAllSprites = ref(false);
|
||||||
|
const isDragOver = ref(false);
|
||||||
|
|
||||||
|
// Context menu state
|
||||||
|
const showContextMenu = ref(false);
|
||||||
|
const contextMenuX = ref(0);
|
||||||
|
const contextMenuY = ref(0);
|
||||||
|
const contextMenuSpriteId = ref<string | null>(null);
|
||||||
|
const contextMenuLayerId = ref<string | null>(null);
|
||||||
|
const fileInput = ref<HTMLInputElement | null>(null);
|
||||||
|
const replacingSpriteId = ref<string | null>(null);
|
||||||
|
|
||||||
|
// Copy to frame modal state
|
||||||
|
const showCopyToFrameModal = ref(false);
|
||||||
|
const copyTargetLayerId = ref(props.activeLayerId);
|
||||||
|
|
||||||
|
// Drag and drop for new sprites
|
||||||
|
const onDragOver = () => {
|
||||||
|
isDragOver.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDragLeave = () => {
|
||||||
|
isDragOver.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDrop = (event: DragEvent) => {
|
||||||
|
isDragOver.value = false;
|
||||||
|
|
||||||
|
if (!event.dataTransfer?.files.length) return;
|
||||||
|
|
||||||
|
const files = Array.from(event.dataTransfer.files).filter(file => file.type.startsWith('image/'));
|
||||||
|
|
||||||
|
if (files.length === 0) return;
|
||||||
|
|
||||||
|
emit('dropSprite', props.activeLayerId, currentFrameIndex.value, files);
|
||||||
|
};
|
||||||
|
|
||||||
const compositeFrames = computed<Sprite[]>(() => {
|
const compositeFrames = computed<Sprite[]>(() => {
|
||||||
|
// Show frames from the active layer for the thumbnail list
|
||||||
|
const activeLayer = props.layers.find(l => l.id === props.activeLayerId);
|
||||||
|
if (!activeLayer) {
|
||||||
|
// Fallback to first visible layer if no active layer
|
||||||
const v = getVisibleLayers();
|
const v = getVisibleLayers();
|
||||||
const len = maxFrames();
|
const len = maxFrames();
|
||||||
const arr: Sprite[] = [];
|
const arr: Sprite[] = [];
|
||||||
@@ -222,6 +385,8 @@
|
|||||||
if (s) arr.push(s);
|
if (s) arr.push(s);
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
|
}
|
||||||
|
return activeLayer.sprites;
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentFrameSprite = computed<Sprite | null>(() => {
|
const currentFrameSprite = computed<Sprite | null>(() => {
|
||||||
@@ -230,98 +395,91 @@
|
|||||||
return layer.sprites[currentFrameIndex.value] || null;
|
return layer.sprites[currentFrameIndex.value] || null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Use the new useGridMetrics composable for consistent calculations
|
||||||
|
const { gridMetrics, getCellPosition: getCellPositionHelper } = useGridMetrics({
|
||||||
|
layers: toRef(props, 'layers'),
|
||||||
|
negativeSpacingEnabled: toRef(settingsStore, 'negativeSpacingEnabled'),
|
||||||
|
manualCellSizeEnabled: toRef(settingsStore, 'manualCellSizeEnabled'),
|
||||||
|
manualCellWidth: toRef(settingsStore, 'manualCellWidth'),
|
||||||
|
manualCellHeight: toRef(settingsStore, 'manualCellHeight'),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Helper function to get cell position (same as SpriteCanvas)
|
||||||
|
const getCellPosition = (index: number) => {
|
||||||
|
return getCellPositionHelper(index, props.columns, gridMetrics.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Computed cell dimensions (for backward compatibility with existing code)
|
||||||
|
const cellDimensions = computed(() => ({
|
||||||
|
cellWidth: gridMetrics.value.maxWidth,
|
||||||
|
cellHeight: gridMetrics.value.maxHeight,
|
||||||
|
negativeSpacing: gridMetrics.value.negativeSpacing,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Use the new useBackgroundStyles composable for consistent background styling
|
||||||
|
const {
|
||||||
|
backgroundImage: previewBackgroundImage,
|
||||||
|
backgroundSize: previewBackgroundSize,
|
||||||
|
backgroundPosition: previewBackgroundPosition,
|
||||||
|
} = useBackgroundStyles({
|
||||||
|
backgroundColor: toRef(settingsStore, 'backgroundColor'),
|
||||||
|
checkerboardEnabled: toRef(settingsStore, 'checkerboardEnabled'),
|
||||||
|
darkMode: toRef(settingsStore, 'darkMode'),
|
||||||
|
});
|
||||||
|
|
||||||
|
const getPreviewBackgroundImage = () => previewBackgroundImage.value;
|
||||||
|
|
||||||
// Dragging state
|
// Dragging state
|
||||||
const isDragging = ref(false);
|
const isDragging = ref(false);
|
||||||
const activeSpriteId = ref<string | null>(null);
|
const activeSpriteId = ref<string | null>(null);
|
||||||
|
const activeLayerId = ref<string | null>(null);
|
||||||
const dragStartX = ref(0);
|
const dragStartX = ref(0);
|
||||||
const dragStartY = ref(0);
|
const dragStartY = ref(0);
|
||||||
const spritePosBeforeDrag = ref({ x: 0, y: 0 });
|
const spritePosBeforeDrag = ref({ x: 0, y: 0 });
|
||||||
|
const allSpritesPosBeforeDrag = ref<Map<string, { x: number; y: number }>>(new Map());
|
||||||
// Canvas drawing
|
|
||||||
|
|
||||||
function drawPreviewCanvas() {
|
|
||||||
if (!previewCanvasRef.value || !canvas2D.ctx.value) return;
|
|
||||||
const visibleLayers = getVisibleLayers();
|
|
||||||
if (!visibleLayers.length || !visibleLayers.some(l => l.sprites.length)) return;
|
|
||||||
|
|
||||||
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers);
|
|
||||||
const allSprites = visibleLayers.flatMap(l => l.sprites);
|
|
||||||
const negativeSpacing = calculateNegativeSpacing(allSprites, settingsStore.negativeSpacingEnabled);
|
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
|
||||||
|
|
||||||
// Apply pixel art optimization
|
|
||||||
canvas2D.applySmoothing();
|
|
||||||
|
|
||||||
// Set canvas size to fit one sprite cell (expanded with negative spacing)
|
|
||||||
canvas2D.setCanvasSize(cellWidth, cellHeight);
|
|
||||||
|
|
||||||
// Clear canvas
|
|
||||||
canvas2D.clear();
|
|
||||||
|
|
||||||
// Draw grid background (cell)
|
|
||||||
canvas2D.fillRect(0, 0, cellWidth, cellHeight, '#f9fafb');
|
|
||||||
|
|
||||||
const frameIndex = currentFrameIndex.value;
|
|
||||||
|
|
||||||
if (showAllSprites.value) {
|
|
||||||
const len = maxFrames();
|
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
if (i === frameIndex || hiddenFrames.value.includes(i)) continue;
|
|
||||||
visibleLayers.forEach(layer => {
|
|
||||||
const sprite = layer.sprites[i];
|
|
||||||
if (!sprite) return;
|
|
||||||
canvas2D.drawImage(sprite.img, negativeSpacing + sprite.x, negativeSpacing + sprite.y, 0.3);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
visibleLayers.forEach(layer => {
|
|
||||||
const sprite = layer.sprites[frameIndex];
|
|
||||||
if (!sprite) return;
|
|
||||||
canvas2D.drawImage(sprite.img, negativeSpacing + sprite.x, negativeSpacing + sprite.y);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Draw cell border
|
|
||||||
canvas2D.strokeRect(0, 0, cellWidth, cellHeight, '#e5e7eb', 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drag functionality
|
// Drag functionality
|
||||||
const startDrag = (event: MouseEvent) => {
|
const startDrag = (event: MouseEvent, sprite: Sprite, layerId: string) => {
|
||||||
if (!isDraggable.value || !previewCanvasRef.value) return;
|
if (!isDraggable.value || !previewContainerRef.value) return;
|
||||||
|
|
||||||
const rect = previewCanvasRef.value.getBoundingClientRect();
|
const rect = previewContainerRef.value.getBoundingClientRect();
|
||||||
const scaleX = previewCanvasRef.value.width / (rect.width / zoom.value);
|
const scaleX = previewContainerRef.value.offsetWidth / (rect.width / zoom.value);
|
||||||
const scaleY = previewCanvasRef.value.height / (rect.height / zoom.value);
|
const scaleY = previewContainerRef.value.offsetHeight / (rect.height / zoom.value);
|
||||||
|
|
||||||
const mouseX = ((event.clientX - rect.left) / zoom.value) * scaleX;
|
const mouseX = ((event.clientX - rect.left) / zoom.value) * scaleX;
|
||||||
const mouseY = ((event.clientY - rect.top) / zoom.value) * scaleY;
|
const mouseY = ((event.clientY - rect.top) / zoom.value) * scaleY;
|
||||||
|
|
||||||
const activeSprite = props.layers.find(l => l.id === props.activeLayerId)?.sprites[currentFrameIndex.value];
|
if (repositionAllLayers.value) {
|
||||||
const vLayers = getVisibleLayers();
|
|
||||||
const allSprites = vLayers.flatMap(l => l.sprites);
|
|
||||||
const negativeSpacing = calculateNegativeSpacing(allSprites, settingsStore.negativeSpacingEnabled);
|
|
||||||
|
|
||||||
// Check if click is on sprite (accounting for negative spacing offset)
|
|
||||||
if (activeSprite) {
|
|
||||||
const spriteCanvasX = negativeSpacing + activeSprite.x;
|
|
||||||
const spriteCanvasY = negativeSpacing + activeSprite.y;
|
|
||||||
if (mouseX >= spriteCanvasX && mouseX <= spriteCanvasX + activeSprite.width && mouseY >= spriteCanvasY && mouseY <= spriteCanvasY + activeSprite.height) {
|
|
||||||
isDragging.value = true;
|
isDragging.value = true;
|
||||||
activeSpriteId.value = activeSprite.id;
|
activeSpriteId.value = 'ALL_LAYERS'; // Special marker for all layers
|
||||||
dragStartX.value = mouseX;
|
dragStartX.value = mouseX;
|
||||||
dragStartY.value = mouseY;
|
dragStartY.value = mouseY;
|
||||||
spritePosBeforeDrag.value = { x: activeSprite.x, y: activeSprite.y };
|
|
||||||
|
// Store initial positions for all sprites in this frame from all visible layers
|
||||||
|
allSpritesPosBeforeDrag.value.clear();
|
||||||
|
const visibleLayers = getVisibleLayers();
|
||||||
|
visibleLayers.forEach(layer => {
|
||||||
|
const s = layer.sprites[currentFrameIndex.value];
|
||||||
|
if (s) {
|
||||||
|
allSpritesPosBeforeDrag.value.set(s.id, { x: s.x, y: s.y });
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
isDragging.value = true;
|
||||||
|
activeSpriteId.value = sprite.id;
|
||||||
|
activeLayerId.value = layerId;
|
||||||
|
dragStartX.value = mouseX;
|
||||||
|
dragStartY.value = mouseY;
|
||||||
|
spritePosBeforeDrag.value = { x: sprite.x, y: sprite.y };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const drag = (event: MouseEvent) => {
|
const drag = (event: MouseEvent) => {
|
||||||
if (!isDragging.value || !activeSpriteId.value || !previewCanvasRef.value) return;
|
if (!isDragging.value || !activeSpriteId.value || !previewContainerRef.value) return;
|
||||||
|
|
||||||
const rect = previewCanvasRef.value.getBoundingClientRect();
|
const rect = previewContainerRef.value.getBoundingClientRect();
|
||||||
const scaleX = previewCanvasRef.value.width / (rect.width / zoom.value);
|
const scaleX = previewContainerRef.value.offsetWidth / (rect.width / zoom.value);
|
||||||
const scaleY = previewCanvasRef.value.height / (rect.height / zoom.value);
|
const scaleY = previewContainerRef.value.offsetHeight / (rect.height / zoom.value);
|
||||||
|
|
||||||
const mouseX = ((event.clientX - rect.left) / zoom.value) * scaleX;
|
const mouseX = ((event.clientX - rect.left) / zoom.value) * scaleX;
|
||||||
const mouseY = ((event.clientY - rect.top) / zoom.value) * scaleY;
|
const mouseY = ((event.clientY - rect.top) / zoom.value) * scaleY;
|
||||||
@@ -329,15 +487,32 @@
|
|||||||
const deltaX = Math.round(mouseX - dragStartX.value);
|
const deltaX = Math.round(mouseX - dragStartX.value);
|
||||||
const deltaY = Math.round(mouseY - dragStartY.value);
|
const deltaY = Math.round(mouseY - dragStartY.value);
|
||||||
|
|
||||||
const activeSprite = props.layers.find(l => l.id === props.activeLayerId)?.sprites[currentFrameIndex.value];
|
const { cellWidth, cellHeight, negativeSpacing } = cellDimensions.value;
|
||||||
if (!activeSprite || activeSprite.id !== activeSpriteId.value) return;
|
|
||||||
|
|
||||||
const vLayers = getVisibleLayers();
|
if (activeSpriteId.value === 'ALL_LAYERS') {
|
||||||
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(vLayers);
|
// Move all sprites in current frame from all visible layers
|
||||||
const allSprites = vLayers.flatMap(l => l.sprites);
|
const visibleLayers = getVisibleLayers();
|
||||||
const negativeSpacing = calculateNegativeSpacing(allSprites, settingsStore.negativeSpacingEnabled);
|
visibleLayers.forEach(layer => {
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
const sprite = layer.sprites[currentFrameIndex.value];
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
if (!sprite) return;
|
||||||
|
|
||||||
|
const originalPos = allSpritesPosBeforeDrag.value.get(sprite.id);
|
||||||
|
if (!originalPos) return;
|
||||||
|
|
||||||
|
// Calculate new position with constraints
|
||||||
|
let newX = Math.round(originalPos.x + deltaX);
|
||||||
|
let newY = Math.round(originalPos.y + deltaY);
|
||||||
|
|
||||||
|
// Constrain movement within expanded cell
|
||||||
|
newX = Math.max(-negativeSpacing, Math.min(cellWidth - negativeSpacing - sprite.width, newX));
|
||||||
|
newY = Math.max(-negativeSpacing, Math.min(cellHeight - negativeSpacing - sprite.height, newY));
|
||||||
|
|
||||||
|
emit('updateSpriteInLayer', layer.id, sprite.id, newX, newY);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Move only the active layer sprite
|
||||||
|
const activeSprite = props.layers.find(l => l.id === activeLayerId.value)?.sprites[currentFrameIndex.value];
|
||||||
|
if (!activeSprite || activeSprite.id !== activeSpriteId.value) return;
|
||||||
|
|
||||||
// Calculate new position with constraints and round to integers
|
// Calculate new position with constraints and round to integers
|
||||||
let newX = Math.round(spritePosBeforeDrag.value.x + deltaX);
|
let newX = Math.round(spritePosBeforeDrag.value.x + deltaX);
|
||||||
@@ -348,15 +523,16 @@
|
|||||||
newY = Math.max(-negativeSpacing, Math.min(cellHeight - negativeSpacing - activeSprite.height, newY));
|
newY = Math.max(-negativeSpacing, Math.min(cellHeight - negativeSpacing - activeSprite.height, newY));
|
||||||
|
|
||||||
emit('updateSprite', activeSpriteId.value, newX, newY);
|
emit('updateSprite', activeSpriteId.value, newX, newY);
|
||||||
drawPreviewCanvas();
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopDrag = () => {
|
const stopDrag = () => {
|
||||||
isDragging.value = false;
|
isDragging.value = false;
|
||||||
activeSpriteId.value = null;
|
activeSpriteId.value = null;
|
||||||
|
activeLayerId.value = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTouchStart = (event: TouchEvent) => {
|
const handleTouchStart = (event: TouchEvent, sprite: Sprite, layerId: string) => {
|
||||||
if (!isDraggable.value) return;
|
if (!isDraggable.value) return;
|
||||||
|
|
||||||
if (event.touches.length === 1) {
|
if (event.touches.length === 1) {
|
||||||
@@ -365,7 +541,7 @@
|
|||||||
clientX: touch.clientX,
|
clientX: touch.clientX,
|
||||||
clientY: touch.clientY,
|
clientY: touch.clientY,
|
||||||
});
|
});
|
||||||
startDrag(mouseEvent);
|
startDrag(mouseEvent, sprite, layerId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -386,42 +562,164 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Arrow key movement handler
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (!isDraggable.value || !arrowKeyMovement.value) return;
|
||||||
|
|
||||||
|
const arrowKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
|
||||||
|
if (!arrowKeys.includes(event.key)) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
let deltaX = 0;
|
||||||
|
let deltaY = 0;
|
||||||
|
const step = event.shiftKey ? 10 : 1; // Hold Shift for larger steps
|
||||||
|
|
||||||
|
switch (event.key) {
|
||||||
|
case 'ArrowUp':
|
||||||
|
deltaY = -step;
|
||||||
|
break;
|
||||||
|
case 'ArrowDown':
|
||||||
|
deltaY = step;
|
||||||
|
break;
|
||||||
|
case 'ArrowLeft':
|
||||||
|
deltaX = -step;
|
||||||
|
break;
|
||||||
|
case 'ArrowRight':
|
||||||
|
deltaX = step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { cellWidth, cellHeight, negativeSpacing } = cellDimensions.value;
|
||||||
|
|
||||||
|
if (repositionAllLayers.value) {
|
||||||
|
// Move all sprites in current frame from all visible layers
|
||||||
|
const visibleLayers = getVisibleLayers();
|
||||||
|
visibleLayers.forEach(layer => {
|
||||||
|
const sprite = layer.sprites[currentFrameIndex.value];
|
||||||
|
if (!sprite) return;
|
||||||
|
|
||||||
|
let newX = Math.round(sprite.x + deltaX);
|
||||||
|
let newY = Math.round(sprite.y + deltaY);
|
||||||
|
|
||||||
|
// Constrain movement within expanded cell
|
||||||
|
newX = Math.max(-negativeSpacing, Math.min(cellWidth - negativeSpacing - sprite.width, newX));
|
||||||
|
newY = Math.max(-negativeSpacing, Math.min(cellHeight - negativeSpacing - sprite.height, newY));
|
||||||
|
|
||||||
|
emit('updateSpriteInLayer', layer.id, sprite.id, newX, newY);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Move only the active layer sprite
|
||||||
|
const activeLayer = props.layers.find(l => l.id === props.activeLayerId);
|
||||||
|
if (!activeLayer) return;
|
||||||
|
|
||||||
|
const sprite = activeLayer.sprites[currentFrameIndex.value];
|
||||||
|
if (!sprite) return;
|
||||||
|
|
||||||
|
let newX = Math.round(sprite.x + deltaX);
|
||||||
|
let newY = Math.round(sprite.y + deltaY);
|
||||||
|
|
||||||
|
// Constrain movement within expanded cell
|
||||||
|
newX = Math.max(-negativeSpacing, Math.min(cellWidth - negativeSpacing - sprite.width, newX));
|
||||||
|
newY = Math.max(-negativeSpacing, Math.min(cellHeight - negativeSpacing - sprite.height, newY));
|
||||||
|
|
||||||
|
emit('updateSprite', sprite.id, newX, newY);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Lifecycle hooks
|
// Lifecycle hooks
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
canvas2D.initContext();
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
drawPreviewCanvas();
|
|
||||||
|
|
||||||
// Listen for forceRedraw event from App.vue
|
|
||||||
window.addEventListener('forceRedraw', handleForceRedraw);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
stopAnimation();
|
stopAnimation();
|
||||||
window.removeEventListener('forceRedraw', handleForceRedraw);
|
window.removeEventListener('keydown', handleKeyDown);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handler for force redraw event
|
// Watchers - most canvas-related watchers removed
|
||||||
const handleForceRedraw = () => {
|
// Keep layer watchers to ensure reactivity
|
||||||
const allSprites = props.layers.flatMap(l => l.sprites);
|
watch(
|
||||||
canvas2D.ensureIntegerPositions(allSprites);
|
() => props.layers,
|
||||||
canvas2D.applySmoothing();
|
() => {},
|
||||||
drawPreviewCanvas();
|
{ deep: true }
|
||||||
|
);
|
||||||
|
watch(
|
||||||
|
() => props.activeLayerId,
|
||||||
|
() => {}
|
||||||
|
);
|
||||||
|
watch(currentFrameIndex, () => {});
|
||||||
|
|
||||||
|
// Context menu functions
|
||||||
|
const openContextMenu = (event: MouseEvent, sprite: Sprite, layerId: string) => {
|
||||||
|
event.preventDefault();
|
||||||
|
contextMenuSpriteId.value = sprite.id;
|
||||||
|
contextMenuLayerId.value = layerId;
|
||||||
|
contextMenuX.value = event.clientX;
|
||||||
|
contextMenuY.value = event.clientY;
|
||||||
|
showContextMenu.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Watchers
|
const hideContextMenu = () => {
|
||||||
watch(() => props.layers, drawPreviewCanvas, { deep: true });
|
showContextMenu.value = false;
|
||||||
watch(currentFrameIndex, drawPreviewCanvas);
|
contextMenuSpriteId.value = null;
|
||||||
watch(zoom, drawPreviewCanvas);
|
contextMenuLayerId.value = null;
|
||||||
watch(isDraggable, drawPreviewCanvas);
|
};
|
||||||
watch(showAllSprites, drawPreviewCanvas);
|
|
||||||
watch(hiddenFrames, drawPreviewCanvas);
|
|
||||||
watch(() => settingsStore.pixelPerfect, drawPreviewCanvas);
|
|
||||||
watch(() => settingsStore.negativeSpacingEnabled, drawPreviewCanvas);
|
|
||||||
|
|
||||||
// Initial draw
|
const rotateSpriteInMenu = (angle: number) => {
|
||||||
if (props.layers.some(l => l.sprites.length > 0)) {
|
if (contextMenuSpriteId.value) {
|
||||||
drawPreviewCanvas();
|
emit('rotateSprite', contextMenuSpriteId.value, angle);
|
||||||
}
|
}
|
||||||
|
hideContextMenu();
|
||||||
|
};
|
||||||
|
|
||||||
|
const flipSpriteInMenu = (direction: 'horizontal' | 'vertical') => {
|
||||||
|
if (contextMenuSpriteId.value) {
|
||||||
|
emit('flipSprite', contextMenuSpriteId.value, direction);
|
||||||
|
}
|
||||||
|
hideContextMenu();
|
||||||
|
};
|
||||||
|
|
||||||
|
const openCopyToFrameModal = () => {
|
||||||
|
if (contextMenuSpriteId.value) {
|
||||||
|
copyTargetLayerId.value = contextMenuLayerId.value || props.activeLayerId;
|
||||||
|
showCopyToFrameModal.value = true;
|
||||||
|
showContextMenu.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeCopyToFrameModal = () => {
|
||||||
|
showCopyToFrameModal.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmCopyToFrame = (targetLayerId: string, targetFrameIndex: number) => {
|
||||||
|
if (contextMenuSpriteId.value) {
|
||||||
|
emit('copySpriteToFrame', contextMenuSpriteId.value, targetLayerId, targetFrameIndex);
|
||||||
|
closeCopyToFrameModal();
|
||||||
|
contextMenuSpriteId.value = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const replaceSprite = () => {
|
||||||
|
if (contextMenuSpriteId.value && fileInput.value) {
|
||||||
|
replacingSpriteId.value = contextMenuSpriteId.value;
|
||||||
|
fileInput.value.click();
|
||||||
|
hideContextMenu();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFileChange = (event: Event) => {
|
||||||
|
const input = event.target as HTMLInputElement;
|
||||||
|
|
||||||
|
if (input.files && input.files.length > 0) {
|
||||||
|
const file = input.files[0];
|
||||||
|
if (file.type.startsWith('image/') && replacingSpriteId.value) {
|
||||||
|
emit('replaceSprite', replacingSpriteId.value, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replacingSpriteId.value = null;
|
||||||
|
input.value = '';
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -444,4 +742,36 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Custom scrollbar for controls panel */
|
||||||
|
.custom-scrollbar::-webkit-scrollbar,
|
||||||
|
.lg\:overflow-y-auto::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-scrollbar::-webkit-scrollbar-track,
|
||||||
|
.lg\:overflow-y-auto::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-scrollbar::-webkit-scrollbar-thumb,
|
||||||
|
.lg\:overflow-y-auto::-webkit-scrollbar-thumb {
|
||||||
|
background-color: rgba(156, 163, 175, 0.5);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-scrollbar::-webkit-scrollbar-thumb:hover,
|
||||||
|
.lg\:overflow-y-auto::-webkit-scrollbar-thumb:hover {
|
||||||
|
background-color: rgba(156, 163, 175, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .custom-scrollbar::-webkit-scrollbar-thumb,
|
||||||
|
:global(.dark) .lg\:overflow-y-auto::-webkit-scrollbar-thumb {
|
||||||
|
background-color: rgba(75, 85, 99, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .custom-scrollbar::-webkit-scrollbar-thumb:hover,
|
||||||
|
:global(.dark) .lg\:overflow-y-auto::-webkit-scrollbar-thumb:hover {
|
||||||
|
background-color: rgba(75, 85, 99, 0.8);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,91 +1,92 @@
|
|||||||
<template>
|
<template>
|
||||||
<Modal :is-open="isOpen" @close="cancel" title="Split spritesheet">
|
<Modal :is-open="isOpen" @close="cancel" title="Split spritesheet">
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
<div class="flex flex-col space-y-4">
|
<!-- Preview Image -->
|
||||||
<div class="flex items-center justify-center mb-4">
|
<div class="flex items-center justify-center">
|
||||||
<img :src="imageUrl" alt="Spritesheet" class="max-w-full max-h-48 sm:max-h-64 border border-gray-300 dark:border-gray-600 rounded-lg" :style="settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}" />
|
<img :src="imageUrl" alt="Spritesheet" class="max-w-full max-h-48 sm:max-h-64 border border-gray-300 dark:border-gray-600 rounded-lg" :style="settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
<!-- Detection Mode -->
|
||||||
|
<div class="space-y-4">
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<label for="detection-method" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Detection Method</label>
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300"> Detection Mode </label>
|
||||||
<select
|
<div class="grid grid-cols-2 gap-3">
|
||||||
id="detection-method"
|
<button @click="detectionMode = 'grid'" :class="['px-4 py-3 rounded-lg border-2 text-left transition-all', detectionMode === 'grid' ? 'border-blue-500 bg-blue-50 dark:bg-blue-900/30' : 'border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500']">
|
||||||
v-model="detectionMethod"
|
<div class="font-medium text-gray-900 dark:text-gray-100">Grid</div>
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-400 dark:focus:border-blue-400"
|
<div class="text-xs text-gray-500 dark:text-gray-400">Split by cell size</div>
|
||||||
data-rybbit-event="spritesheet-detection-method"
|
</button>
|
||||||
>
|
<button @click="detectionMode = 'auto'" :class="['px-4 py-3 rounded-lg border-2 text-left transition-all', detectionMode === 'auto' ? 'border-blue-500 bg-blue-50 dark:bg-blue-900/30' : 'border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500']">
|
||||||
<option value="irregular">Auto-detect</option>
|
<div class="font-medium text-gray-900 dark:text-gray-100">Auto-detect</div>
|
||||||
<option value="manual">Manual (specify rows and columns)</option>
|
<div class="text-xs text-gray-500 dark:text-gray-400">Find individual sprites</div>
|
||||||
</select>
|
</button>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="detectionMethod === 'auto' || detectionMethod === 'irregular'" class="space-y-2">
|
|
||||||
<label for="sensitivity" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Detection Sensitivity</label>
|
|
||||||
<input type="range" id="sensitivity" v-model="sensitivity" min="1" max="100" class="w-full dark:accent-blue-400" data-rybbit-event="spritesheet-sensitivity" />
|
|
||||||
<div class="text-xs text-gray-500 dark:text-gray-400 flex justify-between">
|
|
||||||
<span>Low</span>
|
|
||||||
<span>High</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="detectionMethod === 'manual'" class="space-y-2">
|
<!-- Grid Mode Options -->
|
||||||
<label for="rows" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Rows</label>
|
<div v-if="detectionMode === 'grid'" class="space-y-4">
|
||||||
<input
|
<div class="grid grid-cols-2 gap-4">
|
||||||
type="number"
|
<div class="space-y-1">
|
||||||
id="rows"
|
<label for="cell-width" class="block text-sm font-medium text-gray-700 dark:text-gray-300"> Cell Width (px) </label>
|
||||||
v-model.number="rows"
|
<input type="number" id="cell-width" v-model.number="cellWidth" min="1" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500" />
|
||||||
min="1"
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-400 dark:focus:border-blue-400"
|
|
||||||
data-rybbit-event="spritesheet-rows"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="space-y-1">
|
||||||
<div v-if="detectionMethod === 'manual'" class="space-y-2">
|
<label for="cell-height" class="block text-sm font-medium text-gray-700 dark:text-gray-300"> Cell Height (px) </label>
|
||||||
<label for="columns" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Columns</label>
|
<input type="number" id="cell-height" v-model.number="cellHeight" min="1" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500" />
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
id="columns"
|
|
||||||
v-model.number="columns"
|
|
||||||
min="1"
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-400 dark:focus:border-blue-400"
|
|
||||||
data-rybbit-event="spritesheet-columns"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-2">
|
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<input type="checkbox" id="remove-empty" v-model="removeEmpty" class="h-4 w-4 text-blue-600 dark:text-blue-400 focus:ring-blue-500 dark:focus:ring-blue-400 border-gray-300 dark:border-gray-600 rounded" data-rybbit-event="spritesheet-remove-empty" />
|
<input type="checkbox" id="preserve-cell-size" v-model="preserveCellSize" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded" />
|
||||||
<label for="remove-empty" class="ml-2 block text-sm text-gray-700 dark:text-gray-300"> Remove empty sprites (transparent/background color) </label>
|
<label for="preserve-cell-size" class="ml-2 block text-sm text-gray-700 dark:text-gray-300"> Preserve cell size (keep transparent padding) </label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="imageElement" class="text-xs text-gray-500 dark:text-gray-400">Image: {{ imageElement.width }}×{{ imageElement.height }}px → {{ gridCols }}×{{ gridRows }} cells</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Auto-detect Options -->
|
||||||
|
<div v-if="detectionMode === 'auto'" class="space-y-2">
|
||||||
|
<label for="sensitivity" class="block text-sm font-medium text-gray-700 dark:text-gray-300"> Detection Sensitivity </label>
|
||||||
|
<input type="range" id="sensitivity" v-model.number="sensitivity" min="1" max="100" class="w-full dark:accent-blue-400" />
|
||||||
|
<div class="text-xs text-gray-500 dark:text-gray-400 flex justify-between">
|
||||||
|
<span>Low (more sprites)</span>
|
||||||
|
<span>High (fewer sprites)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="previewSprites.length > 0" class="space-y-2">
|
<!-- Common Options -->
|
||||||
<h3 class="text-sm font-medium text-gray-700 dark:text-gray-300">Preview ({{ previewSprites.length }} sprites)</h3>
|
<div class="flex items-center">
|
||||||
<div class="grid grid-cols-3 sm:grid-cols-6 md:grid-cols-8 gap-2 max-h-96 overflow-y-auto p-2 border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800">
|
<input type="checkbox" id="remove-empty" v-model="removeEmpty" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded" />
|
||||||
<div v-for="(sprite, index) in previewSprites" :key="index" class="relative border border-gray-300 dark:border-gray-600 rounded bg-gray-100 dark:bg-gray-700 flex items-center justify-center" :style="{ width: '80px', height: '80px' }">
|
<label for="remove-empty" class="ml-2 block text-sm text-gray-700 dark:text-gray-300"> Remove empty sprites </label>
|
||||||
<img :src="sprite.url" alt="Sprite preview" class="max-w-full max-h-full" :style="settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Preview -->
|
||||||
|
<div v-if="previewSprites.length > 0 || isProcessing" class="space-y-2">
|
||||||
|
<h3 class="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||||
|
<span v-if="isProcessing">Detecting sprites...</span>
|
||||||
|
<span v-else>Preview ({{ previewSprites.length }} sprites)</span>
|
||||||
|
</h3>
|
||||||
|
<div class="grid grid-cols-4 sm:grid-cols-6 md:grid-cols-8 gap-2 max-h-80 overflow-y-auto p-2 border border-gray-200 dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-800">
|
||||||
|
<div v-for="(sprite, index) in previewSprites" :key="index" class="relative border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 flex items-center justify-center aspect-square">
|
||||||
|
<img :src="sprite.url" alt="Sprite" class="max-w-full max-h-full object-contain" :style="settingsStore.pixelPerfect ? { 'image-rendering': 'pixelated' } : {}" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col-reverse sm:flex-row sm:justify-end space-y-3 space-y-reverse sm:space-y-0 sm:space-x-3">
|
<!-- Actions -->
|
||||||
|
<div class="flex justify-end space-x-3">
|
||||||
<button
|
<button
|
||||||
@click="cancel"
|
@click="cancel"
|
||||||
class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 dark:focus:ring-offset-gray-800"
|
class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
|
||||||
data-rybbit-event="spritesheet-cancel"
|
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
@click="confirm"
|
@click="confirm"
|
||||||
class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 dark:focus:ring-offset-gray-800"
|
|
||||||
:disabled="previewSprites.length === 0 || isProcessing"
|
:disabled="previewSprites.length === 0 || isProcessing"
|
||||||
data-rybbit-event="spritesheet-split"
|
class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
|
||||||
>
|
>
|
||||||
Split spritesheet
|
{{ isProcessing ? 'Processing...' : 'Split spritesheet' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -93,19 +94,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, onUnmounted } from 'vue';
|
import { ref, watch, computed, onUnmounted } from 'vue';
|
||||||
import Modal from './utilities/Modal.vue';
|
import Modal from './utilities/Modal.vue';
|
||||||
import { useSettingsStore } from '@/stores/useSettingsStore';
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
|
import { useSpritesheetSplitter } from '@/composables/useSpritesheetSplitter';
|
||||||
import type { SpriteFile } from '@/types/sprites';
|
import type { SpriteFile } from '@/types/sprites';
|
||||||
|
import type { DetectionMode, SpritePreview } from '@/types/spritesheet';
|
||||||
interface SpritePreview {
|
|
||||||
url: string;
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
isEmpty: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -115,93 +109,80 @@
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'close'): void;
|
(e: 'close'): void;
|
||||||
(e: 'split', sprites: SpriteFile[]): void; // Change from File[] to SpriteFile[]
|
(e: 'split', sprites: SpriteFile[]): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// Get settings from store
|
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
const splitter = useSpritesheetSplitter();
|
||||||
|
|
||||||
// State
|
// State
|
||||||
const detectionMethod = ref<'manual' | 'auto' | 'irregular'>('irregular');
|
const detectionMode = ref<DetectionMode>('grid');
|
||||||
const rows = ref(1);
|
const cellWidth = ref(64);
|
||||||
const columns = ref(1);
|
const cellHeight = ref(64);
|
||||||
const sensitivity = ref(50);
|
const sensitivity = ref(50);
|
||||||
const removeEmpty = ref(true);
|
const removeEmpty = ref(true);
|
||||||
|
const preserveCellSize = ref(true);
|
||||||
const previewSprites = ref<SpritePreview[]>([]);
|
const previewSprites = ref<SpritePreview[]>([]);
|
||||||
const isProcessing = ref(false);
|
const isProcessing = ref(false);
|
||||||
const imageElement = ref<HTMLImageElement | null>(null);
|
const imageElement = ref<HTMLImageElement | null>(null);
|
||||||
const irregularWorker = ref<Worker | null>(null);
|
|
||||||
|
|
||||||
// Cache for sprite detection results
|
// Computed
|
||||||
const detectionCache = new Map<string, SpritePreview[]>();
|
const gridCols = computed(() => (imageElement.value && cellWidth.value > 0 ? Math.floor(imageElement.value.width / cellWidth.value) : 0));
|
||||||
|
|
||||||
// Generate cache key for current detection settings
|
const gridRows = computed(() => (imageElement.value && cellHeight.value > 0 ? Math.floor(imageElement.value.height / cellHeight.value) : 0));
|
||||||
function getCacheKey(url: string, method: string, sensitivity: number, removeEmpty: boolean): string {
|
|
||||||
return `${url}-${method}-${sensitivity}-${removeEmpty}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the image when the component is mounted or the URL changes
|
// Load image and set initial cell size
|
||||||
watch(() => props.imageUrl, loadImage, { immediate: true });
|
watch(
|
||||||
|
() => props.imageUrl,
|
||||||
function loadImage() {
|
url => {
|
||||||
if (!props.imageUrl) return;
|
if (!url) return;
|
||||||
|
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
imageElement.value = img;
|
imageElement.value = img;
|
||||||
|
|
||||||
// Set default rows and columns based on image dimensions
|
// Set suggested cell size
|
||||||
// This is a simple heuristic - for pixel art, we might want to detect sprite size
|
const suggested = splitter.getSuggestedCellSize(img.width, img.height);
|
||||||
const aspectRatio = img.width / img.height;
|
cellWidth.value = suggested.width;
|
||||||
|
cellHeight.value = suggested.height;
|
||||||
|
|
||||||
if (aspectRatio > 1) {
|
|
||||||
// Landscape orientation - likely more columns than rows
|
|
||||||
columns.value = Math.min(Math.ceil(Math.sqrt(aspectRatio * 4)), 8);
|
|
||||||
rows.value = Math.ceil(4 / columns.value);
|
|
||||||
} else {
|
|
||||||
// Portrait orientation - likely more rows than columns
|
|
||||||
rows.value = Math.min(Math.ceil(Math.sqrt(4 / aspectRatio)), 8);
|
|
||||||
columns.value = Math.ceil(4 / rows.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate initial preview
|
|
||||||
generatePreview();
|
generatePreview();
|
||||||
};
|
};
|
||||||
img.src = props.imageUrl;
|
img.src = url;
|
||||||
}
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
// Generate preview of split sprites with caching
|
// Regenerate preview when options change
|
||||||
|
watch([detectionMode, cellWidth, cellHeight, sensitivity, removeEmpty, preserveCellSize], () => {
|
||||||
|
if (imageElement.value) {
|
||||||
|
generatePreview();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Generate preview
|
||||||
async function generatePreview() {
|
async function generatePreview() {
|
||||||
if (!imageElement.value) return;
|
if (!imageElement.value) return;
|
||||||
|
|
||||||
// Check cache first
|
|
||||||
const cacheKey = getCacheKey(props.imageUrl, detectionMethod.value, sensitivity.value, removeEmpty.value);
|
|
||||||
|
|
||||||
if (detectionCache.has(cacheKey)) {
|
|
||||||
previewSprites.value = detectionCache.get(cacheKey)!;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isProcessing.value = true;
|
isProcessing.value = true;
|
||||||
previewSprites.value = [];
|
previewSprites.value = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const img = imageElement.value;
|
const img = imageElement.value;
|
||||||
|
|
||||||
if (detectionMethod.value === 'auto') {
|
if (detectionMode.value === 'grid') {
|
||||||
await autoDetectSprites(img);
|
previewSprites.value = await splitter.splitByGrid(img, {
|
||||||
} else if (detectionMethod.value === 'irregular') {
|
cellWidth: cellWidth.value,
|
||||||
await detectIrregularSprites(img);
|
cellHeight: cellHeight.value,
|
||||||
|
preserveCellSize: preserveCellSize.value,
|
||||||
|
removeEmpty: removeEmpty.value,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
await splitSpritesheet(img, rows.value, columns.value);
|
previewSprites.value = await splitter.detectSprites(img, {
|
||||||
|
sensitivity: sensitivity.value,
|
||||||
|
removeEmpty: removeEmpty.value,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache results (limit cache size to prevent memory issues)
|
|
||||||
if (detectionCache.size > 10) {
|
|
||||||
const firstKey = detectionCache.keys().next().value;
|
|
||||||
detectionCache.delete(firstKey || '');
|
|
||||||
}
|
|
||||||
detectionCache.set(cacheKey, previewSprites.value);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error generating preview:', error);
|
console.error('Error generating preview:', error);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -209,636 +190,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSpriteBoundingBox(ctx: CanvasRenderingContext2D, width: number, height: number) {
|
|
||||||
const imageData = ctx.getImageData(0, 0, width, height);
|
|
||||||
const data = imageData.data;
|
|
||||||
|
|
||||||
let minX = width;
|
|
||||||
let minY = height;
|
|
||||||
let maxX = 0;
|
|
||||||
let maxY = 0;
|
|
||||||
let hasContent = false;
|
|
||||||
|
|
||||||
// Scan through all pixels to find the bounding box
|
|
||||||
for (let y = 0; y < height; y++) {
|
|
||||||
for (let x = 0; x < width; x++) {
|
|
||||||
const idx = (y * width + x) * 4;
|
|
||||||
// Check if pixel is not transparent (alpha > 0)
|
|
||||||
if (data[idx + 3] > 10) {
|
|
||||||
// Allow some tolerance for compression artifacts
|
|
||||||
minX = Math.min(minX, x);
|
|
||||||
minY = Math.min(minY, y);
|
|
||||||
maxX = Math.max(maxX, x);
|
|
||||||
maxY = Math.max(maxY, y);
|
|
||||||
hasContent = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no non-transparent pixels found, return null
|
|
||||||
if (!hasContent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return bounding box with a small padding, ensuring it stays within bounds
|
|
||||||
const bx = Math.max(0, minX - 1);
|
|
||||||
const by = Math.max(0, minY - 1);
|
|
||||||
const bw = Math.min(width - bx, maxX - minX + 3); // +1 for inclusive bounds, +2 for padding
|
|
||||||
const bh = Math.min(height - by, maxY - minY + 3);
|
|
||||||
|
|
||||||
return {
|
|
||||||
x: bx,
|
|
||||||
y: by,
|
|
||||||
width: Math.max(1, bw),
|
|
||||||
height: Math.max(1, bh),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split spritesheet manually based on rows and columns
|
|
||||||
async function splitSpritesheet(img: HTMLImageElement, rows: number, columns: number) {
|
|
||||||
const safeColumns = Number.isFinite(columns) && columns > 0 ? Math.floor(columns) : 1;
|
|
||||||
const safeRows = Number.isFinite(rows) && rows > 0 ? Math.floor(rows) : 1;
|
|
||||||
const spriteWidth = Math.max(1, Math.floor(img.width / safeColumns));
|
|
||||||
const spriteHeight = Math.max(1, Math.floor(img.height / safeRows));
|
|
||||||
|
|
||||||
const sprites: SpritePreview[] = [];
|
|
||||||
|
|
||||||
// Create a canvas for processing the full sprite
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
|
|
||||||
// Create a second canvas for the cropped sprite
|
|
||||||
const croppedCanvas = document.createElement('canvas');
|
|
||||||
const croppedCtx = croppedCanvas.getContext('2d');
|
|
||||||
|
|
||||||
if (!ctx || !croppedCtx) return;
|
|
||||||
|
|
||||||
canvas.width = spriteWidth;
|
|
||||||
canvas.height = spriteHeight;
|
|
||||||
|
|
||||||
// Split the image into individual sprites
|
|
||||||
for (let row = 0; row < safeRows; row++) {
|
|
||||||
for (let col = 0; col < safeColumns; col++) {
|
|
||||||
// Clear the canvas
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
// Draw the portion of the spritesheet
|
|
||||||
ctx.drawImage(img, col * spriteWidth, row * spriteHeight, spriteWidth, spriteHeight, 0, 0, spriteWidth, spriteHeight);
|
|
||||||
|
|
||||||
// Check if the sprite is empty (all transparent or same color)
|
|
||||||
const isEmpty = removeEmpty.value ? isCanvasEmpty(ctx, spriteWidth, spriteHeight) : false;
|
|
||||||
|
|
||||||
// If we're not removing empty sprites or the sprite is not empty
|
|
||||||
if (!removeEmpty.value || !isEmpty) {
|
|
||||||
// Get bounding box of non-transparent pixels
|
|
||||||
const boundingBox = getSpriteBoundingBox(ctx, spriteWidth, spriteHeight);
|
|
||||||
|
|
||||||
let url;
|
|
||||||
let x = 0; // Default position (will be updated if we have a bounding box)
|
|
||||||
let y = 0;
|
|
||||||
let width = spriteWidth;
|
|
||||||
let height = spriteHeight;
|
|
||||||
|
|
||||||
if (boundingBox) {
|
|
||||||
// The key change: preserve the original position where the sprite was found
|
|
||||||
x = boundingBox.x;
|
|
||||||
y = boundingBox.y;
|
|
||||||
width = boundingBox.width;
|
|
||||||
height = boundingBox.height;
|
|
||||||
|
|
||||||
// Set dimensions for the cropped sprite
|
|
||||||
croppedCanvas.width = boundingBox.width;
|
|
||||||
croppedCanvas.height = boundingBox.height;
|
|
||||||
|
|
||||||
// Draw only the non-transparent part
|
|
||||||
croppedCtx.clearRect(0, 0, croppedCanvas.width, croppedCanvas.height);
|
|
||||||
croppedCtx.drawImage(canvas, boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height, 0, 0, boundingBox.width, boundingBox.height);
|
|
||||||
|
|
||||||
// Convert to data URL
|
|
||||||
url = croppedCanvas.toDataURL('image/png');
|
|
||||||
} else {
|
|
||||||
// No non-transparent pixels found, use the original sprite
|
|
||||||
url = canvas.toDataURL('image/png');
|
|
||||||
}
|
|
||||||
|
|
||||||
sprites.push({
|
|
||||||
url,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
isEmpty,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
previewSprites.value = sprites;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-detect sprites based on transparency/color differences
|
|
||||||
async function autoDetectSprites(img: HTMLImageElement) {
|
|
||||||
// This is a simplified implementation
|
|
||||||
// A more sophisticated algorithm would analyze the image to find sprite boundaries
|
|
||||||
|
|
||||||
// For now, we'll use a simple approach:
|
|
||||||
// 1. Try to detect the sprite size by looking for repeating patterns
|
|
||||||
// 2. Then use that size to split the spritesheet
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
if (!ctx) return;
|
|
||||||
|
|
||||||
canvas.width = img.width;
|
|
||||||
canvas.height = img.height;
|
|
||||||
ctx.drawImage(img, 0, 0);
|
|
||||||
|
|
||||||
// Get image data for analysis
|
|
||||||
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
||||||
const data = imageData.data;
|
|
||||||
|
|
||||||
// Simple detection of sprite size based on transparency patterns
|
|
||||||
// This is a very basic implementation and might not work for all spritesheets
|
|
||||||
const { detectedWidth, detectedHeight } = detectSpriteSize(data, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
if (detectedWidth > 0 && detectedHeight > 0) {
|
|
||||||
// Sanity thresholds to avoid absurdly tiny tiles/huge counts
|
|
||||||
const MIN_TILE = 8;
|
|
||||||
const MAX_SPRITES = 1024;
|
|
||||||
if (detectedWidth < MIN_TILE || detectedHeight < MIN_TILE) {
|
|
||||||
// Fallback if tile is too small
|
|
||||||
const s = Math.max(1, Math.min(100, sensitivity.value));
|
|
||||||
const divisor = 3 + Math.round(s / 20); // 3..8
|
|
||||||
const estimatedSize = Math.max(MIN_TILE, Math.floor(Math.min(img.width, img.height) / divisor));
|
|
||||||
const estimatedRows = Math.max(1, Math.floor(img.height / estimatedSize));
|
|
||||||
const estimatedColumns = Math.max(1, Math.floor(img.width / estimatedSize));
|
|
||||||
await splitSpritesheet(img, estimatedRows, estimatedColumns);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const detectedRows = Math.max(1, Math.floor(img.height / detectedHeight));
|
|
||||||
const detectedColumns = Math.max(1, Math.floor(img.width / detectedWidth));
|
|
||||||
|
|
||||||
// If the detected combination is unreasonably high, fallback to estimate
|
|
||||||
if (detectedRows * detectedColumns > MAX_SPRITES) {
|
|
||||||
const s = Math.max(1, Math.min(100, sensitivity.value));
|
|
||||||
const divisor = 3 + Math.round(s / 20); // 3..8
|
|
||||||
const estimatedSize = Math.max(MIN_TILE, Math.floor(Math.min(img.width, img.height) / divisor));
|
|
||||||
const estimatedRows = Math.max(1, Math.floor(img.height / estimatedSize));
|
|
||||||
const estimatedColumns = Math.max(1, Math.floor(img.width / estimatedSize));
|
|
||||||
await splitSpritesheet(img, estimatedRows, estimatedColumns);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the detected size to split the spritesheet
|
|
||||||
await splitSpritesheet(img, detectedRows, detectedColumns);
|
|
||||||
} else {
|
|
||||||
// Fallback to manual splitting with a reasonable guess based on sensitivity
|
|
||||||
const s = Math.max(1, Math.min(100, sensitivity.value));
|
|
||||||
const divisor = 3 + Math.round(s / 20); // 3..8
|
|
||||||
const estimatedSize = Math.max(8, Math.floor(Math.min(img.width, img.height) / divisor));
|
|
||||||
const estimatedRows = Math.max(1, Math.floor(img.height / estimatedSize));
|
|
||||||
const estimatedColumns = Math.max(1, Math.floor(img.width / estimatedSize));
|
|
||||||
|
|
||||||
await splitSpritesheet(img, estimatedRows, estimatedColumns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to detect sprite size based on transparency/color gutters and edge periodicity
|
|
||||||
function detectSpriteSize(data: Uint8ClampedArray, width: number, height: number) {
|
|
||||||
// Map sensitivity (1-100) to thresholds:
|
|
||||||
// Higher sensitivity -> allows stricter background matching and lower gutter proportion thresholds
|
|
||||||
const s = Math.max(1, Math.min(100, sensitivity.value));
|
|
||||||
|
|
||||||
// Background/color thresholds
|
|
||||||
const alphaBgThresh = Math.round(255 * (0.15 + (100 - s) * 0.001)); // 15%-25% depending on sensitivity
|
|
||||||
const colorTol = Math.round(10 + (100 - s) * 0.8); // 10..90 Euclidean approx
|
|
||||||
const gutterPropThresh = 0.92 - s * 0.004; // 0.92 down to ~0.52
|
|
||||||
|
|
||||||
function getPixel(x: number, y: number) {
|
|
||||||
const idx = (y * width + x) * 4;
|
|
||||||
return [data[idx], data[idx + 1], data[idx + 2], data[idx + 3]] as [number, number, number, number];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Estimate background color from corners (median of corners)
|
|
||||||
const corners: [number, number, number, number][] = [getPixel(0, 0), getPixel(width - 1, 0), getPixel(0, height - 1), getPixel(width - 1, height - 1)];
|
|
||||||
function median(arr: number[]) {
|
|
||||||
const a = arr.slice().sort((a, b) => a - b);
|
|
||||||
const mid = (a.length - 1) / 2;
|
|
||||||
return (a[Math.floor(mid)] + a[Math.ceil(mid)]) / 2;
|
|
||||||
}
|
|
||||||
const bg = [median(corners.map(c => c[0])), median(corners.map(c => c[1])), median(corners.map(c => c[2])), median(corners.map(c => c[3]))] as [number, number, number, number];
|
|
||||||
|
|
||||||
function isBg(r: number, g: number, b: number, a: number) {
|
|
||||||
if (a <= alphaBgThresh) return true;
|
|
||||||
const dr = r - bg[0];
|
|
||||||
const dg = g - bg[1];
|
|
||||||
const db = b - bg[2];
|
|
||||||
// Use Manhattan distance approximation for speed
|
|
||||||
const manhattan = Math.abs(dr) + Math.abs(dg) + Math.abs(db);
|
|
||||||
// Normalize approx to 0..~765 and compare to scaled tolerance
|
|
||||||
return manhattan <= colorTol * 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sample stride to speed up scanning large sheets
|
|
||||||
const rowSample = Math.max(1, Math.floor(height / 64));
|
|
||||||
const colSample = Math.max(1, Math.floor(width / 64));
|
|
||||||
|
|
||||||
// Compute background proportion per column and row
|
|
||||||
const colBgProp: number[] = new Array(width).fill(0);
|
|
||||||
for (let x = 0; x < width; x++) {
|
|
||||||
let bgCount = 0;
|
|
||||||
let total = 0;
|
|
||||||
for (let y = 0; y < height; y += rowSample) {
|
|
||||||
const [r, g, b, a] = getPixel(x, y);
|
|
||||||
if (isBg(r, g, b, a)) bgCount++;
|
|
||||||
total++;
|
|
||||||
}
|
|
||||||
colBgProp[x] = total > 0 ? bgCount / total : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rowBgProp: number[] = new Array(height).fill(0);
|
|
||||||
for (let y = 0; y < height; y++) {
|
|
||||||
let bgCount = 0;
|
|
||||||
let total = 0;
|
|
||||||
for (let x = 0; x < width; x += colSample) {
|
|
||||||
const [r, g, b, a] = getPixel(x, y);
|
|
||||||
if (isBg(r, g, b, a)) bgCount++;
|
|
||||||
total++;
|
|
||||||
}
|
|
||||||
rowBgProp[y] = total > 0 ? bgCount / total : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractRuns(bgProp: number[]): { emptyRuns: [number, number][]; segSizes: number[] } {
|
|
||||||
const emptyRuns: [number, number][] = [];
|
|
||||||
const segSizes: number[] = [];
|
|
||||||
let inEmpty = false;
|
|
||||||
let runStart = 0;
|
|
||||||
let lastSeparatorEnd = -1;
|
|
||||||
for (let i = 0; i < bgProp.length; i++) {
|
|
||||||
const isEmpty = bgProp[i] >= gutterPropThresh;
|
|
||||||
if (isEmpty && !inEmpty) {
|
|
||||||
inEmpty = true;
|
|
||||||
runStart = i;
|
|
||||||
if (lastSeparatorEnd >= 0) {
|
|
||||||
const seg = runStart - lastSeparatorEnd - 1;
|
|
||||||
if (seg > 0) segSizes.push(seg);
|
|
||||||
}
|
|
||||||
} else if (!isEmpty && inEmpty) {
|
|
||||||
inEmpty = false;
|
|
||||||
emptyRuns.push([runStart, i - 1]);
|
|
||||||
lastSeparatorEnd = i - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (inEmpty) {
|
|
||||||
emptyRuns.push([runStart, bgProp.length - 1]);
|
|
||||||
lastSeparatorEnd = bgProp.length - 1;
|
|
||||||
}
|
|
||||||
// Trailing segment after last empty run
|
|
||||||
if (lastSeparatorEnd >= 0 && lastSeparatorEnd < bgProp.length - 1) {
|
|
||||||
const seg = bgProp.length - 1 - lastSeparatorEnd;
|
|
||||||
if (seg > 0) segSizes.push(seg);
|
|
||||||
}
|
|
||||||
return { emptyRuns, segSizes };
|
|
||||||
}
|
|
||||||
|
|
||||||
function modeWithTolerance(values: number[], tol = 2): number {
|
|
||||||
if (values.length === 0) return 0;
|
|
||||||
values.sort((a, b) => a - b);
|
|
||||||
let bestCount = 0;
|
|
||||||
let bestVal = values[0];
|
|
||||||
for (let i = 0; i < values.length; i++) {
|
|
||||||
const base = values[i];
|
|
||||||
let count = 1;
|
|
||||||
for (let j = i + 1; j < values.length; j++) {
|
|
||||||
if (Math.abs(values[j] - base) <= tol) count++;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
if (count > bestCount) {
|
|
||||||
bestCount = count;
|
|
||||||
bestVal = base;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
const colRuns = extractRuns(colBgProp);
|
|
||||||
const rowRuns = extractRuns(rowBgProp);
|
|
||||||
|
|
||||||
let detectedWidth = modeWithTolerance(colRuns.segSizes, 2);
|
|
||||||
let detectedHeight = modeWithTolerance(rowRuns.segSizes, 2);
|
|
||||||
|
|
||||||
// Fallback: use edge periodicity via autocorrelation if gutters not found
|
|
||||||
function edgeAutocorrLength(axis: 'x' | 'y'): number {
|
|
||||||
const maxLen = axis === 'x' ? width : height;
|
|
||||||
const otherLen = axis === 'x' ? height : width;
|
|
||||||
const sampleStepMajor = Math.max(1, Math.floor(maxLen / 512));
|
|
||||||
const sampleStepMinor = Math.max(1, Math.floor(otherLen / 64));
|
|
||||||
const energy: number[] = new Array(maxLen).fill(0);
|
|
||||||
if (axis === 'x') {
|
|
||||||
for (let x = 0; x < maxLen - 1; x += sampleStepMajor) {
|
|
||||||
let e = 0;
|
|
||||||
for (let y = 0; y < otherLen; y += sampleStepMinor) {
|
|
||||||
const [r1, g1, b1, a1] = getPixel(x, y);
|
|
||||||
const [r2, g2, b2, a2] = getPixel(x + 1, y);
|
|
||||||
e += Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2) + Math.abs(a1 - a2);
|
|
||||||
}
|
|
||||||
energy[x] = e;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let y = 0; y < maxLen - 1; y += sampleStepMajor) {
|
|
||||||
let e = 0;
|
|
||||||
for (let x = 0; x < otherLen; x += sampleStepMinor) {
|
|
||||||
const [r1, g1, b1, a1] = getPixel(x, y);
|
|
||||||
const [r2, g2, b2, a2] = getPixel(x, y + 1);
|
|
||||||
e += Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2) + Math.abs(a1 - a2);
|
|
||||||
}
|
|
||||||
energy[y] = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const minTile = Math.max(3, Math.floor(Math.min(maxLen / 32, 128)));
|
|
||||||
const maxTile = Math.max(minTile + 1, Math.floor(Math.min(maxLen / 2, 512)));
|
|
||||||
let bestLag = 0;
|
|
||||||
let bestVal = -Infinity;
|
|
||||||
for (let lag = minTile; lag <= maxTile; lag++) {
|
|
||||||
let sum = 0;
|
|
||||||
for (let i = 0; i + lag < energy.length; i++) {
|
|
||||||
const e1 = energy[i] || 0;
|
|
||||||
const e2 = energy[i + lag] || 0;
|
|
||||||
sum += e1 * e2;
|
|
||||||
}
|
|
||||||
if (sum > bestVal) {
|
|
||||||
bestVal = sum;
|
|
||||||
bestLag = lag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestLag;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detectedWidth <= 0 || detectedWidth > width) {
|
|
||||||
const lagX = edgeAutocorrLength('x');
|
|
||||||
if (lagX > 0 && lagX <= width) detectedWidth = lagX;
|
|
||||||
}
|
|
||||||
if (detectedHeight <= 0 || detectedHeight > height) {
|
|
||||||
const lagY = edgeAutocorrLength('y');
|
|
||||||
if (lagY > 0 && lagY <= height) detectedHeight = lagY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanity checks
|
|
||||||
if (!Number.isFinite(detectedWidth) || detectedWidth <= 0 || detectedWidth > width) detectedWidth = 0;
|
|
||||||
if (!Number.isFinite(detectedHeight) || detectedHeight <= 0 || detectedHeight > height) detectedHeight = 0;
|
|
||||||
|
|
||||||
return { detectedWidth, detectedHeight };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect irregular sprites using Web Worker
|
|
||||||
async function detectIrregularSprites(img: HTMLImageElement): Promise<void> {
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
if (!ctx) throw new Error('Could not get canvas context');
|
|
||||||
|
|
||||||
canvas.width = img.width;
|
|
||||||
canvas.height = img.height;
|
|
||||||
ctx.drawImage(img, 0, 0);
|
|
||||||
|
|
||||||
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
// Initialize worker lazily using Vite worker syntax
|
|
||||||
if (!irregularWorker.value) {
|
|
||||||
try {
|
|
||||||
irregularWorker.value = new Worker(new URL('../workers/irregularSpriteDetection.worker.ts', import.meta.url), { type: 'module' });
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to create worker:', error);
|
|
||||||
// Fallback to auto detection if worker fails
|
|
||||||
await autoDetectSprites(img);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
|
||||||
const worker = irregularWorker.value!;
|
|
||||||
|
|
||||||
const handleMessage = async (e: MessageEvent) => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
worker.removeEventListener('message', handleMessage);
|
|
||||||
worker.removeEventListener('error', handleError);
|
|
||||||
|
|
||||||
if (e.data.type === 'spritesDetected') {
|
|
||||||
try {
|
|
||||||
await processDetectedSprites(img, e.data.sprites, e.data.backgroundColor);
|
|
||||||
resolve();
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set timeout for worker processing
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
worker.removeEventListener('message', handleMessage);
|
|
||||||
worker.removeEventListener('error', handleError);
|
|
||||||
console.warn('Worker timeout, falling back to auto detection');
|
|
||||||
// Fallback to auto detection
|
|
||||||
autoDetectSprites(img).then(resolve).catch(reject);
|
|
||||||
}, 30000); // 30 second timeout
|
|
||||||
|
|
||||||
const handleError = (error: ErrorEvent) => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
worker.removeEventListener('message', handleMessage);
|
|
||||||
worker.removeEventListener('error', handleError);
|
|
||||||
console.error('Worker error, falling back to auto detection:', error);
|
|
||||||
// Fallback to auto detection
|
|
||||||
autoDetectSprites(img).then(resolve).catch(reject);
|
|
||||||
};
|
|
||||||
|
|
||||||
worker.addEventListener('message', handleMessage);
|
|
||||||
worker.addEventListener('error', handleError);
|
|
||||||
|
|
||||||
try {
|
|
||||||
worker.postMessage({
|
|
||||||
type: 'detectIrregularSprites',
|
|
||||||
imageData,
|
|
||||||
sensitivity: sensitivity.value,
|
|
||||||
maxSize: 2048, // Limit processing size for performance
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
console.error('Failed to post message to worker:', error);
|
|
||||||
// Fallback to auto detection
|
|
||||||
autoDetectSprites(img).then(resolve).catch(reject);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process sprites detected by the worker (optimized)
|
|
||||||
async function processDetectedSprites(img: HTMLImageElement, detectedSprites: any[], backgroundColor?: [number, number, number, number]): Promise<void> {
|
|
||||||
if (!detectedSprites?.length) {
|
|
||||||
previewSprites.value = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sprites: SpritePreview[] = [];
|
|
||||||
const sourceCanvas = document.createElement('canvas');
|
|
||||||
const sourceCtx = sourceCanvas.getContext('2d');
|
|
||||||
const spriteCanvas = document.createElement('canvas');
|
|
||||||
const spriteCtx = spriteCanvas.getContext('2d');
|
|
||||||
|
|
||||||
if (!sourceCtx || !spriteCtx) return;
|
|
||||||
|
|
||||||
// Setup source canvas once
|
|
||||||
sourceCanvas.width = img.width;
|
|
||||||
sourceCanvas.height = img.height;
|
|
||||||
sourceCtx.drawImage(img, 0, 0);
|
|
||||||
|
|
||||||
// Process sprites in batches to avoid blocking
|
|
||||||
const batchSize = 50;
|
|
||||||
for (let i = 0; i < detectedSprites.length; i += batchSize) {
|
|
||||||
const batch = detectedSprites.slice(i, i + batchSize);
|
|
||||||
|
|
||||||
for (const sprite of batch) {
|
|
||||||
const { x, y, width, height } = sprite;
|
|
||||||
|
|
||||||
// Skip invalid sprites
|
|
||||||
if (width <= 0 || height <= 0) continue;
|
|
||||||
|
|
||||||
spriteCanvas.width = width;
|
|
||||||
spriteCanvas.height = height;
|
|
||||||
spriteCtx.clearRect(0, 0, width, height);
|
|
||||||
spriteCtx.drawImage(sourceCanvas, x, y, width, height, 0, 0, width, height);
|
|
||||||
|
|
||||||
// Remove background and make transparent for irregular sprites
|
|
||||||
if (detectionMethod.value === 'irregular' && backgroundColor) {
|
|
||||||
removeBackgroundFromSprite(spriteCtx, width, height, backgroundColor, sensitivity.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
const isEmpty = removeEmpty.value ? isCanvasEmpty(spriteCtx, width, height) : false;
|
|
||||||
|
|
||||||
if (!removeEmpty.value || !isEmpty) {
|
|
||||||
sprites.push({
|
|
||||||
url: spriteCanvas.toDataURL('image/png'),
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
isEmpty,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Yield control periodically for large batches
|
|
||||||
if (i > 0 && i % 100 === 0) {
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
previewSprites.value = sprites;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove background color and make it transparent
|
|
||||||
function removeBackgroundFromSprite(ctx: CanvasRenderingContext2D, width: number, height: number, backgroundColor: [number, number, number, number], sensitivity: number): void {
|
|
||||||
const imageData = ctx.getImageData(0, 0, width, height);
|
|
||||||
const data = imageData.data;
|
|
||||||
|
|
||||||
const [bgR, bgG, bgB, bgA] = backgroundColor;
|
|
||||||
const colorTolerance = Math.round(50 - sensitivity * 0.45); // Same as worker
|
|
||||||
const alphaTolerance = Math.round(40 - sensitivity * 0.35);
|
|
||||||
|
|
||||||
for (let i = 0; i < data.length; i += 4) {
|
|
||||||
const r = data[i];
|
|
||||||
const g = data[i + 1];
|
|
||||||
const b = data[i + 2];
|
|
||||||
const a = data[i + 3];
|
|
||||||
|
|
||||||
// Handle fully transparent pixels
|
|
||||||
if (a < 10) {
|
|
||||||
data[i + 3] = 0; // Make fully transparent
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate color difference using Euclidean distance
|
|
||||||
const rDiff = r - bgR;
|
|
||||||
const gDiff = g - bgG;
|
|
||||||
const bDiff = b - bgB;
|
|
||||||
const aDiff = a - bgA;
|
|
||||||
|
|
||||||
const colorDistance = Math.sqrt(rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
|
|
||||||
const alphaDistance = Math.abs(aDiff);
|
|
||||||
|
|
||||||
// If pixel matches background color, make it transparent
|
|
||||||
if (colorDistance <= colorTolerance && alphaDistance <= alphaTolerance) {
|
|
||||||
data[i + 3] = 0; // Set alpha to 0 (transparent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.putImageData(imageData, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if a canvas is empty (all transparent or same color)
|
|
||||||
function isCanvasEmpty(ctx: CanvasRenderingContext2D, width: number, height: number): boolean {
|
|
||||||
const imageData = ctx.getImageData(0, 0, width, height);
|
|
||||||
const data = imageData.data;
|
|
||||||
|
|
||||||
// Check if all pixels are transparent
|
|
||||||
let allTransparent = true;
|
|
||||||
let allSameColor = true;
|
|
||||||
|
|
||||||
// Reference values from first pixel
|
|
||||||
const firstR = data[0];
|
|
||||||
const firstG = data[1];
|
|
||||||
const firstB = data[2];
|
|
||||||
const firstA = data[3];
|
|
||||||
|
|
||||||
for (let i = 0; i < data.length; i += 4) {
|
|
||||||
const alpha = data[i + 3];
|
|
||||||
|
|
||||||
// Check transparency
|
|
||||||
if (alpha > 10) {
|
|
||||||
// Allow some tolerance for compression artifacts
|
|
||||||
allTransparent = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if all pixels are the same color
|
|
||||||
if (data[i] !== firstR || data[i + 1] !== firstG || data[i + 2] !== firstB || Math.abs(data[i + 3] - firstA) > 10) {
|
|
||||||
allSameColor = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Early exit if we've determined it's not empty
|
|
||||||
if (!allTransparent && !allSameColor) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allTransparent || allSameColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert preview sprites to actual files
|
|
||||||
async function createSpriteFiles(): Promise<SpriteFile[]> {
|
|
||||||
const spriteFiles: SpriteFile[] = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < previewSprites.value.length; i++) {
|
|
||||||
const sprite = previewSprites.value[i];
|
|
||||||
|
|
||||||
// Convert data URL to blob
|
|
||||||
const response = await fetch(sprite.url);
|
|
||||||
const blob = await response.blob();
|
|
||||||
|
|
||||||
// Create file from blob
|
|
||||||
const fileName = `sprite_${i + 1}.png`;
|
|
||||||
const file = new File([blob], fileName, { type: 'image/png' });
|
|
||||||
|
|
||||||
// Create sprite file with position information
|
|
||||||
spriteFiles.push({
|
|
||||||
file,
|
|
||||||
x: sprite.x,
|
|
||||||
y: sprite.y,
|
|
||||||
width: sprite.width,
|
|
||||||
height: sprite.height,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return spriteFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
function cancel() {
|
function cancel() {
|
||||||
emit('close');
|
emit('close');
|
||||||
@@ -850,8 +201,24 @@
|
|||||||
isProcessing.value = true;
|
isProcessing.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const files = await createSpriteFiles();
|
const spriteFiles: SpriteFile[] = [];
|
||||||
emit('split', files);
|
|
||||||
|
for (let i = 0; i < previewSprites.value.length; i++) {
|
||||||
|
const sprite = previewSprites.value[i];
|
||||||
|
const response = await fetch(sprite.url);
|
||||||
|
const blob = await response.blob();
|
||||||
|
const file = new File([blob], `sprite_${i + 1}.png`, { type: 'image/png' });
|
||||||
|
|
||||||
|
spriteFiles.push({
|
||||||
|
file,
|
||||||
|
x: sprite.x,
|
||||||
|
y: sprite.y,
|
||||||
|
width: sprite.width,
|
||||||
|
height: sprite.height,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('split', spriteFiles);
|
||||||
emit('close');
|
emit('close');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating sprite files:', error);
|
console.error('Error creating sprite files:', error);
|
||||||
@@ -860,19 +227,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add these watchers to automatically update preview
|
|
||||||
watch([rows, columns, removeEmpty, detectionMethod, sensitivity], () => {
|
|
||||||
if (imageElement.value) {
|
|
||||||
generatePreview();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean up worker and cache on component unmount
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (irregularWorker.value) {
|
splitter.cleanup();
|
||||||
irregularWorker.value.terminate();
|
|
||||||
irregularWorker.value = null;
|
|
||||||
}
|
|
||||||
detectionCache.clear();
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
101
src/components/auth/AuthModal.vue
Normal file
101
src/components/auth/AuthModal.vue
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<template>
|
||||||
|
<Modal :is-open="isOpen" @close="close" :title="isLogin ? 'Welcome Back' : 'Create Account'" :initialWidth="450" :initialHeight="500">
|
||||||
|
<div class="space-y-4">
|
||||||
|
<div class="text-center mb-6">
|
||||||
|
<p class="text-sm text-gray-500 dark:text-gray-400">
|
||||||
|
{{ isLogin ? 'Sign in to access your projects' : 'Join to save and manage your spritesheets' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form @submit.prevent="handleSubmit" class="space-y-4">
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Email</label>
|
||||||
|
<input v-model="email" type="email" required class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" placeholder="you@example.com" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Password</label>
|
||||||
|
<input v-model="password" type="password" required minlength="8" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" placeholder="••••••••" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!isLogin">
|
||||||
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Confirm Password</label>
|
||||||
|
<input v-model="passwordConfirm" type="password" required minlength="8" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" placeholder="••••••••" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="error" class="text-red-500 text-sm text-center bg-red-50 dark:bg-red-900/20 p-2 rounded">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" :disabled="loading" class="w-full btn btn-primary py-2.5 flex justify-center items-center">
|
||||||
|
<i v-if="loading" class="fas fa-spinner fa-spin mr-2"></i>
|
||||||
|
{{ isLogin ? 'Sign In' : 'Create Account' }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="mt-6 text-center text-sm text-gray-600 dark:text-gray-400">
|
||||||
|
{{ isLogin ? "Don't have an account?" : 'Already have an account?' }}
|
||||||
|
<button @click="toggleMode" class="text-indigo-600 dark:text-indigo-400 font-medium hover:underline">
|
||||||
|
{{ isLogin ? 'Sign up' : 'Sign in' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useAuthStore } from '@/stores/useAuthStore';
|
||||||
|
import Modal from '@/components/utilities/Modal.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
isOpen: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'close'): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
const isLogin = ref(true);
|
||||||
|
const email = ref('');
|
||||||
|
const password = ref('');
|
||||||
|
const passwordConfirm = ref('');
|
||||||
|
const loading = ref(false);
|
||||||
|
const error = ref('');
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
emit('close');
|
||||||
|
error.value = '';
|
||||||
|
email.value = '';
|
||||||
|
password.value = '';
|
||||||
|
passwordConfirm.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleMode = () => {
|
||||||
|
isLogin.value = !isLogin.value;
|
||||||
|
error.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
error.value = '';
|
||||||
|
try {
|
||||||
|
if (isLogin.value) {
|
||||||
|
await authStore.login(email.value, password.value);
|
||||||
|
} else {
|
||||||
|
if (password.value !== passwordConfirm.value) {
|
||||||
|
throw new Error("Passwords don't match");
|
||||||
|
}
|
||||||
|
await authStore.register(email.value, password.value, passwordConfirm.value);
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
} catch (e: any) {
|
||||||
|
error.value = e.message || 'An error occurred';
|
||||||
|
// Better PB error handling
|
||||||
|
if (e?.data?.message) error.value = e.data.message;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
156
src/components/layout/Navbar.vue
Normal file
156
src/components/layout/Navbar.vue
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
<template>
|
||||||
|
<nav class="sticky top-0 z-50 w-full glass border-b border-gray-200/50 dark:border-gray-800/50">
|
||||||
|
<div class="w-full px-4 sm:px-6 lg:px-8">
|
||||||
|
<div class="flex items-center justify-between h-16">
|
||||||
|
<!-- Left Side: Logo & Navigation -->
|
||||||
|
<div class="flex items-center gap-8">
|
||||||
|
<NavbarLogo />
|
||||||
|
|
||||||
|
<!-- Desktop Navigation -->
|
||||||
|
<div class="hidden md:flex items-center">
|
||||||
|
<NavbarLinks />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Right Side: Actions & User -->
|
||||||
|
<div class="hidden md:flex items-center gap-5">
|
||||||
|
<!-- Auth & Projects -->
|
||||||
|
<template v-if="authStore.user">
|
||||||
|
<NavbarProjectActions :is-saving="isSaving" @save-project="handleQuickSave" @open-save-modal="openSaveModal" @open-new-project-modal="isNewProjectModalOpen = true" @open-project-list="isProjectListOpen = true" />
|
||||||
|
|
||||||
|
<div class="h-4 w-px bg-gray-200 dark:bg-gray-700"></div>
|
||||||
|
|
||||||
|
<!-- User Dropdown -->
|
||||||
|
<NavbarUserMenu @open-auth-modal="isAuthModalOpen = true" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div v-else>
|
||||||
|
<button @click="isAuthModalOpen = true" class="btn btn-primary btn-sm shadow-indigo-500/20 shadow-lg">Login / Register</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="h-4 w-px bg-gray-200 dark:bg-gray-700"></div>
|
||||||
|
|
||||||
|
<NavbarSocials @open-help="$emit('open-help')" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Mobile Menu Button -->
|
||||||
|
<div class="flex md:hidden">
|
||||||
|
<DarkModeToggle />
|
||||||
|
<button @click="isMobileMenuOpen = !isMobileMenuOpen" class="ml-4 p-2 rounded-md text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">
|
||||||
|
<i :class="isMobileMenuOpen ? 'fas fa-times' : 'fas fa-bars'" class="text-lg"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Mobile Menu -->
|
||||||
|
<NavbarMobileMenu
|
||||||
|
:is-open="isMobileMenuOpen"
|
||||||
|
:is-saving="isSaving"
|
||||||
|
@close="isMobileMenuOpen = false"
|
||||||
|
@open-help="$emit('open-help')"
|
||||||
|
@save-project="handleQuickSave"
|
||||||
|
@open-save-modal="openSaveModal"
|
||||||
|
@open-new-project-modal="isNewProjectModalOpen = true"
|
||||||
|
@open-project-list="isProjectListOpen = true"
|
||||||
|
@open-auth-modal="isAuthModalOpen = true"
|
||||||
|
/>
|
||||||
|
</nav>
|
||||||
|
<AuthModal :is-open="isAuthModalOpen" @close="isAuthModalOpen = false" />
|
||||||
|
<ProjectList :is-open="isProjectListOpen" @close="isProjectListOpen = false" @open-project="handleOpenProject" />
|
||||||
|
<SaveProjectModal :is-open="isSaveProjectModalOpen" :initial-name="saveModalInitialName" @close="isSaveProjectModalOpen = false" @save="handleSaveProject" />
|
||||||
|
<NewProjectModal :is-open="isNewProjectModalOpen" @close="isNewProjectModalOpen = false" @create="handleCreateNewProject" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue';
|
||||||
|
import DarkModeToggle from '../utilities/DarkModeToggle.vue';
|
||||||
|
import { useAuthStore } from '@/stores/useAuthStore';
|
||||||
|
import AuthModal from '@/components/auth/AuthModal.vue';
|
||||||
|
import ProjectList from '@/components/project/ProjectList.vue';
|
||||||
|
import SaveProjectModal from '@/components/project/SaveProjectModal.vue';
|
||||||
|
import NewProjectModal from '@/components/project/NewProjectModal.vue';
|
||||||
|
import { useProjectStore, type Project } from '@/stores/useProjectStore';
|
||||||
|
import { useProjectManager } from '@/composables/useProjectManager';
|
||||||
|
import { useToast } from '@/composables/useToast';
|
||||||
|
|
||||||
|
// Sub-components
|
||||||
|
import NavbarLogo from './navbar/NavbarLogo.vue';
|
||||||
|
import NavbarLinks from './navbar/NavbarLinks.vue';
|
||||||
|
import NavbarProjectActions from './navbar/NavbarProjectActions.vue';
|
||||||
|
import NavbarUserMenu from './navbar/NavbarUserMenu.vue';
|
||||||
|
import NavbarSocials from './navbar/NavbarSocials.vue';
|
||||||
|
import NavbarMobileMenu from './navbar/NavbarMobileMenu.vue';
|
||||||
|
|
||||||
|
defineEmits(['open-help']);
|
||||||
|
|
||||||
|
const isMobileMenuOpen = ref(false);
|
||||||
|
const isAuthModalOpen = ref(false);
|
||||||
|
const isProjectListOpen = ref(false);
|
||||||
|
const isSaveProjectModalOpen = ref(false);
|
||||||
|
const isNewProjectModalOpen = ref(false);
|
||||||
|
const saveMode = ref<'save' | 'save-as'>('save');
|
||||||
|
const isSaving = ref(false);
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
const projectStore = useProjectStore();
|
||||||
|
const { createProject, openProject, saveProject, saveAsProject } = useProjectManager();
|
||||||
|
const { addToast } = useToast();
|
||||||
|
|
||||||
|
const handleOpenProject = async (project: Project) => {
|
||||||
|
await openProject(project);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openSaveModal = (mode: 'save' | 'save-as' = 'save') => {
|
||||||
|
saveMode.value = mode;
|
||||||
|
isSaveProjectModalOpen.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveModalInitialName = computed(() => {
|
||||||
|
if (saveMode.value === 'save-as') {
|
||||||
|
return projectStore.currentProject?.name ? projectStore.currentProject.name + ' (copy)' : '';
|
||||||
|
}
|
||||||
|
return projectStore.currentProject?.name;
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleQuickSave = async () => {
|
||||||
|
if (projectStore.currentProject?.name) {
|
||||||
|
isSaving.value = true;
|
||||||
|
try {
|
||||||
|
await saveProject(projectStore.currentProject.name);
|
||||||
|
addToast('Project saved successfully', 'success');
|
||||||
|
} catch (error) {
|
||||||
|
addToast('Failed to save project', 'error');
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
isSaving.value = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
openSaveModal('save');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveProject = async (name: string) => {
|
||||||
|
isSaving.value = true;
|
||||||
|
try {
|
||||||
|
if (saveMode.value === 'save-as') {
|
||||||
|
await saveAsProject(name);
|
||||||
|
addToast('Project saved as new copy', 'success');
|
||||||
|
} else {
|
||||||
|
await saveProject(name);
|
||||||
|
addToast('Project saved successfully', 'success');
|
||||||
|
}
|
||||||
|
isSaveProjectModalOpen.value = false;
|
||||||
|
} catch (error) {
|
||||||
|
addToast('Failed to save project', 'error');
|
||||||
|
console.error(error);
|
||||||
|
// Error handled in composable but kept here for toast
|
||||||
|
} finally {
|
||||||
|
isSaving.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCreateNewProject = (config: { width: number; height: number; columns: number; rows: number }) => {
|
||||||
|
createProject(config);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
38
src/components/layout/navbar/NavbarLinks.vue
Normal file
38
src/components/layout/navbar/NavbarLinks.vue
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<router-link
|
||||||
|
v-for="link in links"
|
||||||
|
:key="link.path"
|
||||||
|
:to="link.path"
|
||||||
|
class="px-3 py-2 rounded-lg text-sm font-medium transition-all duration-200"
|
||||||
|
:class="[
|
||||||
|
isActive(link.path)
|
||||||
|
? 'bg-indigo-50 dark:bg-indigo-500/10 text-indigo-600 dark:text-indigo-400'
|
||||||
|
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-800 hover:text-indigo-600 dark:hover:text-indigo-400'
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ link.name }}
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
|
const links = [
|
||||||
|
{ name: 'Home', path: '/' },
|
||||||
|
{ name: 'Blog', path: '/blog' },
|
||||||
|
{ name: 'About', path: '/about' },
|
||||||
|
{ name: 'FAQ', path: '/faq' },
|
||||||
|
{ name: 'Contact', path: '/contact' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const isActive = (path: string) => {
|
||||||
|
if (path === '/') {
|
||||||
|
return route.path === '/';
|
||||||
|
}
|
||||||
|
return route.path.startsWith(path);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
14
src/components/layout/navbar/NavbarLogo.vue
Normal file
14
src/components/layout/navbar/NavbarLogo.vue
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex-shrink-0 flex items-center gap-3">
|
||||||
|
<router-link to="/" class="flex items-center gap-2 group">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-gray-900 dark:bg-white flex items-center justify-center shadow-lg group-hover:scale-105 transition-transform duration-200">
|
||||||
|
<i class="fas fa-layer-group text-white dark:text-gray-900 text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<!-- <span class="font-bold text-xl tracking-tight text-gray-900 dark:text-white group-hover:opacity-80 transition-opacity"> Spritesheet generator </span>-->
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { RouterLink } from 'vue-router';
|
||||||
|
</script>
|
||||||
168
src/components/layout/navbar/NavbarMobileMenu.vue
Normal file
168
src/components/layout/navbar/NavbarMobileMenu.vue
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<template>
|
||||||
|
<transition
|
||||||
|
enter-active-class="transition ease-out duration-200"
|
||||||
|
enter-from-class="transform opacity-0 -translate-y-2"
|
||||||
|
enter-to-class="transform opacity-100 translate-y-0"
|
||||||
|
leave-active-class="transition ease-in duration-150"
|
||||||
|
leave-from-class="transform opacity-100 translate-y-0"
|
||||||
|
leave-to-class="transform opacity-0 -translate-y-2"
|
||||||
|
>
|
||||||
|
<div v-show="isOpen" class="md:hidden border-t border-gray-200 dark:border-gray-800 bg-white/95 dark:bg-gray-950/95 backdrop-blur-xl absolute top-16 left-0 w-full z-40 shadow-lg max-h-[calc(100vh-4rem)] overflow-y-auto">
|
||||||
|
<div class="px-2 pt-2 pb-3 space-y-1">
|
||||||
|
<!-- User Profile (Mobile) -->
|
||||||
|
<div v-if="authStore.user" class="px-3 py-3 mb-2 border-b border-gray-200 dark:border-gray-800">
|
||||||
|
<div class="flex items-center gap-3 mb-3">
|
||||||
|
<div class="w-10 h-10 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 text-white font-bold text-base flex items-center justify-center shadow-md">
|
||||||
|
{{ userInitials }}
|
||||||
|
</div>
|
||||||
|
<div class="overflow-hidden">
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 uppercase font-semibold tracking-wider mb-0.5">Signed in as</p>
|
||||||
|
<p class="text-sm font-medium text-gray-900 dark:text-white truncate">{{ authStore.user.email }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button @click="handleLogout" class="w-full text-left flex items-center gap-3 px-3 py-2 rounded-md text-base font-medium text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors"><i class="fas fa-sign-out-alt w-5 text-center"></i> Sign out</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="px-3 py-3 mb-2 border-b border-gray-200 dark:border-gray-800">
|
||||||
|
<button
|
||||||
|
@click="
|
||||||
|
$emit('open-auth-modal');
|
||||||
|
$emit('close');
|
||||||
|
"
|
||||||
|
class="w-full btn btn-primary flex justify-center items-center gap-2"
|
||||||
|
>
|
||||||
|
Login / Register
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<router-link
|
||||||
|
v-for="link in links"
|
||||||
|
:key="link.path"
|
||||||
|
:to="link.path"
|
||||||
|
class="flex items-center gap-3 px-3 py-3 rounded-md text-base font-medium transition-all duration-200"
|
||||||
|
:class="[
|
||||||
|
isActive(link.path)
|
||||||
|
? 'bg-indigo-50 dark:bg-indigo-500/10 text-indigo-600 dark:text-indigo-400'
|
||||||
|
: 'text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800 hover:text-indigo-600 dark:hover:text-indigo-400'
|
||||||
|
]"
|
||||||
|
@click="$emit('close')"
|
||||||
|
>
|
||||||
|
<i :class="link.icon" class="w-5 text-center"></i> {{ link.name }}
|
||||||
|
</router-link>
|
||||||
|
|
||||||
|
<!-- Project Actions -->
|
||||||
|
<div v-if="authStore.user" class="border-t border-gray-200 dark:border-gray-800 my-2 pt-2">
|
||||||
|
<p class="px-3 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2">Project</p>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="isEditorActive"
|
||||||
|
@click="
|
||||||
|
$emit('save-project');
|
||||||
|
$emit('close');
|
||||||
|
"
|
||||||
|
class="w-full text-left flex items-center gap-3 px-3 py-2 rounded-md text-base font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800 hover:text-indigo-600 dark:hover:text-indigo-400 transition-colors"
|
||||||
|
:disabled="isSaving"
|
||||||
|
>
|
||||||
|
<svg v-if="isSaving" class="animate-spin w-5 h-5 text-indigo-600 dark:text-indigo-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||||
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||||
|
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||||
|
</svg>
|
||||||
|
<i v-else class="fas fa-save w-5"></i>
|
||||||
|
{{ isSaving ? 'Saving...' : 'Save project' }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="isEditorActive"
|
||||||
|
@click="
|
||||||
|
$emit('open-save-modal', 'save-as');
|
||||||
|
$emit('close');
|
||||||
|
"
|
||||||
|
class="w-full text-left flex items-center gap-3 px-3 py-2 rounded-md text-base font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800 hover:text-indigo-600 dark:hover:text-indigo-400 transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-clone w-5"></i> Save as...
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
@click="
|
||||||
|
$emit('open-new-project-modal');
|
||||||
|
$emit('close');
|
||||||
|
"
|
||||||
|
class="w-full text-left flex items-center gap-3 px-3 py-2 rounded-md text-base font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800 hover:text-indigo-600 dark:hover:text-indigo-400 transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-plus w-5"></i> New project
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
@click="
|
||||||
|
$emit('open-project-list');
|
||||||
|
$emit('close');
|
||||||
|
"
|
||||||
|
class="w-full text-left flex items-center gap-3 px-3 py-2 rounded-md text-base font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800 hover:text-indigo-600 dark:hover:text-indigo-400 transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-folder-open w-5"></i> My projects
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="border-t border-gray-200 dark:border-gray-800 my-2 pt-5 flex gap-4 px-3">
|
||||||
|
<a href="https://gitea.adhd.sh/root/spritesheet-generator" target="_blank" class="text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white">
|
||||||
|
<i class="fab fa-github text-xl"></i>
|
||||||
|
</a>
|
||||||
|
<a href="https://discord.gg/JTev3nzeDa" target="_blank" class="text-gray-500 hover:text-[#5865F2] dark:text-gray-400 dark:hover:text-[#5865F2]">
|
||||||
|
<i class="fab fa-discord text-xl"></i>
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
@click="
|
||||||
|
$emit('open-help');
|
||||||
|
$emit('close');
|
||||||
|
"
|
||||||
|
class="text-gray-500 hover:text-indigo-600 dark:text-gray-400 dark:hover:text-indigo-400"
|
||||||
|
>
|
||||||
|
<i class="fas fa-question-circle text-xl"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { RouterLink, useRoute } from 'vue-router';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const isEditorActive = computed(() => route.name === 'editor');
|
||||||
|
|
||||||
|
const links = [
|
||||||
|
{ name: 'Home', path: '/', icon: 'fas fa-home' },
|
||||||
|
{ name: 'Blog', path: '/blog', icon: 'fas fa-newspaper' },
|
||||||
|
{ name: 'About', path: '/about', icon: 'fas fa-info-circle' },
|
||||||
|
{ name: 'FAQ', path: '/faq', icon: 'fas fa-question-circle' },
|
||||||
|
{ name: 'Contact', path: '/contact', icon: 'fas fa-envelope' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const isActive = (path: string) => {
|
||||||
|
if (path === '/') {
|
||||||
|
return route.path === '/';
|
||||||
|
}
|
||||||
|
return route.path.startsWith(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
isOpen: boolean;
|
||||||
|
isSaving?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
defineEmits(['close', 'open-help', 'save-project', 'open-save-modal', 'open-new-project-modal', 'open-project-list', 'open-auth-modal']);
|
||||||
|
|
||||||
|
import { useAuthStore } from '@/stores/useAuthStore';
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
|
const userInitials = computed(() => {
|
||||||
|
if (!authStore.user?.email) return '??';
|
||||||
|
return authStore.user.email.substring(0, 2).toUpperCase();
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
authStore.logout();
|
||||||
|
// emit('close'); // Optional: close menu on logout? Maybe better to keep open so they can login again if they want.
|
||||||
|
};
|
||||||
|
</script>
|
||||||
69
src/components/layout/navbar/NavbarProjectActions.vue
Normal file
69
src/components/layout/navbar/NavbarProjectActions.vue
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div v-if="isEditorActive" class="flex items-center gap-2 group">
|
||||||
|
<div class="text-right hidden lg:block">
|
||||||
|
<p class="text-[10px] uppercase tracking-wider font-bold text-gray-400 dark:text-gray-500 mb-[-2px]">Current Project</p>
|
||||||
|
<Tooltip text="Rename project">
|
||||||
|
<button @click="$emit('open-save-modal')" class="text-sm font-bold text-gray-800 dark:text-gray-200 hover:text-indigo-600 dark:hover:text-indigo-400 transition-colors truncate max-w-[160px]">
|
||||||
|
{{ projectStore.currentProject?.name || 'Untitled project' }}
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Mobile/Tablet simplified view -->
|
||||||
|
<button @click="$emit('open-save-modal')" class="lg:hidden text-sm font-bold text-gray-800 dark:text-gray-200 hover:text-indigo-600 dark:hover:text-indigo-400 transition-colors truncate max-w-[120px]">
|
||||||
|
{{ projectStore.currentProject?.name || 'Untitled' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isEditorActive" class="h-8 w-px bg-gray-200 dark:bg-gray-700 mx-1"></div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<Tooltip v-if="isEditorActive" :text="isSaving ? 'Saving...' : 'Save project'">
|
||||||
|
<button @click="$emit('save-project')" class="w-8 h-8 rounded-lg flex items-center justify-center text-gray-500 hover:text-indigo-600 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 transition-all" :disabled="isSaving">
|
||||||
|
<svg v-if="isSaving" class="animate-spin h-4 w-4 text-indigo-600 dark:text-indigo-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||||
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||||
|
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||||
|
</svg>
|
||||||
|
<i v-else class="fas fa-save"></i>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip v-if="isEditorActive && projectStore.currentProject" text="Save as...">
|
||||||
|
<button @click="$emit('open-save-modal', 'save-as')" class="w-8 h-8 rounded-lg flex items-center justify-center text-gray-500 hover:text-indigo-600 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 transition-all">
|
||||||
|
<i class="fas fa-clone"></i>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip text="New project">
|
||||||
|
<button @click="$emit('open-new-project-modal')" class="w-8 h-8 rounded-lg flex items-center justify-center text-gray-500 hover:text-indigo-600 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 transition-all">
|
||||||
|
<i class="fas fa-plus"></i>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip text="My projects">
|
||||||
|
<button @click="$emit('open-project-list')" class="w-8 h-8 rounded-lg flex items-center justify-center text-gray-500 hover:text-indigo-600 hover:bg-indigo-50 dark:hover:bg-indigo-900/30 transition-all">
|
||||||
|
<i class="fas fa-folder-open"></i>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
import { useProjectStore } from '@/stores/useProjectStore';
|
||||||
|
import Tooltip from '@/components/utilities/Tooltip.vue';
|
||||||
|
|
||||||
|
defineEmits(['save-project', 'open-save-modal', 'open-project-list', 'open-new-project-modal']);
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const projectStore = useProjectStore();
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
isSaving?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const isEditorActive = computed(() => route.name === 'editor');
|
||||||
|
</script>
|
||||||
27
src/components/layout/navbar/NavbarSocials.vue
Normal file
27
src/components/layout/navbar/NavbarSocials.vue
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<Tooltip text="Source Code">
|
||||||
|
<a href="https://gitea.adhd.sh/root/spritesheet-generator" target="_blank" rel="noopener noreferrer" class="text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white transition-colors">
|
||||||
|
<i class="fab fa-github text-lg"></i>
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Discord Community">
|
||||||
|
<a href="https://discord.gg/JTev3nzeDa" target="_blank" rel="noopener noreferrer" class="text-gray-500 hover:text-[#5865F2] dark:text-gray-400 dark:hover:text-[#5865F2] transition-colors">
|
||||||
|
<i class="fab fa-discord text-lg"></i>
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Help">
|
||||||
|
<button @click="$emit('open-help')" class="text-gray-500 hover:text-indigo-600 dark:text-gray-400 dark:hover:text-indigo-400 transition-colors">
|
||||||
|
<i class="fas fa-question-circle text-lg"></i>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<DarkModeToggle />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import DarkModeToggle from '../../utilities/DarkModeToggle.vue';
|
||||||
|
import Tooltip from '../../utilities/Tooltip.vue';
|
||||||
|
|
||||||
|
defineEmits(['open-help']);
|
||||||
|
</script>
|
||||||
68
src/components/layout/navbar/NavbarUserMenu.vue
Normal file
68
src/components/layout/navbar/NavbarUserMenu.vue
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="authStore.user" class="flex items-center gap-4">
|
||||||
|
<div class="relative" ref="userMenuRef">
|
||||||
|
<button @click="isUserMenuOpen = !isUserMenuOpen" class="w-9 h-9 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 text-white font-bold text-sm flex items-center justify-center shadow-md hover:shadow-lg transition-all border-2 border-white dark:border-gray-800">
|
||||||
|
{{ userInitials }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<transition
|
||||||
|
enter-active-class="transition ease-out duration-200"
|
||||||
|
enter-from-class="transform opacity-0 scale-95"
|
||||||
|
enter-to-class="transform opacity-100 scale-100"
|
||||||
|
leave-active-class="transition ease-in duration-75"
|
||||||
|
leave-from-class="transform opacity-100 scale-100"
|
||||||
|
leave-to-class="transform opacity-0 scale-95"
|
||||||
|
>
|
||||||
|
<div v-if="isUserMenuOpen" class="absolute right-0 mt-2 w-56 bg-white dark:bg-gray-900 rounded-xl shadow-xl border border-gray-200 dark:border-gray-800 overflow-hidden z-50">
|
||||||
|
<div class="p-4 border-b border-gray-100 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-800/50">
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 uppercase font-semibold tracking-wider mb-1">Signed in as</p>
|
||||||
|
<p class="text-sm font-medium text-gray-900 dark:text-white truncate" :title="authStore.user.email">{{ authStore.user.email }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="p-1">
|
||||||
|
<button @click="handleLogout" class="w-full text-left px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-red-50 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 rounded-lg transition-colors flex items-center gap-2">
|
||||||
|
<i class="fas fa-sign-out-alt"></i> Sign out
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<button @click="$emit('open-auth-modal')" class="btn btn-primary btn-sm shadow-indigo-500/20 shadow-lg">Login / Register</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
||||||
|
import { useAuthStore } from '@/stores/useAuthStore';
|
||||||
|
|
||||||
|
defineEmits(['open-auth-modal']);
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
const isUserMenuOpen = ref(false);
|
||||||
|
const userMenuRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const userInitials = computed(() => {
|
||||||
|
if (!authStore.user?.email) return '??';
|
||||||
|
return authStore.user.email.substring(0, 2).toUpperCase();
|
||||||
|
});
|
||||||
|
|
||||||
|
const closeUserMenu = (e: MouseEvent) => {
|
||||||
|
if (userMenuRef.value && !userMenuRef.value.contains(e.target as Node)) {
|
||||||
|
isUserMenuOpen.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
isUserMenuOpen.value = false;
|
||||||
|
authStore.logout();
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
document.addEventListener('click', closeUserMenu);
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
document.removeEventListener('click', closeUserMenu);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
89
src/components/project/NewProjectModal.vue
Normal file
89
src/components/project/NewProjectModal.vue
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<template>
|
||||||
|
<Modal :is-open="isOpen" @close="close" title="New project" :initialWidth="400" :initialHeight="320">
|
||||||
|
<div class="px-2 pt-2 pb-1">
|
||||||
|
<form @submit.prevent="handleSubmit">
|
||||||
|
<div class="grid grid-cols-2 gap-4 mb-3">
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1 uppercase tracking-wider">Sprite Width</label>
|
||||||
|
<div class="relative">
|
||||||
|
<input v-model.number="width" type="number" min="1" required class="w-full pl-3 pr-8 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" />
|
||||||
|
<span class="absolute right-3 top-2 text-gray-400 text-xs">px</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1 uppercase tracking-wider">Sprite Height</label>
|
||||||
|
<div class="relative">
|
||||||
|
<input v-model.number="height" type="number" min="1" required class="w-full pl-3 pr-8 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" />
|
||||||
|
<span class="absolute right-3 top-2 text-gray-400 text-xs">px</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-2 gap-4 mb-4">
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1 uppercase tracking-wider">Columns</label>
|
||||||
|
<input v-model.number="columns" type="number" min="1" max="20" required class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1 uppercase tracking-wider">Rows</label>
|
||||||
|
<input v-model.number="rows" type="number" min="1" required class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" title="Rows are dynamic but this sets an initial expectation" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-3">
|
||||||
|
<button type="button" @click="close" class="btn btn-secondary">Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary" :disabled="!isValid">Create project</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, watch } from 'vue';
|
||||||
|
import Modal from '@/components/utilities/Modal.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
isOpen: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'close'): void;
|
||||||
|
(e: 'create', config: { width: number; height: number; columns: number; rows: number }): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const width = ref(64);
|
||||||
|
const height = ref(64);
|
||||||
|
const columns = ref(8);
|
||||||
|
const rows = ref(8);
|
||||||
|
|
||||||
|
const isValid = computed(() => {
|
||||||
|
return width.value > 0 && height.value > 0 && columns.value > 0 && rows.value > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reset to defaults when opened
|
||||||
|
watch(
|
||||||
|
() => props.isOpen,
|
||||||
|
val => {
|
||||||
|
if (val) {
|
||||||
|
width.value = 64;
|
||||||
|
height.value = 64;
|
||||||
|
columns.value = 8;
|
||||||
|
rows.value = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const close = () => emit('close');
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (isValid.value) {
|
||||||
|
emit('create', {
|
||||||
|
width: width.value,
|
||||||
|
height: height.value,
|
||||||
|
columns: columns.value,
|
||||||
|
rows: rows.value,
|
||||||
|
});
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
245
src/components/project/ProjectList.vue
Normal file
245
src/components/project/ProjectList.vue
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
<template>
|
||||||
|
<Modal :is-open="isOpen" @close="close" title="My projects" :initialWidth="900" :initialHeight="800" noPadding>
|
||||||
|
<div class="flex flex-col h-full bg-white dark:bg-gray-900">
|
||||||
|
<!-- Search Header -->
|
||||||
|
<div class="px-6 py-4 border-b border-gray-100 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-800/20">
|
||||||
|
<div class="mb-4">
|
||||||
|
<p class="text-sm text-gray-500 dark:text-gray-400">Manage your saved sprite sheets</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="relative">
|
||||||
|
<i class="fas fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
|
||||||
|
<input
|
||||||
|
v-model="searchQuery"
|
||||||
|
type="text"
|
||||||
|
placeholder="Search projects..."
|
||||||
|
class="w-full pl-10 pr-4 py-2 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500 dark:focus:border-indigo-500 outline-none transition-all text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Content -->
|
||||||
|
<div class="flex-1 overflow-y-auto custom-scrollbar p-6 bg-gray-50 dark:bg-black/20">
|
||||||
|
<!-- Loading State -->
|
||||||
|
<div v-if="loading" class="flex flex-col items-center justify-center py-12">
|
||||||
|
<div class="w-10 h-10 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin mb-4"></div>
|
||||||
|
<p class="text-gray-500 font-medium">Loading projects...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Empty State -->
|
||||||
|
<div v-else-if="projects.length === 0" class="flex flex-col items-center justify-center py-12 text-center h-full">
|
||||||
|
<div class="w-20 h-20 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center mb-4">
|
||||||
|
<i class="fas fa-folder-open text-3xl text-gray-400 dark:text-gray-500"></i>
|
||||||
|
</div>
|
||||||
|
<h3 class="text-lg font-bold text-gray-900 dark:text-gray-100 mb-2">No projects yet</h3>
|
||||||
|
<p class="text-gray-500 dark:text-gray-400 max-w-xs mb-6">Create your first project or load an example to get started with Sprite Sheet Generator.</p>
|
||||||
|
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<button @click="loadExample" class="btn btn-secondary flex items-center gap-2"><i class="fas fa-lightbulb"></i> Load Example</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- No Search Results -->
|
||||||
|
<div v-else-if="filteredProjects.length === 0" class="flex flex-col items-center justify-center py-12 text-center">
|
||||||
|
<div class="w-16 h-16 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center mb-4">
|
||||||
|
<i class="fas fa-search text-2xl text-gray-400 dark:text-gray-500"></i>
|
||||||
|
</div>
|
||||||
|
<h3 class="text-md font-bold text-gray-900 dark:text-gray-100 mb-1">No matches found</h3>
|
||||||
|
<p class="text-gray-500 dark:text-gray-400 text-sm">No projects match "{{ searchQuery }}"</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Project List -->
|
||||||
|
<div v-else class="flex flex-col gap-3">
|
||||||
|
<div
|
||||||
|
v-for="project in filteredProjects"
|
||||||
|
:key="project.id"
|
||||||
|
class="group bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 hover:border-indigo-500 dark:hover:border-indigo-500 hover:shadow-md dark:hover:shadow-indigo-500/10 transition-all cursor-pointer overflow-hidden flex flex-col sm:flex-row h-auto sm:h-32"
|
||||||
|
@click="selectProject(project)"
|
||||||
|
>
|
||||||
|
<!-- Left: Preview Stripe -->
|
||||||
|
<div class="w-full sm:w-48 bg-gray-100 dark:bg-black/30 flex items-center justify-center relative overflow-hidden border-b sm:border-b-0 sm:border-r border-gray-100 dark:border-gray-700/50 p-2">
|
||||||
|
<div class="absolute inset-0 bg-checkerboard opacity-50"></div>
|
||||||
|
|
||||||
|
<!-- Sprite Stack for Preview -->
|
||||||
|
<div v-if="getProjectSprites(project, 1).length > 0" class="relative z-10 flex -space-x-4">
|
||||||
|
<div
|
||||||
|
v-for="(sprite, idx) in getProjectSprites(project, 3)"
|
||||||
|
:key="idx"
|
||||||
|
class="w-16 h-16 rounded-lg bg-white dark:bg-gray-700 border-2 border-white dark:border-gray-600 shadow-lg flex items-center justify-center overflow-hidden transform transition-transform group-hover:scale-105 group-hover:first:-rotate-6 group-hover:last:rotate-6"
|
||||||
|
:style="{ zIndex: 10 - idx }"
|
||||||
|
>
|
||||||
|
<img :src="sprite.base64" class="w-full h-full object-contain" style="image-rendering: pixelated" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Fallback Icon -->
|
||||||
|
<div v-else class="relative z-10 w-16 h-16 rounded-lg bg-white dark:bg-gray-700 border-2 border-white dark:border-gray-600 shadow-lg flex items-center justify-center text-indigo-300 dark:text-indigo-400/50 font-bold text-2xl">
|
||||||
|
{{ project.name.charAt(0).toUpperCase() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- content -->
|
||||||
|
<div class="flex-1 p-4 flex flex-col justify-center min-w-0">
|
||||||
|
<div class="flex items-start justify-between">
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-gray-900 dark:text-gray-100 truncate text-lg mb-1 group-hover:text-indigo-600 dark:group-hover:text-indigo-400 transition-colors">{{ project.name }}</h3>
|
||||||
|
<div class="flex flex-wrap gap-x-4 gap-y-1 text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
<span class="flex items-center gap-1"><i class="fas fa-layer-group opacity-70"></i> {{ project.data?.layers?.length || 0 }} layers</span>
|
||||||
|
<span class="flex items-center gap-1"><i class="fas fa-border-all opacity-70"></i> {{ project.data?.columns }} columns</span>
|
||||||
|
<span class="flex items-center gap-1"><i class="fas fa-images opacity-70"></i> {{ getSpriteCount(project) }} sprites</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button @click.stop="deleteProject(project.id)" class="opacity-0 group-hover:opacity-100 text-gray-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 p-2 rounded-lg transition-all" title="Delete Project">
|
||||||
|
<i class="fas fa-trash"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-auto pt-3 flex items-center justify-between">
|
||||||
|
<span class="text-xs text-gray-400"> Updated {{ formatDate(project.updated) }} </span>
|
||||||
|
<span class="text-xs font-bold text-indigo-600 dark:text-indigo-400 flex items-center gap-1 transform translate-x-2 opacity-0 group-hover:translate-x-0 group-hover:opacity-100 transition-all"> Open Project <i class="fas fa-arrow-right"></i> </span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<div class="px-6 py-4 border-t border-gray-100 dark:border-gray-800 flex justify-between items-center bg-white dark:bg-gray-900">
|
||||||
|
<p class="text-xs text-gray-400" v-if="projects.length > 0">Showing {{ filteredProjects.length }} of {{ projects.length }} project{{ projects.length !== 1 ? 's' : '' }}</p>
|
||||||
|
<div class="flex gap-2 ml-auto">
|
||||||
|
<button v-if="projects.length > 0" @click="loadExample" class="text-xs font-medium text-gray-500 hover:text-indigo-600 dark:hover:text-indigo-400 px-3 py-2">Load Example</button>
|
||||||
|
<button @click="close" class="btn btn-secondary text-sm">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, toRefs, watch, ref, computed } from 'vue';
|
||||||
|
import { useProjectStore, type Project } from '@/stores/useProjectStore';
|
||||||
|
import { useProjectManager } from '@/composables/useProjectManager';
|
||||||
|
import Modal from '@/components/utilities/Modal.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
isOpen: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'close'): void;
|
||||||
|
(e: 'open-project', project: Project): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const projectStore = useProjectStore();
|
||||||
|
const { projects, isLoading: loading } = toRefs(projectStore);
|
||||||
|
const { createProject, loadProjectData } = useProjectManager();
|
||||||
|
|
||||||
|
const searchQuery = ref('');
|
||||||
|
|
||||||
|
const filteredProjects = computed(() => {
|
||||||
|
if (!searchQuery.value) return projects.value;
|
||||||
|
const query = searchQuery.value.toLowerCase();
|
||||||
|
return projects.value.filter(p => p.name.toLowerCase().includes(query));
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.isOpen,
|
||||||
|
isOpen => {
|
||||||
|
if (isOpen) {
|
||||||
|
projectStore.fetchProjects();
|
||||||
|
searchQuery.value = ''; // Reset search on open
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.isOpen) {
|
||||||
|
projectStore.fetchProjects();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const close = () => emit('close');
|
||||||
|
|
||||||
|
const selectProject = (project: Project) => {
|
||||||
|
emit('open-project', project);
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteProject = async (id: string) => {
|
||||||
|
await projectStore.deleteProject(id);
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDate = (dateString: string) => {
|
||||||
|
return new Date(dateString).toLocaleDateString(undefined, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadExample = async () => {
|
||||||
|
createProject({ width: 32, height: 32, columns: 8, rows: 8 });
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getProjectSprites = (project: Project, limit: number) => {
|
||||||
|
const sprites: any[] = [];
|
||||||
|
if (!project.data || !project.data.layers) return sprites;
|
||||||
|
|
||||||
|
// Iterate through layers to find sprites
|
||||||
|
for (const layer of project.data.layers as any[]) {
|
||||||
|
// Check if layer is visible (default to true if undefined)
|
||||||
|
if (layer.visible === false) continue;
|
||||||
|
|
||||||
|
if (layer.sprites && layer.sprites.length > 0) {
|
||||||
|
for (const sprite of layer.sprites) {
|
||||||
|
if (sprites.length < limit) {
|
||||||
|
sprites.push(sprite);
|
||||||
|
} else {
|
||||||
|
return sprites;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sprites;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSpriteCount = (project: Project) => {
|
||||||
|
if (!project.data || !project.data.layers) return 0;
|
||||||
|
return (project.data.layers as any[]).reduce((acc: number, layer: any) => acc + (layer.sprites?.length || 0), 0);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.bg-checkerboard {
|
||||||
|
background-color: #fff;
|
||||||
|
background-image: linear-gradient(45deg, #e5e5e5 25%, transparent 25%), linear-gradient(-45deg, #e5e5e5 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e5e5e5 75%), linear-gradient(-45deg, transparent 75%, #e5e5e5 75%);
|
||||||
|
background-size: 8px 8px;
|
||||||
|
background-position:
|
||||||
|
0 0,
|
||||||
|
0 4px,
|
||||||
|
4px -4px,
|
||||||
|
-4px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .bg-checkerboard {
|
||||||
|
background-color: #374151;
|
||||||
|
background-image: linear-gradient(45deg, #4b5563 25%, transparent 25%), linear-gradient(-45deg, #4b5563 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #4b5563 75%), linear-gradient(-45deg, transparent 75%, #4b5563 75%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-fade-in-up {
|
||||||
|
animation: fadeInUp 0.3s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeInUp {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(20px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
55
src/components/project/SaveProjectModal.vue
Normal file
55
src/components/project/SaveProjectModal.vue
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<template>
|
||||||
|
<Modal :is-open="isOpen" @close="close" title="Save project" :initialWidth="400" :initialHeight="250">
|
||||||
|
<div class="px-2 pt-2 pb-1">
|
||||||
|
<form @submit.prevent="handleSubmit">
|
||||||
|
<div class="mb-4">
|
||||||
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Project Name</label>
|
||||||
|
<input v-model="projectName" type="text" required class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-indigo-500 dark:bg-gray-700 dark:text-white" placeholder="My Awesome Spritesheet" ref="inputRef" />
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end gap-3">
|
||||||
|
<button type="button" @click="close" class="btn btn-secondary">Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary" :disabled="!projectName.trim()">Save</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch, nextTick } from 'vue';
|
||||||
|
import Modal from '@/components/utilities/Modal.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
isOpen: boolean;
|
||||||
|
initialName?: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'close'): void;
|
||||||
|
(e: 'save', name: string): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const projectName = ref('');
|
||||||
|
const inputRef = ref<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.isOpen,
|
||||||
|
isOpen => {
|
||||||
|
if (isOpen) {
|
||||||
|
projectName.value = props.initialName || '';
|
||||||
|
nextTick(() => {
|
||||||
|
inputRef.value?.focus();
|
||||||
|
inputRef.value?.select();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const close = () => emit('close');
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (projectName.value.trim()) {
|
||||||
|
emit('save', projectName.value);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
72
src/components/utilities/CopyToFrameModal.vue
Normal file
72
src/components/utilities/CopyToFrameModal.vue
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<template>
|
||||||
|
<Modal :is-open="isOpen" @close="close" title="Copy sprite to frame" :initialWidth="380" :initialHeight="320">
|
||||||
|
<div class="p-4 flex flex-col h-full">
|
||||||
|
<div class="space-y-4 flex-1">
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Target frame</label>
|
||||||
|
<select v-model.number="targetFrame" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500">
|
||||||
|
<option v-for="i in maxFrameCount" :key="i" :value="i - 1">Frame {{ i }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Target layer</label>
|
||||||
|
<select v-model="targetLayerId" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500">
|
||||||
|
<option v-for="layer in layers" :key="layer.id" :value="layer.id">{{ layer.name }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-3 mt-6 pt-4 border-t border-gray-100 dark:border-gray-700">
|
||||||
|
<button @click="close" class="px-4 py-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors font-medium text-sm">Cancel</button>
|
||||||
|
<button @click="confirm" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium text-sm">Copy</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, watch } from 'vue';
|
||||||
|
import Modal from './Modal.vue';
|
||||||
|
import type { Layer } from '@/types/sprites';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
isOpen: boolean;
|
||||||
|
layers: Layer[];
|
||||||
|
initialLayerId?: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'close'): void;
|
||||||
|
(e: 'copy', targetLayerId: string, targetFrameIndex: number): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const targetFrame = ref(0);
|
||||||
|
const targetLayerId = ref('');
|
||||||
|
|
||||||
|
const maxFrameCount = computed(() => {
|
||||||
|
const maxLen = Math.max(1, ...props.layers.map(l => l.sprites.length));
|
||||||
|
return maxLen + 1; // Allow copying to one frame beyond current max
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.isOpen,
|
||||||
|
isOpen => {
|
||||||
|
if (isOpen) {
|
||||||
|
targetFrame.value = 0;
|
||||||
|
targetLayerId.value = props.initialLayerId || (props.layers.length > 0 ? props.layers[0].id : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
emit('close');
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirm = () => {
|
||||||
|
if (targetLayerId.value) {
|
||||||
|
emit('copy', targetLayerId.value, targetFrame.value);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<button @click="settingsStore.toggleDarkMode()" class="p-2 rounded-lg transition-colors" :class="settingsStore.darkMode ? 'text-yellow-400 hover:bg-gray-700' : 'text-gray-700 hover:bg-gray-100'" aria-label="Toggle dark mode" data-rybbit-event="toggle-dark-mode">
|
<button @click="settingsStore.toggleDarkMode()" class="btn btn-secondary mr-1" aria-label="Toggle dark mode" data-rybbit-event="toggle-dark-mode"><i :class="settingsStore.darkMode ? 'fas fa-sun' : 'fas fa-moon'"></i> Theme</button>
|
||||||
<i :class="settingsStore.darkMode ? 'fas fa-sun' : 'fas fa-moon'"></i>
|
|
||||||
</button>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|||||||
@@ -10,31 +10,39 @@
|
|||||||
width: isFullScreen ? '100%' : `${size.width}px`,
|
width: isFullScreen ? '100%' : `${size.width}px`,
|
||||||
height: isFullScreen ? '100%' : `${size.height}px`,
|
height: isFullScreen ? '100%' : `${size.height}px`,
|
||||||
}"
|
}"
|
||||||
class="bg-white dark:bg-gray-800 rounded-2xl border-2 border-gray-300 dark:border-gray-700 shadow-xl flex flex-col fixed z-50 transition-colors duration-300"
|
class="bg-white dark:bg-gray-800 rounded-2xl border border-gray-200 dark:border-gray-700 shadow-2xl flex flex-col fixed z-50 transition-colors duration-300 max-w-full max-h-full"
|
||||||
:class="{ 'rounded-none border-0': isFullScreen, 'select-none': isDragging }"
|
:class="{ 'rounded-none border-0': isFullScreen, 'select-none': isDragging }"
|
||||||
>
|
>
|
||||||
<!-- Header with drag handle -->
|
<!-- Header with drag handle -->
|
||||||
<div class="flex justify-between items-center p-4 border-b border-gray-200 dark:border-gray-700" :class="{ 'cursor-move': !isFullScreen && !isMobile }" @mousedown="startDrag" @touchstart="handleTouchStart">
|
<div class="flex justify-between items-center px-5 py-4 border-b border-gray-100 dark:border-gray-700/50" :class="{ 'cursor-move': !isFullScreen && !isMobile }" @mousedown="startDrag" @touchstart="handleTouchStart">
|
||||||
<h3 class="text-xl sm:text-2xl font-semibold text-gray-900 dark:text-gray-100 truncate pr-2">{{ title }}</h3>
|
<h3 class="text-lg sm:text-lg font-bold text-gray-800 dark:text-gray-100 truncate pr-2">{{ title }}</h3>
|
||||||
<div class="flex items-center space-x-2">
|
<div class="flex items-center space-x-1">
|
||||||
<button @click="toggleFullScreen" @mousedown.stop @touchstart.stop class="p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors" data-rybbit-event="modal-fullscreen">
|
<button @click="toggleFullScreen" @mousedown.stop @touchstart.stop class="p-1.5 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-all" data-rybbit-event="modal-fullscreen">
|
||||||
<img src="@/assets/images/fullscreen-icon.svg" class="w-4 h-4 dark:invert" alt="Fullscreen" :class="{ 'rotate-180': isFullScreen }" />
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" v-if="!isFullScreen">
|
||||||
|
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
|
||||||
|
</svg>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" v-else>
|
||||||
|
<path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3" />
|
||||||
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<button @click="close" @mousedown.stop @touchstart.stop class="p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors" data-rybbit-event="modal-close">
|
<button @click="close" @mousedown.stop @touchstart.stop class="p-1.5 text-gray-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-md transition-all" data-rybbit-event="modal-close">
|
||||||
<img src="@/assets/images/close-icon.svg" class="w-5 h-5 dark:invert" alt="Close" />
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||||||
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||||||
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Body -->
|
<!-- Body -->
|
||||||
<div class="p-4 sm:p-6 flex-1 overflow-auto">
|
<div :class="[noPadding ? '' : 'p-5 sm:p-6', 'flex-1 overflow-auto']">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Resize handle -->
|
<!-- Resize handle -->
|
||||||
<div v-if="!isFullScreen && !isMobile" class="absolute bottom-0 right-0 w-8 h-8 cursor-se-resize" @mousedown="startResize" @touchstart="startResize">
|
<div v-if="!isFullScreen && !isMobile" class="absolute bottom-0 right-0 w-6 h-6 cursor-se-resize flex items-end justify-end p-1 opacity-50 hover:opacity-100 transition-opacity" @mousedown="startResize" @touchstart="startResize">
|
||||||
<svg class="w-8 h-8 text-gray-400 dark:text-gray-500" viewBox="0 0 24 24" fill="currentColor">
|
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500" viewBox="0 0 24 24" fill="currentColor">
|
||||||
<path d="M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22Z" />
|
<path d="M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22Z" />
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -49,6 +57,7 @@
|
|||||||
title: string;
|
title: string;
|
||||||
initialWidth?: number;
|
initialWidth?: number;
|
||||||
initialHeight?: number;
|
initialHeight?: number;
|
||||||
|
noPadding?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -59,7 +68,7 @@
|
|||||||
const position = ref({ x: 0, y: 0 });
|
const position = ref({ x: 0, y: 0 });
|
||||||
const size = ref({
|
const size = ref({
|
||||||
width: props.initialWidth || 800,
|
width: props.initialWidth || 800,
|
||||||
height: props.initialHeight || 600,
|
height: props.initialHeight || 400,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isDragging = ref(false);
|
const isDragging = ref(false);
|
||||||
@@ -181,16 +190,19 @@
|
|||||||
|
|
||||||
const constrainSize = (width: number, height: number) => {
|
const constrainSize = (width: number, height: number) => {
|
||||||
return {
|
return {
|
||||||
width: Math.max(400, Math.min(width, window.innerWidth - position.value.x)),
|
width: Math.max(300, Math.min(width, window.innerWidth - position.value.x)),
|
||||||
height: Math.max(300, Math.min(height, window.innerHeight - position.value.y)),
|
height: Math.max(200, Math.min(height, window.innerHeight - position.value.y)),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const centerModal = () => {
|
const centerModal = () => {
|
||||||
if (!modalRef.value) return;
|
if (!modalRef.value) return;
|
||||||
|
const effectiveWidth = Math.min(size.value.width, window.innerWidth);
|
||||||
|
const effectiveHeight = Math.min(size.value.height, window.innerHeight);
|
||||||
|
|
||||||
position.value = {
|
position.value = {
|
||||||
x: (window.innerWidth - size.value.width) / 2,
|
x: Math.max(0, (window.innerWidth - effectiveWidth) / 2),
|
||||||
y: (window.innerHeight - size.value.height) / 2,
|
y: Math.max(0, (window.innerHeight - effectiveHeight) / 2),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
21
src/components/utilities/ToastContainer.vue
Normal file
21
src/components/utilities/ToastContainer.vue
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<template>
|
||||||
|
<div class="fixed bottom-5 right-5 z-[100] flex flex-col items-end space-y-2 pointer-events-none">
|
||||||
|
<TransitionGroup
|
||||||
|
enter-active-class="transform ease-out duration-300 transition"
|
||||||
|
enter-from-class="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
|
||||||
|
enter-to-class="translate-y-0 opacity-100 sm:translate-x-0"
|
||||||
|
leave-active-class="transition ease-in duration-100"
|
||||||
|
leave-from-class="opacity-100"
|
||||||
|
leave-to-class="opacity-0"
|
||||||
|
>
|
||||||
|
<ToastItem v-for="toast in toasts" :key="toast.id" :toast="toast" />
|
||||||
|
</TransitionGroup>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useToast } from '@/composables/useToast';
|
||||||
|
import ToastItem from './ToastItem.vue';
|
||||||
|
|
||||||
|
const { toasts } = useToast();
|
||||||
|
</script>
|
||||||
128
src/components/utilities/ToastItem.vue
Normal file
128
src/components/utilities/ToastItem.vue
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="flex items-center w-full max-w-sm p-4 mb-4 text-gray-500 bg-white dark:bg-gray-800 rounded-lg shadow-lg dark:text-gray-400 border-l-4 pointer-events-auto transform transition-all duration-300 ease-in-out"
|
||||||
|
:class="[typeClasses[props.toast.type], isLeaving ? 'opacity-0 translate-x-full' : 'opacity-100 translate-x-0']"
|
||||||
|
role="alert"
|
||||||
|
>
|
||||||
|
<div class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 rounded-lg" :class="iconBgClasses[props.toast.type]">
|
||||||
|
<component :is="icons[props.toast.type]" class="w-5 h-5" :class="iconColorClasses[props.toast.type]" />
|
||||||
|
</div>
|
||||||
|
<div class="ml-3 text-sm font-medium pr-4">{{ props.toast.message }}</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="ml-auto -mx-1.5 -my-1.5 bg-white text-gray-400 hover:text-gray-900 rounded-lg focus:ring-2 focus:ring-gray-300 p-1.5 hover:bg-gray-100 inline-flex h-8 w-8 dark:text-gray-500 dark:hover:text-white dark:bg-gray-800 dark:hover:bg-gray-700"
|
||||||
|
@click="dismiss"
|
||||||
|
aria-label="Close"
|
||||||
|
>
|
||||||
|
<span class="sr-only">Close</span>
|
||||||
|
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
|
||||||
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, h } from 'vue';
|
||||||
|
import type { Toast } from '@/composables/useToast';
|
||||||
|
import { useToast } from '@/composables/useToast';
|
||||||
|
|
||||||
|
// Simple functional components for icons using h (avoid runtime compiler)
|
||||||
|
const SuccessIcon = {
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
'svg',
|
||||||
|
{
|
||||||
|
'aria-hidden': 'true',
|
||||||
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
|
fill: 'currentColor',
|
||||||
|
viewBox: '0 0 20 20',
|
||||||
|
},
|
||||||
|
[h('path', { d: 'M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z' })]
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const ErrorIcon = {
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
'svg',
|
||||||
|
{
|
||||||
|
'aria-hidden': 'true',
|
||||||
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
|
fill: 'currentColor',
|
||||||
|
viewBox: '0 0 20 20',
|
||||||
|
},
|
||||||
|
[h('path', { d: 'M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 11.793a1 1 0 1 1-1.414 1.414L10 11.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L8.586 10 6.293 7.707a1 1 0 0 1 1.414-1.414L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414L11.414 10l2.293 2.293Z' })]
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const InfoIcon = {
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
'svg',
|
||||||
|
{
|
||||||
|
'aria-hidden': 'true',
|
||||||
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
|
fill: 'currentColor',
|
||||||
|
viewBox: '0 0 20 20',
|
||||||
|
},
|
||||||
|
[h('path', { d: 'M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z' })]
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const WarningIcon = {
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
'svg',
|
||||||
|
{
|
||||||
|
'aria-hidden': 'true',
|
||||||
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
|
fill: 'currentColor',
|
||||||
|
viewBox: '0 0 20 20',
|
||||||
|
},
|
||||||
|
[h('path', { d: 'M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM10 15a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm1-4a1 1 0 0 1-2 0V6a1 1 0 0 1 2 0v5Z' })]
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
toast: Toast;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const { removeToast } = useToast();
|
||||||
|
const isLeaving = ref(false);
|
||||||
|
|
||||||
|
const dismiss = () => {
|
||||||
|
isLeaving.value = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
removeToast(props.toast.id);
|
||||||
|
}, 300); // Match transition duration
|
||||||
|
};
|
||||||
|
|
||||||
|
const icons = {
|
||||||
|
success: SuccessIcon,
|
||||||
|
error: ErrorIcon,
|
||||||
|
info: InfoIcon,
|
||||||
|
warning: WarningIcon,
|
||||||
|
};
|
||||||
|
|
||||||
|
const typeClasses = {
|
||||||
|
success: 'border-green-500 bg-white dark:bg-gray-800',
|
||||||
|
error: 'border-red-500 bg-white dark:bg-gray-800',
|
||||||
|
info: 'border-blue-500 bg-white dark:bg-gray-800',
|
||||||
|
warning: 'border-orange-500 bg-white dark:bg-gray-800',
|
||||||
|
};
|
||||||
|
|
||||||
|
const iconBgClasses = {
|
||||||
|
success: 'bg-green-100 dark:bg-green-800',
|
||||||
|
error: 'bg-red-100 dark:bg-red-800',
|
||||||
|
info: 'bg-blue-100 dark:bg-blue-800',
|
||||||
|
warning: 'bg-orange-100 dark:bg-orange-800',
|
||||||
|
};
|
||||||
|
|
||||||
|
const iconColorClasses = {
|
||||||
|
success: 'text-green-500 dark:text-green-200',
|
||||||
|
error: 'text-red-500 dark:text-red-200',
|
||||||
|
info: 'text-blue-500 dark:text-blue-200',
|
||||||
|
warning: 'text-orange-500 dark:text-orange-200',
|
||||||
|
};
|
||||||
|
</script>
|
||||||
79
src/components/utilities/Tooltip.vue
Normal file
79
src/components/utilities/Tooltip.vue
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<template>
|
||||||
|
<div class="inline-block" @mouseenter="handleMouseEnter" @mouseleave="handleMouseLeave" @mousemove="handleMouseMove">
|
||||||
|
<slot />
|
||||||
|
<Teleport to="body">
|
||||||
|
<div v-if="show && text" ref="tooltipRef" class="fixed px-2.5 py-1.5 text-xs font-medium text-white bg-gray-900 dark:bg-gray-700 rounded-md shadow-lg whitespace-nowrap pointer-events-none" :style="tooltipStyle">
|
||||||
|
{{ text }}
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue';
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
text: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const show = ref(false);
|
||||||
|
const mouseX = ref(0);
|
||||||
|
const mouseY = ref(0);
|
||||||
|
const tooltipRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const handleMouseEnter = () => {
|
||||||
|
show.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseLeave = () => {
|
||||||
|
show.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseMove = (e: MouseEvent) => {
|
||||||
|
mouseX.value = e.clientX;
|
||||||
|
mouseY.value = e.clientY;
|
||||||
|
};
|
||||||
|
|
||||||
|
const tooltipStyle = computed(() => {
|
||||||
|
const offsetX = 12;
|
||||||
|
const offsetY = 16;
|
||||||
|
const padding = 8;
|
||||||
|
|
||||||
|
let x = mouseX.value + offsetX;
|
||||||
|
let y = mouseY.value + offsetY;
|
||||||
|
|
||||||
|
// Get tooltip dimensions (estimate if not mounted yet)
|
||||||
|
const tooltipWidth = tooltipRef.value?.offsetWidth || 200;
|
||||||
|
const tooltipHeight = tooltipRef.value?.offsetHeight || 30;
|
||||||
|
|
||||||
|
// Screen boundaries
|
||||||
|
const screenWidth = window.innerWidth;
|
||||||
|
const screenHeight = window.innerHeight;
|
||||||
|
|
||||||
|
// Adjust horizontal position if too close to right edge
|
||||||
|
if (x + tooltipWidth + padding > screenWidth) {
|
||||||
|
x = mouseX.value - tooltipWidth - offsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust horizontal position if too close to left edge
|
||||||
|
if (x < padding) {
|
||||||
|
x = padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust vertical position if too close to bottom edge
|
||||||
|
if (y + tooltipHeight + padding > screenHeight) {
|
||||||
|
y = mouseY.value - tooltipHeight - offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust vertical position if too close to top edge
|
||||||
|
if (y < padding) {
|
||||||
|
y = padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
left: `${x}px`,
|
||||||
|
top: `${y}px`,
|
||||||
|
zIndex: 99999,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
113
src/composables/useBackgroundStyles.ts
Normal file
113
src/composables/useBackgroundStyles.ts
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import { computed, type Ref, type ComputedRef } from 'vue';
|
||||||
|
|
||||||
|
export interface BackgroundStylesOptions {
|
||||||
|
backgroundColor: Ref<string> | ComputedRef<string> | string;
|
||||||
|
checkerboardEnabled?: Ref<boolean> | ComputedRef<boolean> | boolean;
|
||||||
|
darkMode?: Ref<boolean> | ComputedRef<boolean> | boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackgroundStyles {
|
||||||
|
backgroundColor: string;
|
||||||
|
backgroundImage: string;
|
||||||
|
backgroundSize: string;
|
||||||
|
backgroundPosition: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composable for generating consistent background styles across components.
|
||||||
|
* Handles transparent backgrounds with checkerboard patterns and dark mode.
|
||||||
|
*/
|
||||||
|
export function useBackgroundStyles(options: BackgroundStylesOptions) {
|
||||||
|
// Helper to get reactive values
|
||||||
|
const getBackgroundColor = () => (typeof options.backgroundColor === 'string' ? options.backgroundColor : options.backgroundColor.value);
|
||||||
|
const getCheckerboardEnabled = () => (typeof options.checkerboardEnabled === 'boolean' ? options.checkerboardEnabled : (options.checkerboardEnabled?.value ?? true));
|
||||||
|
const getDarkMode = () => (typeof options.darkMode === 'boolean' ? options.darkMode : (options.darkMode?.value ?? false));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the background color.
|
||||||
|
*/
|
||||||
|
const backgroundColor = computed(() => {
|
||||||
|
const bg = getBackgroundColor();
|
||||||
|
return bg === 'transparent' ? 'transparent' : bg;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the background image (checkerboard pattern for transparent backgrounds).
|
||||||
|
*/
|
||||||
|
const backgroundImage = computed(() => {
|
||||||
|
const bg = getBackgroundColor();
|
||||||
|
const checkerboardEnabled = getCheckerboardEnabled();
|
||||||
|
const darkMode = getDarkMode();
|
||||||
|
|
||||||
|
if (bg === 'transparent' && checkerboardEnabled) {
|
||||||
|
// Checkerboard pattern for transparent backgrounds (dark mode friendly)
|
||||||
|
const color = darkMode ? '#4b5563' : '#d1d5db';
|
||||||
|
return `linear-gradient(45deg, ${color} 25%, transparent 25%), linear-gradient(-45deg, ${color} 25%, transparent 25%), linear-gradient(45deg, transparent 75%, ${color} 75%), linear-gradient(-45deg, transparent 75%, ${color} 75%)`;
|
||||||
|
}
|
||||||
|
return 'none';
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the background size.
|
||||||
|
*/
|
||||||
|
const backgroundSize = computed(() => {
|
||||||
|
const bg = getBackgroundColor();
|
||||||
|
return bg === 'transparent' ? '20px 20px' : 'auto';
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the background position.
|
||||||
|
*/
|
||||||
|
const backgroundPosition = computed(() => {
|
||||||
|
const bg = getBackgroundColor();
|
||||||
|
return bg === 'transparent' ? '0 0, 0 10px, 10px -10px, -10px 0px' : '0 0';
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all background styles as a single object.
|
||||||
|
*/
|
||||||
|
const backgroundStyles = computed<BackgroundStyles>(() => ({
|
||||||
|
backgroundColor: backgroundColor.value,
|
||||||
|
backgroundImage: backgroundImage.value,
|
||||||
|
backgroundSize: backgroundSize.value,
|
||||||
|
backgroundPosition: backgroundPosition.value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return {
|
||||||
|
backgroundColor,
|
||||||
|
backgroundImage,
|
||||||
|
backgroundSize,
|
||||||
|
backgroundPosition,
|
||||||
|
backgroundStyles,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standalone helper to get background styles.
|
||||||
|
* Useful when you don't need the full composable.
|
||||||
|
*/
|
||||||
|
export function getBackgroundStyles(
|
||||||
|
backgroundColor: string,
|
||||||
|
options: {
|
||||||
|
checkerboardEnabled?: boolean;
|
||||||
|
darkMode?: boolean;
|
||||||
|
} = {}
|
||||||
|
): BackgroundStyles {
|
||||||
|
const checkerboardEnabled = options.checkerboardEnabled ?? true;
|
||||||
|
const darkMode = options.darkMode ?? false;
|
||||||
|
|
||||||
|
const bg = backgroundColor === 'transparent' ? 'transparent' : backgroundColor;
|
||||||
|
|
||||||
|
let bgImage = 'none';
|
||||||
|
if (backgroundColor === 'transparent' && checkerboardEnabled) {
|
||||||
|
const color = darkMode ? '#4b5563' : '#d1d5db';
|
||||||
|
bgImage = `linear-gradient(45deg, ${color} 25%, transparent 25%), linear-gradient(-45deg, ${color} 25%, transparent 25%), linear-gradient(45deg, transparent 75%, ${color} 75%), linear-gradient(-45deg, transparent 75%, ${color} 75%)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
backgroundColor: bg,
|
||||||
|
backgroundImage: bgImage,
|
||||||
|
backgroundSize: backgroundColor === 'transparent' ? '20px 20px' : 'auto',
|
||||||
|
backgroundPosition: backgroundColor === 'transparent' ? '0 0, 0 10px, 10px -10px, -10px 0px' : '0 0',
|
||||||
|
};
|
||||||
|
}
|
||||||
48
src/composables/useBlog.ts
Normal file
48
src/composables/useBlog.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import matter from 'gray-matter';
|
||||||
|
|
||||||
|
export interface BlogPost {
|
||||||
|
slug: string;
|
||||||
|
title: string;
|
||||||
|
date: string;
|
||||||
|
description: string;
|
||||||
|
image: string;
|
||||||
|
content: string;
|
||||||
|
keywords?: string;
|
||||||
|
author?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useBlog() {
|
||||||
|
const getPosts = async (): Promise<BlogPost[]> => {
|
||||||
|
const modules = import.meta.glob('../blog/*.md', { query: '?raw', import: 'default' });
|
||||||
|
const posts: BlogPost[] = [];
|
||||||
|
|
||||||
|
for (const path in modules) {
|
||||||
|
const content = (await modules[path]()) as string;
|
||||||
|
const { data, content: markdownContent } = matter(content);
|
||||||
|
const slug = path.split('/').pop()?.replace('.md', '') || '';
|
||||||
|
|
||||||
|
posts.push({
|
||||||
|
slug,
|
||||||
|
title: data.title,
|
||||||
|
date: data.date,
|
||||||
|
description: data.description,
|
||||||
|
image: data.image,
|
||||||
|
content: markdownContent,
|
||||||
|
keywords: data.keywords,
|
||||||
|
author: data.author,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPost = async (slug: string): Promise<BlogPost | undefined> => {
|
||||||
|
const posts = await getPosts();
|
||||||
|
return posts.find(post => post.slug === slug);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
getPosts,
|
||||||
|
getPost,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { ref, computed, type Ref, type ComputedRef } from 'vue';
|
import { ref, computed, type Ref, type ComputedRef } from 'vue';
|
||||||
import type { Sprite } from '@/types/sprites';
|
import type { Sprite, Layer } from '@/types/sprites';
|
||||||
import { getMaxDimensions } from './useSprites';
|
import { useGridMetrics, type GridMetrics } from './useGridMetrics';
|
||||||
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
|
||||||
|
|
||||||
export interface CellPosition {
|
export interface CellPosition {
|
||||||
col: number;
|
col: number;
|
||||||
@@ -28,10 +27,14 @@ export interface SpritePosition {
|
|||||||
|
|
||||||
export interface DragSpriteOptions {
|
export interface DragSpriteOptions {
|
||||||
sprites: Ref<Sprite[]> | ComputedRef<Sprite[]> | Sprite[];
|
sprites: Ref<Sprite[]> | ComputedRef<Sprite[]> | Sprite[];
|
||||||
|
layers?: Ref<Layer[]> | ComputedRef<Layer[]> | Layer[];
|
||||||
columns: Ref<number> | number;
|
columns: Ref<number> | number;
|
||||||
zoom?: Ref<number>;
|
zoom?: Ref<number>;
|
||||||
allowCellSwap?: Ref<boolean>;
|
allowCellSwap?: Ref<boolean>;
|
||||||
negativeSpacingEnabled?: Ref<boolean>;
|
negativeSpacingEnabled?: Ref<boolean>;
|
||||||
|
manualCellSizeEnabled?: Ref<boolean>;
|
||||||
|
manualCellWidth?: Ref<number>;
|
||||||
|
manualCellHeight?: Ref<number>;
|
||||||
getMousePosition: (event: MouseEvent, zoom?: number) => { x: number; y: number } | null;
|
getMousePosition: (event: MouseEvent, zoom?: number) => { x: number; y: number } | null;
|
||||||
onUpdateSprite: (id: string, x: number, y: number) => void;
|
onUpdateSprite: (id: string, x: number, y: number) => void;
|
||||||
onUpdateSpriteCell?: (id: string, newIndex: number) => void;
|
onUpdateSpriteCell?: (id: string, newIndex: number) => void;
|
||||||
@@ -43,10 +46,14 @@ export function useDragSprite(options: DragSpriteOptions) {
|
|||||||
|
|
||||||
// Helper to get reactive values
|
// Helper to get reactive values
|
||||||
const getSprites = () => (Array.isArray(options.sprites) ? options.sprites : options.sprites.value);
|
const getSprites = () => (Array.isArray(options.sprites) ? options.sprites : options.sprites.value);
|
||||||
|
const getLayers = () => (options.layers ? (Array.isArray(options.layers) ? options.layers : options.layers.value) : null);
|
||||||
const getColumns = () => (typeof options.columns === 'number' ? options.columns : options.columns.value);
|
const getColumns = () => (typeof options.columns === 'number' ? options.columns : options.columns.value);
|
||||||
const getZoom = () => options.zoom?.value ?? 1;
|
const getZoom = () => options.zoom?.value ?? 1;
|
||||||
const getAllowCellSwap = () => options.allowCellSwap?.value ?? false;
|
const getAllowCellSwap = () => options.allowCellSwap?.value ?? false;
|
||||||
const getNegativeSpacingEnabled = () => options.negativeSpacingEnabled?.value ?? false;
|
const getNegativeSpacingEnabled = () => options.negativeSpacingEnabled?.value ?? false;
|
||||||
|
const getManualCellSizeEnabled = () => options.manualCellSizeEnabled?.value ?? false;
|
||||||
|
const getManualCellWidth = () => options.manualCellWidth?.value ?? 64;
|
||||||
|
const getManualCellHeight = () => options.manualCellHeight?.value ?? 64;
|
||||||
|
|
||||||
// Drag state
|
// Drag state
|
||||||
const isDragging = ref(false);
|
const isDragging = ref(false);
|
||||||
@@ -62,52 +69,42 @@ export function useDragSprite(options: DragSpriteOptions) {
|
|||||||
const ghostSprite = ref<{ id: string; x: number; y: number } | null>(null);
|
const ghostSprite = ref<{ id: string; x: number; y: number } | null>(null);
|
||||||
const highlightCell = ref<CellPosition | null>(null);
|
const highlightCell = ref<CellPosition | null>(null);
|
||||||
|
|
||||||
// Cache for max dimensions
|
// Use the new useGridMetrics composable for consistent calculations
|
||||||
const lastMaxWidth = ref(1);
|
const gridMetricsComposable = useGridMetrics({
|
||||||
const lastMaxHeight = ref(1);
|
layers: options.layers,
|
||||||
|
sprites: options.sprites,
|
||||||
|
negativeSpacingEnabled: options.negativeSpacingEnabled,
|
||||||
|
manualCellSizeEnabled: options.manualCellSizeEnabled,
|
||||||
|
manualCellWidth: options.manualCellWidth,
|
||||||
|
manualCellHeight: options.manualCellHeight,
|
||||||
|
});
|
||||||
|
|
||||||
const calculateMaxDimensions = () => {
|
const calculateMaxDimensions = (): GridMetrics => {
|
||||||
const sprites = getSprites();
|
return gridMetricsComposable.calculateCellDimensions();
|
||||||
const negativeSpacingEnabled = getNegativeSpacingEnabled();
|
|
||||||
const base = getMaxDimensions(sprites);
|
|
||||||
const baseMaxWidth = Math.max(1, base.maxWidth, lastMaxWidth.value);
|
|
||||||
const baseMaxHeight = Math.max(1, base.maxHeight, lastMaxHeight.value);
|
|
||||||
lastMaxWidth.value = baseMaxWidth;
|
|
||||||
lastMaxHeight.value = baseMaxHeight;
|
|
||||||
|
|
||||||
// Calculate negative spacing using shared composable
|
|
||||||
const negativeSpacing = calculateNegativeSpacing(sprites, negativeSpacingEnabled);
|
|
||||||
|
|
||||||
// Add negative spacing to expand each cell
|
|
||||||
const maxWidth = baseMaxWidth + negativeSpacing;
|
|
||||||
const maxHeight = baseMaxHeight + negativeSpacing;
|
|
||||||
return { maxWidth, maxHeight, negativeSpacing };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Computed sprite positions
|
// Computed sprite positions
|
||||||
const spritePositions = computed<SpritePosition[]>(() => {
|
const spritePositions = computed<SpritePosition[]>(() => {
|
||||||
const sprites = getSprites();
|
const sprites = getSprites();
|
||||||
const columns = getColumns();
|
const columns = getColumns();
|
||||||
const { maxWidth, maxHeight, negativeSpacing } = calculateMaxDimensions();
|
const metrics = calculateMaxDimensions();
|
||||||
|
|
||||||
return sprites.map((sprite, index) => {
|
return sprites.map((sprite, index) => {
|
||||||
const col = index % columns;
|
const cellPos = gridMetricsComposable.getCellPosition(index, columns, metrics);
|
||||||
const row = Math.floor(index / columns);
|
const canvasPos = gridMetricsComposable.getSpriteCanvasPosition(sprite, index, columns, metrics);
|
||||||
|
|
||||||
// With negative spacing, sprites are positioned at bottom-right of cell
|
|
||||||
// (spacing added to top and left)
|
|
||||||
return {
|
return {
|
||||||
id: sprite.id,
|
id: sprite.id,
|
||||||
canvasX: col * maxWidth + negativeSpacing + sprite.x,
|
canvasX: canvasPos.canvasX,
|
||||||
canvasY: row * maxHeight + negativeSpacing + sprite.y,
|
canvasY: canvasPos.canvasY,
|
||||||
cellX: col * maxWidth,
|
cellX: canvasPos.cellX,
|
||||||
cellY: row * maxHeight,
|
cellY: canvasPos.cellY,
|
||||||
width: sprite.width,
|
width: Math.round(sprite.width),
|
||||||
height: sprite.height,
|
height: Math.round(sprite.height),
|
||||||
maxWidth,
|
maxWidth: metrics.maxWidth,
|
||||||
maxHeight,
|
maxHeight: metrics.maxHeight,
|
||||||
col,
|
col: cellPos.col,
|
||||||
row,
|
row: cellPos.row,
|
||||||
index,
|
index,
|
||||||
x: sprite.x,
|
x: sprite.x,
|
||||||
y: sprite.y,
|
y: sprite.y,
|
||||||
@@ -116,19 +113,16 @@ export function useDragSprite(options: DragSpriteOptions) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const findCellAtPosition = (x: number, y: number): CellPosition | null => {
|
const findCellAtPosition = (x: number, y: number): CellPosition | null => {
|
||||||
const sprites = getSprites();
|
|
||||||
const columns = getColumns();
|
const columns = getColumns();
|
||||||
const { maxWidth, maxHeight } = calculateMaxDimensions();
|
const { maxWidth, maxHeight } = calculateMaxDimensions();
|
||||||
const col = Math.floor(x / maxWidth);
|
const col = Math.floor(x / maxWidth);
|
||||||
const row = Math.floor(y / maxHeight);
|
const row = Math.floor(y / maxHeight);
|
||||||
|
|
||||||
const totalRows = Math.ceil(sprites.length / columns);
|
// Allow dropping anywhere in the columns, assuming infinite rows effectively
|
||||||
if (col >= 0 && col < columns && row >= 0 && row < totalRows) {
|
if (col >= 0 && col < columns && row >= 0) {
|
||||||
const index = row * columns + col;
|
const index = row * columns + col;
|
||||||
if (index < sprites.length) {
|
|
||||||
return { col, row, index };
|
return { col, row, index };
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -180,8 +174,8 @@ export function useDragSprite(options: DragSpriteOptions) {
|
|||||||
// Use the sprite's current index in the array to calculate cell position
|
// Use the sprite's current index in the array to calculate cell position
|
||||||
const cellCol = spriteIndex % columns;
|
const cellCol = spriteIndex % columns;
|
||||||
const cellRow = Math.floor(spriteIndex / columns);
|
const cellRow = Math.floor(spriteIndex / columns);
|
||||||
const cellX = cellCol * maxWidth;
|
const cellX = Math.round(cellCol * maxWidth);
|
||||||
const cellY = cellRow * maxHeight;
|
const cellY = Math.round(cellRow * maxHeight);
|
||||||
|
|
||||||
// Calculate new position relative to cell origin (without the negative spacing offset)
|
// Calculate new position relative to cell origin (without the negative spacing offset)
|
||||||
// The sprite's x,y is stored relative to where it would be drawn after the negativeSpacing offset
|
// The sprite's x,y is stored relative to where it would be drawn after the negativeSpacing offset
|
||||||
@@ -215,8 +209,8 @@ export function useDragSprite(options: DragSpriteOptions) {
|
|||||||
highlightCell.value = hoverCell;
|
highlightCell.value = hoverCell;
|
||||||
ghostSprite.value = {
|
ghostSprite.value = {
|
||||||
id: activeSpriteId.value,
|
id: activeSpriteId.value,
|
||||||
x: pos.x - dragOffsetX.value,
|
x: Math.round(pos.x - dragOffsetX.value),
|
||||||
y: pos.y - dragOffsetY.value,
|
y: Math.round(pos.y - dragOffsetY.value),
|
||||||
};
|
};
|
||||||
onDraw();
|
onDraw();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,21 +2,44 @@ import type { Ref } from 'vue';
|
|||||||
import GIF from 'gif.js';
|
import GIF from 'gif.js';
|
||||||
import gifWorkerUrl from 'gif.js/dist/gif.worker.js?url';
|
import gifWorkerUrl from 'gif.js/dist/gif.worker.js?url';
|
||||||
import JSZip from 'jszip';
|
import JSZip from 'jszip';
|
||||||
import type { Sprite } from '../types/sprites';
|
import type { Layer, Sprite } from '../types/sprites';
|
||||||
import { getMaxDimensions } from './useSprites';
|
import { getMaxDimensions } from './useSprites';
|
||||||
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
||||||
|
import { getMaxDimensionsAcrossLayers } from './useLayers';
|
||||||
|
|
||||||
|
export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>, backgroundColor?: Ref<string>, manualCellSizeEnabled?: Ref<boolean>, manualCellWidth?: Ref<number>, manualCellHeight?: Ref<number>, layers?: Ref<Layer[]>) => {
|
||||||
|
const getCellDimensions = () => {
|
||||||
|
// If manual cell size is enabled, use manual values
|
||||||
|
if (manualCellSizeEnabled?.value) {
|
||||||
|
return {
|
||||||
|
cellWidth: manualCellWidth?.value ?? 64,
|
||||||
|
cellHeight: manualCellHeight?.value ?? 64,
|
||||||
|
negativeSpacing: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use dimensions from ALL layers to keep canvas size stable when hiding layers
|
||||||
|
// Fall back to current sprites if layers ref is not provided
|
||||||
|
const { maxWidth, maxHeight } = layers?.value ? getMaxDimensionsAcrossLayers(layers.value, false) : getMaxDimensions(sprites.value);
|
||||||
|
|
||||||
|
// Calculate negative spacing from all layers' sprites for consistency
|
||||||
|
const allSprites = layers?.value ? layers.value.flatMap(l => l.sprites) : sprites.value;
|
||||||
|
const negativeSpacing = calculateNegativeSpacing(allSprites, negativeSpacingEnabled.value);
|
||||||
|
|
||||||
|
return {
|
||||||
|
cellWidth: maxWidth + negativeSpacing,
|
||||||
|
cellHeight: maxHeight + negativeSpacing,
|
||||||
|
negativeSpacing,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>) => {
|
|
||||||
const downloadSpritesheet = () => {
|
const downloadSpritesheet = () => {
|
||||||
if (!sprites.value.length) {
|
if (!sprites.value.length) {
|
||||||
alert('Please upload or import sprites before downloading the spritesheet.');
|
alert('Please upload or import sprites before downloading the spritesheet.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { maxWidth, maxHeight } = getMaxDimensions(sprites.value);
|
const { cellWidth, cellHeight, negativeSpacing } = getCellDimensions();
|
||||||
const negativeSpacing = calculateNegativeSpacing(sprites.value, negativeSpacingEnabled.value);
|
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
|
||||||
const rows = Math.ceil(sprites.value.length / columns.value);
|
const rows = Math.ceil(sprites.value.length / columns.value);
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
@@ -27,12 +50,29 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
canvas.height = cellHeight * rows;
|
canvas.height = cellHeight * rows;
|
||||||
ctx.imageSmoothingEnabled = false;
|
ctx.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
|
// Apply background color if not transparent
|
||||||
|
if (backgroundColor?.value && backgroundColor.value !== 'transparent') {
|
||||||
|
ctx.fillStyle = backgroundColor.value;
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
|
||||||
sprites.value.forEach((sprite, index) => {
|
sprites.value.forEach((sprite, index) => {
|
||||||
const col = index % columns.value;
|
const col = index % columns.value;
|
||||||
const row = Math.floor(index / columns.value);
|
const row = Math.floor(index / columns.value);
|
||||||
const cellX = Math.floor(col * cellWidth);
|
const cellX = Math.floor(col * cellWidth);
|
||||||
const cellY = Math.floor(row * cellHeight);
|
const cellY = Math.floor(row * cellHeight);
|
||||||
|
if (sprite.rotation || sprite.flipX || sprite.flipY) {
|
||||||
|
ctx.save();
|
||||||
|
const centerX = Math.floor(cellX + negativeSpacing + sprite.x + sprite.width / 2);
|
||||||
|
const centerY = Math.floor(cellY + negativeSpacing + sprite.y + sprite.height / 2);
|
||||||
|
ctx.translate(centerX, centerY);
|
||||||
|
ctx.rotate((sprite.rotation * Math.PI) / 180);
|
||||||
|
ctx.scale(sprite.flipX ? -1 : 1, sprite.flipY ? -1 : 1);
|
||||||
|
ctx.drawImage(sprite.img, -sprite.width / 2, -sprite.height / 2);
|
||||||
|
ctx.restore();
|
||||||
|
} else {
|
||||||
ctx.drawImage(sprite.img, Math.floor(cellX + negativeSpacing + sprite.x), Math.floor(cellY + negativeSpacing + sprite.y));
|
ctx.drawImage(sprite.img, Math.floor(cellX + negativeSpacing + sprite.x), Math.floor(cellY + negativeSpacing + sprite.y));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
@@ -54,7 +94,15 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
if (!ctx) return null;
|
if (!ctx) return null;
|
||||||
canvas.width = sprite.width;
|
canvas.width = sprite.width;
|
||||||
canvas.height = sprite.height;
|
canvas.height = sprite.height;
|
||||||
|
if (sprite.rotation) {
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(sprite.width / 2, sprite.height / 2);
|
||||||
|
ctx.rotate((sprite.rotation * Math.PI) / 180);
|
||||||
|
ctx.drawImage(sprite.img, -sprite.width / 2, -sprite.height / 2);
|
||||||
|
ctx.restore();
|
||||||
|
} else {
|
||||||
ctx.drawImage(sprite.img, 0, 0);
|
ctx.drawImage(sprite.img, 0, 0);
|
||||||
|
}
|
||||||
const base64Data = canvas.toDataURL('image/png');
|
const base64Data = canvas.toDataURL('image/png');
|
||||||
return {
|
return {
|
||||||
id: sprite.id,
|
id: sprite.id,
|
||||||
@@ -62,6 +110,9 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
height: sprite.height,
|
height: sprite.height,
|
||||||
x: sprite.x,
|
x: sprite.x,
|
||||||
y: sprite.y,
|
y: sprite.y,
|
||||||
|
rotation: sprite.rotation || 0,
|
||||||
|
flipX: sprite.flipX || false,
|
||||||
|
flipY: sprite.flipY || false,
|
||||||
base64: base64Data,
|
base64: base64Data,
|
||||||
name: sprite.file.name,
|
name: sprite.file.name,
|
||||||
};
|
};
|
||||||
@@ -71,6 +122,10 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
const jsonData = {
|
const jsonData = {
|
||||||
columns: columns.value,
|
columns: columns.value,
|
||||||
negativeSpacingEnabled: negativeSpacingEnabled.value,
|
negativeSpacingEnabled: negativeSpacingEnabled.value,
|
||||||
|
backgroundColor: backgroundColor?.value || 'transparent',
|
||||||
|
manualCellSizeEnabled: manualCellSizeEnabled?.value || false,
|
||||||
|
manualCellWidth: manualCellWidth?.value || 64,
|
||||||
|
manualCellHeight: manualCellHeight?.value || 64,
|
||||||
sprites: spritesData.filter(Boolean),
|
sprites: spritesData.filter(Boolean),
|
||||||
};
|
};
|
||||||
const jsonString = JSON.stringify(jsonData, null, 2);
|
const jsonString = JSON.stringify(jsonData, null, 2);
|
||||||
@@ -91,6 +146,10 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
|
|
||||||
if (jsonData.columns && typeof jsonData.columns === 'number') columns.value = jsonData.columns;
|
if (jsonData.columns && typeof jsonData.columns === 'number') columns.value = jsonData.columns;
|
||||||
if (typeof jsonData.negativeSpacingEnabled === 'boolean') negativeSpacingEnabled.value = jsonData.negativeSpacingEnabled;
|
if (typeof jsonData.negativeSpacingEnabled === 'boolean') negativeSpacingEnabled.value = jsonData.negativeSpacingEnabled;
|
||||||
|
if (typeof jsonData.backgroundColor === 'string' && backgroundColor) backgroundColor.value = jsonData.backgroundColor;
|
||||||
|
if (typeof jsonData.manualCellSizeEnabled === 'boolean' && manualCellSizeEnabled) manualCellSizeEnabled.value = jsonData.manualCellSizeEnabled;
|
||||||
|
if (typeof jsonData.manualCellWidth === 'number' && manualCellWidth) manualCellWidth.value = jsonData.manualCellWidth;
|
||||||
|
if (typeof jsonData.manualCellHeight === 'number' && manualCellHeight) manualCellHeight.value = jsonData.manualCellHeight;
|
||||||
|
|
||||||
// revoke existing blob urls
|
// revoke existing blob urls
|
||||||
if (sprites.value.length) {
|
if (sprites.value.length) {
|
||||||
@@ -125,6 +184,9 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
height: spriteData.height,
|
height: spriteData.height,
|
||||||
x: spriteData.x || 0,
|
x: spriteData.x || 0,
|
||||||
y: spriteData.y || 0,
|
y: spriteData.y || 0,
|
||||||
|
rotation: spriteData.rotation || 0,
|
||||||
|
flipX: spriteData.flipX || false,
|
||||||
|
flipY: spriteData.flipY || false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
img.src = spriteData.base64;
|
img.src = spriteData.base64;
|
||||||
@@ -141,10 +203,7 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { maxWidth, maxHeight } = getMaxDimensions(sprites.value);
|
const { cellWidth, cellHeight, negativeSpacing } = getCellDimensions();
|
||||||
const negativeSpacing = calculateNegativeSpacing(sprites.value, negativeSpacingEnabled.value);
|
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
if (!ctx) return;
|
if (!ctx) return;
|
||||||
@@ -156,7 +215,22 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
|
|
||||||
sprites.value.forEach(sprite => {
|
sprites.value.forEach(sprite => {
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
// Apply background color if not transparent
|
||||||
|
if (backgroundColor?.value && backgroundColor.value !== 'transparent') {
|
||||||
|
ctx.fillStyle = backgroundColor.value;
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
if (sprite.rotation) {
|
||||||
|
ctx.save();
|
||||||
|
const centerX = Math.floor(negativeSpacing + sprite.x + sprite.width / 2);
|
||||||
|
const centerY = Math.floor(negativeSpacing + sprite.y + sprite.height / 2);
|
||||||
|
ctx.translate(centerX, centerY);
|
||||||
|
ctx.rotate((sprite.rotation * Math.PI) / 180);
|
||||||
|
ctx.drawImage(sprite.img, -sprite.width / 2, -sprite.height / 2);
|
||||||
|
ctx.restore();
|
||||||
|
} else {
|
||||||
ctx.drawImage(sprite.img, Math.floor(negativeSpacing + sprite.x), Math.floor(negativeSpacing + sprite.y));
|
ctx.drawImage(sprite.img, Math.floor(negativeSpacing + sprite.x), Math.floor(negativeSpacing + sprite.y));
|
||||||
|
}
|
||||||
gif.addFrame(ctx, { copy: true, delay: 1000 / fps });
|
gif.addFrame(ctx, { copy: true, delay: 1000 / fps });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -179,10 +253,7 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
}
|
}
|
||||||
|
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
const { maxWidth, maxHeight } = getMaxDimensions(sprites.value);
|
const { cellWidth, cellHeight, negativeSpacing } = getCellDimensions();
|
||||||
const negativeSpacing = calculateNegativeSpacing(sprites.value, negativeSpacingEnabled.value);
|
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
if (!ctx) return;
|
if (!ctx) return;
|
||||||
@@ -192,7 +263,22 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
|
|
||||||
sprites.value.forEach((sprite, index) => {
|
sprites.value.forEach((sprite, index) => {
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
// Apply background color if not transparent
|
||||||
|
if (backgroundColor?.value && backgroundColor.value !== 'transparent') {
|
||||||
|
ctx.fillStyle = backgroundColor.value;
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
if (sprite.rotation) {
|
||||||
|
ctx.save();
|
||||||
|
const centerX = Math.floor(negativeSpacing + sprite.x + sprite.width / 2);
|
||||||
|
const centerY = Math.floor(negativeSpacing + sprite.y + sprite.height / 2);
|
||||||
|
ctx.translate(centerX, centerY);
|
||||||
|
ctx.rotate((sprite.rotation * Math.PI) / 180);
|
||||||
|
ctx.drawImage(sprite.img, -sprite.width / 2, -sprite.height / 2);
|
||||||
|
ctx.restore();
|
||||||
|
} else {
|
||||||
ctx.drawImage(sprite.img, Math.floor(negativeSpacing + sprite.x), Math.floor(negativeSpacing + sprite.y));
|
ctx.drawImage(sprite.img, Math.floor(negativeSpacing + sprite.x), Math.floor(negativeSpacing + sprite.y));
|
||||||
|
}
|
||||||
const dataURL = canvas.toDataURL('image/png');
|
const dataURL = canvas.toDataURL('image/png');
|
||||||
const binary = atob(dataURL.split(',')[1]);
|
const binary = atob(dataURL.split(',')[1]);
|
||||||
const buf = new ArrayBuffer(binary.length);
|
const buf = new ArrayBuffer(binary.length);
|
||||||
|
|||||||
@@ -6,10 +6,33 @@ import type { Layer, Sprite } from '@/types/sprites';
|
|||||||
import { getMaxDimensionsAcrossLayers } from './useLayers';
|
import { getMaxDimensionsAcrossLayers } from './useLayers';
|
||||||
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
||||||
|
|
||||||
export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>, activeLayerId?: Ref<string>, backgroundColor?: Ref<string>) => {
|
export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>, activeLayerId?: Ref<string>, backgroundColor?: Ref<string>, manualCellSizeEnabled?: Ref<boolean>, manualCellWidth?: Ref<number>, manualCellHeight?: Ref<number>) => {
|
||||||
const getVisibleLayers = () => layersRef.value.filter(l => l.visible);
|
const getVisibleLayers = () => layersRef.value.filter(l => l.visible);
|
||||||
const getAllVisibleSprites = () => getVisibleLayers().flatMap(l => l.sprites);
|
const getAllVisibleSprites = () => getVisibleLayers().flatMap(l => l.sprites);
|
||||||
|
|
||||||
|
const getCellDimensions = () => {
|
||||||
|
// If manual cell size is enabled, use manual values
|
||||||
|
if (manualCellSizeEnabled?.value) {
|
||||||
|
return {
|
||||||
|
cellWidth: manualCellWidth?.value ?? 64,
|
||||||
|
cellHeight: manualCellHeight?.value ?? 64,
|
||||||
|
negativeSpacing: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, calculate from sprite dimensions across ALL layers (same as canvas)
|
||||||
|
// This ensures export dimensions match what's shown in the canvas
|
||||||
|
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(layersRef.value);
|
||||||
|
// Calculate negative spacing from ALL layers (not just visible) to keep canvas size stable
|
||||||
|
const allSprites = layersRef.value.flatMap(l => l.sprites);
|
||||||
|
const negativeSpacing = calculateNegativeSpacing(allSprites, negativeSpacingEnabled.value);
|
||||||
|
return {
|
||||||
|
cellWidth: maxWidth + negativeSpacing,
|
||||||
|
cellHeight: maxHeight + negativeSpacing,
|
||||||
|
negativeSpacing,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const drawCompositeCell = (ctx: CanvasRenderingContext2D, cellIndex: number, cellWidth: number, cellHeight: number, negativeSpacing: number) => {
|
const drawCompositeCell = (ctx: CanvasRenderingContext2D, cellIndex: number, cellWidth: number, cellHeight: number, negativeSpacing: number) => {
|
||||||
ctx.clearRect(0, 0, cellWidth, cellHeight);
|
ctx.clearRect(0, 0, cellWidth, cellHeight);
|
||||||
// Apply background color if not transparent
|
// Apply background color if not transparent
|
||||||
@@ -21,7 +44,19 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
vLayers.forEach(layer => {
|
vLayers.forEach(layer => {
|
||||||
const sprite = layer.sprites[cellIndex];
|
const sprite = layer.sprites[cellIndex];
|
||||||
if (!sprite) return;
|
if (!sprite) return;
|
||||||
|
|
||||||
|
if (sprite.rotation || sprite.flipX || sprite.flipY) {
|
||||||
|
ctx.save();
|
||||||
|
const centerX = Math.floor(negativeSpacing + sprite.x + sprite.width / 2);
|
||||||
|
const centerY = Math.floor(negativeSpacing + sprite.y + sprite.height / 2);
|
||||||
|
ctx.translate(centerX, centerY);
|
||||||
|
ctx.rotate((sprite.rotation * Math.PI) / 180);
|
||||||
|
ctx.scale(sprite.flipX ? -1 : 1, sprite.flipY ? -1 : 1);
|
||||||
|
ctx.drawImage(sprite.img, -sprite.width / 2, -sprite.height / 2);
|
||||||
|
ctx.restore();
|
||||||
|
} else {
|
||||||
ctx.drawImage(sprite.img, Math.floor(negativeSpacing + sprite.x), Math.floor(negativeSpacing + sprite.y));
|
ctx.drawImage(sprite.img, Math.floor(negativeSpacing + sprite.x), Math.floor(negativeSpacing + sprite.y));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,10 +67,7 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers);
|
const { cellWidth, cellHeight, negativeSpacing } = getCellDimensions();
|
||||||
const negativeSpacing = calculateNegativeSpacing(getAllVisibleSprites(), negativeSpacingEnabled.value);
|
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
|
||||||
const maxLen = Math.max(...visibleLayers.map(l => l.sprites.length));
|
const maxLen = Math.max(...visibleLayers.map(l => l.sprites.length));
|
||||||
const rows = Math.ceil(maxLen / columns.value);
|
const rows = Math.ceil(maxLen / columns.value);
|
||||||
|
|
||||||
@@ -46,6 +78,12 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
canvas.height = cellHeight * rows;
|
canvas.height = cellHeight * rows;
|
||||||
ctx.imageSmoothingEnabled = false;
|
ctx.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
|
// Apply background color to entire canvas if not transparent
|
||||||
|
if (backgroundColor?.value && backgroundColor.value !== 'transparent') {
|
||||||
|
ctx.fillStyle = backgroundColor.value;
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
|
||||||
for (let index = 0; index < maxLen; index++) {
|
for (let index = 0; index < maxLen; index++) {
|
||||||
const col = index % columns.value;
|
const col = index % columns.value;
|
||||||
const row = Math.floor(index / columns.value);
|
const row = Math.floor(index / columns.value);
|
||||||
@@ -57,6 +95,7 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
if (!cellCtx) return;
|
if (!cellCtx) return;
|
||||||
cellCanvas.width = cellWidth;
|
cellCanvas.width = cellWidth;
|
||||||
cellCanvas.height = cellHeight;
|
cellCanvas.height = cellHeight;
|
||||||
|
cellCtx.imageSmoothingEnabled = false;
|
||||||
drawCompositeCell(cellCtx, index, cellWidth, cellHeight, negativeSpacing);
|
drawCompositeCell(cellCtx, index, cellWidth, cellHeight, negativeSpacing);
|
||||||
ctx.drawImage(cellCanvas, cellX, cellY);
|
ctx.drawImage(cellCanvas, cellX, cellY);
|
||||||
}
|
}
|
||||||
@@ -67,13 +106,7 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
link.click();
|
link.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
const exportSpritesheetJSON = async () => {
|
const generateProjectJSON = async () => {
|
||||||
const visibleLayers = getVisibleLayers();
|
|
||||||
if (!visibleLayers.length || !visibleLayers.some(l => l.sprites.length)) {
|
|
||||||
alert('Nothing to export. Please add sprites first.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const layersData = await Promise.all(
|
const layersData = await Promise.all(
|
||||||
layersRef.value.map(async layer => {
|
layersRef.value.map(async layer => {
|
||||||
const sprites = await Promise.all(
|
const sprites = await Promise.all(
|
||||||
@@ -85,14 +118,33 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
canvas.height = sprite.height;
|
canvas.height = sprite.height;
|
||||||
ctx.drawImage(sprite.img, 0, 0);
|
ctx.drawImage(sprite.img, 0, 0);
|
||||||
const base64 = canvas.toDataURL('image/png');
|
const base64 = canvas.toDataURL('image/png');
|
||||||
return { id: sprite.id, width: sprite.width, height: sprite.height, x: sprite.x, y: sprite.y, base64, name: sprite.file.name };
|
return { id: sprite.id, width: sprite.width, height: sprite.height, x: sprite.x, y: sprite.y, rotation: sprite.rotation, flipX: sprite.flipX, flipY: sprite.flipY, base64, name: sprite.file.name };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return { id: layer.id, name: layer.name, visible: layer.visible, locked: layer.locked, sprites: sprites.filter(Boolean) };
|
return { id: layer.id, name: layer.name, visible: layer.visible, locked: layer.locked, sprites: sprites.filter(Boolean) };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const json = { version: 2, columns: columns.value, negativeSpacingEnabled: negativeSpacingEnabled.value, layers: layersData };
|
return {
|
||||||
|
version: 2,
|
||||||
|
columns: columns.value,
|
||||||
|
negativeSpacingEnabled: negativeSpacingEnabled.value,
|
||||||
|
backgroundColor: backgroundColor?.value || 'transparent',
|
||||||
|
manualCellSizeEnabled: manualCellSizeEnabled?.value || false,
|
||||||
|
manualCellWidth: manualCellWidth?.value || 64,
|
||||||
|
manualCellHeight: manualCellHeight?.value || 64,
|
||||||
|
layers: layersData,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const exportSpritesheetJSON = async () => {
|
||||||
|
const visibleLayers = getVisibleLayers();
|
||||||
|
if (!visibleLayers.length || !visibleLayers.some(l => l.sprites.length)) {
|
||||||
|
alert('Nothing to export. Please add sprites first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await generateProjectJSON();
|
||||||
const jsonString = JSON.stringify(json, null, 2);
|
const jsonString = JSON.stringify(json, null, 2);
|
||||||
const blob = new Blob([jsonString], { type: 'application/json' });
|
const blob = new Blob([jsonString], { type: 'application/json' });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
@@ -103,10 +155,7 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
const importSpritesheetJSON = async (jsonFile: File) => {
|
const loadProjectData = async (data: any) => {
|
||||||
const text = await jsonFile.text();
|
|
||||||
const data = JSON.parse(text);
|
|
||||||
|
|
||||||
const loadSprite = (spriteData: any) =>
|
const loadSprite = (spriteData: any) =>
|
||||||
new Promise<Sprite>(resolve => {
|
new Promise<Sprite>(resolve => {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
@@ -119,13 +168,17 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
const blob = new Blob([ab], { type: mimeType });
|
const blob = new Blob([ab], { type: mimeType });
|
||||||
const fileName = spriteData.name || `sprite-${spriteData.id}.png`;
|
const fileName = spriteData.name || `sprite-${spriteData.id}.png`;
|
||||||
const file = new File([blob], fileName, { type: mimeType });
|
const file = new File([blob], fileName, { type: mimeType });
|
||||||
resolve({ id: spriteData.id || crypto.randomUUID(), file, img, url: spriteData.base64, width: spriteData.width, height: spriteData.height, x: spriteData.x || 0, y: spriteData.y || 0 });
|
resolve({ id: spriteData.id || crypto.randomUUID(), file, img, url: spriteData.base64, width: spriteData.width, height: spriteData.height, x: spriteData.x || 0, y: spriteData.y || 0, rotation: spriteData.rotation || 0, flipX: spriteData.flipX || false, flipY: spriteData.flipY || false });
|
||||||
};
|
};
|
||||||
img.src = spriteData.base64;
|
img.src = spriteData.base64;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof data.columns === 'number') columns.value = data.columns;
|
if (typeof data.columns === 'number') columns.value = data.columns;
|
||||||
if (typeof data.negativeSpacingEnabled === 'boolean') negativeSpacingEnabled.value = data.negativeSpacingEnabled;
|
if (typeof data.negativeSpacingEnabled === 'boolean') negativeSpacingEnabled.value = data.negativeSpacingEnabled;
|
||||||
|
if (typeof data.backgroundColor === 'string' && backgroundColor) backgroundColor.value = data.backgroundColor;
|
||||||
|
if (typeof data.manualCellSizeEnabled === 'boolean' && manualCellSizeEnabled) manualCellSizeEnabled.value = data.manualCellSizeEnabled;
|
||||||
|
if (typeof data.manualCellWidth === 'number' && manualCellWidth) manualCellWidth.value = data.manualCellWidth;
|
||||||
|
if (typeof data.manualCellHeight === 'number' && manualCellHeight) manualCellHeight.value = data.manualCellHeight;
|
||||||
|
|
||||||
if (Array.isArray(data.layers)) {
|
if (Array.isArray(data.layers)) {
|
||||||
const newLayers: Layer[] = [];
|
const newLayers: Layer[] = [];
|
||||||
@@ -165,6 +218,12 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
throw new Error('Invalid JSON format');
|
throw new Error('Invalid JSON format');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const importSpritesheetJSON = async (jsonFile: File) => {
|
||||||
|
const text = await jsonFile.text();
|
||||||
|
const data = JSON.parse(text);
|
||||||
|
await loadProjectData(data);
|
||||||
|
};
|
||||||
|
|
||||||
const downloadAsGif = (fps: number) => {
|
const downloadAsGif = (fps: number) => {
|
||||||
const visibleLayers = getVisibleLayers();
|
const visibleLayers = getVisibleLayers();
|
||||||
if (!visibleLayers.length || !visibleLayers.some(l => l.sprites.length)) {
|
if (!visibleLayers.length || !visibleLayers.some(l => l.sprites.length)) {
|
||||||
@@ -172,10 +231,7 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers);
|
const { cellWidth, cellHeight, negativeSpacing } = getCellDimensions();
|
||||||
const negativeSpacing = calculateNegativeSpacing(getAllVisibleSprites(), negativeSpacingEnabled.value);
|
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
@@ -210,10 +266,7 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
}
|
}
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
|
|
||||||
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers);
|
const { cellWidth, cellHeight, negativeSpacing } = getCellDimensions();
|
||||||
const negativeSpacing = calculateNegativeSpacing(getAllVisibleSprites(), negativeSpacingEnabled.value);
|
|
||||||
const cellWidth = maxWidth + negativeSpacing;
|
|
||||||
const cellHeight = maxHeight + negativeSpacing;
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
@@ -241,10 +294,19 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
name: layer.name,
|
name: layer.name,
|
||||||
visible: layer.visible,
|
visible: layer.visible,
|
||||||
locked: layer.locked,
|
locked: layer.locked,
|
||||||
sprites: await Promise.all(layer.sprites.map(async s => ({ id: s.id, width: s.width, height: s.height, x: s.x, y: s.y, name: s.file.name }))),
|
sprites: await Promise.all(layer.sprites.map(async s => ({ id: s.id, width: s.width, height: s.height, x: s.x, y: s.y, rotation: s.rotation, flipX: s.flipX, flipY: s.flipY, name: s.file.name }))),
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
const meta = { version: 2, columns: columns.value, negativeSpacingEnabled: negativeSpacingEnabled.value, layers: layersPayload };
|
const meta = {
|
||||||
|
version: 2,
|
||||||
|
columns: columns.value,
|
||||||
|
negativeSpacingEnabled: negativeSpacingEnabled.value,
|
||||||
|
backgroundColor: backgroundColor?.value || 'transparent',
|
||||||
|
manualCellSizeEnabled: manualCellSizeEnabled?.value || false,
|
||||||
|
manualCellWidth: manualCellWidth?.value || 64,
|
||||||
|
manualCellHeight: manualCellHeight?.value || 64,
|
||||||
|
layers: layersPayload,
|
||||||
|
};
|
||||||
const metaStr = JSON.stringify(meta, null, 2);
|
const metaStr = JSON.stringify(meta, null, 2);
|
||||||
jsonFolder.file('spritesheet.meta.json', metaStr);
|
jsonFolder.file('spritesheet.meta.json', metaStr);
|
||||||
})();
|
})();
|
||||||
@@ -259,5 +321,5 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
return { downloadSpritesheet, exportSpritesheetJSON, importSpritesheetJSON, downloadAsGif, downloadAsZip };
|
return { downloadSpritesheet, exportSpritesheetJSON, importSpritesheetJSON, downloadAsGif, downloadAsZip, generateProjectJSON, loadProjectData };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function useFileDrop(options: FileDropOptions) {
|
|||||||
isDragOver.value = true;
|
isDragOver.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDragLeave = (event: DragEvent, canvasRef?: HTMLCanvasElement | null) => {
|
const handleDragLeave = (event: DragEvent, canvasRef?: HTMLElement | null) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
|
|||||||
165
src/composables/useGridMetrics.ts
Normal file
165
src/composables/useGridMetrics.ts
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
import { computed, type Ref, type ComputedRef } from 'vue';
|
||||||
|
import type { Sprite, Layer } from '@/types/sprites';
|
||||||
|
import { getMaxDimensions } from './useSprites';
|
||||||
|
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
||||||
|
|
||||||
|
export interface GridMetrics {
|
||||||
|
maxWidth: number;
|
||||||
|
maxHeight: number;
|
||||||
|
negativeSpacing: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CellPosition {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
col: number;
|
||||||
|
row: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SpriteCanvasPosition {
|
||||||
|
canvasX: number;
|
||||||
|
canvasY: number;
|
||||||
|
cellX: number;
|
||||||
|
cellY: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GridMetricsOptions {
|
||||||
|
layers?: Ref<Layer[]> | ComputedRef<Layer[]> | Layer[];
|
||||||
|
sprites?: Ref<Sprite[]> | ComputedRef<Sprite[]> | Sprite[];
|
||||||
|
negativeSpacingEnabled?: Ref<boolean> | boolean;
|
||||||
|
manualCellSizeEnabled?: Ref<boolean> | boolean;
|
||||||
|
manualCellWidth?: Ref<number> | number;
|
||||||
|
manualCellHeight?: Ref<number> | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composable for calculating grid metrics and sprite positions.
|
||||||
|
* Provides a single source of truth for cell dimensions and positioning calculations.
|
||||||
|
*/
|
||||||
|
export function useGridMetrics(options: GridMetricsOptions = {}) {
|
||||||
|
// Helper to get reactive values
|
||||||
|
const getLayers = () => (options.layers ? (Array.isArray(options.layers) ? options.layers : options.layers.value) : null);
|
||||||
|
const getSprites = () => (options.sprites ? (Array.isArray(options.sprites) ? options.sprites : options.sprites.value) : []);
|
||||||
|
const getNegativeSpacingEnabled = () => (typeof options.negativeSpacingEnabled === 'boolean' ? options.negativeSpacingEnabled : (options.negativeSpacingEnabled?.value ?? false));
|
||||||
|
const getManualCellSizeEnabled = () => (typeof options.manualCellSizeEnabled === 'boolean' ? options.manualCellSizeEnabled : (options.manualCellSizeEnabled?.value ?? false));
|
||||||
|
const getManualCellWidth = () => (typeof options.manualCellWidth === 'number' ? options.manualCellWidth : (options.manualCellWidth?.value ?? 64));
|
||||||
|
const getManualCellHeight = () => (typeof options.manualCellHeight === 'number' ? options.manualCellHeight : (options.manualCellHeight?.value ?? 64));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate cell dimensions including negative spacing.
|
||||||
|
* This is the canonical calculation used across all components.
|
||||||
|
*/
|
||||||
|
const calculateCellDimensions = (): GridMetrics => {
|
||||||
|
const manualCellSizeEnabled = getManualCellSizeEnabled();
|
||||||
|
|
||||||
|
// If manual cell size is enabled, use manual dimensions
|
||||||
|
if (manualCellSizeEnabled) {
|
||||||
|
return {
|
||||||
|
maxWidth: Math.round(getManualCellWidth()),
|
||||||
|
maxHeight: Math.round(getManualCellHeight()),
|
||||||
|
negativeSpacing: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get sprites to measure from layers or direct sprites array
|
||||||
|
const layers = getLayers();
|
||||||
|
const spritesToMeasure = layers ? layers.flatMap(l => l.sprites) : getSprites();
|
||||||
|
|
||||||
|
// Calculate base dimensions from sprites
|
||||||
|
const base = getMaxDimensions(spritesToMeasure);
|
||||||
|
const baseMaxWidth = Math.max(1, base.maxWidth);
|
||||||
|
const baseMaxHeight = Math.max(1, base.maxHeight);
|
||||||
|
|
||||||
|
// Calculate negative spacing
|
||||||
|
const negativeSpacingEnabled = getNegativeSpacingEnabled();
|
||||||
|
const negativeSpacing = Math.round(calculateNegativeSpacing(spritesToMeasure, negativeSpacingEnabled));
|
||||||
|
|
||||||
|
// Add negative spacing to expand each cell
|
||||||
|
return {
|
||||||
|
maxWidth: Math.round(baseMaxWidth + negativeSpacing),
|
||||||
|
maxHeight: Math.round(baseMaxHeight + negativeSpacing),
|
||||||
|
negativeSpacing,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the position of a cell in the grid.
|
||||||
|
*/
|
||||||
|
const getCellPosition = (index: number, columns: number, metrics: GridMetrics): CellPosition => {
|
||||||
|
const col = index % columns;
|
||||||
|
const row = Math.floor(index / columns);
|
||||||
|
return {
|
||||||
|
x: Math.round(col * metrics.maxWidth),
|
||||||
|
y: Math.round(row * metrics.maxHeight),
|
||||||
|
col,
|
||||||
|
row,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the canvas position of a sprite within a cell.
|
||||||
|
* This is the final position where the sprite should be rendered.
|
||||||
|
*/
|
||||||
|
const getSpriteCanvasPosition = (sprite: Sprite, cellIndex: number, columns: number, metrics: GridMetrics): SpriteCanvasPosition => {
|
||||||
|
const cellPos = getCellPosition(cellIndex, columns, metrics);
|
||||||
|
return {
|
||||||
|
canvasX: Math.round(cellPos.x + metrics.negativeSpacing + sprite.x),
|
||||||
|
canvasY: Math.round(cellPos.y + metrics.negativeSpacing + sprite.y),
|
||||||
|
cellX: cellPos.x,
|
||||||
|
cellY: cellPos.y,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computed grid metrics that automatically updates when dependencies change.
|
||||||
|
*/
|
||||||
|
const gridMetrics = computed(() => calculateCellDimensions());
|
||||||
|
|
||||||
|
return {
|
||||||
|
// Computed values
|
||||||
|
gridMetrics,
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
calculateCellDimensions,
|
||||||
|
getCellPosition,
|
||||||
|
getSpriteCanvasPosition,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standalone helper to calculate cell dimensions.
|
||||||
|
* Useful when you don't need the full composable.
|
||||||
|
*/
|
||||||
|
export function getGridMetrics(
|
||||||
|
spritesOrLayers: Sprite[] | Layer[],
|
||||||
|
options: {
|
||||||
|
negativeSpacingEnabled?: boolean;
|
||||||
|
manualCellSizeEnabled?: boolean;
|
||||||
|
manualCellWidth?: number;
|
||||||
|
manualCellHeight?: number;
|
||||||
|
} = {}
|
||||||
|
): GridMetrics {
|
||||||
|
if (options.manualCellSizeEnabled) {
|
||||||
|
return {
|
||||||
|
maxWidth: Math.round(options.manualCellWidth ?? 64),
|
||||||
|
maxHeight: Math.round(options.manualCellHeight ?? 64),
|
||||||
|
negativeSpacing: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we have layers or sprites
|
||||||
|
const isLayers = spritesOrLayers.length > 0 && 'sprites' in spritesOrLayers[0];
|
||||||
|
const sprites = isLayers ? (spritesOrLayers as Layer[]).flatMap(l => l.sprites) : (spritesOrLayers as Sprite[]);
|
||||||
|
|
||||||
|
const base = getMaxDimensions(sprites);
|
||||||
|
const baseMaxWidth = Math.max(1, base.maxWidth);
|
||||||
|
const baseMaxHeight = Math.max(1, base.maxHeight);
|
||||||
|
|
||||||
|
const negativeSpacing = Math.round(calculateNegativeSpacing(sprites, options.negativeSpacingEnabled ?? false));
|
||||||
|
|
||||||
|
return {
|
||||||
|
maxWidth: Math.round(baseMaxWidth + negativeSpacing),
|
||||||
|
maxHeight: Math.round(baseMaxHeight + negativeSpacing),
|
||||||
|
negativeSpacing,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import type { Layer, Sprite } from '@/types/sprites';
|
import type { Layer, Sprite } from '@/types/sprites';
|
||||||
import { getMaxDimensions as getMaxDimensionsSingle, useSprites as useSpritesSingle } from './useSprites';
|
import { getMaxDimensions as getMaxDimensionsSingle, useSprites as useSpritesSingle } from './useSprites';
|
||||||
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
|
|
||||||
export const createEmptyLayer = (name: string): Layer => ({
|
export const createEmptyLayer = (name: string): Layer => ({
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
@@ -10,11 +11,27 @@ export const createEmptyLayer = (name: string): Layer => ({
|
|||||||
locked: false,
|
locked: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useLayers = () => {
|
|
||||||
const layers = ref<Layer[]>([createEmptyLayer('Base')]);
|
const layers = ref<Layer[]>([createEmptyLayer('Base')]);
|
||||||
const activeLayerId = ref<string>(layers.value[0].id);
|
const activeLayerId = ref<string>(layers.value[0].id);
|
||||||
const columns = ref(4);
|
const columns = ref(4);
|
||||||
|
|
||||||
|
const createEmptySprite = (): Sprite => ({
|
||||||
|
id: crypto.randomUUID(),
|
||||||
|
file: new File([], 'empty'),
|
||||||
|
img: new Image(),
|
||||||
|
url: '',
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useLayers = () => {
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
watch(columns, val => {
|
watch(columns, val => {
|
||||||
const num = typeof val === 'number' ? val : parseInt(String(val));
|
const num = typeof val === 'number' ? val : parseInt(String(val));
|
||||||
const safe = Number.isFinite(num) && num >= 1 ? Math.min(num, 10) : 1;
|
const safe = Number.isFinite(num) && num >= 1 ? Math.min(num, 10) : 1;
|
||||||
@@ -25,6 +42,10 @@ export const useLayers = () => {
|
|||||||
|
|
||||||
const getMaxDimensions = (sprites: Sprite[]) => getMaxDimensionsSingle(sprites);
|
const getMaxDimensions = (sprites: Sprite[]) => getMaxDimensionsSingle(sprites);
|
||||||
|
|
||||||
|
const visibleLayers = computed(() => layers.value.filter(l => l.visible));
|
||||||
|
|
||||||
|
const hasSprites = computed(() => layers.value.some(l => l.sprites.length > 0));
|
||||||
|
|
||||||
const updateSpritePosition = (id: string, x: number, y: number) => {
|
const updateSpritePosition = (id: string, x: number, y: number) => {
|
||||||
const l = activeLayer.value;
|
const l = activeLayer.value;
|
||||||
if (!l) return;
|
if (!l) return;
|
||||||
@@ -35,10 +56,35 @@ export const useLayers = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateSpriteInLayer = (layerId: string, spriteId: string, x: number, y: number) => {
|
||||||
|
const l = layers.value.find(layer => layer.id === layerId);
|
||||||
|
if (!l) return;
|
||||||
|
const i = l.sprites.findIndex(s => s.id === spriteId);
|
||||||
|
if (i !== -1) {
|
||||||
|
l.sprites[i].x = Math.floor(x);
|
||||||
|
l.sprites[i].y = Math.floor(y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const alignSprites = (position: 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom') => {
|
const alignSprites = (position: 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom') => {
|
||||||
const l = activeLayer.value;
|
const l = activeLayer.value;
|
||||||
if (!l || !l.sprites.length) return;
|
if (!l || !l.sprites.length) return;
|
||||||
const { maxWidth, maxHeight } = getMaxDimensions(l.sprites);
|
|
||||||
|
// Determine the cell dimensions to align within
|
||||||
|
let cellWidth: number;
|
||||||
|
let cellHeight: number;
|
||||||
|
|
||||||
|
if (settingsStore.manualCellSizeEnabled) {
|
||||||
|
// Use manual cell size (without negative spacing)
|
||||||
|
cellWidth = settingsStore.manualCellWidth;
|
||||||
|
cellHeight = settingsStore.manualCellHeight;
|
||||||
|
} else {
|
||||||
|
// Use auto-calculated dimensions based on ALL visible layers (not just active layer)
|
||||||
|
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers.value);
|
||||||
|
cellWidth = maxWidth;
|
||||||
|
cellHeight = maxHeight;
|
||||||
|
}
|
||||||
|
|
||||||
l.sprites = l.sprites.map(sprite => {
|
l.sprites = l.sprites.map(sprite => {
|
||||||
let x = sprite.x;
|
let x = sprite.x;
|
||||||
let y = sprite.y;
|
let y = sprite.y;
|
||||||
@@ -47,19 +93,19 @@ export const useLayers = () => {
|
|||||||
x = 0;
|
x = 0;
|
||||||
break;
|
break;
|
||||||
case 'center':
|
case 'center':
|
||||||
x = Math.floor((maxWidth - sprite.width) / 2);
|
x = Math.floor((cellWidth - sprite.width) / 2);
|
||||||
break;
|
break;
|
||||||
case 'right':
|
case 'right':
|
||||||
x = Math.floor(maxWidth - sprite.width);
|
x = Math.floor(cellWidth - sprite.width);
|
||||||
break;
|
break;
|
||||||
case 'top':
|
case 'top':
|
||||||
y = 0;
|
y = 0;
|
||||||
break;
|
break;
|
||||||
case 'middle':
|
case 'middle':
|
||||||
y = Math.floor((maxHeight - sprite.height) / 2);
|
y = Math.floor((cellHeight - sprite.height) / 2);
|
||||||
break;
|
break;
|
||||||
case 'bottom':
|
case 'bottom':
|
||||||
y = Math.floor(maxHeight - sprite.height);
|
y = Math.floor(cellHeight - sprite.height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return { ...sprite, x: Math.floor(x), y: Math.floor(y) };
|
return { ...sprite, x: Math.floor(x), y: Math.floor(y) };
|
||||||
@@ -71,17 +117,66 @@ export const useLayers = () => {
|
|||||||
if (!l) return;
|
if (!l) return;
|
||||||
const currentIndex = l.sprites.findIndex(s => s.id === id);
|
const currentIndex = l.sprites.findIndex(s => s.id === id);
|
||||||
if (currentIndex === -1 || currentIndex === newIndex) return;
|
if (currentIndex === -1 || currentIndex === newIndex) return;
|
||||||
|
|
||||||
const next = [...l.sprites];
|
const next = [...l.sprites];
|
||||||
if (newIndex < next.length) {
|
|
||||||
const moving = { ...next[currentIndex] };
|
// Remove the moving sprite first
|
||||||
const target = { ...next[newIndex] };
|
const [moving] = next.splice(currentIndex, 1);
|
||||||
next[currentIndex] = target;
|
|
||||||
next[newIndex] = moving;
|
// Determine the actual index to insert at, considering we removed one item
|
||||||
} else {
|
// If the target index was greater than current index, it shifts down by 1 in the original array perspective?
|
||||||
const [moved] = next.splice(currentIndex, 1);
|
// Actually simpler: we just want to put 'moving' at 'newIndex' in the final array.
|
||||||
next.splice(newIndex, 0, moved);
|
|
||||||
|
// If newIndex is beyond the current bounds (after removal), fill with placeholders
|
||||||
|
while (next.length < newIndex) {
|
||||||
|
next.push(createEmptySprite());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now insert
|
||||||
|
// If newIndex is within bounds, we might be swapping if there was something there
|
||||||
|
// But the DragSprite logic implies we are "moving to this cell".
|
||||||
|
// If there is existing content at newIndex, we should swap or splice?
|
||||||
|
// The previous implementation did a swap if newIndex < length (before removal).
|
||||||
|
|
||||||
|
// Let's stick to the "swap" logic if there's a sprite there, or "move" if we are reordering.
|
||||||
|
// Wait, Drag and Drop usually implies "insert here" or "swap with this".
|
||||||
|
// useDragSprite says: "if allowCellSwap... updateSpriteCell".
|
||||||
|
|
||||||
|
// The original logic:
|
||||||
|
// if (newIndex < next.length) -> swap
|
||||||
|
// else -> splice (move)
|
||||||
|
|
||||||
|
// Re-evaluating original logic:
|
||||||
|
// next has NOT had the item removed yet in the original logic 'if' block.
|
||||||
|
|
||||||
|
// Let's implement robust swap/move logic.
|
||||||
|
// 1. If target is empty placeholder -> just move there (replace placeholder).
|
||||||
|
// 2. If target has sprite -> swap.
|
||||||
|
// 3. If target is out of bounds -> pad and move.
|
||||||
|
|
||||||
|
if (newIndex < l.sprites.length) {
|
||||||
|
// Perform Swap
|
||||||
|
const target = l.sprites[newIndex];
|
||||||
|
const moving = l.sprites[currentIndex];
|
||||||
|
|
||||||
|
// Clone array
|
||||||
|
const newSprites = [...l.sprites];
|
||||||
|
newSprites[currentIndex] = target;
|
||||||
|
newSprites[newIndex] = moving;
|
||||||
|
l.sprites = newSprites;
|
||||||
|
} else {
|
||||||
|
// Move to previously empty/non-existent cell
|
||||||
|
const newSprites = [...l.sprites];
|
||||||
|
// Remove from old pos
|
||||||
|
const [moved] = newSprites.splice(currentIndex, 1);
|
||||||
|
// Pad
|
||||||
|
while (newSprites.length < newIndex) {
|
||||||
|
newSprites.push(createEmptySprite());
|
||||||
|
}
|
||||||
|
// Insert (or push if equal length)
|
||||||
|
newSprites.splice(newIndex, 0, moved);
|
||||||
|
l.sprites = newSprites;
|
||||||
}
|
}
|
||||||
l.sprites = next;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeSprite = (id: string) => {
|
const removeSprite = (id: string) => {
|
||||||
@@ -98,6 +193,49 @@ export const useLayers = () => {
|
|||||||
l.sprites.splice(i, 1);
|
l.sprites.splice(i, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeSprites = (ids: string[]) => {
|
||||||
|
const l = activeLayer.value;
|
||||||
|
if (!l) return;
|
||||||
|
|
||||||
|
// Sort indices in descending order to avoid shift issues when splicing
|
||||||
|
const indicesToRemove: number[] = [];
|
||||||
|
ids.forEach(id => {
|
||||||
|
const i = l.sprites.findIndex(s => s.id === id);
|
||||||
|
if (i !== -1) indicesToRemove.push(i);
|
||||||
|
});
|
||||||
|
|
||||||
|
indicesToRemove.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
indicesToRemove.forEach(i => {
|
||||||
|
const s = l.sprites[i];
|
||||||
|
if (s.url && s.url.startsWith('blob:')) {
|
||||||
|
try {
|
||||||
|
URL.revokeObjectURL(s.url);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
l.sprites.splice(i, 1);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const rotateSprite = (id: string, angle: number) => {
|
||||||
|
const l = activeLayer.value;
|
||||||
|
if (!l) return;
|
||||||
|
const s = l.sprites.find(s => s.id === id);
|
||||||
|
if (s) {
|
||||||
|
s.rotation = (s.rotation + angle) % 360;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const flipSprite = (id: string, direction: 'horizontal' | 'vertical') => {
|
||||||
|
const l = activeLayer.value;
|
||||||
|
if (!l) return;
|
||||||
|
const s = l.sprites.find(s => s.id === id);
|
||||||
|
if (s) {
|
||||||
|
if (direction === 'horizontal') s.flipX = !s.flipX;
|
||||||
|
if (direction === 'vertical') s.flipY = !s.flipY;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const replaceSprite = (id: string, file: File) => {
|
const replaceSprite = (id: string, file: File) => {
|
||||||
const l = activeLayer.value;
|
const l = activeLayer.value;
|
||||||
if (!l) return;
|
if (!l) return;
|
||||||
@@ -110,23 +248,30 @@ export const useLayers = () => {
|
|||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = URL.createObjectURL(file);
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
l.sprites[i] = { id: old.id, file, img, url, width: img.width, height: img.height, x: old.x, y: old.y };
|
l.sprites[i] = { id: old.id, file, img, url, width: img.width, height: img.height, x: old.x, y: old.y, rotation: old.rotation, flipX: old.flipX || false, flipY: old.flipY || false };
|
||||||
};
|
};
|
||||||
img.onerror = () => {
|
img.onerror = () => {
|
||||||
URL.revokeObjectURL(url);
|
console.error('Failed to load replacement image:', file.name);
|
||||||
};
|
};
|
||||||
img.src = url;
|
img.src = url;
|
||||||
};
|
};
|
||||||
|
reader.onerror = () => {
|
||||||
|
console.error('Failed to read replacement image file:', file.name);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
};
|
||||||
|
|
||||||
const addSprite = (file: File) => addSpriteWithResize(file);
|
const addSprite = (file: File, index?: number) => {
|
||||||
|
|
||||||
const addSpriteWithResize = (file: File) => {
|
|
||||||
const l = activeLayer.value;
|
const l = activeLayer.value;
|
||||||
if (!l) return;
|
if (!l) return;
|
||||||
const url = URL.createObjectURL(file);
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
const next: Sprite = {
|
const next: Sprite = {
|
||||||
@@ -138,15 +283,46 @@ export const useLayers = () => {
|
|||||||
height: img.height,
|
height: img.height,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
};
|
};
|
||||||
l.sprites = [...l.sprites, next];
|
|
||||||
|
const currentSprites = [...l.sprites];
|
||||||
|
|
||||||
|
if (typeof index === 'number') {
|
||||||
|
// If index is provided, insert there (padding if needed)
|
||||||
|
while (currentSprites.length < index) {
|
||||||
|
currentSprites.push(createEmptySprite());
|
||||||
|
}
|
||||||
|
// If valid index, replace if empty or splice?
|
||||||
|
// "Adds it not in the one I selected".
|
||||||
|
// If I select a cell, I expect it to go there.
|
||||||
|
// If the cell is empty (placeholder), replace it.
|
||||||
|
// If the cell has a sprite, maybe insert/shift?
|
||||||
|
// Usually "Add" implies append, but context menu "Add sprite" on a cell implies "Put it here".
|
||||||
|
// Let's Insert (Shift others) for safety, or check if empty.
|
||||||
|
// But simpler: just splice it in.
|
||||||
|
currentSprites.splice(index, 0, next);
|
||||||
|
} else {
|
||||||
|
// No index, append to end
|
||||||
|
currentSprites.push(next);
|
||||||
|
}
|
||||||
|
l.sprites = currentSprites;
|
||||||
|
};
|
||||||
|
img.onerror = () => {
|
||||||
|
console.error('Failed to load sprite image:', file.name);
|
||||||
};
|
};
|
||||||
img.onerror = () => URL.revokeObjectURL(url);
|
|
||||||
img.src = url;
|
img.src = url;
|
||||||
};
|
};
|
||||||
|
reader.onerror = () => {
|
||||||
|
console.error('Failed to read sprite image file:', file.name);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
};
|
||||||
|
|
||||||
const processImageFiles = async (files: File[]) => {
|
const processImageFiles = async (files: File[]) => {
|
||||||
for (const f of files) addSpriteWithResize(f);
|
for (const f of files) addSprite(f);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addLayer = (name?: string) => {
|
const addLayer = (name?: string) => {
|
||||||
@@ -176,7 +352,55 @@ export const useLayers = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const visibleLayers = computed(() => layers.value.filter(l => l.visible));
|
const copySpriteToFrame = (spriteId: string, targetLayerId: string, targetFrameIndex: number) => {
|
||||||
|
// Find the source sprite in any layer
|
||||||
|
let sourceSprite: Sprite | undefined;
|
||||||
|
for (const layer of layers.value) {
|
||||||
|
sourceSprite = layer.sprites.find(s => s.id === spriteId);
|
||||||
|
if (sourceSprite) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sourceSprite) return;
|
||||||
|
|
||||||
|
// Find target layer
|
||||||
|
const targetLayer = layers.value.find(l => l.id === targetLayerId);
|
||||||
|
if (!targetLayer) return;
|
||||||
|
|
||||||
|
// Create a deep copy of the sprite with a new ID
|
||||||
|
const copiedSprite: Sprite = {
|
||||||
|
id: crypto.randomUUID(),
|
||||||
|
file: sourceSprite.file,
|
||||||
|
img: sourceSprite.img,
|
||||||
|
url: sourceSprite.url,
|
||||||
|
width: sourceSprite.width,
|
||||||
|
height: sourceSprite.height,
|
||||||
|
x: sourceSprite.x,
|
||||||
|
y: sourceSprite.y,
|
||||||
|
rotation: sourceSprite.rotation,
|
||||||
|
flipX: sourceSprite.flipX,
|
||||||
|
flipY: sourceSprite.flipY,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Expand the sprites array if necessary with empty placeholder sprites
|
||||||
|
while (targetLayer.sprites.length < targetFrameIndex) {
|
||||||
|
targetLayer.sprites.push(createEmptySprite());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace or insert the sprite at the target index
|
||||||
|
if (targetFrameIndex < targetLayer.sprites.length) {
|
||||||
|
// Replace existing sprite at this frame
|
||||||
|
const old = targetLayer.sprites[targetFrameIndex];
|
||||||
|
if (old.url && old.url.startsWith('blob:')) {
|
||||||
|
try {
|
||||||
|
URL.revokeObjectURL(old.url);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
targetLayer.sprites[targetFrameIndex] = copiedSprite;
|
||||||
|
} else {
|
||||||
|
// Add at the end
|
||||||
|
targetLayer.sprites.push(copiedSprite);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
layers,
|
layers,
|
||||||
@@ -186,20 +410,27 @@ export const useLayers = () => {
|
|||||||
columns,
|
columns,
|
||||||
getMaxDimensions,
|
getMaxDimensions,
|
||||||
updateSpritePosition,
|
updateSpritePosition,
|
||||||
|
updateSpriteInLayer,
|
||||||
updateSpriteCell,
|
updateSpriteCell,
|
||||||
removeSprite,
|
removeSprite,
|
||||||
|
removeSprites,
|
||||||
|
rotateSprite,
|
||||||
|
flipSprite,
|
||||||
replaceSprite,
|
replaceSprite,
|
||||||
addSprite,
|
addSprite,
|
||||||
addSpriteWithResize,
|
|
||||||
processImageFiles,
|
processImageFiles,
|
||||||
alignSprites,
|
alignSprites,
|
||||||
addLayer,
|
addLayer,
|
||||||
removeLayer,
|
removeLayer,
|
||||||
moveLayer,
|
moveLayer,
|
||||||
|
copySpriteToFrame,
|
||||||
|
hasSprites,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMaxDimensionsAcrossLayers = (layers: Layer[]) => {
|
export const getMaxDimensionsAcrossLayers = (layers: Layer[], visibleOnly: boolean = false) => {
|
||||||
const sprites = layers.flatMap(l => (l.visible ? l.sprites : []));
|
// When visibleOnly is false (default), consider ALL layers to keep canvas size stable
|
||||||
|
// When visibleOnly is true (export), only consider visible layers
|
||||||
|
const sprites = layers.flatMap(l => (visibleOnly ? (l.visible ? l.sprites : []) : l.sprites));
|
||||||
return getMaxDimensionsSingle(sprites);
|
return getMaxDimensionsSingle(sprites);
|
||||||
};
|
};
|
||||||
|
|||||||
126
src/composables/useProjectManager.ts
Normal file
126
src/composables/useProjectManager.ts
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import { toRef } from 'vue';
|
||||||
|
import { useLayers, createEmptyLayer } from '@/composables/useLayers';
|
||||||
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
|
import { useProjectStore, type Project } from '@/stores/useProjectStore';
|
||||||
|
import { useExportLayers } from '@/composables/useExportLayers';
|
||||||
|
|
||||||
|
export const useProjectManager = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
const projectStore = useProjectStore();
|
||||||
|
const { layers, columns, activeLayerId } = useLayers();
|
||||||
|
|
||||||
|
const { generateProjectJSON, loadProjectData } = useExportLayers(
|
||||||
|
layers,
|
||||||
|
columns,
|
||||||
|
toRef(settingsStore, 'negativeSpacingEnabled'),
|
||||||
|
activeLayerId,
|
||||||
|
toRef(settingsStore, 'backgroundColor'),
|
||||||
|
toRef(settingsStore, 'manualCellSizeEnabled'),
|
||||||
|
toRef(settingsStore, 'manualCellWidth'),
|
||||||
|
toRef(settingsStore, 'manualCellHeight')
|
||||||
|
);
|
||||||
|
|
||||||
|
const createProject = (config: { width: number; height: number; columns: number; rows: number }) => {
|
||||||
|
// 1. Reset Settings
|
||||||
|
settingsStore.setManualCellSize(config.width, config.height);
|
||||||
|
settingsStore.manualCellSizeEnabled = true;
|
||||||
|
|
||||||
|
// 2. Reset Layers
|
||||||
|
const newLayer = createEmptyLayer('Base');
|
||||||
|
layers.value = [newLayer];
|
||||||
|
activeLayerId.value = newLayer.id;
|
||||||
|
|
||||||
|
// 3. Set Columns
|
||||||
|
columns.value = config.columns;
|
||||||
|
|
||||||
|
// 4. Reset Project Store
|
||||||
|
projectStore.currentProject = null;
|
||||||
|
|
||||||
|
// 5. Navigate to Editor
|
||||||
|
router.push('/editor');
|
||||||
|
};
|
||||||
|
|
||||||
|
const openProject = async (project: Project) => {
|
||||||
|
try {
|
||||||
|
if (project.data) {
|
||||||
|
await loadProjectData(project.data);
|
||||||
|
}
|
||||||
|
projectStore.currentProject = project;
|
||||||
|
router.push({ name: 'editor', params: { id: project.id } });
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to open project', e);
|
||||||
|
alert('Failed to open project data');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveProject = async (name: string) => {
|
||||||
|
try {
|
||||||
|
const data = await generateProjectJSON();
|
||||||
|
|
||||||
|
if (projectStore.currentProject) {
|
||||||
|
// Update existing project (even if name changed)
|
||||||
|
await projectStore.updateProject(projectStore.currentProject.id, name, data);
|
||||||
|
} else {
|
||||||
|
// Create new project if none exists
|
||||||
|
await projectStore.createProject(name, data);
|
||||||
|
// After creating, we should update route to include ID so subsequent saves update it
|
||||||
|
const newProject = projectStore.currentProject as Project | null;
|
||||||
|
if (newProject) {
|
||||||
|
router.replace({ name: 'editor', params: { id: newProject.id } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert('Failed to save project');
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveAsProject = async (name: string) => {
|
||||||
|
try {
|
||||||
|
const data = await generateProjectJSON();
|
||||||
|
// Always create new
|
||||||
|
await projectStore.createProject(name, data);
|
||||||
|
// Navigate to new project
|
||||||
|
if (projectStore.currentProject) {
|
||||||
|
router.push({ name: 'editor', params: { id: projectStore.currentProject.id } });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert('Failed to save project as new');
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeProject = () => {
|
||||||
|
// Reset Layers
|
||||||
|
const newLayer = createEmptyLayer('Base');
|
||||||
|
layers.value = [newLayer];
|
||||||
|
activeLayerId.value = newLayer.id;
|
||||||
|
|
||||||
|
// Reset columns
|
||||||
|
columns.value = 4;
|
||||||
|
|
||||||
|
// Reset Project Store
|
||||||
|
projectStore.currentProject = null;
|
||||||
|
|
||||||
|
// Navigate Home
|
||||||
|
router.push('/');
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeEditor = () => {
|
||||||
|
closeProject();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
createProject,
|
||||||
|
openProject,
|
||||||
|
saveProject,
|
||||||
|
saveAsProject,
|
||||||
|
closeEditor,
|
||||||
|
closeProject,
|
||||||
|
loadProjectData,
|
||||||
|
};
|
||||||
|
};
|
||||||
71
src/composables/useSEO.ts
Normal file
71
src/composables/useSEO.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { useHead } from '@vueuse/head';
|
||||||
|
|
||||||
|
export interface SEOMetaData {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
image?: string;
|
||||||
|
url?: string;
|
||||||
|
type?: 'website' | 'article';
|
||||||
|
author?: string;
|
||||||
|
publishedTime?: string;
|
||||||
|
modifiedTime?: string;
|
||||||
|
keywords?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SITE_NAME = 'Spritesheet Generator';
|
||||||
|
const SITE_URL = 'https://spritesheetgenerator.online';
|
||||||
|
const DEFAULT_IMAGE = '/og-image.png';
|
||||||
|
|
||||||
|
export function useSEO(metadata: SEOMetaData) {
|
||||||
|
const fullTitle = metadata.title.includes(SITE_NAME) ? metadata.title : `${metadata.title} - ${SITE_NAME}`;
|
||||||
|
|
||||||
|
const fullUrl = metadata.url ? `${SITE_URL}${metadata.url}` : SITE_URL;
|
||||||
|
|
||||||
|
const imageUrl = metadata.image ? `${SITE_URL}${metadata.image}` : `${SITE_URL}${DEFAULT_IMAGE}`;
|
||||||
|
|
||||||
|
const metaTags: any[] = [
|
||||||
|
// Primary Meta Tags
|
||||||
|
{ name: 'title', content: fullTitle },
|
||||||
|
{ name: 'description', content: metadata.description },
|
||||||
|
{ name: 'robots', content: 'index, follow' },
|
||||||
|
|
||||||
|
// Open Graph / Facebook
|
||||||
|
{ property: 'og:type', content: metadata.type || 'website' },
|
||||||
|
{ property: 'og:url', content: fullUrl },
|
||||||
|
{ property: 'og:title', content: fullTitle },
|
||||||
|
{ property: 'og:description', content: metadata.description },
|
||||||
|
{ property: 'og:image', content: imageUrl },
|
||||||
|
{ property: 'og:site_name', content: SITE_NAME },
|
||||||
|
|
||||||
|
// Twitter
|
||||||
|
{ name: 'twitter:card', content: 'summary_large_image' },
|
||||||
|
{ name: 'twitter:url', content: fullUrl },
|
||||||
|
{ name: 'twitter:title', content: fullTitle },
|
||||||
|
{ name: 'twitter:description', content: metadata.description },
|
||||||
|
{ name: 'twitter:image', content: imageUrl },
|
||||||
|
];
|
||||||
|
|
||||||
|
// Add article-specific meta tags
|
||||||
|
if (metadata.type === 'article') {
|
||||||
|
if (metadata.author) {
|
||||||
|
metaTags.push({ property: 'article:author', content: metadata.author });
|
||||||
|
}
|
||||||
|
if (metadata.publishedTime) {
|
||||||
|
metaTags.push({ property: 'article:published_time', content: metadata.publishedTime });
|
||||||
|
}
|
||||||
|
if (metadata.modifiedTime) {
|
||||||
|
metaTags.push({ property: 'article:modified_time', content: metadata.modifiedTime });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add keywords if provided
|
||||||
|
if (metadata.keywords) {
|
||||||
|
metaTags.push({ name: 'keywords', content: metadata.keywords });
|
||||||
|
}
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
title: fullTitle,
|
||||||
|
meta: metaTags,
|
||||||
|
link: [{ rel: 'canonical', href: fullUrl }],
|
||||||
|
});
|
||||||
|
}
|
||||||
169
src/composables/useShare.ts
Normal file
169
src/composables/useShare.ts
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
import type { Ref } from 'vue';
|
||||||
|
import type { Layer } from '@/types/sprites';
|
||||||
|
|
||||||
|
const POCKETBASE_URL = import.meta.env.VITE_POCKETBASE_URL;
|
||||||
|
const COLLECTION = 'spritesheets';
|
||||||
|
|
||||||
|
export interface SpritesheetConfig {
|
||||||
|
version: number;
|
||||||
|
columns: number;
|
||||||
|
negativeSpacingEnabled: boolean;
|
||||||
|
backgroundColor: string;
|
||||||
|
manualCellSizeEnabled: boolean;
|
||||||
|
manualCellWidth: number;
|
||||||
|
manualCellHeight: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SharedSprite {
|
||||||
|
id: string;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
rotation: number;
|
||||||
|
flipX: boolean;
|
||||||
|
flipY: boolean;
|
||||||
|
base64: string;
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SharedLayer {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
visible: boolean;
|
||||||
|
locked: boolean;
|
||||||
|
sprites: SharedSprite[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SpritesheetRecord {
|
||||||
|
id: string;
|
||||||
|
config: SpritesheetConfig;
|
||||||
|
sprites: SharedLayer[];
|
||||||
|
created: string;
|
||||||
|
updated: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ShareResult {
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the shareable URL for a spritesheet
|
||||||
|
*/
|
||||||
|
export const buildShareUrl = (id: string): string => {
|
||||||
|
return `${window.location.origin}/share/${id}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Share a spritesheet by uploading to PocketBase
|
||||||
|
*/
|
||||||
|
export const shareSpritesheet = async (layersRef: Ref<Layer[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>, backgroundColor?: Ref<string>, manualCellSizeEnabled?: Ref<boolean>, manualCellWidth?: Ref<number>, manualCellHeight?: Ref<number>): Promise<ShareResult> => {
|
||||||
|
// Build layers data with base64 sprites (same format as exportSpritesheetJSON)
|
||||||
|
const layersData = await Promise.all(
|
||||||
|
layersRef.value.map(async layer => {
|
||||||
|
const sprites = await Promise.all(
|
||||||
|
layer.sprites.map(async sprite => {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (!ctx) return null;
|
||||||
|
canvas.width = sprite.width;
|
||||||
|
canvas.height = sprite.height;
|
||||||
|
if (sprite.rotation || sprite.flipX || sprite.flipY) {
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(sprite.width / 2, sprite.height / 2);
|
||||||
|
ctx.rotate((sprite.rotation * Math.PI) / 180);
|
||||||
|
ctx.scale(sprite.flipX ? -1 : 1, sprite.flipY ? -1 : 1);
|
||||||
|
ctx.drawImage(sprite.img, -sprite.width / 2, -sprite.height / 2);
|
||||||
|
ctx.restore();
|
||||||
|
} else {
|
||||||
|
ctx.drawImage(sprite.img, 0, 0);
|
||||||
|
}
|
||||||
|
const base64 = canvas.toDataURL('image/png');
|
||||||
|
// Since we bake transformations into the image, set them to 0/false in metadata
|
||||||
|
return {
|
||||||
|
id: sprite.id,
|
||||||
|
width: sprite.width,
|
||||||
|
height: sprite.height,
|
||||||
|
x: sprite.x,
|
||||||
|
y: sprite.y,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
|
base64,
|
||||||
|
name: sprite.file.name,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
id: layer.id,
|
||||||
|
name: layer.name,
|
||||||
|
visible: layer.visible,
|
||||||
|
locked: layer.locked,
|
||||||
|
sprites: sprites.filter(Boolean),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const config: SpritesheetConfig = {
|
||||||
|
version: 2,
|
||||||
|
columns: columns.value,
|
||||||
|
negativeSpacingEnabled: negativeSpacingEnabled.value,
|
||||||
|
backgroundColor: backgroundColor?.value || 'transparent',
|
||||||
|
manualCellSizeEnabled: manualCellSizeEnabled?.value || false,
|
||||||
|
manualCellWidth: manualCellWidth?.value || 64,
|
||||||
|
manualCellHeight: manualCellHeight?.value || 64,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${POCKETBASE_URL}/api/collections/${COLLECTION}/records`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
config,
|
||||||
|
sprites: layersData,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const text = await response.text().catch(() => '');
|
||||||
|
throw new Error(text || `Request failed with status ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const record = await response.json();
|
||||||
|
return {
|
||||||
|
id: record.id,
|
||||||
|
url: buildShareUrl(record.id),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch a shared spritesheet from PocketBase
|
||||||
|
*/
|
||||||
|
export const fetchSpritesheet = async (id: string): Promise<SpritesheetRecord> => {
|
||||||
|
const response = await fetch(`${POCKETBASE_URL}/api/collections/${COLLECTION}/records/${id}`);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
if (response.status === 404) {
|
||||||
|
throw new Error('Spritesheet not found');
|
||||||
|
}
|
||||||
|
const text = await response.text().catch(() => '');
|
||||||
|
throw new Error(text || `Request failed with status ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composable hook for share functionality
|
||||||
|
*/
|
||||||
|
export const useShare = (layersRef: Ref<Layer[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>, backgroundColor?: Ref<string>, manualCellSizeEnabled?: Ref<boolean>, manualCellWidth?: Ref<number>, manualCellHeight?: Ref<number>) => {
|
||||||
|
const share = () => shareSpritesheet(layersRef, columns, negativeSpacingEnabled, backgroundColor, manualCellSizeEnabled, manualCellWidth, manualCellHeight);
|
||||||
|
|
||||||
|
return {
|
||||||
|
share,
|
||||||
|
fetchSpritesheet,
|
||||||
|
buildShareUrl,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -87,7 +87,9 @@ export const useSprites = () => {
|
|||||||
const old = sprites.value[i];
|
const old = sprites.value[i];
|
||||||
revokeIfBlob(old.url);
|
revokeIfBlob(old.url);
|
||||||
|
|
||||||
const url = URL.createObjectURL(file);
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
const next: Sprite = {
|
const next: Sprite = {
|
||||||
@@ -99,6 +101,9 @@ export const useSprites = () => {
|
|||||||
height: img.height,
|
height: img.height,
|
||||||
x: old.x,
|
x: old.x,
|
||||||
y: old.y,
|
y: old.y,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
};
|
};
|
||||||
const arr = [...sprites.value];
|
const arr = [...sprites.value];
|
||||||
arr[i] = next;
|
arr[i] = next;
|
||||||
@@ -106,13 +111,19 @@ export const useSprites = () => {
|
|||||||
};
|
};
|
||||||
img.onerror = () => {
|
img.onerror = () => {
|
||||||
console.error('Failed to load replacement image:', file.name);
|
console.error('Failed to load replacement image:', file.name);
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
};
|
};
|
||||||
img.src = url;
|
img.src = url;
|
||||||
};
|
};
|
||||||
|
reader.onerror = () => {
|
||||||
|
console.error('Failed to read replacement image file:', file.name);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
};
|
||||||
|
|
||||||
const addSprite = (file: File) => {
|
const addSprite = (file: File) => {
|
||||||
const url = URL.createObjectURL(file);
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
const s: Sprite = {
|
const s: Sprite = {
|
||||||
@@ -124,18 +135,27 @@ export const useSprites = () => {
|
|||||||
height: img.height,
|
height: img.height,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
};
|
};
|
||||||
sprites.value = [...sprites.value, s];
|
sprites.value = [...sprites.value, s];
|
||||||
};
|
};
|
||||||
img.onerror = () => {
|
img.onerror = () => {
|
||||||
console.error('Failed to load new sprite image:', file.name);
|
console.error('Failed to load new sprite image:', file.name);
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
};
|
};
|
||||||
img.src = url;
|
img.src = url;
|
||||||
};
|
};
|
||||||
|
reader.onerror = () => {
|
||||||
|
console.error('Failed to read sprite image file:', file.name);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
};
|
||||||
|
|
||||||
const addSpriteWithResize = (file: File) => {
|
const addSpriteWithResize = (file: File) => {
|
||||||
const url = URL.createObjectURL(file);
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
const { maxWidth, maxHeight } = getMaxDimensions(sprites.value);
|
const { maxWidth, maxHeight } = getMaxDimensions(sprites.value);
|
||||||
@@ -149,6 +169,9 @@ export const useSprites = () => {
|
|||||||
height: img.height,
|
height: img.height,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const newMaxWidth = Math.max(maxWidth, img.width);
|
const newMaxWidth = Math.max(maxWidth, img.width);
|
||||||
@@ -180,17 +203,23 @@ export const useSprites = () => {
|
|||||||
};
|
};
|
||||||
img.onerror = () => {
|
img.onerror = () => {
|
||||||
console.error('Failed to load new sprite image:', file.name);
|
console.error('Failed to load new sprite image:', file.name);
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
};
|
};
|
||||||
img.src = url;
|
img.src = url;
|
||||||
};
|
};
|
||||||
|
reader.onerror = () => {
|
||||||
|
console.error('Failed to read sprite image file:', file.name);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
};
|
||||||
|
|
||||||
const processImageFiles = (files: File[]) => {
|
const processImageFiles = (files: File[]) => {
|
||||||
Promise.all(
|
Promise.all(
|
||||||
files.map(
|
files.map(
|
||||||
file =>
|
file =>
|
||||||
new Promise<Sprite>(resolve => {
|
new Promise<Sprite>((resolve, reject) => {
|
||||||
const url = URL.createObjectURL(file);
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
resolve({
|
resolve({
|
||||||
@@ -202,13 +231,24 @@ export const useSprites = () => {
|
|||||||
height: img.height,
|
height: img.height,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
img.onerror = () => reject(new Error(`Failed to load image: ${file.name}`));
|
||||||
img.src = url;
|
img.src = url;
|
||||||
|
};
|
||||||
|
reader.onerror = () => reject(new Error(`Failed to read file: ${file.name}`));
|
||||||
|
reader.readAsDataURL(file);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
).then(newSprites => {
|
)
|
||||||
|
.then(newSprites => {
|
||||||
sprites.value = [...sprites.value, ...newSprites];
|
sprites.value = [...sprites.value, ...newSprites];
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error('Error processing image files:', err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
316
src/composables/useSpritesheetSplitter.ts
Normal file
316
src/composables/useSpritesheetSplitter.ts
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
import { ref, computed, type Ref } from 'vue';
|
||||||
|
import type { SpritePreview, SpriteRegion, GridSplitOptions, AutoDetectOptions, SpriteWorkerResponse } from '@/types/spritesheet';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composable for spritesheet splitting logic
|
||||||
|
* Handles grid-based and auto-detection sprite extraction
|
||||||
|
*/
|
||||||
|
export function useSpritesheetSplitter() {
|
||||||
|
const isProcessing = ref(false);
|
||||||
|
const previewSprites: Ref<SpritePreview[]> = ref([]);
|
||||||
|
const worker: Ref<Worker | null> = ref(null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split image into grid cells
|
||||||
|
*/
|
||||||
|
async function splitByGrid(img: HTMLImageElement, options: GridSplitOptions): Promise<SpritePreview[]> {
|
||||||
|
const { cellWidth, cellHeight, preserveCellSize, removeEmpty } = options;
|
||||||
|
|
||||||
|
if (cellWidth <= 0 || cellHeight <= 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const cols = Math.floor(img.width / cellWidth);
|
||||||
|
const rows = Math.floor(img.height / cellHeight);
|
||||||
|
const sprites: SpritePreview[] = [];
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
const cropCanvas = document.createElement('canvas');
|
||||||
|
const cropCtx = cropCanvas.getContext('2d');
|
||||||
|
|
||||||
|
if (!ctx || !cropCtx) return [];
|
||||||
|
|
||||||
|
canvas.width = cellWidth;
|
||||||
|
canvas.height = cellHeight;
|
||||||
|
|
||||||
|
for (let row = 0; row < rows; row++) {
|
||||||
|
for (let col = 0; col < cols; col++) {
|
||||||
|
ctx.clearRect(0, 0, cellWidth, cellHeight);
|
||||||
|
ctx.drawImage(img, col * cellWidth, row * cellHeight, cellWidth, cellHeight, 0, 0, cellWidth, cellHeight);
|
||||||
|
|
||||||
|
const isEmpty = removeEmpty ? isCanvasEmpty(ctx, cellWidth, cellHeight) : false;
|
||||||
|
|
||||||
|
if (!removeEmpty || !isEmpty) {
|
||||||
|
let url: string;
|
||||||
|
let x = 0;
|
||||||
|
let y = 0;
|
||||||
|
let width = cellWidth;
|
||||||
|
let height = cellHeight;
|
||||||
|
|
||||||
|
if (preserveCellSize) {
|
||||||
|
// Keep full cell with transparent padding
|
||||||
|
url = canvas.toDataURL('image/png');
|
||||||
|
} else {
|
||||||
|
// Crop to sprite bounds
|
||||||
|
const bounds = getSpriteBounds(ctx, cellWidth, cellHeight);
|
||||||
|
if (bounds) {
|
||||||
|
x = bounds.x;
|
||||||
|
y = bounds.y;
|
||||||
|
width = bounds.width;
|
||||||
|
height = bounds.height;
|
||||||
|
|
||||||
|
cropCanvas.width = width;
|
||||||
|
cropCanvas.height = height;
|
||||||
|
cropCtx.clearRect(0, 0, width, height);
|
||||||
|
cropCtx.drawImage(canvas, x, y, width, height, 0, 0, width, height);
|
||||||
|
url = cropCanvas.toDataURL('image/png');
|
||||||
|
} else {
|
||||||
|
url = canvas.toDataURL('image/png');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sprites.push({ url, x, y, width, height, isEmpty });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprites;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect sprites using web worker for irregular layouts
|
||||||
|
*/
|
||||||
|
async function detectSprites(img: HTMLImageElement, options: AutoDetectOptions): Promise<SpritePreview[]> {
|
||||||
|
const { sensitivity, removeEmpty } = options;
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (!ctx) return [];
|
||||||
|
|
||||||
|
canvas.width = img.width;
|
||||||
|
canvas.height = img.height;
|
||||||
|
ctx.drawImage(img, 0, 0);
|
||||||
|
|
||||||
|
const imageData = ctx.getImageData(0, 0, img.width, img.height);
|
||||||
|
|
||||||
|
// Initialize worker lazily
|
||||||
|
if (!worker.value) {
|
||||||
|
try {
|
||||||
|
worker.value = new Worker(new URL('../workers/irregularSpriteDetection.worker.ts', import.meta.url), { type: 'module' });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to create worker:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise<SpritePreview[]>(resolve => {
|
||||||
|
const w = worker.value!;
|
||||||
|
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
w.removeEventListener('message', handleMessage);
|
||||||
|
console.warn('Worker timeout');
|
||||||
|
resolve([]);
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
const handleMessage = async (e: MessageEvent<SpriteWorkerResponse>) => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
w.removeEventListener('message', handleMessage);
|
||||||
|
|
||||||
|
if (e.data.type === 'spritesDetected') {
|
||||||
|
const sprites = await processDetectedSprites(img, e.data.sprites, e.data.backgroundColor, removeEmpty);
|
||||||
|
resolve(sprites);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
w.addEventListener('message', handleMessage);
|
||||||
|
|
||||||
|
w.postMessage({
|
||||||
|
type: 'detectIrregularSprites',
|
||||||
|
imageData,
|
||||||
|
sensitivity,
|
||||||
|
maxSize: 2048,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process sprites detected by worker into preview format
|
||||||
|
*/
|
||||||
|
async function processDetectedSprites(img: HTMLImageElement, regions: SpriteRegion[], backgroundColor: [number, number, number, number], removeEmpty: boolean): Promise<SpritePreview[]> {
|
||||||
|
if (!regions?.length) return [];
|
||||||
|
|
||||||
|
const sprites: SpritePreview[] = [];
|
||||||
|
const sourceCanvas = document.createElement('canvas');
|
||||||
|
const sourceCtx = sourceCanvas.getContext('2d');
|
||||||
|
const spriteCanvas = document.createElement('canvas');
|
||||||
|
const spriteCtx = spriteCanvas.getContext('2d');
|
||||||
|
|
||||||
|
if (!sourceCtx || !spriteCtx) return [];
|
||||||
|
|
||||||
|
sourceCanvas.width = img.width;
|
||||||
|
sourceCanvas.height = img.height;
|
||||||
|
sourceCtx.drawImage(img, 0, 0);
|
||||||
|
|
||||||
|
for (const region of regions) {
|
||||||
|
const { x, y, width, height } = region;
|
||||||
|
if (width <= 0 || height <= 0) continue;
|
||||||
|
|
||||||
|
spriteCanvas.width = width;
|
||||||
|
spriteCanvas.height = height;
|
||||||
|
spriteCtx.clearRect(0, 0, width, height);
|
||||||
|
spriteCtx.drawImage(sourceCanvas, x, y, width, height, 0, 0, width, height);
|
||||||
|
|
||||||
|
// Remove background color
|
||||||
|
removeBackground(spriteCtx, width, height, backgroundColor);
|
||||||
|
|
||||||
|
const isEmpty = removeEmpty ? isCanvasEmpty(spriteCtx, width, height) : false;
|
||||||
|
|
||||||
|
if (!removeEmpty || !isEmpty) {
|
||||||
|
sprites.push({
|
||||||
|
url: spriteCanvas.toDataURL('image/png'),
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
isEmpty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprites;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get bounding box of non-transparent pixels
|
||||||
|
*/
|
||||||
|
function getSpriteBounds(ctx: CanvasRenderingContext2D, width: number, height: number): { x: number; y: number; width: number; height: number } | null {
|
||||||
|
const imageData = ctx.getImageData(0, 0, width, height);
|
||||||
|
const data = imageData.data;
|
||||||
|
|
||||||
|
let minX = width,
|
||||||
|
minY = height,
|
||||||
|
maxX = 0,
|
||||||
|
maxY = 0;
|
||||||
|
let hasContent = false;
|
||||||
|
|
||||||
|
for (let y = 0; y < height; y++) {
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
const alpha = data[(y * width + x) * 4 + 3];
|
||||||
|
if (alpha > 10) {
|
||||||
|
minX = Math.min(minX, x);
|
||||||
|
minY = Math.min(minY, y);
|
||||||
|
maxX = Math.max(maxX, x);
|
||||||
|
maxY = Math.max(maxY, y);
|
||||||
|
hasContent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasContent) return null;
|
||||||
|
|
||||||
|
// Add small padding
|
||||||
|
const pad = 1;
|
||||||
|
return {
|
||||||
|
x: Math.max(0, minX - pad),
|
||||||
|
y: Math.max(0, minY - pad),
|
||||||
|
width: Math.min(width - Math.max(0, minX - pad), maxX - minX + 1 + pad * 2),
|
||||||
|
height: Math.min(height - Math.max(0, minY - pad), maxY - minY + 1 + pad * 2),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if canvas is empty (all transparent or same color)
|
||||||
|
*/
|
||||||
|
function isCanvasEmpty(ctx: CanvasRenderingContext2D, width: number, height: number): boolean {
|
||||||
|
const data = ctx.getImageData(0, 0, width, height).data;
|
||||||
|
let allTransparent = true;
|
||||||
|
let allSameColor = true;
|
||||||
|
|
||||||
|
const [firstR, firstG, firstB, firstA] = [data[0], data[1], data[2], data[3]];
|
||||||
|
|
||||||
|
for (let i = 0; i < data.length; i += 4) {
|
||||||
|
if (data[i + 3] > 10) allTransparent = false;
|
||||||
|
if (data[i] !== firstR || data[i + 1] !== firstG || data[i + 2] !== firstB || Math.abs(data[i + 3] - firstA) > 10) {
|
||||||
|
allSameColor = false;
|
||||||
|
}
|
||||||
|
if (!allTransparent && !allSameColor) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return allTransparent || allSameColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove background color from sprite, making it transparent
|
||||||
|
*/
|
||||||
|
function removeBackground(ctx: CanvasRenderingContext2D, width: number, height: number, bgColor: [number, number, number, number]): void {
|
||||||
|
const imageData = ctx.getImageData(0, 0, width, height);
|
||||||
|
const data = imageData.data;
|
||||||
|
const [bgR, bgG, bgB, bgA] = bgColor;
|
||||||
|
const tolerance = 30;
|
||||||
|
|
||||||
|
for (let i = 0; i < data.length; i += 4) {
|
||||||
|
const a = data[i + 3];
|
||||||
|
if (a < 10) {
|
||||||
|
data[i + 3] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rDiff = data[i] - bgR;
|
||||||
|
const gDiff = data[i + 1] - bgG;
|
||||||
|
const bDiff = data[i + 2] - bgB;
|
||||||
|
const dist = Math.sqrt(rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
|
||||||
|
|
||||||
|
if (dist <= tolerance && Math.abs(a - bgA) <= 40) {
|
||||||
|
data[i + 3] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.putImageData(imageData, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup worker on unmount
|
||||||
|
*/
|
||||||
|
function cleanup() {
|
||||||
|
if (worker.value) {
|
||||||
|
worker.value.terminate();
|
||||||
|
worker.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate suggested cell size based on image dimensions
|
||||||
|
*/
|
||||||
|
function getSuggestedCellSize(width: number, height: number): { width: number; height: number } {
|
||||||
|
const commonSizes = [256, 192, 128, 96, 64, 48, 32, 16];
|
||||||
|
|
||||||
|
let cellWidth = 64;
|
||||||
|
let cellHeight = 64;
|
||||||
|
|
||||||
|
for (const size of commonSizes) {
|
||||||
|
if (width % size === 0 && width / size <= 16 && width / size >= 1) {
|
||||||
|
cellWidth = size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const size of commonSizes) {
|
||||||
|
if (height % size === 0 && height / size <= 16 && height / size >= 1) {
|
||||||
|
cellHeight = size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { width: cellWidth, height: cellHeight };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isProcessing,
|
||||||
|
previewSprites,
|
||||||
|
splitByGrid,
|
||||||
|
detectSprites,
|
||||||
|
getSuggestedCellSize,
|
||||||
|
cleanup,
|
||||||
|
};
|
||||||
|
}
|
||||||
200
src/composables/useStructuredData.ts
Normal file
200
src/composables/useStructuredData.ts
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import { useHead } from '@vueuse/head';
|
||||||
|
|
||||||
|
const SITE_URL = 'https://spritesheetgenerator.online';
|
||||||
|
const SITE_NAME = 'Spritesheet Generator';
|
||||||
|
|
||||||
|
export interface BlogPostSchema {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
author: string;
|
||||||
|
datePublished: string;
|
||||||
|
dateModified?: string;
|
||||||
|
image: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BreadcrumbItem {
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FAQItem {
|
||||||
|
question: string;
|
||||||
|
answer: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useStructuredData() {
|
||||||
|
// Organization Schema
|
||||||
|
const addOrganizationSchema = () => {
|
||||||
|
const schema = {
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'Organization',
|
||||||
|
name: SITE_NAME,
|
||||||
|
url: SITE_URL,
|
||||||
|
logo: `${SITE_URL}/og-image.png`,
|
||||||
|
description: 'Free online tool to create spritesheets for game development',
|
||||||
|
sameAs: ['https://gitea.adhd.sh/root/spritesheet-generator', 'https://discord.gg/JTev3nzeDa'],
|
||||||
|
};
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
script: [
|
||||||
|
{
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify(schema),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// WebSite Schema
|
||||||
|
const addWebSiteSchema = () => {
|
||||||
|
const schema = {
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'WebSite',
|
||||||
|
name: SITE_NAME,
|
||||||
|
url: SITE_URL,
|
||||||
|
description: 'Create professional spritesheets for your game development projects',
|
||||||
|
potentialAction: {
|
||||||
|
'@type': 'SearchAction',
|
||||||
|
target: `${SITE_URL}/blog?search={search_term_string}`,
|
||||||
|
'query-input': 'required name=search_term_string',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
script: [
|
||||||
|
{
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify(schema),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// BlogPosting Schema
|
||||||
|
const addBlogPostSchema = (post: BlogPostSchema) => {
|
||||||
|
const schema = {
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'BlogPosting',
|
||||||
|
headline: post.title,
|
||||||
|
description: post.description,
|
||||||
|
image: `${SITE_URL}${post.image}`,
|
||||||
|
author: {
|
||||||
|
'@type': 'Person',
|
||||||
|
name: post.author,
|
||||||
|
},
|
||||||
|
publisher: {
|
||||||
|
'@type': 'Organization',
|
||||||
|
name: SITE_NAME,
|
||||||
|
logo: {
|
||||||
|
'@type': 'ImageObject',
|
||||||
|
url: `${SITE_URL}/og-image.png`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
datePublished: post.datePublished,
|
||||||
|
dateModified: post.dateModified || post.datePublished,
|
||||||
|
mainEntityOfPage: {
|
||||||
|
'@type': 'WebPage',
|
||||||
|
'@id': `${SITE_URL}${post.url}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
script: [
|
||||||
|
{
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify(schema),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Breadcrumb Schema
|
||||||
|
const addBreadcrumbSchema = (items: BreadcrumbItem[]) => {
|
||||||
|
const schema = {
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'BreadcrumbList',
|
||||||
|
itemListElement: items.map((item, index) => ({
|
||||||
|
'@type': 'ListItem',
|
||||||
|
position: index + 1,
|
||||||
|
name: item.name,
|
||||||
|
item: `${SITE_URL}${item.url}`,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
script: [
|
||||||
|
{
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify(schema),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Blog List Schema
|
||||||
|
const addBlogListSchema = (posts: BlogPostSchema[]) => {
|
||||||
|
const schema = {
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'Blog',
|
||||||
|
name: `${SITE_NAME} Blog`,
|
||||||
|
description: 'Latest articles about sprite sheet generation and game development',
|
||||||
|
url: `${SITE_URL}/blog`,
|
||||||
|
blogPost: posts.map(post => ({
|
||||||
|
'@type': 'BlogPosting',
|
||||||
|
headline: post.title,
|
||||||
|
description: post.description,
|
||||||
|
image: `${SITE_URL}${post.image}`,
|
||||||
|
author: {
|
||||||
|
'@type': 'Person',
|
||||||
|
name: post.author,
|
||||||
|
},
|
||||||
|
datePublished: post.datePublished,
|
||||||
|
url: `${SITE_URL}${post.url}`,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
script: [
|
||||||
|
{
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify(schema),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// FAQ Schema
|
||||||
|
const addFAQSchema = (faqs: FAQItem[]) => {
|
||||||
|
const schema = {
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'FAQPage',
|
||||||
|
mainEntity: faqs.map(faq => ({
|
||||||
|
'@type': 'Question',
|
||||||
|
name: faq.question,
|
||||||
|
acceptedAnswer: {
|
||||||
|
'@type': 'Answer',
|
||||||
|
text: faq.answer,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
script: [
|
||||||
|
{
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify(schema),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
addOrganizationSchema,
|
||||||
|
addWebSiteSchema,
|
||||||
|
addBlogPostSchema,
|
||||||
|
addBreadcrumbSchema,
|
||||||
|
addBlogListSchema,
|
||||||
|
addFAQSchema,
|
||||||
|
};
|
||||||
|
}
|
||||||
39
src/composables/useToast.ts
Normal file
39
src/composables/useToast.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
export type ToastType = 'success' | 'error' | 'info' | 'warning';
|
||||||
|
|
||||||
|
export interface Toast {
|
||||||
|
id: string;
|
||||||
|
message: string;
|
||||||
|
type: ToastType;
|
||||||
|
duration?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const toasts = ref<Toast[]>([]);
|
||||||
|
|
||||||
|
export function useToast() {
|
||||||
|
const addToast = (message: string, type: ToastType = 'info', duration: number = 3000) => {
|
||||||
|
const id = Date.now().toString(36) + Math.random().toString(36).substr(2);
|
||||||
|
const toast: Toast = { id, message, type, duration };
|
||||||
|
toasts.value.push(toast);
|
||||||
|
|
||||||
|
if (duration > 0) {
|
||||||
|
setTimeout(() => {
|
||||||
|
removeToast(id);
|
||||||
|
}, duration);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeToast = (id: string) => {
|
||||||
|
const index = toasts.value.findIndex(t => t.id === id);
|
||||||
|
if (index !== -1) {
|
||||||
|
toasts.value.splice(index, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
toasts,
|
||||||
|
addToast,
|
||||||
|
removeToast,
|
||||||
|
};
|
||||||
|
}
|
||||||
10
src/main.ts
10
src/main.ts
@@ -1,11 +1,21 @@
|
|||||||
|
import { Buffer } from 'buffer';
|
||||||
|
// @ts-ignore
|
||||||
|
window.Buffer = Buffer;
|
||||||
|
|
||||||
import './assets/main.css';
|
import './assets/main.css';
|
||||||
|
|
||||||
import { createApp } from 'vue';
|
import { createApp } from 'vue';
|
||||||
import { createPinia } from 'pinia';
|
import { createPinia } from 'pinia';
|
||||||
|
import { createHead } from '@vueuse/head';
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
|
|
||||||
|
import router from './router';
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
const head = createHead();
|
||||||
|
|
||||||
app.use(createPinia());
|
app.use(createPinia());
|
||||||
|
app.use(router);
|
||||||
|
app.use(head);
|
||||||
|
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|||||||
62
src/router/index.ts
Normal file
62
src/router/index.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
|
import HomeView from '../views/HomeView.vue';
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'home',
|
||||||
|
component: HomeView,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/about',
|
||||||
|
name: 'about',
|
||||||
|
component: () => import('../views/AboutUs.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/contact',
|
||||||
|
name: 'contact',
|
||||||
|
component: () => import('../views/Contact.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/privacy-policy',
|
||||||
|
name: 'privacy-policy',
|
||||||
|
component: () => import('../views/PrivacyPolicy.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/faq',
|
||||||
|
name: 'faq',
|
||||||
|
component: () => import('../views/FAQ.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/blog',
|
||||||
|
name: 'blog-overview',
|
||||||
|
component: () => import('../views/BlogOverview.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/blog/:slug',
|
||||||
|
name: 'blog-detail',
|
||||||
|
component: () => import('../views/BlogDetail.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/share/:id',
|
||||||
|
name: 'share',
|
||||||
|
component: () => import('../views/ShareView.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/editor/:id?',
|
||||||
|
name: 'editor',
|
||||||
|
component: () => import('../views/EditorView.vue'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
scrollBehavior(to, from, savedPosition) {
|
||||||
|
if (savedPosition) {
|
||||||
|
return savedPosition;
|
||||||
|
} else {
|
||||||
|
return { top: 0 };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
39
src/stores/useAuthStore.ts
Normal file
39
src/stores/useAuthStore.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import PocketBase from 'pocketbase';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
|
const pb = new PocketBase(import.meta.env.VITE_POCKETBASE_URL);
|
||||||
|
const user = ref(pb.authStore.model);
|
||||||
|
|
||||||
|
// Sync user state on change
|
||||||
|
pb.authStore.onChange(() => {
|
||||||
|
user.value = pb.authStore.model;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function login(email: string, password: string) {
|
||||||
|
await pb.collection('users').authWithPassword(email, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function register(email: string, password: string, passwordConfirm: string) {
|
||||||
|
await pb.collection('users').create({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
passwordConfirm,
|
||||||
|
});
|
||||||
|
// Auto login after register
|
||||||
|
await login(email, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
pb.authStore.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
pb,
|
||||||
|
user,
|
||||||
|
login,
|
||||||
|
register,
|
||||||
|
logout,
|
||||||
|
};
|
||||||
|
});
|
||||||
136
src/stores/useProjectStore.ts
Normal file
136
src/stores/useProjectStore.ts
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useAuthStore } from './useAuthStore';
|
||||||
|
|
||||||
|
export interface Project {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
data: any; // Store the JSON export of the project here
|
||||||
|
created: string;
|
||||||
|
updated: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useProjectStore = defineStore('project', () => {
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
const projects = ref<Project[]>([]);
|
||||||
|
const currentProject = ref<Project | null>(null);
|
||||||
|
const isLoading = ref(false);
|
||||||
|
|
||||||
|
async function fetchProjects() {
|
||||||
|
if (!authStore.user) return;
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
const records = await authStore.pb.collection('projects').getList(1, 50, {
|
||||||
|
sort: '-updated',
|
||||||
|
});
|
||||||
|
projects.value = records.items.map((r: any) => ({
|
||||||
|
id: r.id,
|
||||||
|
name: r.name,
|
||||||
|
data: r.data,
|
||||||
|
created: r.created,
|
||||||
|
updated: r.updated,
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch projects:', error);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createProject(name: string, data: any) {
|
||||||
|
if (!authStore.user) return;
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
const record = await authStore.pb.collection('projects').create({
|
||||||
|
name,
|
||||||
|
data,
|
||||||
|
user: authStore.user.id,
|
||||||
|
});
|
||||||
|
currentProject.value = {
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
data: record.data,
|
||||||
|
created: record.created,
|
||||||
|
updated: record.updated,
|
||||||
|
};
|
||||||
|
await fetchProjects();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to create project:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateProject(id: string, name: string, data: any) {
|
||||||
|
if (!authStore.user) return;
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
const record = await authStore.pb.collection('projects').update(id, {
|
||||||
|
name,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
currentProject.value = {
|
||||||
|
...currentProject.value!,
|
||||||
|
name: record.name,
|
||||||
|
data: record.data,
|
||||||
|
updated: record.updated,
|
||||||
|
};
|
||||||
|
await fetchProjects();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to update project:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadProject(id: string) {
|
||||||
|
if (!authStore.user) return;
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
const record = await authStore.pb.collection('projects').getOne(id);
|
||||||
|
currentProject.value = {
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
data: record.data,
|
||||||
|
created: record.created,
|
||||||
|
updated: record.updated,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load project', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteProject(id: string) {
|
||||||
|
if (!authStore.user) return;
|
||||||
|
if (!confirm('Are you sure you want to delete this project?')) return;
|
||||||
|
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
await authStore.pb.collection('projects').delete(id);
|
||||||
|
if (currentProject.value?.id === id) {
|
||||||
|
currentProject.value = null;
|
||||||
|
}
|
||||||
|
await fetchProjects();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to delete project:', error);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
projects,
|
||||||
|
currentProject,
|
||||||
|
isLoading,
|
||||||
|
fetchProjects,
|
||||||
|
createProject,
|
||||||
|
updateProject,
|
||||||
|
loadProject,
|
||||||
|
deleteProject,
|
||||||
|
};
|
||||||
|
});
|
||||||
@@ -5,6 +5,10 @@ const pixelPerfect = ref(true);
|
|||||||
const darkMode = ref(false);
|
const darkMode = ref(false);
|
||||||
const negativeSpacingEnabled = ref(false);
|
const negativeSpacingEnabled = ref(false);
|
||||||
const backgroundColor = ref('transparent');
|
const backgroundColor = ref('transparent');
|
||||||
|
const manualCellSizeEnabled = ref(false);
|
||||||
|
const manualCellWidth = ref(64);
|
||||||
|
const manualCellHeight = ref(64);
|
||||||
|
const checkerboardEnabled = ref(false);
|
||||||
|
|
||||||
// Initialize dark mode from localStorage or system preference
|
// Initialize dark mode from localStorage or system preference
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
@@ -61,16 +65,46 @@ export const useSettingsStore = defineStore('settings', () => {
|
|||||||
backgroundColor.value = color;
|
backgroundColor.value = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleManualCellSize() {
|
||||||
|
manualCellSizeEnabled.value = !manualCellSizeEnabled.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setManualCellWidth(width: number) {
|
||||||
|
manualCellWidth.value = Math.max(1, Math.floor(width));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setManualCellHeight(height: number) {
|
||||||
|
manualCellHeight.value = Math.max(1, Math.floor(height));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setManualCellSize(width: number, height: number) {
|
||||||
|
setManualCellWidth(width);
|
||||||
|
setManualCellHeight(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleCheckerboard() {
|
||||||
|
checkerboardEnabled.value = !checkerboardEnabled.value;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pixelPerfect,
|
pixelPerfect,
|
||||||
darkMode,
|
darkMode,
|
||||||
negativeSpacingEnabled,
|
negativeSpacingEnabled,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
|
manualCellSizeEnabled,
|
||||||
|
manualCellWidth,
|
||||||
|
manualCellHeight,
|
||||||
|
checkerboardEnabled,
|
||||||
togglePixelPerfect,
|
togglePixelPerfect,
|
||||||
setPixelPerfect,
|
setPixelPerfect,
|
||||||
toggleDarkMode,
|
toggleDarkMode,
|
||||||
setDarkMode,
|
setDarkMode,
|
||||||
toggleNegativeSpacing,
|
toggleNegativeSpacing,
|
||||||
setBackgroundColor,
|
setBackgroundColor,
|
||||||
|
toggleManualCellSize,
|
||||||
|
setManualCellWidth,
|
||||||
|
setManualCellHeight,
|
||||||
|
setManualCellSize,
|
||||||
|
toggleCheckerboard,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ export interface Sprite {
|
|||||||
height: number;
|
height: number;
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
rotation: number;
|
||||||
|
flipX: boolean;
|
||||||
|
flipY: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SpriteFile {
|
export interface SpriteFile {
|
||||||
|
|||||||
54
src/types/spritesheet.ts
Normal file
54
src/types/spritesheet.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* Spritesheet splitting types
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** A detected sprite region with bounds and position */
|
||||||
|
export interface SpriteRegion {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
pixelCount?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A sprite preview with data URL for display */
|
||||||
|
export interface SpritePreview {
|
||||||
|
url: string;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
isEmpty: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Detection mode for sprite splitting */
|
||||||
|
export type DetectionMode = 'grid' | 'auto';
|
||||||
|
|
||||||
|
/** Options for grid-based splitting */
|
||||||
|
export interface GridSplitOptions {
|
||||||
|
cellWidth: number;
|
||||||
|
cellHeight: number;
|
||||||
|
preserveCellSize: boolean;
|
||||||
|
removeEmpty: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Options for auto-detection splitting */
|
||||||
|
export interface AutoDetectOptions {
|
||||||
|
sensitivity: number;
|
||||||
|
removeEmpty: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Worker message for irregular sprite detection */
|
||||||
|
export interface SpriteWorkerMessage {
|
||||||
|
type: 'detectIrregularSprites';
|
||||||
|
imageData: ImageData;
|
||||||
|
sensitivity: number;
|
||||||
|
maxSize?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Worker response with detected sprites */
|
||||||
|
export interface SpriteWorkerResponse {
|
||||||
|
type: 'spritesDetected';
|
||||||
|
sprites: SpriteRegion[];
|
||||||
|
backgroundColor: [number, number, number, number];
|
||||||
|
}
|
||||||
38
src/views/AboutUs.vue
Normal file
38
src/views/AboutUs.vue
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useSEO } from '../composables/useSEO';
|
||||||
|
import { useStructuredData } from '../composables/useStructuredData';
|
||||||
|
|
||||||
|
const { addBreadcrumbSchema } = useStructuredData();
|
||||||
|
|
||||||
|
// Set SEO synchronously
|
||||||
|
useSEO({
|
||||||
|
title: 'About Us - Our Mission & Story',
|
||||||
|
description: 'Learn about Spritesheet Generator, a free tool designed to help game developers and artists streamline their workflow with optimized spritesheet creation.',
|
||||||
|
url: '/about',
|
||||||
|
type: 'website',
|
||||||
|
keywords: 'about spritesheet generator, game development tools, open source sprite editor',
|
||||||
|
});
|
||||||
|
|
||||||
|
addBreadcrumbSchema([
|
||||||
|
{ name: 'Home', url: '/' },
|
||||||
|
{ name: 'About Us', url: '/about' },
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="glass-panel rounded-3xl shadow-2xl p-8 sm:p-12">
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-extrabold text-gray-900 dark:text-white mb-6">About Us</h1>
|
||||||
|
<div class="space-y-6">
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">Welcome to Spritesheet Generator, a tool designed to help game developers and artists streamline their workflow.</p>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">
|
||||||
|
Our mission is to provide a simple, powerful, and free tool for creating optimized spritesheets directly in your browser. Whether you are an indie developer, a hobbyist, or part of a large studio, we hope this tool makes your life easier.
|
||||||
|
</p>
|
||||||
|
<div class="space-y-3">
|
||||||
|
<h3 class="text-xl font-bold text-gray-900 dark:text-white">Our story</h3>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">This project started as a small utility for personal game jams and has grown into a full-featured spritesheet packer. We believe in open source and community-driven development.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
221
src/views/BlogDetail.vue
Normal file
221
src/views/BlogDetail.vue
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted, computed, watch } from 'vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import { useBlog, type BlogPost } from '../composables/useBlog';
|
||||||
|
import { useHead } from '@vueuse/head';
|
||||||
|
import { marked } from 'marked';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
|
const { getPost } = useBlog();
|
||||||
|
const post = ref<BlogPost | undefined>(undefined);
|
||||||
|
const renderedContent = ref('');
|
||||||
|
|
||||||
|
const slug = computed(() => route.params.slug as string);
|
||||||
|
|
||||||
|
// Reactive SEO data that updates when post loads
|
||||||
|
const pageTitle = computed(() => (post.value ? `${post.value.title} - Spritesheet Generator` : 'Blog Post - Spritesheet Generator'));
|
||||||
|
|
||||||
|
const pageDescription = computed(() => post.value?.description || 'Read our latest article about spritesheet generation and game development.');
|
||||||
|
|
||||||
|
const pageImage = computed(() => (post.value?.image ? `https://spritesheetgenerator.online${post.value.image}` : 'https://spritesheetgenerator.online/og-image.png'));
|
||||||
|
|
||||||
|
const pageUrl = computed(() => `https://spritesheetgenerator.online/blog/${slug.value}`);
|
||||||
|
|
||||||
|
const keywords = computed(() => post.value?.keywords || 'sprite sheet, game development, blog');
|
||||||
|
|
||||||
|
// Dynamic meta tags using reactive computed values
|
||||||
|
useHead({
|
||||||
|
title: pageTitle,
|
||||||
|
meta: [
|
||||||
|
{ name: 'title', content: pageTitle },
|
||||||
|
{ name: 'description', content: pageDescription },
|
||||||
|
{ name: 'keywords', content: keywords },
|
||||||
|
{ name: 'robots', content: 'index, follow' },
|
||||||
|
|
||||||
|
// Open Graph
|
||||||
|
{ property: 'og:type', content: 'article' },
|
||||||
|
{ property: 'og:url', content: pageUrl },
|
||||||
|
{ property: 'og:title', content: pageTitle },
|
||||||
|
{ property: 'og:description', content: pageDescription },
|
||||||
|
{ property: 'og:image', content: pageImage },
|
||||||
|
{ property: 'og:site_name', content: 'Spritesheet Generator' },
|
||||||
|
{ property: 'article:author', content: computed(() => post.value?.author || 'streetshadow') },
|
||||||
|
{ property: 'article:published_time', content: computed(() => post.value?.date || '') },
|
||||||
|
|
||||||
|
// Twitter
|
||||||
|
{ name: 'twitter:card', content: 'summary_large_image' },
|
||||||
|
{ name: 'twitter:url', content: pageUrl },
|
||||||
|
{ name: 'twitter:title', content: pageTitle },
|
||||||
|
{ name: 'twitter:description', content: pageDescription },
|
||||||
|
{ name: 'twitter:image', content: pageImage },
|
||||||
|
],
|
||||||
|
link: [{ rel: 'canonical', href: pageUrl }],
|
||||||
|
script: computed(() => {
|
||||||
|
const scripts = [];
|
||||||
|
|
||||||
|
// Breadcrumb schema
|
||||||
|
scripts.push({
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify({
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'BreadcrumbList',
|
||||||
|
itemListElement: [
|
||||||
|
{
|
||||||
|
'@type': 'ListItem',
|
||||||
|
position: 1,
|
||||||
|
name: 'Home',
|
||||||
|
item: 'https://spritesheetgenerator.online/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'@type': 'ListItem',
|
||||||
|
position: 2,
|
||||||
|
name: 'Blog',
|
||||||
|
item: 'https://spritesheetgenerator.online/blog',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'@type': 'ListItem',
|
||||||
|
position: 3,
|
||||||
|
name: post.value?.title || 'Article',
|
||||||
|
item: pageUrl.value,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Blog post schema
|
||||||
|
if (post.value) {
|
||||||
|
scripts.push({
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify({
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'BlogPosting',
|
||||||
|
headline: post.value.title,
|
||||||
|
description: post.value.description,
|
||||||
|
image: `https://spritesheetgenerator.online${post.value.image}`,
|
||||||
|
author: {
|
||||||
|
'@type': 'Person',
|
||||||
|
name: post.value.author || 'streetshadow',
|
||||||
|
},
|
||||||
|
publisher: {
|
||||||
|
'@type': 'Organization',
|
||||||
|
name: 'Spritesheet Generator',
|
||||||
|
logo: {
|
||||||
|
'@type': 'ImageObject',
|
||||||
|
url: 'https://spritesheetgenerator.online/og-image.png',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
datePublished: post.value.date,
|
||||||
|
dateModified: post.value.date,
|
||||||
|
mainEntityOfPage: {
|
||||||
|
'@type': 'WebPage',
|
||||||
|
'@id': pageUrl.value,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return scripts;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
post.value = await getPost(slug.value);
|
||||||
|
|
||||||
|
if (post.value) {
|
||||||
|
renderedContent.value = await marked(post.value.content);
|
||||||
|
} else {
|
||||||
|
router.push({ name: 'blog-overview' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full">
|
||||||
|
<div v-if="post" class="glass-panel rounded-3xl shadow-2xl p-8 sm:p-12">
|
||||||
|
<RouterLink :to="{ name: 'blog-overview' }" class="inline-flex items-center text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white mb-6 transition-colors" title="Return to blog overview" aria-label="Navigate back to blog overview page">
|
||||||
|
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
||||||
|
</svg>
|
||||||
|
Back to overview
|
||||||
|
</RouterLink>
|
||||||
|
|
||||||
|
<div class="mb-10 sm:mb-12 max-w-3xl">
|
||||||
|
<div class="flex items-center gap-3 text-sm text-gray-500 dark:text-gray-400 mb-6 font-medium">
|
||||||
|
<time :datetime="post.date">
|
||||||
|
{{ new Date(post.date).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) }}
|
||||||
|
</time>
|
||||||
|
<span class="w-1 h-1 rounded-full bg-gray-300 dark:bg-gray-600"></span>
|
||||||
|
<span v-if="post.author">
|
||||||
|
{{ post.author }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1 class="text-3xl sm:text-5xl font-bold tracking-tight text-gray-900 dark:text-white leading-tight">
|
||||||
|
{{ post.title }}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Image is intentionally omitted here as per requirements -->
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="markdown-content prose prose-lg dark:prose-invert max-w-none prose-headings:font-bold prose-headings:tracking-tight prose-headings:text-gray-900 dark:prose-headings:text-gray-100 prose-p:leading-relaxed prose-a:text-primary-600 prose-a:no-underline prose-a:border-b prose-a:border-primary-300 hover:prose-a:border-primary-600 prose-a:transition-colors prose-blockquote:not-italic prose-blockquote:font-normal prose-blockquote:text-gray-600 dark:prose-blockquote:text-gray-300 prose-blockquote:border-l-4 prose-blockquote:border-primary-500 prose-blockquote:bg-gray-50 dark:prose-blockquote:bg-gray-800/30 prose-blockquote:rounded-r prose-code:text-primary-700 dark:prose-code:text-primary-300 prose-code:bg-primary-50 dark:prose-code:bg-primary-900/30 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:before:content-none prose-code:after:content-none prose-code:font-mono prose-code:text-sm prose-pre:bg-gray-900 prose-pre:text-gray-200 prose-pre:shadow-lg prose-pre:rounded-xl prose-img:rounded-xl prose-img:shadow-lg prose-img:border prose-img:border-gray-200 dark:prose-img:border-gray-700 prose-hr:border-gray-200 dark:prose-hr:border-gray-800 prose-li:marker:text-primary-500"
|
||||||
|
v-html="renderedContent"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="text-center py-12">
|
||||||
|
<p class="text-xl text-gray-600 dark:text-gray-400">Loading...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
/* Force spacing for markdown content since prose modifiers can be overridden */
|
||||||
|
.markdown-content :deep(p) {
|
||||||
|
margin-top: 1.5em;
|
||||||
|
margin-bottom: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(h2),
|
||||||
|
.markdown-content :deep(h3),
|
||||||
|
.markdown-content :deep(h4) {
|
||||||
|
margin-top: 2em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(img) {
|
||||||
|
margin-top: 2.5em;
|
||||||
|
margin-bottom: 2.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(ul),
|
||||||
|
.markdown-content :deep(ol) {
|
||||||
|
margin-top: 1.5em;
|
||||||
|
margin-bottom: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(li) {
|
||||||
|
margin-top: 0.5em;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(blockquote) {
|
||||||
|
margin-top: 2em;
|
||||||
|
margin-bottom: 2em;
|
||||||
|
padding-top: 1em;
|
||||||
|
padding-bottom: 1em;
|
||||||
|
padding-left: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(pre) {
|
||||||
|
margin-top: 2em;
|
||||||
|
margin-bottom: 2em;
|
||||||
|
padding: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(hr) {
|
||||||
|
margin-top: 3em;
|
||||||
|
margin-bottom: 3em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
48
src/views/BlogOverview.vue
Normal file
48
src/views/BlogOverview.vue
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted } from 'vue';
|
||||||
|
import { useBlog, type BlogPost } from '../composables/useBlog';
|
||||||
|
import { useSEO } from '../composables/useSEO';
|
||||||
|
import { useStructuredData } from '../composables/useStructuredData';
|
||||||
|
import { RouterLink } from 'vue-router';
|
||||||
|
|
||||||
|
const { getPosts } = useBlog();
|
||||||
|
const { addBreadcrumbSchema } = useStructuredData();
|
||||||
|
const posts = ref<BlogPost[]>([]);
|
||||||
|
|
||||||
|
// Set SEO meta tags synchronously
|
||||||
|
useSEO({
|
||||||
|
title: 'Blog - Latest Articles on Spritesheet Generation',
|
||||||
|
description: 'Explore our latest articles about sprite sheet generation, game development, pixel art, and sprite animation techniques.',
|
||||||
|
url: '/blog',
|
||||||
|
type: 'website',
|
||||||
|
keywords: 'sprite sheet blog, game development articles, pixel art tutorials, sprite animation',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add breadcrumb synchronously
|
||||||
|
addBreadcrumbSchema([
|
||||||
|
{ name: 'Home', url: '/' },
|
||||||
|
{ name: 'Blog', url: '/blog' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
posts.value = await getPosts();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full">
|
||||||
|
<h1 class="text-4xl font-bold mb-8 text-gray-900 dark:text-white">Blog</h1>
|
||||||
|
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
|
<article v-for="post in posts" :key="post.slug" class="glass-panel overflow-hidden hover:shadow-xl transition-all duration-300 flex flex-col h-full group border-0 ring-1 ring-gray-200 dark:ring-gray-700">
|
||||||
|
<RouterLink :to="{ name: 'blog-detail', params: { slug: post.slug } }" class="flex flex-col h-full" :title="`Read more: ${post.title}`" :aria-label="`Read full blog post: ${post.title}`">
|
||||||
|
<img :src="post.image" :alt="post.title" class="w-full h-48 object-cover" loading="lazy" decoding="async" />
|
||||||
|
<div class="p-6 flex-1 flex flex-col">
|
||||||
|
<h2 class="text-xl font-bold mb-2 text-gray-900 dark:text-white line-clamp-2">{{ post.title }}</h2>
|
||||||
|
<p class="text-gray-600 dark:text-gray-400 text-xs mb-3">{{ post.date }}</p>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 text-sm line-clamp-3 flex-1">{{ post.description }}</p>
|
||||||
|
</div>
|
||||||
|
</RouterLink>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
62
src/views/Contact.vue
Normal file
62
src/views/Contact.vue
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useSEO } from '../composables/useSEO';
|
||||||
|
import { useStructuredData } from '../composables/useStructuredData';
|
||||||
|
|
||||||
|
const { addBreadcrumbSchema } = useStructuredData();
|
||||||
|
|
||||||
|
// Set SEO synchronously
|
||||||
|
useSEO({
|
||||||
|
title: 'Contact Us - Get in Touch',
|
||||||
|
description: "Contact the Spritesheet Generator team. Join our Discord community or report bugs and contribute on Gitea. We'd love to hear from you!",
|
||||||
|
url: '/contact',
|
||||||
|
type: 'website',
|
||||||
|
keywords: 'contact spritesheet generator, support, discord, gitea',
|
||||||
|
});
|
||||||
|
|
||||||
|
addBreadcrumbSchema([
|
||||||
|
{ name: 'Home', url: '/' },
|
||||||
|
{ name: 'Contact', url: '/contact' },
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="glass-panel rounded-3xl shadow-2xl p-8 sm:p-12">
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-extrabold text-gray-900 dark:text-white mb-6">Contact Us</h1>
|
||||||
|
<div class="space-y-6">
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">We'd love to hear from you! Whether you have a question, feedback, or just want to say hi, feel free to reach out.</p>
|
||||||
|
<div class="flex flex-col gap-4 mt-8">
|
||||||
|
<a
|
||||||
|
href="https://discord.gg/JTev3nzeDa"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="flex items-center gap-3 p-4 bg-gray-100 dark:bg-gray-800 rounded-xl hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors no-underline"
|
||||||
|
title="Join our Discord community"
|
||||||
|
aria-label="Join Discord server"
|
||||||
|
>
|
||||||
|
<i class="fab fa-discord text-2xl text-[#5865F2]"></i>
|
||||||
|
<div>
|
||||||
|
<div class="font-bold text-gray-900 dark:text-white">Join our Discord</div>
|
||||||
|
<div class="text-sm text-gray-600 dark:text-gray-400">Chat with the community and developers</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://gitea.adhd.sh/root/spritesheet-generator"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="flex items-center gap-3 p-4 bg-gray-100 dark:bg-gray-800 rounded-xl hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors no-underline"
|
||||||
|
title="View source code and report bugs"
|
||||||
|
aria-label="View source code repository"
|
||||||
|
>
|
||||||
|
<i class="fab fa-github text-2xl text-gray-900 dark:text-white"></i>
|
||||||
|
<div>
|
||||||
|
<div class="font-bold text-gray-900 dark:text-white">Source Code</div>
|
||||||
|
<div class="text-sm text-gray-600 dark:text-gray-400">Report bugs or contribute on Gitea</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
670
src/views/EditorView.vue
Normal file
670
src/views/EditorView.vue
Normal file
@@ -0,0 +1,670 @@
|
|||||||
|
<template>
|
||||||
|
<main class="flex flex-col flex-1 h-full min-h-0 relative">
|
||||||
|
<!-- Main Editor Interface -->
|
||||||
|
<div class="flex flex-col lg:flex-row gap-6 h-full min-h-[600px] lg:overflow-hidden">
|
||||||
|
<!-- Sidebar Controls -->
|
||||||
|
<aside class="flex flex-col w-full lg:w-[340px] gap-4 shrink-0 lg:overflow-hidden">
|
||||||
|
<div class="glass-panel rounded-xl flex flex-col h-full lg:overflow-hidden border border-gray-200 dark:border-gray-700/60 shadow-lg">
|
||||||
|
<!-- Sidebar Header -->
|
||||||
|
<div class="px-5 py-4 border-b border-gray-200/50 dark:border-gray-700/50 flex items-center justify-between shrink-0 bg-gray-50/50 dark:bg-gray-800/10">
|
||||||
|
<h2 class="text-sm font-bold uppercase tracking-wider text-gray-500 dark:text-gray-400">Editor Tools</h2>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<button @click="closeProject" class="btn btn-secondary btn-sm w-8 h-8 p-0 justify-center border-gray-200 dark:border-gray-700 hover:bg-red-50 hover:text-red-500 dark:hover:bg-red-900/20 dark:hover:text-red-400 dark:text-gray-400" title="Close Project">
|
||||||
|
<i class="fas fa-times"></i>
|
||||||
|
</button>
|
||||||
|
<button @click="openFileDialog" class="btn btn-primary btn-sm shadow-indigo-500/20" title="Add more sprites"><i class="fas fa-plus mr-1"></i> Add</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Scrollable Content -->
|
||||||
|
<div class="flex-1 overflow-y-auto overflow-x-hidden p-5 space-y-6 scrollbar-thin">
|
||||||
|
<!-- Layers -->
|
||||||
|
<section>
|
||||||
|
<div class="flex items-center justify-between mb-3">
|
||||||
|
<h3 class="text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide">Layers</h3>
|
||||||
|
<button @click="addLayer()" class="text-xs p-1 text-indigo-600 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-900/20 rounded transition-colors" title="Add Layer"><i class="fas fa-layer-group mr-1"></i> New</button>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<div
|
||||||
|
v-for="layer in layers"
|
||||||
|
:key="layer.id"
|
||||||
|
class="group flex items-center gap-2 p-2 rounded-lg border transition-all duration-200"
|
||||||
|
:class="activeLayerId === layer.id ? 'bg-white dark:bg-gray-800 border-indigo-500 ring-1 ring-indigo-500 shadow-sm' : 'bg-gray-50 dark:bg-gray-800/40 border-transparent hover:border-gray-200 dark:hover:border-gray-700'"
|
||||||
|
>
|
||||||
|
<!-- Visibility Toggle -->
|
||||||
|
<button @click.stop="layer.visible = !layer.visible" class="w-6 h-6 flex items-center justify-center rounded text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors">
|
||||||
|
<i :class="layer.visible ? 'fas fa-eye' : 'fas fa-eye-slash'" class="text-xs"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Layer Name -->
|
||||||
|
<div class="flex-1 min-w-0">
|
||||||
|
<input
|
||||||
|
v-if="editingLayerId === layer.id"
|
||||||
|
v-model="editingLayerName"
|
||||||
|
@blur="finishEditingLayer"
|
||||||
|
@keyup.enter="finishEditingLayer"
|
||||||
|
@keyup.esc="cancelEditingLayer"
|
||||||
|
ref="layerNameInput"
|
||||||
|
class="w-full text-sm bg-transparent border-b border-indigo-500 outline-none p-0 text-gray-900 dark:text-gray-100"
|
||||||
|
/>
|
||||||
|
<button v-else @click="activeLayerId = layer.id" class="w-full text-left text-sm font-medium truncate" :class="activeLayerId === layer.id ? 'text-gray-900 dark:text-gray-100' : 'text-gray-600 dark:text-gray-400'">
|
||||||
|
{{ layer.name }} <span class="text-xs opacity-50 font-normal ml-1">({{ layer.sprites.length }})</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Actions -->
|
||||||
|
<div class="flex items-center opacity-0 group-hover:opacity-100 transition-opacity">
|
||||||
|
<button @click="startEditingLayer(layer.id, layer.name)" class="p-1.5 text-gray-400 hover:text-indigo-500 transition-colors" title="Rename"><i class="fas fa-pen text-[10px]"></i></button>
|
||||||
|
<button @click="moveLayer(layer.id, 'up')" class="p-1.5 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors" title="Move Up"><i class="fas fa-chevron-up text-[10px]"></i></button>
|
||||||
|
<button @click="moveLayer(layer.id, 'down')" class="p-1.5 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors" title="Move Down"><i class="fas fa-chevron-down text-[10px]"></i></button>
|
||||||
|
<button v-if="layers.length > 1" @click="removeLayer(layer.id)" class="p-1.5 text-gray-400 hover:text-red-500 transition-colors" title="Delete"><i class="fas fa-trash text-[10px]"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Alignment Tools (Always visible) -->
|
||||||
|
<section>
|
||||||
|
<h3 class="text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-3">Alignment</h3>
|
||||||
|
<div class="card p-2 bg-gray-50/50 dark:bg-gray-800/40 grid grid-cols-3 gap-2">
|
||||||
|
<Tooltip text="Align sprites to the left edge">
|
||||||
|
<button @click="alignSprites('left')" class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"><i class="fas fa-arrow-left"></i>Left</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Center sprites horizontally">
|
||||||
|
<button @click="alignSprites('center')" class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"><i class="fas fa-arrows-left-right"></i>Center</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Align sprites to the right edge">
|
||||||
|
<button @click="alignSprites('right')" class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"><i class="fas fa-arrow-right"></i>Right</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Align sprites to the top edge">
|
||||||
|
<button @click="alignSprites('top')" class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"><i class="fas fa-arrow-up"></i>Top</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Center sprites vertically">
|
||||||
|
<button @click="alignSprites('middle')" class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"><i class="fas fa-arrows-up-down"></i>Middle</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Align sprites to the bottom edge">
|
||||||
|
<button @click="alignSprites('bottom')" class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"><i class="fas fa-arrow-down"></i>Bottom</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Canvas Grid Settings (Editor only) -->
|
||||||
|
<section v-if="activeTab === 'canvas'">
|
||||||
|
<h3 class="text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-3">Grid Layout</h3>
|
||||||
|
<div class="card p-3 bg-gray-50/50 dark:bg-gray-800/40 space-y-3">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<label class="text-sm text-gray-600 dark:text-gray-300">Columns</label>
|
||||||
|
<input type="number" v-model.number="columns" min="1" max="20" class="input-field w-16 text-center" />
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<label class="text-sm text-gray-600 dark:text-gray-300">Force Size</label>
|
||||||
|
<input type="checkbox" v-model="settingsStore.manualCellSizeEnabled" class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />
|
||||||
|
</div>
|
||||||
|
<div v-if="settingsStore.manualCellSizeEnabled" class="flex items-center gap-1">
|
||||||
|
<input v-model.number="settingsStore.manualCellWidth" class="input-field w-14 text-center px-1" placeholder="W" />
|
||||||
|
<span class="text-gray-400 text-xs">x</span>
|
||||||
|
<input v-model.number="settingsStore.manualCellHeight" class="input-field w-14 text-center px-1" placeholder="H" />
|
||||||
|
</div>
|
||||||
|
<span v-else class="text-xs font-mono text-gray-400 bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded">{{ cellSize.width }}×{{ cellSize.height }}px</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- View Options (Editor only) -->
|
||||||
|
<section v-if="activeTab === 'canvas'">
|
||||||
|
<h3 class="text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-3">View Options</h3>
|
||||||
|
<div class="card p-2 bg-gray-50/50 dark:bg-gray-800/40 grid grid-cols-2 gap-2">
|
||||||
|
<Tooltip text="Disable anti-aliasing for crisp pixel art rendering">
|
||||||
|
<button
|
||||||
|
@click="settingsStore.pixelPerfect = !settingsStore.pixelPerfect"
|
||||||
|
:class="settingsStore.pixelPerfect ? 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-th mr-2"></i>Pixel
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Show checkerboard background">
|
||||||
|
<button
|
||||||
|
@click="settingsStore.checkerboardEnabled = !settingsStore.checkerboardEnabled"
|
||||||
|
:class="settingsStore.checkerboardEnabled ? 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-chess-board mr-2"></i>Grid
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Show selection borders">
|
||||||
|
<button
|
||||||
|
@click="showActiveBorder = !showActiveBorder"
|
||||||
|
:class="showActiveBorder ? 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-vector-square mr-2"></i>Borders
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Show sprite coordinates">
|
||||||
|
<button
|
||||||
|
@click="showOffsetLabels = !showOffsetLabels"
|
||||||
|
:class="showOffsetLabels ? 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-tag mr-2"></i>Coordinates
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Show frame index number">
|
||||||
|
<button
|
||||||
|
@click="showFrameIds = !showFrameIds"
|
||||||
|
:class="showFrameIds ? 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-hashtag mr-2"></i>Frame IDs
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Compare with ghost overlays">
|
||||||
|
<button
|
||||||
|
@click="showAllSprites = !showAllSprites"
|
||||||
|
:class="showAllSprites ? 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-clone mr-2"></i>Compare
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Tools (Editor only) -->
|
||||||
|
<section v-if="activeTab === 'canvas'">
|
||||||
|
<h3 class="text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-3">Tools</h3>
|
||||||
|
<div class="card p-2 bg-gray-50/50 dark:bg-gray-800/40 space-y-2">
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<Tooltip text="Select multiple sprites" class="flex-1">
|
||||||
|
<button
|
||||||
|
@click="isMultiSelectMode = !isMultiSelectMode"
|
||||||
|
:class="isMultiSelectMode ? 'bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-object-group mr-2"></i>Multi
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip text="Swap cell positions" class="flex-1">
|
||||||
|
<button
|
||||||
|
@click="allowCellSwap = !allowCellSwap"
|
||||||
|
:class="allowCellSwap ? 'bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300' : 'text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700'"
|
||||||
|
class="w-full flex items-center justify-start gap-2 p-2 rounded text-xs font-medium transition-colors"
|
||||||
|
>
|
||||||
|
<i class="fas fa-exchange-alt mr-2"></i>Swap
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between px-2 pt-1 border-t border-gray-100 dark:border-gray-700/50">
|
||||||
|
<span class="text-xs text-gray-600 dark:text-gray-400">Negative Spacing</span>
|
||||||
|
<button
|
||||||
|
@click="settingsStore.negativeSpacingEnabled = !settingsStore.negativeSpacingEnabled"
|
||||||
|
class="relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
|
||||||
|
:class="settingsStore.negativeSpacingEnabled ? 'bg-indigo-600' : 'bg-gray-200 dark:bg-gray-700'"
|
||||||
|
>
|
||||||
|
<span class="inline-block h-3 w-3 transform rounded-full bg-white transition-transform" :class="settingsStore.negativeSpacingEnabled ? 'translate-x-5' : 'translate-x-1'" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Sidebar Footer (Export) -->
|
||||||
|
<div class="p-4 border-t border-gray-200/50 dark:border-gray-700/50 bg-gray-50/50 dark:bg-gray-800/10 space-y-2 shrink-0">
|
||||||
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
<button @click="downloadSpritesheet" class="btn btn-secondary btn-sm justify-start" title="Download PNG"><i class="fas fa-image text-indigo-500 w-4"></i> PNG</button>
|
||||||
|
<button @click="exportSpritesheetJSON" class="btn btn-secondary btn-sm justify-start" title="Download JSON"><i class="fas fa-code text-indigo-500 w-4"></i> JSON</button>
|
||||||
|
<button @click="openGifFpsModal" class="btn btn-secondary btn-sm justify-start" title="Export GIF"><i class="fas fa-film text-pink-500 w-4"></i> GIF</button>
|
||||||
|
<button @click="downloadAsZip" class="btn btn-secondary btn-sm justify-start" title="Download ZIP"><i class="fas fa-file-archive text-yellow-500 w-4"></i> ZIP</button>
|
||||||
|
</div>
|
||||||
|
<button @click="openShareModal" class="btn btn-secondary w-full justify-start"><i class="fas fa-share-alt mr-2 text-indigo-500"></i> Share project</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<!-- Main Canvas Area -->
|
||||||
|
<div class="flex-1 flex flex-col min-h-0 glass-panel rounded-xl border border-gray-200 dark:border-gray-700/60 shadow-lg overflow-hidden">
|
||||||
|
<!-- Tabs / Toolbar -->
|
||||||
|
<div class="flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-gray-50/30 dark:bg-gray-800/20">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div class="flex p-1 bg-gray-100 dark:bg-gray-800 rounded-lg">
|
||||||
|
<button
|
||||||
|
@click="activeTab = 'canvas'"
|
||||||
|
:class="activeTab === 'canvas' ? 'bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 shadow-sm' : 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300'"
|
||||||
|
class="px-4 py-1.5 rounded-md text-sm font-medium transition-all duration-200"
|
||||||
|
>
|
||||||
|
<i class="fas fa-th mr-2"></i>Editor
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
@click="activeTab = 'preview'"
|
||||||
|
:class="activeTab === 'preview' ? 'bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 shadow-sm' : 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300'"
|
||||||
|
class="px-4 py-1.5 rounded-md text-sm font-medium transition-all duration-200"
|
||||||
|
>
|
||||||
|
<i class="fas fa-play mr-2"></i>Preview
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Background Color (Compact) -->
|
||||||
|
<div class="flex items-center gap-2 pl-3 border-l border-gray-200 dark:border-gray-700">
|
||||||
|
<span class="text-xs font-medium text-gray-500 uppercase">Bg</span>
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<select v-model="bgSelectValue" class="text-xs dark:text-gray-300 focus:ring-0 cursor-pointer pr-8">
|
||||||
|
<option value="transparent">None</option>
|
||||||
|
<option value="#ffffff">White</option>
|
||||||
|
<option value="#000000">Black</option>
|
||||||
|
<option value="#f9fafb">Gray</option>
|
||||||
|
<option value="custom">Custom</option>
|
||||||
|
</select>
|
||||||
|
<div v-if="bgSelectValue === 'custom'" class="relative w-5 h-5 rounded-full overflow-hidden border border-gray-300 dark:border-gray-600 shadow-sm">
|
||||||
|
<input type="color" v-model="customColor" @input="updateCustomColor" class="absolute -top-1 -left-1 w-8 h-8 cursor-pointer p-0 border-0 opacity-0" />
|
||||||
|
<div class="w-full h-full" :style="{ backgroundColor: customColor }"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="activeTab === 'canvas'" class="flex items-center gap-2">
|
||||||
|
<div class="flex items-center bg-gray-100 dark:bg-gray-800 rounded-lg p-1">
|
||||||
|
<button @click="zoomOut" class="p-1.5 hover:bg-white dark:hover:bg-gray-700 rounded text-gray-500 transition-colors"><i class="fas fa-minus text-xs"></i></button>
|
||||||
|
<span class="text-xs font-mono w-12 text-center text-gray-600 dark:text-gray-300">{{ Math.round(zoom * 100) }}%</span>
|
||||||
|
<button @click="zoomIn" class="p-1.5 hover:bg-white dark:hover:bg-gray-700 rounded text-gray-500 transition-colors"><i class="fas fa-plus text-xs"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Canvas Content -->
|
||||||
|
<div class="flex-1 overflow-hidden relative bg-white dark:bg-gray-900/50">
|
||||||
|
<!-- Grid Background Pattern -->
|
||||||
|
<div
|
||||||
|
class="absolute inset-0 opacity-5 pointer-events-none bg-gray-500"
|
||||||
|
style="background-image: url('data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%2220%22 height=%2220%22><circle cx=%2210%22 cy=%2210%22 r=%221%22 fill=%22%236b7280%22/></svg>'); background-size: 20px 20px"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<div class="h-full overflow-auto custom-scrollbar p-4">
|
||||||
|
<div v-if="activeTab === 'canvas'" class="h-full flex flex-col justify-center">
|
||||||
|
<sprite-canvas
|
||||||
|
:layers="layers"
|
||||||
|
:active-layer-id="activeLayerId"
|
||||||
|
:columns="columns"
|
||||||
|
:zoom="zoom"
|
||||||
|
:is-multi-select-mode="isMultiSelectMode"
|
||||||
|
:show-active-border="showActiveBorder"
|
||||||
|
:allow-cell-swap="allowCellSwap"
|
||||||
|
:show-all-sprites="showAllSprites"
|
||||||
|
:show-offset-labels="showOffsetLabels"
|
||||||
|
:show-frame-ids="showFrameIds"
|
||||||
|
@update-sprite="updateSpritePosition"
|
||||||
|
@update-sprite-cell="updateSpriteCell"
|
||||||
|
@remove-sprite="removeSprite"
|
||||||
|
@remove-sprites="removeSprites"
|
||||||
|
@replace-sprite="replaceSprite"
|
||||||
|
@add-sprite="addSprite"
|
||||||
|
@rotate-sprite="rotateSprite"
|
||||||
|
@flip-sprite="flipSprite"
|
||||||
|
@copy-sprite-to-frame="copySpriteToFrame"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div v-if="activeTab === 'preview'" class="h-full flex items-center justify-center">
|
||||||
|
<sprite-preview
|
||||||
|
:layers="layers"
|
||||||
|
:active-layer-id="activeLayerId"
|
||||||
|
:columns="columns"
|
||||||
|
@update-sprite="updateSpritePosition"
|
||||||
|
@update-sprite-in-layer="updateSpriteInLayer"
|
||||||
|
@drop-sprite="handleDropSprite"
|
||||||
|
@rotate-sprite="rotateSprite"
|
||||||
|
@flip-sprite="flipSprite"
|
||||||
|
@copy-sprite-to-frame="copySpriteToFrame"
|
||||||
|
@replace-sprite="replaceSprite"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modals & Hidden Inputs -->
|
||||||
|
<SpritesheetSplitter :is-open="isSpritesheetSplitterOpen" :image-url="spritesheetImageUrl" :image-file="spritesheetImageFile" @close="closeSpritesheetSplitter" @split="handleSplitSpritesheet" />
|
||||||
|
<GifFpsModal :is-open="isGifFpsModalOpen" @close="closeGifFpsModal" @confirm="downloadAsGif" :default-fps="10" />
|
||||||
|
<ShareModal :is-open="isShareModalOpen" :share-function="shareFunction" @close="closeShareModal" />
|
||||||
|
|
||||||
|
<input ref="uploadInput" type="file" multiple accept="image/*" class="hidden" @change="handleUploadChange" />
|
||||||
|
<input ref="jsonFileInput" type="file" accept=".json,application/json" class="hidden" @change="handleJSONFileChange" />
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, toRef, computed, watch, nextTick, onMounted } from 'vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import FileUploader from '@/components/FileUploader.vue';
|
||||||
|
import SpriteCanvas from '@/components/SpriteCanvas.vue';
|
||||||
|
import SpritePreview from '@/components/SpritePreview.vue';
|
||||||
|
import SpritesheetSplitter from '@/components/SpritesheetSplitter.vue';
|
||||||
|
import GifFpsModal from '@/components/GifFpsModal.vue';
|
||||||
|
import ShareModal from '@/components/ShareModal.vue';
|
||||||
|
import Tooltip from '@/components/utilities/Tooltip.vue';
|
||||||
|
import { useExportLayers } from '@/composables/useExportLayers';
|
||||||
|
import { useShare } from '@/composables/useShare';
|
||||||
|
import { useLayers } from '@/composables/useLayers';
|
||||||
|
import { getMaxDimensionsAcrossLayers } from '@/composables/useLayers';
|
||||||
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
|
import { calculateNegativeSpacing } from '@/composables/useNegativeSpacing';
|
||||||
|
import { useZoom } from '@/composables/useZoom';
|
||||||
|
import { useProjectManager } from '@/composables/useProjectManager';
|
||||||
|
import { useProjectStore } from '@/stores/useProjectStore';
|
||||||
|
import type { SpriteFile } from '@/types/sprites';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
|
const projectStore = useProjectStore();
|
||||||
|
const { closeProject, loadProjectData } = useProjectManager();
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
const { layers, visibleLayers, activeLayer, activeLayerId, columns, updateSpritePosition, updateSpriteInLayer, updateSpriteCell, removeSprite, removeSprites, replaceSprite, addSprite, processImageFiles, alignSprites, addLayer, removeLayer, moveLayer, rotateSprite, flipSprite, copySpriteToFrame } =
|
||||||
|
useLayers();
|
||||||
|
|
||||||
|
const { downloadSpritesheet, exportSpritesheetJSON, importSpritesheetJSON, downloadAsGif, downloadAsZip } = useExportLayers(
|
||||||
|
layers,
|
||||||
|
columns,
|
||||||
|
toRef(settingsStore, 'negativeSpacingEnabled'),
|
||||||
|
activeLayerId,
|
||||||
|
toRef(settingsStore, 'backgroundColor'),
|
||||||
|
toRef(settingsStore, 'manualCellSizeEnabled'),
|
||||||
|
toRef(settingsStore, 'manualCellWidth'),
|
||||||
|
toRef(settingsStore, 'manualCellHeight')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Zoom Control
|
||||||
|
const {
|
||||||
|
zoom,
|
||||||
|
increase: zoomIn,
|
||||||
|
decrease: zoomOut,
|
||||||
|
reset: resetZoom,
|
||||||
|
} = useZoom({
|
||||||
|
min: 0.5,
|
||||||
|
max: 3,
|
||||||
|
step: 0.25,
|
||||||
|
initial: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
// View Options & Tools
|
||||||
|
const isMultiSelectMode = ref(false);
|
||||||
|
const showActiveBorder = ref(true);
|
||||||
|
const allowCellSwap = ref(false);
|
||||||
|
const showAllSprites = ref(false);
|
||||||
|
const showOffsetLabels = ref(false);
|
||||||
|
const showFrameIds = ref(false);
|
||||||
|
const customColor = ref('#ffffff');
|
||||||
|
const isCustomMode = ref(false);
|
||||||
|
|
||||||
|
// Background Color Logic
|
||||||
|
const presetBgColors = ['transparent', '#ffffff', '#000000', '#f9fafb'] as const;
|
||||||
|
const isHexColor = (val: string) => /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(val);
|
||||||
|
|
||||||
|
if (isHexColor(settingsStore.backgroundColor) && !presetBgColors.includes(settingsStore.backgroundColor as any)) {
|
||||||
|
customColor.value = settingsStore.backgroundColor;
|
||||||
|
isCustomMode.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bgSelectValue = computed<string>({
|
||||||
|
get() {
|
||||||
|
if (isCustomMode.value) return 'custom';
|
||||||
|
const val = settingsStore.backgroundColor;
|
||||||
|
if (presetBgColors.includes(val as any)) return val;
|
||||||
|
if (isHexColor(val)) {
|
||||||
|
customColor.value = val;
|
||||||
|
isCustomMode.value = true;
|
||||||
|
return 'custom';
|
||||||
|
}
|
||||||
|
return 'transparent';
|
||||||
|
},
|
||||||
|
set(v: string) {
|
||||||
|
if (v === 'custom') {
|
||||||
|
isCustomMode.value = true;
|
||||||
|
settingsStore.setBackgroundColor(customColor.value);
|
||||||
|
} else {
|
||||||
|
isCustomMode.value = false;
|
||||||
|
settingsStore.setBackgroundColor(v);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateCustomColor = () => {
|
||||||
|
settingsStore.setBackgroundColor(customColor.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCellSize = () => {
|
||||||
|
if (!visibleLayers.value.length) return { width: 0, height: 0 };
|
||||||
|
if (settingsStore.manualCellSizeEnabled) {
|
||||||
|
return { width: settingsStore.manualCellWidth, height: settingsStore.manualCellHeight };
|
||||||
|
}
|
||||||
|
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers.value);
|
||||||
|
const allSprites = visibleLayers.value.flatMap(l => l.sprites);
|
||||||
|
const negativeSpacing = calculateNegativeSpacing(allSprites, settingsStore.negativeSpacingEnabled);
|
||||||
|
return { width: maxWidth + negativeSpacing, height: maxHeight + negativeSpacing };
|
||||||
|
};
|
||||||
|
|
||||||
|
const cellSize = computed(getCellSize);
|
||||||
|
const activeTab = ref<'canvas' | 'preview'>('canvas');
|
||||||
|
|
||||||
|
const isSpritesheetSplitterOpen = ref(false);
|
||||||
|
const isGifFpsModalOpen = ref(false);
|
||||||
|
const isShareModalOpen = ref(false);
|
||||||
|
|
||||||
|
const uploadInput = ref<HTMLInputElement | null>(null);
|
||||||
|
const jsonFileInput = ref<HTMLInputElement | null>(null);
|
||||||
|
const spritesheetImageUrl = ref('');
|
||||||
|
const spritesheetImageFile = ref<File | null>(null);
|
||||||
|
|
||||||
|
const editingLayerId = ref<string | null>(null);
|
||||||
|
const editingLayerName = ref('');
|
||||||
|
const layerNameInput = ref<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
// Upload Handlers
|
||||||
|
const handleSpritesUpload = async (files: File[]) => {
|
||||||
|
const jsonFile = files.find(file => file.type === 'application/json' || file.name.endsWith('.json'));
|
||||||
|
|
||||||
|
if (jsonFile) {
|
||||||
|
await handleJSONImport(jsonFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.length === 1 && files[0].type.startsWith('image/')) {
|
||||||
|
const file = files[0];
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
if (confirm('This looks like it might be a spritesheet. Would you like to split it into individual sprites?')) {
|
||||||
|
spritesheetImageUrl.value = url;
|
||||||
|
spritesheetImageFile.value = file;
|
||||||
|
isSpritesheetSplitterOpen.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
processImageFiles([file]);
|
||||||
|
};
|
||||||
|
img.onerror = () => {
|
||||||
|
console.error('Failed to load image:', file.name);
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
processImageFiles(files);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleJSONImport = async (jsonFile: File) => {
|
||||||
|
try {
|
||||||
|
await importSpritesheetJSON(jsonFile);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error importing JSON:', error);
|
||||||
|
alert('Failed to import JSON file. Please check the file format.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeSpritesheetSplitter = () => {
|
||||||
|
isSpritesheetSplitterOpen.value = false;
|
||||||
|
if (spritesheetImageUrl.value && spritesheetImageUrl.value.startsWith('blob:')) {
|
||||||
|
try {
|
||||||
|
URL.revokeObjectURL(spritesheetImageUrl.value);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
spritesheetImageUrl.value = '';
|
||||||
|
spritesheetImageFile.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const openGifFpsModal = () => {
|
||||||
|
if (!visibleLayers.value.some(l => l.sprites.length > 0)) {
|
||||||
|
alert('Please upload or import sprites before generating a GIF.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isGifFpsModalOpen.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeGifFpsModal = () => (isGifFpsModalOpen.value = false);
|
||||||
|
|
||||||
|
const { share } = useShare(layers, columns, toRef(settingsStore, 'negativeSpacingEnabled'), toRef(settingsStore, 'backgroundColor'), toRef(settingsStore, 'manualCellSizeEnabled'), toRef(settingsStore, 'manualCellWidth'), toRef(settingsStore, 'manualCellHeight'));
|
||||||
|
const shareFunction = () => share();
|
||||||
|
|
||||||
|
const openShareModal = () => {
|
||||||
|
if (!visibleLayers.value.some(l => l.sprites.length > 0)) {
|
||||||
|
alert('Please upload or import sprites before sharing.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isShareModalOpen.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeShareModal = () => (isShareModalOpen.value = false);
|
||||||
|
|
||||||
|
const handleSplitSpritesheet = (spriteFiles: SpriteFile[]) => {
|
||||||
|
processImageFiles(spriteFiles.map(s => s.file));
|
||||||
|
};
|
||||||
|
|
||||||
|
const openFileDialog = () => uploadInput.value?.click();
|
||||||
|
|
||||||
|
const handleJSONFileChange = async (event: Event) => {
|
||||||
|
const input = event.target as HTMLInputElement;
|
||||||
|
if (input.files && input.files.length > 0) {
|
||||||
|
await handleJSONImport(input.files[0]);
|
||||||
|
input.value = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUploadChange = async (event: Event) => {
|
||||||
|
const input = event.target as HTMLInputElement;
|
||||||
|
if (input.files && input.files.length > 0) {
|
||||||
|
await handleSpritesUpload(Array.from(input.files));
|
||||||
|
input.value = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Layer Editing
|
||||||
|
const startEditingLayer = (layerId: string, currentName: string) => {
|
||||||
|
editingLayerId.value = layerId;
|
||||||
|
editingLayerName.value = currentName;
|
||||||
|
setTimeout(() => {
|
||||||
|
layerNameInput.value?.focus();
|
||||||
|
layerNameInput.value?.select();
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const finishEditingLayer = () => {
|
||||||
|
if (editingLayerId.value && editingLayerName.value.trim()) {
|
||||||
|
const layer = layers.value.find(l => l.id === editingLayerId.value);
|
||||||
|
if (layer) layer.name = editingLayerName.value.trim();
|
||||||
|
}
|
||||||
|
editingLayerId.value = null;
|
||||||
|
editingLayerName.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelEditingLayer = () => {
|
||||||
|
editingLayerId.value = null;
|
||||||
|
editingLayerName.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDropSprite = (layerId: string, frameIndex: number, files: File[]) => {
|
||||||
|
const layer = layers.value.find(l => l.id === layerId);
|
||||||
|
if (!layer) return;
|
||||||
|
|
||||||
|
files.forEach((file, fileIdx) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
const sprite = {
|
||||||
|
id: crypto.randomUUID(),
|
||||||
|
file,
|
||||||
|
img,
|
||||||
|
url,
|
||||||
|
width: img.width,
|
||||||
|
height: img.height,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
|
};
|
||||||
|
const insertIndex = frameIndex + fileIdx;
|
||||||
|
if (insertIndex < layer.sprites.length) {
|
||||||
|
layer.sprites = [...layer.sprites.slice(0, insertIndex), sprite, ...layer.sprites.slice(insertIndex + 1)];
|
||||||
|
} else {
|
||||||
|
while (layer.sprites.length < insertIndex) {
|
||||||
|
layer.sprites.push({
|
||||||
|
id: crypto.randomUUID(),
|
||||||
|
file: new File([], 'empty'),
|
||||||
|
img: new Image(),
|
||||||
|
url: '',
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
layer.sprites = [...layer.sprites, sprite];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
const id = route.params.id as string;
|
||||||
|
if (id) {
|
||||||
|
if (projectStore.currentProject?.id !== id) {
|
||||||
|
// Only load if active project is different
|
||||||
|
await projectStore.loadProject(id);
|
||||||
|
if (projectStore.currentProject?.data) {
|
||||||
|
await loadProjectData(projectStore.currentProject.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => route.params.id,
|
||||||
|
async newId => {
|
||||||
|
if (newId) {
|
||||||
|
if (projectStore.currentProject?.id !== newId) {
|
||||||
|
await projectStore.loadProject(newId as string);
|
||||||
|
if (projectStore.currentProject?.data) {
|
||||||
|
await loadProjectData(projectStore.currentProject.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If navigated to /editor without ID, maybe clear logic?
|
||||||
|
// We likely want to keep state if user created new project.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
106
src/views/FAQ.vue
Normal file
106
src/views/FAQ.vue
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useSEO } from '../composables/useSEO';
|
||||||
|
import { useStructuredData } from '../composables/useStructuredData';
|
||||||
|
|
||||||
|
const { addFAQSchema, addBreadcrumbSchema } = useStructuredData();
|
||||||
|
|
||||||
|
// Set SEO synchronously
|
||||||
|
useSEO({
|
||||||
|
title: 'FAQ - Frequently Asked Questions',
|
||||||
|
description: 'Find answers to common questions about the Spritesheet Generator. Learn about supported formats, export options, and how to use the tool effectively.',
|
||||||
|
url: '/faq',
|
||||||
|
type: 'website',
|
||||||
|
keywords: 'faq, spritesheet generator help, questions, support, documentation',
|
||||||
|
});
|
||||||
|
|
||||||
|
addBreadcrumbSchema([
|
||||||
|
{ name: 'Home', url: '/' },
|
||||||
|
{ name: 'FAQ', url: '/faq' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
const faqs = [
|
||||||
|
{
|
||||||
|
question: 'What is a sprite sheet generator?',
|
||||||
|
answer: 'A sprite sheet generator is a tool that combines multiple images into a single file. Our sprite maker online simplifies the process of making a sprite sheet, allowing you to create a sprite sheet for games and websites instantly.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'How do I create a sprite sheet from images?',
|
||||||
|
answer: 'To create a sprite sheet, simply drag and drop your files into our images to sprite sheet converter. We support various formats, making it easy to turn PNG to sprite sheet or use our gif to sprite sheet converter.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'Can I use this as a 2D sprite generator for games?',
|
||||||
|
answer: 'Yes! This tool acts as a powerful 2D sprite generator. Whether you need a character sprite sheet generator, an FNF sprite generator, or just a general sprite image generator, our tool handles the packing efficiently.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'Do you support GIF to sprite sheet conversion?',
|
||||||
|
answer: 'Absolutely. You can turn gif into sprite sheet layouts easily. Our tool creates a clean sprite strip or sprite grid from your animations, functioning as a comprehensive image to sprite animation tool.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'Is there a specific sprite sheet template?',
|
||||||
|
answer: 'No fixed sprite sheet template is needed. Our image sprite generator automatically arranges your uploads. It works as a flexible sprite converter for all your needs.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'How does the PNG to sprite conversion work?',
|
||||||
|
answer: 'Our PNG to sprite feature is simple. Upload your images, and the sprite sheet converter stitches them together. It is the easiest way to image to sprite converter workflows.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'Can I create a sprite sheet for Unity or Godot?',
|
||||||
|
answer: 'Yes, you can create a sprite sheet compatible with major game engines like Unity, Godot, and Unreal Engine. Our sprite sheet converter exports standard formats that work seamlessly with these tools.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'What is the difference between a sprite strip and a sprite grid?',
|
||||||
|
answer: 'A sprite strip arranges images in a single horizontal or vertical row, ideal for simple animations. A sprite grid arranges images in rows and columns, which is better for larger collections or character sprite sheets.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'Can I preview the image to sprite animation?',
|
||||||
|
answer: 'Yes, our tool includes a preview feature. After using the image to sprite animation function, you can play back the sequence to ensure your animation looks perfect before exporting.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'Does this sprite maker online work on mobile devices?',
|
||||||
|
answer: 'Our sprite maker online is fully responsive and works on most modern mobile devices and tablets, allowing you to create sprite sheets on the go.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: 'How many images can I add to the images to sprite sheet converter?',
|
||||||
|
answer: 'There is no hard limit on the number of images you can add to the images to sprite sheet converter, but performance may vary depending on your device and the size of the images.',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
addFAQSchema(faqs);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="glass-panel rounded-3xl shadow-2xl p-8 sm:p-12">
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-extrabold text-gray-900 dark:text-white mb-6">Frequently Asked Questions</h1>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed mb-10">Got questions? We've got answers. If you can't find what you're looking for, feel free to <router-link to="/contact" class="text-blue-600 dark:text-blue-400 hover:underline">contact us</router-link>.</p>
|
||||||
|
|
||||||
|
<div class="space-y-6">
|
||||||
|
<details
|
||||||
|
v-for="(faq, index) in faqs"
|
||||||
|
:key="index"
|
||||||
|
class="group bg-gray-50 dark:bg-gray-800/50 rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden transition-all duration-300 hover:shadow-md open:bg-white dark:open:bg-gray-800 open:shadow-lg open:border-blue-200 dark:open:border-blue-900"
|
||||||
|
>
|
||||||
|
<summary class="flex items-center justify-between p-6 cursor-pointer list-none">
|
||||||
|
<h3 class="text-lg font-bold text-gray-900 dark:text-white pr-4">{{ faq.question }}</h3>
|
||||||
|
<span class="transform transition-transform duration-300 group-open:rotate-180 text-gray-500 dark:text-gray-400">
|
||||||
|
<i class="fas fa-chevron-down"></i>
|
||||||
|
</span>
|
||||||
|
</summary>
|
||||||
|
<div class="px-6 pb-6 text-gray-700 dark:text-gray-300 leading-relaxed border-t border-gray-100 dark:border-gray-700/50 pt-4">
|
||||||
|
{{ faq.answer }}
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
/* Remove default triangle for details/summary */
|
||||||
|
details > summary {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
details > summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
53
src/views/HomeView.seo.ts
Normal file
53
src/views/HomeView.seo.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { useSEO } from '../composables/useSEO';
|
||||||
|
import { useStructuredData } from '../composables/useStructuredData';
|
||||||
|
import { useHead } from '@vueuse/head';
|
||||||
|
|
||||||
|
export function useHomeViewSEO() {
|
||||||
|
const { addOrganizationSchema, addWebSiteSchema } = useStructuredData();
|
||||||
|
|
||||||
|
// Set page SEO synchronously
|
||||||
|
useSEO({
|
||||||
|
title: 'Spritesheet Generator - Create Game Spritesheets Online',
|
||||||
|
description: 'Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.',
|
||||||
|
url: '/',
|
||||||
|
type: 'website',
|
||||||
|
keywords: 'spritesheet generator, sprite sheet maker, game development, pixel art, sprite animation, game assets, 2D game tools',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add organization schema
|
||||||
|
addOrganizationSchema();
|
||||||
|
|
||||||
|
// Add website schema
|
||||||
|
addWebSiteSchema();
|
||||||
|
|
||||||
|
// Add SoftwareApplication schema
|
||||||
|
useHead({
|
||||||
|
script: [
|
||||||
|
{
|
||||||
|
type: 'application/ld+json',
|
||||||
|
children: JSON.stringify({
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'SoftwareApplication',
|
||||||
|
name: 'Spritesheet Generator',
|
||||||
|
applicationCategory: 'DesignApplication',
|
||||||
|
offers: {
|
||||||
|
'@type': 'Offer',
|
||||||
|
price: '0',
|
||||||
|
priceCurrency: 'USD',
|
||||||
|
},
|
||||||
|
operatingSystem: 'Web Browser',
|
||||||
|
description: 'Free online tool to create spritesheets for game development. Upload sprites, arrange them, and export as a spritesheet with animation preview.',
|
||||||
|
url: 'https://spritesheetgenerator.online',
|
||||||
|
screenshot: 'https://spritesheetgenerator.online/og-image.png',
|
||||||
|
featureList: ['Free sprite editor', 'Automatic spritesheet generation', 'Customizable grid layouts', 'Animation preview', 'Cross-platform compatibility', 'Zero installation required', 'Batch processing', 'Multiple export formats (PNG, JPG, GIF, ZIP, JSON)'],
|
||||||
|
browserRequirements: 'Requires JavaScript. Requires HTML5.',
|
||||||
|
aggregateRating: {
|
||||||
|
'@type': 'AggregateRating',
|
||||||
|
ratingValue: '4.8',
|
||||||
|
ratingCount: '127',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
217
src/views/HomeView.vue
Normal file
217
src/views/HomeView.vue
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
<template>
|
||||||
|
<main class="flex flex-col h-full min-h-0 relative">
|
||||||
|
<!-- Welcome / Empty State -->
|
||||||
|
<div class="flex-1 flex flex-col items-center justify-center pb-12">
|
||||||
|
<div class="w-full flex flex-col gap-8 lg:gap-12 items-start">
|
||||||
|
<!-- Top Row: Upload Field & Video Side by Side -->
|
||||||
|
<div class="w-full grid grid-cols-1 lg:grid-cols-2 gap-6 lg:gap-8">
|
||||||
|
<!-- File Uploader Component -->
|
||||||
|
<div class="glass-panel p-2 rounded-2xl shadow-xl shadow-indigo-500/10 border border-indigo-50/50 dark:border-gray-700 h-full flex flex-col">
|
||||||
|
<file-uploader @upload-sprites="handleSpritesUpload" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Video Showcase -->
|
||||||
|
<div class="rounded-2xl overflow-hidden shadow-2xl border border-gray-200 dark:border-gray-800 bg-gray-900 relative group h-full min-h-[300px] lg:min-h-0">
|
||||||
|
<video autoplay controls loop muted playsinline class="w-full h-full object-cover opacity-90 group-hover:opacity-100 transition-opacity duration-500">
|
||||||
|
<source :src="tutVideo" type="video/mp4" />
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Bottom Section: Features -->
|
||||||
|
<div class="w-full grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-12">
|
||||||
|
<!-- Hero Text -->
|
||||||
|
<div class="text-left">
|
||||||
|
<h1 class="text-4xl sm:text-5xl md:text-6xl font-extrabold tracking-tight mb-6 text-gray-900 dark:text-gray-50 leading-[1.1]">Welcome to <span class="text-indigo-600 dark:text-indigo-400">Spritesheet generator</span></h1>
|
||||||
|
<p class="text-lg text-gray-600 dark:text-gray-300 leading-relaxed">
|
||||||
|
Create spritesheets for your game development and animation projects with our completely free, open-source Spritesheet generator. This powerful online tool lets you upload individual sprite images and automatically arrange them into optimized sprite sheets with customizable layouts -
|
||||||
|
perfect for indie developers, animators, and studios of any size.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Key Features Grid -->
|
||||||
|
<div class="space-y-6">
|
||||||
|
<h2 class="text-xl font-bold text-gray-900 dark:text-gray-100 flex items-center gap-2"><i class="fas fa-star text-yellow-500 text-sm"></i> Key features</h2>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-left">
|
||||||
|
<!-- Features List -->
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-edit text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">Free sprite editor</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Edit, organize, and optimize directly in browser.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-magic text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">Automatic generation</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Convert images into efficient sprite atlases.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-th text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">Customizable layouts</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Adjust spacing for pixel-perfect results.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-play-circle text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">Animation preview</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Test animations before exporting.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-gamepad text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">Cross-platform</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Works with Unity, Godot, etc.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-globe text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">No installation</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Use our web-based tool instantly.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-layer-group text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">Batch processing</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Upload/process multiple sprites.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 hover:border-indigo-500/30 transition-colors flex gap-4 items-start">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 shrink-0">
|
||||||
|
<i class="fas fa-file-export text-sm"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold text-sm text-gray-900 dark:text-gray-100 mb-0.5">Export options</h3>
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-400 leading-snug">Download PNG, JSON, ZIP, or GIF.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modals -->
|
||||||
|
<SpritesheetSplitter :is-open="isSpritesheetSplitterOpen" :image-url="spritesheetImageUrl" :image-file="spritesheetImageFile" @close="closeSpritesheetSplitter" @split="handleSplitSpritesheet" />
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, toRef } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import FileUploader from '@/components/FileUploader.vue';
|
||||||
|
import SpritesheetSplitter from '@/components/SpritesheetSplitter.vue';
|
||||||
|
import { useHomeViewSEO } from './HomeView.seo';
|
||||||
|
import { useLayers } from '@/composables/useLayers';
|
||||||
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
|
import { useExportLayers } from '@/composables/useExportLayers';
|
||||||
|
import tutVideo from '@/assets/tut2.mp4';
|
||||||
|
import type { SpriteFile } from '@/types/sprites';
|
||||||
|
|
||||||
|
useHomeViewSEO();
|
||||||
|
const router = useRouter();
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
const { layers, columns, processImageFiles, activeLayerId } = useLayers();
|
||||||
|
|
||||||
|
const { importSpritesheetJSON } = useExportLayers(
|
||||||
|
layers,
|
||||||
|
columns,
|
||||||
|
toRef(settingsStore, 'negativeSpacingEnabled'),
|
||||||
|
activeLayerId,
|
||||||
|
toRef(settingsStore, 'backgroundColor'),
|
||||||
|
toRef(settingsStore, 'manualCellSizeEnabled'),
|
||||||
|
toRef(settingsStore, 'manualCellWidth'),
|
||||||
|
toRef(settingsStore, 'manualCellHeight')
|
||||||
|
);
|
||||||
|
|
||||||
|
const isSpritesheetSplitterOpen = ref(false);
|
||||||
|
const spritesheetImageUrl = ref('');
|
||||||
|
const spritesheetImageFile = ref<File | null>(null);
|
||||||
|
|
||||||
|
const closeSpritesheetSplitter = () => {
|
||||||
|
isSpritesheetSplitterOpen.value = false;
|
||||||
|
if (spritesheetImageUrl.value && spritesheetImageUrl.value.startsWith('blob:')) {
|
||||||
|
try {
|
||||||
|
URL.revokeObjectURL(spritesheetImageUrl.value);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
spritesheetImageUrl.value = '';
|
||||||
|
spritesheetImageFile.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSplitSpritesheet = (spriteFiles: SpriteFile[]) => {
|
||||||
|
processImageFiles(spriteFiles.map(s => s.file));
|
||||||
|
router.push('/editor');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSpritesUpload = async (files: File[]) => {
|
||||||
|
const jsonFile = files.find(file => file.type === 'application/json' || file.name.endsWith('.json'));
|
||||||
|
|
||||||
|
if (jsonFile) {
|
||||||
|
try {
|
||||||
|
await importSpritesheetJSON(jsonFile);
|
||||||
|
router.push('/editor');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert('Failed to import JSON file');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.length === 1 && files[0].type.startsWith('image/')) {
|
||||||
|
const file = files[0];
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = e => {
|
||||||
|
const url = e.target?.result as string;
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
if (confirm('This looks like it might be a spritesheet. Would you like to split it into individual sprites?')) {
|
||||||
|
spritesheetImageUrl.value = url;
|
||||||
|
spritesheetImageFile.value = file;
|
||||||
|
isSpritesheetSplitterOpen.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
processImageFiles([file]);
|
||||||
|
router.push('/editor');
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
processImageFiles(files);
|
||||||
|
router.push('/editor');
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
56
src/views/PrivacyPolicy.vue
Normal file
56
src/views/PrivacyPolicy.vue
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useSEO } from '../composables/useSEO';
|
||||||
|
import { useStructuredData } from '../composables/useStructuredData';
|
||||||
|
|
||||||
|
const { addBreadcrumbSchema } = useStructuredData();
|
||||||
|
|
||||||
|
// Set SEO synchronously
|
||||||
|
useSEO({
|
||||||
|
title: 'Privacy Policy - Your Data Protection',
|
||||||
|
description: 'Read our privacy policy. Spritesheet Generator is a client-side tool that does not collect personal data or upload your images to our servers.',
|
||||||
|
url: '/privacy-policy',
|
||||||
|
type: 'website',
|
||||||
|
keywords: 'privacy policy, data protection, client-side processing',
|
||||||
|
});
|
||||||
|
|
||||||
|
addBreadcrumbSchema([
|
||||||
|
{ name: 'Home', url: '/' },
|
||||||
|
{ name: 'Privacy Policy', url: '/privacy-policy' },
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="glass-panel rounded-3xl shadow-2xl p-8 sm:p-12">
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-extrabold text-gray-900 dark:text-white mb-6">Privacy Policy</h1>
|
||||||
|
<div class="space-y-6">
|
||||||
|
<p class="text-sm text-gray-500 dark:text-gray-400 mb-8">Last updated: November 26, 2025</p>
|
||||||
|
|
||||||
|
<div class="space-y-3">
|
||||||
|
<h3 class="text-xl font-bold text-gray-900 dark:text-white">1. Introduction</h3>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">We respect your privacy. This Spritesheet Generator is a client-side tool, meaning your images are processed directly in your browser and are not uploaded to our servers.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-3">
|
||||||
|
<h3 class="text-xl font-bold text-gray-900 dark:text-white">2. Data collection</h3>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">We do not collect any personal data or uploaded images. All processing happens locally on your device.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-3">
|
||||||
|
<h3 class="text-xl font-bold text-gray-900 dark:text-white">3. Local storage</h3>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">We use your browser's Local Storage to save your preferences (such as dark mode and grid settings) to improve your experience.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-3">
|
||||||
|
<h3 class="text-xl font-bold text-gray-900 dark:text-white">4. Third-Party services</h3>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">We do not use third-party services for analytics.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-3">
|
||||||
|
<h3 class="text-xl font-bold text-gray-900 dark:text-white">5. Contact</h3>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300 leading-relaxed">If you have any questions about this Privacy Policy, please contact us via our Discord server.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
295
src/views/ShareView.vue
Normal file
295
src/views/ShareView.vue
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
<template>
|
||||||
|
<main class="flex-1 glass-panel rounded-3xl shadow-2xl transition-all duration-300">
|
||||||
|
<div class="p-6 sm:p-10 max-w-4xl mx-auto">
|
||||||
|
<!-- Loading state -->
|
||||||
|
<div v-if="loading" class="flex flex-col items-center justify-center py-24">
|
||||||
|
<div class="relative">
|
||||||
|
<div class="w-16 h-16 border-4 border-gray-200 dark:border-gray-700 rounded-full"></div>
|
||||||
|
<div class="absolute top-0 left-0 w-16 h-16 border-4 border-transparent border-t-blue-500 rounded-full"></div>
|
||||||
|
</div>
|
||||||
|
<p class="mt-6 text-lg font-medium text-gray-600 dark:text-gray-300">Loading shared spritesheet...</p>
|
||||||
|
<p class="mt-2 text-sm text-gray-500 dark:text-gray-400">Please wait while we fetch your spritesheet</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error state -->
|
||||||
|
<div v-else-if="error" class="flex flex-col items-center justify-center py-24">
|
||||||
|
<div class="w-20 h-20 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mb-6">
|
||||||
|
<i class="fas fa-exclamation-triangle text-3xl text-red-500 dark:text-red-400"></i>
|
||||||
|
</div>
|
||||||
|
<h2 class="text-2xl font-bold text-gray-800 dark:text-gray-100 mb-2">Oops! Something went wrong</h2>
|
||||||
|
<p class="text-gray-600 dark:text-gray-400 mb-6 text-center max-w-md">{{ error }}</p>
|
||||||
|
<router-link to="/" class="btn btn-primary px-6 py-3">
|
||||||
|
<i class="fas fa-home mr-2"></i>
|
||||||
|
Back to Home
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Success state - show spritesheet info -->
|
||||||
|
<div v-else-if="spritesheetData">
|
||||||
|
<!-- Header -->
|
||||||
|
<div class="text-center mb-10">
|
||||||
|
<div class="inline-flex items-center justify-center w-16 h-16 bg-indigo-600 rounded-2xl shadow-lg mb-4">
|
||||||
|
<i class="fas fa-share-alt text-2xl text-white"></i>
|
||||||
|
</div>
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-extrabold text-gray-900 dark:text-white mb-2">Shared spritesheet</h1>
|
||||||
|
<p class="text-gray-500 dark:text-gray-400">Shared {{ formatDate(spritesheetData.created) }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Stats Grid -->
|
||||||
|
<div class="grid grid-cols-2 sm:grid-cols-4 gap-4 mb-8">
|
||||||
|
<div class="group p-5 bg-blue-50 dark:bg-blue-900/20 rounded-2xl border border-blue-200/50 dark:border-blue-700/30">
|
||||||
|
<div class="flex items-center justify-center w-10 h-10 bg-blue-500/20 dark:bg-blue-500/30 rounded-xl mb-3">
|
||||||
|
<i class="fas fa-columns text-blue-600 dark:text-blue-400"></i>
|
||||||
|
</div>
|
||||||
|
<p class="text-xs font-medium text-blue-600/80 dark:text-blue-400/80 uppercase tracking-wider">Columns</p>
|
||||||
|
<p class="text-2xl font-bold text-blue-700 dark:text-blue-300">{{ spritesheetData.config.columns }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="group p-5 bg-purple-50 dark:bg-purple-900/20 rounded-2xl border border-purple-200/50 dark:border-purple-700/30">
|
||||||
|
<div class="flex items-center justify-center w-10 h-10 bg-purple-500/20 dark:bg-purple-500/30 rounded-xl mb-3">
|
||||||
|
<i class="fas fa-layer-group text-purple-600 dark:text-purple-400"></i>
|
||||||
|
</div>
|
||||||
|
<p class="text-xs font-medium text-purple-600/80 dark:text-purple-400/80 uppercase tracking-wider">Layers</p>
|
||||||
|
<p class="text-2xl font-bold text-purple-700 dark:text-purple-300">{{ spritesheetData.sprites.length }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="group p-5 bg-emerald-50 dark:bg-emerald-900/20 rounded-2xl border border-emerald-200/50 dark:border-emerald-700/30">
|
||||||
|
<div class="flex items-center justify-center w-10 h-10 bg-emerald-500/20 dark:bg-emerald-500/30 rounded-xl mb-3">
|
||||||
|
<i class="fas fa-images text-emerald-600 dark:text-emerald-400"></i>
|
||||||
|
</div>
|
||||||
|
<p class="text-xs font-medium text-emerald-600/80 dark:text-emerald-400/80 uppercase tracking-wider">Sprites</p>
|
||||||
|
<p class="text-2xl font-bold text-emerald-700 dark:text-emerald-300">{{ totalSprites }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="group p-5 bg-amber-50 dark:bg-amber-900/20 rounded-2xl border border-amber-200/50 dark:border-amber-700/30">
|
||||||
|
<div class="flex items-center justify-center w-10 h-10 bg-amber-500/20 dark:bg-amber-500/30 rounded-xl mb-3">
|
||||||
|
<i class="fas fa-fill-drip text-amber-600 dark:text-amber-400"></i>
|
||||||
|
</div>
|
||||||
|
<p class="text-xs font-medium text-amber-600/80 dark:text-amber-400/80 uppercase tracking-wider">Background</p>
|
||||||
|
<p class="text-lg font-bold text-amber-700 dark:text-amber-300 truncate">{{ spritesheetData.config.backgroundColor }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Preview Section -->
|
||||||
|
<div class="mb-8">
|
||||||
|
<h3 class="flex items-center gap-2 text-lg font-bold text-gray-800 dark:text-gray-100 mb-4">
|
||||||
|
<i class="fas fa-eye text-gray-500 dark:text-gray-400"></i>
|
||||||
|
Sprite preview
|
||||||
|
</h3>
|
||||||
|
<div class="p-6 bg-gray-50 dark:bg-gray-800/50 rounded-2xl border border-gray-200 dark:border-gray-700">
|
||||||
|
<div v-for="(layer, layerIndex) in spritesheetData.sprites" :key="layerIndex" class="mb-6 last:mb-0">
|
||||||
|
<div class="flex items-center gap-2 mb-3">
|
||||||
|
<span class="inline-flex items-center justify-center w-6 h-6 bg-gray-200 dark:bg-gray-700 rounded-full text-xs font-bold text-gray-600 dark:text-gray-300">
|
||||||
|
{{ layerIndex + 1 }}
|
||||||
|
</span>
|
||||||
|
<p class="text-sm font-semibold text-gray-700 dark:text-gray-300">{{ layer.name || `Layer ${layerIndex + 1}` }}</p>
|
||||||
|
<span class="text-xs text-gray-400 dark:text-gray-500">({{ layer.sprites.length }} sprites)</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<div v-for="(sprite, spriteIndex) in layer.sprites.slice(0, 12)" :key="spriteIndex" class="relative group">
|
||||||
|
<div class="w-16 h-16 bg-checkerboard rounded-lg border-2 border-gray-200 dark:border-gray-600 overflow-hidden transition-transform group-hover:scale-110 group-hover:border-blue-400 group-hover:shadow-lg">
|
||||||
|
<img :src="sprite.base64" :alt="`Sprite ${spriteIndex + 1}`" class="w-full h-full object-contain" style="image-rendering: pixelated" />
|
||||||
|
</div>
|
||||||
|
<div class="absolute -bottom-1 -right-1 w-5 h-5 bg-gray-800 dark:bg-gray-600 rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
|
||||||
|
<span class="text-[10px] font-bold text-white">{{ spriteIndex + 1 }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="layer.sprites.length > 12" class="w-16 h-16 flex flex-col items-center justify-center bg-gray-100 dark:bg-gray-700 rounded-lg border-2 border-dashed border-gray-300 dark:border-gray-600">
|
||||||
|
<span class="text-lg font-bold text-gray-500 dark:text-gray-400">+{{ layer.sprites.length - 12 }}</span>
|
||||||
|
<span class="text-[10px] text-gray-400 dark:text-gray-500">more</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Actions -->
|
||||||
|
<div class="flex flex-col sm:flex-row gap-3 justify-center">
|
||||||
|
<button @click="loadIntoEditor" class="btn btn-primary px-8 py-3 text-base font-semibold shadow-lg hover:shadow-xl transition-shadow shadow-indigo-500/20">
|
||||||
|
<i class="fas fa-edit mr-2"></i>
|
||||||
|
Open in editor
|
||||||
|
</button>
|
||||||
|
<button @click="downloadJSON" class="btn btn-secondary px-8 py-3 text-base font-semibold">
|
||||||
|
<i class="fas fa-download mr-2"></i>
|
||||||
|
Download JSON
|
||||||
|
</button>
|
||||||
|
<router-link to="/" class="btn btn-ghost px-8 py-3 text-base font-semibold text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200">
|
||||||
|
<i class="fas fa-plus-circle mr-2"></i>
|
||||||
|
Create new
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, onMounted } from 'vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import { fetchSpritesheet, type SpritesheetRecord } from '@/composables/useShare';
|
||||||
|
import { useLayers } from '@/composables/useLayers';
|
||||||
|
import { useSettingsStore } from '@/stores/useSettingsStore';
|
||||||
|
import { useProjectStore } from '@/stores/useProjectStore';
|
||||||
|
import type { Layer, Sprite } from '@/types/sprites';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
const projectStore = useProjectStore();
|
||||||
|
const { layers, activeLayerId, columns } = useLayers();
|
||||||
|
|
||||||
|
const loading = ref(true);
|
||||||
|
const error = ref('');
|
||||||
|
const spritesheetData = ref<SpritesheetRecord | null>(null);
|
||||||
|
|
||||||
|
const totalSprites = computed(() => {
|
||||||
|
if (!spritesheetData.value) return 0;
|
||||||
|
return spritesheetData.value.sprites.reduce((sum: number, layer) => sum + (layer.sprites?.length || 0), 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
const formatDate = (dateString: string) => {
|
||||||
|
const date = new Date(dateString);
|
||||||
|
const now = new Date();
|
||||||
|
const diffMs = now.getTime() - date.getTime();
|
||||||
|
const diffMins = Math.floor(diffMs / 60000);
|
||||||
|
const diffHours = Math.floor(diffMs / 3600000);
|
||||||
|
const diffDays = Math.floor(diffMs / 86400000);
|
||||||
|
|
||||||
|
if (diffMins < 1) return 'just now';
|
||||||
|
if (diffMins < 60) return `${diffMins} minute${diffMins === 1 ? '' : 's'} ago`;
|
||||||
|
if (diffHours < 24) return `${diffHours} hour${diffHours === 1 ? '' : 's'} ago`;
|
||||||
|
if (diffDays < 7) return `${diffDays} day${diffDays === 1 ? '' : 's'} ago`;
|
||||||
|
|
||||||
|
return date.toLocaleDateString(undefined, {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadIntoEditor = async () => {
|
||||||
|
if (!spritesheetData.value) return;
|
||||||
|
|
||||||
|
const data = spritesheetData.value;
|
||||||
|
|
||||||
|
// Apply config settings
|
||||||
|
columns.value = data.config.columns;
|
||||||
|
settingsStore.negativeSpacingEnabled = data.config.negativeSpacingEnabled;
|
||||||
|
settingsStore.backgroundColor = data.config.backgroundColor;
|
||||||
|
settingsStore.manualCellSizeEnabled = data.config.manualCellSizeEnabled;
|
||||||
|
settingsStore.manualCellWidth = data.config.manualCellWidth;
|
||||||
|
settingsStore.manualCellHeight = data.config.manualCellHeight;
|
||||||
|
|
||||||
|
// Load sprites into layers
|
||||||
|
const loadSprite = (spriteData: any): Promise<Sprite> =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
const byteString = atob(spriteData.base64.split(',')[1]);
|
||||||
|
const mimeType = spriteData.base64.split(',')[0].split(':')[1].split(';')[0];
|
||||||
|
const ab = new ArrayBuffer(byteString.length);
|
||||||
|
const ia = new Uint8Array(ab);
|
||||||
|
for (let i = 0; i < byteString.length; i++) ia[i] = byteString.charCodeAt(i);
|
||||||
|
const blob = new Blob([ab], { type: mimeType });
|
||||||
|
const fileName = spriteData.name || `sprite-${spriteData.id}.png`;
|
||||||
|
const file = new File([blob], fileName, { type: mimeType });
|
||||||
|
resolve({
|
||||||
|
id: spriteData.id || crypto.randomUUID(),
|
||||||
|
file,
|
||||||
|
img,
|
||||||
|
url: spriteData.base64,
|
||||||
|
width: spriteData.width,
|
||||||
|
height: spriteData.height,
|
||||||
|
x: spriteData.x || 0,
|
||||||
|
y: spriteData.y || 0,
|
||||||
|
// Transformations are already baked into the base64 image
|
||||||
|
rotation: 0,
|
||||||
|
flipX: false,
|
||||||
|
flipY: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
img.src = spriteData.base64;
|
||||||
|
});
|
||||||
|
|
||||||
|
const newLayers: Layer[] = [];
|
||||||
|
for (const layerData of data.sprites) {
|
||||||
|
const sprites: Sprite[] = await Promise.all(layerData.sprites.map((s: any) => loadSprite(s)));
|
||||||
|
newLayers.push({
|
||||||
|
id: layerData.id || crypto.randomUUID(),
|
||||||
|
name: layerData.name || 'Layer',
|
||||||
|
visible: layerData.visible !== false,
|
||||||
|
locked: !!layerData.locked,
|
||||||
|
sprites,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
layers.value = newLayers;
|
||||||
|
if (newLayers.length > 0) {
|
||||||
|
const firstWithSprites = newLayers.find(l => l.sprites.length > 0);
|
||||||
|
activeLayerId.value = firstWithSprites ? firstWithSprites.id : newLayers[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear current project so it's treated as new/unsaved
|
||||||
|
projectStore.currentProject = null;
|
||||||
|
|
||||||
|
// Navigate to editor
|
||||||
|
router.push({ name: 'editor' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloadJSON = () => {
|
||||||
|
if (!spritesheetData.value) return;
|
||||||
|
|
||||||
|
const json = {
|
||||||
|
version: spritesheetData.value.config.version,
|
||||||
|
columns: spritesheetData.value.config.columns,
|
||||||
|
negativeSpacingEnabled: spritesheetData.value.config.negativeSpacingEnabled,
|
||||||
|
backgroundColor: spritesheetData.value.config.backgroundColor,
|
||||||
|
manualCellSizeEnabled: spritesheetData.value.config.manualCellSizeEnabled,
|
||||||
|
manualCellWidth: spritesheetData.value.config.manualCellWidth,
|
||||||
|
manualCellHeight: spritesheetData.value.config.manualCellHeight,
|
||||||
|
layers: spritesheetData.value.sprites,
|
||||||
|
};
|
||||||
|
|
||||||
|
const jsonString = JSON.stringify(json, null, 2);
|
||||||
|
const blob = new Blob([jsonString], { type: 'application/json' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = 'spritesheet.json';
|
||||||
|
a.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
const id = route.params.id as string;
|
||||||
|
if (!id) {
|
||||||
|
error.value = 'No spritesheet ID provided';
|
||||||
|
loading.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
spritesheetData.value = await fetchSpritesheet(id);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error('Failed to load spritesheet:', e);
|
||||||
|
error.value = e.message || 'Failed to load spritesheet';
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.bg-checkerboard {
|
||||||
|
background-color: #fff;
|
||||||
|
background-image: linear-gradient(45deg, #e5e5e5 25%, transparent 25%), linear-gradient(-45deg, #e5e5e5 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e5e5e5 75%), linear-gradient(-45deg, transparent 75%, #e5e5e5 75%);
|
||||||
|
background-size: 12px 12px;
|
||||||
|
background-position:
|
||||||
|
0 0,
|
||||||
|
0 6px,
|
||||||
|
6px -6px,
|
||||||
|
-6px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .bg-checkerboard {
|
||||||
|
background-color: #374151;
|
||||||
|
background-image: linear-gradient(45deg, #4b5563 25%, transparent 25%), linear-gradient(-45deg, #4b5563 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #4b5563 75%), linear-gradient(-45deg, transparent 75%, #4b5563 75%);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -6,67 +6,161 @@ export default {
|
|||||||
extend: {
|
extend: {
|
||||||
colors: {
|
colors: {
|
||||||
gray: {
|
gray: {
|
||||||
900: '#111827', // bg-primary
|
50: '#fafafa',
|
||||||
800: '#1F2937', // bg-secondary
|
100: '#f4f4f5',
|
||||||
700: '#374151', // bg-tertiary
|
200: '#e4e4e7', // border-light
|
||||||
600: '#4B5563', // border
|
300: '#d4d4d8',
|
||||||
400: '#9CA3AF', // text-secondary
|
400: '#a1a1aa', // text-secondary
|
||||||
200: '#E5E7EB', // text-primary
|
500: '#71717a',
|
||||||
|
600: '#52525b', // border-dark
|
||||||
|
700: '#3f3f46',
|
||||||
|
800: '#27272a', // bg-secondary
|
||||||
|
900: '#18181b', // bg-primary
|
||||||
|
950: '#09090b', // bg-deep
|
||||||
},
|
},
|
||||||
blue: {
|
primary: {
|
||||||
500: '#3B82F6', // accent
|
50: '#eff6ff',
|
||||||
600: '#2563EB', // accent-hover
|
100: '#dbeafe',
|
||||||
|
200: '#bfdbfe',
|
||||||
|
300: '#93c5fd',
|
||||||
|
400: '#60a5fa',
|
||||||
|
500: '#3b82f6', // accent
|
||||||
|
600: '#2563eb', // accent-hover
|
||||||
|
700: '#1d4ed8',
|
||||||
|
800: '#1e40af',
|
||||||
|
900: '#1e3a8a',
|
||||||
|
950: '#172554',
|
||||||
},
|
},
|
||||||
red: {
|
d: {
|
||||||
500: '#EF4444', // danger
|
50: '#fef2f2',
|
||||||
600: '#DC2626', // danger-hover
|
100: '#fee2e2',
|
||||||
|
200: '#fecaca',
|
||||||
|
300: '#fca5a5',
|
||||||
|
400: '#f87171',
|
||||||
|
500: '#ef4444',
|
||||||
|
600: '#dc2626',
|
||||||
|
700: '#b91c1c',
|
||||||
|
800: '#991b1b',
|
||||||
|
900: '#7f1d1d',
|
||||||
|
950: '#450a0a',
|
||||||
},
|
},
|
||||||
green: {
|
s: {
|
||||||
500: '#10B981', // success
|
50: '#f0fdf4',
|
||||||
600: '#059669', // success-hover
|
100: '#dcfce7',
|
||||||
|
200: '#bbf7d0',
|
||||||
|
300: '#86efac',
|
||||||
|
400: '#4ade80',
|
||||||
|
500: '#22c55e',
|
||||||
|
600: '#16a34a',
|
||||||
|
700: '#15803d',
|
||||||
|
800: '#166534',
|
||||||
|
900: '#14532d',
|
||||||
|
950: '#052e16',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
boxShadow: {
|
boxShadow: {
|
||||||
'soft': '0 2px 15px -3px rgba(0, 0, 0, 0.07), 0 10px 20px -2px rgba(0, 0, 0, 0.04)',
|
'soft': '0 2px 15px -3px rgba(0, 0, 0, 0.07), 0 10px 20px -2px rgba(0, 0, 0, 0.04)',
|
||||||
|
'glass': '0 8px 32px 0 rgba(0, 0, 0, 0.08)',
|
||||||
|
'glow': '0 0 15px rgba(59, 130, 246, 0.5)',
|
||||||
|
},
|
||||||
|
|
||||||
|
fontFamily: {
|
||||||
|
sans: [
|
||||||
|
'Inter',
|
||||||
|
'ui-sans-serif',
|
||||||
|
'system-ui',
|
||||||
|
'-apple-system',
|
||||||
|
'BlinkMacSystemFont',
|
||||||
|
'"Segoe UI"',
|
||||||
|
'Roboto',
|
||||||
|
'"Helvetica Neue"',
|
||||||
|
'Arial',
|
||||||
|
'"Noto Sans"',
|
||||||
|
'sans-serif',
|
||||||
|
'"Apple Color Emoji"',
|
||||||
|
'"Segoe UI Emoji"',
|
||||||
|
'"Segoe UI Symbol"',
|
||||||
|
'"Noto Color Emoji"'
|
||||||
|
],
|
||||||
|
mono: [
|
||||||
|
'ui-monospace',
|
||||||
|
'SFMono-Regular',
|
||||||
|
'Menlo',
|
||||||
|
'Monaco',
|
||||||
|
'Consolas',
|
||||||
|
'"Liberation Mono"',
|
||||||
|
'"Courier New"',
|
||||||
|
'monospace'
|
||||||
|
],
|
||||||
},
|
},
|
||||||
typography: (theme) => ({
|
typography: (theme) => ({
|
||||||
DEFAULT: {
|
DEFAULT: {
|
||||||
css: {
|
css: {
|
||||||
maxWidth: 'none',
|
maxWidth: 'none',
|
||||||
|
color: theme('colors.gray.700'),
|
||||||
|
a: {
|
||||||
|
color: theme('colors.primary.600'),
|
||||||
|
'&:hover': {
|
||||||
|
color: theme('colors.primary.500'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h1: {
|
||||||
|
color: theme('colors.gray.900'),
|
||||||
|
letterSpacing: '-0.025em',
|
||||||
|
},
|
||||||
|
h2: {
|
||||||
|
color: theme('colors.gray.900'),
|
||||||
|
letterSpacing: '-0.025em',
|
||||||
|
},
|
||||||
|
h3: {
|
||||||
|
color: theme('colors.gray.900'),
|
||||||
|
},
|
||||||
|
h4: {
|
||||||
|
color: theme('colors.gray.900'),
|
||||||
|
},
|
||||||
|
code: {
|
||||||
|
color: theme('colors.primary.600'),
|
||||||
|
backgroundColor: theme('colors.gray.100'),
|
||||||
|
borderRadius: '0.25rem',
|
||||||
|
paddingLeft: '0.25rem',
|
||||||
|
paddingRight: '0.25rem',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
dark: {
|
dark: {
|
||||||
css: {
|
css: {
|
||||||
color: theme('colors.gray.200'),
|
color: theme('colors.gray.300'),
|
||||||
a: {
|
a: {
|
||||||
color: theme('colors.blue.500'),
|
color: theme('colors.primary.400'),
|
||||||
'&:hover': {
|
'&:hover': {
|
||||||
color: theme('colors.blue.400'),
|
color: theme('colors.primary.300'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
h1: {
|
h1: {
|
||||||
color: theme('colors.gray.200'),
|
color: theme('colors.gray.50'),
|
||||||
},
|
},
|
||||||
h2: {
|
h2: {
|
||||||
color: theme('colors.gray.200'),
|
color: theme('colors.gray.50'),
|
||||||
},
|
},
|
||||||
h3: {
|
h3: {
|
||||||
color: theme('colors.gray.200'),
|
color: theme('colors.gray.100'),
|
||||||
},
|
},
|
||||||
h4: {
|
h4: {
|
||||||
color: theme('colors.gray.200'),
|
color: theme('colors.gray.100'),
|
||||||
},
|
},
|
||||||
code: {
|
code: {
|
||||||
color: theme('colors.gray.200'),
|
color: theme('colors.primary.300'),
|
||||||
backgroundColor: theme('colors.gray.800'),
|
backgroundColor: theme('colors.gray.800'),
|
||||||
},
|
},
|
||||||
pre: {
|
pre: {
|
||||||
backgroundColor: theme('colors.gray.800'),
|
backgroundColor: theme('colors.gray.900'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: [
|
||||||
|
require('@tailwindcss/typography'),
|
||||||
|
],
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user