x4js 2.0.35 → 2.1.0-manual

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 (134) hide show
  1. package/README.md +21 -21
  2. package/package.json +39 -26
  3. package/src/components/base.scss +25 -89
  4. package/src/components/boxes/boxes.module.scss +54 -54
  5. package/src/components/boxes/boxes.ts +513 -513
  6. package/src/components/breadcrumb/breadcrumb.scss +56 -56
  7. package/src/components/breadcrumb/breadcrumb.ts +93 -93
  8. package/src/components/btngroup/btngroup.module.scss +40 -40
  9. package/src/components/btngroup/btngroup.ts +152 -152
  10. package/src/components/button/button.module.scss +172 -172
  11. package/src/components/button/button.ts +232 -232
  12. package/src/components/calendar/calendar.module.scss +162 -162
  13. package/src/components/calendar/calendar.ts +326 -326
  14. package/src/components/canvas/canvas.module.scss +24 -24
  15. package/src/components/canvas/canvas.ts +195 -195
  16. package/src/components/canvas/canvas_ex.ts +275 -275
  17. package/src/components/checkbox/check.svg +3 -3
  18. package/src/components/checkbox/checkbox.module.scss +141 -141
  19. package/src/components/checkbox/checkbox.ts +139 -139
  20. package/src/components/colorinput/colorinput.module.scss +64 -64
  21. package/src/components/colorinput/colorinput.ts +90 -90
  22. package/src/components/colorpicker/colorpicker.module.scss +132 -132
  23. package/src/components/colorpicker/colorpicker.ts +481 -481
  24. package/src/components/combobox/combobox.module.scss +145 -145
  25. package/src/components/combobox/combobox.ts +282 -282
  26. package/src/components/combobox/updown.svg +3 -3
  27. package/src/components/components.ts +45 -44
  28. package/src/components/dialog/dialog.module.scss +103 -105
  29. package/src/components/dialog/dialog.ts +233 -233
  30. package/src/components/filedrop/filedrop.module.scss +69 -69
  31. package/src/components/filedrop/filedrop.ts +130 -130
  32. package/src/components/form/form.module.scss +38 -38
  33. package/src/components/form/form.ts +172 -172
  34. package/src/components/gridview/gridview.module.scss +323 -337
  35. package/src/components/gridview/gridview.ts +1276 -1316
  36. package/src/components/header/header.module.scss +40 -40
  37. package/src/components/header/header.ts +141 -141
  38. package/src/components/icon/icon.module.scss +32 -32
  39. package/src/components/icon/icon.ts +165 -165
  40. package/src/components/image/image.module.scss +27 -27
  41. package/src/components/image/image.ts +168 -168
  42. package/src/components/input/input.module.scss +74 -74
  43. package/src/components/input/input.ts +537 -537
  44. package/src/components/keyboard/keyboard.module.scss +136 -136
  45. package/src/components/keyboard/keyboard.ts +549 -549
  46. package/src/components/label/label.module.scss +90 -91
  47. package/src/components/label/label.ts +101 -101
  48. package/src/components/link/link.module.scss +44 -44
  49. package/src/components/link/link.ts +87 -87
  50. package/src/components/listbox/listbox.module.scss +179 -179
  51. package/src/components/listbox/listbox.ts +596 -596
  52. package/src/components/menu/menu.module.scss +128 -128
  53. package/src/components/menu/menu.ts +174 -174
  54. package/src/components/messages/messages.module.scss +92 -146
  55. package/src/components/messages/messages.ts +237 -303
  56. package/src/components/normalize.scss +391 -391
  57. package/src/components/notification/notification.module.scss +83 -83
  58. package/src/components/notification/notification.ts +107 -107
  59. package/src/components/panel/panel.module.scss +66 -71
  60. package/src/components/panel/panel.ts +57 -57
  61. package/src/components/popup/popup.module.scss +51 -51
  62. package/src/components/popup/popup.ts +457 -457
  63. package/src/components/progress/progress.module.scss +56 -56
  64. package/src/components/progress/progress.ts +43 -43
  65. package/src/components/propgrid/progrid.module.scss +111 -111
  66. package/src/components/propgrid/propgrid.ts +300 -300
  67. package/src/components/propgrid/updown.svg +3 -3
  68. package/src/components/radio/radio.module.scss +163 -163
  69. package/src/components/radio/radio.svg +3 -3
  70. package/src/components/radio/radio.ts +141 -141
  71. package/src/components/rating/rating.module.scss +22 -22
  72. package/src/components/rating/rating.ts +131 -131
  73. package/src/components/select/select.module.scss +8 -8
  74. package/src/components/select/select.ts +134 -134
  75. package/src/components/shared.scss +141 -71
  76. package/src/components/sizers/sizer.module.scss +90 -112
  77. package/src/components/sizers/sizer.ts +131 -155
  78. package/src/components/slider/slider.module.scss +117 -117
  79. package/src/components/slider/slider.ts +197 -197
  80. package/src/components/spreadsheet/spreadsheet.module.scss +307 -307
  81. package/src/components/spreadsheet/spreadsheet.ts +1223 -1223
  82. package/src/components/switch/switch.module.scss +126 -126
  83. package/src/components/switch/switch.ts +61 -61
  84. package/src/components/tabs/tabs.module.scss +46 -67
  85. package/src/components/tabs/tabs.ts +229 -234
  86. package/src/components/textarea/textarea.module.scss +63 -63
  87. package/src/components/textarea/textarea.ts +131 -131
  88. package/src/components/textedit/textedit.module.scss +115 -115
  89. package/src/components/textedit/textedit.ts +122 -122
  90. package/src/components/themes.scss +90 -90
  91. package/src/components/tickline/tickline.module.scss +25 -25
  92. package/src/components/tickline/tickline.ts +81 -81
  93. package/src/components/tooltips/tooltips.scss +71 -71
  94. package/src/components/tooltips/tooltips.ts +120 -120
  95. package/src/components/treeview/treeview.module.scss +192 -192
  96. package/src/components/treeview/treeview.ts +484 -484
  97. package/src/components/viewport/viewport.module.scss +31 -31
  98. package/src/components/viewport/viewport.ts +41 -41
  99. package/src/core/component.ts +1299 -1299
  100. package/src/core/core_application.ts +361 -361
  101. package/src/core/core_colors.ts +512 -512
  102. package/src/core/core_data.ts +1297 -1310
  103. package/src/core/core_dom.ts +481 -481
  104. package/src/core/core_dragdrop.ts +225 -225
  105. package/src/core/core_element.ts +221 -221
  106. package/src/core/core_events.ts +214 -214
  107. package/src/core/core_i18n.ts +395 -395
  108. package/src/core/core_pdf.ts +454 -454
  109. package/src/core/core_react.ts +78 -78
  110. package/src/core/core_router.ts +296 -296
  111. package/src/core/core_state.ts +62 -62
  112. package/src/core/core_styles.ts +213 -213
  113. package/src/core/core_svg.ts +1042 -1042
  114. package/src/core/core_tools.ts +996 -996
  115. package/src/types/scss.d.ts +4 -4
  116. package/src/types/x4react.d.ts +8 -8
  117. package/src/x4.scss +19 -19
  118. package/src/x4.ts +36 -36
  119. package/src/x4tsx.d.ts +26 -26
  120. package/.vscode/launch.json +0 -14
  121. package/.vscode/settings.json +0 -2
  122. package/demo/assets/house-light.svg +0 -1
  123. package/demo/assets/radio.svg +0 -4
  124. package/demo/index.html +0 -12
  125. package/demo/main.scss +0 -23
  126. package/demo/main.ts +0 -324
  127. package/demo/package.json +0 -26
  128. package/demo/scss.d.ts +0 -4
  129. package/demo/svg.d.ts +0 -1
  130. package/demo/tsconfig.json +0 -14
  131. package/src/components/gridview/folder-open.svg +0 -1
  132. package/src/components/messages/spinner.svg +0 -1
  133. package/src/x4.d.ts +0 -10
  134. package/tsconfig.json +0 -11
