@sc4rfurryx/proteusjs 1.0.0 → 1.1.1

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 +140 -0
  5. package/dist/adapters/react.esm.js +849 -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 +909 -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 +873 -0
  12. package/dist/adapters/vue.esm.js.map +1 -0
  13. package/dist/modules/a11y-audit.d.ts +31 -0
  14. package/dist/modules/a11y-audit.esm.js +64 -0
  15. package/dist/modules/a11y-audit.esm.js.map +1 -0
  16. package/dist/modules/a11y-primitives.d.ts +36 -0
  17. package/dist/modules/a11y-primitives.esm.js +114 -0
  18. package/dist/modules/a11y-primitives.esm.js.map +1 -0
  19. package/dist/modules/anchor.d.ts +30 -0
  20. package/dist/modules/anchor.esm.js +219 -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 +1554 -12
  41. package/dist/proteus.cjs.js.map +1 -1
  42. package/dist/proteus.d.ts +516 -12
  43. package/dist/proteus.esm.js +1545 -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 +1554 -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 +69 -7
  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 +84 -0
  57. package/src/modules/a11y-primitives/index.ts +152 -0
  58. package/src/modules/anchor/index.ts +259 -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,849 @@
1
+ /*!
2
+ * ProteusJS v1.1.1
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 { useCallback, useEffect, useRef, createElement } from 'react';
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
+ update: updatePosition,
554
+ destroy
555
+ };
556
+ }
557
+
558
+ /**
559
+ * @sc4rfurryx/proteusjs/container
560
+ * Container/Style Query helpers with visualization devtools
561
+ *
562
+ * @version 1.1.0
563
+ * @author sc4rfurry
564
+ * @license MIT
565
+ */
566
+ /**
567
+ * Sugar on native container queries with dev visualization
568
+ */
569
+ function defineContainer(target, name, opts = {}) {
570
+ const targetEl = typeof target === 'string' ? document.querySelector(target) : target;
571
+ if (!targetEl) {
572
+ throw new Error('Target element not found');
573
+ }
574
+ const { type = 'size', inlineSize: _inlineSize = true } = opts;
575
+ const containerName = name || `container-${Math.random().toString(36).substring(2, 11)}`;
576
+ // Apply container properties
577
+ const element = targetEl;
578
+ element.style.containerName = containerName;
579
+ element.style.containerType = type;
580
+ // Warn if containment settings are missing
581
+ const computedStyle = getComputedStyle(element);
582
+ if (!computedStyle.contain || computedStyle.contain === 'none') {
583
+ console.warn(`Container "${containerName}" may need explicit containment settings for optimal performance`);
584
+ }
585
+ // Dev overlay (only in development)
586
+ if (process.env['NODE_ENV'] === 'development' || window.__PROTEUS_DEV__) {
587
+ createDevOverlay(element, containerName);
588
+ }
589
+ }
590
+ /**
591
+ * Create development overlay showing container bounds and breakpoints
592
+ */
593
+ function createDevOverlay(element, name) {
594
+ const overlay = document.createElement('div');
595
+ overlay.className = 'proteus-container-overlay';
596
+ overlay.style.cssText = `
597
+ position: absolute;
598
+ top: 0;
599
+ left: 0;
600
+ right: 0;
601
+ bottom: 0;
602
+ pointer-events: none;
603
+ border: 2px dashed rgba(255, 0, 255, 0.5);
604
+ background: rgba(255, 0, 255, 0.05);
605
+ z-index: 9999;
606
+ font-family: monospace;
607
+ font-size: 12px;
608
+ color: #ff00ff;
609
+ `;
610
+ const label = document.createElement('div');
611
+ label.style.cssText = `
612
+ position: absolute;
613
+ top: -20px;
614
+ left: 0;
615
+ background: rgba(255, 0, 255, 0.9);
616
+ color: white;
617
+ padding: 2px 6px;
618
+ border-radius: 3px;
619
+ font-size: 10px;
620
+ white-space: nowrap;
621
+ `;
622
+ label.textContent = `Container: ${name}`;
623
+ const sizeInfo = document.createElement('div');
624
+ sizeInfo.style.cssText = `
625
+ position: absolute;
626
+ bottom: 2px;
627
+ right: 2px;
628
+ background: rgba(0, 0, 0, 0.7);
629
+ color: white;
630
+ padding: 2px 4px;
631
+ border-radius: 2px;
632
+ font-size: 10px;
633
+ `;
634
+ overlay.appendChild(label);
635
+ overlay.appendChild(sizeInfo);
636
+ // Position overlay relative to container
637
+ if (getComputedStyle(element).position === 'static') {
638
+ element.style.position = 'relative';
639
+ }
640
+ element.appendChild(overlay);
641
+ // Update size info
642
+ const updateSizeInfo = () => {
643
+ const rect = element.getBoundingClientRect();
644
+ sizeInfo.textContent = `${Math.round(rect.width)}×${Math.round(rect.height)}`;
645
+ };
646
+ updateSizeInfo();
647
+ // Update on resize
648
+ if ('ResizeObserver' in window) {
649
+ const resizeObserver = new ResizeObserver(updateSizeInfo);
650
+ resizeObserver.observe(element);
651
+ }
652
+ // Store cleanup function
653
+ element._proteusContainerCleanup = () => {
654
+ overlay.remove();
655
+ };
656
+ }
657
+
658
+ /**
659
+ * @sc4rfurryx/proteusjs/adapters/react
660
+ * React hooks and components for ProteusJS
661
+ *
662
+ * @version 1.1.0
663
+ * @author sc4rfurry
664
+ * @license MIT
665
+ */
666
+ /**
667
+ * Hook for view transitions
668
+ */
669
+ function useTransition() {
670
+ return useCallback(async (run, opts) => {
671
+ return transition(run, opts);
672
+ }, []);
673
+ }
674
+ /**
675
+ * Hook for scroll-driven animations
676
+ */
677
+ function useScrollAnimate(ref, opts) {
678
+ useEffect(() => {
679
+ if (!ref.current)
680
+ return;
681
+ scrollAnimate(ref.current, opts);
682
+ return () => {
683
+ // Cleanup would be handled by the scroll module
684
+ };
685
+ }, [ref, opts]);
686
+ }
687
+ /**
688
+ * Hook for popover functionality
689
+ */
690
+ function usePopover(triggerRef, panelRef, opts) {
691
+ const controllerRef = useRef(null);
692
+ useEffect(() => {
693
+ if (!triggerRef.current || !panelRef.current)
694
+ return;
695
+ controllerRef.current = attach(triggerRef.current, panelRef.current, opts);
696
+ return () => {
697
+ if (controllerRef.current) {
698
+ controllerRef.current.destroy();
699
+ controllerRef.current = null;
700
+ }
701
+ };
702
+ }, [triggerRef, panelRef, opts]);
703
+ return controllerRef.current;
704
+ }
705
+ /**
706
+ * Hook for anchor positioning
707
+ */
708
+ function useAnchor(floatingRef, anchorRef, opts) {
709
+ const controllerRef = useRef(null);
710
+ useEffect(() => {
711
+ if (!floatingRef.current || !anchorRef.current)
712
+ return;
713
+ controllerRef.current = tether(floatingRef.current, {
714
+ anchor: anchorRef.current,
715
+ ...opts
716
+ });
717
+ return () => {
718
+ if (controllerRef.current) {
719
+ controllerRef.current.destroy();
720
+ controllerRef.current = null;
721
+ }
722
+ };
723
+ }, [floatingRef, anchorRef, opts]);
724
+ return controllerRef.current;
725
+ }
726
+ /**
727
+ * Hook for container queries
728
+ */
729
+ function useContainer(ref, name, opts) {
730
+ useEffect(() => {
731
+ if (!ref.current)
732
+ return;
733
+ defineContainer(ref.current, name, opts);
734
+ }, [ref, name, opts]);
735
+ }
736
+ /**
737
+ * Hook for performance optimizations
738
+ */
739
+ function usePerformance(ref) {
740
+ useEffect(() => {
741
+ if (!ref.current)
742
+ return;
743
+ // Apply basic performance optimizations
744
+ const element = ref.current;
745
+ // Content visibility for off-screen content
746
+ const observer = new IntersectionObserver((entries) => {
747
+ entries.forEach(entry => {
748
+ if (entry.isIntersecting) {
749
+ element.style.contentVisibility = 'visible';
750
+ }
751
+ else {
752
+ element.style.contentVisibility = 'auto';
753
+ }
754
+ });
755
+ }, { rootMargin: '50px' });
756
+ observer.observe(element);
757
+ return () => {
758
+ observer.disconnect();
759
+ };
760
+ }, [ref]);
761
+ }
762
+ /**
763
+ * Hook for accessibility features
764
+ */
765
+ function useA11y(ref, options = {}) {
766
+ const { announceChanges = false, focusManagement = true } = options;
767
+ useEffect(() => {
768
+ if (!ref.current)
769
+ return;
770
+ const element = ref.current;
771
+ // Basic accessibility enhancements
772
+ if (focusManagement) {
773
+ // Ensure focusable elements have visible focus indicators
774
+ const focusableElements = element.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
775
+ focusableElements.forEach((el) => {
776
+ const htmlEl = el;
777
+ if (!htmlEl.style.outline && !getComputedStyle(htmlEl).outline) {
778
+ htmlEl.style.outline = '2px solid transparent';
779
+ htmlEl.style.outlineOffset = '2px';
780
+ htmlEl.addEventListener('focus', () => {
781
+ htmlEl.style.outline = '2px solid #0066cc';
782
+ });
783
+ htmlEl.addEventListener('blur', () => {
784
+ htmlEl.style.outline = '2px solid transparent';
785
+ });
786
+ }
787
+ });
788
+ }
789
+ if (announceChanges) {
790
+ // Set up mutation observer for announcing changes
791
+ const observer = new MutationObserver((mutations) => {
792
+ mutations.forEach(mutation => {
793
+ if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
794
+ // Announce significant changes to screen readers
795
+ const announcement = document.createElement('div');
796
+ announcement.setAttribute('aria-live', 'polite');
797
+ announcement.setAttribute('aria-atomic', 'true');
798
+ announcement.style.position = 'absolute';
799
+ announcement.style.left = '-10000px';
800
+ announcement.textContent = 'Content updated';
801
+ document.body.appendChild(announcement);
802
+ setTimeout(() => {
803
+ document.body.removeChild(announcement);
804
+ }, 1000);
805
+ }
806
+ });
807
+ });
808
+ observer.observe(element, {
809
+ childList: true,
810
+ subtree: true
811
+ });
812
+ return () => {
813
+ observer.disconnect();
814
+ };
815
+ }
816
+ }, [ref, announceChanges, focusManagement]);
817
+ }
818
+ /**
819
+ * Higher-order component for adding ProteusJS features
820
+ */
821
+ function withProteus(Component, features = {}) {
822
+ return function ProteusEnhanced(props) {
823
+ const ref = useRef(null);
824
+ if (features.container) {
825
+ useContainer(ref, features.container.name, features.container.options);
826
+ }
827
+ if (features.performance) {
828
+ usePerformance(ref);
829
+ }
830
+ if (features.accessibility) {
831
+ useA11y(ref);
832
+ }
833
+ return createElement('div', { ref }, createElement(Component, props));
834
+ };
835
+ }
836
+ // Export all hooks and utilities
837
+ var react = {
838
+ useTransition,
839
+ useScrollAnimate,
840
+ usePopover,
841
+ useAnchor,
842
+ useContainer,
843
+ usePerformance,
844
+ useA11y,
845
+ withProteus
846
+ };
847
+
848
+ export { react as default, useA11y, useAnchor, useContainer, usePerformance, usePopover, useScrollAnimate, useTransition, withProteus };
849
+ //# sourceMappingURL=react.esm.js.map