├── .eslintrc.cjs ├── .github └── FUNDING.yml ├── .gitignore ├── .nvmrc ├── LICENSE ├── README.md ├── index.html ├── package-lock.json ├── package.json ├── postcss.config.js ├── public ├── _redirects ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico └── site.webmanifest ├── src ├── App.tsx ├── ConfigurationForm.tsx ├── DownloadModal.tsx ├── FileInput.tsx ├── Footer.tsx ├── GlassesColorPicker.tsx ├── GlassesDraggable.tsx ├── InputImage.tsx ├── ResizeHandle.tsx ├── SettingsDrawer.tsx ├── SortableGlassesItem.tsx ├── SortableGlassesList.tsx ├── ThemeSwitcher.tsx ├── Title.tsx ├── assets │ ├── example-group.jpg │ ├── example-person.jpg │ ├── example-portrait.jpg │ ├── glasses-small.png │ ├── glasses-symmetrical-party.png │ ├── glasses-symmetrical.png │ ├── glasses.png │ └── glasses.svg ├── icons │ ├── FlipH.tsx │ └── FlipV.tsx ├── index.css ├── index.d.ts ├── lib │ ├── drag-modifiers.ts │ ├── glasses.ts │ ├── id-utils.ts │ └── utils.ts ├── main.tsx ├── store │ ├── index.ts │ └── slices │ │ ├── app.ts │ │ ├── face-detection.ts │ │ ├── glasses.ts │ │ ├── image.ts │ │ └── theme.ts ├── vite-env.d.ts └── worker │ ├── gif.worker.ts │ └── utils.ts ├── tailwind.config.js ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.node.json └── vite.config.ts /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:import/recommended', 7 | 'plugin:@typescript-eslint/recommended', 8 | 'plugin:react-hooks/recommended', 9 | 'plugin:prettier/recommended', 10 | ], 11 | ignorePatterns: ['dist', '.eslintrc.cjs'], 12 | parser: '@typescript-eslint/parser', 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react-refresh/only-export-components': [ 16 | 'warn', 17 | { allowConstantExport: true }, 18 | ], 19 | 'import/order': [ 20 | 'error', 21 | { 22 | 'groups': ['builtin', 'external', 'parent', 'sibling', 'index'], 23 | 'named': true, 24 | 'newlines-between': 'always', 25 | 'alphabetize': { 26 | 'order': 'asc', 27 | 'caseInsensitive': true 28 | } 29 | } 30 | ], 31 | '@typescript-eslint/no-unused-vars': [ 32 | "error", 33 | { 34 | 'args': 'all', 35 | 'argsIgnorePattern': '^_', 36 | 'caughtErrors': 'all', 37 | 'caughtErrorsIgnorePattern': '^_', 38 | 'destructuredArrayIgnorePattern': '^_', 39 | 'varsIgnorePattern': '^_', 40 | 'ignoreRestSiblings': true 41 | } 42 | ] 43 | }, 44 | } 45 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [klimeryk] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: klimeryk 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v20.14.0 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deal With It emoji generator 2 | 3 | Fully client-side Deal With It emoji generator hosted at https://emoji.build/deal-with-it-generator/ 4 | 5 | ## Over-engineered features 6 | 7 | - All operations done fully client-side - no backend, no private data leaves your browser. 8 | - Uses [MediaPipe Face Detector task](https://ai.google.dev/edge/mediapipe/solutions/vision/face_detector) to automatically scale and position glasses on the detected faces. 9 | - Extensive customization options for glasses: 10 | - Placement of glasses anywhere on the input image (including slightly going outside it). 11 | - Change the size of glasses. 12 | - Change the color of glasses to any RGBA value (only applies to the Classic style). 13 | - No limit on the number of glasses. 14 | - Flip the glasses vertically or horizontally. 15 | - Customize the direction from which the glasses appear on the image. 16 | - Different types of glasses. 17 | - GIF output options: 18 | - Looping mode. 19 | - Number of frames. 20 | - Frame delay. 21 | - Separate delay setting for last frame. 22 | - Output size. 23 | - Anonymous product analytics using [PostHog](https://posthog.com/), requiring explicit *opt-in*. 24 | - Celebration confetti 🎉 25 | - Easter eggs. 26 | 27 | ## Development 28 | 29 | Uses [Vite](https://vitejs.dev/), so the usual dance is enough: 30 | 31 | ``` 32 | nvm use 33 | npm install 34 | npm run dev 35 | ``` 36 | 37 | Then visit http://localhost:5173/deal-with-it-generator/ (note the subdirectory). 38 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Deal With It GIF emoji generator 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dealwithit", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc -b && vite build && rm -f dist/deal-with-it-generator/_redirects && cp public/_redirects dist/", 9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "@ant-design/icons": "^5.5.1", 14 | "@dnd-kit/core": "^6.1.0", 15 | "@dnd-kit/modifiers": "^7.0.0", 16 | "@dnd-kit/sortable": "^8.0.0", 17 | "@mediapipe/tasks-vision": "^0.10.16", 18 | "antd": "^5.21.2", 19 | "file-saver": "^2.0.5", 20 | "gifwrap": "^0.10.1", 21 | "immer": "^10.1.1", 22 | "jimp": "^0.22.12", 23 | "nanoid": "^5.0.7", 24 | "party-js": "^2.2.0", 25 | "posthog-js": "^1.155.0", 26 | "react": "^18.3.1", 27 | "react-dom": "^18.3.1", 28 | "zustand": "^5.0.0-rc.2" 29 | }, 30 | "devDependencies": { 31 | "@types/file-saver": "^2.0.7", 32 | "@types/react": "^18.3.3", 33 | "@types/react-dom": "^18.3.0", 34 | "@typescript-eslint/eslint-plugin": "^7.15.0", 35 | "@typescript-eslint/parser": "^7.18.0", 36 | "@vitejs/plugin-react": "^4.3.1", 37 | "autoprefixer": "^10.4.20", 38 | "eslint": "^8.57.0", 39 | "eslint-config-prettier": "^9.1.0", 40 | "eslint-import-resolver-typescript": "^3.6.1", 41 | "eslint-plugin-import": "^2.31.0", 42 | "eslint-plugin-prettier": "^5.2.1", 43 | "eslint-plugin-react-hooks": "^4.6.2", 44 | "eslint-plugin-react-refresh": "^0.4.7", 45 | "postcss": "^8.4.40", 46 | "prettier": "3.3.3", 47 | "tailwindcss": "^3.4.7", 48 | "typescript": "^5.2.2", 49 | "vite": "^5.3.4" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/_redirects: -------------------------------------------------------------------------------- 1 | / /deal-with-it-generator/ 302 2 | -------------------------------------------------------------------------------- /public/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/public/android-chrome-192x192.png -------------------------------------------------------------------------------- /public/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/public/android-chrome-512x512.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/public/favicon-16x16.png -------------------------------------------------------------------------------- /public/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/public/favicon-32x32.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/public/favicon.ico -------------------------------------------------------------------------------- /public/site.webmanifest: -------------------------------------------------------------------------------- 1 | {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import "jimp/browser/lib/jimp.js"; 2 | import { SettingOutlined } from "@ant-design/icons"; 3 | import { Button } from "antd"; 4 | import { useEffect, useRef } from "react"; 5 | 6 | import ConfigurationForm from "./ConfigurationForm.tsx"; 7 | import DownloadModal from "./DownloadModal.tsx"; 8 | import FileInput from "./FileInput.tsx"; 9 | import Footer from "./Footer.tsx"; 10 | import InputImage from "./InputImage.tsx"; 11 | import SettingsDrawer from "./SettingsDrawer.tsx"; 12 | import SortableGlassesList from "./SortableGlassesList.tsx"; 13 | import { useBoundStore } from "./store/index.ts"; 14 | import Title from "./Title.tsx"; 15 | 16 | function App() { 17 | const messageApi = useBoundStore((state) => state.messageApi); 18 | const setDrawerOpen = useBoundStore((state) => state.setDrawerOpen); 19 | const status = useBoundStore((state) => state.status); 20 | const detectFaces = useBoundStore((state) => state.detectFaces); 21 | const inputImageRef = useRef(null); 22 | const mode = useBoundStore((state) => state.mode); 23 | 24 | useEffect(() => { 25 | if (mode === "HEDGEHOG") { 26 | messageApi?.info({ 27 | content: "Hello fellow hedgehog fan!", 28 | icon: 🦔, 29 | }); 30 | } 31 | }, [mode, messageApi]); 32 | 33 | function renderInputImage() { 34 | async function handleInputImageLoad() { 35 | if (!inputImageRef.current) { 36 | return; 37 | } 38 | detectFaces(inputImageRef.current); 39 | } 40 | 41 | return ( 42 | <> 43 | 47 | 48 | 49 | ); 50 | } 51 | 52 | function onOpenDrawer() { 53 | setDrawerOpen(true); 54 | } 55 | 56 | const shouldRenderFileInput = ["START", "INPUT", "LOADING"].includes(status); 57 | 58 | return ( 59 | <> 60 | 61 | <div className="relative py-3 sm:max-w-2xl sm:mx-auto"> 62 | <div className="relative p-10 bg-white dark:bg-slate-900 shadow-lg sm:rounded-3xl"> 63 | <Button 64 | icon={<SettingOutlined />} 65 | shape="circle" 66 | className="absolute right-0 top-0 mt-2 me-2" 67 | onClick={onOpenDrawer} 68 | /> 69 | <div className="sm:grid grid-cols-3 gap-4"> 70 | <div className="col-span-2 mb-4 sm:mb-0"> 71 | {shouldRenderFileInput ? <FileInput /> : renderInputImage()} 72 | </div> 73 | <ConfigurationForm inputImageRef={inputImageRef} /> 74 | </div> 75 | <DownloadModal /> 76 | </div> 77 | </div> 78 | <Footer /> 79 | <SettingsDrawer /> 80 | </> 81 | ); 82 | } 83 | 84 | export default App; 85 | -------------------------------------------------------------------------------- /src/ConfigurationForm.tsx: -------------------------------------------------------------------------------- 1 | import { FireOutlined } from "@ant-design/icons"; 2 | import { 3 | Button, 4 | Form, 5 | InputNumber, 6 | Progress, 7 | Radio, 8 | Space, 9 | Switch, 10 | } from "antd"; 11 | import { useMemo, useState } from "react"; 12 | 13 | import { DEFAULT_GLASSES_SIZE } from "./lib/glasses.ts"; 14 | import { useBoundStore } from "./store/index.ts"; 15 | 16 | const EMOJI_GENERATION_START_MARK = "EmojiGenerationStartMark"; 17 | const EMOJI_GENERATION_END_MARK = "EmojiGenerationEndMark"; 18 | 19 | interface ConfigurationFormProps { 20 | inputImageRef: React.RefObject<HTMLImageElement>; 21 | } 22 | 23 | export default function ConfigurationForm({ 24 | inputImageRef, 25 | }: ConfigurationFormProps) { 26 | const gifWorker = useMemo( 27 | () => 28 | new Worker(new URL("./worker/gif.worker.ts", import.meta.url), { 29 | type: "module", 30 | }), 31 | [], 32 | ); 33 | 34 | const inputFile = useBoundStore((state) => state.inputFile); 35 | const setOutputImage = useBoundStore((state) => state.setOutputImage); 36 | const glassesList = useBoundStore((state) => state.glassesList); 37 | const imageOptions = useBoundStore((state) => state.imageOptions); 38 | const posthog = useBoundStore((state) => state.posthog); 39 | const status = useBoundStore((state) => state.status); 40 | const setStatus = useBoundStore((state) => state.setStatus); 41 | 42 | const [form] = Form.useForm(); 43 | const lastFrameDelayEnabled = Form.useWatch( 44 | ["lastFrameDelay", "enabled"], 45 | form, 46 | ); 47 | const numberOfLoops = Form.useWatch(["looping", "loops"], form); 48 | 49 | const [progressState, setProgressState] = useState(0); 50 | 51 | gifWorker.onmessage = ({ data }) => { 52 | if (data.type === "PROGRESS") { 53 | setProgressState(Math.round(data.progress)); 54 | return; 55 | } 56 | 57 | performance.mark(EMOJI_GENERATION_END_MARK); 58 | const emojiMeasure = performance.measure( 59 | "EmojiGeneration", 60 | EMOJI_GENERATION_START_MARK, 61 | EMOJI_GENERATION_END_MARK, 62 | ); 63 | posthog?.capture("user_finished_emoji_generation", { 64 | duration: emojiMeasure.duration, 65 | }); 66 | 67 | const { gifBlob, resultDataUrl } = data; 68 | setOutputImage(gifBlob, resultDataUrl); 69 | setStatus("DONE"); 70 | }; 71 | 72 | function generateOutputImage() { 73 | if (!inputFile || !inputImageRef.current) { 74 | return; 75 | } 76 | 77 | const configurationOptions = form.getFieldsValue([ 78 | ["looping"], 79 | ["lastFrameDelay"], 80 | ["frameDelay"], 81 | ["numberOfFrames"], 82 | ["size"], 83 | ]); 84 | 85 | posthog?.capture("user_started_emoji_generation", { 86 | ...configurationOptions, 87 | }); 88 | 89 | performance.mark(EMOJI_GENERATION_START_MARK); 90 | 91 | gifWorker.postMessage({ 92 | configurationOptions, 93 | glassesList: glassesList, 94 | imageOptions, 95 | inputImage: { 96 | renderedWidth: inputImageRef.current.width, 97 | renderedHeight: inputImageRef.current.height, 98 | }, 99 | inputFile, 100 | }); 101 | 102 | setProgressState(0); 103 | setStatus("GENERATING"); 104 | } 105 | 106 | return ( 107 | <Form 108 | form={form} 109 | layout="vertical" 110 | disabled={status !== "READY"} 111 | initialValues={ 112 | { 113 | numberOfFrames: 10, 114 | frameDelay: 120, 115 | lastFrameDelay: { enabled: true, value: 1000 }, 116 | looping: { mode: "infinite", loops: 5 }, 117 | size: DEFAULT_GLASSES_SIZE, 118 | } as ConfigurationOptions 119 | } 120 | > 121 | <Form.Item label="Loops" name={["looping", "mode"]}> 122 | <Radio.Group> 123 | <Space direction="vertical"> 124 | <Radio value="infinite">Infinite</Radio> 125 | <Radio value="off">Off</Radio> 126 | <Radio value="finite"> 127 | <Form.Item name={["looping", "loops"]} noStyle> 128 | <InputNumber 129 | min={1} 130 | addonAfter={numberOfLoops === 1 ? "loop" : "loops"} 131 | /> 132 | </Form.Item> 133 | </Radio> 134 | </Space> 135 | </Radio.Group> 136 | </Form.Item> 137 | <Form.Item 138 | label="Number of frames" 139 | tooltip="How many frames should be rendered - more frames, smoother motion, but bigger file size." 140 | name="numberOfFrames" 141 | > 142 | <InputNumber addonAfter="frames" style={{ width: "100%" }} min={2} /> 143 | </Form.Item> 144 | <Form.Item 145 | label="Frame delay" 146 | tooltip="How long each frame should take, in miliseconds" 147 | name="frameDelay" 148 | > 149 | <InputNumber 150 | addonAfter="ms" 151 | style={{ width: "100%" }} 152 | min={0} 153 | step={10} 154 | /> 155 | </Form.Item> 156 | <Form.Item 157 | label="Last frame delay" 158 | tooltip="How long the last frame should linger, for maximum awesomeness! YEAH!" 159 | > 160 | <Space> 161 | <Form.Item 162 | noStyle 163 | valuePropName="checked" 164 | name={["lastFrameDelay", "enabled"]} 165 | > 166 | <Switch /> 167 | </Form.Item> 168 | <Form.Item noStyle name={["lastFrameDelay", "value"]}> 169 | <InputNumber 170 | addonAfter="ms" 171 | style={{ width: "100%" }} 172 | min={10} 173 | step={100} 174 | disabled={!lastFrameDelayEnabled || status !== "READY"} 175 | /> 176 | </Form.Item> 177 | </Space> 178 | </Form.Item> 179 | <Form.Item 180 | label="Largest dimension (width or height)" 181 | tooltip="The largest dimension of the output image - either width or height, depending on the aspect ratio." 182 | name="size" 183 | > 184 | <InputNumber addonAfter="px" style={{ width: "100%" }} min={1} /> 185 | </Form.Item> 186 | <Button 187 | block 188 | disabled={glassesList.length === 0} 189 | type="primary" 190 | size="large" 191 | onClick={generateOutputImage} 192 | loading={status === "GENERATING"} 193 | icon={<FireOutlined />} 194 | > 195 | Deal with it! 196 | </Button> 197 | {status === "GENERATING" && ( 198 | <Progress 199 | percent={progressState} 200 | showInfo={false} 201 | strokeColor={{ from: "#108ee9", to: "#87d068" }} 202 | /> 203 | )} 204 | </Form> 205 | ); 206 | } 207 | -------------------------------------------------------------------------------- /src/DownloadModal.tsx: -------------------------------------------------------------------------------- 1 | import { DownloadOutlined } from "@ant-design/icons"; 2 | import { Button, Modal } from "antd"; 3 | import { saveAs } from "file-saver"; 4 | import party from "party-js"; 5 | import { useRef } from "react"; 6 | 7 | import { generateOutputFilename, getSuccessMessage } from "./lib/utils.ts"; 8 | import { useBoundStore } from "./store/index.ts"; 9 | 10 | function DownloadModal() { 11 | const posthog = useBoundStore((state) => state.posthog); 12 | const mode = useBoundStore((state) => state.mode); 13 | const successCount = useBoundStore((state) => state.successCount); 14 | const status = useBoundStore((state) => state.status); 15 | const setStatus = useBoundStore((state) => state.setStatus); 16 | const inputFile = useBoundStore((state) => state.inputFile); 17 | const outputImage = useBoundStore((state) => state.outputImage); 18 | const outputImageDataUrl = useBoundStore((state) => state.outputImageDataUrl); 19 | 20 | const outputImageRef = useRef<null | HTMLImageElement>(null); 21 | 22 | function closeModal() { 23 | posthog.capture("user_closed_download_modal"); 24 | setStatus("READY"); 25 | } 26 | 27 | function downloadOutput() { 28 | posthog.capture("user_downloaded_emoji"); 29 | if (outputImage && inputFile) { 30 | saveAs(outputImage, generateOutputFilename(inputFile)); 31 | } 32 | closeModal(); 33 | } 34 | 35 | function onModalOpenChange(open: boolean) { 36 | if (open && outputImageRef.current) { 37 | posthog.capture("user_opened_download_modal"); 38 | 39 | if (mode === "HEDGEHOG") { 40 | const hedgehog = document.createElement("span"); 41 | hedgehog.innerText = "🦔"; 42 | hedgehog.style.fontSize = "48px"; 43 | const heart = document.createElement("span"); 44 | heart.innerText = "💖"; 45 | heart.style.fontSize = "24px"; 46 | party.confetti(outputImageRef.current, { shapes: [hedgehog, heart] }); 47 | } else { 48 | party.confetti(outputImageRef.current); 49 | } 50 | } 51 | } 52 | 53 | function renderOutputImage() { 54 | return ( 55 | <div className="flex flex-col items-center"> 56 | <img ref={outputImageRef} src={outputImageDataUrl} /> 57 | </div> 58 | ); 59 | } 60 | 61 | return ( 62 | <Modal 63 | title={getSuccessMessage(successCount)} 64 | open={status === "DONE"} 65 | onCancel={closeModal} 66 | destroyOnClose 67 | afterOpenChange={onModalOpenChange} 68 | footer={[ 69 | <Button 70 | key="download" 71 | type="primary" 72 | onClick={downloadOutput} 73 | icon={<DownloadOutlined />} 74 | > 75 | Download 76 | </Button>, 77 | ]} 78 | width={304} 79 | > 80 | {renderOutputImage()} 81 | </Modal> 82 | ); 83 | } 84 | 85 | export default DownloadModal; 86 | -------------------------------------------------------------------------------- /src/FileInput.tsx: -------------------------------------------------------------------------------- 1 | import { SmileOutlined } from "@ant-design/icons"; 2 | import { Button, Input, Space, Spin, Typography, Upload } from "antd"; 3 | import type { UploadProps } from "antd"; 4 | import { useState } from "react"; 5 | 6 | import groupImageUrl from "./assets/example-group.jpg"; 7 | import personImageUrl from "./assets/example-person.jpg"; 8 | import portraitImageUrl from "./assets/example-portrait.jpg"; 9 | import { useBoundStore } from "./store/index.ts"; 10 | 11 | const { Link, Paragraph } = Typography; 12 | const { Dragger } = Upload; 13 | 14 | const EXAMPLE_IMAGES = [personImageUrl, portraitImageUrl, groupImageUrl]; 15 | 16 | export default function FileInput() { 17 | const [imageUrl, setImageUrl] = useState(""); 18 | 19 | const posthog = useBoundStore((state) => state.posthog); 20 | const status = useBoundStore((state) => state.status); 21 | const setStatus = useBoundStore((state) => state.setStatus); 22 | const setInputFile = useBoundStore((state) => state.setInputFile); 23 | 24 | function handleImageUrlChange(event: React.ChangeEvent<HTMLInputElement>) { 25 | setImageUrl(event.target.value); 26 | } 27 | 28 | async function handleImageUrlSubmit() { 29 | setStatus("LOADING"); 30 | 31 | posthog.capture("user_submitted_image_url"); 32 | const response = await fetch(imageUrl); 33 | const data = await response.blob(); 34 | const contentType = response.headers.get("content-type") || "image/jpeg"; 35 | const metadata = { 36 | type: contentType, 37 | }; 38 | const file = new File([data], "image", metadata); 39 | handleFileSelected(file); 40 | } 41 | 42 | async function handleExampleClick( 43 | event: React.MouseEvent<HTMLElement, MouseEvent>, 44 | ) { 45 | const imageUrl = event.currentTarget.dataset.url as string; 46 | posthog.capture("user_selected_example_image", { 47 | imageUrl, 48 | }); 49 | const response = await fetch(imageUrl); 50 | const data = await response.blob(); 51 | const metadata = { 52 | type: "image/jpeg", 53 | }; 54 | const file = new File([data], "example.jpg", metadata); 55 | handleFileSelected(file); 56 | } 57 | 58 | function handleFileSelected(selectedFile: File) { 59 | setStatus("LOADING"); 60 | setInputFile(selectedFile); 61 | } 62 | 63 | const props: UploadProps = { 64 | className: "flex flex-1", 65 | name: "file", 66 | multiple: false, 67 | accept: "image/png, image/jpeg", 68 | showUploadList: false, 69 | customRequest: (info) => { 70 | handleFileSelected(info.file as File); 71 | }, 72 | }; 73 | 74 | function renderExample(imageUrl: string) { 75 | return ( 76 | <Link key={imageUrl} data-url={imageUrl} onClick={handleExampleClick}> 77 | <img src={imageUrl} /> 78 | </Link> 79 | ); 80 | } 81 | 82 | const fileInput = ( 83 | <> 84 | <Dragger disabled={status === "LOADING"} {...props}> 85 | <p className="ant-upload-drag-icon"> 86 | <SmileOutlined /> 87 | </p> 88 | <p className="ant-upload-text"> 89 | Click or drag file to this area to start! 90 | </p> 91 | </Dragger> 92 | <Paragraph className="text-center my-2">Or paste an image URL:</Paragraph> 93 | <Space.Compact className="w-full"> 94 | <Input 95 | placeholder="https://example.com/image.jpg" 96 | value={imageUrl} 97 | onChange={handleImageUrlChange} 98 | /> 99 | <Button 100 | type="primary" 101 | onClick={handleImageUrlSubmit} 102 | disabled={imageUrl.length === 0} 103 | > 104 | Submit 105 | </Button> 106 | </Space.Compact> 107 | <Paragraph className="text-center my-2">Or try these examples:</Paragraph> 108 | <div className="grid grid-cols-3 gap-2 items-center"> 109 | {EXAMPLE_IMAGES.map(renderExample)} 110 | </div> 111 | </> 112 | ); 113 | 114 | if (status === "START") { 115 | return ( 116 | <Spin tip="Loading AI models for face detection...">{fileInput}</Spin> 117 | ); 118 | } 119 | 120 | return fileInput; 121 | } 122 | -------------------------------------------------------------------------------- /src/Footer.tsx: -------------------------------------------------------------------------------- 1 | import { GithubOutlined } from "@ant-design/icons"; 2 | import { Typography } from "antd"; 3 | 4 | const { Text, Link } = Typography; 5 | 6 | export default function Title() { 7 | return ( 8 | <div className="text-center"> 9 | <Text className="sm:flex justify-center gap-1" type="secondary"> 10 | <div> 11 | Made with passion by{" "} 12 | <Link href="https://klimer.eu/" target="_blank"> 13 | Igor Klimer 14 | </Link> 15 | . 16 | </div> 17 | <div> 18 | Source code on 19 | <Link 20 | className="ms-2" 21 | href="https://github.com/klimeryk/dealwithit" 22 | target="_blank" 23 | > 24 | <GithubOutlined className="mr-1" /> 25 | GitHub 26 | </Link> 27 | . 28 | </div> 29 | </Text> 30 | </div> 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /src/GlassesColorPicker.tsx: -------------------------------------------------------------------------------- 1 | import { ColorPicker } from "antd"; 2 | import type { AggregationColor } from "antd/es/color-picker/color"; 3 | 4 | import { useBoundStore } from "./store/index.ts"; 5 | 6 | interface GlassesColorPickerProps { 7 | disabled: boolean; 8 | glasses: Glasses; 9 | } 10 | 11 | function GlassesColorPicker({ disabled, glasses }: GlassesColorPickerProps) { 12 | const updateStyleColor = useBoundStore((state) => state.updateStyleColor); 13 | 14 | function handleColorChange(_: AggregationColor, css: string) { 15 | updateStyleColor(glasses.id, css); 16 | } 17 | 18 | return ( 19 | <span title="Color of the glasses"> 20 | <ColorPicker 21 | defaultValue="#000000" 22 | size="small" 23 | onChange={handleColorChange} 24 | disabled={disabled} 25 | /> 26 | </span> 27 | ); 28 | } 29 | 30 | export default GlassesColorPicker; 31 | -------------------------------------------------------------------------------- /src/GlassesDraggable.tsx: -------------------------------------------------------------------------------- 1 | import { DndContext, useDraggable } from "@dnd-kit/core"; 2 | import type { DragMoveEvent } from "@dnd-kit/core"; 3 | import { CSS } from "@dnd-kit/utilities"; 4 | import { useState } from "react"; 5 | 6 | import { getAspectRatio } from "./lib/glasses.ts"; 7 | import { getFlipTransform } from "./lib/utils.ts"; 8 | import ResizeHandle from "./ResizeHandle.tsx"; 9 | import { useBoundStore } from "./store/index.ts"; 10 | 11 | interface GlassesDraggableProps { 12 | glasses: Glasses; 13 | inputImageRef: React.RefObject<HTMLImageElement>; 14 | } 15 | 16 | const MIN_WIDTH = 16; 17 | 18 | function GlassesDraggable({ glasses, inputImageRef }: GlassesDraggableProps) { 19 | const { 20 | attributes, 21 | listeners, 22 | setNodeRef: setDraggableRef, 23 | transform, 24 | } = useDraggable({ 25 | id: glasses.id, 26 | }); 27 | 28 | const updateGlassesSize = useBoundStore((state) => state.updateSize); 29 | const posthog = useBoundStore((state) => state.posthog); 30 | 31 | const [startSize, setStartSize] = useState({ width: 0, height: 0 }); 32 | 33 | function handleDragStart() { 34 | setStartSize(glasses.size); 35 | } 36 | 37 | function handleDragMove({ delta }: DragMoveEvent) { 38 | if (!inputImageRef.current) { 39 | return; 40 | } 41 | 42 | let newWidth = startSize.width + delta.x; 43 | if (newWidth < MIN_WIDTH) { 44 | newWidth = MIN_WIDTH; 45 | } 46 | const maxWidthRelativeToParent = 47 | inputImageRef.current.width - glasses.coordinates.x; 48 | if (newWidth > maxWidthRelativeToParent) { 49 | newWidth = maxWidthRelativeToParent; 50 | } 51 | let newHeight = newWidth / getAspectRatio(glasses.styleUrl); 52 | const maxHeightRelativeToParent = 53 | inputImageRef.current.height - glasses.coordinates.y; 54 | if (newHeight > maxHeightRelativeToParent) { 55 | newHeight = maxHeightRelativeToParent; 56 | newWidth = glasses.size.width; 57 | } 58 | 59 | updateGlassesSize(glasses.id, { width: newWidth, height: newHeight }); 60 | } 61 | 62 | function handleDragEnd() { 63 | posthog.capture("user_resized_glasses"); 64 | } 65 | 66 | const clipPath = { 67 | top: 0, 68 | right: 0, 69 | bottom: 0, 70 | left: 0, 71 | }; 72 | 73 | const positionX = glasses.coordinates.x + (transform?.x || 0); 74 | if (positionX < 0) { 75 | clipPath.left = Math.abs(positionX); 76 | } else if ( 77 | inputImageRef.current && 78 | positionX + glasses.size.width > inputImageRef.current.width 79 | ) { 80 | clipPath.right = Math.abs( 81 | positionX + glasses.size.width - inputImageRef.current.width, 82 | ); 83 | } 84 | 85 | const positionY = glasses.coordinates.y + (transform?.y || 0); 86 | if (positionY < 0) { 87 | clipPath.top = Math.abs(positionY); 88 | } else if ( 89 | inputImageRef.current && 90 | positionY + glasses.size.height > inputImageRef.current.height 91 | ) { 92 | clipPath.bottom = Math.abs( 93 | positionY + glasses.size.height - inputImageRef.current.height, 94 | ); 95 | } 96 | 97 | const glassesStyle = { 98 | transform: CSS.Translate.toString(transform), 99 | left: glasses.coordinates.x, 100 | top: glasses.coordinates.y, 101 | zIndex: glasses.isSelected ? 20 : 10, 102 | width: `${glasses.size.width}px`, 103 | height: `${glasses.size.height}px`, 104 | clipPath: `inset(${clipPath.top}px ${clipPath.right}px ${clipPath.bottom}px ${clipPath.left}px)`, 105 | }; 106 | 107 | const imageStyle = { 108 | transform: getFlipTransform(glasses), 109 | width: `${glasses.size.width}px`, 110 | height: `${glasses.size.height}px`, 111 | }; 112 | 113 | return ( 114 | <span 115 | className="absolute w-1/2 left-0 top-0 touch-none" 116 | ref={setDraggableRef} 117 | style={glassesStyle} 118 | > 119 | <img 120 | src={glasses.styleUrl} 121 | style={imageStyle} 122 | className={"cursor-move " + (glasses.isSelected ? "invert" : "")} 123 | {...attributes} 124 | {...listeners} 125 | /> 126 | <DndContext 127 | onDragStart={handleDragStart} 128 | onDragMove={handleDragMove} 129 | onDragEnd={handleDragEnd} 130 | > 131 | <ResizeHandle item={glasses} /> 132 | </DndContext> 133 | </span> 134 | ); 135 | } 136 | 137 | export default GlassesDraggable; 138 | -------------------------------------------------------------------------------- /src/InputImage.tsx: -------------------------------------------------------------------------------- 1 | import { DeleteOutlined } from "@ant-design/icons"; 2 | import { DndContext } from "@dnd-kit/core"; 3 | import type { DragEndEvent } from "@dnd-kit/core"; 4 | import { Button } from "antd"; 5 | 6 | import GlassesDraggable from "./GlassesDraggable.tsx"; 7 | import FlipH from "./icons/FlipH.tsx"; 8 | import FlipV from "./icons/FlipV.tsx"; 9 | import { restrictToParentWithOffset } from "./lib/drag-modifiers.ts"; 10 | import { getFlipTransform } from "./lib/utils.ts"; 11 | import { useBoundStore } from "./store/index.ts"; 12 | 13 | interface InputImageProps { 14 | onInputImageLoad: () => void; 15 | 16 | inputImageRef: React.RefObject<HTMLImageElement>; 17 | } 18 | 19 | function InputImage({ onInputImageLoad, inputImageRef }: InputImageProps) { 20 | const messageApi = useBoundStore((state) => state.messageApi); 21 | const posthog = useBoundStore((state) => state.posthog); 22 | const status = useBoundStore((state) => state.status); 23 | const goBackToStart = useBoundStore((state) => state.goBackToStart); 24 | const imageOptions = useBoundStore((state) => state.imageOptions); 25 | const toggleImageOption = useBoundStore((state) => state.toggleImageOption); 26 | const inputImageDataUrl = useBoundStore((state) => state.inputImageDataUrl); 27 | const glassesList = useBoundStore((state) => state.glassesList); 28 | const updateCoordinates = useBoundStore((state) => state.updateCoordinates); 29 | 30 | const imageStyle = { 31 | transform: getFlipTransform(imageOptions), 32 | }; 33 | 34 | function handleImageOptionsChange( 35 | event: React.MouseEvent<HTMLElement, MouseEvent>, 36 | ) { 37 | const field = event.currentTarget.dataset.field as string; 38 | if (field !== "flipVertically" && field !== "flipHorizontally") { 39 | return; 40 | } 41 | 42 | toggleImageOption(field); 43 | } 44 | 45 | function handleRemoveInputImage() { 46 | posthog.capture("user_removed_input_image"); 47 | 48 | goBackToStart(); 49 | } 50 | 51 | function handleInputImageError() { 52 | messageApi?.warning( 53 | "The file could not be loaded - make sure it's a valid image file.", 54 | ); 55 | posthog.capture("user_uploaded_invalid_input_image"); 56 | 57 | goBackToStart(); 58 | } 59 | 60 | function handleDragEnd({ delta, active }: DragEndEvent) { 61 | updateCoordinates(active.id as nanoId, delta); 62 | } 63 | 64 | function renderGlasses(glasses: Glasses) { 65 | return ( 66 | <GlassesDraggable 67 | key={glasses.id} 68 | glasses={glasses} 69 | inputImageRef={inputImageRef} 70 | /> 71 | ); 72 | } 73 | 74 | const isLoading = status !== "READY"; 75 | 76 | return ( 77 | <DndContext 78 | onDragEnd={handleDragEnd} 79 | modifiers={[restrictToParentWithOffset]} 80 | > 81 | <div className="flex flex-col gap-2 items-center"> 82 | <div className="relative select-none"> 83 | <img 84 | style={imageStyle} 85 | ref={inputImageRef} 86 | src={inputImageDataUrl} 87 | onError={handleInputImageError} 88 | onLoad={onInputImageLoad} 89 | draggable={false} 90 | /> 91 | {glassesList.map(renderGlasses)} 92 | </div> 93 | <div className="flex justify-between w-full"> 94 | <div className="flex gap-2"> 95 | <Button 96 | title="Flip image horizontally" 97 | size="small" 98 | icon={<FlipH />} 99 | data-field="flipHorizontally" 100 | disabled={isLoading} 101 | onClick={handleImageOptionsChange} 102 | /> 103 | <Button 104 | title="Flip image vertically" 105 | size="small" 106 | icon={<FlipV />} 107 | data-field="flipVertically" 108 | disabled={isLoading} 109 | onClick={handleImageOptionsChange} 110 | /> 111 | </div> 112 | <Button 113 | type="dashed" 114 | danger 115 | size="small" 116 | icon={<DeleteOutlined />} 117 | disabled={isLoading} 118 | onClick={handleRemoveInputImage} 119 | > 120 | Remove image 121 | </Button> 122 | </div> 123 | </div> 124 | </DndContext> 125 | ); 126 | } 127 | 128 | export default InputImage; 129 | -------------------------------------------------------------------------------- /src/ResizeHandle.tsx: -------------------------------------------------------------------------------- 1 | import { useDraggable } from "@dnd-kit/core"; 2 | 3 | interface ResizeHandleProps { 4 | item: WithNanoId; 5 | } 6 | 7 | function ResizeHandle({ item }: ResizeHandleProps) { 8 | const { 9 | attributes, 10 | listeners, 11 | setNodeRef: setDraggableRef, 12 | } = useDraggable({ 13 | id: item.id + "-handle", 14 | }); 15 | 16 | const handleStyle = { 17 | bottom: 0, 18 | right: 0, 19 | width: "16px", 20 | height: "16px", 21 | cursor: "nwse-resize", 22 | }; 23 | 24 | return ( 25 | <span 26 | ref={setDraggableRef} 27 | className="absolute" 28 | style={handleStyle} 29 | {...attributes} 30 | {...listeners} 31 | > 32 | <svg 33 | xmlns="http://www.w3.org/2000/svg" 34 | width="1em" 35 | height="1em" 36 | viewBox="0 0 16 16" 37 | > 38 | <path 39 | fill="currentColor" 40 | d="M6.7 16L16 6.7V5.3L5.3 16zm3 0L16 9.7V8.3L8.3 16zm3 0l3.3-3.3v-1.4L11.3 16zm3 0l.3-.3v-1.4L14.3 16z" 41 | ></path> 42 | </svg> 43 | </span> 44 | ); 45 | } 46 | 47 | export default ResizeHandle; 48 | -------------------------------------------------------------------------------- /src/SettingsDrawer.tsx: -------------------------------------------------------------------------------- 1 | import { MoonOutlined, SunOutlined } from "@ant-design/icons"; 2 | import { Drawer, Form, Segmented, Switch, Typography } from "antd"; 3 | 4 | import { useBoundStore } from "./store/index.ts"; 5 | 6 | const { Link, Paragraph, Title } = Typography; 7 | 8 | function SettingsDrawer() { 9 | const isOpen = useBoundStore((state) => state.isDrawerOpen); 10 | const setDrawerOpen = useBoundStore((state) => state.setDrawerOpen); 11 | const posthog = useBoundStore((state) => state.posthog); 12 | const theme = useBoundStore((state) => state.themeMode); 13 | const setTheme = useBoundStore((state) => state.setThemeMode); 14 | 15 | function handleClose() { 16 | setDrawerOpen(false); 17 | } 18 | 19 | function handleTrackingChange(isEnabled: boolean) { 20 | if (isEnabled) { 21 | posthog.opt_in_capturing(); 22 | } else { 23 | posthog.opt_out_capturing(); 24 | } 25 | } 26 | return ( 27 | <Drawer title="Settings and help" onClose={handleClose} open={isOpen}> 28 | <Title level={4}>Settings 29 | }, 34 | { label: "Dark mode", value: "dark", icon: }, 35 | ]} 36 | /> 37 | 42 | 46 | 47 | About 48 | 49 |
    50 |
  • 51 | All operations done fully client-side - no backend, no private data 52 | leaves your browser. 53 |
  • 54 |
  • 55 | Uses{" "} 56 | 60 | MediaPipe Face Detector task 61 | {" "} 62 | to automatically scale and position glasses on the detected faces. 63 |
  • 64 |
  • 65 | Extensive customization options for glasses: 66 |
      67 |
    • 68 | Placement of glasses anywhere on the input image (including 69 | slightly going outside it). 70 |
    • 71 |
    • Change the size of glasses.
    • 72 |
    • 73 | Change the color of glasses to any RGBA color (only applies to 74 | Classic style). 75 |
    • 76 |
    • No limit on the number of glasses.
    • 77 |
    • Flip the glasses vertically or horizontally.
    • 78 |
    • 79 | Customize the direction from which the glasses appear on the 80 | image. 81 |
    • 82 |
    • Different types of glasses.
    • 83 |
    84 |
  • 85 |
  • 86 | GIF output options: 87 |
      88 |
    • Looping mode.
    • 89 |
    • Number of frames.
    • 90 |
    • Frame delay.
    • 91 |
    • Separate delay setting for last frame.
    • 92 |
    • Output size.
    • 93 |
    94 |
  • 95 |
  • 96 | Anonymous product analytics using{" "} 97 | 98 | PostHog 99 | 100 | , requiring explicit opt-in. 101 |
  • 102 |
  • Celebration confetti 🎉
  • 103 |
  • Easter eggs.
  • 104 |
