tiny-essentials 1.17.0 โ†’ 1.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -747,6 +747,102 @@ Normalizes and converts input (elements, arrays, or strings) into appendable DOM
747
747
 
748
748
  ---
749
749
 
750
+ ## ๐Ÿงฎ Easing Functions
751
+
752
+ ### `TinyHtml.easings`
753
+
754
+ A collection of predefined easing functions used for scroll and animation calculations.
755
+ Each easing function takes a normalized time (`t` from 0 to 1) and returns a transformed progress value.
756
+
757
+ | Name | Description |
758
+ | ---------------- | ------------------------------------- |
759
+ | `linear` | Constant speed, no easing. |
760
+ | `easeInQuad` | Accelerates from zero velocity. |
761
+ | `easeOutQuad` | Decelerates to zero velocity. |
762
+ | `easeInOutQuad` | Accelerates, then decelerates. |
763
+ | `easeInCubic` | Starts slow, speeds up sharply. |
764
+ | `easeOutCubic` | Starts fast, slows down gradually. |
765
+ | `easeInOutCubic` | Smooth acceleration and deceleration. |
766
+
767
+ ```ts
768
+ type Easings =
769
+ | 'linear'
770
+ | 'easeInQuad'
771
+ | 'easeOutQuad'
772
+ | 'easeInOutQuad'
773
+ | 'easeInCubic'
774
+ | 'easeOutCubic'
775
+ | 'easeInOutCubic';
776
+ ```
777
+
778
+ ```ts
779
+ TinyHtml.easings = {
780
+ linear: (t) => t,
781
+ easeInQuad: (t) => t * t,
782
+ easeOutQuad: (t) => t * (2 - t),
783
+ easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
784
+ easeInCubic: (t) => t * t * t,
785
+ easeOutCubic: (t) => --t * t * t + 1,
786
+ easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
787
+ };
788
+ ```
789
+
790
+ ---
791
+
792
+ ## ๐Ÿงญ Smooth Scrolling
793
+
794
+ ### `TinyHtml.scrollToXY(el, settings)`
795
+
796
+ Smoothly scrolls one or more elements (or `window`) to a target position using a custom duration and easing.
797
+
798
+ If no `duration` or invalid `easing` is provided, the scroll happens instantly.
799
+
800
+ ```ts
801
+ TinyHtml.scrollToXY(el, {
802
+ targetX?: number,
803
+ targetY?: number,
804
+ duration?: number,
805
+ easing?: Easings,
806
+ });
807
+ ```
808
+
809
+ | Parameter | Type | Description |
810
+ | -------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
811
+ | `el` | `TinyElementAndWindow \| TinyElementAndWindow[]` | One or more elements or the `window` to scroll. |
812
+ | `settings` | `Object` | Scroll configuration. |
813
+ | `targetX` | `number` *(optional)* | Final horizontal scroll position. |
814
+ | `targetY` | `number` *(optional)* | Final vertical scroll position. |
815
+ | `duration` | `number` *(optional)* | Duration of the scroll animation in milliseconds. |
816
+ | `easing` | `Easings` *(optional)* | Name of easing function to control animation curve. |
817
+ | `onAnimation` | `OnScrollAnimation` *(optional)* | Optional callback invoked on each animation frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag. |
818
+
819
+ ---
820
+
821
+ ## โš™๏ธ Internal Scroll Mechanism
822
+
823
+ When called, `scrollToXY()` performs:
824
+
825
+ 1. **Start Position Detection** โ€“ Gets current scroll positions.
826
+ 2. **Delta Calculation** โ€“ Calculates the distance to scroll.
827
+ 3. **Easing Evaluation** โ€“ Determines the easing curve to use.
828
+ 4. **Scroll Loop** โ€“ Uses `requestAnimationFrame` to animate over time.
829
+ 5. **Instant Scroll Fallback** โ€“ If no easing/duration is defined, scrolls instantly.
830
+
831
+ ```ts
832
+ function executeScroll(elem, newX, newY) {
833
+ if (elem instanceof Window) {
834
+ window.scrollTo(newX, newY);
835
+ } else if (elem.nodeType === 9) {
836
+ elem.defaultView.scrollTo(newX, newY); // For documents
837
+ } else {
838
+ if (elem.scrollLeft !== newX) elem.scrollLeft = newX;
839
+ if (elem.scrollTop !== newY) elem.scrollTop = newY;
840
+ }
841
+ }
842
+ ```
843
+
844
+ ---
845
+
750
846
  ## ๐Ÿ“ Dimensions (Size API)
751
847
 
752
848
  TinyHtml provides methods to **read** and **set** an element's dimensions, similar to jQueryโ€™s width/height API, with support for box models: `content`, `padding`, `border`, and `margin`.
@@ -823,6 +919,9 @@ This API set focuses on **measuring element offsets**, **scroll positions**, and
823
919
 
824
920
  ### ๐Ÿ“ Element Positioning
825
921
 
922
+ #### `.animate(keyframes, ops?)` / `TinyHtml.animate(el, keyframes, ops?)`
923
+ Applies an animation to one or more TinyElement instances using the Web Animations API.
924
+
826
925
  #### `.offset()` / `TinyHtml.offset(el)`
827
926
  Returns the coordinates `{ top, left }` of the element **relative to the document**.
828
927
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",