├── .github
└── FUNDING.yml
├── LICENSE
├── README.md
├── docs
├── components.md
├── introducing-yumjs.md
└── todo.md
├── images
├── gitlogo.png
└── yumlogo.png
├── yum.js
└── yum.min.js
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # Supported funding model platforms
2 | patreon: yumjs
3 |
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 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 General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Deprecated
4 | see https://github.com/bretgeek/surf
5 |
6 | # YumJS
7 | YumJS is a small reactive JavaScript library with JQuery like syntax.
8 |
9 | Small as in ~19KB minified with drag ~15KB minified without drag and about half of that if served gzipped.
10 |
11 | Please see https://surf.monster for ongoing documentation, minified downloads and optional builds.
12 |
13 |
14 | Yum provides a familiar **procedural** and a **component** based syntax with low overhead and a slice of delicious reactivity when you need it.
15 |
16 |
17 | **Funding:** https://www.patreon.com/yumjs?fan_landing=true
18 |
19 | ## Features
20 |
21 | - Simple, easy to learn with familiar syntax.
22 | - Optional component (rendering) syntax with props and state.
23 | - A lightweight alternative to JQuery (not all JQuery functions implemented).
24 | - Tons of utility functions.
25 | - Ability to observe or subscribe to **any** element for complex reactivity.
26 | - Small, fast, lightweight and flexible.
27 | - Built in Drag and Drop/swipe.
28 | - A nodeJS build tool for component based apps [Yum App Builder](https://github.com/bretgeek/yumapp/).
29 |
30 | ## Downloads and Docs
31 |
32 | Feel free to download and try one of these minified versions:
33 |
34 | **Minified Download:** https://yumjs.net/js/yum.min.js
35 |
36 | **No Dragging Download:** https://yumjs.net/js/yum.nodrag-min.js
37 |
38 | **Documentation** - in progress: https://yumjs.net/docs/
39 |
40 |
41 | ## Build / minify
42 | There is a custom build/minify process that runs on https://yumjs.net and builds the drag and no drag versions. You should probably use those (linked above) but if you want to minify Yum yourself you can use **terser** https://github.com/terser/terser.
43 |
44 |
45 | terser --c -m -- yum.js >yum.min.js
46 |
47 |
48 |
49 | ## USAGE
50 | Load in your web app like:
51 | ```javascript
52 |
53 | ```
54 |
55 | ### Starting
56 | You probably want to load your code when the document is ready like:
57 |
58 |
59 | ```javascript
60 |
69 | ```
70 | ## More Usage Examples
71 | See more examples at https://yumjs.net/
72 |
73 | ## Thanks for your support!
74 |
75 | [](https://github.com/bretgeek/yumjs/stargazers)
76 |
--------------------------------------------------------------------------------
/docs/components.md:
--------------------------------------------------------------------------------
1 | ### Rendering Components
2 |
3 |
4 |
5 | ```javascript
6 |
15 | ```
16 |
17 |
--------------------------------------------------------------------------------
/docs/introducing-yumjs.md:
--------------------------------------------------------------------------------
1 | 
2 | # YumJS
3 |
4 | **YumJS** is a small reactive JavaScript library with JQuery like syntax that I have created for myself and released in the hope it will be useful to anyone who needs it.
5 |
6 |
7 | *[examples near bottom of post, gotta do the fluff first.]*
8 |
9 |
10 | Aside from having a familiar procedural syntax (and optional component syntax) it gives you the (optional) ability to make **any element** reactive and subscribable.
11 |
12 | ## Why another JS library?
13 |
14 | **Why not?**
15 |
16 | No really, I started this project because:
17 |
18 | - I wanted it to be useful for others to learn from.
19 | - I wanted to see if it **could** be done.
20 | - I wanted it to be open source / open for iteration (if found to be useful).
21 | - I needed it for cutting down on repetitive tasks in my personal projects.
22 |
23 |
24 | As mentioned above, **Yum** provides a familiar **procedural** and a **component** based syntax with low overhead and a slice of delicious reactivity when you need it.
25 |
26 | ## Is this a substitute for [*insert latest popular lib here* ].
27 |
28 | Most definitely not!
29 |
30 | Look I am no expert on JS frameworks. I am just a dude who likes to make stuff.
31 |
32 | In all honesty I steer clear of popular frameworks preferring Vanilla Javascript (and now YumJS) for the things I build.
33 |
34 | I make no claims about using **YumJS** in place of your favorite lib/framework (although maybe it could be).
35 |
36 |
37 | ## Goals
38 |
39 | - Be simple, easy to learn with familiar syntax.
40 | - Complement and shorten JavaScript's syntax whenever possible.
41 | - Ability to subscribe to and make **any** element reactive.
42 | - Be small, fast, lightweight and flexible.
43 | - Built in Drag and Drop/swipe.
44 | - Optional component syntax.
45 | - Be open source and extendable with intuitive plugin system.
46 | - Encourage less DOM diving.
47 |
48 | **Before I get into any examples let me point you to the docs and downloads...**
49 |
50 | ## Downloads and Docs
51 |
52 | **GitHub repo:** https://github.com/bretgeek/yumjs
53 |
54 | Feel free to download and try one of these minified versions:
55 |
56 | **Minified Download:** https://yumjs.net/js/yum.min.js
57 |
58 | **No Dragging Download:** https://yumjs.net/js/yum.nodrag-min.js
59 |
60 | **Documentation** - in progress: https://yumjs.net/docs/
61 |
62 |
63 |
64 | ## USAGE
65 | Load in your web app like:
66 | ``
67 |
68 |
69 | ## EXAMPLES
70 | ###Basic usage
71 |
72 | **You probably want to do stuff when the document is ready.**
73 |
74 | ```javascript
75 |
84 | ```
85 |
86 |
87 | **Querying the DOM and getting references to elements**
88 |
89 | ```javascript
90 | // Assign a collection to variable for re-use, note the underscore.
91 |
92 | let buttons = yum('.button')._;
93 |
94 | // Change the text of the entire collection.
95 |
96 | yum(buttons).text('We are collected buttons.');
97 |
98 | // The above prevents future DOM diving and re-use
99 | // but same effect can be done with:
100 |
101 | yum('.buttons').text('We are collected buttons.');
102 | ```
103 |
104 |
105 | **Make any element reactive**
106 |
107 | ```javascript
108 | // get a reference to only the first h2 element
109 |
110 | let h2 = yum('h2').first;
111 | yum(h2).Reactor(); // set up the reactor
112 |
113 |
114 | // a function for ReactTo
115 |
116 | let runme = function(reactor){
117 | console.log('H4 reacted '+reactor.data);
118 | yum(reactor.subscriber).text(reactor.data)
119 | };
120 |
121 | // Set All h4's to **react to** h2 property 'a' with a subscriber name 'myName'
122 |
123 | yum('h4').ReactTo(h2, 'myName', runme, 'a'); // "a" here can be any property you want
124 |
125 | //later on H2.
126 |
127 | h2.atom.a = "I am some data";
128 |
129 | // After which all H4's will react and exec 'runme'
130 | // and change their text to "I am some data"
131 | ```
132 |
133 |
134 | **Basic component syntax**
135 |
136 | ```javascript
137 | const App = () => {
138 |
139 |
140 | let html = `2
`;
141 |
142 | let h = yum(html).first;
143 |
144 | yum(h).addClass('hey');
145 |
146 | yum(h).on('click', function() { let num = yum(h).text(); num = Number(num) + 1 ; yum(h).text(num); console.log('num is '+num)} );
147 |
148 | return h;
149 | }
150 |
151 |
152 | // Render the App to the body element (or wherever).
153 | yum()._render(App, 'body', { pos: 'append' } );
154 |
155 | ```
156 | Components have built in Reactors. More about that here https://yumjs.net/#yum
157 |
158 |
159 | ## Events
160 | **Adding Event Listeners**
161 |
162 | ```javascript
163 | // assumes runme function exists
164 |
165 | yum('.button').addEvent('mousedown, touchstart', runme);
166 |
167 | // on is an alias for addEvent
168 | // same as above but with on alias
169 |
170 | yum('.button').on('mousedown, touchstart', runme);
171 | ```
172 |
173 | **Creating custom events**
174 |
175 | ```javascript
176 | // create a custom event and assign it to a variable
177 |
178 | let myEvt = yum()._createEvent('myEvt');
179 |
180 |
181 | // Use addEvent to add a listener for the the custom event on .button class
182 |
183 | yum('.button').addEvent( 'myEvt', function(e) { console.log('I am myEvt'), true });
184 |
185 | // Finally trigger the event maybe on a timeout or whatever
186 |
187 | setTimeout(t => {
188 | yum('.button').trigger('myEvt');
189 | }, 2000);
190 | };
191 | ```
192 |
193 |
194 | ## More Usage Examples
195 | There is a whole lot more stuff **YumJS** can do. See more examples at https://yumjs.net/ and the docs at https://yumjs.net/docs/
196 |
197 | #More to do
198 | Trying to keep it short here so I didn't explain the **component** syntax in depth (have a look at the site or the code). Maybe I can cover it further in a future post.
199 |
200 | The documentation still needs some work and while there are examples on the site, many more need to be created.
201 |
202 | I'm sure there is plenty more to do but that is where you come in!
203 |
204 | If you find **YumJS** interesting or useful let's make it better together. Again the **GitHub repo is:** https://github.com/bretgeek/yumjs
205 |
206 | Let me know your thoughts...
207 |
208 | **Thanks for taking the time to read! **
209 |
210 |
--------------------------------------------------------------------------------
/docs/todo.md:
--------------------------------------------------------------------------------
1 | #Todo
2 |
3 | - Finish documention for Methods
4 | - Finish documentation for utilities
5 | - Write plugin examples
6 | - Create more component examples
7 | - More documention and examples for Reactor() and ReactTo()
8 | - More documention and examples for spy() and unsp()()
9 | - Move Bash/PHP build system from local to GitHub
10 |
11 |
--------------------------------------------------------------------------------
/images/gitlogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bretgeek/yumjs/62cebe311929091d3ed0c4fd3fad1d1dc89a795a/images/gitlogo.png
--------------------------------------------------------------------------------
/images/yumlogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bretgeek/yumjs/62cebe311929091d3ed0c4fd3fad1d1dc89a795a/images/yumlogo.png
--------------------------------------------------------------------------------
/yum.js:
--------------------------------------------------------------------------------
1 | function yum(itr, ...Arr) { // itr is things to iterate over
2 | // components can have non global yumobservers - see spy
3 |
4 | globalThis.yumobservers = globalThis.yumobservers || {};
5 |
6 | let itrtemp; // for saving itr
7 |
8 | // idk why anyone would want to do this but...
9 | if (isFunction(itr)) {
10 | // console.log('functor');
11 | itr();
12 | return this;
13 | }
14 |
15 |
16 | // THE STACK
17 | let _stk = [];
18 |
19 | // handle if itr itself is an object or a string
20 | if (itr) {
21 | if (isObject(itr)) {
22 | // can take an array of objects like [ obj, obj2];
23 | if (Array.isArray(itr)) {
24 | for ( const a of itr ) {
25 | if (a.nodeType === 1) {
26 | _stk.push(a);
27 | }
28 | }
29 | } else {
30 | if (itr.nodeType == 1) {
31 | // console.log('node type is a '+itr.nodeType);
32 | // not sure why itr has to be an array even if it is only one object
33 | // crazy hack to get one selector object passed in to work
34 | const tempitr = [itr];
35 | for ( const a of tempitr ) {
36 | if (a.nodeType === 1) {
37 | _stk.push(a);
38 | }
39 | }
40 | }
41 | }
42 | }
43 |
44 |
45 | // check for window
46 | if (itr === window) {
47 | // console.log('window');
48 | _stk.push(itr);
49 | }
50 | // check for document
51 | if (itr.nodeName === '#document' ) {
52 | // console.log('selector name is '+itr.nodeName);
53 | var yumloaded = false; // yes var
54 | (function ready(fn) {
55 | if (document.readyState != 'loading') {
56 | yumloaded = true;
57 | // console.log('ready state');
58 | } else if (document.addEventListener) {
59 | document.addEventListener('DOMContentLoaded', function() {
60 | yumloaded = true;
61 | // console.log('DOM Loaded');
62 | });
63 | } else {
64 | document.attachEvent('onreadystatechange', function() {
65 | if (document.readyState != 'loading') {
66 | yumloaded = true;
67 | // console.log('ready state');
68 | }
69 | });
70 | }
71 | })();
72 | }
73 |
74 | if (isString(itr)) {
75 | itrtemp = itr;
76 | itr = itr.split(',');
77 | itr = itr.filter((x, i, a) => a.indexOf(x) == i);
78 | for ( const s of itr ) {
79 | // console.log('s type is '+typeof(s));
80 | if (__isHTML(s)) {
81 | // console.log('s is html '+s);
82 | // console.log('the tagname is '+__isHTML(s, true));
83 | // create the element from an html tag name which was parsed
84 | __procHTML(__isHTML(s, true));// returns tagname
85 | } else {
86 | let els;
87 | // if just sending in an ID this would be faster
88 | if (s.startsWith('#')) {
89 | const id = s.replace(/#/, '');
90 | els = document.getElementById(id);
91 | // console.log('s is '+s);
92 | _stk.push(els);
93 | }
94 | // handle classes as live HTML collection
95 | else if (s.startsWith('.')) {
96 | const cn = s.replace(/./, '');
97 | els = document.getElementsByClassName(cn);
98 | // console.log('cn is '+s);
99 | for ( const el of els ) {
100 | _stk.push(el);
101 | }
102 | } else {
103 | els = document.querySelectorAll(s);
104 | for ( const el of els ) {
105 | _stk.push(el);
106 | }
107 | }
108 | }
109 | }
110 | }
111 | } // end if itr
112 |
113 | // check for ...rest as Arr
114 | // make unique array first
115 | Arr = Arr.filter((x, i, a) => a.indexOf(x) == i);
116 | for ( let sel of Arr ) { // let instead of cont because sel gets mutated below sel = sel.split(',');
117 | if (Array.isArray(sel)) {
118 | for ( const a of sel ) {
119 | if (a.nodeType === 1) {
120 | _stk.push(a);
121 | }
122 | }
123 | }
124 | if (isObject(sel)) {
125 | if (sel.nodeType === 1) {
126 | _stk.push(sel);
127 | }
128 | }
129 |
130 | if (isString(sel)) {
131 | sel = sel.split(',');
132 | for ( const s of sel ) {
133 | // console.log('s type is '+typeof(s));
134 |
135 | const els = document.querySelectorAll(s);
136 | for ( const el of els) {
137 | if (el.nodeType === 1) {
138 | _stk.push(el);
139 | }
140 | }
141 | }
142 | }
143 | } // end Arr ...Arr
144 |
145 | /* END THE STACK */
146 |
147 |
148 | /* START LIBRARY FUNCTIONS */
149 |
150 | let doc;
151 | let docint;
152 | function ready(fn, fallbacktime=3000) {
153 | let tout;
154 | let inc = 1;
155 | docint = setInterval( (i) => {
156 | if (yumloaded) {
157 | clearInterval(docint);
158 | clearTimeout(tout);
159 | // console.log('ran and cleared in Intv and cleared timeout');
160 | if (fn && isFunction(fn) && inc <=1) { // dont run more than once per call
161 | try {
162 | fn();
163 | inc++;
164 | } catch (e) {}
165 | } else {
166 | // should also be able to use to check if docready is true
167 | return true;
168 | }
169 | }
170 | }, 6);
171 | // if all else fails set yumloaded after fallbacktime (can pass it in too)
172 | tout = setTimeout( (e) => {
173 | // console.log('ran in Timeout');
174 | yumloaded = true;
175 | }, fallbacktime);
176 | }// end ready
177 |
178 |
179 | let Y = 1;
180 | let X = 1;
181 | let scrLeft;
182 | let scrTop = 0;
183 | function _scrollPos() {
184 | doc = document.documentElement;
185 | scrLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
186 | scrTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
187 | scrTop = _rpx(scrTop);
188 | scrLeft = _rpx(scrLeft);
189 | // console.log('scrTop = '+scrTop+' scrLeft= '+scrLeft);
190 | }
191 |
192 |
193 | let tchdev = false;
194 | function _isTouch() {
195 | return window.matchMedia('(pointer: coarse)').matches || false;
196 | }
197 |
198 | if (_isTouch()) {
199 | tchdev = true;
200 | }
201 |
202 | function _rect(el, st=false, round=false) {
203 | let e = el; // if el is object
204 | if (isString(el)) {
205 | e = document.querySelector(el);
206 | }
207 |
208 | const allow = ['x', 'y', 'width', 'height', 'right', 'left', 'top', 'bottom'];
209 | if (!allow.includes(st)) {
210 | return null;
211 | }
212 |
213 | const ret = e.getBoundingClientRect()[st];
214 |
215 | if (round) {
216 | return Math.round(ret);
217 | } else {
218 | return ret;
219 | }
220 | }
221 |
222 |
223 | // Get Computed Styles of el
224 | function _cs(el, prop, trim=false) {
225 | if (isString(el)) {
226 | el = document.querySelector(el);
227 | }
228 | if (el) {
229 | let cs = getComputedStyle(el).getPropertyValue(prop) || null;
230 | if (trim) {
231 | try {
232 | cs = _rpx(cs);
233 | } catch (e) {}
234 | }
235 | return cs;
236 | }
237 | }
238 |
239 |
240 | /* HTXT */
241 | // HTML
242 | function html(str=false, limit='all' ) {
243 | let res = '';
244 | if (!str && limit==='all') {
245 | // console.log('stk len' + _stk.length);
246 | for ( const y of _stk) {
247 | res += y.innerHTML;
248 | }
249 | return res;
250 | }
251 | __htxt(str, limit='all' );
252 | return this;
253 | }
254 |
255 |
256 | /* TEXT */
257 | // if limit is set then only do for that many times
258 | function text(str, limit='all' ) {
259 | let res = '';
260 | if (!str && limit==='all') {
261 | // console.log('stk len' + _stk.length);
262 | for ( const y of _stk) {
263 | res += y.textContent;
264 | }
265 | return res;
266 | }
267 |
268 | __htxt(str, limit='all', true );
269 | return this;
270 | }
271 |
272 | // if limit is set then only do for that many times
273 | function __htxt(str, limit='all', t=false ) {
274 | const content = '';
275 | let inc = 0;
276 | for ( const y of _stk) {
277 | if (__isNum(limit) && inc <= limit) {
278 | // console.log('limit '+ inc);
279 | inc++;
280 | if (t) {
281 | y.textContent = str;
282 | } else {
283 | y.innerHTML = str;
284 | }
285 | }
286 | if (limit === 'all') {
287 | if (t) {
288 | y.textContent = str;
289 | } else {
290 | y.innerHTML = str;
291 | }
292 | }
293 | }
294 | // console.log('str should set '+ str);
295 | return this;
296 | }
297 | /* END HTXT */
298 |
299 |
300 | /* TOOLS */
301 |
302 | // takes an array s of [tagname, innerHTML]
303 | function __procHTML(s, r=false) {
304 | // console.log('GOT HTML');
305 | // create a wrapper so we can turn HTML string into a node
306 | // console.log('tag name is '+ s[0]);
307 | const el = document.createElement(s[0]);
308 | el.innerHTML = s[1];
309 | if (r) {
310 | return el;
311 | } else {
312 | _stk.push(el);// push el onto stack
313 | }
314 | }
315 |
316 |
317 | function __isHTML(str, t = false) {
318 | // if t is true return the tag name
319 | const doc = new DOMParser().parseFromString(str, 'text/html');
320 | if (t) {
321 | return [doc.body.childNodes[0].tagName.toLowerCase(), doc.body.childNodes[0].innerHTML];
322 | } else {
323 | return Array.from(doc.body.childNodes).some((node) => node.nodeType === 1 );
324 | }
325 | }
326 |
327 | // filter strings
328 | function _sfilter(str, strict=false) {
329 | str = str.replace(/[^\x20-\x7E]+/g, '');
330 | if (strict) {
331 | str = str.replace(/[^a-z0-9-#]+|\s+/gmi, '');
332 | }
333 | str = str.trim();
334 | return str;
335 | }
336 |
337 |
338 | /* _createNode */
339 | function _createNode( nodetype='div', override=false, selector='default') {
340 | const allowedNodes = ['html', 'head', 'link', 'meta', 'script', 'style', 'title', 'body', 'article', 'aside', 'footer', 'header', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'main', 'nav', 'section', 'blockquote', 'div', 'figure', 'hr', 'li', 'ol', 'p', 'pre', 'ul', 'a', 'code', 'data', 'time', 'em', 'i', 'span', 'strong', 'audio', 'source', 'img', 'track', 'video', 'iframe', 'svg', 'canvas', 'noscript', 'col', 'colgroup', 'button', 'option', 'fieldset', 'label', 'form', 'input', 'select', 'textarea', 'menu', 'template'];
341 |
342 | if (!allowedNodes.includes(nodetype)) {
343 | if (!override) {// you can send in an element not in the list by setting override to true (think custom elements that are properly defined)
344 | nodetype = 'div';
345 | }
346 | }
347 |
348 | const newnode = document.createElement(nodetype);
349 | return newnode;
350 | }
351 |
352 |
353 | /* generate uuid */
354 | function _uuidv4() {
355 | return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, (c) =>
356 | (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16),
357 | );
358 | }
359 |
360 | /* DELAY execute function for every element after a delay, fn takes in */
361 | function delay(wait=500, fn) {
362 | setTimeout((t) => {
363 | for ( const y of _stk ) {
364 | fn(y);
365 | }
366 | // console.log('delayed');
367 | }, wait);
368 | return this;
369 | }
370 |
371 | /* ISNUMBER */
372 | function __isNum(value) {
373 | return /^-{0,1}\d+$/.test(value);
374 | }
375 |
376 | function hidkbd(el) {
377 | if (!el) {
378 | for ( const el of _stk ) {
379 | setTimeout(function() {
380 | el.onfocus = blur(); // close the keyboard
381 | }, 100);
382 | }
383 | }
384 | }
385 |
386 | // return a number minus px since parseInt is flakey
387 | function _rpx(s) {
388 | s = s.toString();
389 | return Math.round(Number(s.replace(/px/g, '')));
390 | }
391 |
392 | // get outer margins and return them
393 | function __getM(el) {
394 | const computed = getComputedStyle(el);
395 | const padding = parseInt(computed.paddingTop) + parseInt(computed.paddingBottom);
396 |
397 | const marginT = _rpx(computed.getPropertyValue('margin-top')) || 0;
398 | const marginB = _rpx(computed.getPropertyValue('margin-bottom')) || 0;
399 |
400 | const marginL = _rpx(computed.getPropertyValue('margin-left')) || 0;
401 | const marginR = _rpx(computed.getPropertyValue('margin-right')) || 0;
402 | return [marginT, marginL, marginB, marginR];
403 | }
404 |
405 | function _getAtPt(x, y) {
406 | return document.elementFromPoint(x, y);
407 | }
408 |
409 |
410 | /* END TOOLS */
411 |
412 | /* EVENTS */
413 |
414 | /* create events */
415 | function _createEvent(str, bubbles=false, cancelable=false) {
416 | const evt = new Event(str, {'bubbles': bubbles, 'cancelable': cancelable});
417 | // console.log('the event was '+evt);
418 | return evt;
419 | }
420 |
421 | // this will dispatch the event for the specified element must be valid string name for e element reference for el
422 | function _eventDispatch(e, el) {
423 | el.dispatchEvent(e);
424 | }
425 |
426 |
427 | function addEvent(etype='mousedown', handler, cap = false ) {
428 | let userCap = cap;
429 | // console.log(typeof(cap));
430 | // if cap is sent in as boolean then set capture to true
431 | if (typeof(cap) === 'boolean' ) {
432 | if (cap) {
433 | userCap = {'capture': true};
434 | } else {
435 | userCap = {'capture': false};
436 | }
437 | }
438 | // note do e.preventDefault() in the handlier
439 | const types = etype.split(',');
440 | for ( const y of _stk ) {
441 | // console.log('stack');
442 | for ( let t of types ) { // let here instead of const because t is immediately mutated
443 | t = t.trim();
444 | y.addEventListener(t, handler, userCap);
445 | }
446 | }
447 | return this;
448 | }
449 |
450 |
451 | function removeEvent(etype='mousedown', handler, cap=false ) {
452 | let userCap = cap;
453 | // console.log(typeof(cap));
454 | // if cap is sent in as boolean then set capture to true
455 | if (typeof(cap) === 'boolean' ) {
456 | if (cap) {
457 | userCap = {'capture': true};
458 | } else {
459 | userCap = {'capture': false};
460 | }
461 | }
462 |
463 | const types = etype.split(',');
464 | for ( const y of _stk ) {
465 | for ( const t of types ) {
466 | y.removeEventListener(t, handler, userCap);
467 | }
468 | }
469 | return this;
470 | }
471 |
472 |
473 | /* object and var rm is a removal pattern for building without drag */
474 | /* eslint-disable */
475 | {drag: rm}
476 | var rm = 'r';
477 | /* eslint-enable */
478 |
479 | /* DRAG AND SWIPE */
480 |
481 |
482 | // short hand for just dragging
483 | function drg() {
484 | if (tchdev) {
485 | swipe(_stk[0]);
486 | } else {
487 | drag(false, _stk[0], {});
488 | }
489 | return this;
490 | }
491 |
492 | function drag(node, {drop='.droppable', drpfn=false, lvupfn = false, zindex=false, contain=false} ) {
493 | // for deciding if parent is to be dragged
494 | if (node && typeof(node) !== 'function') { // if it is a function then its a swipe
495 | node = _stk[0].parentNode;
496 | } else {
497 | node = _stk[0];
498 | }
499 | if (!zindex) {
500 | zindex = 1006;
501 | }
502 | if (tchdev) {
503 | swipe(node, drop, drpfn, lvupfn, zindex, contain);
504 | } else {
505 | const drgfn = function(e) {
506 | // we have to handle touch devices differently
507 | if (tchdev) {
508 | setTimeout((t) => {
509 | hidkbd(e);
510 | }, 20);
511 | } else {
512 | stopped = false;
513 | doDrag(_stk[0], e, node, drop, false, false, zindex, contain );
514 | }
515 | _stk[0].style.cursor = 'move';
516 | };
517 |
518 |
519 | const upfn = function(e) {
520 | const dropped = document.querySelector(drop);
521 | const drp = _data(e.target, 'dropping', 'get');
522 | if (drp) {
523 | // console.log('GOT '+drp);
524 | if (isFunction(drpfn)) {
525 | // console.log('drpfn should run');
526 | if (dropped) {
527 | drpfn(dropped, e.target);
528 | }
529 | }
530 | }// end if drp
531 |
532 | if (!drp) {
533 | if (isFunction(lvupfn)) {
534 | if (dropped) {
535 | lvupfn(dropped, e.target);
536 | }
537 | }
538 | }// end not drp
539 | };// end upfn
540 |
541 | addEvent('mousedown, touchstart', drgfn, true);
542 | addEvent('mouseup', upfn, true);
543 | }
544 | return this;
545 | }
546 |
547 | /* dragee is the thing you want to drag while el is the handle thing to click to do the dragging */
548 | function doDrag(el, e, dragee, droppable=false, drpfn, lvupfn, zindex=false, contain=false) {
549 | if (!dragee) return;
550 |
551 | e.preventDefault();
552 |
553 | dragee.ondragstart = function() {
554 | return false;
555 | };
556 |
557 | let shiftX;
558 | let shiftY;
559 | if (tchdev) {
560 | // console.log('droppable = '+droppable);
561 | }
562 | let dropel = droppable;
563 | if (dropel) {
564 | dropel = document.querySelector(droppable);
565 | } else {
566 | dropel = document.querySelector('.droppable');
567 | }
568 | let cont = contain;
569 | // the container as an element need for getting dimensions
570 | if (cont) {
571 | if(cont !== 'no'){
572 | cont = document.querySelector(contain);
573 | }
574 | } else {
575 | // prevent from going off screen
576 | cont = document.documentElement || document.querySelector('body') || window;
577 | }
578 | // the container must be static and it's parents must be static
579 | // yum(cont).css('position: static;');
580 |
581 | // Cutoff and adjust shift for margins
582 | let shiftLR = 0;
583 | const shiftArr = __getM(dragee);
584 | const [shiftT, shiftL, shiftR] = shiftArr;
585 | shiftLR = shiftL+shiftR;
586 | let stopped = false;
587 |
588 |
589 | dragee.style.position = 'absolute';
590 | dragee.style.marginTop = 0;
591 | dragee.style.marginLeft = 0;
592 | dragee.style.marginRight = 0;
593 | dragee.style.zIndex = zindex;
594 |
595 |
596 | shiftX = e.clientX - dragee.getBoundingClientRect().left-shiftLR;// was left and top
597 | shiftY = e.clientY - dragee.getBoundingClientRect().top-shiftT;
598 | if (tchdev) {
599 | const touchLocation = e.targetTouches[0];
600 | shiftX = touchLocation.pageX - dragee.getBoundingClientRect().left-shiftLR;
601 | shiftY = touchLocation.pageY - dragee.getBoundingClientRect().top-shiftT;
602 | }
603 | function moveTo(pageX, pageY) {
604 | // console.log('pagex and y '+pageX+' ' +pageY);
605 | pageX = Math.round(pageX);
606 | pageY = Math.round(pageY);
607 | shiftX = Math.round(shiftX);
608 | shiftY = Math.round(shiftY);
609 |
610 | _scrollPos();
611 | // for some reason touch doesnt adjust for scroll
612 | if (tchdev) {
613 | pageX = pageX + scrLeft;
614 | pageY = pageY + scrTop;
615 | }
616 |
617 |
618 | if (tchdev) {
619 | dragee.style.left = pageX - shiftX + 'px';
620 | dragee.style.top = pageY - shiftY +'px';
621 | X = pageX;
622 | Y = pageY;
623 | } else {
624 | dragee.style.left = pageX - shiftX + 'px';
625 | dragee.style.top = pageY - shiftY + 'px';
626 | X = pageX;
627 | Y = pageY;
628 | }
629 |
630 | if (dropel) {
631 | drop(dragee, dropel, pageX, pageY);
632 | }
633 | }// end moveTo
634 |
635 |
636 | function drop(dragee, cont, pageX, pageY) {
637 | _scrollPos();
638 | const cRct = dropel.getBoundingClientRect();
639 | const dRct = dragee.getBoundingClientRect();
640 | // touch device have to subrtact scroll for some reason
641 | if (tchdev) {
642 | pageX = pageX - scrLeft;
643 | pageY = pageY - scrTop;
644 | }
645 | // keep element in container
646 | // top
647 | const dtop = _rpx(dRct.top) + scrTop;
648 | const contop = _rpx(cRct.top) + scrTop;
649 | // console.log('moving '+ pageY+' '+contop);
650 | if (pageY < contop ) {
651 | // console.log('mouse OUT Y top in contM');
652 | // pageY = contop + 9;
653 | // dragee.style.top = contop + 6+'px';
654 | }
655 |
656 | let inY = false;
657 | let inX= false;
658 | if ( dtop > contop ) {
659 | // console.log('inside drop from top '+ dtop+' '+contop);
660 | inY = true;
661 | }
662 |
663 | // bottom
664 | const dbot = _rpx(dRct.y) - scrTop;
665 | const conbot = _rpx(cRct.y)+cont.offsetHeight + scrTop;
666 |
667 | if (pageY > conbot ) {
668 | // console.log('inside drop from bottom '+ dbot+' '+contop);
669 | inY = false;
670 | }
671 |
672 | // left
673 | if ( pageX < cRct.x + cont.offsetWidth + scrLeft ) {
674 | // console.log('inside drop from left '+ dRct.x+' '+cRct.x);
675 | inX= true;
676 | }
677 |
678 | // right
679 | if ( pageX < cRct.x || pageX > cRct.x + cont.offsetWidth + scrLeft) {
680 | // console.log('inside drop from left '+ dRct.x+' '+cRct.x);
681 | inX = false;
682 | }
683 |
684 | if (inY && inX) {
685 | // console.log('in Droppable');
686 | _data(dragee, 'dropping', 'set');
687 | } else {
688 | _data(dragee, 'dropping', 'remove' );// remove dropping data
689 | }
690 | }// end drop
691 |
692 | // the containment function
693 | function contM(dragee, cont, pageX, pageY) {
694 | _scrollPos();
695 | const cRct = cont.getBoundingClientRect();
696 | const dRct = dragee.getBoundingClientRect();
697 |
698 | // keep element in container
699 | // top
700 | const dtop = _rpx(dRct.top) + scrTop;
701 | const contop = _rpx(cRct.top) + scrTop;
702 | // console.log('moving '+ pageY+' '+contop);
703 | if (pageY < contop ) {
704 | // console.log('mouse OUT Y top in contM');
705 | pageY = contop + 9;
706 | dragee.style.top = contop + 6+'px';
707 | stopped = true;
708 | return;
709 | }
710 |
711 | if ( dtop < contop ) {
712 | pageY = _rpx(dragee.style.top) + 20;
713 | dragee.style.top = contop + 6+'px';
714 | // console.log('hit contain top '+ dtop+' '+contop);
715 | stopped = true;
716 | return;
717 | }
718 |
719 | // bottom
720 | const dbot = _rpx(dRct.y) - scrTop;
721 | const conbot = _rpx(cRct.y)+cont.offsetHeight + scrTop;
722 |
723 | if (pageY > conbot ) {
724 | // console.log('mouse OUT Y bottom');
725 | dragee.style.top = conbot - dragee.offsetHeight - 6+'px';
726 | stopped = true;
727 | return;
728 | }
729 |
730 | if ( dbot - conbot > conbot ) {
731 | pageY = conbot-20;
732 | dragee.style.top = conbot - dragee.offsetHeight - 3 +'px';
733 | // console.log('touch shift page x '+ conbot);
734 | stopped = true;
735 | return;
736 | }
737 |
738 | // TODO adjust for left scroll
739 | // left
740 | if ( dRct.x < cRct.x ) {
741 | // console.log('less than left');
742 | dragee.style.left = Math.round(cRct.x)+ 3 +'px';
743 | stopped = true;
744 | return;
745 | }
746 |
747 | // right
748 | if ( dRct.x+dragee.offsetWidth > cRct.x+cont.offsetWidth) {
749 | // console.log('more than right');
750 | dragee.style.left = cRct.x+cont.offsetWidth - dragee.offsetWidth - 3 +'px';
751 | // pageX = cRct.x+cont.offsetWidth-3;
752 | stopped = true;
753 | return;
754 | }
755 | }// end contM
756 |
757 |
758 | // for mobile drag
759 | if (tchdev) {
760 | // touchscreen
761 | // console.log('touch');
762 | // wrap the handler
763 | function tHandler(e) {
764 | e.preventDefault();
765 | // grab the location of touch
766 | const touchLocation = e.targetTouches[0];
767 | try {
768 | if (cont) {
769 | mob(e.target, cont, touchLocation.pageX, touchLocation.pageY);
770 | }
771 | if (!stopped) {
772 | moveTo(touchLocation.pageX, touchLocation.pageY);
773 | }
774 | } catch (e) {}
775 | }
776 | el.addEventListener('touchmove', tHandler, true);
777 | function mob(t, cont, pageX, pageY) {
778 | contM(t, cont, pageX, pageY);
779 | }
780 |
781 |
782 | // wrap the handler
783 | function endHandler(e) {
784 | try {
785 | stopped = false;
786 | if (droppable) {
787 | // console.log('touch droppable is '+ droppable);
788 | const upfn = function(e) {
789 | const dropped = document.querySelector(droppable);
790 | const drp = _data(e.target, 'dropping', 'get');
791 | if (drp) {
792 | // console.log('Touch GOT '+drp);
793 | if (isFunction(drpfn)) {
794 | // console.log('drpfn should run');
795 | if (dropped) {
796 | // drpfn(dropped,e);
797 | drpfn(dropped, e.target);
798 | }
799 | }
800 | }// end if drp
801 |
802 | if (!drp) {
803 | if (isFunction(lvupfn)) {
804 | if (dropped) {
805 | // lvupfn(dropped);
806 | lvupfn(dropped, e.target);
807 | }
808 | }
809 | }// end not drp
810 | };// end upfn
811 |
812 | upfn(e);
813 | } // end droppable
814 | } catch (e) {
815 | // console.log(X+','+ Y);
816 | }
817 |
818 | el.removeEventListener('touchend', endHandler, true);
819 | el.removeEventListener('touchmove', tHandler, true);
820 | }
821 |
822 | el.addEventListener('touchend', endHandler, true);
823 | } else {
824 | if (!stopped) {
825 | moveTo(e.pageX, e.pageY);
826 | }
827 | globalThis.onMouseMove = function(e) {
828 | e.preventDefault();
829 |
830 | // contM func desktop
831 | if (cont) {
832 | contM(dragee, cont, e.pageX, e.pageY);
833 | // console.log('in CONT');
834 | }
835 | // end func
836 |
837 | // console.log('event '+e);
838 | if (!stopped) {
839 | moveTo(e.pageX, e.pageY);
840 | }
841 | };// endonMouseOver
842 |
843 | document.addEventListener('mousemove', onMouseMove, true);
844 | // remove listener if dragee mouse up
845 | dragee.onmouseup = function() {
846 | // console.log('remove listener');
847 | document.removeEventListener('mousemove', onMouseMove, true);
848 | dragee.onmouseup = null;
849 | };
850 |
851 |
852 | // remove listener if handle mouse up
853 | el.onmouseup = function() {
854 | document.removeEventListener('mousemove', onMouseMove, true);
855 | el.onmouseup = null;
856 | };
857 |
858 | // remove listener if document mouse up
859 | document.onmouseup = function() {
860 | document.removeEventListener('mousemove', onMouseMove, true);
861 | el.onmouseup = null;
862 | };
863 | el.ondragstart = function() {
864 | return false;
865 | };
866 | }// end if tchdev
867 | };
868 |
869 | /* END DRAG */
870 |
871 |
872 | /* SWIPE */
873 | function swipe(node, drop=false, drpfn=false, lvupfn = false, zindex=1006, contain=false) {
874 | // if first param is a func or false then swiping is in affect
875 | let swipe = false;
876 | // swipeleft etc
877 | let swipeleft;
878 | // if first param if false or function then it is a swipe
879 | if (isFunction(node) || !node) {
880 | swipe = true;
881 | if (node) { // if node is actual a function sent in then swipeleft function activated
882 | swipeleft = node;
883 | }
884 | }
885 | let swiperight;
886 | if (drop && isFunction(drop) && swipe) {
887 | swiperight = drop;
888 | }
889 |
890 | var swipeup;
891 | if (drpfn && isFunction(drpfn) && swipe) {
892 | swipeup = drpfn;
893 | }
894 |
895 | var swipeup;
896 | if (lvupfn && isFunction(lvupfn) && swipe) {
897 | swipedown = lvupfn;
898 | }
899 |
900 |
901 | s = _stk[0];
902 | s.addEventListener('touchstart', handleTouchStart, false);
903 | s.addEventListener('touchmove', handleTouchMove, false);
904 | s.addEventListener('touchend', handleTouchEnd, false);
905 | let xDown = null;
906 | let yDown = null;
907 |
908 |
909 | let draggable = false;
910 | if (s.matches('.draggable') && !swipe) { // only draggable if not swiping
911 | draggable = true;
912 | }
913 |
914 | function dragme(e) {
915 | e.preventDefault();
916 | if (draggable) {
917 | doDrag(_stk[0], e, node, drop, drpfn, lvupfn, zindex, contain );
918 | }
919 | }
920 |
921 | function handleTouchEnd(e) {
922 | // for future use
923 | return;
924 | }
925 | function handleTouchStart(e) {
926 | const touchLocation = e.targetTouches[0];
927 |
928 | xDown = touchLocation.pageX;
929 | yDown = touchLocation.pageY;
930 | };
931 | function handleTouchMove(e) {
932 | e.preventDefault();
933 | if ( ! xDown || ! yDown ) {
934 | return;
935 | }
936 | const touchLocation = e.targetTouches[0];
937 |
938 | const xUp = touchLocation.pageX;
939 | const yUp = touchLocation.pageY;
940 |
941 | const xDiff = xDown - xUp;
942 | const yDiff = yDown - yUp;
943 |
944 | if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) { // most significant
945 | if ( xDiff > 0 ) {
946 | // left swipe
947 | // console.log('swiped left');
948 | if (swipe && swipeleft ) {
949 | swipeleft(e);
950 | }
951 | dragme(e);
952 | } else {
953 | // right swipe
954 | // console.log('swiped right');
955 | if (swipe && swiperight ) {
956 | swiperight(e);
957 | }
958 | dragme(e);
959 | }
960 | } else {
961 | if ( yDiff > 0 ) {
962 | // up swipe
963 | // console.log('swiped up');
964 | if (swipe && swipeup ) {
965 | swipeup(e);
966 | }
967 | dragme(e);
968 | } else {
969 | // down swipe
970 | // console.log('swiped down');
971 | if (swipe && swipedown ) {
972 | swipedown(e);
973 | }
974 | dragme(e);
975 | }
976 | }
977 | // reset values
978 | xDown = null;
979 | yDown = null;
980 | if (swipe) {
981 | // console.log('swiped');
982 | }
983 | };
984 | return this;
985 | }
986 | /* END SWIPE */
987 |
988 |
989 | /* END DRAG AND SWIPE */
990 |
991 | // edrag removal pattern here
992 | /* eslint-disable */
993 | {edrag: rm}
994 | /* eslint-enable */
995 |
996 |
997 | function _Route( dir, ...args) {
998 | let newroute;
999 | const search = globalThis.location.search;
1000 | const hash = globalThis.location.hash;
1001 | let loc = globalThis.location.pathname;
1002 | // console.log('SEARCH '+search);
1003 | if (!dir) {
1004 | return globalThis.location.pathname;
1005 | }
1006 |
1007 | if (isString(dir)) {
1008 | if (dir.match(/^[?#&]/) ) {
1009 | // console.log('hash '+dir);
1010 | if (hash !== dir) {
1011 | if (dir.match(/^[#]/) ) {
1012 | loc = loc.replace(/\/$/, '');
1013 | }
1014 | // console.log(loc + dir);
1015 | // console.log(globalThis.location.protocol +'//'+ globalThis.location.hostname+loc+dir);
1016 | return;
1017 | // return globalThis.location = globalThis.location.protocol +'//'+ globalThis.location.hostname+loc+dir;
1018 | }
1019 | }
1020 |
1021 |
1022 | if (dir.match(/^[?#&]/) && dir === hash ) {
1023 | return;
1024 | }
1025 | }
1026 |
1027 | newroute = dir+'/';
1028 |
1029 | if (args.length) {
1030 | for ( const r of args ) {
1031 | if (r.match(/^[?#&]/) ) {
1032 | newroute += r;
1033 | } else {
1034 | newroute += r+'/';
1035 | }
1036 | }
1037 | }
1038 |
1039 | const curpath = globalThis.location.pathname + search;
1040 | if (curpath !== '/'+newroute) {
1041 | // console.log('curpath is '+ curpath);
1042 | // console.log('newroute /'+ newroute);
1043 | globalThis.location = '/'+newroute;
1044 | }
1045 | }
1046 |
1047 |
1048 | function Reactor(prop) {
1049 | if (prop) {
1050 | prop = _camelDash(prop);
1051 | } else {
1052 | prop = 'atom';
1053 | }
1054 | for ( const e of _stk ) {
1055 | // Initialize the reactor on every component's data prop
1056 | e.subscribers = [];
1057 |
1058 | e.reactor = {
1059 | set: function(target, key, value) {
1060 | // console.log(`The property ${prop}.${key} on ${e.tagName} has been updated with ${value}`);
1061 | for ( let i=0; i< e.subscribers.length; i++ ) {
1062 | // console.log(e.subscribers[i]);
1063 | const reactees = Object.keys(e.subscribers[i]);
1064 | const watchers = Object.values(e.subscribers[i]);
1065 | const watchProp = e.subscribers[i].watch; // property we are watching
1066 | const sname = Object.keys(e.subscribers[i])[0];// subscriber name
1067 | const el = e.subscribers[i].el;
1068 | for ( const o of watchers ) {
1069 | if (isFunction(o)) {
1070 | if (watchProp === 'all' || watchProp == key) {
1071 | o( {data: value, name: sname, watch: watchProp, subscriber: el});
1072 | // expost the value to the element
1073 | e.data = value;
1074 | e.subscriber = el;
1075 | }
1076 | }
1077 | }
1078 | }
1079 | return true;
1080 | },
1081 | };
1082 | const react = new Proxy({}, e.reactor);
1083 | // e.data = react;
1084 | e[prop] = react;
1085 | }
1086 | return this;
1087 | }
1088 |
1089 |
1090 | // for external use
1091 | function ReactTo(obj, ob, localProp, externalProp = false) {
1092 | if (_stk.length) {
1093 | for ( const y of _stk ) {
1094 | _ReactTo(obj, ob, localProp, externalProp, y);
1095 | }
1096 | } else {
1097 | _ReactTo(obj, ob, localProp, externalProp );
1098 | }
1099 |
1100 | return this;
1101 | }
1102 |
1103 | // for internal use
1104 | function _ReactTo(obj, ob, localProp, externalProp = false, e = false) {
1105 | const name = _camelDash(ob);
1106 | if (externalProp) {
1107 | externalProp = _camelDash(externalProp);
1108 | }
1109 | if (!externalProp) {
1110 | externalProp = 'all';
1111 | }
1112 | obj.subscribers.push({[name]: localProp, watch: externalProp, el: e} );
1113 | return this;
1114 | }
1115 |
1116 |
1117 | function unReact(obj, name, prop='all' ) {
1118 | name = _camelDash(name);
1119 | prop = _camelDash(prop);
1120 | const inc = 0;
1121 | const narr = [];
1122 | // console.log('prop '+ prop);
1123 | for ( const s of obj.subscribers ) {
1124 | if ( name in s && s.watch === prop ) {
1125 | obj.subscribers.splice(s, 1);
1126 | // console.log('S Watch '+s.watch);
1127 | // console.log('NAME is IN '+name)
1128 | // console.log('WATCH is '+s.watch)
1129 | }
1130 | }
1131 | return this;
1132 | }
1133 |
1134 | // this trigger will trigger the event for all on the stack
1135 | function trigger(e) {
1136 | for ( const y of _stk ) {
1137 | const ev = new Event(e);
1138 | y.dispatchEvent(ev, {'bubbles': true, 'cancelable': true} );
1139 | }
1140 | return this;
1141 | }
1142 |
1143 |
1144 | /* SPY */
1145 | // params sel, fn to run after delay
1146 | // Pass in an object and build config from that then change the if mutation
1147 | // function spy(fn, name = 'name', delay=10 ) {
1148 | function spy(fn, name = 'name', {delay=10, child=true, attr=true, subtree=false, attrs=['none'], chardat=false, attrsOV=false, chardatOV=false}, yo=false ) {
1149 | // keep a record of observers in an object of global var or component so we can disconnect them later
1150 | // yo here is to pass in a reference to a component object
1151 | if (yo) {
1152 | var yumobservers = yo.yob;
1153 | // console.log('I SPY COMPONENT YO');
1154 | } else {
1155 | var yumobservers = globalThis.yumobservers;
1156 | }
1157 | if (typeof(fn) !== 'function') {
1158 | return;
1159 | }
1160 | // console.log('observer running');
1161 | // configuration of the observer
1162 | const config = {
1163 | childList: child,
1164 | attributes: attr,
1165 | characterData: chardat,
1166 | subtree: subtree,
1167 | attributeFilter: attrs,
1168 | attributeOldValue: attrsOV,
1169 | characterDataOldValue: chardatOV,
1170 | };
1171 |
1172 |
1173 | const target = _stk;
1174 | for ( let i = 0; i < target.length; i++) {
1175 | // console.log('spying '+name+i );
1176 | const e = target[i];
1177 | // create an observer instance
1178 | const ob = new MutationObserver(function(mutations) {
1179 | mutations.forEach(function(mutation) {
1180 | // handle attributes seperately if passed in i.e if you dont pass any attrs in then it will only spy on DOM/node changes
1181 |
1182 | if (mutation.type === 'attributes') {
1183 | if (attrs[0] !== 'none') {
1184 | setTimeout((t) => {
1185 | fn(e);
1186 | }, delay);
1187 | }
1188 | } else {
1189 | if (attrs[0] === 'none') {
1190 | if (mutation.type === 'childList' || mutation.type === 'subtree' || mutation.type === 'characterData' ) {
1191 | setTimeout((t) => {
1192 | // console.log('mutor type '+mutation.type);
1193 | fn(e);
1194 | }, delay);
1195 | }// end childList
1196 | }
1197 | }
1198 | });
1199 | });
1200 | // add to yumobservers object, pass in target nodes, and observer config
1201 | // Do not allow spy with same name to exist - i.e the user might try to use same name on different object leaving the first one with a data-spy attr so just return here
1202 | const spydat = document.querySelector(`[data-spy="${name+i}"]`);
1203 | if (yumobservers[name+i] || spydat) {
1204 | throw new Error(`spy ${name} exists choose a different name`);
1205 | return;
1206 | }
1207 | _data(target[i], name+i, 'spy');
1208 | yumobservers[name+i] = ob;
1209 | yumobservers[name+i].observe(target[i], config);
1210 | }
1211 | return this;
1212 | }// end spy
1213 |
1214 | function unspy(name='name', yo=false ) {
1215 | if (yo) {
1216 | var yumobservers = yo.yob;
1217 | // console.log('I UNSPY COMPONENT YO');
1218 | } else {
1219 | var yumobservers = globalThis.yumobservers;
1220 | }
1221 |
1222 | // disconnect all
1223 | if (name === 'all') {
1224 | for ( const o in yumobservers) {
1225 | // console.log('disconnecting all');
1226 | yumobservers[o].disconnect();
1227 | }
1228 | } else {
1229 | const ykeys = Object.keys(yumobservers);
1230 | let kinc = -1;
1231 | // console.log('the keys' + ykeys);
1232 |
1233 | for ( const o of ykeys) {
1234 | if (o.startsWith(name) ) {
1235 | kinc++;
1236 | // console.log('unspying '+name+kinc);
1237 | }
1238 | if (yumobservers[name+kinc] || yumobservers[name]) {
1239 | let spydat;
1240 | if (o === name) {
1241 | spydat = document.querySelector(`[data-spy="${name}"]`);
1242 | // if called directly by name
1243 | // console.log('unspying direct '+name);
1244 | yumobservers[name].disconnect();
1245 | } else {
1246 | spydat = document.querySelector(`[data-spy="${name+kinc}"]`);
1247 | // console.log('unspying all that start with '+name);
1248 | yumobservers[name+kinc].disconnect();
1249 | }
1250 | if (spydat) {
1251 | // console.log('deleting spied '+typeof(spydat));
1252 | // these both work but the first is probably faster
1253 | spydat.removeAttribute('data-spy');
1254 | // _data(spydat, 'spy', 'remove');
1255 | }
1256 | }
1257 | }
1258 | }
1259 |
1260 | return this;
1261 | }
1262 |
1263 | /* END SPY and UNSPY */
1264 |
1265 |
1266 | /* END EVENTS */
1267 |
1268 | /* DOM TOOLS */
1269 | /* scroll to bottom of el */
1270 | function scroller(el) {
1271 | el.scrollTop = el.scrollHeight;
1272 | }
1273 |
1274 | /*
1275 | function xscrollTo(to) {// object paramater for behavior smooth doesnt work in safari maybe some day it will
1276 | if (typeof(to) === 'string') {
1277 | to = document.querySelectorAll(to)[0];
1278 | }else{
1279 | to = _stk[0];
1280 | }
1281 | let top = _rect(to, 'x');
1282 | console.log(top);
1283 | window.scroll({
1284 | top: top,
1285 | left: 0,
1286 | behavior: 'smooth'
1287 | });
1288 | return this;
1289 | }
1290 | */
1291 |
1292 |
1293 | function scrollTo(to) {
1294 | if (isString(to)) {
1295 | to = document.querySelectorAll(to)[0];
1296 | } else {
1297 | to = _stk[0];
1298 | }
1299 | to.scrollIntoView();
1300 | return this;
1301 | }
1302 |
1303 |
1304 | /* ATTR */
1305 | function removeAttr(str) {
1306 | attr(str, false, true);
1307 | return this;
1308 | }
1309 |
1310 | function _data(e, a, r='set') {
1311 | if (r === 'remove' ) {
1312 | e.removeAttribute('data-'+a);
1313 | }
1314 | if (r === 'set') {
1315 | e.setAttribute('data-'+a, a);
1316 | }
1317 |
1318 | if (r === 'spy') { // for setting data on spy elements
1319 | e.setAttribute('data-spy', a);
1320 | }
1321 |
1322 |
1323 | if (r === 'get') {
1324 | return e.getAttribute('data-'+a);
1325 | }
1326 | }
1327 |
1328 | function attr(str, s=false, r=false) {
1329 | if (str && isString(str)) {
1330 | if (r) {
1331 | for ( const y of _stk) {
1332 | y.removeAttribute(str);
1333 | }
1334 | return this;
1335 | }
1336 |
1337 |
1338 | if (isString(s) || typeof(s) === 'number' ) {
1339 | for ( const y of _stk) {
1340 | y.setAttribute(str, s);
1341 | }
1342 | return this;
1343 | }
1344 | if (!s) {
1345 | const a = _stk[0].getAttribute(str);
1346 | return a;
1347 | }
1348 | }
1349 | }
1350 |
1351 |
1352 | /* CSS */
1353 |
1354 | function __dumpCSS(el) {
1355 | let s = '';
1356 | const o = getComputedStyle(el);
1357 | for ( let i = 0; i < o.length; i++) {
1358 | if (o.getPropertyValue(o[i]).length) {
1359 | s+=o[i] + ':' + o.getPropertyValue(o[i])+';';
1360 | }
1361 | }
1362 | return s;
1363 | }
1364 |
1365 |
1366 | // set 2nd param to true to over write the css
1367 | function css(str, append = false) {
1368 | if (!append && !str) {
1369 | let style;
1370 | for ( const y of _stk) {
1371 | style += __dumpCSS(y);
1372 | // console.log('css for '+y);
1373 | }
1374 | return style;
1375 | }
1376 |
1377 |
1378 | if (!append) {
1379 | // console.log(str);
1380 | for ( const y of _stk) {
1381 | y.style.cssText = y.style.cssText + str;
1382 | }
1383 | } else {
1384 | for ( const y of _stk) {
1385 | y.style.cssText = str;
1386 | }
1387 | }
1388 | return this;
1389 | }
1390 | function fadeOut(delay=500) {
1391 | setTimeout((t) => {
1392 | for (const y of _stk) {
1393 | yum(y).css(`visibility: hidden; opacity: 0; transition: visibility 0s 2s, opacity 2s linear;`);
1394 | }
1395 | }, delay);
1396 | return this;
1397 | }
1398 |
1399 |
1400 | function fadeIn(delay=500) {
1401 | setTimeout((t) => {
1402 | for (const y of _stk) {
1403 | yum(y).css(`visibility: visible; opacity: 1; transition: opacity 2s linear;`);
1404 | }
1405 | }, delay);
1406 | return this;
1407 | }
1408 |
1409 |
1410 | function classToggle(str) {
1411 | if (isString(str)) {
1412 | for ( const y of _stk) {
1413 | y.classList.toggle(str);
1414 | }
1415 | }
1416 | return this;
1417 | }
1418 |
1419 | function toggle(dtype='block') {
1420 | for ( const s of _stk) {
1421 | if (!s.matches('body')) { // no toggling on the body in case the selector is invalid
1422 | let hid = false;
1423 |
1424 | if (s.style.opacity && Number(s.style.opacity) < 0.1) {
1425 | hid = true;
1426 | }
1427 |
1428 |
1429 | if (s.visibility === 'hidden') {
1430 | hid = true;
1431 | }
1432 |
1433 | const disp = getComputedStyle(s).display;
1434 | if (s.style.display === 'none' || disp === 'none') {
1435 | hid = true;
1436 | }
1437 |
1438 | if (hid) {
1439 | s.visibility = 'visible';
1440 | s.style.opacity = 1;
1441 | s.style.display = dtype;
1442 | }
1443 |
1444 | if (!hid) {
1445 | s.style.opacity = 0;
1446 | s.visibility = 'hidden';
1447 | s.style.display = dtype;
1448 | }
1449 | }
1450 | }
1451 |
1452 | return this;
1453 | }
1454 |
1455 | function after(str) {
1456 | __beforeOrAfter(str);
1457 | return this;
1458 | }
1459 |
1460 |
1461 | function before(str) {
1462 | __beforeOrAfter(str, true);
1463 | return this;
1464 | }
1465 |
1466 | function insertBefore(str) {
1467 | __beforeOrAfter(str, true, true);
1468 | return this;
1469 | }
1470 |
1471 | function insertAfter(str) {
1472 | __beforeOrAfter(str, false, true);
1473 | return this;
1474 | }
1475 |
1476 |
1477 | function __beforeOrAfter(str, p=false, I=false ) {
1478 | for ( const y of _stk) {
1479 | if (isString(str)) {
1480 | // only append to first one found
1481 | let to;
1482 | if (__isHTML(str)) {
1483 | to = __procHTML(__isHTML(str, true), true);
1484 | if (!to) {
1485 | break;
1486 | }// break out of for if to does not exist
1487 | } else {
1488 | to = document.querySelectorAll(str)[0];
1489 | if (!to) {
1490 | break;
1491 | }// break out of for if to does not exist
1492 | }
1493 | if (p) {
1494 | if (I) {
1495 | to.before(y);
1496 | } else {
1497 | y.before(to);
1498 | }
1499 | } else {
1500 | if (I) {
1501 | to.after(y);
1502 | } else {
1503 | y.after(to);
1504 | }
1505 | }
1506 | }
1507 | if ( isObject(str) && str.nodeType == 1) {
1508 | if (p) {
1509 | if (I) {
1510 | str.before(y);
1511 | } else {
1512 | y.before(str);
1513 | }
1514 | } else {
1515 | if (I) {
1516 | str.after(y);
1517 | } else {
1518 | y.after(str);
1519 | }
1520 | }
1521 | }
1522 | return this;
1523 | }
1524 | }
1525 |
1526 | // APPEND
1527 | function append(str, p=false) {
1528 | if (!str) {
1529 | return this;
1530 | }
1531 | // console.log('type of str '+ typeof(str));
1532 | for ( const y of _stk) {
1533 | if (isString(str)) {
1534 | // only append to first one found
1535 | let el;
1536 | if (__isHTML(str)) {
1537 | el = __procHTML(__isHTML(str, true), true);
1538 | } else {
1539 | el = str;
1540 | }
1541 | if (p) {
1542 | y.prepend(el);
1543 | } else {
1544 | y.append(el);
1545 | }
1546 | } else {
1547 | if (p) {
1548 | y.prepend(str);
1549 | // console.log('prepending');
1550 | } else {
1551 | y.append(str);
1552 | // console.log('not prepending');
1553 | }
1554 | }
1555 | }
1556 | return this;
1557 | }
1558 |
1559 | // PREPEND
1560 | function prepend(str) {
1561 | if (!str) {
1562 | return this;
1563 | }
1564 | append(str, true);
1565 | return this;
1566 | }
1567 |
1568 | // APPENDTO AND PREPENDTO
1569 | function prependTo(str) {
1570 | if (!str) {
1571 | return this;
1572 | }
1573 |
1574 |
1575 | __To(str, true);
1576 | return this;
1577 | }
1578 |
1579 |
1580 | function appendTo(str, p=false) {
1581 | if (!str) {
1582 | return this;
1583 | }
1584 |
1585 | __To(str);
1586 | return this;
1587 | }
1588 |
1589 | function __To(str, p=false) {
1590 | for ( const y of _stk) {
1591 | if (isString(str)) {
1592 | // only append to first one found
1593 | const to = document.querySelectorAll(str)[0];
1594 | if (!to) {
1595 | return this;
1596 | }
1597 | if (p) {
1598 | to.prepend(y);
1599 | } else {
1600 | to.append(y);
1601 | }
1602 | }
1603 | if ( isObject(str) && str.nodeType == 1) {
1604 | if (p) {
1605 | str.prepend(y);
1606 | } else {
1607 | str.append(y);
1608 | }
1609 | }
1610 | return this;
1611 | }
1612 | }
1613 |
1614 |
1615 |
1616 |
1617 | function show(dtype='block', op=1, v='visible') {
1618 | for ( const y of _stk) {
1619 | y.style.visibility = v;
1620 | y.style.display = dtype;
1621 | y.style.opacity = op;
1622 | }
1623 | return this;
1624 | }
1625 |
1626 | function hide(dtype='none', op=1, v='hidden') {
1627 | for ( const y of _stk) {
1628 | y.style.visibility = v;
1629 | y.style.display = dtype;
1630 | y.style.opacity = op;
1631 | }
1632 | return this;
1633 | }
1634 |
1635 |
1636 |
1637 |
1638 | // PARENT for each element in the stack put each direct parent on the stack and subsequent chains will act on the parent/s - if You want to return the collection chain with ._ or .first to return the first parent of the stack
1639 | function parent() {
1640 | let nstk = [];// the new stack
1641 | for ( const y of _stk) {
1642 | nstk.push(y.parentElement);
1643 | // console.log(y.parentElement.classList);
1644 | }
1645 | if (nstk.length) {
1646 | // console.log('GOT nstk');
1647 | nstk = nstk.filter((x, i, a) => a.indexOf(x) == i);
1648 | _stk = nstk.slice(0);
1649 | obj._ = _stk;
1650 | obj.first = _stk[0];
1651 | // make stack unique since elements could have the same parent
1652 | }
1653 | return this;
1654 | }
1655 |
1656 | // PARENTS
1657 | function parents(fn=false, matchsel=false) {
1658 | // if matchsel then only operate on matches
1659 | // if fn is a function run fn against all parents[done];
1660 | // if fn is not a function(maybe bool) push all parents to an array and replace the _stk with the new array (nstk) of parents so that we the next chained functions will operate on them (like css or text or html etc)
1661 | const nstk = [];// the new stack
1662 |
1663 |
1664 | if (matchsel) {
1665 | for ( const y of _stk) {
1666 | let els = y;
1667 | while (els = els.parentElement) {
1668 | if (els.matches(matchsel)) {
1669 | nstk.push(els);
1670 | }
1671 | }
1672 | }
1673 | }
1674 |
1675 | if (!matchsel) {
1676 | for ( const y of _stk) {
1677 | let els = y;
1678 | while (els = els.parentElement) {
1679 | nstk.push(els);
1680 | }
1681 | }
1682 | }
1683 | // if nstk has anything in it then replace the _stk with the new stack of parents so that subsequent chains act upon the parents
1684 | if (nstk.length) {
1685 | _stk = nstk.slice(0);
1686 |
1687 | // make stack unique since elements could have the same parent
1688 | _stk = _stk.filter((x, i, a) => a.indexOf(x) == i);
1689 | obj._ = _stk;// update _ function to reflect new _stk
1690 | obj.first = _stk[0];
1691 | if (isFunction(fn)) {
1692 | for ( const y of _stk) {
1693 | fn(y);
1694 | }
1695 | }
1696 | }
1697 | return this;
1698 | }
1699 |
1700 |
1701 | // CHILDREN
1702 | // finds only direct children of elements on stack but children.children will keep going if first in chain is true
1703 | // str can be singular selector, nothing or comma delim list of selectors, fn if passed in will run on each found child
1704 | function children(str, fn=false) {
1705 | // str can be comma delim list of selectors to match
1706 | let starr=[];
1707 | if (isString(str)) {
1708 | starr = str.split(',');
1709 | }
1710 | // console.log('starr is '+starr);
1711 | const carr = [];// the children array
1712 | for ( const y of _stk) {
1713 | const c = y.children;// a collections of child nodes for each item on the stack;
1714 | // each item on the stacks children are pushed to carr array
1715 | for (let i = 0; i < c.length; i++) {
1716 | if (starr.length) {
1717 | for ( const a of starr) {
1718 | if (c[i].matches(a)) {
1719 | carr.push(c[i]);
1720 | // console.log(c[i].classList);
1721 | }
1722 | }
1723 | }
1724 | // no selectors just get all children
1725 | else {
1726 | carr.push(c[i]);
1727 | // console.log(i);
1728 | }
1729 | }
1730 | }// end outer for
1731 |
1732 | // we got some so change the stack
1733 | if (carr.length) {
1734 | _stk = carr.slice(0);
1735 | obj._ = _stk;
1736 | obj.first = _stk[0];
1737 |
1738 | // if a function was passed execute it for every element of the new stack
1739 | if (isFunction(fn)) {
1740 | for ( const y of _stk) {
1741 | fn(y);
1742 | }
1743 | }
1744 | }
1745 |
1746 | if (!carr.length) {
1747 | // return false; // this was set to stop the stack being changed when no children were found but that causes errors so..
1748 | // instead of returning false create a fake node but never add it to the document it so chaining still works
1749 | const faux = _createNode('span');
1750 | _stk = [faux];
1751 | obj._ = _stk;
1752 | obj.first = _stk[0];
1753 | faux.remove();
1754 | }
1755 |
1756 | return this;
1757 | }
1758 |
1759 | // FIND
1760 | // can pass in a selector that is valid to querySelector all or a singular element
1761 | function find(str, fn=false) {
1762 | const farr = [];// the found array
1763 | let type = 's';
1764 | if (isObject(str)) {
1765 | type = 'o';
1766 | }
1767 | for ( const y of _stk) {
1768 | // fn(y);
1769 | if (type !== 'o') {
1770 | const sel = y.querySelectorAll(str);
1771 | for ( const s of sel) {
1772 | // console.log(s.classList);
1773 | farr.push(s);
1774 | }
1775 | }// end is selector
1776 | // if an actual object element was sent in
1777 | else {
1778 | for ( const y of _stk) {
1779 | if (y.contains(str)) {
1780 | farr.push(str);
1781 | }
1782 | }
1783 | }
1784 | }// end for
1785 |
1786 | // we got some so change the stack
1787 | if (farr.length) {
1788 | _stk = farr.slice(0);
1789 | obj._ = _stk;
1790 | obj.first = _stk[0];
1791 | // if a function was passed execute it for every element of the new stack
1792 | if (isFunction(fn)) {
1793 | for ( const y of _stk) {
1794 | fn(y);
1795 | }
1796 | }
1797 | }
1798 |
1799 | if (!farr.length) {
1800 | // return false; // this was set to stop the stack being changed when no children were found but that causes errors so..
1801 | // instead of returning false create a fake node but never add it to the document it so chaining still works
1802 | const faux = _createNode('span');
1803 | _stk = [faux];
1804 | obj._ = _stk;
1805 | obj.first = _stk[0];
1806 | faux.remove();
1807 | }
1808 | return this;
1809 | }
1810 |
1811 |
1812 | // FOREVERY
1813 | function forEvery(str, fn) {
1814 | for ( const y of _stk) {
1815 | // console.log(str);
1816 | if (y.matches(str)) {
1817 | if (isFunction(fn)) {
1818 | fn(y);
1819 | }
1820 | }
1821 | }
1822 | return this;
1823 | }
1824 |
1825 | // EACH
1826 | function each(fn) {
1827 | for ( const y of _stk) {
1828 | fn(y);
1829 | }
1830 | return this;
1831 | }
1832 |
1833 | function detach() {
1834 | for ( const y of _stk) {
1835 | y.remove();
1836 | }
1837 | return this;
1838 | }
1839 |
1840 |
1841 | // addClass
1842 | function addClass(s, r=false) {
1843 | for ( const y of _stk) {
1844 | if (!r) {
1845 | y.classList.add(s);
1846 | } else {
1847 | // console.log('I should remove class');
1848 | y.classList.remove(s);
1849 | }
1850 | }
1851 | return this;
1852 | }
1853 | // removeClass
1854 | function removeClass(s) {
1855 | addClass(s, true); // call addClass with remove option
1856 | return this;
1857 | }
1858 |
1859 |
1860 | function clearfx() {
1861 | for ( const y of _stk) {
1862 | y.farr = [];
1863 | y.lock = false;
1864 | y.step = 0;
1865 | }
1866 |
1867 | return this;
1868 | }
1869 |
1870 | // PLUGIN
1871 | // time is the distance away from each subsequent fx chains on the same element. If incTime set is used to specify the distance between iterations and if not set time is used
1872 | // You can set raf to false to not use requestAnimation frame
1873 | function plug(fn, {time = 10, step = 1, iterate = 1, incTime = 0, logTime = false, raf = true} = 1) {
1874 | let count = 0;
1875 | for ( const y of _stk) {
1876 | y.lock = y.lock || false; // Performing an external check if lock exists can be used to block events until the lock is cleared
1877 | y.step = step;
1878 | let ttime = time; // temp time
1879 | if (iterate >= 1) {
1880 | const tarr = [...Array(iterate).keys()];
1881 | // console.log(`tarr is ${tarr}`);
1882 | for (let i of tarr) {
1883 | i += 1;
1884 | if (incTime) {
1885 | ttime = time + (Number(incTime) * i);
1886 | } else {
1887 | ttime = time * Number(i);
1888 | }
1889 | if (logTime) {
1890 | console.log(`time is ${ttime}`);
1891 | }
1892 | q(y, fn, ttime, y.step, iterate, raf);
1893 | y.count = count++;
1894 | }
1895 | } else {
1896 | q(y, fn, ttime, y.step, iterate, raf);
1897 | y.count = count++;
1898 | }
1899 | }
1900 | return this;
1901 | }
1902 |
1903 | function q(y, fnc, time, step, itr=0, raf) {
1904 | y.lock = true;
1905 |
1906 | let rAF;
1907 | if (raf) {
1908 | rAF = (
1909 | window.requestAnimationFrame ||
1910 | window.mozRequestAnimationFrame ||
1911 | window.webkitRequestAnimationFrame ||
1912 | window.msRequestAnimationFrame || false
1913 | );
1914 |
1915 | if (!rAF) {
1916 | // console.log('no RAF so defaulting to setInterval');
1917 | raf = false;
1918 | }
1919 | }
1920 |
1921 |
1922 | let intv;
1923 | intv = setInterval((t)=>{
1924 | // console.log('iterating');
1925 | if (raf) {
1926 | // console.log('rAFing');
1927 | function dofnc() {
1928 | fnc(y, step, itr);
1929 | }
1930 | rAF(dofnc);
1931 | } else {
1932 | fnc(y, step, itr);
1933 | }
1934 |
1935 | y.count--;
1936 | if (y.count <= 0) {
1937 | y.lock = false;
1938 | }
1939 | clearInterval(intv);
1940 | }, time);
1941 |
1942 | window.onblur = function() {
1943 | clearInterval(intv);
1944 | };
1945 | }
1946 |
1947 | // bare bones plug
1948 | function fn(f) {
1949 | f(_stk);
1950 | return this;
1951 | }
1952 |
1953 |
1954 | /*
1955 | // a TEMPLATE for future use
1956 | function template() {
1957 | for ( let y of _stk) {
1958 | // console.log(y.classList);
1959 | }
1960 | return this;
1961 | }
1962 | */
1963 |
1964 | /* END DOM TOOLS */
1965 |
1966 |
1967 | /* STACK TOOLS */
1968 | function _getstack(num) {
1969 | // use like yum('.butt').getstack(0);
1970 | if (num === 'all') {
1971 | return _stk;
1972 | } else {
1973 | return _stk[num];
1974 | }
1975 | }
1976 |
1977 | /* END STACK TOOLS */
1978 |
1979 |
1980 | // replace multiple dashes with one
1981 | function _singleDash(str) {
1982 | str = str.trim().replace(/\s/g, '-');
1983 | str = str.replace(/-$/, '');
1984 | str = str.replace(/^-/, '');
1985 | str = str.replace(/-+/g, '-');
1986 | str = str.replace(/[^a-z0-9-]+/gi, '');
1987 | return str;
1988 | }
1989 | // return hyphenated names as camel case foo-foo becomes fooFoo
1990 | function _camelDash(str) {
1991 | str = _singleDash(str);
1992 | return str.split('-').reduce((a, b) => a + b.charAt(0).toUpperCase() + b.slice(1));
1993 | }
1994 | // DATA
1995 | function data(name, data=false) {
1996 | for ( const y of _stk) {
1997 | if (!y.data) {
1998 | y.data = {};
1999 | }
2000 |
2001 | if (name) {
2002 | name = _camelDash(name);
2003 | }
2004 |
2005 | const nm = name;
2006 | // if the name exists but the data is different, update it
2007 | if (y.data.nm && y.data[nm] !== data) {
2008 | y.data[nm] = data;
2009 | // console.log('UPDATE DATA '+data);
2010 | }
2011 |
2012 |
2013 | // if data doesnt exist by that name store it
2014 | if (name && !y.data.nm && data) {
2015 | y.data[nm] = data;
2016 | // console.log('STORE DATA '+data);
2017 | }
2018 |
2019 | // not name return what is in data
2020 | if (!name) {
2021 | // console.log('RETURN DATA ');
2022 | return y.data;
2023 | }
2024 |
2025 | if (name && !data) {
2026 | // retrieve the named data
2027 | const res = [];
2028 | const keys = Object.keys(y.data);
2029 | for ( const k of keys) {
2030 | // console.log('DATA NAME: '+k);
2031 | if (k === nm) {
2032 | res.push(y.data[k]);
2033 | }
2034 | }
2035 | // console.log('RETRIEVE DATA '+nm);
2036 | return res;
2037 | }
2038 | }
2039 | return this;
2040 | }
2041 |
2042 | function isString(thing) {
2043 | return typeof thing === 'string';
2044 | }
2045 |
2046 | function isFunction(thing) {
2047 | return typeof thing === 'function';
2048 | }
2049 |
2050 |
2051 | function isObject(thing) {
2052 | // arrays are objects too so use isArray if you want to find arrays
2053 | return typeof thing === 'object';
2054 | }
2055 |
2056 | function isArray(thing) {
2057 | if (Array.isArray(thing)) {
2058 | return true;
2059 | } else {
2060 | return false;
2061 | }
2062 | }
2063 |
2064 | function ctx(str='2d', obj=false) {
2065 | // obj can be context attributes see MDN
2066 | console.log(typeof(_stk[0]));
2067 | console.log('n name = '+_stk[0].nodeName);
2068 | if (_stk[0].tagName === 'CANVAS' || _stk[0].nodeName === 'CANVAS' || _stk[0] instanceof HTMLCanvasElement ) {
2069 | if (obj) {
2070 | return _stk[0].getContext(str, obj);
2071 | } else {
2072 | return _stk[0].getContext(str);
2073 | }
2074 | } else {
2075 | throw new Error( 'First argument to yum is not an instance of canvas.' );
2076 | }
2077 | }
2078 |
2079 | // App, to=element {options [pos=position, reactor = create a reactor, set reactor element to atom }
2080 | function _render(fn, to='body', {pos='append', reactor=true, state='state', initState=false, addClass=true, props=false} = 'nada' ) {
2081 | let position = 'append';
2082 |
2083 | if (pos) {
2084 | position = pos;
2085 | }
2086 |
2087 | // check if function
2088 | let h;
2089 | if (isFunction(fn)) {
2090 | h = fn(props); // returns the object to be inserted, Ex. let html = `1
`; let h = yum(html).first;
2091 |
2092 | if (addClass) {
2093 | yum(h).addClass(fn.name);
2094 | }
2095 |
2096 | if (reactor) {
2097 | yum(h).Reactor();
2098 | }
2099 | // local yumobservers
2100 | h.yob = {};
2101 | } else {
2102 | return;
2103 | }
2104 |
2105 |
2106 | if (!isFunction(h.react) && initState) {
2107 | h.react = function() {
2108 | console.log('initState property found but no el.react function');
2109 | };
2110 | }
2111 |
2112 | if (isFunction(h.ready)) {
2113 | yum(document).ready( function() {
2114 | h.ready();
2115 | });
2116 | }
2117 |
2118 | if (isFunction(h.react)) {
2119 | yum(h).ReactTo(h, fn.name, h.react, state);
2120 | if (initState === 0) {
2121 | h.atom.state = 0;
2122 | }
2123 | // dont run this if 0 was passed in
2124 | if (initState) {
2125 | h.atom.state = initState;
2126 | }
2127 | }
2128 |
2129 | // switch for pos
2130 | switch (position) {
2131 | case 'after':
2132 | yum(h).insertAfter(to);
2133 | break;
2134 |
2135 | case 'before':
2136 | yum(h).insertBefore(to);
2137 | break;
2138 |
2139 | case 'prepend':
2140 | yum(h).prependTo(to);
2141 | break;
2142 |
2143 | default:
2144 | yum(h).appendTo(to);
2145 | break;
2146 | }
2147 | return;
2148 | }
2149 |
2150 | const obj = {
2151 | first: _stk[0],
2152 | _: _stk,
2153 | _getstack: _getstack,
2154 | _createNode: _createNode,
2155 | _render: _render,
2156 | css: css,
2157 | ctx: ctx,
2158 | data: data,
2159 | parents: parents,
2160 | parent: parent,
2161 | _sfilter: _sfilter,
2162 | _uuidv4: _uuidv4,
2163 | addEvent: addEvent,
2164 | on: addEvent,
2165 | off: removeEvent,
2166 | removeEvent: removeEvent,
2167 | doDrag: doDrag,
2168 | drag: drag,
2169 | drg: drg,
2170 | swipe: swipe,
2171 | _isTouch: _isTouch,
2172 | _createEvent: _createEvent,
2173 | _ReactTo: _ReactTo,
2174 | ReactTo: ReactTo,
2175 | Reactor: Reactor,
2176 | _Route: _Route,
2177 | isFunction: isFunction,
2178 | isArray: isArray,
2179 | unReact: unReact,
2180 | scroller: scroller,
2181 | scrollTo: scrollTo,
2182 | text: text,
2183 | html: html,
2184 | attr: attr,
2185 | addClass: addClass,
2186 | removeClass: removeClass,
2187 | classToggle: classToggle,
2188 | toggle: toggle,
2189 | removeAttr: removeAttr,
2190 | before: before,
2191 | insertBefore: insertBefore,
2192 | insertAfter: insertAfter,
2193 | after: after,
2194 | append: append,
2195 | prepend: prepend,
2196 | appendTo: appendTo,
2197 | prependTo: prependTo,
2198 | forEvery: forEvery,
2199 | each: each,
2200 | show: show,
2201 | hide: hide,
2202 | detach: detach,
2203 | fadeIn: fadeIn,
2204 | fadeOut: fadeOut,
2205 | ready: ready,
2206 | delay: delay,
2207 | plug: plug,
2208 | fx: plug,
2209 | clearfx: clearfx,
2210 | spy: spy,
2211 | unspy: unspy,
2212 | trigger: trigger,
2213 | find: find,
2214 | children: children,
2215 | _eventDispatch: _eventDispatch,
2216 | _rpx: _rpx,
2217 | _rect: _rect,
2218 | _cs: _cs,
2219 | _singleDash: _singleDash,
2220 | _camelDash: _camelDash,
2221 | _getAtPt: _getAtPt,
2222 | fn: fn,
2223 | _cs: _cs,
2224 | };
2225 |
2226 |
2227 | return obj;
2228 | };
2229 |
--------------------------------------------------------------------------------
/yum.min.js:
--------------------------------------------------------------------------------
1 | function yum(e,...t){globalThis.yumobservers=globalThis.yumobservers||{};let n;if(Ve(e)){e();return this}let o=[];if(e){if(Be(e)){if(Array.isArray(e)){for(const t of e){if(t.nodeType===1){o.push(t)}}}else{if(e.nodeType==1){const t=[e];for(const e of t){if(e.nodeType===1){o.push(e)}}}}}if(e===window){o.push(e)}if(e.nodeName==="#document"){var r=false;(function e(t){if(document.readyState!="loading"){r=true}else if(document.addEventListener){document.addEventListener("DOMContentLoaded",(function(){r=true}))}else{document.attachEvent("onreadystatechange",(function(){if(document.readyState!="loading"){r=true}}))}})()}if(Ne(e)){n=e;e=e.split(",");e=e.filter((e,t,n)=>n.indexOf(e)==t);for(const t of e){if(x(t)){w(x(t,true))}else{let e;if(t.startsWith("#")){const n=t.replace(/#/,"");e=document.getElementById(n);o.push(e)}else if(t.startsWith(".")){const n=t.replace(/./,"");e=document.getElementsByClassName(n);for(const t of e){o.push(t)}}else{e=document.querySelectorAll(t);for(const t of e){o.push(t)}}}}}}t=t.filter((e,t,n)=>n.indexOf(e)==t);for(let e of t){if(Array.isArray(e)){for(const t of e){if(t.nodeType===1){o.push(t)}}}if(Be(e)){if(e.nodeType===1){o.push(e)}}if(Ne(e)){e=e.split(",");for(const t of e){const e=document.querySelectorAll(t);for(const t of e){if(t.nodeType===1){o.push(t)}}}}}let i;let f;function l(e,t=3e3){let n;let o=1;f=setInterval(t=>{if(r){clearInterval(f);clearTimeout(n);if(e&&Ve(e)&&o<=1){try{e();o++}catch(e){}}else{return true}}},6);n=setTimeout(e=>{r=true},t)}let c=1;let u=1;let a;let d=0;function p(){i=document.documentElement;a=(window.pageXOffset||i.scrollLeft)-(i.clientLeft||0);d=(window.pageYOffset||i.scrollTop)-(i.clientTop||0);d=_(d);a=_(a)}let h=false;function m(){return window.matchMedia("(pointer: coarse)").matches||false}if(m()){h=true}function y(e,t=false,n=false){let o=e;if(Ne(e)){o=document.querySelector(e)}const r=["x","y","width","height","right","left","top","bottom"];if(!r.includes(t)){return null}const s=o.getBoundingClientRect()[t];if(n){return Math.round(s)}else{return s}}function g(e,t,n=false){if(Ne(e)){e=document.querySelector(e)}if(e){let o=getComputedStyle(e).getPropertyValue(t)||null;if(n){try{o=_(o)}catch(e){}}return o}}function b(e=false,t="all"){let n="";if(!e&&t==="all"){for(const e of o){n+=e.innerHTML}return n}T(e,t="all");return this}function v(e,t="all"){let n="";if(!e&&t==="all"){for(const e of o){n+=e.textContent}return n}T(e,t="all",true);return this}function T(e,t="all",n=false){const r="";let s=0;for(const r of o){if(C(t)&&s<=t){s++;if(n){r.textContent=e}else{r.innerHTML=e}}if(t==="all"){if(n){r.textContent=e}else{r.innerHTML=e}}}return this}function w(e,t=false){const n=document.createElement(e[0]);n.innerHTML=e[1];if(t){return n}else{o.push(n)}}function x(e,t=false){const n=(new DOMParser).parseFromString(e,"text/html");if(t){return[n.body.childNodes[0].tagName.toLowerCase(),n.body.childNodes[0].innerHTML]}else{return Array.from(n.body.childNodes).some(e=>e.nodeType===1)}}function E(e,t=false){e=e.replace(/[^\x20-\x7E]+/g,"");if(t){e=e.replace(/[^a-z0-9-#]+|\s+/gim,"")}e=e.trim();return e}function A(e="div",t=false,n="default"){const o=["html","head","link","meta","script","style","title","body","article","aside","footer","header","h1","h2","h3","h4","h5","h6","main","nav","section","blockquote","div","figure","hr","li","ol","p","pre","ul","a","code","data","time","em","i","span","strong","audio","source","img","track","video","iframe","svg","canvas","noscript","col","colgroup","button","option","fieldset","label","form","input","select","textarea","menu","template"];if(!o.includes(e)){if(!t){e="div"}}const r=document.createElement(e);return r}function L(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))}function S(e=500,t){setTimeout(e=>{for(const e of o){t(e)}},e);return this}function C(e){return/^-{0,1}\d+$/.test(e)}function M(e){if(!e){for(const e of o){setTimeout((function(){e.onfocus=blur()}),100)}}}function _(e){e=e.toString();return Math.round(Number(e.replace(/px/g,"")))}function k(e){const t=getComputedStyle(e);const n=parseInt(t.paddingTop)+parseInt(t.paddingBottom);const o=_(t.getPropertyValue("margin-top"))||0;const r=_(t.getPropertyValue("margin-bottom"))||0;const s=_(t.getPropertyValue("margin-left"))||0;const i=_(t.getPropertyValue("margin-right"))||0;return[o,s,r,i]}function q(e,t){return document.elementFromPoint(e,t)}function R(e,t=false,n=false){const o=new Event(e,{bubbles:t,cancelable:n});return o}function O(e,t){t.dispatchEvent(e)}function N(e="mousedown",t,n=false){let r=n;if(typeof n==="boolean"){if(n){r={capture:true}}else{r={capture:false}}}const s=e.split(",");for(const e of o){for(let n of s){n=n.trim();e.addEventListener(n,t,r)}}return this}function V(e="mousedown",t,n=false){let r=n;if(typeof n==="boolean"){if(n){r={capture:true}}else{r={capture:false}}}const s=e.split(",");for(const e of o){for(const n of s){e.removeEventListener(n,t,r)}}return this}function B(){if(h){I(o[0])}else{D(false,o[0],{})}return this}function D(e,{drop:t=".droppable",drpfn:n=false,lvupfn:r=false,zindex:s=false,contain:i=false}){if(e&&typeof e!=="function"){e=o[0].parentNode}else{e=o[0]}if(!s){s=1006}if(h){I(e,t,n,r,s,i)}else{const f=function(n){if(h){setTimeout(e=>{M(n)},20)}else{stopped=false;H(o[0],n,e,t,false,false,s,i)}o[0].style.cursor="move"};const l=function(e){const o=document.querySelector(t);const s=K(e.target,"dropping","get");if(s){if(Ve(n)){if(o){n(o,e.target)}}}if(!s){if(Ve(r)){if(o){r(o,e.target)}}}};N("mousedown, touchstart",f,true);N("mouseup",l,true)}return this}function H(e,t,n,o=false,r,s,i=false,f=false){if(!n)return;t.preventDefault();n.ondragstart=function(){return false};let l;let m;if(h){}let y=o;if(y){y=document.querySelector(o)}else{y=document.querySelector(".droppable")}let g=f;if(g){if(g!=="no"){g=document.querySelector(f)}}else{g=document.documentElement||document.querySelector("body")||window}let b=0;const v=k(n);const[T,w,x]=v;b=w+x;let E=false;n.style.position="absolute";n.style.marginTop=0;n.style.marginLeft=0;n.style.marginRight=0;n.style.zIndex=i;l=t.clientX-n.getBoundingClientRect().left-b;m=t.clientY-n.getBoundingClientRect().top-T;if(h){const e=t.targetTouches[0];l=e.pageX-n.getBoundingClientRect().left-b;m=e.pageY-n.getBoundingClientRect().top-T}function A(e,t){e=Math.round(e);t=Math.round(t);l=Math.round(l);m=Math.round(m);p();if(h){e=e+a;t=t+d}if(h){n.style.left=e-l+"px";n.style.top=t-m+"px";u=e;c=t}else{n.style.left=e-l+"px";n.style.top=t-m+"px";u=e;c=t}if(y){L(n,y,e,t)}}function L(e,t,n,o){p();const r=y.getBoundingClientRect();const s=e.getBoundingClientRect();if(h){n=n-a;o=o-d}const i=_(s.top)+d;const f=_(r.top)+d;if(of){l=true}const u=_(s.y)-d;const m=_(r.y)+t.offsetHeight+d;if(o>m){l=false}if(nr.x+t.offsetWidth+a){c=false}if(l&&c){K(e,"dropping","set")}else{K(e,"dropping","remove")}}function S(e,t,n,o){p();const r=t.getBoundingClientRect();const s=e.getBoundingClientRect();const i=_(s.top)+d;const f=_(r.top)+d;if(oc){e.style.top=c-e.offsetHeight-6+"px";E=true;return}if(l-c>c){o=c-20;e.style.top=c-e.offsetHeight-3+"px";E=true;return}if(s.xr.x+t.offsetWidth){e.style.left=r.x+t.offsetWidth-e.offsetWidth-3+"px";E=true;return}}if(h){function C(e){e.preventDefault();const t=e.targetTouches[0];try{if(g){M(e.target,g,t.pageX,t.pageY)}if(!E){A(t.pageX,t.pageY)}}catch(e){}}e.addEventListener("touchmove",C,true);function M(e,t,n,o){S(e,t,n,o)}function q(t){try{E=false;if(o){const e=function(e){const t=document.querySelector(o);const n=K(e.target,"dropping","get");if(n){if(Ve(r)){if(t){r(t,e.target)}}}if(!n){if(Ve(s)){if(t){s(t,e.target)}}}};e(t)}}catch(t){}e.removeEventListener("touchend",q,true);e.removeEventListener("touchmove",C,true)}e.addEventListener("touchend",q,true)}else{if(!E){A(t.pageX,t.pageY)}globalThis.onMouseMove=function(e){e.preventDefault();if(g){S(n,g,e.pageX,e.pageY)}if(!E){A(e.pageX,e.pageY)}};document.addEventListener("mousemove",onMouseMove,true);n.onmouseup=function(){document.removeEventListener("mousemove",onMouseMove,true);n.onmouseup=null};e.onmouseup=function(){document.removeEventListener("mousemove",onMouseMove,true);e.onmouseup=null};document.onmouseup=function(){document.removeEventListener("mousemove",onMouseMove,true);e.onmouseup=null};e.ondragstart=function(){return false}}}function I(e,t=false,n=false,r=false,i=1006,f=false){let l=false;let c;if(Ve(e)||!e){l=true;if(e){c=e}}let u;if(t&&Ve(t)&&l){u=t}var a;if(n&&Ve(n)&&l){a=n}var a;if(r&&Ve(r)&&l){swipedown=r}s=o[0];s.addEventListener("touchstart",g,false);s.addEventListener("touchmove",b,false);s.addEventListener("touchend",y,false);let d=null;let p=null;let h=false;if(s.matches(".draggable")&&!l){h=true}function m(s){s.preventDefault();if(h){H(o[0],s,e,t,n,r,i,f)}}function y(e){return}function g(e){const t=e.targetTouches[0];d=t.pageX;p=t.pageY}function b(e){e.preventDefault();if(!d||!p){return}const t=e.targetTouches[0];const n=t.pageX;const o=t.pageY;const r=d-n;const s=p-o;if(Math.abs(r)>Math.abs(s)){if(r>0){if(l&&c){c(e)}m(e)}else{if(l&&u){u(e)}m(e)}}else{if(s>0){if(l&&a){a(e)}m(e)}else{if(l&&swipedown){swipedown(e)}m(e)}}d=null;p=null;if(l){}}return this}function P(e,...t){let n;const o=globalThis.location.search;const r=globalThis.location.hash;let s=globalThis.location.pathname;if(!e){return globalThis.location.pathname}if(Ne(e)){if(e.match(/^[?#&]/)){if(r!==e){if(e.match(/^[#]/)){s=s.replace(/\/$/,"")}return}}if(e.match(/^[?#&]/)&&e===r){return}}n=e+"/";if(t.length){for(const e of t){if(e.match(/^[?#&]/)){n+=e}else{n+=e+"/"}}}const i=globalThis.location.pathname+o;if(i!=="/"+n){globalThis.location="/"+n}}function X(e){if(e){e=Re(e)}else{e="atom"}for(const t of o){t.subscribers=[];t.reactor={set:function(e,n,o){for(let e=0;e{e(r)},n)}}else{if(f[0]==="none"){if(t.type==="childList"||t.type==="subtree"||t.type==="characterData"){setTimeout(t=>{e(r)},n)}}}}))}));const i=document.querySelector(`[data-spy="${t+o}"]`);if(d[t+o]||i){throw new Error(`spy ${t} exists choose a different name`);return}K(h[o],t+o,"spy");d[t+o]=s;d[t+o].observe(h[o],p)}return this}function z(e="name",t=false){if(t){var n=t.yob}else{var n=globalThis.yumobservers}if(e==="all"){for(const e in n){n[e].disconnect()}}else{const t=Object.keys(n);let o=-1;for(const r of t){if(r.startsWith(e)){o++}if(n[e+o]||n[e]){let t;if(r===e){t=document.querySelector(`[data-spy="${e}"]`);n[e].disconnect()}else{t=document.querySelector(`[data-spy="${e+o}"]`);n[e+o].disconnect()}if(t){t.removeAttribute("data-spy")}}}}return this}function U(e){e.scrollTop=e.scrollHeight}function G(e){if(Ne(e)){e=document.querySelectorAll(e)[0]}else{e=o[0]}e.scrollIntoView();return this}function J(e){Q(e,false,true);return this}function K(e,t,n="set"){if(n==="remove"){e.removeAttribute("data-"+t)}if(n==="set"){e.setAttribute("data-"+t,t)}if(n==="spy"){e.setAttribute("data-spy",t)}if(n==="get"){return e.getAttribute("data-"+t)}}function Q(e,t=false,n=false){if(e&&Ne(e)){if(n){for(const t of o){t.removeAttribute(e)}return this}if(Ne(t)||typeof t==="number"){for(const n of o){n.setAttribute(e,t)}return this}if(!t){const t=o[0].getAttribute(e);return t}}}function Z(e){let t="";const n=getComputedStyle(e);for(let e=0;e{for(const e of o){yum(e).css(`visibility: hidden; opacity: 0; transition: visibility 0s 2s, opacity 2s linear;`)}},e);return this}function ne(e=500){setTimeout(e=>{for(const e of o){yum(e).css(`visibility: visible; opacity: 1; transition: opacity 2s linear;`)}},e);return this}function oe(e){if(Ne(e)){for(const t of o){t.classList.toggle(e)}}return this}function re(e="block"){for(const t of o){if(!t.matches("body")){let n=false;if(t.style.opacity&&Number(t.style.opacity)<.1){n=true}if(t.visibility==="hidden"){n=true}const o=getComputedStyle(t).display;if(t.style.display==="none"||o==="none"){n=true}if(n){t.visibility="visible";t.style.opacity=1;t.style.display=e}if(!n){t.style.opacity=0;t.visibility="hidden";t.style.display=e}}}return this}function se(e){ce(e);return this}function ie(e){ce(e,true);return this}function fe(e){ce(e,true,true);return this}function le(e){ce(e,false,true);return this}function ce(e,t=false,n=false){for(const r of o){if(Ne(e)){let o;if(x(e)){o=w(x(e,true),true);if(!o){break}}else{o=document.querySelectorAll(e)[0];if(!o){break}}if(t){if(n){o.before(r)}else{r.before(o)}}else{if(n){o.after(r)}else{r.after(o)}}}if(Be(e)&&e.nodeType==1){if(t){if(n){e.before(r)}else{r.before(e)}}else{if(n){e.after(r)}else{r.after(e)}}}return this}}function ue(e,t=false){if(!e){return this}for(const n of o){if(Ne(e)){let o;if(x(e)){o=w(x(e,true),true)}else{o=e}if(t){n.prepend(o)}else{n.append(o)}}else{if(t){n.prepend(e)}else{n.append(e)}}}return this}function ae(e){if(!e){return this}ue(e,true);return this}function de(e){if(!e){return this}he(e,true);return this}function pe(e,t=false){if(!e){return this}he(e);return this}function he(e,t=false){for(const n of o){if(Ne(e)){const o=document.querySelectorAll(e)[0];if(!o){return this}if(t){o.prepend(n)}else{o.append(n)}}if(Be(e)&&e.nodeType==1){if(t){e.prepend(n)}else{e.append(n)}}return this}}function me(e="block",t=1,n="visible"){for(const r of o){r.style.visibility=n;r.style.display=e;r.style.opacity=t}return this}function ye(e="none",t=1,n="hidden"){for(const r of o){r.style.visibility=n;r.style.display=e;r.style.opacity=t}return this}function ge(){let e=[];for(const t of o){e.push(t.parentElement)}if(e.length){e=e.filter((e,t,n)=>n.indexOf(e)==t);o=e.slice(0);Pe._=o;Pe.first=o[0]}return this}function be(e=false,t=false){const n=[];if(t){for(const e of o){let o=e;while(o=o.parentElement){if(o.matches(t)){n.push(o)}}}}if(!t){for(const e of o){let t=e;while(t=t.parentElement){n.push(t)}}}if(n.length){o=n.slice(0);o=o.filter((e,t,n)=>n.indexOf(e)==t);Pe._=o;Pe.first=o[0];if(Ve(e)){for(const t of o){e(t)}}}return this}function ve(e,t=false){let n=[];if(Ne(e)){n=e.split(",")}const r=[];for(const e of o){const t=e.children;for(let e=0;e=1){const n=[...Array(r).keys()];for(let u of n){u+=1;if(s){o=t+Number(s)*u}else{o=t*Number(u)}if(i){console.log(`time is ${o}`)}Me(c,e,o,c.step,r,f);c.count=l++}}else{Me(c,e,o,c.step,r,f);c.count=l++}}return this}function Me(e,t,n,o,r=0,s){e.lock=true;let i;if(s){i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||false;if(!i){s=false}}let f;f=setInterval(n=>{if(s){function l(){t(e,o,r)}i(l)}else{t(e,o,r)}e.count--;if(e.count<=0){e.lock=false}clearInterval(f)},n);window.onblur=function(){clearInterval(f)}}function _e(e){e(o);return this}function ke(e){if(e==="all"){return o}else{return o[e]}}function qe(e){e=e.trim().replace(/\s/g,"-");e=e.replace(/-$/,"");e=e.replace(/^-/,"");e=e.replace(/-+/g,"-");e=e.replace(/[^a-z0-9-]+/gi,"");return e}function Re(e){e=qe(e);return e.split("-").reduce((e,t)=>e+t.charAt(0).toUpperCase()+t.slice(1))}function Oe(e,t=false){for(const n of o){if(!n.data){n.data={}}if(e){e=Re(e)}const o=e;if(n.data.nm&&n.data[o]!==t){n.data[o]=t}if(e&&!n.data.nm&&t){n.data[o]=t}if(!e){return n.data}if(e&&!t){const e=[];const t=Object.keys(n.data);for(const r of t){if(r===o){e.push(n.data[r])}}return e}}return this}function Ne(e){return typeof e==="string"}function Ve(e){return typeof e==="function"}function Be(e){return typeof e==="object"}function De(e){if(Array.isArray(e)){return true}else{return false}}function He(e="2d",t=false){console.log(typeof o[0]);console.log("n name = "+o[0].nodeName);if(o[0].tagName==="CANVAS"||o[0].nodeName==="CANVAS"||o[0]instanceof HTMLCanvasElement){if(t){return o[0].getContext(e,t)}else{return o[0].getContext(e)}}else{throw new Error("First argument to yum is not an instance of canvas.")}}function Ie(e,t="body",{pos:n="append",reactor:o=true,state:r="state",initState:s=false,addClass:i=true,props:f=false}="nada"){let l="append";if(n){l=n}let c;if(Ve(e)){c=e(f);if(i){yum(c).addClass(e.name)}if(o){yum(c).Reactor()}c.yob={}}else{return}if(!Ve(c.react)&&s){c.react=function(){console.log("initState property found but no el.react function")}}if(Ve(c.ready)){yum(document).ready((function(){c.ready()}))}if(Ve(c.react)){yum(c).ReactTo(c,e.name,c.react,r);if(s===0){c.atom.state=0}if(s){c.atom.state=s}}switch(l){case"after":yum(c).insertAfter(t);break;case"before":yum(c).insertBefore(t);break;case"prepend":yum(c).prependTo(t);break;default:yum(c).appendTo(t);break}return}const Pe={first:o[0],_:o,_getstack:ke,_createNode:A,_render:Ie,css:ee,ctx:He,data:Oe,parents:be,parent:ge,_sfilter:E,_uuidv4:L,addEvent:N,on:N,off:V,removeEvent:V,doDrag:H,drag:D,drg:B,swipe:I,_isTouch:m,_createEvent:R,_ReactTo:F,ReactTo:Y,Reactor:X,_Route:P,isFunction:Ve,isArray:De,unReact:W,scroller:U,scrollTo:G,text:v,html:b,attr:Q,addClass:Ae,removeClass:Le,classToggle:oe,toggle:re,removeAttr:J,before:ie,insertBefore:fe,insertAfter:le,after:se,append:ue,prepend:ae,appendTo:pe,prependTo:de,forEvery:we,each:xe,show:me,hide:ye,detach:Ee,fadeIn:ne,fadeOut:te,ready:l,delay:S,plug:Ce,fx:Ce,clearfx:Se,spy:j,unspy:z,trigger:$,find:Te,children:ve,_eventDispatch:O,_rpx:_,_rect:y,_cs:g,_singleDash:qe,_camelDash:Re,_getAtPt:q,fn:_e,_cs:g};return Pe}
2 |
--------------------------------------------------------------------------------