@castlenine/svelte-aoe 2.0.0 → 2.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
@@ -143,9 +143,45 @@ You can add your own animations by following the same pattern in your CSS.
143
143
 
144
144
  `threshold` is either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed. A value of `0.0` or `0` indicates that even a single pixel of the target is visible. A value of `1.0` or `1` indicates that the target is completely visible. Defaults to `0.3` (30%).
145
145
 
146
+ ## Scoped Overrides
147
+
148
+ Set defaults for all `data-aoe` elements within a page or section using `data-aoe-scope` on a container element, or the `<AnimateOnEnterScope>` convenience component. Elements inside a scope inherit its values unless they have their own per-element `data-aoe-*` overrides.
149
+
150
+ ### Using `data-aoe-scope` attribute
151
+
152
+ ```svelte
153
+ <div data-aoe-scope data-aoe-threshold="0.5" data-aoe-root-margin="20px">
154
+ <!-- All elements inside use threshold=0.5 and rootMargin=20px -->
155
+ <img data-aoe="fade-up" src="..." />
156
+
157
+ <!-- Per-element override still takes priority -->
158
+ <img data-aoe="fade-up" data-aoe-threshold="0.8" src="..." />
159
+ </div>
160
+ ```
161
+
162
+ ### Using `<AnimateOnEnterScope>` component
163
+
164
+ ```svelte
165
+ <script>
166
+ import { AnimateOnEnterScope } from '@castlenine/svelte-aoe';
167
+ </script>
168
+
169
+ <AnimateOnEnterScope threshold={0.5} rootMargin="20px">
170
+ <img data-aoe="fade-up" src="..." />
171
+ </AnimateOnEnterScope>
172
+ ```
173
+
174
+ | Property name | Type | Default value |
175
+ | ------------- | -------------------------------------------- | ------------- |
176
+ | `root` | CSS selector `string` | `undefined` |
177
+ | `rootMargin` | `string` in pixel (`px`) or percentage (`%`) | `undefined` |
178
+ | `threshold` | `number` between `0` and `1.0` | `undefined` |
179
+
180
+ Scopes can be nested. The innermost scope wins.
181
+
146
182
  ## Per-Element Overrides
147
183
 
148
- Individual elements can override the global properties using `data-aoe-*` attributes. If an attribute is not set, the value from `<AnimateOnEnter />` is used, which itself falls back to the package default.
184
+ Individual elements can override scope or global properties using `data-aoe-*` attributes. If an attribute is not set, the value from the nearest `data-aoe-scope` ancestor is used, then `<AnimateOnEnter />`, then the package default.
149
185
 
150
186
  | Attribute | Type | Overrides |
151
187
  | -------------------- | ---------------------------------------------- | ------------ |
@@ -0,0 +1,27 @@
1
+ <!--
2
+ @component
3
+ ### AnimateOnEnterScope
4
+ Convenience wrapper that sets `data-aoe-scope` defaults for all `data-aoe` descendants.
5
+ Elements inside the scope inherit these values unless they have their own `data-aoe-*` overrides.
6
+
7
+ &nbsp;
8
+
9
+ @param {string | undefined} `root` - CSS selector for the root element used as the viewport.
10
+ @param {string | undefined} `rootMargin` - Margin around the root (px or %).
11
+ @param {number | undefined} `threshold` - Visibility percentage (0 to 1) to trigger animations.
12
+ -->
13
+
14
+ <script>export let root = void 0;
15
+ export let rootMargin = void 0;
16
+ export let threshold = void 0;
17
+ </script>
18
+
19
+ <div
20
+ {...$$restProps}
21
+ data-aoe-scope
22
+ data-aoe-root={root}
23
+ data-aoe-root-margin={rootMargin}
24
+ data-aoe-threshold={threshold != null ? String(threshold) : undefined}
25
+ >
26
+ <slot />
27
+ </div>
@@ -0,0 +1,33 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ root?: string | undefined;
6
+ rootMargin?: string | undefined;
7
+ threshold?: number | undefined;
8
+ };
9
+ events: {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {
13
+ default: {};
14
+ };
15
+ };
16
+ export type AnimateOnEnterScopeProps = typeof __propDef.props;
17
+ export type AnimateOnEnterScopeEvents = typeof __propDef.events;
18
+ export type AnimateOnEnterScopeSlots = typeof __propDef.slots;
19
+ /**
20
+ * ### AnimateOnEnterScope
21
+ * Convenience wrapper that sets `data-aoe-scope` defaults for all `data-aoe` descendants.
22
+ * Elements inside the scope inherit these values unless they have their own `data-aoe-*` overrides.
23
+ *
24
+ * &nbsp;
25
+ *
26
+ * @param {string | undefined} `root` - CSS selector for the root element used as the viewport.
27
+ * @param {string | undefined} `rootMargin` - Margin around the root (px or %).
28
+ * @param {number | undefined} `threshold` - Visibility percentage (0 to 1) to trigger animations.
29
+ */
30
+ export default class AnimateOnEnterScope extends SvelteComponentTyped<AnimateOnEnterScopeProps, AnimateOnEnterScopeEvents, AnimateOnEnterScopeSlots> {
31
+ }
32
+ export {};
33
+ //# sourceMappingURL=AnimateOnEnterScope.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimateOnEnterScope.svelte.d.ts","sourceRoot":"","sources":["../src/lib/AnimateOnEnterScope.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AAeD,QAAA,MAAM,SAAS;;;eADyE,MAAM,GAAG,SAAS;qBAAe,MAAM,GAAG,SAAS;oBAAc,MAAM,GAAG,SAAS;;;;;;;;CAC3F,CAAC;AACjF,MAAM,MAAM,wBAAwB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC9D,MAAM,MAAM,yBAAyB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAChE,MAAM,MAAM,wBAAwB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,oBAAoB,CAAC,wBAAwB,EAAE,yBAAyB,EAAE,wBAAwB,CAAC;CACnJ"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import AnimateOnEnter from './index.svelte';
2
2
  export default AnimateOnEnter;
