@sc4rfurryx/proteusjs 1.0.0 → 1.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.
Files changed (65) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +331 -77
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/adapters/react.d.ts +139 -0
  5. package/dist/adapters/react.esm.js +848 -0
  6. package/dist/adapters/react.esm.js.map +1 -0
  7. package/dist/adapters/svelte.d.ts +181 -0
  8. package/dist/adapters/svelte.esm.js +908 -0
  9. package/dist/adapters/svelte.esm.js.map +1 -0
  10. package/dist/adapters/vue.d.ts +205 -0
  11. package/dist/adapters/vue.esm.js +872 -0
  12. package/dist/adapters/vue.esm.js.map +1 -0
  13. package/dist/modules/a11y-audit.d.ts +39 -0
  14. package/dist/modules/a11y-audit.esm.js +509 -0
  15. package/dist/modules/a11y-audit.esm.js.map +1 -0
  16. package/dist/modules/a11y-primitives.d.ts +69 -0
  17. package/dist/modules/a11y-primitives.esm.js +445 -0
  18. package/dist/modules/a11y-primitives.esm.js.map +1 -0
  19. package/dist/modules/anchor.d.ts +29 -0
  20. package/dist/modules/anchor.esm.js +218 -0
  21. package/dist/modules/anchor.esm.js.map +1 -0
  22. package/dist/modules/container.d.ts +60 -0
  23. package/dist/modules/container.esm.js +194 -0
  24. package/dist/modules/container.esm.js.map +1 -0
  25. package/dist/modules/perf.d.ts +82 -0
  26. package/dist/modules/perf.esm.js +257 -0
  27. package/dist/modules/perf.esm.js.map +1 -0
  28. package/dist/modules/popover.d.ts +33 -0
  29. package/dist/modules/popover.esm.js +191 -0
  30. package/dist/modules/popover.esm.js.map +1 -0
  31. package/dist/modules/scroll.d.ts +43 -0
  32. package/dist/modules/scroll.esm.js +195 -0
  33. package/dist/modules/scroll.esm.js.map +1 -0
  34. package/dist/modules/transitions.d.ts +35 -0
  35. package/dist/modules/transitions.esm.js +120 -0
  36. package/dist/modules/transitions.esm.js.map +1 -0
  37. package/dist/modules/typography.d.ts +72 -0
  38. package/dist/modules/typography.esm.js +168 -0
  39. package/dist/modules/typography.esm.js.map +1 -0
  40. package/dist/proteus.cjs.js +2332 -12
  41. package/dist/proteus.cjs.js.map +1 -1
  42. package/dist/proteus.d.ts +561 -12
  43. package/dist/proteus.esm.js +2323 -12
  44. package/dist/proteus.esm.js.map +1 -1
  45. package/dist/proteus.esm.min.js +3 -3
  46. package/dist/proteus.esm.min.js.map +1 -1
  47. package/dist/proteus.js +2332 -12
  48. package/dist/proteus.js.map +1 -1
  49. package/dist/proteus.min.js +3 -3
  50. package/dist/proteus.min.js.map +1 -1
  51. package/package.json +61 -4
  52. package/src/adapters/react.ts +264 -0
  53. package/src/adapters/svelte.ts +321 -0
  54. package/src/adapters/vue.ts +268 -0
  55. package/src/index.ts +33 -6
  56. package/src/modules/a11y-audit/index.ts +608 -0
  57. package/src/modules/a11y-primitives/index.ts +554 -0
  58. package/src/modules/anchor/index.ts +257 -0
  59. package/src/modules/container/index.ts +230 -0
  60. package/src/modules/perf/index.ts +291 -0
  61. package/src/modules/popover/index.ts +238 -0
  62. package/src/modules/scroll/index.ts +251 -0
  63. package/src/modules/transitions/index.ts +145 -0
  64. package/src/modules/typography/index.ts +239 -0
  65. package/src/utils/version.ts +1 -1