@@ -1,481 +1,481 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
7
- *
8
- * @file core_dom.ts
9
- * @author Etienne Cochard
10
- *
11
- * @copyright (c) 2024 R-libre ingenierie
12
- *
13
- * Use of this source code is governed by an MIT-style license
14
- * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
- **/
16
-
17
- /** @ignore this events must be defined on domNode (do not bubble) */
18
- export const unbubbleEvents = {
19
- mouseleave: 1, mouseenter: 1, load: 1, unload: 1, scroll: 1, focus: 1, blur: 1, rowexit: 1, beforeunload: 1, stop: 1,
20
- dragdrop: 1, dragenter: 1, dragexit: 1, draggesture: 1, dragover: 1, contextmenu: 1, created: 2, removed: 2, sizechange: 2
21
- };
22
-
23
- export type DOMEventHandler = ( ev: Event ) => void;
24
- type EventEntry = Record<string,DOMEventHandler | DOMEventHandler[]>;
25
-
26
- const event_handlers = new WeakMap<Node,EventEntry>( );
27
-
28
- /**
29
- * handle dom mutations
30
- */
31
-
32
- let mutObserver: MutationObserver = null;
33
-
34
- const observeMutation = (mutations: MutationRecord[], observer: MutationObserver): void => {
35
-
36
- const sendEvent = ( node: Node, code: "created" | "removed" ) => {
37
- // console.log( "notify", node, code );
38
-
39
- const store = event_handlers.get( node );
40
- if ( store && store[code] ) {
41
- node.dispatchEvent( new Event( code, {} ) );
42
- }
43
- }
44
-
45
- const notify = ( node: Node, create: boolean ) => {
46
-
47
- if( create ) {
48
- sendEvent( node, "created" );
49
- }
50
-
51
- for( let c=node.firstChild; c; c=c.nextSibling ) {
52
- notify( c, create );
53
- }
54
-
55
- if( !create ) {
56
- sendEvent( node, "removed" );
57
- }
58
- }
59
-
60
-
61
- for (const mutation of mutations) {
62
- if( mutation.type=="childList" ) {
63
- if( mutation.addedNodes ) {
64
- mutation.addedNodes.forEach( node => {
65
- notify( node, true );
66
- } );
67
- }
68
-
69
- if( mutation.removedNodes ) {
70
- mutation.removedNodes.forEach( node => {
71
- notify( node, false );
72
- } );
73
- }
74
- }
75
- }
76
- }
77
-
78
-
79
-
80
- /**
81
- *
82
- */
83
-
84
- let sizeObserver: ResizeObserver = null;
85
-
86
- function observeSize(entries: ResizeObserverEntry[]) {
87
- entries.forEach((entry) => {
88
- let dom = entry.target as HTMLElement;
89
- if (dom.offsetParent !== null) {
90
- dom.dispatchEvent( new Event('resized') );
91
- }
92
- });
93
- }
94
-
95
- /**
96
- * Manually dispatches an event through the custom event system.
97
- * Simulates bubbling unless the event type is in the unbubbleEvents list.
98
- *
99
- * @param ev - The event to dispatch.
100
- */
101
-
102
- export function dispatchEvent(ev: Event) {
103
-
104
- let target = ev.target as Node,
105
- noup = (unbubbleEvents as any)[ev.type] === 2;
106
-
107
- while (target) {
108
- const store = event_handlers.get( target );
109
- if ( store ) {
110
- const callback = store[ev.type];
111
- if( callback ) {
112
- if( Array.isArray(callback) ) {
113
- callback.some( c => c( ev ) );
114
- }
115
- else {
116
- callback( ev );
117
- }
118
-
119
- if (ev.stopPropagation || ev.defaultPrevented || noup) {
120
- break;
121
- }
122
- }
123
- }
124
-
125
- target = target.parentNode;
126
-
127
- // no need to go above
128
- if (target == document) {
129
- break;
130
- }
131
- }
132
- }
133
-
134
- /**
135
- * Registers an event handler for a specific node.
136
- * Automatically initializes MutationObserver or ResizeObserver if special events
137
- * ('created', 'removed', 'resized') are requested.
138
- *
139
- * @param node - The target DOM node.
140
- * @param name - The name of the event to listen for.
141
- * @param handler - The function to call when the event occurs.
142
- * @param prepend - Whether to prepend the handler to the list (default: false).
143
- */
144
-
145
- export function addEvent( node: Node, name: string, handler: DOMEventHandler, prepend = false ) {
146
-
147
- if( name=="removed" || name=="created" ) {
148
- if( !mutObserver ) {
149
- mutObserver = new MutationObserver( observeMutation )
150
- mutObserver.observe( document.body, {childList: true,subtree: true} );
151
- }
152
- }
153
- else if( name=="resized" ) {
154
- if (!sizeObserver) {
155
- sizeObserver = new ResizeObserver( observeSize );
156
- }
157
-
158
- sizeObserver.observe( node as Element );
159
- }
160
-
161
-
162
- let store = event_handlers.get( node );
163
- if( !store ) {
164
- store = {}
165
- event_handlers.set( node, store );
166
- }
167
-
168
- if( !store[name] ) {
169
- store[name] = handler;
170
- node.addEventListener( name, dispatchEvent );
171
- }
172
- else {
173
- const entry = store[name];
174
- if( Array.isArray(entry) ) {
175
- entry.push( handler );
176
- }
177
- else {
178
- store[name] = [entry,handler];
179
- }
180
- }
181
- }
182
-
183
- /**
184
- *
185
- */
186
-
187
- export interface GlobalDOMEvents {
188
-
189
- /**
190
- * Fires when the user aborts the download.
191
- * @param ev The event.
192
- */
193
-
194
- abort?: (ev: UIEvent) => any;
195
- animationcancel?: (ev: AnimationEvent) => any;
196
- animationend?: (ev: AnimationEvent) => any;
197
- animationiteration?: (ev: AnimationEvent) => any;
198
- animationstart?: (ev: AnimationEvent) => any;
199
- auxclick?: (ev: MouseEvent) => any;
200
-
201
- /**
202
- * Fires when the object loses the input focus.
203
- * @param ev The focus event.
204
- */
205
- blur?: (ev: FocusEvent) => any;
206
- cancel?: (ev: Event) => any;
207
-
208
- /**
209
- * Occurs when playback is possible, but would require further buffering.
210
- * @param ev The event.
211
- */
212
- canplay?: (ev: Event) => any;
213
- canplaythrough?: (ev: Event) => any;
214
- /**
215
- * Fires when the contents of the object or selection have changed.
216
- * @param ev The event.
217
- */
218
- change?: (ev: Event) => any;
219
- /**
220
- * Fires when the user clicks the left mouse button on the object
221
- * @param ev The mouse event.
222
- */
223
- click?: (ev: MouseEvent) => any;
224
- close?: (ev: Event) => any;
225
- /**
226
- * Fires when the user clicks the right mouse button in the client area, opening the context menu.
227
- * @param ev The mouse event.
228
- */
229
- contextmenu?: (ev: MouseEvent) => any;
230
- cuechange?: (ev: Event) => any;
231
- /**
232
- * Fires when the user double-clicks the object.
233
- * @param ev The mouse event.
234
- */
235
- dblclick?: (ev: MouseEvent) => any;
236
- /**
237
- * Fires on the source object continuously during a drag operation.
238
- * @param ev The event.
239
- */
240
- drag?: (ev: DragEvent) => any;
241
- /**
242
- * Fires on the source object when the user releases the mouse at the close of a drag operation.
243
- * @param ev The event.
244
- */
245
- dragend?: (ev: DragEvent) => any;
246
- /**
247
- * Fires on the target element when the user drags the object to a valid drop target.
248
- * @param ev The drag event.
249
- */
250
- dragenter?: (ev: DragEvent) => any;
251
- dragexit?: (ev: Event) => any;
252
- /**
253
- * Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation.
254
- * @param ev The drag event.
255
- */
256
- dragleave?: (ev: DragEvent) => any;
257
- /**
258
- * Fires on the target element continuously while the user drags the object over a valid drop target.
259
- * @param ev The event.
260
- */
261
- dragover?: (ev: DragEvent) => any;
262
- /**
263
- * Fires on the source object when the user starts to drag a text selection or selected object.
264
- * @param ev The event.
265
- */
266
- dragstart?: (ev: DragEvent) => any;
267
- drop?: (ev: DragEvent) => any;
268
- /**
269
- * Occurs when the duration attribute is updated.
270
- * @param ev The event.
271
- */
272
- durationchange?: (ev: Event) => any;
273
- /**
274
- * Occurs when the media element is reset to its initial state.
275
- * @param ev The event.
276
- */
277
- emptied?: (ev: Event) => any;
278
- /**
279
- * Occurs when the end of playback is reached.
280
- * @param ev The event
281
- */
282
- ended?: (ev: Event) => any;
283
- /**
284
- * Fires when an error occurs during object loading.
285
- * @param ev The event.
286
- */
287
- error?: OnErrorEventHandler;
288
- /**
289
- * Fires when the object receives focus.
290
- * @param ev The event.
291
- */
292
- focusin?: (ev: FocusEvent) => any;
293
- focusout?: (ev: FocusEvent) => any;
294
- focus?: (ev: FocusEvent) => any;
295
- gotpointercapture?: (ev: PointerEvent) => any;
296
- input?: (ev: Event) => any;
297
- invalid?: (ev: Event) => any;
298
- /**
299
- * Fires when the user presses a key.
300
- * @param ev The keyboard event
301
- */
302
- keydown?: (ev: KeyboardEvent) => any;
303
- /**
304
- * Fires when the user presses an alphanumeric key.
305
- * @param ev The event.
306
- */
307
- keypress?: (ev: KeyboardEvent) => any;
308
- /**
309
- * Fires when the user releases a key.
310
- * @param ev The keyboard event
311
- */
312
- keyup?: (ev: KeyboardEvent) => any;
313
- /**
314
- * Fires immediately after the browser loads the object.
315
- * @param ev The event.
316
- */
317
- load?: (ev: Event) => any;
318
- /**
319
- * Occurs when media data is loaded at the current playback position.
320
- * @param ev The event.
321
- */
322
- loadeddata?: (ev: Event) => any;
323
- /**
324
- * Occurs when the duration and dimensions of the media have been determined.
325
- * @param ev The event.
326
- */
327
- loadedmetadata?: (ev: Event) => any;
328
- /**
329
- * Occurs when Internet Explorer begins looking for media data.
330
- * @param ev The event.
331
- */
332
- loadstart?: (ev: Event) => any;
333
- lostpointercapture?: (ev: PointerEvent) => any;
334
- /**
335
- * Fires when the user clicks the object with either mouse button.
336
- * @param ev The mouse event.
337
- */
338
- mousedown?: (ev: MouseEvent) => any;
339
- mouseenter?: (ev: MouseEvent) => any;
340
- mouseleave?: (ev: MouseEvent) => any;
341
- /**
342
- * Fires when the user moves the mouse over the object.
343
- * @param ev The mouse event.
344
- */
345
- mousemove?: (ev: MouseEvent) => any;
346
- /**
347
- * Fires when the user moves the mouse pointer outside the boundaries of the object.
348
- * @param ev The mouse event.
349
- */
350
- mouseout?: (ev: MouseEvent) => any;
351
- /**
352
- * Fires when the user moves the mouse pointer into the object.
353
- * @param ev The mouse event.
354
- */
355
- mouseover?: (ev: MouseEvent) => any;
356
- /**
357
- * Fires when the user releases a mouse button while the mouse is over the object.
358
- * @param ev The mouse event.
359
- */
360
- mouseup?: (ev: MouseEvent) => any;
361
- /**
362
- * Occurs when playback is paused.
363
- * @param ev The event.
364
- */
365
- pause?: (ev: Event) => any;
366
- /**
367
- * Occurs when the play method is requested.
368
- * @param ev The event.
369
- */
370
- play?: (ev: Event) => any;
371
- /**
372
- * Occurs when the audio or video has started playing.
373
- * @param ev The event.
374
- */
375
- playing?: (ev: Event) => any;
376
- pointercancel?: (ev: PointerEvent) => any;
377
- pointerdown?: (ev: PointerEvent) => any;
378
- pointerenter?: (ev: PointerEvent) => any;
379
- pointerleave?: (ev: PointerEvent) => any;
380
- pointermove?: (ev: PointerEvent) => any;
381
- pointerout?: (ev: PointerEvent) => any;
382
- pointerover?: (ev: PointerEvent) => any;
383
- pointerup?: (ev: PointerEvent) => any;
384
- /**
385
- * Occurs to indicate progress while downloading media data.
386
- * @param ev The event.
387
- */
388
- progress?: (ev: ProgressEvent) => any;
389
- /**
390
- * Occurs when the playback rate is increased or decreased.
391
- * @param ev The event.
392
- */
393
- ratechange?: (ev: Event) => any;
394
- /**
395
- * Fires when the user resets a form.
396
- * @param ev The event.
397
- */
398
- reset?: (ev: Event) => any;
399
- //resize?: (ev: UIEvent) => any; remove to avoid errors with sizechange event
400
-
401
- /**
402
- * Fires when the user repositions the scroll box in the scroll bar on the object.
403
- * @param ev The event.
404
- */
405
- scroll?: (ev: Event) => any;
406
- securitypolicyviolation?: (ev: SecurityPolicyViolationEvent) => any;
407
- /**
408
- * Occurs when the seek operation ends.
409
- * @param ev The event.
410
- */
411
- seeked?: (ev: Event) => any;
412
- /**
413
- * Occurs when the current playback position is moved.
414
- * @param ev The event.
415
- */
416
- seeking?: (ev: Event) => any;
417
- /**
418
- * Fires when the current selection changes.
419
- * @param ev The event.
420
- */
421
- select?: (ev: Event) => any;
422
- selectionchange?: (ev: Event) => any;
423
- selectstart?: (ev: Event) => any;
424
- /**
425
- * Occurs when the download has stopped.
426
- * @param ev The event.
427
- */
428
- stalled?: (ev: Event) => any;
429
- submit?: (ev: Event) => any;
430
-
431
- /**
432
- * Occurs if the load operation has been intentionally halted.
433
- * @param ev The event.
434
- */
435
- suspend?: (ev: Event) => any;
436
-
437
- /**
438
- * Occurs to indicate the current playback position.
439
- * @param ev The event.
440
- */
441
- timeupdate?: (ev: Event) => any;
442
- toggle?: (ev: Event) => any;
443
- touchcancel?: (ev: TouchEvent) => any;
444
- touchend?: (ev: TouchEvent) => any;
445
- touchmove?: (ev: TouchEvent) => any;
446
- touchstart?: (ev: TouchEvent) => any;
447
- transitioncancel?: (ev: TransitionEvent) => any;
448
- transitionend?: (ev: TransitionEvent) => any;
449
- transitionrun?: (ev: TransitionEvent) => any;
450
- transitionstart?: (ev: TransitionEvent) => any;
451
-
452
- /**
453
- * Occurs when the volume is changed, or playback is muted or unmuted.
454
- * @param ev The event.
455
- */
456
- volumechange?: (ev: Event) => any;
457
-
458
- /**
459
- * Occurs when playback stops because the next frame of a video resource is not available.
460
- * @param ev The event.
461
- */
462
- waiting?: (ev: Event) => any;
463
- wheel?: (ev: WheelEvent) => any;
464
-
465
- /**
466
- * custom x4 events
467
- */
468
-
469
- resized?: (ev: Event) => void; // occurs when size changed
470
- created?: ( ev: Event ) => void; // occurs when inserted in the dom
471
- removed?: ( ev: Event ) => void; // occurs when removed from dom
472
- }
473
-
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file core_dom.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * @copyright (c) 2024 R-libre ingenierie
12
+ *
13
+ * Use of this source code is governed by an MIT-style license
14
+ * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
+ **/
16
+
17
+ /** @ignore this events must be defined on domNode (do not bubble) */
18
+ export const unbubbleEvents = {
19
+ mouseleave: 1, mouseenter: 1, load: 1, unload: 1, scroll: 1, focus: 1, blur: 1, rowexit: 1, beforeunload: 1, stop: 1,
20
+ dragdrop: 1, dragenter: 1, dragexit: 1, draggesture: 1, dragover: 1, contextmenu: 1, created: 2, removed: 2, sizechange: 2
21
+ };
22
+
23
+ export type DOMEventHandler = ( ev: Event ) => void;
24
+ type EventEntry = Record<string,DOMEventHandler | DOMEventHandler[]>;
25
+
26
+ const event_handlers = new WeakMap<Node,EventEntry>( );
27
+
28
+ /**
29
+ * handle dom mutations
30
+ */
31
+
32
+ let mutObserver: MutationObserver = null;
33
+
34
+ const observeMutation = (mutations: MutationRecord[], observer: MutationObserver): void => {
35
+
36
+ const sendEvent = ( node: Node, code: "created" | "removed" ) => {
37
+ // console.log( "notify", node, code );
38
+
39
+ const store = event_handlers.get( node );
40
+ if ( store && store[code] ) {
41
+ node.dispatchEvent( new Event( code, {} ) );
42
+ }
43
+ }
44
+
45
+ const notify = ( node: Node, create: boolean ) => {
46
+
47
+ if( create ) {
48
+ sendEvent( node, "created" );
49
+ }
50
+
51
+ for( let c=node.firstChild; c; c=c.nextSibling ) {
52
+ notify( c, create );
53
+ }
54
+
55
+ if( !create ) {
56
+ sendEvent( node, "removed" );
57
+ }
58
+ }
59
+
60
+
61
+ for (const mutation of mutations) {
62
+ if( mutation.type=="childList" ) {
63
+ if( mutation.addedNodes ) {
64
+ mutation.addedNodes.forEach( node => {
65
+ notify( node, true );
66
+ } );
67
+ }
68
+
69
+ if( mutation.removedNodes ) {
70
+ mutation.removedNodes.forEach( node => {
71
+ notify( node, false );
72
+ } );
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+
79
+
80
+ /**
81
+ *
82
+ */
83
+
84
+ let sizeObserver: ResizeObserver = null;
85
+
86
+ function observeSize(entries: ResizeObserverEntry[]) {
87
+ entries.forEach((entry) => {
88
+ let dom = entry.target as HTMLElement;
89
+ if (dom.offsetParent !== null) {
90
+ dom.dispatchEvent( new Event('resized') );
91
+ }
92
+ });
93
+ }
94
+
95
+ /**
96
+ * Manually dispatches an event through the custom event system.
97
+ * Simulates bubbling unless the event type is in the unbubbleEvents list.
98
+ *
99
+ * @param ev - The event to dispatch.
100
+ */
101
+
102
+ export function dispatchEvent(ev: Event) {
103
+
104
+ let target = ev.target as Node,
105
+ noup = (unbubbleEvents as any)[ev.type] === 2;
106
+
107
+ while (target) {
108
+ const store = event_handlers.get( target );
109
+ if ( store ) {
110
+ const callback = store[ev.type];
111
+ if( callback ) {
112
+ if( Array.isArray(callback) ) {
113
+ callback.some( c => c( ev ) );
114
+ }
115
+ else {
116
+ callback( ev );
117
+ }
118
+
119
+ if (ev.stopPropagation || ev.defaultPrevented || noup) {
120
+ break;
121
+ }
122
+ }
123
+ }
124
+
125
+ target = target.parentNode;
126
+
127
+ // no need to go above
128
+ if (target == document) {
129
+ break;
130
+ }
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Registers an event handler for a specific node.
136
+ * Automatically initializes MutationObserver or ResizeObserver if special events
137
+ * ('created', 'removed', 'resized') are requested.
138
+ *
139
+ * @param node - The target DOM node.
140
+ * @param name - The name of the event to listen for.
141
+ * @param handler - The function to call when the event occurs.
142
+ * @param prepend - Whether to prepend the handler to the list (default: false).
143
+ */
144
+
145
+ export function addEvent( node: Node, name: string, handler: DOMEventHandler, prepend = false ) {
146
+
147
+ if( name=="removed" || name=="created" ) {
148
+ if( !mutObserver ) {
149
+ mutObserver = new MutationObserver( observeMutation )
150
+ mutObserver.observe( document.body, {childList: true,subtree: true} );
151
+ }
152
+ }
153
+ else if( name=="resized" ) {
154
+ if (!sizeObserver) {
155
+ sizeObserver = new ResizeObserver( observeSize );
156
+ }
157
+
158
+ sizeObserver.observe( node as Element );
159
+ }
160
+
161
+
162
+ let store = event_handlers.get( node );
163
+ if( !store ) {
164
+ store = {}
165
+ event_handlers.set( node, store );
166
+ }
167
+
168
+ if( !store[name] ) {
169
+ store[name] = handler;
170
+ node.addEventListener( name, dispatchEvent );
171
+ }
172
+ else {
173
+ const entry = store[name];
174
+ if( Array.isArray(entry) ) {
175
+ entry.push( handler );
176
+ }
177
+ else {
178
+ store[name] = [entry,handler];
179
+ }
180
+ }
181
+ }
182
+
183
+ /**
184
+ *
185
+ */
186
+
187
+ export interface GlobalDOMEvents {
188
+
189
+ /**
190
+ * Fires when the user aborts the download.
191
+ * @param ev The event.
192
+ */
193
+
194
+ abort?: (ev: UIEvent) => any;
195
+ animationcancel?: (ev: AnimationEvent) => any;
196
+ animationend?: (ev: AnimationEvent) => any;
197
+ animationiteration?: (ev: AnimationEvent) => any;
198
+ animationstart?: (ev: AnimationEvent) => any;
199
+ auxclick?: (ev: MouseEvent) => any;
200
+
201
+ /**
202
+ * Fires when the object loses the input focus.
203
+ * @param ev The focus event.
204
+ */
205
+ blur?: (ev: FocusEvent) => any;
206
+ cancel?: (ev: Event) => any;
207
+
208
+ /**
209
+ * Occurs when playback is possible, but would require further buffering.
210
+ * @param ev The event.
211
+ */
212
+ canplay?: (ev: Event) => any;
213
+ canplaythrough?: (ev: Event) => any;
214
+ /**
215
+ * Fires when the contents of the object or selection have changed.
216
+ * @param ev The event.
217
+ */
218
+ change?: (ev: Event) => any;
219
+ /**
220
+ * Fires when the user clicks the left mouse button on the object
221
+ * @param ev The mouse event.
222
+ */
223
+ click?: (ev: MouseEvent) => any;
224
+ close?: (ev: Event) => any;
225
+ /**
226
+ * Fires when the user clicks the right mouse button in the client area, opening the context menu.
227
+ * @param ev The mouse event.
228
+ */
229
+ contextmenu?: (ev: MouseEvent) => any;
230
+ cuechange?: (ev: Event) => any;
231
+ /**
232
+ * Fires when the user double-clicks the object.
233
+ * @param ev The mouse event.
234
+ */
235
+ dblclick?: (ev: MouseEvent) => any;
236
+ /**
237
+ * Fires on the source object continuously during a drag operation.
238
+ * @param ev The event.
239
+ */
240
+ drag?: (ev: DragEvent) => any;
241
+ /**
242
+ * Fires on the source object when the user releases the mouse at the close of a drag operation.
243
+ * @param ev The event.
244
+ */
245
+ dragend?: (ev: DragEvent) => any;
246
+ /**
247
+ * Fires on the target element when the user drags the object to a valid drop target.
248
+ * @param ev The drag event.
249
+ */
250
+ dragenter?: (ev: DragEvent) => any;
251
+ dragexit?: (ev: Event) => any;
252
+ /**
253
+ * Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation.
254
+ * @param ev The drag event.
255
+ */
256
+ dragleave?: (ev: DragEvent) => any;
257
+ /**
258
+ * Fires on the target element continuously while the user drags the object over a valid drop target.
259
+ * @param ev The event.
260
+ */
261
+ dragover?: (ev: DragEvent) => any;
262
+ /**
263
+ * Fires on the source object when the user starts to drag a text selection or selected object.
264
+ * @param ev The event.
265
+ */
266
+ dragstart?: (ev: DragEvent) => any;
267
+ drop?: (ev: DragEvent) => any;
268
+ /**
269
+ * Occurs when the duration attribute is updated.
270
+ * @param ev The event.
271
+ */
272
+ durationchange?: (ev: Event) => any;
273
+ /**
274
+ * Occurs when the media element is reset to its initial state.
275
+ * @param ev The event.
276
+ */
277
+ emptied?: (ev: Event) => any;
278
+ /**
279
+ * Occurs when the end of playback is reached.
280
+ * @param ev The event
281
+ */
282
+ ended?: (ev: Event) => any;
283
+ /**
284
+ * Fires when an error occurs during object loading.
285
+ * @param ev The event.
286
+ */
287
+ error?: OnErrorEventHandler;
288
+ /**
289
+ * Fires when the object receives focus.
290
+ * @param ev The event.
291
+ */
292
+ focusin?: (ev: FocusEvent) => any;
293
+ focusout?: (ev: FocusEvent) => any;
294
+ focus?: (ev: FocusEvent) => any;
295
+ gotpointercapture?: (ev: PointerEvent) => any;
296
+ input?: (ev: Event) => any;
297
+ invalid?: (ev: Event) => any;
298
+ /**
299
+ * Fires when the user presses a key.
300
+ * @param ev The keyboard event
301
+ */
302
+ keydown?: (ev: KeyboardEvent) => any;
303
+ /**
304
+ * Fires when the user presses an alphanumeric key.
305
+ * @param ev The event.
306
+ */
307
+ keypress?: (ev: KeyboardEvent) => any;
308
+ /**
309
+ * Fires when the user releases a key.
310
+ * @param ev The keyboard event
311
+ */
312
+ keyup?: (ev: KeyboardEvent) => any;
313
+ /**
314
+ * Fires immediately after the browser loads the object.
315
+ * @param ev The event.
316
+ */
317
+ load?: (ev: Event) => any;
318
+ /**
319
+ * Occurs when media data is loaded at the current playback position.
320
+ * @param ev The event.
321
+ */
322
+ loadeddata?: (ev: Event) => any;
323
+ /**
324
+ * Occurs when the duration and dimensions of the media have been determined.
325
+ * @param ev The event.
326
+ */
327
+ loadedmetadata?: (ev: Event) => any;
328
+ /**
329
+ * Occurs when Internet Explorer begins looking for media data.
330
+ * @param ev The event.
331
+ */
332
+ loadstart?: (ev: Event) => any;
333
+ lostpointercapture?: (ev: PointerEvent) => any;
334
+ /**
335
+ * Fires when the user clicks the object with either mouse button.
336
+ * @param ev The mouse event.
337
+ */
338
+ mousedown?: (ev: MouseEvent) => any;
339
+ mouseenter?: (ev: MouseEvent) => any;
340
+ mouseleave?: (ev: MouseEvent) => any;
341
+ /**
342
+ * Fires when the user moves the mouse over the object.
343
+ * @param ev The mouse event.
344
+ */
345
+ mousemove?: (ev: MouseEvent) => any;
346
+ /**
347
+ * Fires when the user moves the mouse pointer outside the boundaries of the object.
348
+ * @param ev The mouse event.
349
+ */
350
+ mouseout?: (ev: MouseEvent) => any;
351
+ /**
352
+ * Fires when the user moves the mouse pointer into the object.
353
+ * @param ev The mouse event.
354
+ */
355
+ mouseover?: (ev: MouseEvent) => any;
356
+ /**
357
+ * Fires when the user releases a mouse button while the mouse is over the object.
358
+ * @param ev The mouse event.
359
+ */
360
+ mouseup?: (ev: MouseEvent) => any;
361
+ /**
362
+ * Occurs when playback is paused.
363
+ * @param ev The event.
364
+ */
365
+ pause?: (ev: Event) => any;
366
+ /**
367
+ * Occurs when the play method is requested.
368
+ * @param ev The event.
369
+ */
370
+ play?: (ev: Event) => any;
371
+ /**
372
+ * Occurs when the audio or video has started playing.
373
+ * @param ev The event.
374
+ */
375
+ playing?: (ev: Event) => any;
376
+ pointercancel?: (ev: PointerEvent) => any;
377
+ pointerdown?: (ev: PointerEvent) => any;
378
+ pointerenter?: (ev: PointerEvent) => any;
379
+ pointerleave?: (ev: PointerEvent) => any;
380
+ pointermove?: (ev: PointerEvent) => any;
381
+ pointerout?: (ev: PointerEvent) => any;
382
+ pointerover?: (ev: PointerEvent) => any;
383
+ pointerup?: (ev: PointerEvent) => any;
384
+ /**
385
+ * Occurs to indicate progress while downloading media data.
386
+ * @param ev The event.
387
+ */
388
+ progress?: (ev: ProgressEvent) => any;
389
+ /**
390
+ * Occurs when the playback rate is increased or decreased.
391
+ * @param ev The event.
392
+ */
393
+ ratechange?: (ev: Event) => any;
394
+ /**
395
+ * Fires when the user resets a form.
396
+ * @param ev The event.
397
+ */
398
+ reset?: (ev: Event) => any;
399
+ //resize?: (ev: UIEvent) => any; remove to avoid errors with sizechange event
400
+
401
+ /**
402
+ * Fires when the user repositions the scroll box in the scroll bar on the object.
403
+ * @param ev The event.
404
+ */
405
+ scroll?: (ev: Event) => any;
406
+ securitypolicyviolation?: (ev: SecurityPolicyViolationEvent) => any;
407
+ /**
408
+ * Occurs when the seek operation ends.
409
+ * @param ev The event.
410
+ */
411
+ seeked?: (ev: Event) => any;
412
+ /**
413
+ * Occurs when the current playback position is moved.
414
+ * @param ev The event.
415
+ */
416
+ seeking?: (ev: Event) => any;
417
+ /**
418
+ * Fires when the current selection changes.
419
+ * @param ev The event.
420
+ */
421
+ select?: (ev: Event) => any;
422
+ selectionchange?: (ev: Event) => any;
423
+ selectstart?: (ev: Event) => any;
424
+ /**
425
+ * Occurs when the download has stopped.
426
+ * @param ev The event.
427
+ */
428
+ stalled?: (ev: Event) => any;
429
+ submit?: (ev: Event) => any;
430
+
431
+ /**
432
+ * Occurs if the load operation has been intentionally halted.
433
+ * @param ev The event.
434
+ */
435
+ suspend?: (ev: Event) => any;
436
+
437
+ /**
438
+ * Occurs to indicate the current playback position.
439
+ * @param ev The event.
440
+ */
441
+ timeupdate?: (ev: Event) => any;
442
+ toggle?: (ev: Event) => any;
443
+ touchcancel?: (ev: TouchEvent) => any;
444
+ touchend?: (ev: TouchEvent) => any;
445
+ touchmove?: (ev: TouchEvent) => any;
446
+ touchstart?: (ev: TouchEvent) => any;
447
+ transitioncancel?: (ev: TransitionEvent) => any;
448
+ transitionend?: (ev: TransitionEvent) => any;
449
+ transitionrun?: (ev: TransitionEvent) => any;
450
+ transitionstart?: (ev: TransitionEvent) => any;
451
+
452
+ /**
453
+ * Occurs when the volume is changed, or playback is muted or unmuted.
454
+ * @param ev The event.
455
+ */
456
+ volumechange?: (ev: Event) => any;
457
+
458
+ /**
459
+ * Occurs when playback stops because the next frame of a video resource is not available.
460
+ * @param ev The event.
461
+ */
462
+ waiting?: (ev: Event) => any;
463
+ wheel?: (ev: WheelEvent) => any;
464
+
465
+ /**
466
+ * custom x4 events
467
+ */
468
+
469
+ resized?: (ev: Event) => void; // occurs when size changed
470
+ created?: ( ev: Event ) => void; // occurs when inserted in the dom
471
+ removed?: ( ev: Event ) => void; // occurs when removed from dom
472
+ }
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+