3
+ export { default as AnimateOnEnterScope } from './AnimateOnEnterScope.svelte';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,gBAAgB,CAAC;AAE5C,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,gBAAgB,CAAC;AAE5C,eAAe,cAAc,CAAC;AAC9B,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import AnimateOnEnter from './index.svelte';
2
2
  export default AnimateOnEnter;
3
+ export { default as AnimateOnEnterScope } from './AnimateOnEnterScope.svelte';
package/dist/index.svelte CHANGED
@@ -8,7 +8,8 @@ Place this component once in your root layout. Elements with `data-aoe` attribut
8
8
  #### Configuration cascade
9
9
  1. Package defaults: `root: null`, `rootMargin: '0px'`, `threshold: 0.3`
10
10
  2. Component props: override package defaults globally
11
- 3. Per-element `data-aoe-*` attributes: override component props for individual elements
11
+ 3. `data-aoe-scope` on a container: override component props for a page or section
12
+ 4. Per-element `data-aoe-*` attributes: override scope or component props for individual elements
12
13
 
13
14
  &nbsp;
14
15
 
@@ -58,26 +59,34 @@ onMount(() => {
58
59
  }
59
60
  return observer;
60
61
  }
62
+ function resolveConfig(el) {
63
+ var _a, _b;
64
+ const ROOT_ATTR = el.getAttribute("data-aoe-root");
65
+ const ROOT_MARGIN_ATTR = el.getAttribute("data-aoe-root-margin");
66
+ const THRESHOLD_ATTR = el.getAttribute("data-aoe-threshold");
67
+ const SCOPE = el.closest("[data-aoe-scope]");
68
+ const ROOT_SELECTOR = (_a = ROOT_ATTR !== null && ROOT_ATTR !== void 0 ? ROOT_ATTR : SCOPE === null || SCOPE === void 0 ? void 0 : SCOPE.getAttribute("data-aoe-root")) !== null && _a !== void 0 ? _a : null;
69
+ const ROOT_MARGIN = (_b = ROOT_MARGIN_ATTR !== null && ROOT_MARGIN_ATTR !== void 0 ? ROOT_MARGIN_ATTR : SCOPE === null || SCOPE === void 0 ? void 0 : SCOPE.getAttribute("data-aoe-root-margin")) !== null && _b !== void 0 ? _b : DEFAULT_ROOT_MARGIN;
70
+ const RAW_THRESHOLD = THRESHOLD_ATTR !== null && THRESHOLD_ATTR !== void 0 ? THRESHOLD_ATTR : SCOPE === null || SCOPE === void 0 ? void 0 : SCOPE.getAttribute("data-aoe-threshold");
71
+ const PARSED = RAW_THRESHOLD != null ? parseFloat(RAW_THRESHOLD) : NaN;
72
+ const THRESHOLD = !isNaN(PARSED) ? PARSED : DEFAULT_THRESHOLD;
73
+ return { rootSelector: ROOT_SELECTOR, rootMargin: ROOT_MARGIN, threshold: THRESHOLD };
74
+ }
61
75
  function registerElement(el) {
62
76
  if (REGISTERED.has(el) || el.classList.contains("aoe"))
63
77
  return;
64
78
  REGISTERED.add(el);
65
- const ROOT_ATTR = el.getAttribute("data-aoe-root");
66
- const ROOT_MARGIN_ATTR = el.getAttribute("data-aoe-root-margin");
67
- const THRESHOLD_ATTR = el.getAttribute("data-aoe-threshold");
68
- if (!ROOT_ATTR && !ROOT_MARGIN_ATTR && !THRESHOLD_ATTR) {
79
+ const { rootSelector: ROOT_SELECTOR, rootMargin: ROOT_MARGIN, threshold: THRESHOLD } = resolveConfig(el);
80
+ if (!ROOT_SELECTOR && ROOT_MARGIN === DEFAULT_ROOT_MARGIN && THRESHOLD === DEFAULT_THRESHOLD) {
69
81
  DEFAULT_OBSERVER.observe(el);
70
82
  return;
71
83
  }
72
- const EL_ROOT = ROOT_ATTR ? document.querySelector(ROOT_ATTR) : DEFAULT_ROOT;
73
- const EL_ROOT_MARGIN = ROOT_MARGIN_ATTR !== null && ROOT_MARGIN_ATTR !== void 0 ? ROOT_MARGIN_ATTR : DEFAULT_ROOT_MARGIN;
74
- const PARSED_THRESHOLD = THRESHOLD_ATTR != null ? parseFloat(THRESHOLD_ATTR) : null;
75
- const EL_THRESHOLD = PARSED_THRESHOLD != null && !isNaN(PARSED_THRESHOLD) ? PARSED_THRESHOLD : DEFAULT_THRESHOLD;
76
- const KEY = configKey(ROOT_ATTR, EL_ROOT_MARGIN, EL_THRESHOLD);
84
+ const EL_ROOT = ROOT_SELECTOR ? document.querySelector(ROOT_SELECTOR) : DEFAULT_ROOT;
85
+ const KEY = configKey(ROOT_SELECTOR, ROOT_MARGIN, THRESHOLD);
77
86
  const OBSERVER = getOrCreateObserver(KEY, {
78
87
  root: EL_ROOT,
79
- rootMargin: EL_ROOT_MARGIN,
80
- threshold: EL_THRESHOLD
88
+ rootMargin: ROOT_MARGIN,
89
+ threshold: THRESHOLD
81
90
  });
82
91
  OBSERVER.observe(el);
83
92
  }
@@ -23,7 +23,8 @@ export type IndexSlots = typeof __propDef.slots;
23
23
  * #### Configuration cascade
24
24
  * 1. Package defaults: `root: null`, `rootMargin: '0px'`, `threshold: 0.3`
25
25
  * 2. Component props: override package defaults globally
26
- * 3. Per-element `data-aoe-*` attributes: override component props for individual elements
26
+ * 3. `data-aoe-scope` on a container: override component props for a page or section
27
+ * 4. Per-element `data-aoe-*` attributes: override scope or component props for individual elements
27
28
  *
28
29
  * &nbsp;
29
30
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.svelte.d.ts","sourceRoot":"","sources":["../src/lib/index.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AACD,OAAO,kBAAkB,CAAC;AA8G1B,QAAA,MAAM,SAAS;;eADyE,QAAQ,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS;qBAAe,MAAM,GAAG,SAAS;oBAAc,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;;;;;;CAChJ,CAAC;AAC1D,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAChD,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAEhD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,oBAAoB,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC;CAC3F"}
1
+ {"version":3,"file":"index.svelte.d.ts","sourceRoot":"","sources":["../src/lib/index.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AACD,OAAO,kBAAkB,CAAC;AA6H1B,QAAA,MAAM,SAAS;;eADyE,QAAQ,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS;qBAAe,MAAM,GAAG,SAAS;oBAAc,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;;;;;;CAChJ,CAAC;AAC1D,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAChD,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAEhD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,oBAAoB,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC;CAC3F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@castlenine/svelte-aoe",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "A Svelte component to animate elements, with no dependencies.",
5
5
  "license": "MIT",
6
6
  "keywords": [