svelte-aos 0.0.3 → 0.1.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.
@@ -1,143 +0,0 @@
1
- import { detectDeviceType } from "../utils.js";
2
- const defaultOptions = {
3
- delay: 0,
4
- easing: 'ease',
5
- duration: 600,
6
- disable: 'mobile',
7
- once: false,
8
- anchorPlacement: 'top-bottom',
9
- offset: 120,
10
- threshold: 0.1
11
- // TODO: implement these later
12
- // animatedClassName: 'aos-animate',
13
- // initClassName?: 'aos-init',
14
- // useClassNames: false,
15
- // disableMutationObserver: false
16
- };
17
- function isValidDistance(value) {
18
- const el = document.createElement('div');
19
- el.style.width = '';
20
- el.style.width = value;
21
- return el.style.width !== '';
22
- }
23
- class IntersectionObserverManager {
24
- observer;
25
- options;
26
- elements = new Map();
27
- constructor(options) {
28
- this.options = options;
29
- this.observer = new IntersectionObserver(this.handleIntersect.bind(this), {
30
- threshold: options.threshold,
31
- rootMargin: `0px 0px -${options.offset}px 0px`
32
- });
33
- console.log('disabled options:', options);
34
- // handle disable option
35
- if (typeof options?.disable === 'boolean' && options.disable) {
36
- document.body.classList.add('aos-disabled');
37
- }
38
- else if (typeof options?.disable === 'string') {
39
- const deviceType = detectDeviceType();
40
- if (options.disable === deviceType) {
41
- document.body.classList.add('aos-disabled');
42
- }
43
- }
44
- else if (typeof options?.disable === 'function') {
45
- if (options.disable()) {
46
- document.body.classList.add('aos-disabled');
47
- }
48
- }
49
- }
50
- handleIntersect(entries) {
51
- console.log('Handling intersections with options:', this.options);
52
- entries.forEach((entry) => {
53
- if (entry.isIntersecting && entry.intersectionRatio > 0.05) {
54
- if (this.elements.has(entry.target)) {
55
- entry.target.classList.add('aos-animate');
56
- const elementOptions = this.elements.get(entry.target);
57
- if (elementOptions?.once) {
58
- // if only once why keep observing
59
- this.observer.unobserve(entry.target);
60
- }
61
- }
62
- else {
63
- // this should never happen if it does don't observe the element
64
- console.warn('No options found for element:', entry.target);
65
- this.observer.unobserve(entry.target);
66
- }
67
- }
68
- else {
69
- const once = entry.target.hasAttribute('data-aos-once') || this.options.once;
70
- if (!once) {
71
- entry.target.classList.remove('aos-animate');
72
- }
73
- }
74
- });
75
- }
76
- observe(element, options) {
77
- console.log('Before Observing element with options:', element, options);
78
- this.elements.set(element, this.options);
79
- if (options.animation) {
80
- element.setAttribute('data-aos', options.animation);
81
- }
82
- if (options.duration) {
83
- element.style.setProperty('--aos-duration', `${options.duration}ms`);
84
- }
85
- if (options.delay) {
86
- element.style.setProperty('--aos-delay', `${options.delay}ms`);
87
- }
88
- if (options.easing) {
89
- element.style.setProperty('--aos-easing', options.easing);
90
- }
91
- if (options.distance && isValidDistance(options.distance)) {
92
- element.style.setProperty('--aos-distance', options.distance);
93
- }
94
- this.observer.observe(element);
95
- }
96
- unobserve(element) {
97
- this.observer.unobserve(element);
98
- this.elements.delete(element);
99
- }
100
- }
101
- let observerManager = null;
102
- export function initAOS(options = {}) {
103
- console.log('Initializing AOS with options:', options);
104
- if (typeof window === 'undefined') {
105
- console.warn('AOS can only be initialized in a browser environment.');
106
- return;
107
- }
108
- const requiredOptions = { ...defaultOptions, ...options };
109
- if (!observerManager) {
110
- observerManager = new IntersectionObserverManager(requiredOptions);
111
- }
112
- else {
113
- console.warn('AOS already initialzed, ');
114
- }
115
- }
116
- function observe(node, options) {
117
- if (observerManager) {
118
- observerManager.observe(node, options);
119
- }
120
- else {
121
- console.warn('AOS not initialized. Please call initialize it first.');
122
- }
123
- return () => observerManager?.unobserve(node);
124
- }
125
- export function aos(options = {
126
- animation: 'fade'
127
- }) {
128
- return (node) => {
129
- const unobserve = observe(node, options);
130
- return unobserve;
131
- };
132
- }
133
- export function aosAction(node, options = {
134
- animation: 'fade'
135
- }) {
136
- const unobserve = observe(node, options);
137
- return {
138
- update: () => { },
139
- destroy() {
140
- unobserve();
141
- }
142
- };
143
- }
@@ -1,2 +0,0 @@
1
- export { default as AOS } from './AOS.svelte';
2
- export { aos, aosAction } from './aos.ts';
@@ -1,2 +0,0 @@
1
- export { default as AOS } from './AOS.svelte';
2
- export { aos, aosAction } from "./aos.js";