@jsenv/dom 0.6.1 → 0.7.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 (109) hide show
  1. package/dist/jsenv_dom.js +339 -327
  2. package/package.json +2 -4
  3. package/index.js +0 -124
  4. package/src/attr/add_attribute_effect.js +0 -93
  5. package/src/attr/attributes.js +0 -32
  6. package/src/color/color_constrast.js +0 -69
  7. package/src/color/color_parsing.js +0 -319
  8. package/src/color/color_scheme.js +0 -28
  9. package/src/color/pick_light_or_dark.js +0 -34
  10. package/src/color/resolve_css_color.js +0 -60
  11. package/src/demos/3_columns_resize_demo.html +0 -84
  12. package/src/demos/3_rows_resize_demo.html +0 -89
  13. package/src/demos/aside_and_main_demo.html +0 -93
  14. package/src/demos/coordinates_demo.html +0 -450
  15. package/src/demos/document_autoscroll_demo.html +0 -517
  16. package/src/demos/drag_gesture_constraints_demo.html +0 -701
  17. package/src/demos/drag_gesture_demo.html +0 -1047
  18. package/src/demos/drag_gesture_element_to_impact_demo.html +0 -445
  19. package/src/demos/drag_reference_element_demo.html +0 -480
  20. package/src/demos/flex_details_set_demo.html +0 -302
  21. package/src/demos/flex_details_set_demo_2.html +0 -315
  22. package/src/demos/visible_rect_demo.html +0 -525
  23. package/src/element_signature.js +0 -100
  24. package/src/interaction/drag/constraint_feedback_line.js +0 -92
  25. package/src/interaction/drag/drag_constraint.js +0 -659
  26. package/src/interaction/drag/drag_debug_markers.js +0 -635
  27. package/src/interaction/drag/drag_element_positioner.js +0 -382
  28. package/src/interaction/drag/drag_gesture.js +0 -566
  29. package/src/interaction/drag/drag_resize_demo.html +0 -571
  30. package/src/interaction/drag/drag_to_move.js +0 -301
  31. package/src/interaction/drag/drag_to_resize_gesture.js +0 -68
  32. package/src/interaction/drag/drop_target_detection.js +0 -148
  33. package/src/interaction/drag/sticky_frontiers.js +0 -160
  34. package/src/interaction/event_marker.js +0 -14
  35. package/src/interaction/focus/active_element.js +0 -33
  36. package/src/interaction/focus/arrow_navigation.js +0 -599
  37. package/src/interaction/focus/element_is_focusable.js +0 -57
  38. package/src/interaction/focus/element_visibility.js +0 -111
  39. package/src/interaction/focus/find_focusable.js +0 -21
  40. package/src/interaction/focus/focus_group.js +0 -91
  41. package/src/interaction/focus/focus_group_registry.js +0 -12
  42. package/src/interaction/focus/focus_nav.js +0 -12
  43. package/src/interaction/focus/focus_nav_event_marker.js +0 -14
  44. package/src/interaction/focus/focus_trap.js +0 -105
  45. package/src/interaction/focus/tab_navigation.js +0 -128
  46. package/src/interaction/focus/tests/focus_group_skip_tab_test.html +0 -206
  47. package/src/interaction/focus/tests/tree_focus_test.html +0 -304
  48. package/src/interaction/focus/tests/tree_focus_test.jsx +0 -261
  49. package/src/interaction/focus/tests/tree_focus_test_preact.html +0 -13
  50. package/src/interaction/isolate_interactions.js +0 -161
  51. package/src/interaction/keyboard.js +0 -26
  52. package/src/interaction/scroll/capture_scroll.js +0 -47
  53. package/src/interaction/scroll/is_scrollable.js +0 -159
  54. package/src/interaction/scroll/scroll_container.js +0 -110
  55. package/src/interaction/scroll/scroll_trap.js +0 -44
  56. package/src/interaction/scroll/scrollbar_size.js +0 -20
  57. package/src/interaction/scroll/wheel_through.js +0 -138
  58. package/src/iterable_weak_set.js +0 -66
  59. package/src/position/dom_coords.js +0 -340
  60. package/src/position/offset_parent.js +0 -15
  61. package/src/position/position_fixed.js +0 -15
  62. package/src/position/position_sticky.js +0 -213
  63. package/src/position/sticky_rect.js +0 -79
  64. package/src/position/visible_rect.js +0 -486
  65. package/src/pub_sub.js +0 -31
  66. package/src/size/can_take_size.js +0 -11
  67. package/src/size/details_content_full_height.js +0 -63
  68. package/src/size/flex_details_set.js +0 -974
  69. package/src/size/get_available_height.js +0 -22
  70. package/src/size/get_available_width.js +0 -22
  71. package/src/size/get_border_sizes.js +0 -14
  72. package/src/size/get_height.js +0 -4
  73. package/src/size/get_inner_height.js +0 -15
  74. package/src/size/get_inner_width.js +0 -15
  75. package/src/size/get_margin_sizes.js +0 -10
  76. package/src/size/get_max_height.js +0 -57
  77. package/src/size/get_max_width.js +0 -47
  78. package/src/size/get_min_height.js +0 -14
  79. package/src/size/get_min_width.js +0 -14
  80. package/src/size/get_padding_sizes.js +0 -10
  81. package/src/size/get_width.js +0 -4
  82. package/src/size/hooks/use_available_height.js +0 -27
  83. package/src/size/hooks/use_available_width.js +0 -27
  84. package/src/size/hooks/use_max_height.js +0 -10
  85. package/src/size/hooks/use_max_width.js +0 -10
  86. package/src/size/hooks/use_resize_status.js +0 -62
  87. package/src/size/resize.js +0 -695
  88. package/src/size/resolve_css_size.js +0 -32
  89. package/src/style/dom_styles.js +0 -97
  90. package/src/style/style_composition.js +0 -121
  91. package/src/style/style_controller.js +0 -345
  92. package/src/style/style_default.js +0 -153
  93. package/src/style/style_default_demo.html +0 -128
  94. package/src/style/style_parsing.js +0 -375
  95. package/src/transition/demos/animation_resumption_test.xhtml +0 -500
  96. package/src/transition/demos/height_toggle_test.xhtml +0 -515
  97. package/src/transition/dom_transition.js +0 -254
  98. package/src/transition/easing.js +0 -48
  99. package/src/transition/group_transition.js +0 -261
  100. package/src/transition/transform_style_parser.js +0 -32
  101. package/src/transition/transition_playback.js +0 -366
  102. package/src/transition/transition_timeline.js +0 -79
  103. package/src/traversal.js +0 -247
  104. package/src/ui_transition/demos/content_states_transition_demo.html +0 -628
  105. package/src/ui_transition/demos/smooth_height_transition_demo.html +0 -149
  106. package/src/ui_transition/demos/transition_testing.html +0 -354
  107. package/src/ui_transition/ui_transition.js +0 -1470
  108. package/src/utils.js +0 -69
  109. package/src/value_effect.js +0 -35