105 |
106 | 107 | ); 108 | } 109 | 110 | export default SettingsDrawer; 111 | -------------------------------------------------------------------------------- /src/SortableGlassesItem.tsx: -------------------------------------------------------------------------------- 1 | import { DeleteOutlined, EyeOutlined, HolderOutlined } from "@ant-design/icons"; 2 | import { useSortable } from "@dnd-kit/sortable"; 3 | import { CSS } from "@dnd-kit/utilities"; 4 | import { Button, Select } from "antd"; 5 | 6 | import glassesSmallImageUrl from "./assets/glasses-small.png"; 7 | import glassesSymmetricalPartyImageUrl from "./assets/glasses-symmetrical-party.png"; 8 | import glassesSymmetricalImageUrl from "./assets/glasses-symmetrical.png"; 9 | import glassesImageUrl from "./assets/glasses.png"; 10 | import GlassesColorPicker from "./GlassesColorPicker.tsx"; 11 | import FlipH from "./icons/FlipH.tsx"; 12 | import FlipV from "./icons/FlipV.tsx"; 13 | import { useBoundStore } from "./store/index.ts"; 14 | 15 | interface SortableGlassesItemProps { 16 | glasses: Glasses; 17 | } 18 | 19 | function SortableGlassesItem({ glasses }: SortableGlassesItemProps) { 20 | const { attributes, listeners, setNodeRef, transform, transition } = 21 | useSortable({ id: glasses.id }); 22 | 23 | const status = useBoundStore((state) => state.status); 24 | const flipGlasses = useBoundStore((state) => state.flip); 25 | const removeGlasses = useBoundStore((state) => state.remove); 26 | const selectGlasses = useBoundStore((state) => state.select); 27 | const updateGlassesDirection = useBoundStore( 28 | (state) => state.updateDirection, 29 | ); 30 | const updateGlassesStyle = useBoundStore((state) => state.updateStyle); 31 | 32 | const style = { 33 | transform: CSS.Transform.toString(transform), 34 | transition, 35 | }; 36 | 37 | function handleDirectionChange(value: GlassesDirection) { 38 | updateGlassesDirection(glasses.id, value); 39 | } 40 | 41 | async function handleStyleChange(value: string) { 42 | updateGlassesStyle(glasses.id, value); 43 | } 44 | 45 | function handleSelectionChange( 46 | event: React.MouseEvent, 47 | ) { 48 | const id = event.currentTarget.dataset.id as nanoId; 49 | selectGlasses(id); 50 | } 51 | 52 | function handleFlipChange(event: React.MouseEvent) { 53 | const id = event.currentTarget.dataset.id as nanoId; 54 | const field = event.currentTarget.dataset.field as string; 55 | if (field !== "flipHorizontally" && field !== "flipVertically") { 56 | return; 57 | } 58 | flipGlasses(id, field); 59 | } 60 | 61 | function handleRemove(event: React.MouseEvent) { 62 | const id = event.currentTarget.dataset.id as nanoId; 63 | removeGlasses(id); 64 | } 65 | 66 | const styleOptions = [ 67 | { 68 | label: ( 69 |
70 | Classic 71 | 🎨 72 |
73 | ), 74 | value: glassesImageUrl, 75 | }, 76 | { 77 | label: "Small", 78 | value: glassesSmallImageUrl, 79 | }, 80 | { 81 | label: "Symmetrical", 82 | value: glassesSymmetricalImageUrl, 83 | }, 84 | { 85 | label: "Party", 86 | value: glassesSymmetricalPartyImageUrl, 87 | }, 88 | ]; 89 | 90 | const directionOptions = [ 91 | { 92 | label: "⬇️", 93 | value: "up", 94 | }, 95 | { 96 | label: "⬆️", 97 | value: "down", 98 | }, 99 | { 100 | label: "➡️", 101 | value: "left", 102 | }, 103 | { 104 | label: "⬅️", 105 | value: "right", 106 | }, 107 | ]; 108 | 109 | const isLoading = status !== "READY"; 110 | 111 | return ( 112 |
  • 117 |
    118 |
    119 |
    173 |
    174 |
    175 |
    193 | 194 |
  • 195 | ); 196 | } 197 | 198 | export default SortableGlassesItem; 199 | -------------------------------------------------------------------------------- /src/SortableGlassesList.tsx: -------------------------------------------------------------------------------- 1 | import { PlusCircleOutlined } from "@ant-design/icons"; 2 | import { closestCenter, DndContext } from "@dnd-kit/core"; 3 | import type { DragEndEvent } from "@dnd-kit/core"; 4 | import { 5 | restrictToParentElement, 6 | restrictToVerticalAxis, 7 | } from "@dnd-kit/modifiers"; 8 | import { 9 | SortableContext, 10 | verticalListSortingStrategy, 11 | } from "@dnd-kit/sortable"; 12 | import { Alert, Button, Card } from "antd"; 13 | 14 | import SortableGlassesItem from "./SortableGlassesItem.tsx"; 15 | import { useBoundStore } from "./store/index.ts"; 16 | 17 | function SortableGlassesList() { 18 | const status = useBoundStore((state) => state.status); 19 | const glassesList = useBoundStore((state) => state.glassesList); 20 | const addDefaultGlasses = useBoundStore((state) => state.addDefault); 21 | const reorderGlasses = useBoundStore((state) => state.reorder); 22 | 23 | function renderGlassesItem(glasses: Glasses) { 24 | return ; 25 | } 26 | 27 | function handleGlassesItemDragEnd({ active, over }: DragEndEvent) { 28 | const oldId = active.id as nanoId; 29 | const newId = over?.id as nanoId; 30 | reorderGlasses(oldId, newId); 31 | } 32 | 33 | const cardStyles = { 34 | body: { 35 | padding: 0, 36 | }, 37 | }; 38 | 39 | return ( 40 | } 50 | disabled={status !== "READY"} 51 | onClick={addDefaultGlasses} 52 | > 53 | Add 54 | 55 | } 56 | > 57 | 62 | 66 |
      67 | {glassesList.map(renderGlassesItem)} 68 | {glassesList.length === 0 && ( 69 | } 79 | onClick={addDefaultGlasses} 80 | > 81 | Add 82 | 83 | } 84 | /> 85 | )} 86 |
    87 |
    88 |
    89 |
    90 | ); 91 | } 92 | 93 | export default SortableGlassesList; 94 | -------------------------------------------------------------------------------- /src/ThemeSwitcher.tsx: -------------------------------------------------------------------------------- 1 | import { ConfigProvider, message, theme } from "antd"; 2 | import { useEffect } from "react"; 3 | 4 | import { useBoundStore } from "./store/index.ts"; 5 | 6 | type Props = { 7 | children: React.ReactNode; 8 | }; 9 | 10 | export function ThemeSwitcher({ children }: Props) { 11 | const [messageApi, contextHolder] = message.useMessage(); 12 | const setMessageApi = useBoundStore((state) => state.setMessageApi); 13 | const themeMode = useBoundStore((state) => state.themeMode); 14 | const isDarkMode = themeMode === "dark"; 15 | useEffect(() => { 16 | if (isDarkMode) { 17 | localStorage.setItem("theme", "dark"); 18 | document.documentElement.classList.add("dark"); 19 | } else { 20 | localStorage.setItem("theme", "light"); 21 | document.documentElement.classList.remove("dark"); 22 | } 23 | setMessageApi(messageApi); 24 | }, [isDarkMode, setMessageApi, messageApi]); 25 | 26 | return ( 27 | 32 | {contextHolder} 33 | {children} 34 | 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /src/Title.tsx: -------------------------------------------------------------------------------- 1 | import glassesImageUrl from "./assets/glasses.png"; 2 | 3 | export default function Title() { 4 | return ( 5 | <> 6 |
    7 | 8 | Deal With It 9 | 10 |

    11 | Deal With It 12 | 17 |

    18 |
    19 |

    20 | GIF emoji generator 21 |

    22 |

    23 | All done artisanally and securely in your browser. 24 |

    25 | 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /src/assets/example-group.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/src/assets/example-group.jpg -------------------------------------------------------------------------------- /src/assets/example-person.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/src/assets/example-person.jpg -------------------------------------------------------------------------------- /src/assets/example-portrait.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/src/assets/example-portrait.jpg -------------------------------------------------------------------------------- /src/assets/glasses-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/src/assets/glasses-small.png -------------------------------------------------------------------------------- /src/assets/glasses-symmetrical-party.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/src/assets/glasses-symmetrical-party.png -------------------------------------------------------------------------------- /src/assets/glasses-symmetrical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/src/assets/glasses-symmetrical.png -------------------------------------------------------------------------------- /src/assets/glasses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klimeryk/dealwithit/07f41ead41419ba91ce56f3140aaa67291224d7f/src/assets/glasses.png -------------------------------------------------------------------------------- /src/assets/glasses.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 45 | 54 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 72 | 75 | 81 | 87 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /src/icons/FlipH.tsx: -------------------------------------------------------------------------------- 1 | export default function FlipH() { 2 | return ( 3 | 9 | 13 | 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /src/icons/FlipV.tsx: -------------------------------------------------------------------------------- 1 | export default function FlipV() { 2 | return ( 3 | 9 | 13 | 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @media (prefers-color-scheme: dark) { 6 | html { 7 | content: "dark"; 8 | } 9 | } 10 | 11 | @media (prefers-color-scheme: light) { 12 | html { 13 | content: "light"; 14 | } 15 | } 16 | 17 | @keyframes slideInFromTop { 18 | 0% { 19 | transform: translateY(-300%); 20 | } 21 | 22 | 100% { 23 | transform: translateY(0); 24 | } 25 | } 26 | 27 | img.slide-glasses { 28 | animation: 1.5s linear 0s 1 slideInFromTop; 29 | } 30 | -------------------------------------------------------------------------------- /src/index.d.ts: -------------------------------------------------------------------------------- 1 | type AppStatus = 2 | | "START" 3 | | "INPUT" 4 | | "LOADING" 5 | | "DETECTING" 6 | | "READY" 7 | | "GENERATING" 8 | | "DONE"; 9 | 10 | type AppMode = "NORMAL" | "HEDGEHOG"; 11 | 12 | type WithFlip = { 13 | flipHorizontally: boolean; 14 | flipVertically: boolean; 15 | }; 16 | 17 | type ImageOptions = WithFlip; 18 | 19 | type nanoId = string; 20 | 21 | interface WithNanoId { 22 | id: nanoId; 23 | } 24 | 25 | type GlassesDirection = "up" | "down" | "right" | "left"; 26 | 27 | type Glasses = WithFlip & 28 | WithNanoId & { 29 | coordinates: Coordinates; 30 | direction: GlassesDirection; 31 | isSelected: boolean; 32 | style: string; 33 | styleColor: string; 34 | styleUrl: string; 35 | size: Size; 36 | }; 37 | 38 | interface LoopingOptions { 39 | mode: "infinite" | "off" | "finite"; 40 | loops: number; 41 | } 42 | 43 | interface Size { 44 | width: number; 45 | height: number; 46 | } 47 | 48 | interface ToggleValue { 49 | enabled: boolean; 50 | value: Type; 51 | } 52 | 53 | interface ConfigurationOptions { 54 | looping: LoopingOptions; 55 | lastFrameDelay: ToggleValue; 56 | frameDelay: number; 57 | numberOfFrames: number; 58 | size: number; 59 | } 60 | -------------------------------------------------------------------------------- /src/lib/drag-modifiers.ts: -------------------------------------------------------------------------------- 1 | import type { Modifier } from "@dnd-kit/core"; 2 | 3 | export const restrictToParentWithOffset: Modifier = ({ 4 | containerNodeRect, 5 | draggingNodeRect, 6 | transform, 7 | }) => { 8 | if (!draggingNodeRect || !containerNodeRect) { 9 | return transform; 10 | } 11 | 12 | const value = { 13 | ...transform, 14 | }; 15 | 16 | const containerRectTop = containerNodeRect.top - draggingNodeRect.height / 2; 17 | const containerRectLeft = containerNodeRect.left - draggingNodeRect.width / 2; 18 | const containerRectWidth = containerNodeRect.width + draggingNodeRect.width; 19 | const containerRectHeight = 20 | containerNodeRect.height + draggingNodeRect.height; 21 | 22 | if (draggingNodeRect.top + transform.y <= containerRectTop) { 23 | value.y = containerRectTop - draggingNodeRect.top; 24 | } else if ( 25 | draggingNodeRect.bottom + transform.y >= 26 | containerRectTop + containerRectHeight 27 | ) { 28 | value.y = containerRectTop + containerRectHeight - draggingNodeRect.bottom; 29 | } 30 | 31 | if (draggingNodeRect.left + transform.x <= containerRectLeft) { 32 | value.x = containerRectLeft - draggingNodeRect.left; 33 | } else if ( 34 | draggingNodeRect.right + transform.x >= 35 | containerRectLeft + containerRectWidth 36 | ) { 37 | value.x = containerRectLeft + containerRectWidth - draggingNodeRect.right; 38 | } 39 | 40 | return value; 41 | }; 42 | -------------------------------------------------------------------------------- /src/lib/glasses.ts: -------------------------------------------------------------------------------- 1 | import type { Coordinates } from "@dnd-kit/core/dist/types"; 2 | import { nanoid } from "nanoid"; 3 | 4 | import glassesSmallImageUrl from "../assets/glasses-small.png"; 5 | import glassesSymmetricalPartyImageUrl from "../assets/glasses-symmetrical-party.png"; 6 | import glassesSymmetricalImageUrl from "../assets/glasses-symmetrical.png"; 7 | import glassesImageUrl from "../assets/glasses.png"; 8 | import glassesImageSvg from "../assets/glasses.svg?raw"; // eslint-disable-line import/no-unresolved 9 | 10 | export const DEFAULT_GLASSES_SIZE = 128; 11 | 12 | export function getDefaultGlasses(styleUrl = glassesImageUrl): Glasses { 13 | return { 14 | id: nanoid(), 15 | direction: "up", 16 | coordinates: { 17 | x: 35, 18 | y: 54, 19 | }, 20 | flipHorizontally: false, 21 | flipVertically: false, 22 | isSelected: false, 23 | style: styleUrl, 24 | styleColor: "#000000", 25 | styleUrl: styleUrl, 26 | size: { 27 | width: DEFAULT_GLASSES_SIZE, 28 | height: DEFAULT_GLASSES_SIZE / getAspectRatio(styleUrl), 29 | }, 30 | }; 31 | } 32 | 33 | export function getGlassesSize(style: string): Size { 34 | switch (style) { 35 | case glassesSmallImageUrl: 36 | return { width: 240, height: 60 }; 37 | 38 | case glassesSymmetricalPartyImageUrl: 39 | case glassesSymmetricalImageUrl: 40 | return { width: 832, height: 160 }; 41 | 42 | case glassesImageUrl: 43 | default: 44 | return { width: 1024, height: 165 }; 45 | } 46 | } 47 | 48 | export function getAspectRatio(style: string) { 49 | const { width, height } = getGlassesSize(style); 50 | return width / height; 51 | } 52 | 53 | export function getNoseOffset({ style }: Glasses): Coordinates { 54 | switch (style) { 55 | case glassesSmallImageUrl: 56 | return { x: 119, y: 19 }; 57 | 58 | case glassesSymmetricalPartyImageUrl: 59 | case glassesSymmetricalImageUrl: 60 | return { x: 415, y: 32 }; 61 | 62 | case glassesImageUrl: 63 | default: 64 | return { x: 660, y: 64 }; 65 | } 66 | } 67 | 68 | export function getEyesDistance({ style }: Glasses) { 69 | switch (style) { 70 | case glassesSmallImageUrl: 71 | return 140; 72 | 73 | case glassesSymmetricalPartyImageUrl: 74 | case glassesSymmetricalImageUrl: 75 | return 415; 76 | 77 | case glassesImageUrl: 78 | default: 79 | return 385; 80 | } 81 | } 82 | 83 | export function getRandomGlassesStyle(): string { 84 | const glassesStyles = [ 85 | glassesImageUrl, 86 | glassesSmallImageUrl, 87 | glassesSymmetricalImageUrl, 88 | glassesSymmetricalPartyImageUrl, 89 | ]; 90 | return glassesStyles[Math.floor(Math.random() * glassesStyles.length)]; 91 | } 92 | 93 | export async function computeStyleUrl( 94 | style: string, 95 | styleColor: string, 96 | ): Promise { 97 | if (style !== glassesImageUrl) { 98 | return style; 99 | } 100 | 101 | const dataHeader = "data:image/svg+xml;charset=utf-8"; 102 | const encodeAsUTF8 = (s: string) => `${dataHeader},${encodeURIComponent(s)}`; 103 | 104 | const loadImage = async (url: string): Promise => { 105 | const $img = document.createElement("img"); 106 | $img.src = url; 107 | return new Promise((resolve, reject) => { 108 | $img.onload = () => resolve($img); 109 | $img.onerror = reject; 110 | }); 111 | }; 112 | 113 | const coloredGlasses = glassesImageSvg.replace("#000000", styleColor); 114 | const svgData = encodeAsUTF8(coloredGlasses); 115 | const img = await loadImage(svgData); 116 | const canvas = document.createElement("canvas"); 117 | const glassesSize = getGlassesSize(style); 118 | canvas.width = glassesSize.width; 119 | canvas.height = glassesSize.height; 120 | const context = canvas.getContext("2d"); 121 | if (!context) { 122 | return glassesImageUrl; 123 | } 124 | 125 | context.drawImage(img, 0, 0, glassesSize.width, glassesSize.height); 126 | 127 | return canvas.toDataURL(`image/png`, 1.0); 128 | } 129 | -------------------------------------------------------------------------------- /src/lib/id-utils.ts: -------------------------------------------------------------------------------- 1 | export function byId(idToSearchFor: nanoId) { 2 | return ({ id }: WithNanoId) => id === idToSearchFor; 3 | } 4 | -------------------------------------------------------------------------------- /src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | export function generateOutputFilename(inputFile: File) { 2 | const nameParts = inputFile.name.split("."); 3 | nameParts.pop(); 4 | const filename = nameParts.pop(); 5 | nameParts.push(filename + "-dealwithit"); 6 | nameParts.push("gif"); 7 | return nameParts.join("."); 8 | } 9 | 10 | export function getFlipTransform({ 11 | flipHorizontally, 12 | flipVertically, 13 | }: WithFlip) { 14 | let transform = ""; 15 | if (flipVertically) { 16 | transform += "scaleY(-1) "; 17 | } 18 | if (flipHorizontally) { 19 | transform += "scaleX(-1) "; 20 | } 21 | 22 | return transform; 23 | } 24 | 25 | export function getSuccessMessage(count: number) { 26 | switch (count) { 27 | case 5: 28 | return "Is it perfect now?"; 29 | 30 | case 10: 31 | return "Wow, you really want it perfect!"; 32 | 33 | case 15: 34 | return "Your laptop must be quite warm now - hope the results are worth it!"; 35 | 36 | case 20: 37 | return "I admire your perseverance in the quest for the perfect emoji!"; 38 | 39 | case 42: 40 | return "Hope this emoji is the answer you're looking for."; 41 | 42 | case 100: 43 | return "You're actively contributing to global warming with this much CPU usage."; 44 | 45 | case Number.MAX_VALUE: 46 | return "I like the way you think! Or you have a serious problem."; 47 | } 48 | 49 | const successMessages = [ 50 | "Here's your shiny new emoji!", 51 | "Freshly baked, grab it while it's hot!", 52 | "Enjoy your new emoji!", 53 | ]; 54 | return successMessages[Math.floor(Math.random() * successMessages.length)]; 55 | } 56 | -------------------------------------------------------------------------------- /src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom/client"; 3 | 4 | import App from "./App.tsx"; 5 | import { ThemeSwitcher } from "./ThemeSwitcher.tsx"; 6 | 7 | import "./index.css"; 8 | 9 | declare global { 10 | interface Window { 11 | Jimp: typeof import("jimp"); 12 | } 13 | } 14 | 15 | ReactDOM.createRoot(document.getElementById("root")!).render( 16 | 17 | 18 | 19 | 20 | , 21 | ); 22 | -------------------------------------------------------------------------------- /src/store/index.ts: -------------------------------------------------------------------------------- 1 | import { create } from "zustand"; 2 | 3 | import { AppSlice, createAppSlice } from "./slices/app.ts"; 4 | import { 5 | createFaceDetectionSlice, 6 | FaceDetectionSlice, 7 | } from "./slices/face-detection.ts"; 8 | import { createGlassesSlice, GlassesSlice } from "./slices/glasses.ts"; 9 | import { createImageSlice, ImageSlice } from "./slices/image.ts"; 10 | import { createThemeSlice, ThemeSlice } from "./slices/theme.ts"; 11 | 12 | export const useBoundStore = create< 13 | AppSlice & FaceDetectionSlice & GlassesSlice & ImageSlice & ThemeSlice 14 | >((...a) => ({ 15 | ...createAppSlice(...a), 16 | ...createFaceDetectionSlice(...a), 17 | ...createGlassesSlice(...a), 18 | ...createImageSlice(...a), 19 | ...createThemeSlice(...a), 20 | })); 21 | -------------------------------------------------------------------------------- /src/store/slices/app.ts: -------------------------------------------------------------------------------- 1 | import { MessageInstance } from "antd/es/message/interface"; 2 | import { posthog, PostHogConfig } from "posthog-js"; 3 | import type { PostHog } from "posthog-js/react"; 4 | import { StateCreator } from "zustand"; 5 | 6 | export interface AppSlice { 7 | isDrawerOpen: boolean; 8 | messageApi: MessageInstance | undefined; 9 | mode: AppMode; 10 | posthog: PostHog; 11 | status: AppStatus; 12 | successCount: number; 13 | goBackToStart: () => void; 14 | setDrawerOpen: (isOpen: boolean) => void; 15 | setMessageApi: (messageApi: MessageInstance) => void; 16 | setMode: (newMode: AppMode) => void; 17 | setStatus: (newStatus: AppStatus) => void; 18 | } 19 | 20 | function initializePosthog() { 21 | const options: Partial = { 22 | api_host: "https://jez.emoji.build", 23 | ui_host: "https://eu.i.posthog.com", 24 | autocapture: false, 25 | opt_out_capturing_by_default: true, 26 | disable_surveys: true, 27 | disable_session_recording: true, 28 | persistence: "localStorage", 29 | }; 30 | posthog.init("phc_7SZQ8Cl3ymxNbRF8K5OLMO3VOQ51MD8Gnh6UDLU17lG", options); 31 | if (import.meta.env.DEV) { 32 | posthog.debug(); 33 | } 34 | if (!posthog.has_opted_in_capturing()) { 35 | posthog.opt_out_capturing(); 36 | } 37 | return posthog; 38 | } 39 | 40 | export const createAppSlice: StateCreator = (set) => ({ 41 | isDrawerOpen: false, 42 | messageApi: undefined, 43 | mode: "NORMAL", 44 | status: "START", 45 | successCount: 0, 46 | posthog: initializePosthog(), 47 | goBackToStart: () => 48 | set(() => ({ 49 | status: "INPUT", 50 | inputFile: undefined, 51 | inputImageDataUrl: "", 52 | glassesList: [], 53 | imageOptions: { 54 | flipVertically: false, 55 | flipHorizontally: false, 56 | }, 57 | })), 58 | setDrawerOpen: (isOpen) => set(() => ({ isDrawerOpen: isOpen })), 59 | setMessageApi: (messageApi) => set(() => ({ messageApi })), 60 | setMode: (newMode) => set(() => ({ mode: newMode })), 61 | setStatus: (newStatus) => set(() => ({ status: newStatus })), 62 | }); 63 | -------------------------------------------------------------------------------- /src/store/slices/face-detection.ts: -------------------------------------------------------------------------------- 1 | import { FaceDetector, FilesetResolver } from "@mediapipe/tasks-vision"; 2 | import { StateCreator } from "zustand"; 3 | 4 | import { 5 | getDefaultGlasses, 6 | getEyesDistance, 7 | getGlassesSize, 8 | getNoseOffset, 9 | getRandomGlassesStyle, 10 | } from "../../lib/glasses.ts"; 11 | 12 | import { AppSlice } from "./app.ts"; 13 | import { GlassesSlice } from "./glasses.ts"; 14 | 15 | export interface FaceDetectionSlice { 16 | faceDetector: FaceDetector | undefined; 17 | detectFaces: (image: HTMLImageElement) => void; 18 | } 19 | 20 | export const createFaceDetectionSlice: StateCreator< 21 | FaceDetectionSlice & AppSlice & GlassesSlice, 22 | [], 23 | [], 24 | FaceDetectionSlice 25 | > = (set, get) => { 26 | function startInitializingFaceDetector() { 27 | async function initializeFaceDetector() { 28 | const vision = await FilesetResolver.forVisionTasks( 29 | "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm", 30 | ); 31 | const faceDetector = await FaceDetector.createFromOptions(vision, { 32 | baseOptions: { 33 | modelAssetPath: `https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite`, 34 | delegate: "GPU", 35 | }, 36 | runningMode: "IMAGE", 37 | }); 38 | set(() => ({ faceDetector, status: "INPUT" })); 39 | } 40 | initializeFaceDetector(); 41 | 42 | return undefined; 43 | } 44 | 45 | return { 46 | faceDetector: startInitializingFaceDetector(), 47 | detectFaces(image: HTMLImageElement) { 48 | function getDetectedGlasses(): Glasses[] { 49 | const faceDetector = get().faceDetector; 50 | if (!faceDetector) { 51 | return [getDefaultGlasses()]; 52 | } 53 | 54 | const faces = faceDetector.detect(image).detections; 55 | if (faces.length === 0) { 56 | return [getDefaultGlasses()]; 57 | } 58 | 59 | const scaleX = image.width / image.naturalWidth; 60 | const scaleY = image.height / image.naturalHeight; 61 | 62 | const newGlassesList: Glasses[] = []; 63 | for (const face of faces) { 64 | for (const keypoint of face.keypoints) { 65 | keypoint.x *= image.naturalWidth; 66 | keypoint.y *= image.naturalHeight; 67 | } 68 | 69 | const newGlasses = 70 | faces.length === 1 71 | ? getDefaultGlasses() 72 | : getDefaultGlasses(getRandomGlassesStyle()); 73 | const originalGlassesSize = getGlassesSize(newGlasses.styleUrl); 74 | const originalEyesDistance = getEyesDistance(newGlasses); 75 | const eyesDistance = Math.sqrt( 76 | Math.pow(scaleY * (face.keypoints[0].y - face.keypoints[1].y), 2) + 77 | Math.pow(scaleX * (face.keypoints[0].x - face.keypoints[1].x), 2), 78 | ); 79 | const glassesScale = eyesDistance / originalEyesDistance; 80 | newGlasses.size.width = originalGlassesSize.width * glassesScale; 81 | newGlasses.size.height = originalGlassesSize.height * glassesScale; 82 | const noseX = face.keypoints[2].x; 83 | const noseY = Math.abs(face.keypoints[0].y - face.keypoints[1].y) / 2; 84 | const noseOffset = getNoseOffset(newGlasses); 85 | const glassesScaleX = 86 | newGlasses.size.width / originalGlassesSize.width; 87 | const glassesScaleY = 88 | newGlasses.size.height / originalGlassesSize.height; 89 | newGlasses.coordinates = { 90 | x: Math.abs(noseX * scaleX - noseOffset.x * glassesScaleX), 91 | y: Math.abs( 92 | (face.keypoints[0].y + noseY) * scaleY - 93 | noseOffset.y * glassesScaleY, 94 | ), 95 | }; 96 | 97 | newGlassesList.push(newGlasses); 98 | } 99 | 100 | return newGlassesList; 101 | } 102 | 103 | set(() => ({ glassesList: getDetectedGlasses(), status: "READY" })); 104 | }, 105 | }; 106 | }; 107 | -------------------------------------------------------------------------------- /src/store/slices/glasses.ts: -------------------------------------------------------------------------------- 1 | import type { Coordinates } from "@dnd-kit/core/dist/types"; 2 | import { arrayMove } from "@dnd-kit/sortable"; 3 | import { produce } from "immer"; 4 | import { StateCreator } from "zustand"; 5 | 6 | import { computeStyleUrl, getDefaultGlasses } from "../../lib/glasses.ts"; 7 | import { byId } from "../../lib/id-utils.ts"; 8 | 9 | export interface GlassesSlice { 10 | glassesList: Glasses[]; 11 | flip: (id: nanoId, field: keyof WithFlip) => void; 12 | addDefault: () => void; 13 | updateCoordinates: (id: nanoId, delta: Coordinates) => void; 14 | updateDirection: (id: nanoId, direction: GlassesDirection) => void; 15 | updateStyle: (id: nanoId, styleUrl: string) => void; 16 | updateStyleColor: (id: nanoId, color: string) => void; 17 | updateSize: (id: nanoId, size: Size) => void; 18 | reorder: (oldId: nanoId, newId: nanoId) => void; 19 | remove: (id: nanoId) => void; 20 | select: (id: nanoId) => void; 21 | } 22 | 23 | export const createGlassesSlice: StateCreator = (set, get) => ({ 24 | glassesList: [], 25 | addDefault: () => 26 | set( 27 | produce((draft) => { 28 | draft.glassesList.push(getDefaultGlasses()); 29 | draft.posthog.capture("user_added_glasses"); 30 | }), 31 | ), 32 | updateCoordinates: (id: nanoId, delta: Coordinates) => 33 | set( 34 | produce((draft) => { 35 | const index = draft.glassesList.findIndex(byId(id)); 36 | if (index === -1) { 37 | return; 38 | } 39 | const { x, y } = draft.glassesList[index].coordinates; 40 | draft.glassesList[index].coordinates = { 41 | x: x + delta.x, 42 | y: y + delta.y, 43 | }; 44 | draft.posthog.capture("user_dragged_glasses"); 45 | }), 46 | ), 47 | updateDirection: (id: nanoId, direction: GlassesDirection) => 48 | set( 49 | produce((draft) => { 50 | const index = draft.glassesList.findIndex(byId(id)); 51 | if (index === -1) { 52 | return; 53 | } 54 | draft.glassesList[index].direction = direction; 55 | draft.posthog.capture("user_changed_glasses_direction", { 56 | direction, 57 | }); 58 | }), 59 | ), 60 | updateStyle: async (id: nanoId, style: string) => { 61 | const index = get().glassesList.findIndex(byId(id)); 62 | if (index === -1) { 63 | return; 64 | } 65 | const newStyleUrl = await computeStyleUrl( 66 | style, 67 | get().glassesList[index].styleColor, 68 | ); 69 | return set( 70 | produce((draft) => { 71 | draft.glassesList[index].style = style; 72 | draft.glassesList[index].styleUrl = newStyleUrl; 73 | draft.posthog.capture("user_changed_glasses_style", { 74 | style, 75 | }); 76 | }), 77 | ); 78 | }, 79 | updateStyleColor: async (id: nanoId, color: string) => { 80 | const index = get().glassesList.findIndex(byId(id)); 81 | if (index === -1) { 82 | return; 83 | } 84 | 85 | const newStyleUrl = await computeStyleUrl( 86 | get().glassesList[index].style, 87 | color, 88 | ); 89 | return set( 90 | produce((draft) => { 91 | draft.glassesList[index].styleColor = color; 92 | draft.glassesList[index].styleUrl = newStyleUrl; 93 | draft.posthog.capture("user_changed_glasses_color"); 94 | }), 95 | ); 96 | }, 97 | updateSize: (id: nanoId, size: Size) => 98 | set( 99 | produce((draft) => { 100 | const index = draft.glassesList.findIndex(byId(id)); 101 | if (index === -1) { 102 | return; 103 | } 104 | draft.glassesList[index].size = size; 105 | // Don't send analytics here, as this could be fired 106 | // many times in a row. 107 | }), 108 | ), 109 | reorder: (oldId: nanoId, newId: nanoId) => 110 | set( 111 | produce((draft) => { 112 | const oldIndex = draft.glassesList.findIndex(byId(oldId)); 113 | const newIndex = draft.glassesList.findIndex(byId(newId)); 114 | if (oldIndex === -1 || newIndex === -1) { 115 | return; 116 | } 117 | draft.glassesList = arrayMove(draft.glassesList, oldIndex, newIndex); 118 | draft.posthog.capture("user_reordered_glasses"); 119 | }), 120 | ), 121 | remove: (id: nanoId) => 122 | set( 123 | produce((draft) => { 124 | const index = draft.glassesList.findIndex(byId(id)); 125 | if (index === -1) { 126 | return; 127 | } 128 | draft.glassesList.splice(index, 1); 129 | draft.posthog.capture("user_removed_glasses"); 130 | }), 131 | ), 132 | select: (id: nanoId) => 133 | set( 134 | produce((draft) => { 135 | const index = draft.glassesList.findIndex(byId(id)); 136 | if (index === -1) { 137 | return; 138 | } 139 | let previouslySelectedId; 140 | draft.glassesList = draft.glassesList.map((glasses: Glasses) => { 141 | if (glasses.isSelected) { 142 | previouslySelectedId = glasses.id; 143 | } 144 | glasses.isSelected = false; 145 | return glasses; 146 | }); 147 | if (previouslySelectedId !== id) { 148 | draft.glassesList[index].isSelected = true; 149 | draft.posthog.capture("user_selected_glasses"); 150 | } else { 151 | draft.posthog.capture("user_deselected_glasses"); 152 | } 153 | }), 154 | ), 155 | flip: (id, field) => 156 | set( 157 | produce((draft) => { 158 | const index = draft.glassesList.findIndex(byId(id)); 159 | if (index === -1) { 160 | return; 161 | } 162 | draft.glassesList[index][field] = !draft.glassesList[index][field]; 163 | draft.posthog.capture("user_flipped_glasses", { 164 | flip: field, 165 | }); 166 | }), 167 | ), 168 | }); 169 | -------------------------------------------------------------------------------- /src/store/slices/image.ts: -------------------------------------------------------------------------------- 1 | import { produce } from "immer"; 2 | import { StateCreator } from "zustand"; 3 | 4 | import { AppSlice } from "./app.ts"; 5 | 6 | export interface ImageSlice { 7 | imageOptions: ImageOptions; 8 | inputFile: File | undefined; 9 | inputImageDataUrl: string; 10 | outputImage: Blob | undefined; 11 | outputImageDataUrl: string; 12 | setInputFile: (file: File) => void; 13 | setOutputImage: (imageBlob: Blob, imageDataUrl: string) => void; 14 | toggleImageOption: (field: keyof ImageOptions) => void; 15 | } 16 | 17 | export const createImageSlice: StateCreator< 18 | ImageSlice & AppSlice, 19 | [], 20 | [], 21 | ImageSlice 22 | > = (set, get) => ({ 23 | imageOptions: { flipVertically: false, flipHorizontally: false }, 24 | inputFile: undefined, 25 | inputImageDataUrl: "", 26 | outputImage: undefined, 27 | outputImageDataUrl: "", 28 | 29 | setInputFile: async (file) => { 30 | const detectedMode = file.name.match(/(hedgehog|posthog)/gi) 31 | ? "HEDGEHOG" 32 | : "NORMAL"; 33 | 34 | get().posthog.capture("user_selected_input_file", { 35 | mode: detectedMode, 36 | fileType: file.type, 37 | }); 38 | 39 | const fileAsDataUrl = await getDataUrl(file); 40 | set(() => ({ 41 | mode: detectedMode, 42 | inputFile: file, 43 | inputImageDataUrl: fileAsDataUrl, 44 | status: "DETECTING", 45 | })); 46 | }, 47 | 48 | setOutputImage: (imageBlob, imageDataUrl) => 49 | set(() => ({ 50 | outputImage: imageBlob, 51 | outputImageDataUrl: imageDataUrl, 52 | successCount: get().successCount + 1, 53 | })), 54 | 55 | toggleImageOption: (field: keyof ImageOptions) => 56 | set( 57 | produce((draft) => { 58 | draft.imageOptions[field] = !draft.imageOptions[field]; 59 | }), 60 | ), 61 | }); 62 | 63 | function getDataUrl(file: File): Promise { 64 | return new Promise((resolve, reject) => { 65 | const reader = new FileReader(); 66 | reader.readAsDataURL(file); 67 | reader.onload = () => resolve(reader.result as string); 68 | reader.onerror = (error) => reject(error); 69 | }); 70 | } 71 | -------------------------------------------------------------------------------- /src/store/slices/theme.ts: -------------------------------------------------------------------------------- 1 | import { StateCreator } from "zustand"; 2 | 3 | export type ThemeMode = "dark" | "light"; 4 | 5 | export interface ThemeSlice { 6 | themeMode: ThemeMode; 7 | setThemeMode: (newTheme: ThemeMode) => void; 8 | } 9 | 10 | function getInitialThemeModePreference(): ThemeMode { 11 | const savedThemeMode = localStorage.getItem("theme"); 12 | if ( 13 | savedThemeMode && 14 | (savedThemeMode === "light" || savedThemeMode === "dark") 15 | ) { 16 | return savedThemeMode; 17 | } 18 | 19 | if (window.matchMedia) { 20 | if (window.matchMedia("(prefers-color-scheme: dark)").matches) { 21 | return "dark"; 22 | } 23 | } 24 | 25 | const contentThemeMode = window.getComputedStyle( 26 | document.documentElement, 27 | ).content; 28 | if ( 29 | contentThemeMode && 30 | (contentThemeMode === "light" || contentThemeMode === "dark") 31 | ) { 32 | return contentThemeMode; 33 | } 34 | 35 | return "light"; 36 | } 37 | 38 | export const createThemeSlice: StateCreator = (set) => ({ 39 | themeMode: getInitialThemeModePreference(), 40 | setThemeMode: (newThemeMode) => set(() => ({ themeMode: newThemeMode })), 41 | }); 42 | -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/worker/gif.worker.ts: -------------------------------------------------------------------------------- 1 | import "jimp/browser/lib/jimp.js"; 2 | import type { Jimp } from "@jimp/core"; 3 | import type { Blit } from "@jimp/plugin-blit"; 4 | import type { ResizeClass } from "@jimp/plugin-resize"; 5 | import { GifCodec } from "gifwrap"; 6 | 7 | import { 8 | getGlassesImages, 9 | maybeFlipImage, 10 | prepareReportProgress, 11 | renderGlassesFrame, 12 | } from "./utils.ts"; 13 | 14 | const { Jimp } = self; 15 | 16 | function getProcessedImage( 17 | image: Jimp & ResizeClass & Blit, 18 | size: number, 19 | imageOptions: ImageOptions, 20 | ) { 21 | const isImageLong = image.bitmap.width >= image.bitmap.height; 22 | const width = isImageLong ? size : Jimp.AUTO; 23 | const height = isImageLong ? Jimp.AUTO : size; 24 | 25 | const processedImage = image 26 | .clone() 27 | .resize(width, height, Jimp.RESIZE_BICUBIC); 28 | maybeFlipImage(processedImage, imageOptions); 29 | 30 | return processedImage; 31 | } 32 | 33 | self.onmessage = (event: MessageEvent) => { 34 | const { 35 | configurationOptions, 36 | glassesList, 37 | inputFile, 38 | inputImage, 39 | imageOptions, 40 | } = event.data; 41 | const { looping, numberOfFrames, size } = 42 | configurationOptions as ConfigurationOptions; 43 | const { renderedWidth, renderedHeight } = inputImage; 44 | const reader = new FileReader(); 45 | 46 | const reportProgress = prepareReportProgress(numberOfFrames); 47 | 48 | reader.onload = async () => { 49 | const originalImage = await Jimp.read(reader.result as Buffer); 50 | reportProgress(); 51 | const image = getProcessedImage(originalImage, size, imageOptions); 52 | reportProgress(); 53 | const { width, height } = image.bitmap; 54 | 55 | function getNumberOfLoops() { 56 | if (looping.mode === "infinite") { 57 | return 0; 58 | } 59 | 60 | return looping.loops; 61 | } 62 | 63 | const frames = []; 64 | const scaleX = width / renderedWidth; 65 | const scaleY = height / renderedHeight; 66 | const glassesImages = await getGlassesImages(glassesList, scaleX, scaleY); 67 | reportProgress(); 68 | for (let frameNumber = 0; frameNumber < numberOfFrames + 1; ++frameNumber) { 69 | frames.push( 70 | renderGlassesFrame( 71 | glassesList, 72 | glassesImages, 73 | image, 74 | scaleX, 75 | scaleY, 76 | frameNumber, 77 | configurationOptions, 78 | ), 79 | ); 80 | reportProgress(); 81 | } 82 | 83 | const codec = new GifCodec(); 84 | const gif = await codec.encodeGif(frames, { loops: getNumberOfLoops() }); 85 | const gifBlob = new File([gif.buffer], "", { type: "image/gif" }); 86 | reportProgress(); 87 | 88 | const fileReader = new FileReader(); 89 | fileReader.onload = () => { 90 | self.postMessage({ 91 | type: "OUTPUT", 92 | gifBlob, 93 | resultDataUrl: fileReader.result as string, 94 | }); 95 | }; 96 | fileReader.readAsDataURL(gifBlob); 97 | }; 98 | reader.readAsArrayBuffer(inputFile); 99 | }; 100 | -------------------------------------------------------------------------------- /src/worker/utils.ts: -------------------------------------------------------------------------------- 1 | import type { Bitmap, Jimp } from "@jimp/core"; 2 | import type { Blit } from "@jimp/plugin-blit"; 3 | import type { ResizeClass } from "@jimp/plugin-resize"; 4 | import { BitmapImage, GifFrame, GifUtil } from "gifwrap"; 5 | 6 | const { Jimp } = self; 7 | 8 | export function prepareReportProgress(numberOfFrames: number) { 9 | let stepNumber = 0; 10 | const numberOfSteps = numberOfFrames + 4; 11 | return function reportProgress() { 12 | ++stepNumber; 13 | self.postMessage({ 14 | type: "PROGRESS", 15 | progress: (stepNumber / numberOfSteps) * 100, 16 | }); 17 | }; 18 | } 19 | 20 | function getLastFrameDelay({ 21 | looping, 22 | lastFrameDelay, 23 | frameDelay, 24 | }: ConfigurationOptions) { 25 | if (looping.mode === "off") { 26 | // If you waited for a day, you deserve to see this workaround... 27 | // Since there is no way to not loop a gif using gifwrap, 28 | // let's just put a reeeeaaaaallly long delay after the last frame. 29 | return 8640000; 30 | } 31 | 32 | return Math.round( 33 | (lastFrameDelay.enabled && lastFrameDelay.value > 0 34 | ? lastFrameDelay.value 35 | : frameDelay) / 10, 36 | ); 37 | } 38 | 39 | function getMovementForFrame( 40 | direction: GlassesDirection, 41 | { width: imageWidth, height: imageHeight }: Bitmap, 42 | { width: glassesWidth, height: glassesHeight }: Bitmap, 43 | scaledX: number, 44 | scaledY: number, 45 | frameNumber: number, 46 | numberOfFrames: number, 47 | ) { 48 | if (direction === "up") { 49 | const yMovementPerFrame = (scaledY + glassesHeight) / numberOfFrames; 50 | return { x: scaledX, y: frameNumber * yMovementPerFrame - glassesHeight }; 51 | } 52 | if (direction === "down") { 53 | const yMovementPerFrame = (imageHeight - scaledY) / numberOfFrames; 54 | return { 55 | x: scaledX, 56 | y: imageHeight - frameNumber * yMovementPerFrame, 57 | }; 58 | } 59 | if (direction === "left") { 60 | const xMovementPerFrame = (scaledX + glassesWidth) / numberOfFrames; 61 | return { x: frameNumber * xMovementPerFrame - glassesWidth, y: scaledY }; 62 | } else { 63 | const xMovementPerFrame = (imageWidth - scaledX) / numberOfFrames; 64 | return { 65 | x: imageWidth - frameNumber * xMovementPerFrame, 66 | y: scaledY, 67 | }; 68 | } 69 | } 70 | 71 | export function renderGlassesFrame( 72 | glassesList: Glasses[], 73 | glassesImages: Record, 74 | originalImage: Jimp & Blit, 75 | scaleX: number, 76 | scaleY: number, 77 | frameNumber: number, 78 | configurationOptions: ConfigurationOptions, 79 | ) { 80 | const { numberOfFrames, frameDelay } = configurationOptions; 81 | const jimpFrame = originalImage.clone(); 82 | for (const glasses of glassesList) { 83 | const scaledX = scaleX * glasses.coordinates.x; 84 | const scaledY = scaleY * glasses.coordinates.y; 85 | const movement = getMovementForFrame( 86 | glasses.direction, 87 | originalImage.bitmap, 88 | glassesImages[glasses.id].bitmap, 89 | scaledX, 90 | scaledY, 91 | frameNumber, 92 | numberOfFrames, 93 | ); 94 | jimpFrame.blit(glassesImages[glasses.id], movement.x, movement.y); 95 | } 96 | const jimpBitmap = new BitmapImage(jimpFrame.bitmap); 97 | GifUtil.quantizeDekker(jimpBitmap, 64); 98 | return new GifFrame(jimpBitmap, { 99 | delayCentisecs: 100 | frameNumber !== numberOfFrames 101 | ? Math.round(frameDelay / 10) 102 | : getLastFrameDelay(configurationOptions), 103 | }); 104 | } 105 | 106 | export function maybeFlipImage( 107 | image: Jimp, 108 | { flipHorizontally, flipVertically }: WithFlip, 109 | ) { 110 | if (flipHorizontally || flipVertically) { 111 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 112 | (image as any).flip(flipHorizontally, flipVertically); 113 | } 114 | 115 | return image; 116 | } 117 | 118 | const glassesImagesCache: Record = {}; 119 | 120 | export async function getGlassesImages( 121 | glassesList: Glasses[], 122 | scaleX: number, 123 | scaleY: number, 124 | ) { 125 | const outputList = {} as Record; 126 | for (const glasses of glassesList) { 127 | const cacheKey = `${glasses.styleUrl} ${glasses.size.width} ${glasses.size.height} ${scaleX} ${scaleY}`; 128 | if (!glassesImagesCache[cacheKey]) { 129 | const glassesImage = await Jimp.read(glasses.styleUrl); 130 | glassesImagesCache[cacheKey] = glassesImage.resize( 131 | scaleX * glasses.size.width, 132 | scaleY * glasses.size.height, 133 | Jimp.RESIZE_BICUBIC, 134 | ); 135 | } 136 | const glassesImage = glassesImagesCache[cacheKey].clone(); 137 | maybeFlipImage(glassesImage, glasses); 138 | outputList[glasses.id] = glassesImage; 139 | } 140 | return outputList; 141 | } 142 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], 4 | darkMode: "selector", 5 | theme: { 6 | extend: {}, 7 | }, 8 | plugins: [], 9 | }; 10 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", 5 | "target": "ES2020", 6 | "useDefineForClassFields": true, 7 | "lib": [ 8 | "ES2022", 9 | "DOM", 10 | "DOM.Iterable", 11 | "webworker" 12 | ], 13 | "module": "ESNext", 14 | "skipLibCheck": true, 15 | /* Bundler mode */ 16 | "moduleResolution": "bundler", 17 | "allowImportingTsExtensions": true, 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "moduleDetection": "force", 21 | "noEmit": true, 22 | "jsx": "react-jsx", 23 | /* Linting */ 24 | "strict": true, 25 | "noUnusedLocals": true, 26 | "noUnusedParameters": true, 27 | "noFallthroughCasesInSwitch": true 28 | }, 29 | "include": [ 30 | "src" 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [ 4 | { 5 | "path": "./tsconfig.app.json" 6 | }, 7 | { 8 | "path": "./tsconfig.node.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", 5 | "skipLibCheck": true, 6 | "module": "ESNext", 7 | "moduleResolution": "bundler", 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "noEmit": true 11 | }, 12 | "include": ["vite.config.ts"] 13 | } 14 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import react from "@vitejs/plugin-react"; 2 | import { defineConfig } from "vite"; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | base: "/deal-with-it-generator/", 7 | plugins: [react()], 8 | build: { 9 | outDir: "dist/deal-with-it-generator", 10 | }, 11 | }); 12 | --------------------------------------------------------------------------------