@onsvisual/svelte-components 0.1.4 → 0.1.5

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.
@@ -45,11 +45,13 @@
45
45
  },
46
46
 
47
47
  remove: ({ outer, update }) => {
48
- const index = handlers.indexOf(update);
49
- if (index !== -1) handlers.splice(index, 1);
48
+ if (map.get(outer)) {
49
+ const index = handlers.indexOf(update);
50
+ if (index !== -1) handlers.splice(index, 1);
50
51
 
51
- map.delete(outer);
52
- observer.unobserve(outer);
52
+ map.delete(outer);
53
+ observer.unobserve(outer);
54
+ }
53
55
  },
54
56
  };
55
57
  } else {
@@ -67,7 +69,9 @@
67
69
  </script>
68
70
 
69
71
  <script>
70
- import { onMount, createEventDispatcher } from "svelte";
72
+ import { onMount, setContext, createEventDispatcher } from "svelte";
73
+ import { writable } from "svelte/store";
74
+
71
75
  const dispatch = createEventDispatcher();
72
76
 
73
77
  // config
@@ -94,7 +98,6 @@
94
98
 
95
99
  let top = 0;
96
100
  let bottom = 1;
97
- let query = "section";
98
101
  let parallax = false;
99
102
 
100
103
  // bindings
@@ -129,11 +132,14 @@
129
132
  */
130
133
  export let visible = false;
131
134
 
135
+ const sections = writable([]);
136
+ setContext("sections", sections);
137
+
138
+ let scroller;
132
139
  let outer;
133
140
  let foreground;
134
141
  let background;
135
142
  let left;
136
- let sections;
137
143
  let wh = 0;
138
144
  let fixed;
139
145
  let offset_top = 0;
@@ -156,17 +162,20 @@
156
162
 
157
163
  $: widthStyle = fixed ? `width:${width}px;` : "";
158
164
 
159
- onMount(() => {
160
- sections = foreground.querySelectorAll(query);
165
+ function initSections(sections) {
166
+ console.log("updating scroller", sections.length);
167
+ if (scroller) manager.remove(scroller);
168
+
161
169
  count = sections.length;
162
170
 
163
171
  update();
164
172
 
165
- const scroller = { outer, update };
173
+ scroller = { outer, update };
166
174
 
167
175
  manager.add(scroller);
168
176
  return () => manager.remove(scroller);
169
- });
177
+ }
178
+ $: outer && initSections($sections);
170
179
 
171
180
  function update() {
172
181
  if (!foreground) return;
@@ -203,11 +212,11 @@
203
212
  fixed = true;
204
213
  }
205
214
 
206
- for (let i = 0; i < sections.length; i++) {
207
- const section = sections[i];
215
+ for (let i = 0; i < $sections.length; i++) {
216
+ const section = $sections[i];
208
217
  const { top } = section.getBoundingClientRect();
209
218
 
210
- const next = sections[i + 1];
219
+ const next = $sections[i + 1];
211
220
  const bottom = next ? next.getBoundingClientRect().top : fg.bottom;
212
221
 
213
222
  offset = (threshold_px - top) / (bottom - top);
@@ -1,5 +1,5 @@
1
1
  <script>
2
- // import { onMount } from "svelte";
2
+ import { onMount, onDestroy, getContext } from "svelte";
3
3
  import Container from "../../wrappers/Container/Container.svelte";
4
4
 
5
5
  /**
@@ -24,12 +24,20 @@
24
24
  export let hideTitle = false;
25
25
 
26
26
  let section;
27
- // let background;
28
27
 
29
- // onMount(() => {
30
- // background = getComputedStyle(section).getPropertyValue("--background").replaceAll('"', "");
31
- // console.log(section, getComputedStyle(section), background);
32
- // });
28
+ const sections = getContext("sections");
29
+
30
+ onMount(() => {
31
+ if (sections) {
32
+ $sections = [...$sections, section];
33
+ }
34
+ });
35
+
36
+ onDestroy(() => {
37
+ if (sections) {
38
+ $sections = $sections.filter((s) => s !== section);
39
+ }
40
+ });
33
41
  </script>
34
42
 
35
43
  <section data-id="{id}" bind:this="{section}">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",