@@ -0,0 +1,908 @@
1
+ /*!
2
+ * ProteusJS v1.1.0
3
+ * Shape-shifting responsive design that adapts like the sea god himself
4
+ * (c) 2025 sc4rfurry
5
+ * Released under the MIT License
6
+ */
7
+ import { writable } from 'svelte/store';
8
+
9
+ /**
10
+ * @sc4rfurryx/proteusjs/transitions
11
+ * View Transitions API wrapper with safe fallbacks
12
+ *
13
+ * @version 1.1.0
14
+ * @author sc4rfurry
15
+ * @license MIT
16
+ */
17
+ /**
18
+ * One API for animating DOM state changes and cross-document navigations
19
+ * using the View Transitions API with safe fallbacks.
20
+ */
21
+ async function transition(run, opts = {}) {
22
+ const { name, duration = 300, onBefore, onAfter, allowInterrupt = true } = opts;
23
+ // Check for View Transitions API support
24
+ const hasViewTransitions = 'startViewTransition' in document;
25
+ if (onBefore) {
26
+ onBefore();
27
+ }
28
+ if (!hasViewTransitions) {
29
+ // Fallback: run immediately without transitions
30
+ try {
31
+ await run();
32
+ }
33
+ finally {
34
+ if (onAfter) {
35
+ onAfter();
36
+ }
37
+ }
38
+ return;
39
+ }
40
+ // Use native View Transitions API
41
+ try {
42
+ const viewTransition = document.startViewTransition(async () => {
43
+ await run();
44
+ });
45
+ // Add CSS view-transition-name if name provided
46
+ if (name) {
47
+ const style = document.createElement('style');
48
+ style.textContent = `
49
+ ::view-transition-old(${name}),
50
+ ::view-transition-new(${name}) {
51
+ animation-duration: ${duration}ms;
52
+ }
53
+ `;
54
+ document.head.appendChild(style);
55
+ // Clean up style after transition
56
+ viewTransition.finished.finally(() => {
57
+ style.remove();
58
+ });
59
+ }
60
+ await viewTransition.finished;
61
+ }
62
+ catch (error) {
63
+ console.warn('View transition failed, falling back to immediate execution:', error);
64
+ await run();
65
+ }
66
+ finally {
67
+ if (onAfter) {
68
+ onAfter();
69
+ }
70
+ }
71
+ }
72
+
73
+ /**
74
+ * @sc4rfurryx/proteusjs/scroll
75
+ * Scroll-driven animations with CSS Scroll-Linked Animations
76
+ *
77
+ * @version 1.1.0
78
+ * @author sc4rfurry
79
+ * @license MIT
80
+ */
81
+ /**
82
+ * Zero-boilerplate setup for CSS Scroll-Linked Animations with fallbacks
83
+ */
84
+ function scrollAnimate(target, opts) {
85
+ const targetEl = typeof target === 'string' ? document.querySelector(target) : target;
86
+ if (!targetEl) {
87
+ throw new Error('Target element not found');
88
+ }
89
+ const { keyframes, range = ['0%', '100%'], timeline = {}, fallback = 'io' } = opts;
90
+ const { axis = 'block', start = '0%', end = '100%' } = timeline;
91
+ // Check for CSS Scroll-Linked Animations support
92
+ const hasScrollTimeline = 'CSS' in window && CSS.supports('animation-timeline', 'scroll()');
93
+ // Check for reduced motion preference
94
+ const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
95
+ if (prefersReducedMotion) {
96
+ // Respect user preference - either disable or reduce animation
97
+ if (fallback === false)
98
+ return;
99
+ // Apply only the end state for reduced motion
100
+ const endKeyframe = keyframes[keyframes.length - 1];
101
+ Object.assign(targetEl.style, endKeyframe);
102
+ return;
103
+ }
104
+ if (hasScrollTimeline) {
105
+ // Use native CSS Scroll-Linked Animations
106
+ const timelineName = `scroll-timeline-${Math.random().toString(36).substr(2, 9)}`;
107
+ // Create scroll timeline
108
+ const style = document.createElement('style');
109
+ style.textContent = `
110
+ @scroll-timeline ${timelineName} {
111
+ source: nearest;
112
+ orientation: ${axis};
113
+ scroll-offsets: ${start}, ${end};
114
+ }
115
+
116
+ .scroll-animate-${timelineName} {
117
+ animation-timeline: ${timelineName};
118
+ animation-duration: 1ms; /* Required but ignored */
119
+ animation-fill-mode: both;
120
+ }
121
+ `;
122
+ document.head.appendChild(style);
123
+ // Apply animation class
124
+ targetEl.classList.add(`scroll-animate-${timelineName}`);
125
+ // Create Web Animations API animation
126
+ const animation = targetEl.animate(keyframes, {
127
+ duration: 1, // Required but ignored with scroll timeline
128
+ fill: 'both'
129
+ });
130
+ // Set scroll timeline (when supported)
131
+ if ('timeline' in animation) {
132
+ animation.timeline = new window.ScrollTimeline({
133
+ source: document.scrollingElement,
134
+ orientation: axis,
135
+ scrollOffsets: [
136
+ { target: targetEl, edge: 'start', threshold: parseFloat(start) / 100 },
137
+ { target: targetEl, edge: 'end', threshold: parseFloat(end) / 100 }
138
+ ]
139
+ });
140
+ }
141
+ }
142
+ else if (fallback === 'io') {
143
+ // Fallback using Intersection Observer
144
+ let animation = null;
145
+ const observer = new IntersectionObserver((entries) => {
146
+ entries.forEach(entry => {
147
+ const progress = Math.max(0, Math.min(1, entry.intersectionRatio));
148
+ if (!animation) {
149
+ animation = targetEl.animate(keyframes, {
150
+ duration: 1000,
151
+ fill: 'both'
152
+ });
153
+ animation.pause();
154
+ }
155
+ // Update animation progress based on intersection
156
+ animation.currentTime = progress * 1000;
157
+ });
158
+ }, {
159
+ threshold: Array.from({ length: 101 }, (_, i) => i / 100) // 0 to 1 in 0.01 steps
160
+ });
161
+ observer.observe(targetEl);
162
+ // Store cleanup function
163
+ targetEl._scrollAnimateCleanup = () => {
164
+ observer.disconnect();
165
+ if (animation) {
166
+ animation.cancel();
167
+ }
168
+ };
169
+ }
170
+ }
171
+
172
+ /**
173
+ * @sc4rfurryx/proteusjs/popover
174
+ * HTML Popover API wrapper with robust focus/inert handling
175
+ *
176
+ * @version 1.1.0
177
+ * @author sc4rfurry
178
+ * @license MIT
179
+ */
180
+ /**
181
+ * Unified API for menus, tooltips, and dialogs using the native Popover API
182
+ * with robust focus/inert handling
183
+ */
184
+ function attach(trigger, panel, opts = {}) {
185
+ const triggerEl = typeof trigger === 'string' ? document.querySelector(trigger) : trigger;
186
+ const panelEl = typeof panel === 'string' ? document.querySelector(panel) : panel;
187
+ if (!triggerEl || !panelEl) {
188
+ throw new Error('Both trigger and panel elements must exist');
189
+ }
190
+ const { type = 'menu', trapFocus = type === 'dialog', restoreFocus = true, closeOnEscape = true, onOpen, onClose } = opts;
191
+ let isOpen = false;
192
+ let previousFocus = null;
193
+ let focusTrap = null;
194
+ // Check for native Popover API support
195
+ const hasPopoverAPI = 'popover' in HTMLElement.prototype;
196
+ // Set up ARIA attributes
197
+ const setupAria = () => {
198
+ const panelId = panelEl.id || `popover-${Math.random().toString(36).substr(2, 9)}`;
199
+ panelEl.id = panelId;
200
+ triggerEl.setAttribute('aria-expanded', 'false');
201
+ triggerEl.setAttribute('aria-controls', panelId);
202
+ if (type === 'menu') {
203
+ triggerEl.setAttribute('aria-haspopup', 'menu');
204
+ panelEl.setAttribute('role', 'menu');
205
+ }
206
+ else if (type === 'dialog') {
207
+ triggerEl.setAttribute('aria-haspopup', 'dialog');
208
+ panelEl.setAttribute('role', 'dialog');
209
+ panelEl.setAttribute('aria-modal', 'true');
210
+ }
211
+ else if (type === 'tooltip') {
212
+ triggerEl.setAttribute('aria-describedby', panelId);
213
+ panelEl.setAttribute('role', 'tooltip');
214
+ }
215
+ };
216
+ // Set up native popover if supported
217
+ const setupNativePopover = () => {
218
+ if (hasPopoverAPI) {
219
+ panelEl.popover = type === 'dialog' ? 'manual' : 'auto';
220
+ triggerEl.setAttribute('popovertarget', panelEl.id);
221
+ }
222
+ };
223
+ // Focus trap implementation
224
+ class FocusTrap {
225
+ constructor(container) {
226
+ this.container = container;
227
+ this.focusableElements = [];
228
+ this.handleKeyDown = (e) => {
229
+ if (e.key !== 'Tab')
230
+ return;
231
+ const firstElement = this.focusableElements[0];
232
+ const lastElement = this.focusableElements[this.focusableElements.length - 1];
233
+ if (e.shiftKey) {
234
+ if (document.activeElement === firstElement) {
235
+ e.preventDefault();
236
+ lastElement.focus();
237
+ }
238
+ }
239
+ else {
240
+ if (document.activeElement === lastElement) {
241
+ e.preventDefault();
242
+ firstElement.focus();
243
+ }
244
+ }
245
+ };
246
+ this.updateFocusableElements();
247
+ }
248
+ updateFocusableElements() {
249
+ const selector = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
250
+ this.focusableElements = Array.from(this.container.querySelectorAll(selector));
251
+ }
252
+ activate() {
253
+ this.updateFocusableElements();
254
+ if (this.focusableElements.length > 0) {
255
+ this.focusableElements[0].focus();
256
+ }
257
+ document.addEventListener('keydown', this.handleKeyDown);
258
+ }
259
+ deactivate() {
260
+ document.removeEventListener('keydown', this.handleKeyDown);
261
+ }
262
+ }
263
+ const open = () => {
264
+ if (isOpen)
265
+ return;
266
+ if (restoreFocus) {
267
+ previousFocus = document.activeElement;
268
+ }
269
+ if (hasPopoverAPI) {
270
+ panelEl.showPopover();
271
+ }
272
+ else {
273
+ panelEl.style.display = 'block';
274
+ panelEl.setAttribute('data-popover-open', 'true');
275
+ }
276
+ triggerEl.setAttribute('aria-expanded', 'true');
277
+ isOpen = true;
278
+ if (trapFocus) {
279
+ focusTrap = new FocusTrap(panelEl);
280
+ focusTrap.activate();
281
+ }
282
+ if (onOpen) {
283
+ onOpen();
284
+ }
285
+ };
286
+ const close = () => {
287
+ if (!isOpen)
288
+ return;
289
+ if (hasPopoverAPI) {
290
+ panelEl.hidePopover();
291
+ }
292
+ else {
293
+ panelEl.style.display = 'none';
294
+ panelEl.removeAttribute('data-popover-open');
295
+ }
296
+ triggerEl.setAttribute('aria-expanded', 'false');
297
+ isOpen = false;
298
+ if (focusTrap) {
299
+ focusTrap.deactivate();
300
+ focusTrap = null;
301
+ }
302
+ if (restoreFocus && previousFocus) {
303
+ previousFocus.focus();
304
+ previousFocus = null;
305
+ }
306
+ if (onClose) {
307
+ onClose();
308
+ }
309
+ };
310
+ const toggle = () => {
311
+ if (isOpen) {
312
+ close();
313
+ }
314
+ else {
315
+ open();
316
+ }
317
+ };
318
+ const handleKeyDown = (e) => {
319
+ if (closeOnEscape && e.key === 'Escape' && isOpen) {
320
+ e.preventDefault();
321
+ close();
322
+ }
323
+ };
324
+ const handleClick = (e) => {
325
+ e.preventDefault();
326
+ toggle();
327
+ };
328
+ const destroy = () => {
329
+ triggerEl.removeEventListener('click', handleClick);
330
+ document.removeEventListener('keydown', handleKeyDown);
331
+ if (focusTrap) {
332
+ focusTrap.deactivate();
333
+ }
334
+ if (isOpen) {
335
+ close();
336
+ }
337
+ };
338
+ // Initialize
339
+ setupAria();
340
+ setupNativePopover();
341
+ triggerEl.addEventListener('click', handleClick);
342
+ document.addEventListener('keydown', handleKeyDown);
343
+ return {
344
+ open,
345
+ close,
346
+ toggle,
347
+ destroy
348
+ };
349
+ }
350
+
351
+ /**
352
+ * @sc4rfurryx/proteusjs/anchor
353
+ * CSS Anchor Positioning utilities with robust JS fallback
354
+ *
355
+ * @version 1.1.0
356
+ * @author sc4rfurry
357
+ * @license MIT
358
+ */
359
+ /**
360
+ * Declarative tethers (tooltips, callouts) via CSS Anchor Positioning when available;
361
+ * robust JS fallback with flip/collision detection
362
+ */
363
+ function tether(floating, opts) {
364
+ const floatingEl = typeof floating === 'string' ? document.querySelector(floating) : floating;
365
+ const anchorEl = typeof opts.anchor === 'string' ? document.querySelector(opts.anchor) : opts.anchor;
366
+ if (!floatingEl || !anchorEl) {
367
+ throw new Error('Both floating and anchor elements must exist');
368
+ }
369
+ const { placement = 'bottom', align = 'center', offset = 8, strategy = 'absolute' } = opts;
370
+ // Check for CSS Anchor Positioning support
371
+ const hasAnchorPositioning = CSS.supports('anchor-name', 'test');
372
+ let isDestroyed = false;
373
+ let resizeObserver = null;
374
+ const setupCSSAnchorPositioning = () => {
375
+ if (!hasAnchorPositioning)
376
+ return false;
377
+ // Generate unique anchor name
378
+ const anchorName = `anchor-${Math.random().toString(36).substring(2, 11)}`;
379
+ // Set anchor name on anchor element
380
+ anchorEl.style.setProperty('anchor-name', anchorName);
381
+ // Position floating element using CSS anchor positioning
382
+ const floatingStyle = floatingEl;
383
+ floatingStyle.style.position = strategy;
384
+ floatingStyle.style.setProperty('position-anchor', anchorName);
385
+ // Set position based on placement
386
+ switch (placement) {
387
+ case 'top':
388
+ floatingStyle.style.bottom = `anchor(bottom, ${offset}px)`;
389
+ break;
390
+ case 'bottom':
391
+ floatingStyle.style.top = `anchor(bottom, ${offset}px)`;
392
+ break;
393
+ case 'left':
394
+ floatingStyle.style.right = `anchor(left, ${offset}px)`;
395
+ break;
396
+ case 'right':
397
+ floatingStyle.style.left = `anchor(right, ${offset}px)`;
398
+ break;
399
+ }
400
+ // Set alignment
401
+ if (placement === 'top' || placement === 'bottom') {
402
+ switch (align) {
403
+ case 'start':
404
+ floatingStyle.style.left = 'anchor(left)';
405
+ break;
406
+ case 'center':
407
+ floatingStyle.style.left = 'anchor(center)';
408
+ floatingStyle.style.transform = 'translateX(-50%)';
409
+ break;
410
+ case 'end':
411
+ floatingStyle.style.right = 'anchor(right)';
412
+ break;
413
+ }
414
+ }
415
+ else {
416
+ switch (align) {
417
+ case 'start':
418
+ floatingStyle.style.top = 'anchor(top)';
419
+ break;
420
+ case 'center':
421
+ floatingStyle.style.top = 'anchor(center)';
422
+ floatingStyle.style.transform = 'translateY(-50%)';
423
+ break;
424
+ case 'end':
425
+ floatingStyle.style.bottom = 'anchor(bottom)';
426
+ break;
427
+ }
428
+ }
429
+ return true;
430
+ };
431
+ const calculatePosition = () => {
432
+ const anchorRect = anchorEl.getBoundingClientRect();
433
+ const floatingRect = floatingEl.getBoundingClientRect();
434
+ const viewport = {
435
+ width: window.innerWidth,
436
+ height: window.innerHeight
437
+ };
438
+ let finalPlacement = placement;
439
+ let x = 0;
440
+ let y = 0;
441
+ // Calculate base position
442
+ switch (finalPlacement) {
443
+ case 'top':
444
+ x = anchorRect.left;
445
+ y = anchorRect.top - floatingRect.height - offset;
446
+ break;
447
+ case 'bottom':
448
+ x = anchorRect.left;
449
+ y = anchorRect.bottom + offset;
450
+ break;
451
+ case 'left':
452
+ x = anchorRect.left - floatingRect.width - offset;
453
+ y = anchorRect.top;
454
+ break;
455
+ case 'right':
456
+ x = anchorRect.right + offset;
457
+ y = anchorRect.top;
458
+ break;
459
+ case 'auto': {
460
+ // Choose best placement based on available space
461
+ const spaces = {
462
+ top: anchorRect.top,
463
+ bottom: viewport.height - anchorRect.bottom,
464
+ left: anchorRect.left,
465
+ right: viewport.width - anchorRect.right
466
+ };
467
+ const bestPlacement = Object.entries(spaces).reduce((a, b) => spaces[a[0]] > spaces[b[0]] ? a : b)[0];
468
+ finalPlacement = bestPlacement;
469
+ return calculatePosition(); // Recursive call with determined placement
470
+ }
471
+ }
472
+ // Apply alignment
473
+ if (finalPlacement === 'top' || finalPlacement === 'bottom') {
474
+ switch (align) {
475
+ case 'start':
476
+ // x already set correctly
477
+ break;
478
+ case 'center':
479
+ x = anchorRect.left + (anchorRect.width - floatingRect.width) / 2;
480
+ break;
481
+ case 'end':
482
+ x = anchorRect.right - floatingRect.width;
483
+ break;
484
+ }
485
+ }
486
+ else {
487
+ switch (align) {
488
+ case 'start':
489
+ // y already set correctly
490
+ break;
491
+ case 'center':
492
+ y = anchorRect.top + (anchorRect.height - floatingRect.height) / 2;
493
+ break;
494
+ case 'end':
495
+ y = anchorRect.bottom - floatingRect.height;
496
+ break;
497
+ }
498
+ }
499
+ // Collision detection and adjustment
500
+ if (x < 0)
501
+ x = 8;
502
+ if (y < 0)
503
+ y = 8;
504
+ if (x + floatingRect.width > viewport.width) {
505
+ x = viewport.width - floatingRect.width - 8;
506
+ }
507
+ if (y + floatingRect.height > viewport.height) {
508
+ y = viewport.height - floatingRect.height - 8;
509
+ }
510
+ return { x, y };
511
+ };
512
+ const updatePosition = () => {
513
+ if (isDestroyed)
514
+ return;
515
+ if (!hasAnchorPositioning) {
516
+ const { x, y } = calculatePosition();
517
+ const floatingStyle = floatingEl;
518
+ floatingStyle.style.position = strategy;
519
+ floatingStyle.style.left = `${x}px`;
520
+ floatingStyle.style.top = `${y}px`;
521
+ }
522
+ };
523
+ const setupJSFallback = () => {
524
+ updatePosition();
525
+ // Set up observers for position updates
526
+ resizeObserver = new ResizeObserver(updatePosition);
527
+ resizeObserver.observe(anchorEl);
528
+ resizeObserver.observe(floatingEl);
529
+ window.addEventListener('scroll', updatePosition, { passive: true });
530
+ window.addEventListener('resize', updatePosition, { passive: true });
531
+ };
532
+ const destroy = () => {
533
+ isDestroyed = true;
534
+ if (resizeObserver) {
535
+ resizeObserver.disconnect();
536
+ resizeObserver = null;
537
+ }
538
+ window.removeEventListener('scroll', updatePosition);
539
+ window.removeEventListener('resize', updatePosition);
540
+ // Clean up CSS anchor positioning
541
+ if (hasAnchorPositioning) {
542
+ anchorEl.style.removeProperty('anchor-name');
543
+ const floatingStyle = floatingEl;
544
+ floatingStyle.style.removeProperty('position-anchor');
545
+ floatingStyle.style.position = '';
546
+ }
547
+ };
548
+ // Initialize
549
+ if (!setupCSSAnchorPositioning()) {
550
+ setupJSFallback();
551
+ }
552
+ return {
553
+ destroy
554
+ };
555
+ }
556
+
557
+ /**
558
+ * @sc4rfurryx/proteusjs/container
559
+ * Container/Style Query helpers with visualization devtools
560
+ *
561
+ * @version 1.1.0
562
+ * @author sc4rfurry
563
+ * @license MIT
564
+ */
565
+ /**
566
+ * Sugar on native container queries with dev visualization
567
+ */
568
+ function defineContainer(target, name, opts = {}) {
569
+ const targetEl = typeof target === 'string' ? document.querySelector(target) : target;
570
+ if (!targetEl) {
571
+ throw new Error('Target element not found');
572
+ }
573
+ const { type = 'size', inlineSize: _inlineSize = true } = opts;
574
+ const containerName = name || `container-${Math.random().toString(36).substring(2, 11)}`;
575
+ // Apply container properties
576
+ const element = targetEl;
577
+ element.style.containerName = containerName;
578
+ element.style.containerType = type;
579
+ // Warn if containment settings are missing
580
+ const computedStyle = getComputedStyle(element);
581
+ if (!computedStyle.contain || computedStyle.contain === 'none') {
582
+ console.warn(`Container "${containerName}" may need explicit containment settings for optimal performance`);
583
+ }
584
+ // Dev overlay (only in development)
585
+ if (process.env['NODE_ENV'] === 'development' || window.__PROTEUS_DEV__) {
586
+ createDevOverlay(element, containerName);
587
+ }
588
+ }
589
+ /**
590
+ * Create development overlay showing container bounds and breakpoints
591
+ */
592
+ function createDevOverlay(element, name) {
593
+ const overlay = document.createElement('div');
594
+ overlay.className = 'proteus-container-overlay';
595
+ overlay.style.cssText = `
596
+ position: absolute;
597
+ top: 0;
598
+ left: 0;
599
+ right: 0;
600
+ bottom: 0;
601
+ pointer-events: none;
602
+ border: 2px dashed rgba(255, 0, 255, 0.5);
603
+ background: rgba(255, 0, 255, 0.05);
604
+ z-index: 9999;
605
+ font-family: monospace;
606
+ font-size: 12px;
607
+ color: #ff00ff;
608
+ `;
609
+ const label = document.createElement('div');
610
+ label.style.cssText = `
611
+ position: absolute;
612
+ top: -20px;
613
+ left: 0;
614
+ background: rgba(255, 0, 255, 0.9);
615
+ color: white;
616
+ padding: 2px 6px;
617
+ border-radius: 3px;
618
+ font-size: 10px;
619
+ white-space: nowrap;
620
+ `;
621
+ label.textContent = `Container: ${name}`;
622
+ const sizeInfo = document.createElement('div');
623
+ sizeInfo.style.cssText = `
624
+ position: absolute;
625
+ bottom: 2px;
626
+ right: 2px;
627
+ background: rgba(0, 0, 0, 0.7);
628
+ color: white;
629
+ padding: 2px 4px;
630
+ border-radius: 2px;
631
+ font-size: 10px;
632
+ `;
633
+ overlay.appendChild(label);
634
+ overlay.appendChild(sizeInfo);
635
+ // Position overlay relative to container
636
+ if (getComputedStyle(element).position === 'static') {
637
+ element.style.position = 'relative';
638
+ }
639
+ element.appendChild(overlay);
640
+ // Update size info
641
+ const updateSizeInfo = () => {
642
+ const rect = element.getBoundingClientRect();
643
+ sizeInfo.textContent = `${Math.round(rect.width)}×${Math.round(rect.height)}`;
644
+ };
645
+ updateSizeInfo();
646
+ // Update on resize
647
+ if ('ResizeObserver' in window) {
648
+ const resizeObserver = new ResizeObserver(updateSizeInfo);
649
+ resizeObserver.observe(element);
650
+ }
651
+ // Store cleanup function
652
+ element._proteusContainerCleanup = () => {
653
+ overlay.remove();
654
+ };
655
+ }
656
+
657
+ /**
658
+ * @sc4rfurryx/proteusjs/adapters/svelte
659
+ * Svelte actions and stores for ProteusJS
660
+ *
661
+ * @version 1.1.0
662
+ * @author sc4rfurry
663
+ * @license MIT
664
+ */
665
+ /**
666
+ * Svelte action for scroll animations
667
+ */
668
+ function proteusScroll(node, options) {
669
+ scrollAnimate(node, options);
670
+ return {
671
+ update(newOptions) {
672
+ // Re-apply with new options
673
+ scrollAnimate(node, newOptions);
674
+ },
675
+ destroy() {
676
+ // Cleanup handled by scroll module
677
+ }
678
+ };
679
+ }
680
+ /**
681
+ * Svelte action for container queries
682
+ */
683
+ function proteusContainer(node, options = {}) {
684
+ const { name, containerOptions } = options;
685
+ defineContainer(node, name, containerOptions);
686
+ return {
687
+ update(newOptions) {
688
+ const { name: newName, containerOptions: newContainerOptions } = newOptions;
689
+ defineContainer(node, newName, newContainerOptions);
690
+ }
691
+ };
692
+ }
693
+ /**
694
+ * Svelte action for popover functionality
695
+ */
696
+ function proteusPopover(node, options) {
697
+ let controller = null;
698
+ const { panel, popoverOptions } = options;
699
+ controller = attach(node, panel, popoverOptions);
700
+ return {
701
+ update(newOptions) {
702
+ if (controller) {
703
+ controller.destroy();
704
+ }
705
+ controller = attach(node, newOptions.panel, newOptions.popoverOptions);
706
+ },
707
+ destroy() {
708
+ if (controller) {
709
+ controller.destroy();
710
+ }
711
+ }
712
+ };
713
+ }
714
+ /**
715
+ * Svelte action for anchor positioning
716
+ */
717
+ function proteusAnchor(node, options) {
718
+ let controller = null;
719
+ controller = tether(node, options);
720
+ return {
721
+ update(newOptions) {
722
+ if (controller) {
723
+ controller.destroy();
724
+ }
725
+ controller = tether(node, newOptions);
726
+ },
727
+ destroy() {
728
+ if (controller) {
729
+ controller.destroy();
730
+ }
731
+ }
732
+ };
733
+ }
734
+ /**
735
+ * Svelte action for performance optimizations
736
+ */
737
+ function proteusPerf(node) {
738
+ const observer = new IntersectionObserver((entries) => {
739
+ entries.forEach(entry => {
740
+ if (entry.isIntersecting) {
741
+ node.style.contentVisibility = 'visible';
742
+ }
743
+ else {
744
+ node.style.contentVisibility = 'auto';
745
+ }
746
+ });
747
+ }, { rootMargin: '50px' });
748
+ observer.observe(node);
749
+ return {
750
+ destroy() {
751
+ observer.disconnect();
752
+ }
753
+ };
754
+ }
755
+ /**
756
+ * Svelte action for accessibility enhancements
757
+ */
758
+ function proteusA11y(node, options = {}) {
759
+ const { announceChanges = false } = options;
760
+ // Enhance focus indicators
761
+ const focusableElements = node.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
762
+ const focusHandlers = new Map();
763
+ focusableElements.forEach(element => {
764
+ const htmlEl = element;
765
+ const focusHandler = () => {
766
+ htmlEl.style.outline = '2px solid #0066cc';
767
+ htmlEl.style.outlineOffset = '2px';
768
+ };
769
+ const blurHandler = () => {
770
+ htmlEl.style.outline = 'none';
771
+ };
772
+ htmlEl.addEventListener('focus', focusHandler);
773
+ htmlEl.addEventListener('blur', blurHandler);
774
+ focusHandlers.set(htmlEl, { focusHandler, blurHandler });
775
+ });
776
+ let mutationObserver = null;
777
+ if (announceChanges) {
778
+ mutationObserver = new MutationObserver(() => {
779
+ const announcement = document.createElement('div');
780
+ announcement.setAttribute('aria-live', 'polite');
781
+ announcement.style.position = 'absolute';
782
+ announcement.style.left = '-10000px';
783
+ announcement.textContent = 'Content updated';
784
+ document.body.appendChild(announcement);
785
+ setTimeout(() => {
786
+ document.body.removeChild(announcement);
787
+ }, 1000);
788
+ });
789
+ mutationObserver.observe(node, { childList: true, subtree: true });
790
+ }
791
+ return {
792
+ destroy() {
793
+ // Clean up focus handlers
794
+ focusHandlers.forEach(({ focusHandler, blurHandler }, element) => {
795
+ element.removeEventListener('focus', focusHandler);
796
+ element.removeEventListener('blur', blurHandler);
797
+ });
798
+ if (mutationObserver) {
799
+ mutationObserver.disconnect();
800
+ }
801
+ }
802
+ };
803
+ }
804
+ /**
805
+ * Store for managing popover state
806
+ */
807
+ function createPopover(triggerSelector, panelSelector, options) {
808
+ const isOpen = writable(false);
809
+ let controller = null;
810
+ const initialize = () => {
811
+ const trigger = document.querySelector(triggerSelector);
812
+ const panel = document.querySelector(panelSelector);
813
+ if (trigger && panel) {
814
+ controller = attach(trigger, panel, {
815
+ ...options,
816
+ onOpen: () => {
817
+ isOpen.set(true);
818
+ options?.onOpen?.();
819
+ },
820
+ onClose: () => {
821
+ isOpen.set(false);
822
+ options?.onClose?.();
823
+ }
824
+ });
825
+ }
826
+ };
827
+ const open = () => controller?.open();
828
+ const close = () => controller?.close();
829
+ const toggle = () => controller?.toggle();
830
+ const destroy = () => {
831
+ if (controller) {
832
+ controller.destroy();
833
+ controller = null;
834
+ }
835
+ };
836
+ return {
837
+ isOpen,
838
+ initialize,
839
+ open,
840
+ close,
841
+ toggle,
842
+ destroy
843
+ };
844
+ }
845
+ /**
846
+ * Store for managing transition state
847
+ */
848
+ function createTransition() {
849
+ const isTransitioning = writable(false);
850
+ const runTransition = async (run, opts) => {
851
+ isTransitioning.set(true);
852
+ try {
853
+ await transition(run, opts);
854
+ }
855
+ finally {
856
+ isTransitioning.set(false);
857
+ }
858
+ };
859
+ return {
860
+ isTransitioning,
861
+ runTransition
862
+ };
863
+ }
864
+ /**
865
+ * Utility function to create reactive container size store
866
+ */
867
+ function createContainerSize(element) {
868
+ const size = writable({ width: 0, height: 0 });
869
+ if ('ResizeObserver' in window) {
870
+ const resizeObserver = new ResizeObserver((entries) => {
871
+ for (const entry of entries) {
872
+ const { width, height } = entry.contentRect;
873
+ size.set({ width, height });
874
+ }
875
+ });
876
+ resizeObserver.observe(element);
877
+ return {
878
+ size,
879
+ destroy: () => resizeObserver.disconnect()
880
+ };
881
+ }
882
+ // Fallback for browsers without ResizeObserver
883
+ const updateSize = () => {
884
+ const rect = element.getBoundingClientRect();
885
+ size.set({ width: rect.width, height: rect.height });
886
+ };
887
+ updateSize();
888
+ window.addEventListener('resize', updateSize);
889
+ return {
890
+ size,
891
+ destroy: () => window.removeEventListener('resize', updateSize)
892
+ };
893
+ }
894
+ // Export all actions and utilities
895
+ var svelte = {
896
+ proteusScroll,
897
+ proteusContainer,
898
+ proteusPopover,
899
+ proteusAnchor,
900
+ proteusPerf,
901
+ proteusA11y,
902
+ createPopover,
903
+ createTransition,
904
+ createContainerSize
905
+ };
906
+
907
+ export { createContainerSize, createPopover, createTransition, svelte as default, proteusA11y, proteusAnchor, proteusContainer, proteusPerf, proteusPopover, proteusScroll };
908
+ //# sourceMappingURL=svelte.esm.js.map