@adia-ai/web-components 0.2.2 → 0.2.4

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.
Files changed (121) hide show
  1. package/components/agent-trace/agent-trace.css +24 -3
  2. package/components/button/button.js +3 -0
  3. package/components/demo-toggle/demo-toggle.a2ui.json +144 -0
  4. package/components/demo-toggle/demo-toggle.css +120 -0
  5. package/components/demo-toggle/demo-toggle.js +144 -0
  6. package/components/demo-toggle/demo-toggle.test.js +102 -0
  7. package/components/demo-toggle/demo-toggle.yaml +144 -0
  8. package/components/index.js +1 -0
  9. package/components/input/input.js +11 -0
  10. package/components/list/list.css +66 -3
  11. package/components/nav-group/nav-group.a2ui.json +1 -1
  12. package/components/nav-group/nav-group.css +5 -5
  13. package/components/nav-group/nav-group.yaml +1 -1
  14. package/components/nav-item/nav-item.a2ui.json +1 -1
  15. package/components/nav-item/nav-item.css +3 -4
  16. package/components/nav-item/nav-item.yaml +1 -1
  17. package/components/textarea/textarea.js +10 -0
  18. package/core/icons.js +13 -1
  19. package/package.json +1 -1
  20. package/styles/components.css +1 -0
  21. package/styles/typography.css +1 -1
  22. package/traits/_catalog.json +258 -5
  23. package/traits/active-state.test.js +1 -1
  24. package/traits/anchor-positioning.js +205 -52
  25. package/traits/anchor-positioning.test.js +77 -4
  26. package/traits/announcer-stage.js +157 -0
  27. package/traits/announcer.js +145 -0
  28. package/traits/announcer.test.js +268 -0
  29. package/traits/arrow-grid-nav.js +234 -0
  30. package/traits/arrow-grid-nav.test.js +375 -0
  31. package/traits/attention-pulse.js +1 -1
  32. package/traits/attention-pulse.test.js +1 -1
  33. package/traits/confetti-burst.js +90 -60
  34. package/traits/confetti-burst.test.js +16 -8
  35. package/traits/confetti-stage.js +143 -0
  36. package/traits/confetti.js +44 -47
  37. package/traits/confetti.test.js +24 -5
  38. package/traits/count-up.js +31 -6
  39. package/traits/count-up.test.js +1 -1
  40. package/traits/declarative.test.js +1 -1
  41. package/traits/dirty-state.test.js +1 -1
  42. package/traits/drag-ghost.js +55 -3
  43. package/traits/drag-ghost.test.js +1 -1
  44. package/traits/draggable-list-item.js +279 -0
  45. package/traits/draggable-list-item.test.js +51 -0
  46. package/traits/draggable.js +14 -4
  47. package/traits/draggable.test.js +1 -1
  48. package/traits/drop-target.js +223 -0
  49. package/traits/drop-target.test.js +241 -0
  50. package/traits/droppable-collection.js +89 -0
  51. package/traits/droppable-collection.test.js +99 -0
  52. package/traits/droppable.js +125 -0
  53. package/traits/droppable.test.js +54 -0
  54. package/traits/error-shake.js +157 -0
  55. package/traits/error-shake.test.js +114 -0
  56. package/traits/fade-presence.test.js +1 -1
  57. package/traits/focus-restore.js +135 -0
  58. package/traits/focus-restore.test.js +202 -0
  59. package/traits/focus-trap.test.js +1 -1
  60. package/traits/focusable.test.js +1 -1
  61. package/traits/glow-focus.js +1 -1
  62. package/traits/glow-focus.test.js +1 -1
  63. package/traits/gradient-shift.js +1 -1
  64. package/traits/gradient-shift.test.js +1 -1
  65. package/traits/haptic-feedback.test.js +1 -1
  66. package/traits/hotkey.test.js +1 -1
  67. package/traits/hoverable.test.js +1 -1
  68. package/traits/index.js +15 -0
  69. package/traits/inertia-drag.js +9 -0
  70. package/traits/inertia-drag.test.js +1 -1
  71. package/traits/input-mask.js +328 -0
  72. package/traits/input-mask.test.js +151 -0
  73. package/traits/intersection-observer.test.js +1 -1
  74. package/traits/keyboard-nav.test.js +1 -1
  75. package/traits/keyboard-reorderable.js +254 -0
  76. package/traits/keyboard-reorderable.test.js +45 -0
  77. package/traits/layout-animation.js +229 -0
  78. package/traits/layout-animation.test.js +114 -0
  79. package/traits/long-press.js +212 -0
  80. package/traits/long-press.test.js +244 -0
  81. package/traits/magnetic-hover.js +1 -1
  82. package/traits/magnetic-hover.test.js +1 -1
  83. package/traits/noise-texture.js +7 -3
  84. package/traits/noise-texture.test.js +1 -1
  85. package/traits/parallax.js +1 -1
  86. package/traits/parallax.test.js +1 -1
  87. package/traits/portal.test.js +1 -1
  88. package/traits/pressable.test.js +1 -1
  89. package/traits/resettable.js +29 -3
  90. package/traits/resettable.test.js +34 -1
  91. package/traits/resizable.test.js +1 -1
  92. package/traits/resize-observer.test.js +1 -1
  93. package/traits/ripple.js +1 -1
  94. package/traits/ripple.test.js +1 -1
  95. package/traits/roving-tabindex.test.js +1 -1
  96. package/traits/scale-press.test.js +1 -1
  97. package/traits/scroll-lock.test.js +1 -1
  98. package/traits/scroll-progress.js +201 -0
  99. package/traits/scroll-progress.test.js +182 -0
  100. package/traits/shimmer-loading.js +1 -1
  101. package/traits/shimmer-loading.test.js +1 -1
  102. package/traits/{_smoke.test.js → smoke.test.js} +1 -1
  103. package/traits/snap-to-grid.test.js +1 -1
  104. package/traits/sound-feedback.test.js +1 -1
  105. package/traits/spring-animate.js +8 -3
  106. package/traits/spring-animate.test.js +1 -1
  107. package/traits/success-checkmark.js +222 -0
  108. package/traits/success-checkmark.test.js +120 -0
  109. package/traits/tilt-hover.js +1 -1
  110. package/traits/tilt-hover.test.js +1 -1
  111. package/traits/tossable.js +9 -0
  112. package/traits/tossable.test.js +1 -1
  113. package/traits/traits-host.test.js +1 -1
  114. package/traits/typeahead.test.js +1 -1
  115. package/traits/typewriter.js +1 -1
  116. package/traits/typewriter.test.js +1 -1
  117. package/traits/validation.test.js +1 -1
  118. package/traits/view-transition.js +140 -0
  119. package/traits/view-transition.test.js +268 -0
  120. /package/traits/{_motion.js → motion.js} +0 -0
  121. /package/traits/{_test-helpers.js → test-helpers.js} +0 -0