@@ -1,701 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>Drag Gesture Demo - Custom Bounds Constraints</title>
7
- <style>
8
- * {
9
- box-sizing: border-box;
10
- }
11
-
12
- body {
13
- margin: 0;
14
- padding: 20px;
15
- font-family: Arial, sans-serif;
16
- background: #f0f0f0;
17
- }
18
-
19
- .demo-section {
20
- margin: 40px auto;
21
- max-width: 900px;
22
- }
23
-
24
- .demo-title {
25
- background: white;
26
- padding: 15px 20px;
27
- border-radius: 8px 8px 0 0;
28
- border-bottom: 2px solid #333;
29
- margin: 0;
30
- font-size: 18px;
31
- font-weight: bold;
32
- color: #333;
33
- }
34
-
35
- .container {
36
- width: 400px;
37
- height: 300px;
38
- background: white;
39
- overflow: auto;
40
- overscroll-behavior: contain;
41
- position: relative;
42
- margin: 0 auto;
43
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
44
- border-radius: 4px;
45
- border: 30px solid #ddd;
46
- }
47
-
48
- /* Horizontal constraints content */
49
- .horizontal-content {
50
- width: 800px; /* Wider than container = horizontal scrollbar */
51
- height: 280px; /* Same height as container = no vertical scrollbar */
52
- background:
53
- linear-gradient(
54
- 90deg,
55
- transparent 99px,
56
- #eee 100px,
57
- #eee 101px,
58
- transparent 102px
59
- ),
60
- linear-gradient(
61
- 90deg,
62
- #ff9999 0px,
63
- #ff9999 100px,
64
- transparent 100px,
65
- transparent 580px,
66
- #ff9999 580px,
67
- #ff9999 800px
68
- );
69
- background-size:
70
- 100px 280px,
71
- 800px 280px;
72
- position: relative;
73
- }
74
-
75
- /* Vertical constraints content */
76
- .vertical-content {
77
- width: 380px; /* Same width as container = no horizontal scrollbar */
78
- height: 600px; /* Taller than container = vertical scrollbar */
79
- background:
80
- linear-gradient(
81
- transparent 99px,
82
- #eee 100px,
83
- #eee 101px,
84
- transparent 102px
85
- ),
86
- linear-gradient(
87
- #ff9999 0px,
88
- #ff9999 100px,
89
- transparent 100px,
90
- transparent 460px,
91
- #ff9999 460px,
92
- #ff9999 600px
93
- );
94
- background-size:
95
- 380px 100px,
96
- 380px 600px;
97
- position: relative;
98
- }
99
-
100
- .draggable-rectangle {
101
- width: 80px;
102
- height: 60px;
103
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
104
- /* border: 3px solid #333; */
105
- border-radius: 8px;
106
- position: absolute;
107
- cursor: grab;
108
- display: flex;
109
- align-items: center;
110
- justify-content: center;
111
- color: white;
112
- font-weight: bold;
113
- font-size: 12px;
114
- text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
115
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
116
- transition: box-shadow 0.2s ease;
117
- user-select: none;
118
- }
119
-
120
- .draggable-rectangle:hover {
121
- box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
122
- }
123
-
124
- .draggable-rectangle[data-dragging] {
125
- cursor: grabbing;
126
- box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
127
- z-index: 1000;
128
- }
129
-
130
- .info {
131
- max-width: 900px;
132
- margin: 0 auto;
133
- padding: 20px;
134
- background: white;
135
- border-radius: 8px;
136
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
137
- }
138
-
139
- .info h1 {
140
- margin-top: 0;
141
- color: #333;
142
- }
143
-
144
- .info ul {
145
- line-height: 1.6;
146
- }
147
-
148
- .debug-toggle {
149
- margin: 20px auto;
150
- text-align: center;
151
- }
152
-
153
- .debug-toggle label {
154
- display: inline-flex;
155
- align-items: center;
156
- gap: 8px;
157
- font-size: 14px;
158
- color: #333;
159
- cursor: pointer;
160
- background: white;
161
- padding: 10px 15px;
162
- border-radius: 4px;
163
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
164
- transition: all 0.2s ease;
165
- }
166
-
167
- .debug-toggle label:hover {
168
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
169
- }
170
-
171
- .debug-toggle input[type="checkbox"] {
172
- width: 18px;
173
- height: 18px;
174
- cursor: pointer;
175
- }
176
-
177
- /* Visual indicators for bounds */
178
- .bounds-legend {
179
- background: white;
180
- padding: 15px;
181
- border-radius: 6px;
182
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
183
- margin: 20px auto;
184
- max-width: 400px;
185
- text-align: center;
186
- }
187
-
188
- .bounds-legend h4 {
189
- margin: 0 0 10px 0;
190
- font-size: 14px;
191
- color: #333;
192
- }
193
-
194
- .legend-item {
195
- display: inline-flex;
196
- align-items: center;
197
- gap: 8px;
198
- margin: 0 10px;
199
- font-size: 12px;
200
- }
201
-
202
- .legend-color {
203
- width: 20px;
204
- height: 15px;
205
- border-radius: 2px;
206
- border: 1px solid #333;
207
- }
208
-
209
- .red-zone {
210
- background: #ff9999;
211
- }
212
-
213
- .position-display {
214
- position: fixed;
215
- top: 10px;
216
- right: 10px;
217
- background: rgba(0, 0, 0, 0.8);
218
- color: white;
219
- padding: 10px;
220
- border-radius: 4px;
221
- font-family: monospace;
222
- font-size: 11px;
223
- z-index: 10000;
224
- line-height: 1.4;
225
- min-width: 200px;
226
- }
227
-
228
- .position-display div {
229
- margin: 2px 0;
230
- }
231
-
232
- .position-display .label {
233
- font-weight: bold;
234
- color: #ffeb3b;
235
- }
236
- </style>
237
- </head>
238
- <body>
239
- <div class="info">
240
- <h1>Drag Gesture Demo - Custom Bounds Constraints</h1>
241
- <p>
242
- This demo demonstrates custom boundary constraints that prevent dragging
243
- beyond specific limits:
244
- </p>
245
- <ul>
246
- <li>
247
- <strong>Horizontal Constraints:</strong> Element's left edge must stay
248
- between 100px-500px. Red zones show forbidden positions for the
249
- element.
250
- </li>
251
- <li>
252
- <strong>Vertical Constraints:</strong> Element's top edge must stay
253
- between 100px-400px. Red zones show forbidden positions for the
254
- element.
255
- </li>
256
- <li>
257
- <strong>Red zones:</strong> Show areas where the element cannot be
258
- positioned accounting for its full size (0-100px and 580px+
259
- horizontally, 0-100px and 460px+ vertically)
260
- </li>
261
- <li>
262
- <strong>Auto-scroll:</strong> Still works when dragging near container
263
- edges, but respects bounds
264
- </li>
265
- </ul>
266
- </div>
267
-
268
- <div class="debug-toggle">
269
- <label>
270
- <input type="checkbox" id="debugMarkersCheckbox" checked />
271
- Show Debug Markers
272
- </label>
273
- </div>
274
-
275
- <div class="bounds-legend">
276
- <h4>Visual Legend</h4>
277
- <div class="legend-item">
278
- <div class="legend-color red-zone"></div>
279
- <span>Forbidden Zone</span>
280
- </div>
281
- </div>
282
-
283
- <!-- Test Case: Sticky Element with Scroll Issue -->
284
- <div class="demo-section">
285
- <h2 class="demo-title">
286
- Test Case: Sticky Element Drag with Initial Scroll
287
- </h2>
288
- <div style="text-align: center; margin-bottom: 15px">
289
- <button
290
- id="resetScrollBtn"
291
- style="
292
- padding: 8px 16px;
293
- margin-right: 10px;
294
- border: 1px solid #666;
295
- border-radius: 4px;
296
- background: white;
297
- cursor: pointer;
298
- "
299
- >
300
- Reset Scroll to 0
301
- </button>
302
- <button
303
- id="addScrollBtn"
304
- style="
305
- padding: 8px 16px;
306
- border: 1px solid #666;
307
- border-radius: 4px;
308
- background: white;
309
- cursor: pointer;
310
- "
311
- >
312
- Add 200px Scroll
313
- </button>
314
- <div style="margin-top: 8px; font-size: 12px; color: #666">
315
- Current scroll: <span id="scrollDisplay">0</span>px
316
- </div>
317
- </div>
318
- <div
319
- class="container"
320
- id="stickyTestContainer"
321
- style="border: 2px solid #333"
322
- >
323
- <div
324
- style="
325
- width: 1000px;
326
- height: 280px;
327
- background: linear-gradient(
328
- 90deg,
329
- #f0f0f0 0%,
330
- #e0e0e0 50%,
331
- #d0d0d0 100%
332
- );
333
- position: relative;
334
- "
335
- >
336
- <!-- Sticky element on the left -->
337
- <div
338
- class="draggable-rectangle"
339
- id="stickyRectangle"
340
- data-sticky-left
341
- style="
342
- left: 50px;
343
- top: 110px;
344
- position: sticky;
345
- background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
346
- "
347
- >
348
- STICKY
349
- </div>
350
- <!-- Grid lines for visual reference -->
351
- <div
352
- style="
353
- position: absolute;
354
- left: 100px;
355
- top: 0;
356
- width: 1px;
357
- height: 100%;
358
- background: #999;
359
- opacity: 0.3;
360
- "
361
- ></div>
362
- <div
363
- style="
364
- position: absolute;
365
- left: 300px;
366
- top: 0;
367
- width: 1px;
368
- height: 100%;
369
- background: #999;
370
- opacity: 0.3;
371
- "
372
- ></div>
373
- <div
374
- style="
375
- position: absolute;
376
- left: 500px;
377
- top: 0;
378
- width: 1px;
379
- height: 100%;
380
- background: #999;
381
- opacity: 0.3;
382
- "
383
- ></div>
384
- <div
385
- style="
386
- position: absolute;
387
- left: 700px;
388
- top: 0;
389
- width: 1px;
390
- height: 100%;
391
- background: #999;
392
- opacity: 0.3;
393
- "
394
- ></div>
395
- <div
396
- style="
397
- position: absolute;
398
- left: 900px;
399
- top: 0;
400
- width: 1px;
401
- height: 100%;
402
- background: #999;
403
- opacity: 0.3;
404
- "
405
- ></div>
406
- </div>
407
- </div>
408
- <div
409
- style="
410
- text-align: center;
411
- margin-top: 10px;
412
- font-size: 12px;
413
- color: #666;
414
- "
415
- >
416
- <div>
417
- Try dragging with scroll = 0, then set scroll = 200px and try again
418
- </div>
419
- <div>
420
- The sticky element should respect bounds constraints in both cases
421
- </div>
422
- </div>
423
- </div>
424
-
425
- <!-- Case 1: Horizontal Custom Bounds -->
426
- <div class="demo-section">
427
- <h2 class="demo-title">
428
- Case 1: Horizontal Custom Bounds (customLeftBound: 100px,
429
- customRightBound: 500px)
430
- </h2>
431
- <div class="container" id="horizontalContainer">
432
- <div class="horizontal-content">
433
- <div
434
- class="draggable-rectangle"
435
- id="horizontalRectangle"
436
- style="left: 200px; top: 110px"
437
- >
438
- DRAG H
439
- </div>
440
- </div>
441
- </div>
442
- </div>
443
-
444
- <!-- Case 2: Vertical Custom Bounds -->
445
- <div class="demo-section">
446
- <h2 class="demo-title">
447
- Case 2: Vertical Custom Bounds (customTopBound: 100px,
448
- customBottomBound: 400px)
449
- </h2>
450
- <div class="container" id="verticalContainer">
451
- <div class="vertical-content">
452
- <div
453
- class="draggable-rectangle"
454
- id="verticalRectangle"
455
- style="left: 150px; top: 250px"
456
- >
457
- DRAG V
458
- </div>
459
- </div>
460
- </div>
461
- </div>
462
-
463
- <!-- Position Display -->
464
- <div class="position-display" id="positionDisplay">
465
- <div class="label">Drag Position Info</div>
466
- <div id="horizontalInfo">Horizontal: Not dragging</div>
467
- <div id="verticalInfo">Vertical: Not dragging</div>
468
- <div id="boundsInfo">Bounds: Hover to see limits</div>
469
- </div>
470
-
471
- <script type="module">
472
- import { createDragToMoveGestureController } from "@jsenv/dom";
473
-
474
- const horizontalRectangle = document.getElementById(
475
- "horizontalRectangle",
476
- );
477
- const verticalRectangle = document.getElementById("verticalRectangle");
478
- const horizontalContainer = document.getElementById(
479
- "horizontalContainer",
480
- );
481
- const verticalContainer = document.getElementById("verticalContainer");
482
- const stickyRectangle = document.getElementById("stickyRectangle");
483
- const stickyTestContainer = document.getElementById(
484
- "stickyTestContainer",
485
- );
486
- const resetScrollBtn = document.getElementById("resetScrollBtn");
487
- const addScrollBtn = document.getElementById("addScrollBtn");
488
- const scrollDisplay = document.getElementById("scrollDisplay");
489
-
490
- const horizontalInfo = document.getElementById("horizontalInfo");
491
- const verticalInfo = document.getElementById("verticalInfo");
492
- const boundsInfo = document.getElementById("boundsInfo");
493
-
494
- // Set up sticky test case
495
- function updateScrollDisplay() {
496
- scrollDisplay.textContent = Math.round(stickyTestContainer.scrollLeft);
497
- }
498
-
499
- resetScrollBtn.addEventListener("click", () => {
500
- stickyTestContainer.scrollLeft = 0;
501
- updateScrollDisplay();
502
- console.log("Scroll reset to 0");
503
- });
504
-
505
- addScrollBtn.addEventListener("click", () => {
506
- stickyTestContainer.scrollLeft = 200;
507
- updateScrollDisplay();
508
- console.log("Scroll set to 200px");
509
- });
510
-
511
- // Update scroll display initially and on scroll
512
- updateScrollDisplay();
513
- stickyTestContainer.addEventListener("scroll", updateScrollDisplay);
514
-
515
- // Set up drag gesture for sticky element
516
- stickyRectangle.addEventListener("mousedown", (event) => {
517
- console.log(
518
- "Sticky drag started with scrollLeft:",
519
- stickyTestContainer.scrollLeft,
520
- );
521
-
522
- createDragToMoveGestureController({
523
- backdrop: false,
524
- // No custom bounds - should respect scrollable area bounds
525
- onGrab: (gestureInfo) => {
526
- console.log("Sticky - Grab started", {
527
- gestureInfo,
528
- scrollLeftAtStart: gestureInfo.scrollLeftAtStart,
529
- currentScrollLeft: stickyTestContainer.scrollLeft,
530
- });
531
- stickyRectangle.setAttribute("data-dragging", "");
532
- },
533
- onDragStart: (gestureInfo) => {
534
- console.log("Sticky - Drag started", gestureInfo);
535
- },
536
- onDrag: (gestureInfo, phase) => {
537
- console.log("Sticky - Dragging", {
538
- phase,
539
- xMove: gestureInfo.xMove,
540
- yMove: gestureInfo.yMove,
541
- leftAtStart: gestureInfo.leftAtStart,
542
- scrollLeftAtStart: gestureInfo.scrollLeftAtStart,
543
- currentScrollLeft: stickyTestContainer.scrollLeft,
544
- });
545
- },
546
- onRelease: (gestureInfo) => {
547
- console.log("Sticky - Drag released", gestureInfo);
548
- stickyRectangle.removeAttribute("data-dragging");
549
- },
550
- }).grabViaMouse(event, {
551
- element: stickyRectangle,
552
- });
553
- });
554
-
555
- // Set up drag gesture for horizontal constraints
556
- horizontalRectangle.addEventListener("mousedown", (event) => {
557
- // Custom bounds in container-relative coordinates
558
- const customLeftBound = 100; // Cannot drag left of 100px from content start
559
- const customRightBound = 500; // Cannot drag right of 500px from content start
560
-
561
- createDragToMoveGestureController({
562
- direction: { x: true },
563
- backdrop: false,
564
- customAreaConstraint: {
565
- left: customLeftBound,
566
- right: customRightBound,
567
- },
568
- onGrab: (gestureInfo) => {
569
- console.log("Horizontal - Grab started", gestureInfo);
570
- horizontalRectangle.setAttribute("data-dragging", "");
571
- updateHorizontalInfo(gestureInfo, "Grabbed");
572
- },
573
- onDragStart: (gestureInfo) => {
574
- console.log("Horizontal - Drag started", gestureInfo);
575
- updateHorizontalInfo(gestureInfo, "Drag Start");
576
- },
577
- onDrag: (gestureInfo, phase) => {
578
- updateHorizontalInfo(gestureInfo, `Dragging (${phase})`);
579
- updateBoundsInfo("Horizontal bounds: L=100px, R=500px");
580
- },
581
- onRelease: (gestureInfo) => {
582
- console.log("Horizontal - Drag released", gestureInfo);
583
- horizontalRectangle.removeAttribute("data-dragging");
584
- updateHorizontalInfo(gestureInfo, "Released");
585
- updateBoundsInfo("Hover to see limits");
586
- },
587
- }).grabViaMouse(event, {
588
- element: horizontalRectangle,
589
- });
590
- });
591
-
592
- // Set up drag gesture for vertical constraints
593
- verticalRectangle.addEventListener("mousedown", (event) => {
594
- // Custom bounds in container-relative coordinates
595
- const customTopBound = 100; // Cannot drag above 100px from content start
596
- const customBottomBound = 400; // Cannot drag below 400px from content start
597
-
598
- createDragToMoveGestureController({
599
- backdrop: false,
600
- customAreaConstraint: {
601
- top: customTopBound,
602
- bottom: customBottomBound,
603
- },
604
- onGrab: (gestureInfo) => {
605
- console.log("Vertical - Grab started", gestureInfo);
606
- verticalRectangle.setAttribute("data-dragging", "");
607
- updateVerticalInfo(gestureInfo, "Grabbed");
608
- },
609
- onDragStart: (gestureInfo) => {
610
- console.log("Vertical - Drag started", gestureInfo);
611
- updateVerticalInfo(gestureInfo, "Drag Start");
612
- },
613
- onDrag: (gestureInfo, phase) => {
614
- updateVerticalInfo(gestureInfo, `Dragging (${phase})`);
615
- updateBoundsInfo("Vertical bounds: T=100px, B=400px");
616
- },
617
- onRelease: (gestureInfo) => {
618
- console.log("Vertical - Drag released", gestureInfo);
619
- verticalRectangle.removeAttribute("data-dragging");
620
- updateVerticalInfo(gestureInfo, "Released");
621
- updateBoundsInfo("Hover to see limits");
622
- },
623
- }).grabViaMouse(event, {
624
- element: verticalRectangle,
625
- });
626
- });
627
-
628
- function updateHorizontalInfo(gestureInfo, status) {
629
- const container = horizontalContainer;
630
- const rect = horizontalRectangle.getBoundingClientRect();
631
- const containerRect = container.getBoundingClientRect();
632
- const relativeX = rect.left - containerRect.left + container.scrollLeft;
633
-
634
- horizontalInfo.innerHTML = `Horizontal: ${status} | X: ${Math.round(relativeX)}px | Scroll: ${Math.round(container.scrollLeft)}px`;
635
- }
636
-
637
- function updateVerticalInfo(gestureInfo, status) {
638
- const container = verticalContainer;
639
- const rect = verticalRectangle.getBoundingClientRect();
640
- const containerRect = container.getBoundingClientRect();
641
- const relativeY = rect.top - containerRect.top + container.scrollTop;
642
-
643
- verticalInfo.innerHTML = `Vertical: ${status} | Y: ${Math.round(relativeY)}px | Scroll: ${Math.round(container.scrollTop)}px`;
644
- }
645
-
646
- function updateBoundsInfo(text) {
647
- boundsInfo.textContent = text;
648
- }
649
-
650
- // Initial position updates
651
- function updatePositions() {
652
- const hRect = horizontalRectangle.getBoundingClientRect();
653
- const hContainerRect = horizontalContainer.getBoundingClientRect();
654
- const hRelativeX =
655
- hRect.left - hContainerRect.left + horizontalContainer.scrollLeft;
656
-
657
- const vRect = verticalRectangle.getBoundingClientRect();
658
- const vContainerRect = verticalContainer.getBoundingClientRect();
659
- const vRelativeY =
660
- vRect.top - vContainerRect.top + verticalContainer.scrollTop;
661
-
662
- horizontalInfo.innerHTML = `Horizontal: Ready | X: ${Math.round(hRelativeX)}px | Scroll: ${Math.round(horizontalContainer.scrollLeft)}px`;
663
- verticalInfo.innerHTML = `Vertical: Ready | Y: ${Math.round(vRelativeY)}px | Scroll: ${Math.round(verticalContainer.scrollTop)}px`;
664
- }
665
-
666
- // Update positions on scroll
667
- horizontalContainer.addEventListener("scroll", updatePositions);
668
- verticalContainer.addEventListener("scroll", updatePositions);
669
- updatePositions();
670
-
671
- // Add hover effects to show bounds information
672
- horizontalRectangle.addEventListener("mouseenter", () => {
673
- if (!horizontalRectangle.hasAttribute("data-dragging")) {
674
- updateBoundsInfo(
675
- "Horizontal bounds: L=100px, R=500px (red = forbidden)",
676
- );
677
- }
678
- });
679
-
680
- verticalRectangle.addEventListener("mouseenter", () => {
681
- if (!verticalRectangle.hasAttribute("data-dragging")) {
682
- updateBoundsInfo(
683
- "Vertical bounds: T=100px, B=400px (red = forbidden)",
684
- );
685
- }
686
- });
687
-
688
- horizontalRectangle.addEventListener("mouseleave", () => {
689
- if (!horizontalRectangle.hasAttribute("data-dragging")) {
690
- updateBoundsInfo("Hover to see limits");
691
- }
692
- });
693
-
694
- verticalRectangle.addEventListener("mouseleave", () => {
695
- if (!verticalRectangle.hasAttribute("data-dragging")) {
696
- updateBoundsInfo("Hover to see limits");
697
- }
698
- });
699
- </script>
700
- </body>
701
- </html>