@reimujs/aos 0.0.1 → 0.1.0

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.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # aos.js
2
2
 
3
+ ![NPM License](https://img.shields.io/npm/l/%40reimujs%2Faos) ![NPM Version](https://img.shields.io/npm/v/%40reimujs%2Faos) ![npm bundle size](https://img.shields.io/bundlephobia/min/%40reimujs%2Faos)
4
+
3
5
  Animate on scroll library.
4
6
 
5
7
  Rewrite [aos](https://github.com/michalsnik/aos) using typescript.
@@ -26,6 +28,7 @@ Just same as aos@next. For more information, please visit [aos-how-to-use-it](ht
26
28
 
27
29
  ```typescript
28
30
  import AOS from "@reimujs/aos";
31
+ import "@reimujs/aos/dist/aos.css";
29
32
 
30
33
  AOS.init({
31
34
  // Global settings:
@@ -52,13 +55,76 @@ AOS.init({
52
55
  });
53
56
  ```
54
57
 
58
+ ### Next.js
59
+
60
+ ```typescript
61
+ "use client";
62
+ import { useEffect } from "react";
63
+ import "@reimujs/aos/dist/aos.css";
64
+
65
+ export default function Page() {
66
+ useEffect(() => {
67
+ import("@reimujs/aos").then(({ default: AOS }) => {
68
+ AOS.init();
69
+ });
70
+ }, []);
71
+ }
72
+ ```
73
+
74
+ ### Nuxt
75
+
76
+ ```html
77
+ <script lang="ts" setup>
78
+ import { onMounted } from "vue";
79
+ import "@reimujs/aos/dist/aos.css";
80
+
81
+ onMounted(() => {
82
+ import("@reimujs/aos").then(({ default: AOS }) => {
83
+ AOS.init();
84
+ });
85
+ });
86
+ </script>
87
+ ```
88
+
89
+ ### Augular
90
+
91
+ ```typescript
92
+ import { Component, Inject, PLATFORM_ID } from '@angular/core';
93
+ import { isPlatformBrowser } from '@angular/common';
94
+ import '@reimujs/aos/dist/aos.css';
95
+
96
+ @Component({})
97
+ export class AppComponent {
98
+ constructor(
99
+ @Inject(PLATFORM_ID) private platformId: Object
100
+ ) {
101
+ if (isPlatformBrowser(this.platformId)) {
102
+ import("@reimujs/aos").then(({ default: AOS }) => {
103
+ AOS.init();
104
+ });
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ ### Astro
111
+
112
+ ```html
113
+ ---
114
+ import "@reimujs/aos/dist/aos.css";
115
+ ---
116
+ <script>
117
+ import AOS from "@reimujs/aos";
118
+ AOS.init();
119
+ </script>
120
+ ```
121
+
55
122
  ## Difference
56
123
 
57
124
  So what's the difference between aos and @reimujs/aos?
58
125
 
59
-
60
126
  - Typescript friendly
61
- - Smaller package size (from 14.7KB + 26.1KB to 6.74KB + 24.5KB)
127
+ - Smaller package size (from 14.7KB + 26.1KB to 6.9KB + 25.2KB)
62
128
  - Only support modern browsers
63
129
  - Support additional settings
64
130
  - Support additional API
@@ -83,6 +149,6 @@ function destroy(): void;
83
149
 
84
150
  Remove all event listeners and disconnect MutationObserver.
85
151
 
86
-
87
152
  ## License
88
- MIT
153
+
154
+ MIT
package/dist/aos.cjs.js CHANGED
@@ -1,6 +1,87 @@
1
1
  'use strict';
2
2
 
3
- var esToolkit = require('es-toolkit');
3
+ function debounce(func, debounceMs, { signal, edges } = {}) {
4
+ let pendingThis = undefined;
5
+ let pendingArgs = null;
6
+ const leading = edges != null && edges.includes('leading');
7
+ const trailing = edges == null || edges.includes('trailing');
8
+ const invoke = () => {
9
+ if (pendingArgs !== null) {
10
+ func.apply(pendingThis, pendingArgs);
11
+ pendingThis = undefined;
12
+ pendingArgs = null;
13
+ }
14
+ };
15
+ const onTimerEnd = () => {
16
+ if (trailing) {
17
+ invoke();
18
+ }
19
+ cancel();
20
+ };
21
+ let timeoutId = null;
22
+ const schedule = () => {
23
+ if (timeoutId != null) {
24
+ clearTimeout(timeoutId);
25
+ }
26
+ timeoutId = setTimeout(() => {
27
+ timeoutId = null;
28
+ onTimerEnd();
29
+ }, debounceMs);
30
+ };
31
+ const cancelTimer = () => {
32
+ if (timeoutId !== null) {
33
+ clearTimeout(timeoutId);
34
+ timeoutId = null;
35
+ }
36
+ };
37
+ const cancel = () => {
38
+ cancelTimer();
39
+ pendingThis = undefined;
40
+ pendingArgs = null;
41
+ };
42
+ const flush = () => {
43
+ cancelTimer();
44
+ invoke();
45
+ };
46
+ const debounced = function (...args) {
47
+ if (signal?.aborted) {
48
+ return;
49
+ }
50
+ pendingThis = this;
51
+ pendingArgs = args;
52
+ const isFirstCall = timeoutId == null;
53
+ schedule();
54
+ if (leading && isFirstCall) {
55
+ invoke();
56
+ }
57
+ };
58
+ debounced.schedule = schedule;
59
+ debounced.cancel = cancel;
60
+ debounced.flush = flush;
61
+ signal?.addEventListener('abort', cancel, { once: true });
62
+ return debounced;
63
+ }
64
+
65
+ function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
66
+ let pendingAt = null;
67
+ const debounced = debounce(func, throttleMs, { signal, edges });
68
+ const throttled = function (...args) {
69
+ if (pendingAt == null) {
70
+ pendingAt = Date.now();
71
+ }
72
+ else {
73
+ if (Date.now() - pendingAt >= throttleMs) {
74
+ pendingAt = Date.now();
75
+ debounced.cancel();
76
+ debounced(...args);
77
+ }
78
+ }
79
+ debounced(...args);
80
+ };
81
+ throttled.cancel = debounced.cancel;
82
+ throttled.flush = debounced.flush;
83
+ return throttled;
84
+ }
4
85
 
5
86
  const phoneRe = /iphone|ipod|android.*mobile|windows phone|blackberry|opera mini|mobile|phone/i;
6
87
  const tabletRe = /ipad|android(?!.*mobile)|tablet|kindle/i;
@@ -245,7 +326,7 @@ class Aos {
245
326
  const { container } = this;
246
327
  this.elements = prepare(this.elements, this.options, container);
247
328
  handleScroll(this.elements, this.container);
248
- this.scrollHandler = esToolkit.throttle(() => {
329
+ this.scrollHandler = throttle(() => {
249
330
  handleScroll(this.elements, container);
250
331
  }, this.options.throttleDelay);
251
332
  container.addEventListener("scroll", this.scrollHandler, {
@@ -286,7 +367,7 @@ class Aos {
286
367
  ["complete", "interactive"].indexOf(document.readyState) > -1) {
287
368
  this.refresh(true);
288
369
  }
289
- this.resizeHandler = esToolkit.debounce(this.refresh.bind(this), this.options.debounceDelay);
370
+ this.resizeHandler = debounce(this.refresh.bind(this), this.options.debounceDelay);
290
371
  window.addEventListener("resize", this.resizeHandler);
291
372
  window.addEventListener("orientationchange", this.resizeHandler);
292
373
  }
package/dist/aos.esm.js CHANGED
@@ -1,4 +1,85 @@
1
- import { throttle, debounce } from 'es-toolkit';
1
+ function debounce(func, debounceMs, { signal, edges } = {}) {
2
+ let pendingThis = undefined;
3
+ let pendingArgs = null;
4
+ const leading = edges != null && edges.includes('leading');
5
+ const trailing = edges == null || edges.includes('trailing');
6
+ const invoke = () => {
7
+ if (pendingArgs !== null) {
8
+ func.apply(pendingThis, pendingArgs);
9
+ pendingThis = undefined;
10
+ pendingArgs = null;
11
+ }
12
+ };
13
+ const onTimerEnd = () => {
14
+ if (trailing) {
15
+ invoke();
16
+ }
17
+ cancel();
18
+ };
19
+ let timeoutId = null;
20
+ const schedule = () => {
21
+ if (timeoutId != null) {
22
+ clearTimeout(timeoutId);
23
+ }
24
+ timeoutId = setTimeout(() => {
25
+ timeoutId = null;
26
+ onTimerEnd();
27
+ }, debounceMs);
28
+ };
29
+ const cancelTimer = () => {
30
+ if (timeoutId !== null) {
31
+ clearTimeout(timeoutId);
32
+ timeoutId = null;
33
+ }
34
+ };
35
+ const cancel = () => {
36
+ cancelTimer();
37
+ pendingThis = undefined;
38
+ pendingArgs = null;
39
+ };
40
+ const flush = () => {
41
+ cancelTimer();
42
+ invoke();
43
+ };
44
+ const debounced = function (...args) {
45
+ if (signal?.aborted) {
46
+ return;
47
+ }
48
+ pendingThis = this;
49
+ pendingArgs = args;
50
+ const isFirstCall = timeoutId == null;
51
+ schedule();
52
+ if (leading && isFirstCall) {
53
+ invoke();
54
+ }
55
+ };
56
+ debounced.schedule = schedule;
57
+ debounced.cancel = cancel;
58
+ debounced.flush = flush;
59
+ signal?.addEventListener('abort', cancel, { once: true });
60
+ return debounced;
61
+ }
62
+
63
+ function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
64
+ let pendingAt = null;
65
+ const debounced = debounce(func, throttleMs, { signal, edges });
66
+ const throttled = function (...args) {
67
+ if (pendingAt == null) {
68
+ pendingAt = Date.now();
69
+ }
70
+ else {
71
+ if (Date.now() - pendingAt >= throttleMs) {
72
+ pendingAt = Date.now();
73
+ debounced.cancel();
74
+ debounced(...args);
75
+ }
76
+ }
77
+ debounced(...args);
78
+ };
79
+ throttled.cancel = debounced.cancel;
80
+ throttled.flush = debounced.flush;
81
+ return throttled;
82
+ }
2
83
 
3
84
  const phoneRe = /iphone|ipod|android.*mobile|windows phone|blackberry|opera mini|mobile|phone/i;
4
85
  const tabletRe = /ipad|android(?!.*mobile)|tablet|kindle/i;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,23 @@
1
+ type AosEventType = "aos:in" | "aos:out";
2
+ interface AosEvent extends Event {
3
+ detail: Element;
4
+ }
5
+ declare global {
6
+ interface Document {
7
+ addEventListener(type: AosEventType, listener: (event: AosEvent) => void, options?: boolean | AddEventListenerOptions): void;
8
+ }
9
+ }
10
+ type easingOptions = "linear" | "ease" | "ease-in" | "ease-out" | "ease-in-out" | "ease-in-back" | "ease-out-back" | "ease-in-out-back" | "ease-in-sine" | "ease-out-sine" | "ease-in-out-sine" | "ease-in-quad" | "ease-out-quad" | "ease-in-out-quad" | "ease-in-cubic" | "ease-out-cubic" | "ease-in-out-cubic" | "ease-in-quart" | "ease-out-quart" | "ease-in-out-quart";
11
+ type anchorPlacementOptions = "top-bottom" | "top-center" | "top-top" | "center-bottom" | "center-center" | "center-top" | "bottom-bottom" | "bottom-center" | "bottom-top";
1
12
  export interface Options {
2
13
  offset: number;
3
14
  delay: number;
4
- easing: string;
15
+ easing: easingOptions;
5
16
  duration: number;
6
17
  disable: boolean | "mobile" | "phone" | "tablet" | (() => boolean);
7
18
  once: boolean;
8
19
  mirror: boolean;
9
- anchorPlacement: string;
20
+ anchorPlacement: anchorPlacementOptions;
10
21
  startEvent: string;
11
22
  animatedClassName: string;
12
23
  initClassName: string;
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@reimujs/aos",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "main": "dist/aos.cjs.js",
5
5
  "module": "dist/aos.esm.js",
6
6
  "browser": "dist/aos.umd.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
9
- "build": "rollup -c",
10
- "build:umd": "rollup -c umd.config.mjs"
9
+ "build": "rollup -c"
11
10
  },
12
11
  "author": "D-Sketon",
13
12
  "license": "MIT",
@@ -20,9 +19,7 @@
20
19
  "rollup-plugin-scss": "^3.0.0",
21
20
  "sass": "^1.79.4",
22
21
  "tslib": "^2.7.0",
23
- "typescript": "^5.6.2"
24
- },
25
- "dependencies": {
22
+ "typescript": "^5.6.2",
26
23
  "es-toolkit": "^1.23.0"
27
24
  },
28
25
  "repository": {