@@ -0,0 +1,268 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
+ import { viewTransition } from './view-transition.js';
3
+ import { _resetMotionCache } from './motion.js';
4
+ import {
5
+ mountHost,
6
+ connectTrait,
7
+ spyEvent,
8
+ resetDOM,
9
+ expectValidSchema,
10
+ wait,
11
+ } from './test-helpers.js';
12
+
13
+ describe('view-transition', () => {
14
+ beforeEach(() => {
15
+ resetDOM();
16
+ _resetMotionCache();
17
+ // happy-dom has no startViewTransition; ensure we start clean each test.
18
+ delete document.startViewTransition;
19
+ });
20
+
21
+ afterEach(() => {
22
+ delete document.startViewTransition;
23
+ _resetMotionCache();
24
+ });
25
+
26
+ it('exposes a valid schema', () => {
27
+ expectValidSchema(viewTransition);
28
+ expect(viewTransition.schema.name).toBe('view-transition');
29
+ expect(viewTransition.schema.category).toBe('motion-positioning');
30
+ expect(viewTransition.schema.events).toContain('view-transition-start');
31
+ expect(viewTransition.schema.events).toContain('view-transition-end');
32
+ expect(viewTransition.schema.config).toContain('data-view-transition-name');
33
+ expect(viewTransition.schema.config).toContain('data-view-transition-duration');
34
+ expect(viewTransition.schema.config).toContain('data-view-transition-easing');
35
+ });
36
+
37
+ it('writes view-transition-name to the host inline style', () => {
38
+ const host = mountHost('div', { 'data-view-transition-name': 'card-42' });
39
+ connectTrait(viewTransition, host);
40
+ expect(host.style.viewTransitionName).toBe('card-42');
41
+ });
42
+
43
+ it('writes --vt-duration / --vt-easing custom props', () => {
44
+ const host = mountHost('div', {
45
+ 'data-view-transition-name': 'hero',
46
+ 'data-view-transition-duration': '450ms',
47
+ 'data-view-transition-easing': 'cubic-bezier(0.2, 0.8, 0.2, 1)',
48
+ });
49
+ connectTrait(viewTransition, host);
50
+ expect(host.style.getPropertyValue('--vt-duration')).toBe('450ms');
51
+ expect(host.style.getPropertyValue('--vt-easing')).toBe(
52
+ 'cubic-bezier(0.2, 0.8, 0.2, 1)',
53
+ );
54
+ });
55
+
56
+ it('omits CSS props when their data attrs are absent', () => {
57
+ const host = mountHost('div');
58
+ connectTrait(viewTransition, host);
59
+ // happy-dom returns undefined for unset viewTransitionName; real browsers
60
+ // return ''. Either is acceptable — the contract is "nothing was set."
61
+ expect(host.style.viewTransitionName || '').toBe('');
62
+ expect(host.style.getPropertyValue('--vt-duration')).toBe('');
63
+ expect(host.style.getPropertyValue('--vt-easing')).toBe('');
64
+ });
65
+
66
+ it('installs host.startTransition() method', () => {
67
+ const host = mountHost();
68
+ expect(typeof host.startTransition).toBe('undefined');
69
+ connectTrait(viewTransition, host);
70
+ expect(typeof host.startTransition).toBe('function');
71
+ });
72
+
73
+ it('removes host.startTransition() on disconnect', () => {
74
+ const host = mountHost();
75
+ const inst = connectTrait(viewTransition, host);
76
+ expect(typeof host.startTransition).toBe('function');
77
+ inst.disconnect(host);
78
+ expect(host.startTransition).toBeUndefined();
79
+ });
80
+
81
+ it('runs the callback when the API is missing (feature-detect fallback)', () => {
82
+ const host = mountHost();
83
+ connectTrait(viewTransition, host);
84
+ let ran = false;
85
+ host.startTransition(() => { ran = true; });
86
+ expect(ran).toBe(true);
87
+ });
88
+
89
+ it('fires start + end events when the API is missing', async () => {
90
+ const host = mountHost();
91
+ connectTrait(viewTransition, host);
92
+ const startSpy = spyEvent(host, 'view-transition-start');
93
+ const endSpy = spyEvent(host, 'view-transition-end');
94
+ host.startTransition(() => {});
95
+ // start fires synchronously; end fires on the next microtask.
96
+ expect(startSpy.count).toBe(1);
97
+ await Promise.resolve();
98
+ expect(endSpy.count).toBe(1);
99
+ });
100
+
101
+ it('toggles data-view-transition-active across start → end', async () => {
102
+ const host = mountHost();
103
+ connectTrait(viewTransition, host);
104
+ expect(host.hasAttribute('data-view-transition-active')).toBe(false);
105
+ host.startTransition(() => {
106
+ // Mutation runs while the attribute is set.
107
+ expect(host.hasAttribute('data-view-transition-active')).toBe(true);
108
+ });
109
+ // The end is queued on a microtask in the fallback path.
110
+ await Promise.resolve();
111
+ expect(host.hasAttribute('data-view-transition-active')).toBe(false);
112
+ });
113
+
114
+ it('returns a finished-promise even in the fallback path', async () => {
115
+ const host = mountHost();
116
+ connectTrait(viewTransition, host);
117
+ const transition = host.startTransition(() => {});
118
+ expect(transition).toBeTruthy();
119
+ expect(transition.finished).toBeInstanceOf(Promise);
120
+ await expect(transition.finished).resolves.toBeUndefined();
121
+ });
122
+
123
+ it('uses real document.startViewTransition when available', () => {
124
+ const finished = Promise.resolve();
125
+ const fakeTransition = { finished, ready: finished, updateCallbackDone: finished };
126
+ const stub = vi.fn((cb) => { cb(); return fakeTransition; });
127
+ document.startViewTransition = stub;
128
+
129
+ const host = mountHost();
130
+ connectTrait(viewTransition, host);
131
+ const cb = vi.fn();
132
+ const result = host.startTransition(cb);
133
+
134
+ expect(stub).toHaveBeenCalledTimes(1);
135
+ expect(cb).toHaveBeenCalledTimes(1);
136
+ expect(result).toBe(fakeTransition);
137
+ });
138
+
139
+ it('fires end after the real transition resolves', async () => {
140
+ let resolveFinished;
141
+ const finished = new Promise((r) => { resolveFinished = r; });
142
+ document.startViewTransition = (cb) => {
143
+ cb();
144
+ return { finished, ready: finished, updateCallbackDone: finished };
145
+ };
146
+
147
+ const host = mountHost();
148
+ connectTrait(viewTransition, host);
149
+ const endSpy = spyEvent(host, 'view-transition-end');
150
+
151
+ host.startTransition(() => {});
152
+ // End hasn't fired yet — the transition is still in flight.
153
+ expect(endSpy.count).toBe(0);
154
+
155
+ resolveFinished();
156
+ await Promise.resolve();
157
+ await Promise.resolve();
158
+ expect(endSpy.count).toBe(1);
159
+ });
160
+
161
+ it('fires end even if the real transition rejects (user-skipped)', async () => {
162
+ const finished = Promise.reject(new Error('skipped'));
163
+ // Pre-attach a noop catch so the rejection isn't unhandled in the test runner.
164
+ finished.catch(() => {});
165
+ document.startViewTransition = (cb) => {
166
+ cb();
167
+ return { finished, ready: finished, updateCallbackDone: finished };
168
+ };
169
+
170
+ const host = mountHost();
171
+ connectTrait(viewTransition, host);
172
+ const endSpy = spyEvent(host, 'view-transition-end');
173
+
174
+ host.startTransition(() => {});
175
+ await Promise.resolve();
176
+ await Promise.resolve();
177
+ expect(endSpy.count).toBe(1);
178
+ });
179
+
180
+ it('runs callback synchronously even with a missing/invalid argument', () => {
181
+ const host = mountHost();
182
+ connectTrait(viewTransition, host);
183
+ expect(() => host.startTransition()).not.toThrow();
184
+ expect(() => host.startTransition('not a function')).not.toThrow();
185
+ });
186
+
187
+ it('honors prefers-reduced-motion: reduce — synchronous lifecycle, no animation', async () => {
188
+ // Force prefersReducedMotion() to return true.
189
+ const origMatchMedia = window.matchMedia;
190
+ window.matchMedia = (q) => ({
191
+ matches: typeof q === 'string' && q.includes('prefers-reduced-motion'),
192
+ media: q,
193
+ addEventListener() {},
194
+ removeEventListener() {},
195
+ addListener() {},
196
+ removeListener() {},
197
+ dispatchEvent() { return false; },
198
+ onchange: null,
199
+ });
200
+ _resetMotionCache();
201
+
202
+ // Even if the API is "available", reduced-motion takes the fallback path.
203
+ document.startViewTransition = vi.fn();
204
+
205
+ const host = mountHost();
206
+ connectTrait(viewTransition, host);
207
+ const startSpy = spyEvent(host, 'view-transition-start');
208
+ const endSpy = spyEvent(host, 'view-transition-end');
209
+ let ran = false;
210
+ host.startTransition(() => { ran = true; });
211
+
212
+ expect(ran).toBe(true);
213
+ expect(startSpy.count).toBe(1);
214
+ await Promise.resolve();
215
+ expect(endSpy.count).toBe(1);
216
+ expect(document.startViewTransition).not.toHaveBeenCalled();
217
+
218
+ window.matchMedia = origMatchMedia;
219
+ _resetMotionCache();
220
+ });
221
+
222
+ it('disconnect clears active attr and restores inline styles', () => {
223
+ const host = mountHost('div', {
224
+ 'data-view-transition-name': 'card-9',
225
+ 'data-view-transition-duration': '300ms',
226
+ });
227
+ const inst = connectTrait(viewTransition, host);
228
+ // Force the attribute on so disconnect's cleanup is observable.
229
+ host.setAttribute('data-view-transition-active', '');
230
+ inst.disconnect(host);
231
+
232
+ expect(host.hasAttribute('data-view-transition-active')).toBe(false);
233
+ expect(host.style.viewTransitionName || '').toBe('');
234
+ expect(host.style.getPropertyValue('--vt-duration')).toBe('');
235
+ });
236
+
237
+ it('does not clobber an existing host.startTransition; restores it on disconnect', () => {
238
+ const host = mountHost();
239
+ const sentinel = () => 'pre-existing';
240
+ host.startTransition = sentinel;
241
+ const inst = connectTrait(viewTransition, host);
242
+ expect(host.startTransition).not.toBe(sentinel); // trait took over
243
+ inst.disconnect(host);
244
+ expect(host.startTransition).toBe(sentinel); // restored
245
+ });
246
+
247
+ it('connect → disconnect → connect-again does not throw', () => {
248
+ const host = mountHost('div', { 'data-view-transition-name': 'a' });
249
+ const inst1 = connectTrait(viewTransition, host);
250
+ inst1.disconnect(host);
251
+ expect(() => {
252
+ const inst2 = connectTrait(viewTransition, host);
253
+ inst2.disconnect(host);
254
+ }).not.toThrow();
255
+ });
256
+
257
+ it('two parallel hosts each get their own startTransition', () => {
258
+ const a = mountHost();
259
+ const b = mountHost();
260
+ const instA = connectTrait(viewTransition, a);
261
+ const instB = connectTrait(viewTransition, b);
262
+ expect(typeof a.startTransition).toBe('function');
263
+ expect(typeof b.startTransition).toBe('function');
264
+ expect(a.startTransition).not.toBe(b.startTransition);
265
+ instA.disconnect(a);
266
+ instB.disconnect(b);
267
+ });
268
+ });
File without changes
File without changes