@marcwiest/midday.js 0.2.0 → 0.2.2

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
@@ -181,6 +181,8 @@ useEffect(() => {
181
181
  }, [navItems]);
182
182
  ```
183
183
 
184
+ **Section changes are not auto-detected.** The library uses `ResizeObserver` to track section and element *sizes*, but it does not watch for new or removed `[data-midday-section]` elements. In SPAs or pages with dynamic sections, call `refresh()` after route changes or any DOM mutation that adds, removes, or reorders sections.
185
+
184
186
  **Headless mode** doesn't manage element DOM — you own the variant elements. The engine reads element and variant sizes live on every scroll frame via `getBoundingClientRect()`, so size changes to your variant elements are picked up automatically. You only need `refresh()` when sections change, since section bounds are cached.
185
187
 
186
188
  ### `onChange` callback
package/dist/core.mjs CHANGED
@@ -1,196 +1,204 @@
1
- function k(t) {
2
- const i = t.getBoundingClientRect();
1
+ function z(t) {
2
+ const o = t.getBoundingClientRect();
3
3
  return {
4
- top: i.top + window.scrollY,
5
- height: i.height
4
+ top: o.top + window.scrollY,
5
+ height: o.height
6
6
  };
7
7
  }
8
- function z(t) {
9
- const i = t.getBoundingClientRect();
8
+ function G(t) {
9
+ const o = t.getBoundingClientRect();
10
10
  return {
11
- top: i.top,
12
- height: i.height
11
+ top: o.top,
12
+ height: o.height
13
13
  };
14
14
  }
15
- function P(t) {
16
- for (const i of t) {
17
- const p = k(i.el);
18
- i.top = p.top, i.height = p.height;
15
+ function S(t) {
16
+ for (const o of t) {
17
+ const p = z(o.el);
18
+ o.top = p.top, o.height = p.height;
19
19
  }
20
20
  }
21
- const G = "[data-midday-section]", K = "data-midday-section", J = "data-midday-target";
22
- function Y(t) {
23
- const i = document.querySelectorAll(G), p = [];
24
- for (const s of i) {
25
- const h = s.getAttribute(K);
26
- if (!h) continue;
21
+ const K = "[data-midday-section]", J = "data-midday-section", Q = "data-midday-target";
22
+ function U(t) {
23
+ const o = document.querySelectorAll(K), p = [];
24
+ for (const s of o) {
27
25
  const w = s.getAttribute(J);
28
- w && (!t || !w.split(" ").includes(t)) || p.push({ el: s, variant: h, top: 0, height: 0 });
26
+ if (!w) continue;
27
+ const a = s.getAttribute(Q);
28
+ a && (!t || !a.split(" ").includes(t)) || p.push({ el: s, variant: w, top: 0, height: 0 });
29
29
  }
30
- return P(p), p;
30
+ return S(p), p;
31
31
  }
32
- function Q(t) {
33
- let { element: i, variants: p, sections: s } = t;
34
- const { defaultName: h, onChange: w } = t;
35
- let c = null, d = !1, x = "", r = null;
36
- function L() {
37
- y();
32
+ function X(t) {
33
+ let { element: o, variants: p, sections: s } = t;
34
+ const { defaultName: w, onChange: a } = t;
35
+ let h = null, B = !1, x = "", l = null;
36
+ function R() {
37
+ g();
38
38
  }
39
- function S() {
40
- P(s), y();
39
+ function V() {
40
+ S(s), g();
41
41
  }
42
- function y() {
43
- d || (d = !0, c = requestAnimationFrame(l));
42
+ function g() {
43
+ B || (B = !0, h = requestAnimationFrame(c));
44
44
  }
45
- function l() {
46
- d = !1, v();
45
+ function c() {
46
+ B = !1, v();
47
47
  }
48
48
  function v() {
49
- const a = z(i), o = a.height;
50
- if (o <= 0) return;
51
- const W = window.scrollY, F = a.top, q = F + o, R = [], _ = /* @__PURE__ */ new Map();
52
- let H = o, $ = 0, j = 0;
53
- const U = /* @__PURE__ */ new Map();
49
+ const r = G(o), i = r.height;
50
+ if (i <= 0) return;
51
+ const k = window.scrollY, _ = r.top, D = _ + i, I = [], q = /* @__PURE__ */ new Map();
52
+ let L = i, j = 0, F = 0;
53
+ const H = /* @__PURE__ */ new Map();
54
54
  for (const e of s) {
55
- const T = e.top - W, g = T + e.height, M = Math.max(F, T), u = Math.min(q, g), B = Math.max(0, u - M);
56
- if (B > 0) {
57
- j += B;
58
- const b = M - F, E = q - u;
59
- H = Math.min(H, b), $ = Math.max($, o - E);
60
- const I = _.get(e.variant);
61
- I ? (I.topInset = Math.min(I.topInset, b), I.bottomInset = Math.min(I.bottomInset, E)) : _.set(e.variant, { topInset: b, bottomInset: E });
55
+ const y = e.top - k, m = y + e.height, C = Math.max(_, y), u = Math.min(D, m), M = Math.max(0, u - C);
56
+ if (M > 0) {
57
+ F += M;
58
+ const b = C - _, E = D - u;
59
+ L = Math.min(L, b), j = Math.max(j, i - E);
60
+ const P = q.get(e.variant);
61
+ P ? (P.topInset = Math.min(P.topInset, b), P.bottomInset = Math.min(P.bottomInset, E)) : q.set(e.variant, { topInset: b, bottomInset: E });
62
62
  }
63
- let f = U.get(e.variant);
64
- f || (f = [], U.set(e.variant, f)), f.push({ viewTop: T, viewBottom: g });
63
+ let f = H.get(e.variant);
64
+ f || (f = [], H.set(e.variant, f)), f.push({ viewTop: y, viewBottom: m });
65
65
  }
66
- let C = null;
66
+ let T = null;
67
67
  for (const e of p) {
68
- if (e.name === h) {
69
- C = e.wrapper;
68
+ if (e.name === w) {
69
+ T = e.wrapper;
70
70
  continue;
71
71
  }
72
- const T = U.get(e.name);
73
- if (!T) {
72
+ const y = H.get(e.name);
73
+ if (!y) {
74
74
  e.wrapper.style.clipPath = "inset(0 0 100% 0)";
75
75
  continue;
76
76
  }
77
- const g = e.wrapper.getBoundingClientRect(), M = g.height || o;
78
- let u = M, B = M;
79
- for (const f of T) {
80
- const b = Math.max(g.top, f.viewTop), E = Math.min(g.bottom, f.viewBottom);
81
- E <= b || (u = Math.min(u, b - g.top), B = Math.min(B, g.bottom - E));
77
+ const m = e.wrapper.getBoundingClientRect(), C = m.height || i;
78
+ let u = C, M = C;
79
+ for (const f of y) {
80
+ const b = Math.max(m.top, f.viewTop), E = Math.min(m.bottom, f.viewBottom);
81
+ E <= b || (u = Math.min(u, b - m.top), M = Math.min(M, m.bottom - E));
82
82
  }
83
- if (u + B < M) {
84
- e.wrapper.style.clipPath = `inset(${u}px 0 ${B}px 0)`;
85
- const f = _.get(e.name), b = f ? (o - f.topInset - f.bottomInset) / o : 0;
86
- R.push({ name: e.name, progress: b });
83
+ if (u + M < C) {
84
+ e.wrapper.style.clipPath = `inset(${u}px 0 ${M}px 0)`;
85
+ const f = q.get(e.name), b = f ? (i - f.topInset - f.bottomInset) / i : 0;
86
+ I.push({ name: e.name, progress: b });
87
87
  } else
88
88
  e.wrapper.style.clipPath = "inset(0 0 100% 0)";
89
89
  }
90
- if (C) {
91
- const e = C.getBoundingClientRect().height || o;
92
- if (j >= o)
93
- C.style.clipPath = "inset(0 0 100% 0)";
94
- else if (j <= 0)
95
- C.style.clipPath = "inset(0)", R.unshift({
96
- name: h,
90
+ if (T) {
91
+ const e = T.getBoundingClientRect().height || i;
92
+ if (F >= i)
93
+ T.style.clipPath = "inset(0 0 100% 0)";
94
+ else if (F <= 0)
95
+ T.style.clipPath = "inset(0)", I.unshift({
96
+ name: w,
97
97
  progress: 1
98
98
  });
99
99
  else {
100
- const T = H;
101
- if (o - $ >= T) {
102
- const u = e * ($ / o);
103
- C.style.clipPath = `inset(${u}px 0 0 0)`;
100
+ const y = L;
101
+ if (i - j >= y) {
102
+ const u = e * (j / i);
103
+ T.style.clipPath = `inset(${u}px 0 0 0)`;
104
104
  } else {
105
- const u = e * ((o - H) / o);
106
- C.style.clipPath = `inset(0 0 ${u}px 0)`;
105
+ const u = e * ((i - L) / i);
106
+ T.style.clipPath = `inset(0 0 ${u}px 0)`;
107
107
  }
108
- const M = o - j;
109
- R.unshift({
110
- name: h,
111
- progress: M / o
108
+ const C = i - F;
109
+ I.unshift({
110
+ name: w,
111
+ progress: C / i
112
112
  });
113
113
  }
114
114
  }
115
- const D = R.map((e) => `${e.name}:${e.progress.toFixed(3)}`).join("|");
116
- D !== x && (x = D, w == null || w(R));
115
+ const O = I.map((e) => `${e.name}:${e.progress.toFixed(3)}`).join("|");
116
+ O !== x && (x = O, a == null || a(I));
117
117
  }
118
- function m() {
119
- r == null || r.disconnect(), r = new ResizeObserver(() => {
120
- P(s), y();
118
+ function d() {
119
+ l == null || l.disconnect(), l = new ResizeObserver(() => {
120
+ S(s), g();
121
121
  });
122
- for (const a of s)
123
- r.observe(a.el);
122
+ for (const r of s)
123
+ l.observe(r.el);
124
+ l.observe(o);
124
125
  }
125
126
  function n() {
126
- window.addEventListener("scroll", L, { passive: !0 }), window.addEventListener("resize", S, { passive: !0 }), m(), y();
127
+ window.addEventListener("scroll", R, { passive: !0 }), window.addEventListener("resize", V, { passive: !0 }), d(), g();
127
128
  }
128
129
  function A() {
129
- P(s), y();
130
+ S(s), g();
130
131
  }
131
- function V(a, o) {
132
- p = a, s = o, P(s), m(), y();
132
+ function N(r, i) {
133
+ p = r, s = i, S(s), d(), g();
133
134
  }
134
- function N() {
135
- c !== null && cancelAnimationFrame(c), window.removeEventListener("scroll", L), window.removeEventListener("resize", S), r == null || r.disconnect(), r = null;
135
+ function $() {
136
+ h !== null && cancelAnimationFrame(h), window.removeEventListener("scroll", R), window.removeEventListener("resize", V), l == null || l.disconnect(), l = null;
136
137
  }
137
- return n(), { recalculate: A, update: V, destroy: N };
138
+ return n(), { recalculate: A, update: N, destroy: $ };
138
139
  }
139
- const X = "data-midday-variant", O = "default";
140
- function Z(t, i = {}) {
141
- const { onChange: p } = i, s = i.name ?? (t.getAttribute("data-midday-element") || void 0), h = t.innerHTML, w = t.style.overflow;
142
- let c = null, d = [];
143
- function x() {
144
- const l = Y(s), v = /* @__PURE__ */ new Set();
145
- for (const a of l)
146
- v.add(a.variant);
140
+ const W = "data-midday-variant", Y = "default";
141
+ function Z(t, o = {}) {
142
+ const { onChange: p } = o, s = o.name ?? (t.getAttribute("data-midday-element") || void 0), w = t.style.overflow;
143
+ let a = null, h = [];
144
+ function B() {
145
+ const c = U(s), v = /* @__PURE__ */ new Set();
146
+ for (const r of c)
147
+ v.add(r.variant);
147
148
  t.style.overflow = "visible";
148
- const m = document.createDocumentFragment();
149
+ const d = document.createDocumentFragment();
149
150
  for (; t.firstChild; )
150
- m.appendChild(t.firstChild);
151
+ d.appendChild(t.firstChild);
151
152
  const n = [];
152
- for (const a of v)
153
- n.push(r(a, m, !0));
153
+ for (const r of v)
154
+ n.push(x(r, d, !0));
154
155
  const A = document.createElement("div");
155
- A.style.visibility = "hidden", A.style.pointerEvents = "none", A.setAttribute("aria-hidden", "true"), A.appendChild(m.cloneNode(!0)), t.appendChild(A);
156
- const V = r(O, m, !1);
157
- t.appendChild(V.wrapper);
158
- const N = [V];
159
- for (const a of n)
160
- t.appendChild(a.wrapper), N.push(a);
161
- return N;
162
- }
163
- function r(l, v, m) {
156
+ A.style.visibility = "hidden", A.style.pointerEvents = "none", A.setAttribute("aria-hidden", "true"), A.appendChild(d.cloneNode(!0)), t.appendChild(A);
157
+ const N = x(Y, d, !1);
158
+ t.appendChild(N.wrapper);
159
+ const $ = [N];
160
+ for (const r of n)
161
+ t.appendChild(r.wrapper), $.push(r);
162
+ return $;
163
+ }
164
+ function x(c, v, d) {
164
165
  const n = document.createElement("div");
165
- return n.setAttribute(X, l), n.style.position = "absolute", n.style.top = "0", n.style.left = "0", n.style.right = "0", n.style.bottom = "0", n.style.willChange = "clip-path", n.style.clipPath = "inset(0 0 100% 0)", m ? (n.setAttribute("aria-hidden", "true"), n.setAttribute("inert", ""), n.style.pointerEvents = "none", n.appendChild(v.cloneNode(!0))) : n.appendChild(v), { wrapper: n, name: l };
166
+ return n.setAttribute(W, c), n.style.position = "absolute", n.style.top = "0", n.style.left = "0", n.style.right = "0", n.style.bottom = "0", n.style.willChange = "clip-path", n.style.clipPath = "inset(0 0 100% 0)", d ? (n.setAttribute("aria-hidden", "true"), n.setAttribute("inert", ""), n.style.pointerEvents = "none", n.appendChild(v.cloneNode(!0))) : n.appendChild(v), { wrapper: n, name: c };
166
167
  }
167
- function L() {
168
- const l = Y(s);
169
- d = x(), c = Q({
168
+ function l() {
169
+ const c = U(s);
170
+ h = B(), a = X({
170
171
  element: t,
171
- variants: d,
172
- defaultName: O,
173
- sections: l,
172
+ variants: h,
173
+ defaultName: Y,
174
+ sections: c,
174
175
  onChange: p
175
176
  });
176
177
  }
177
- function S() {
178
- for (const v of d)
179
- v.wrapper.remove();
180
- t.innerHTML = h;
181
- const l = Y(s);
182
- d = x(), c == null || c.update(d, l);
178
+ function R() {
179
+ const c = t.querySelector(
180
+ `[${W}="${Y}"]`
181
+ ), v = t.querySelectorAll(`[${W}]`);
182
+ for (const d of v)
183
+ d.remove();
184
+ for (; t.firstChild; )
185
+ t.removeChild(t.firstChild);
186
+ if (c)
187
+ for (; c.firstChild; )
188
+ t.appendChild(c.firstChild);
189
+ }
190
+ function V() {
191
+ R();
192
+ const c = U(s);
193
+ h = B(), a == null || a.update(h, c);
183
194
  }
184
- function y() {
185
- c == null || c.destroy(), c = null;
186
- for (const l of d)
187
- l.wrapper.remove();
188
- d = [], t.innerHTML = h, t.style.overflow = w;
195
+ function g() {
196
+ a == null || a.destroy(), a = null, R(), h = [], t.style.overflow = w;
189
197
  }
190
- return L(), { refresh: S, destroy: y };
198
+ return l(), { refresh: V, destroy: g };
191
199
  }
192
200
  export {
193
201
  Z as a,
194
- Q as c,
195
- Y as s
202
+ X as c,
203
+ U as s
196
204
  };
@@ -1 +1 @@
1
- (function(C,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(C=typeof globalThis<"u"?globalThis:C||self,I(C.midday={}))})(this,(function(C){"use strict";function I(t){const o=t.getBoundingClientRect();return{top:o.top+window.scrollY,height:o.height}}function G(t){const o=t.getBoundingClientRect();return{top:o.top,height:o.height}}function V(t){for(const o of t){const l=I(o.el);o.top=l.top,o.height=l.height}}const K="[data-midday-section]",J="data-midday-section",Q="data-midday-target";function N(t){const o=document.querySelectorAll(K),l=[];for(const s of o){const u=s.getAttribute(J);if(!u)continue;const m=s.getAttribute(Q);m&&(!t||!m.split(" ").includes(t))||l.push({el:s,variant:u,top:0,height:0})}return V(l),l}function D(t){let{element:o,variants:l,sections:s}=t;const{defaultName:u,onChange:m}=t;let n=null,c=!1,B="",r=null;function P(){g()}function v(){V(s),g()}function g(){c||(c=!0,n=requestAnimationFrame(p))}function p(){c=!1,w()}function w(){const d=G(o),a=d.height;if(a<=0)return;const ot=window.scrollY,U=d.top,k=U+a,H=[],Y=new Map;let F=a,_=0,O=0;const q=new Map;for(const e of s){const M=e.top-ot,T=M+e.height,b=Math.max(U,M),f=Math.min(k,T),R=Math.max(0,f-b);if(R>0){O+=R;const A=b-U,S=k-f;F=Math.min(F,A),_=Math.max(_,a-S);const L=Y.get(e.variant);L?(L.topInset=Math.min(L.topInset,A),L.bottomInset=Math.min(L.bottomInset,S)):Y.set(e.variant,{topInset:A,bottomInset:S})}let h=q.get(e.variant);h||(h=[],q.set(e.variant,h)),h.push({viewTop:M,viewBottom:T})}let x=null;for(const e of l){if(e.name===u){x=e.wrapper;continue}const M=q.get(e.name);if(!M){e.wrapper.style.clipPath="inset(0 0 100% 0)";continue}const T=e.wrapper.getBoundingClientRect(),b=T.height||a;let f=b,R=b;for(const h of M){const A=Math.max(T.top,h.viewTop),S=Math.min(T.bottom,h.viewBottom);S<=A||(f=Math.min(f,A-T.top),R=Math.min(R,T.bottom-S))}if(f+R<b){e.wrapper.style.clipPath=`inset(${f}px 0 ${R}px 0)`;const h=Y.get(e.name),A=h?(a-h.topInset-h.bottomInset)/a:0;H.push({name:e.name,progress:A})}else e.wrapper.style.clipPath="inset(0 0 100% 0)"}if(x){const e=x.getBoundingClientRect().height||a;if(O>=a)x.style.clipPath="inset(0 0 100% 0)";else if(O<=0)x.style.clipPath="inset(0)",H.unshift({name:u,progress:1});else{const M=F;if(a-_>=M){const f=e*(_/a);x.style.clipPath=`inset(${f}px 0 0 0)`}else{const f=e*((a-F)/a);x.style.clipPath=`inset(0 0 ${f}px 0)`}const b=a-O;H.unshift({name:u,progress:b/a})}}const z=H.map(e=>`${e.name}:${e.progress.toFixed(3)}`).join("|");z!==B&&(B=z,m==null||m(H))}function y(){r==null||r.disconnect(),r=new ResizeObserver(()=>{V(s),g()});for(const d of s)r.observe(d.el)}function i(){window.addEventListener("scroll",P,{passive:!0}),window.addEventListener("resize",v,{passive:!0}),y(),g()}function E(){V(s),g()}function j(d,a){l=d,s=a,V(s),y(),g()}function $(){n!==null&&cancelAnimationFrame(n),window.removeEventListener("scroll",P),window.removeEventListener("resize",v),r==null||r.disconnect(),r=null}return i(),{recalculate:E,update:j,destroy:$}}const X="data-midday-variant",W="default";function Z(t,o={}){const{onChange:l}=o,s=o.name??(t.getAttribute("data-midday-element")||void 0),u=t.innerHTML,m=t.style.overflow;let n=null,c=[];function B(){const p=N(s),w=new Set;for(const d of p)w.add(d.variant);t.style.overflow="visible";const y=document.createDocumentFragment();for(;t.firstChild;)y.appendChild(t.firstChild);const i=[];for(const d of w)i.push(r(d,y,!0));const E=document.createElement("div");E.style.visibility="hidden",E.style.pointerEvents="none",E.setAttribute("aria-hidden","true"),E.appendChild(y.cloneNode(!0)),t.appendChild(E);const j=r(W,y,!1);t.appendChild(j.wrapper);const $=[j];for(const d of i)t.appendChild(d.wrapper),$.push(d);return $}function r(p,w,y){const i=document.createElement("div");return i.setAttribute(X,p),i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.right="0",i.style.bottom="0",i.style.willChange="clip-path",i.style.clipPath="inset(0 0 100% 0)",y?(i.setAttribute("aria-hidden","true"),i.setAttribute("inert",""),i.style.pointerEvents="none",i.appendChild(w.cloneNode(!0))):i.appendChild(w),{wrapper:i,name:p}}function P(){const p=N(s);c=B(),n=D({element:t,variants:c,defaultName:W,sections:p,onChange:l})}function v(){for(const w of c)w.wrapper.remove();t.innerHTML=u;const p=N(s);c=B(),n==null||n.update(c,p)}function g(){n==null||n.destroy(),n=null;for(const p of c)p.wrapper.remove();c=[],t.innerHTML=u,t.style.overflow=m}return P(),{refresh:v,destroy:g}}function tt(t){const{element:o,variants:l,defaultVariant:s="default",name:u,onChange:m}=t;let n=null;function c(){return Object.entries(l).map(([v,g])=>({name:v,wrapper:g}))}function B(){const v=N(u);n=D({element:o,variants:c(),defaultName:s,sections:v,onChange:m})}function r(){const v=N(u);n==null||n.update(c(),v)}function P(){n==null||n.destroy(),n=null}return B(),{refresh:r,destroy:P}}function et(t,o){return Z(t,o)}function nt(t){return tt(t)}C.midday=et,C.middayHeadless=nt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(M,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(M=typeof globalThis<"u"?globalThis:M||self,I(M.midday={}))})(this,(function(M){"use strict";function I(t){const n=t.getBoundingClientRect();return{top:n.top+window.scrollY,height:n.height}}function K(t){const n=t.getBoundingClientRect();return{top:n.top,height:n.height}}function V(t){for(const n of t){const d=I(n.el);n.top=d.top,n.height=d.height}}const J="[data-midday-section]",Q="data-midday-section",X="data-midday-target";function N(t){const n=document.querySelectorAll(J),d=[];for(const s of n){const p=s.getAttribute(Q);if(!p)continue;const a=s.getAttribute(X);a&&(!t||!a.split(" ").includes(t))||d.push({el:s,variant:p,top:0,height:0})}return V(d),d}function k(t){let{element:n,variants:d,sections:s}=t;const{defaultName:p,onChange:a}=t;let i=null,y=!1,B="",r=null;function E(){w()}function v(){V(s),w()}function w(){y||(y=!0,i=requestAnimationFrame(l))}function l(){y=!1,g()}function g(){const u=K(n),c=u.height;if(c<=0)return;const ot=window.scrollY,W=u.top,z=W+c,$=[],Y=new Map;let F=c,_=0,q=0;const D=new Map;for(const e of s){const b=e.top-ot,C=b+e.height,T=Math.max(W,b),h=Math.min(z,C),R=Math.max(0,h-T);if(R>0){q+=R;const A=T-W,P=z-h;F=Math.min(F,A),_=Math.max(_,c-P);const j=Y.get(e.variant);j?(j.topInset=Math.min(j.topInset,A),j.bottomInset=Math.min(j.bottomInset,P)):Y.set(e.variant,{topInset:A,bottomInset:P})}let m=D.get(e.variant);m||(m=[],D.set(e.variant,m)),m.push({viewTop:b,viewBottom:C})}let S=null;for(const e of d){if(e.name===p){S=e.wrapper;continue}const b=D.get(e.name);if(!b){e.wrapper.style.clipPath="inset(0 0 100% 0)";continue}const C=e.wrapper.getBoundingClientRect(),T=C.height||c;let h=T,R=T;for(const m of b){const A=Math.max(C.top,m.viewTop),P=Math.min(C.bottom,m.viewBottom);P<=A||(h=Math.min(h,A-C.top),R=Math.min(R,C.bottom-P))}if(h+R<T){e.wrapper.style.clipPath=`inset(${h}px 0 ${R}px 0)`;const m=Y.get(e.name),A=m?(c-m.topInset-m.bottomInset)/c:0;$.push({name:e.name,progress:A})}else e.wrapper.style.clipPath="inset(0 0 100% 0)"}if(S){const e=S.getBoundingClientRect().height||c;if(q>=c)S.style.clipPath="inset(0 0 100% 0)";else if(q<=0)S.style.clipPath="inset(0)",$.unshift({name:p,progress:1});else{const b=F;if(c-_>=b){const h=e*(_/c);S.style.clipPath=`inset(${h}px 0 0 0)`}else{const h=e*((c-F)/c);S.style.clipPath=`inset(0 0 ${h}px 0)`}const T=c-q;$.unshift({name:p,progress:T/c})}}const G=$.map(e=>`${e.name}:${e.progress.toFixed(3)}`).join("|");G!==B&&(B=G,a==null||a($))}function f(){r==null||r.disconnect(),r=new ResizeObserver(()=>{V(s),w()});for(const u of s)r.observe(u.el);r.observe(n)}function o(){window.addEventListener("scroll",E,{passive:!0}),window.addEventListener("resize",v,{passive:!0}),f(),w()}function x(){V(s),w()}function L(u,c){d=u,s=c,V(s),f(),w()}function H(){i!==null&&cancelAnimationFrame(i),window.removeEventListener("scroll",E),window.removeEventListener("resize",v),r==null||r.disconnect(),r=null}return o(),{recalculate:x,update:L,destroy:H}}const O="data-midday-variant",U="default";function Z(t,n={}){const{onChange:d}=n,s=n.name??(t.getAttribute("data-midday-element")||void 0),p=t.style.overflow;let a=null,i=[];function y(){const l=N(s),g=new Set;for(const u of l)g.add(u.variant);t.style.overflow="visible";const f=document.createDocumentFragment();for(;t.firstChild;)f.appendChild(t.firstChild);const o=[];for(const u of g)o.push(B(u,f,!0));const x=document.createElement("div");x.style.visibility="hidden",x.style.pointerEvents="none",x.setAttribute("aria-hidden","true"),x.appendChild(f.cloneNode(!0)),t.appendChild(x);const L=B(U,f,!1);t.appendChild(L.wrapper);const H=[L];for(const u of o)t.appendChild(u.wrapper),H.push(u);return H}function B(l,g,f){const o=document.createElement("div");return o.setAttribute(O,l),o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.right="0",o.style.bottom="0",o.style.willChange="clip-path",o.style.clipPath="inset(0 0 100% 0)",f?(o.setAttribute("aria-hidden","true"),o.setAttribute("inert",""),o.style.pointerEvents="none",o.appendChild(g.cloneNode(!0))):o.appendChild(g),{wrapper:o,name:l}}function r(){const l=N(s);i=y(),a=k({element:t,variants:i,defaultName:U,sections:l,onChange:d})}function E(){const l=t.querySelector(`[${O}="${U}"]`),g=t.querySelectorAll(`[${O}]`);for(const f of g)f.remove();for(;t.firstChild;)t.removeChild(t.firstChild);if(l)for(;l.firstChild;)t.appendChild(l.firstChild)}function v(){E();const l=N(s);i=y(),a==null||a.update(i,l)}function w(){a==null||a.destroy(),a=null,E(),i=[],t.style.overflow=p}return r(),{refresh:v,destroy:w}}function tt(t){const{element:n,variants:d,defaultVariant:s="default",name:p,onChange:a}=t;let i=null;function y(){return Object.entries(d).map(([v,w])=>({name:v,wrapper:w}))}function B(){const v=N(p);i=k({element:n,variants:y(),defaultName:s,sections:v,onChange:a})}function r(){const v=N(p);i==null||i.update(y(),v)}function E(){i==null||i.destroy(),i=null}return B(),{refresh:r,destroy:E}}function et(t,n){return Z(t,n)}function nt(t){return tt(t)}M.midday=et,M.middayHeadless=nt,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
package/dist/svelte.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { a as t } from "./core.mjs";
2
- function u(d, o) {
3
- let r = t(d, o);
1
+ import { a as o } from "./core.mjs";
2
+ function l(d, y) {
3
+ let r = o(d, y);
4
4
  return {
5
5
  update(e) {
6
- r == null || r.destroy(), r = t(d, e);
6
+ e !== void 0 ? (r == null || r.destroy(), r = o(d, e)) : r == null || r.refresh();
7
7
  },
8
8
  destroy() {
9
9
  r == null || r.destroy(), r = null;
@@ -11,5 +11,5 @@ function u(d, o) {
11
11
  };
12
12
  }
13
13
  export {
14
- u as midday
14
+ l as midday
15
15
  };
package/dist/vue.mjs CHANGED
@@ -1,22 +1,26 @@
1
1
  import { shallowRef as o, onMounted as u, onUnmounted as s } from "vue";
2
- import { a as d } from "./core.mjs";
3
- function c(n, a) {
4
- const e = o(null);
2
+ import { a as t } from "./core.mjs";
3
+ function c(n, e) {
4
+ const a = o(null);
5
5
  return u(() => {
6
- n.value && (e.value = d(n.value, a));
6
+ n.value && (a.value = t(n.value, e));
7
7
  }), s(() => {
8
- var t;
9
- (t = e.value) == null || t.destroy(), e.value = null;
10
- }), e;
8
+ var d;
9
+ (d = a.value) == null || d.destroy(), a.value = null;
10
+ }), a;
11
11
  }
12
12
  const l = {
13
- mounted(n, a) {
14
- const e = d(n, a.value);
15
- n.__middayInstance = e;
13
+ mounted(n, e) {
14
+ const a = t(n, e.value);
15
+ n.__middayInstance = a;
16
+ },
17
+ updated(n) {
18
+ var e;
19
+ (e = n.__middayInstance) == null || e.refresh();
16
20
  },
17
21
  unmounted(n) {
18
- var a;
19
- (a = n.__middayInstance) == null || a.destroy(), delete n.__middayInstance;
22
+ var e;
23
+ (e = n.__middayInstance) == null || e.destroy(), delete n.__middayInstance;
20
24
  }
21
25
  };
22
26
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marcwiest/midday.js",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A modern vanilla JS plugin for fixed headers that change style as you scroll through sections. Zero dependencies. The spiritual successor to midnight.js.",
5
5
  "publishConfig": {
6
6
  "access": "public"