@threadlabs/looma 0.51.4 → 0.51.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.
@@ -42,18 +42,52 @@ export function connect(host) {
42
42
  host.state.internalOpen = Boolean(external);
43
43
  let groupName = "";
44
44
  let disposed = false;
45
+ let motionFrame = 0;
46
+ let takeoverMotion;
47
+ const view = document.defaultView;
48
+ const reducedMotion = view?.matchMedia?.("(prefers-reduced-motion: reduce)");
49
+ const stopTakeoverMotion = () => {
50
+ view?.cancelAnimationFrame(motionFrame);
51
+ motionFrame = 0;
52
+ takeoverMotion?.cancel();
53
+ };
54
+ const onMotionPreferenceChange = () => { if (reducedMotion.matches) stopTakeoverMotion(); };
55
+ reducedMotion?.addEventListener("change", onMotionPreferenceChange);
56
+ // A consumer may hide a sibling when this panel takes over the remaining space.
57
+ // Flex interpolation alone cannot animate the resulting change of position.
58
+ const animateFillTakeover = () => {
59
+ if (motionFrame || !host.props.fill.value || !view || !host.element.animate) return;
60
+ const previousTop = host.refs.heading.getBoundingClientRect().top;
61
+ takeoverMotion?.cancel();
62
+ if (reducedMotion?.matches) return;
63
+ motionFrame = view.requestAnimationFrame(() => {
64
+ motionFrame = 0;
65
+ if (disposed || !host.element.isConnected) return;
66
+ const delta = previousTop - host.refs.heading.getBoundingClientRect().top;
67
+ if (Math.abs(delta) < 1) return;
68
+ const style = view.getComputedStyle(host.element);
69
+ const duration = style.transitionDuration.split(",")[0].trim();
70
+ const milliseconds = parseFloat(duration) * (duration.endsWith("ms") ? 1 : 1000);
71
+ if (!(milliseconds > 0)) return;
72
+ takeoverMotion = host.element.animate([{ translate: `0 ${delta}px` }, { translate: "0 0" }], {
73
+ duration: milliseconds, easing: style.transitionTimingFunction, fill: "none",
74
+ });
75
+ });
76
+ };
45
77
  const member = {
46
78
  isOpen: () => Boolean(host.state.internalOpen),
47
79
  required: () => Boolean(host.props.requiredOpen.value),
48
80
  disabled: () => Boolean(host.props.disabled.value),
49
81
  open() {
50
82
  if (disposed || host.state.internalOpen) return;
83
+ animateFillTakeover();
51
84
  host.state.internalOpen = true;
52
85
  syncGroup("programmatic", "programmatic");
53
86
  host.dispatch("open", { open: true, reason: "programmatic", trigger: "programmatic" });
54
87
  },
55
88
  close(reason, how) {
56
89
  if (!host.state.internalOpen) return;
90
+ animateFillTakeover();
57
91
  host.state.internalOpen = false;
58
92
  host.dispatch("close", { open: false, reason, trigger: how });
59
93
  },
@@ -78,7 +112,10 @@ export function connect(host) {
78
112
  const stop = host.effect(() => {
79
113
  if (host.props.open.value !== external) {
80
114
  external = host.props.open.value;
81
- if (external || mayClose()) host.state.internalOpen = Boolean(external);
115
+ if (external || mayClose()) {
116
+ animateFillTakeover();
117
+ host.state.internalOpen = Boolean(external);
118
+ }
82
119
  }
83
120
  const level = Number(host.props.headingLevel.value);
84
121
  host.state.headingRole = Number.isInteger(level) && level >= 2 && level <= 6 ? "heading" : null;
@@ -92,12 +129,14 @@ export function connect(host) {
92
129
  const open = !host.state.internalOpen;
93
130
  if (!open && !mayClose()) return;
94
131
  const how = trigger();
132
+ animateFillTakeover();
95
133
  host.state.internalOpen = open;
96
134
  if (open) syncGroup("action", how);
97
135
  host.dispatch(open ? "open" : "close", { open, reason: "action", trigger: how });
98
136
  };
99
137
  const onBeforematch = () => queueMicrotask(() => {
100
138
  if (disposed || host.state.internalOpen) return;
139
+ animateFillTakeover();
101
140
  host.state.internalOpen = true;
102
141
  syncGroup("programmatic", "programmatic");
103
142
  host.dispatch("open", { open: true, reason: "programmatic", trigger: "programmatic" });
@@ -111,6 +150,8 @@ export function connect(host) {
111
150
  measureHeading();
112
151
  return () => {
113
152
  disposed = true;
153
+ stopTakeoverMotion();
154
+ reducedMotion?.removeEventListener("change", onMotionPreferenceChange);
114
155
  headingObserver?.disconnect();
115
156
  stop();
116
157
  stopTracking();
package/docs/catalog.json CHANGED
@@ -533,7 +533,7 @@
533
533
  ],
534
534
  "schemaVersion": 1,
535
535
  "package": "@threadlabs/looma",
536
- "version": "0.51.4",
536
+ "version": "0.51.5",
537
537
  "groups": [
538
538
  {
539
539
  "id": "layout",
package/editor/index.js CHANGED
@@ -12077,12 +12077,47 @@ function connect$2(host) {
12077
12077
  host.state.internalOpen = Boolean(external);
12078
12078
  let groupName = "";
12079
12079
  let disposed = false;
12080
+ let motionFrame = 0;
12081
+ let takeoverMotion;
12082
+ const view = document.defaultView;
12083
+ const reducedMotion = view?.matchMedia?.("(prefers-reduced-motion: reduce)");
12084
+ const stopTakeoverMotion = () => {
12085
+ view?.cancelAnimationFrame(motionFrame);
12086
+ motionFrame = 0;
12087
+ takeoverMotion?.cancel();
12088
+ };
12089
+ const onMotionPreferenceChange = () => {
12090
+ if (reducedMotion.matches) stopTakeoverMotion();
12091
+ };
12092
+ reducedMotion?.addEventListener("change", onMotionPreferenceChange);
12093
+ const animateFillTakeover = () => {
12094
+ if (motionFrame || !host.props.fill.value || !view || !host.element.animate) return;
12095
+ const previousTop = host.refs.heading.getBoundingClientRect().top;
12096
+ takeoverMotion?.cancel();
12097
+ if (reducedMotion?.matches) return;
12098
+ motionFrame = view.requestAnimationFrame(() => {
12099
+ motionFrame = 0;
12100
+ if (disposed || !host.element.isConnected) return;
12101
+ const delta = previousTop - host.refs.heading.getBoundingClientRect().top;
12102
+ if (Math.abs(delta) < 1) return;
12103
+ const style = view.getComputedStyle(host.element);
12104
+ const duration = style.transitionDuration.split(",")[0].trim();
12105
+ const milliseconds = parseFloat(duration) * (duration.endsWith("ms") ? 1 : 1e3);
12106
+ if (!(milliseconds > 0)) return;
12107
+ takeoverMotion = host.element.animate([{ translate: `0 ${delta}px` }, { translate: "0 0" }], {
12108
+ duration: milliseconds,
12109
+ easing: style.transitionTimingFunction,
12110
+ fill: "none"
12111
+ });
12112
+ });
12113
+ };
12080
12114
  const member = {
12081
12115
  isOpen: () => Boolean(host.state.internalOpen),
12082
12116
  required: () => Boolean(host.props.requiredOpen.value),
12083
12117
  disabled: () => Boolean(host.props.disabled.value),
12084
12118
  open() {
12085
12119
  if (disposed || host.state.internalOpen) return;
12120
+ animateFillTakeover();
12086
12121
  host.state.internalOpen = true;
12087
12122
  syncGroup("programmatic", "programmatic");
12088
12123
  host.dispatch("open", {
@@ -12093,6 +12128,7 @@ function connect$2(host) {
12093
12128
  },
12094
12129
  close(reason, how) {
12095
12130
  if (!host.state.internalOpen) return;
12131
+ animateFillTakeover();
12096
12132
  host.state.internalOpen = false;
12097
12133
  host.dispatch("close", {
12098
12134
  open: false,
@@ -12121,7 +12157,10 @@ function connect$2(host) {
12121
12157
  const stop = host.effect(() => {
12122
12158
  if (host.props.open.value !== external) {
12123
12159
  external = host.props.open.value;
12124
- if (external || mayClose()) host.state.internalOpen = Boolean(external);
12160
+ if (external || mayClose()) {
12161
+ animateFillTakeover();
12162
+ host.state.internalOpen = Boolean(external);
12163
+ }
12125
12164
  }
12126
12165
  const level = Number(host.props.headingLevel.value);
12127
12166
  host.state.headingRole = Number.isInteger(level) && level >= 2 && level <= 6 ? "heading" : null;
@@ -12135,6 +12174,7 @@ function connect$2(host) {
12135
12174
  const open = !host.state.internalOpen;
12136
12175
  if (!open && !mayClose()) return;
12137
12176
  const how = trigger();
12177
+ animateFillTakeover();
12138
12178
  host.state.internalOpen = open;
12139
12179
  if (open) syncGroup("action", how);
12140
12180
  host.dispatch(open ? "open" : "close", {
@@ -12145,6 +12185,7 @@ function connect$2(host) {
12145
12185
  };
12146
12186
  const onBeforematch = () => queueMicrotask(() => {
12147
12187
  if (disposed || host.state.internalOpen) return;
12188
+ animateFillTakeover();
12148
12189
  host.state.internalOpen = true;
12149
12190
  syncGroup("programmatic", "programmatic");
12150
12191
  host.dispatch("open", {
@@ -12162,6 +12203,8 @@ function connect$2(host) {
12162
12203
  measureHeading();
12163
12204
  return () => {
12164
12205
  disposed = true;
12206
+ stopTakeoverMotion();
12207
+ reducedMotion?.removeEventListener("change", onMotionPreferenceChange);
12165
12208
  headingObserver?.disconnect();
12166
12209
  stop();
12167
12210
  stopTracking();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadlabs/looma",
3
- "version": "0.51.4",
3
+ "version": "0.51.5",
4
4
  "type": "module",
5
5
  "description": "HTML Next UI components, native DOM support and design tokens.",
6
6
  "license": "MIT",