-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplain-overlay-sync-debug.esm.js
1539 lines (1259 loc) · 52.8 KB
/
plain-overlay-sync-debug.esm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ================================================
DON'T MANUALLY EDIT THIS FILE
================================================ */
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/*
* PlainOverlay
* https://anseki.github.io/plain-overlay/
*
* Copyright (c) 2021 anseki
* Licensed under the MIT license.
*/
import CSSPrefix from 'cssprefix';
import AnimEvent from 'anim-event';
import mClassList from 'm-class-list';
import TimedTransition from 'timed-transition';
/* Static ESM */ /* import CSS_TEXT from './default.scss' */ var CSS_TEXT = ".plainoverlay:not(.plainoverlay-hide) .plainoverlay-builtin-face_01,.plainoverlay{-webkit-tap-highlight-color:rgba(0,0,0,0);transform:translateZ(0);box-shadow:0 0 1px rgba(0,0,0,0)}.plainoverlay{position:absolute;left:0;top:0;overflow:hidden;background-color:rgba(136,136,136,.6);cursor:wait;z-index:9000;transition-property:opacity;transition-duration:200ms;transition-timing-function:linear;opacity:0}.plainoverlay.plainoverlay-show{opacity:1}.plainoverlay.plainoverlay-force{transition-property:none}.plainoverlay.plainoverlay-hide{display:none}.plainoverlay.plainoverlay-doc{position:fixed;left:-200px;top:-200px;overflow:visible;padding:200px;width:100vw;height:100vh}.plainoverlay-body{width:100%;height:100%;display:flex;justify-content:center;align-items:center}.plainoverlay.plainoverlay-doc .plainoverlay-body{width:100vw;height:100vh}.plainoverlay-builtin-face{width:90%;height:90%;max-width:320px;max-height:320px}#plainoverlay-builtin-face-defs{width:0;height:0;position:fixed;left:-100px;top:-100px}#plainoverlay-builtin-face_01 circle,#plainoverlay-builtin-face_01 path{fill:none;stroke-width:40px}#plainoverlay-builtin-face_01 circle{stroke:#fff;opacity:.25}#plainoverlay-builtin-face_01 path{stroke-linecap:round}.plainoverlay:not(.plainoverlay-hide) .plainoverlay-builtin-face_01{-webkit-animation-name:plainoverlay-builtin-face_01-spin;animation-name:plainoverlay-builtin-face_01-spin;-webkit-animation-duration:1s;animation-duration:1s;-webkit-animation-timing-function:linear;animation-timing-function:linear;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite}@-webkit-keyframes plainoverlay-builtin-face_01-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}@keyframes plainoverlay-builtin-face_01-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}"; // [FACE]
/* Static ESM */ /* import FACE_DEFS from './face.html?tag=defs' */ var FACE_DEFS = "<svg id=\"plainoverlay-builtin-face-defs\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"><defs><linearGradient id=\"plainoverlay-builtin-face_01-grad\" gradientUnits=\"userSpaceOnUse\" x1=\"160\" y1=\"20\" x2=\"300\" y2=\"160\"><stop offset=\"0\" stop-color=\"#fff\" stop-opacity=\"0\"/><stop offset=\"0.2\" stop-color=\"#fff\" stop-opacity=\"0.1\"/><stop offset=\"1\" stop-color=\"#fff\" stop-opacity=\"1\"/></linearGradient><g id=\"plainoverlay-builtin-face_01\"><circle cx=\"160\" cy=\"160\" r=\"140\"/><path d=\"M160 20a140 140 0 0 1 140 140\" stroke=\"url('#plainoverlay-builtin-face_01-grad')\"/></g></defs></svg>";
/* Static ESM */ /* import FACE_01 from './face.html?tag=face_01' */ var FACE_01 = "<svg class=\"plainoverlay-builtin-face plainoverlay-builtin-face_01\" version=\"1.1\" viewBox=\"0 0 320 320\"><use xlink:href=\"#plainoverlay-builtin-face_01\"/></svg>"; // [/FACE]
mClassList.ignoreNative = true;
var APP_ID = 'plainoverlay',
STYLE_ELEMENT_ID = "".concat(APP_ID, "-style"),
STYLE_CLASS = APP_ID,
STYLE_CLASS_DOC = "".concat(APP_ID, "-doc"),
STYLE_CLASS_SHOW = "".concat(APP_ID, "-show"),
STYLE_CLASS_HIDE = "".concat(APP_ID, "-hide"),
STYLE_CLASS_FORCE = "".concat(APP_ID, "-force"),
STYLE_CLASS_BODY = "".concat(APP_ID, "-body"),
FACE_DEFS_ELEMENT_ID = "".concat(APP_ID, "-builtin-face-defs"),
STATE_HIDDEN = 0,
STATE_SHOWING = 1,
STATE_SHOWN = 2,
STATE_HIDING = 3,
// DURATION = 2500, // COPY: default.scss
DURATION = 200,
// COPY: default.scss
TOLERANCE = 0.5,
IS_EDGE = '-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style && !window.navigator.msPointerEnabled,
IS_TRIDENT = !IS_EDGE && !!document.uniqueID,
// Future Edge might support `document.uniqueID`.
IS_GECKO = ('MozAppearance' in document.documentElement.style),
IS_BLINK = !IS_EDGE && !IS_GECKO && // Edge has `window.chrome`, and future Gecko might have that.
!!window.chrome && !!window.CSS,
// [DEBUG]
IS_WEBKIT = !IS_EDGE && !IS_TRIDENT && !IS_GECKO && !IS_BLINK && // Some engines support `webkit-*` properties.
!window.chrome && 'WebkitAppearance' in document.documentElement.style,
// [/DEBUG]
isObject = function () {
var toString = {}.toString,
fnToString = {}.hasOwnProperty.toString,
objFnString = fnToString.call(Object);
return function (obj) {
var proto, constr;
return obj && toString.call(obj) === '[object Object]' && (!(proto = Object.getPrototypeOf(obj)) || (constr = proto.hasOwnProperty('constructor') && proto.constructor) && typeof constr === 'function' && fnToString.call(constr) === objFnString);
};
}(),
isFinite = Number.isFinite || function (value) {
return typeof value === 'number' && window.isFinite(value);
},
/**
* An object that has properties of instance.
* @typedef {Object} props
* @property {Element} elmTarget - Target element.
* @property {Element} elmTargetBody - Target body element.
* @property {Element} elmOverlay - Overlay element.
* @property {Element} elmOverlayBody - Overlay body element.
* @property {boolean} isDoc - `true` if target is document.
* @property {Window} window - Window that conatins target element.
* @property {HTMLDocument} document - Document that conatins target element.
* @property {TimedTransition} transition - TimedTransition instance.
* @property {number} state - Current state.
* @property {Object} options - Options.
*/
/** @type {Object.<_id: number, props>} */
insProps = {};
var insId = 0; // [DEBUG]
var traceLog = [];
var STATE_TEXT = {};
STATE_TEXT[STATE_HIDDEN] = 'STATE_HIDDEN';
STATE_TEXT[STATE_SHOWING] = 'STATE_SHOWING';
STATE_TEXT[STATE_SHOWN] = 'STATE_SHOWN';
STATE_TEXT[STATE_HIDING] = 'STATE_HIDING'; // [/DEBUG]
function forceReflow(target) {
// Trident and Blink bug (reflow like `offsetWidth` can't update)
setTimeout(function () {
var parent = target.parentNode,
next = target.nextSibling; // It has to be removed first for Blink.
parent.insertBefore(parent.removeChild(target), next);
}, 0);
}
window.forceReflow = forceReflow; // [DEBUG/]
/**
* Set style properties while saving current properties.
* @param {Element} element - Target element.
* @param {Object} styleProps - New style properties.
* @param {(Object|null)} savedStyleProps - Current style properties holder.
* @param {Array} [propNames] - Names of target properties.
* @returns {Element} Target element itself.
*/
function setStyle(element, styleProps, savedStyleProps, propNames) {
var style = element.style;
(propNames || Object.keys(styleProps)).forEach(function (prop) {
if (styleProps[prop] != null) {
if (savedStyleProps && savedStyleProps[prop] == null) {
savedStyleProps[prop] = style[prop];
}
style[prop] = styleProps[prop];
styleProps[prop] = null;
}
});
return element;
}
/**
* Restore saved style properties.
* @param {Element} element - Target element.
* @param {Object} savedStyleProps - Saved style properties.
* @param {Array} [propNames] - Names of properties that is restored.
* @returns {Element} Target element itself.
*/
function restoreStyle(element, savedStyleProps, propNames) {
return setStyle(element, savedStyleProps, null, propNames);
}
/**
* An object that simulates `DOMRect` to indicate a bounding-box.
* @typedef {Object} BBox
* @property {(number|null)} left - document coordinate
* @property {(number|null)} top - document coordinate
* @property {(number|null)} right - document coordinate
* @property {(number|null)} bottom - document coordinate
* @property {(number|null)} width
* @property {(number|null)} height
*/
/**
* Get an element's bounding-box that contains coordinates relative to the element's document or window.
* @param {Element} element - Target element.
* @param {Window} [window] - Whether it's relative to the element's window, or document.
* @returns {(BBox|null)} A bounding-box or null when failed.
*/
function getBBox(element, window) {
var rect = element.getBoundingClientRect(),
bBox = {
left: rect.left,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
width: rect.width,
height: rect.height
};
if (window) {
bBox.left += window.pageXOffset;
bBox.right += window.pageXOffset;
bBox.top += window.pageYOffset;
bBox.bottom += window.pageYOffset;
}
return bBox;
}
window.getBBox = getBBox; // [DEBUG/]
function scrollLeft(element, isDoc, window, value) {
if (isDoc) {
if (value != null) {
window.scrollTo(value, window.pageYOffset);
}
return window.pageXOffset;
}
if (value != null) {
element.scrollLeft = value;
}
return element.scrollLeft;
}
window.scrollLeft = scrollLeft; // [DEBUG/]
function scrollTop(element, isDoc, window, value) {
if (isDoc) {
if (value != null) {
window.scrollTo(window.pageXOffset, value);
}
return window.pageYOffset;
}
if (value != null) {
element.scrollTop = value;
}
return element.scrollTop;
}
window.scrollTop = scrollTop; // [DEBUG/]
function resizeTarget(props, width, height) {
var elmTargetBody = props.elmTargetBody;
var rect = elmTargetBody.getBoundingClientRect();
if (Math.abs(rect.width - width) < TOLERANCE && Math.abs(rect.height - height) < TOLERANCE) {
return;
}
var targetBodyCmpStyle = props.window.getComputedStyle(elmTargetBody, ''),
boxSizing = targetBodyCmpStyle.boxSizing,
includeProps = boxSizing === 'border-box' ? [] : boxSizing === 'padding-box' ? ['border'] : ['border', 'padding'],
// content-box
PROP_NAMES = {
border: {
width: ['borderLeftWidth', 'borderRightWidth'],
height: ['borderTopWidth', 'borderBottomWidth']
},
padding: {
width: ['paddingLeft', 'paddingRight'],
height: ['paddingTop', 'paddingBottom']
}
},
values = ['width', 'height'].reduce(function (values, dir) {
includeProps.forEach(function (part) {
PROP_NAMES[part][dir].forEach(function (propName) {
values[dir] -= parseFloat(targetBodyCmpStyle[propName]);
});
});
return values;
}, {
width: width,
height: height
}); // Since the `width` and `height` might change each other, fix both.
setStyle(elmTargetBody, {
// The value might be negative number when size is too small.
width: values.width > 0 ? "".concat(values.width, "px") : 0,
height: values.height > 0 ? "".concat(values.height, "px") : 0
}, props.savedStyleTargetBody); // In some browsers, getComputedStyle might return computed values that is not px instead of used values.
var fixStyle = {};
rect = elmTargetBody.getBoundingClientRect();
if (Math.abs(rect.width - width) >= TOLERANCE) {
// [DEBUG]
console.warn("[resizeTarget] Incorrect width: ".concat(rect.width) + " (expected: ".concat(width, " passed: ").concat(values.width, ")")); // [/DEBUG]
fixStyle.width = "".concat(values.width - (rect.width - width), "px");
}
if (rect.height !== height) {
// [DEBUG]
console.warn("[resizeTarget] Incorrect height: ".concat(rect.height) + " (expected: ".concat(height, " passed: ").concat(values.height, ")")); // [/DEBUG]
fixStyle.height = "".concat(values.height - (rect.height - height), "px");
}
setStyle(elmTargetBody, fixStyle, props.savedStyleTargetBody);
}
window.resizeTarget = resizeTarget; // [DEBUG/]
// Trident and Edge bug, width and height are interchanged.
function getDocClientWH(props) {
var elmTarget = props.elmTarget,
width = elmTarget.clientWidth,
height = elmTarget.clientHeight;
if (IS_TRIDENT || IS_EDGE) {
var targetBodyCmpStyle = props.window.getComputedStyle(props.elmTargetBody, ''),
wMode = targetBodyCmpStyle.writingMode || targetBodyCmpStyle['writing-mode'],
// Trident bug
direction = targetBodyCmpStyle.direction;
return wMode === 'tb-rl' || wMode === 'bt-rl' || wMode === 'tb-lr' || wMode === 'bt-lr' || IS_EDGE && (direction === 'ltr' && (wMode === 'vertical-rl' || wMode === 'vertical-lr') || direction === 'rtl' && (wMode === 'vertical-rl' || wMode === 'vertical-lr')) ? {
width: height,
height: width
} : // interchange
{
width: width,
height: height
};
}
return {
width: width,
height: height
};
}
window.getDocClientWH = getDocClientWH; // [DEBUG/]
function restoreScroll(props, element) {
traceLog.push('<restoreScroll>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
function scrollElement(element, isDoc, left, top) {
try {
scrollLeft(element, isDoc, props.window, left);
scrollTop(element, isDoc, props.window, top);
} catch (error) {
/* Something might have been changed, and that can be ignored. */
}
}
if (element) {
return props.savedElementsScroll.some(function (elementScroll) {
if (elementScroll.element === element) {
scrollElement(elementScroll.element, elementScroll.isDoc, elementScroll.left, elementScroll.top);
return true;
}
return false;
}) ? (traceLog.push('DONE:ELEMENT', "_id:".concat(props._id), '</restoreScroll>'), true) : ( // [DEBUG/]
traceLog.push('NotInTarget', "_id:".concat(props._id), '</restoreScroll>'), false) // [DEBUG/]
; // eslint-disable-line semi-style
}
props.savedElementsScroll.forEach(function (elementScroll) {
scrollElement(elementScroll.element, elementScroll.isDoc, elementScroll.left, elementScroll.top);
});
traceLog.push('DONE:ALL', "_id:".concat(props._id), '</restoreScroll>'); // [DEBUG/]
return true;
}
function restoreAccKeys(props) {
props.savedElementsAccKeys.forEach(function (elementAccKeys) {
try {
if (elementAccKeys.tabIndex === false) {
elementAccKeys.element.removeAttribute('tabindex');
} else if (elementAccKeys.tabIndex != null) {
elementAccKeys.element.tabIndex = elementAccKeys.tabIndex;
}
} catch (error) {
/* Something might have been changed, and that can be ignored. */
}
try {
if (elementAccKeys.accessKey) {
elementAccKeys.element.accessKey = elementAccKeys.accessKey;
}
} catch (error) {
/* Something might have been changed, and that can be ignored. */
}
});
}
window.restoreAccKeys = restoreAccKeys; // [DEBUG/]
function avoidFocus(props, element) {
// [DEBUG]
traceLog.push('<avoidFocus>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state]));
traceLog.push("element:".concat(element === document ? 'document' : element.tagName || 'UNKNOWN') + "".concat(element.id ? "#".concat(element.id) : '')); // [/DEBUG]
if (props.isDoc && element !== element.ownerDocument.body && !(props.elmOverlay.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_CONTAINED_BY) || !props.isDoc && (element === props.elmTargetBody || props.elmTargetBody.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_CONTAINED_BY)) {
if (element.blur) {
// Trident and Edge don't support SVG#blur
element.blur();
} else {
element.ownerDocument.body.focus();
}
traceLog.push('DONE', "_id:".concat(props._id), '</avoidFocus>'); // [DEBUG/]
return true;
}
traceLog.push('NotInTarget', "_id:".concat(props._id), '</avoidFocus>'); // [DEBUG/]
return false;
} // Selection.containsNode polyfill for Trident
function selContainsNode(selection, node, partialContainment) {
var nodeRange = node.ownerDocument.createRange(),
iLen = selection.rangeCount;
nodeRange.selectNodeContents(node);
for (var i = 0; i < iLen; i++) {
var selRange = selection.getRangeAt(i); // Edge bug (Issue #7321753); getRangeAt returns empty (collapsed) range
// NOTE: It can not recover when the selection has multiple ranges.
if (!selRange.toString().length && selection.toString().length && iLen === 1) {
console.log('Edge bug (Issue #7321753)'); // [DEBUG/]
selRange.setStart(selection.anchorNode, selection.anchorOffset);
selRange.setEnd(selection.focusNode, selection.focusOffset); // Edge doesn't throw when end is upper than start.
if (selRange.toString() !== selection.toString()) {
selRange.setStart(selection.focusNode, selection.focusOffset);
selRange.setEnd(selection.anchorNode, selection.anchorOffset);
if (selRange.toString() !== selection.toString()) {
throw new Error('Edge bug (Issue #7321753); Couldn\'t recover');
}
}
}
if (partialContainment ? selRange.compareBoundaryPoints(Range.START_TO_END, nodeRange) >= 0 && selRange.compareBoundaryPoints(Range.END_TO_START, nodeRange) <= 0 : selRange.compareBoundaryPoints(Range.START_TO_START, nodeRange) < 0 && selRange.compareBoundaryPoints(Range.END_TO_END, nodeRange) > 0) {
return true;
}
}
return false;
}
window.selContainsNode = selContainsNode; // [DEBUG/]
/**
* Indicates whether the selection is part of the node or not.
* @param {Node} node - Target node.
* @param {Selection} selection - The parsed selection.
* @returns {boolean} `true` if all ranges of `selection` are part of `node`.
*/
function nodeContainsSel(node, selection) {
var nodeRange = node.ownerDocument.createRange(),
iLen = selection.rangeCount;
nodeRange.selectNode(node);
for (var i = 0; i < iLen; i++) {
var selRange = selection.getRangeAt(i);
if (selRange.compareBoundaryPoints(Range.START_TO_START, nodeRange) < 0 || selRange.compareBoundaryPoints(Range.END_TO_END, nodeRange) > 0) {
return false;
}
}
return true;
}
window.nodeContainsSel = nodeContainsSel; // [DEBUG/]
function avoidSelect(props) {
traceLog.push('<avoidSelect>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
var selection = ('getSelection' in window ? props.window : props.document).getSelection(); // [DEBUG]
if (selection.rangeCount) {
var start = selection.anchorNode,
end = selection.focusNode;
if (start && start.nodeType === Node.TEXT_NODE) {
start = start.parentNode;
}
if (end && end.nodeType === Node.TEXT_NODE) {
end = end.parentNode;
}
traceLog.push("start:".concat(!start ? 'NONE' : start === document ? 'document' : start.tagName || 'UNKNOWN') + "".concat(start && start.id ? "#".concat(start.id) : '') + "(".concat(selection.anchorOffset, ")") + ",end:".concat(!end ? 'NONE' : end === document ? 'document' : end.tagName || 'UNKNOWN') + "".concat(end && end.id ? "#".concat(end.id) : '') + "(".concat(selection.focusOffset, ")") + ",isCollapsed:".concat(selection.isCollapsed));
} else {
traceLog.push('NoRange');
} // [/DEBUG]
if (selection.rangeCount && (props.isDoc ? !nodeContainsSel(props.elmOverlayBody, selection) : selection.containsNode && (!IS_BLINK || !selection.isCollapsed) // Blink bug, fails with empty string.
? selection.containsNode(props.elmTargetBody, true) : selContainsNode(selection, props.elmTargetBody, true))) {
try {
selection.removeAllRanges(); // Trident bug?, `Error:800a025e` comes sometime
} catch (error) {
/* ignore */
}
props.document.body.focus(); // Trident bug? It seems that `focus()` makes selection again.
if (selection.rangeCount > 0) {
try {
selection.removeAllRanges(); // Trident bug?, `Error:800a025e` comes sometime
} catch (error) {
/* ignore */
}
}
traceLog.push('DONE', "_id:".concat(props._id), '</avoidSelect>'); // [DEBUG/]
return true;
}
traceLog.push('NoSelection', "_id:".concat(props._id), '</avoidSelect>'); // [DEBUG/]
return false;
}
function barLeft(wMode, direction) {
var svgSpec = wMode === 'rl-tb' || wMode === 'tb-rl' || wMode === 'bt-rl' || wMode === 'rl-bt';
return IS_TRIDENT && svgSpec || IS_EDGE && (svgSpec || direction === 'rtl' && (wMode === 'horizontal-tb' || wMode === 'vertical-rl') || direction === 'ltr' && wMode === 'vertical-rl');
}
window.barLeft = barLeft; // [DEBUG/]
function barTop(wMode, direction) {
var svgSpec = wMode === 'bt-rl' || wMode === 'bt-lr' || wMode === 'lr-bt' || wMode === 'rl-bt';
return IS_TRIDENT && svgSpec || IS_EDGE && (svgSpec || direction === 'rtl' && (wMode === 'vertical-lr' || wMode === 'vertical-rl'));
}
window.barTop = barTop; // [DEBUG/]
function disableDocBars(props) {
var elmTarget = props.elmTarget,
elmTargetBody = props.elmTargetBody,
targetBodyRect = elmTargetBody.getBoundingClientRect(); // Get size of each scrollbar.
var clientWH = getDocClientWH(props),
barV = -clientWH.width,
barH = -clientWH.height; // elmTarget.clientWidth/clientHeight
setStyle(elmTarget, {
overflow: 'hidden'
}, props.savedStyleTarget);
clientWH = getDocClientWH(props);
barV += clientWH.width;
barH += clientWH.height;
if (barV || barH) {
var targetBodyCmpStyle = props.window.getComputedStyle(elmTargetBody, '');
var propV, propH; // There is no way to get absolute position of document.
// We need distance between the document and its window, or a method like `element.screenX`
// that gets absolute position of an element.
// For the moment, Trident and Edge make a scrollbar at the left/top side when RTL document
// or CJK vertical document is rendered.
if (IS_TRIDENT || IS_EDGE) {
var wMode = targetBodyCmpStyle.writingMode || targetBodyCmpStyle['writing-mode'],
// Trident bug
direction = targetBodyCmpStyle.direction;
if (barV) {
propV = barLeft(wMode, direction) ? 'marginLeft' : 'marginRight';
}
if (barH) {
propH = barTop(wMode, direction) ? 'marginTop' : 'marginBottom';
}
} else {
if (barV) {
propV = 'marginRight';
}
if (barH) {
propH = 'marginBottom';
}
}
var addStyle = {};
if (barV) {
addStyle[propV] = "".concat(parseFloat(targetBodyCmpStyle[propV]) + barV, "px");
}
if (barH) {
addStyle[propH] = "".concat(parseFloat(targetBodyCmpStyle[propH]) + barH, "px");
}
setStyle(elmTargetBody, addStyle, props.savedStyleTargetBody);
resizeTarget(props, targetBodyRect.width, targetBodyRect.height); // `overflow: 'hidden'` might change scroll.
restoreScroll(props, elmTarget);
return true;
}
restoreStyle(elmTarget, props.savedStyleTarget, ['overflow']);
return false;
}
window.disableDocBars = disableDocBars; // [DEBUG/]
function _position(props, targetBodyBBox) {
var elmTargetBody = props.elmTargetBody,
targetBodyCmpStyle = props.window.getComputedStyle(elmTargetBody, ''),
elmOverlay = props.elmOverlay,
overlayCmpStyle = props.window.getComputedStyle(elmOverlay, ''),
overlayBBox = getBBox(elmOverlay, props.window),
borders = ['Top', 'Right', 'Bottom', 'Left'].reduce(function (borders, prop) {
borders[prop.toLowerCase()] = parseFloat(targetBodyCmpStyle["border".concat(prop, "Width")]);
return borders;
}, {}),
// Get distance between document and origin of `elmOverlay`.
offset = {
left: overlayBBox.left - parseFloat(overlayCmpStyle.left),
top: overlayBBox.top - parseFloat(overlayCmpStyle.top)
},
style = {
left: "".concat(targetBodyBBox.left - offset.left + borders.left, "px"),
top: "".concat(targetBodyBBox.top - offset.top + borders.top, "px"),
width: "".concat(targetBodyBBox.width - borders.left - borders.right, "px"),
height: "".concat(targetBodyBBox.height - borders.top - borders.bottom, "px")
},
reValue = /^([\d.]+)(px|%)$/; // border-radius
[{
prop: 'TopLeft',
hBorder: 'left',
vBorder: 'top'
}, {
prop: 'TopRight',
hBorder: 'right',
vBorder: 'top'
}, {
prop: 'BottomRight',
hBorder: 'right',
vBorder: 'bottom'
}, {
prop: 'BottomLeft',
hBorder: 'left',
vBorder: 'bottom'
}].forEach(function (corner) {
var prop = CSSPrefix.getName("border".concat(corner.prop, "Radius")),
values = targetBodyCmpStyle[prop].split(' ');
var h = values[0],
v = values[1] || values[0],
matches = reValue.exec(h);
h = !matches ? 0 : matches[2] === 'px' ? +matches[1] : matches[1] * targetBodyBBox.width / 100;
matches = reValue.exec(v);
v = !matches ? 0 : matches[2] === 'px' ? +matches[1] : matches[1] * targetBodyBBox.height / 100;
h -= borders[corner.hBorder];
v -= borders[corner.vBorder];
if (h > 0 && v > 0) {
style[prop] = "".concat(h, "px ").concat(v, "px");
}
});
setStyle(elmOverlay, style);
props.targetBodyBBox = targetBodyBBox;
}
window.position = _position; // [DEBUG/]
function getTargetElements(props) {
var elmTargetBody = props.elmTargetBody,
elmOverlay = props.elmOverlay,
targetElements = [props.elmTarget];
if (props.isDoc) {
targetElements.push(elmTargetBody);
Array.prototype.slice.call(elmTargetBody.childNodes).forEach(function (childNode) {
if (childNode.nodeType === Node.ELEMENT_NODE && childNode !== elmOverlay && !mClassList(childNode).contains(STYLE_CLASS) && childNode.id !== FACE_DEFS_ELEMENT_ID) {
targetElements.push(childNode);
Array.prototype.push.apply(targetElements, childNode.querySelectorAll('*'));
}
});
} else {
Array.prototype.push.apply(targetElements, elmTargetBody.querySelectorAll('*'));
}
return targetElements;
}
function finishShowing(props) {
traceLog.push('<finishShowing>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
// blur
props.filterElements = null;
if (props.options.blur !== false) {
var propName = CSSPrefix.getName('filter'),
propValue = CSSPrefix.getValue('filter', "blur(".concat(props.options.blur, "px)"));
if (propValue) {
// undefined if no propName
// Array of {element: element, savedStyle: {}}
var filterElements = props.isDoc ? Array.prototype.slice.call(props.elmTargetBody.childNodes).filter(function (childNode) {
return childNode.nodeType === Node.ELEMENT_NODE && childNode !== props.elmOverlay && !mClassList(childNode).contains(STYLE_CLASS) && childNode.id !== FACE_DEFS_ELEMENT_ID;
}).map(function (element) {
return {
element: element,
savedStyle: {}
};
}) : [{
element: props.elmTargetBody,
savedStyle: {}
}];
filterElements.forEach(function (filterElement) {
var style = {}; // new object for each element.
style[propName] = propValue;
setStyle(filterElement.element, style, filterElement.savedStyle);
});
props.filterElements = filterElements;
}
}
props.state = STATE_SHOWN;
traceLog.push("state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
if (props.options.onShow) {
props.options.onShow.call(props.ins);
}
traceLog.push("_id:".concat(props._id), '</finishShowing>'); // [DEBUG/]
}
function finishHiding(props, sync) {
// sync-mode (`sync` is `true`): Skip restoring active element and finish all immediately.
traceLog.push('<finishHiding>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
traceLog.push("sync:".concat(!!sync)); // [DEBUG/]
mClassList(props.elmOverlay).add(STYLE_CLASS_HIDE);
restoreStyle(props.elmTarget, props.savedStyleTarget);
restoreStyle(props.elmTargetBody, props.savedStyleTargetBody);
props.savedStyleTarget = {};
props.savedStyleTargetBody = {};
restoreAccKeys(props);
props.savedElementsAccKeys = [];
if (!sync && props.isDoc && props.activeElement) {
// props.state must be STATE_HIDDEN for avoiding focus.
var stateSave = props.state;
props.state = STATE_HIDDEN;
traceLog.push("[SAVE1]state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
// the event is fired after function exited in some browsers (e.g. Trident).
traceLog.push('focusListener:REMOVE'); // [DEBUG/]
props.elmTargetBody.removeEventListener('focus', props.focusListener, true);
props.activeElement.focus(); // Don't change props.state for calling `hide(force)` before `restoreAndFinish` (async-mode)
props.state = stateSave;
traceLog.push("[SAVE2]state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
}
props.activeElement = null; // Since `focus()` might scroll, do this after `focus()` and reflow.
function restoreAndFinish() {
traceLog.push('<finishHiding.restoreAndFinish>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
props.timerRestoreAndFinish = null;
props.state = STATE_HIDDEN;
traceLog.push("state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
traceLog.push('focusListener:ADD'); // [DEBUG/]
props.elmTargetBody.addEventListener('focus', props.focusListener, true);
restoreScroll(props);
props.savedElementsScroll = null;
if (props.options.onHide) {
props.options.onHide.call(props.ins);
}
traceLog.push("_id:".concat(props._id), '</finishHiding.restoreAndFinish>'); // [DEBUG/]
}
if (props.timerRestoreAndFinish) {
traceLog.push('ClearPrevTimer'); // [DEBUG/]
clearTimeout(props.timerRestoreAndFinish);
props.timerRestoreAndFinish = null;
}
if (sync) {
restoreAndFinish();
} else {
props.timerRestoreAndFinish = setTimeout(restoreAndFinish, 0);
}
traceLog.push("_id:".concat(props._id), '</finishHiding>'); // [DEBUG/]
}
/**
* @param {props} props - `props` of instance.
* @param {boolean} [force] - Skip effect.
* @returns {void}
*/
function _show(props, force) {
traceLog.push('<show>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
traceLog.push("force:".concat(!!force)); // [DEBUG/]
function getScroll(elements, fromDoc) {
function elementCanScroll(element, isDoc) {
var cmpStyle = props.window.getComputedStyle(element, ''),
tagName = element.nodeName.toLowerCase();
return cmpStyle.overflow === 'scroll' || cmpStyle.overflow === 'auto' || cmpStyle.overflowX === 'scroll' || cmpStyle.overflowX === 'auto' || cmpStyle.overflowY === 'scroll' || cmpStyle.overflowY === 'auto' || // document with `visible` might make scrollbars.
isDoc && (cmpStyle.overflow === 'visible' || cmpStyle.overflowX === 'visible' || cmpStyle.overflowY === 'visible') || // `overflow` of these differs depending on browser.
!isDoc && (tagName === 'textarea' || tagName === 'select');
}
var elementsScroll = [];
elements.forEach(function (element, i) {
var isDoc = fromDoc && i === 0;
if (elementCanScroll(element, isDoc)) {
elementsScroll.push({
element: element,
isDoc: isDoc,
left: scrollLeft(element, isDoc, props.window),
top: scrollTop(element, isDoc, props.window)
});
}
});
return elementsScroll;
}
function disableAccKeys(elements, fromDoc) {
var savedElementsAccKeys = [];
elements.forEach(function (element, i) {
if (fromDoc && i === 0) {
return;
}
var elementAccKeys = {},
tabIndex = element.tabIndex; // In Trident and Edge, `tabIndex` of all elements are `0` or something even if the element is not focusable.
if (tabIndex !== -1) {
elementAccKeys.element = element;
elementAccKeys.tabIndex = element.hasAttribute('tabindex') ? tabIndex : false;
element.tabIndex = -1;
}
var accessKey = element.accessKey;
if (accessKey) {
elementAccKeys.element = element;
elementAccKeys.accessKey = accessKey;
element.accessKey = '';
}
if (elementAccKeys.element) {
savedElementsAccKeys.push(elementAccKeys);
}
});
return savedElementsAccKeys;
}
if (props.state === STATE_SHOWN || props.state === STATE_SHOWING && !force || props.state !== STATE_SHOWING && props.options.onBeforeShow && props.options.onBeforeShow.call(props.ins) === false) {
traceLog.push('CANCEL', '</show>'); // [DEBUG/]
return;
}
if (props.state === STATE_HIDDEN) {
var elmOverlay = props.elmOverlay,
elmOverlayClassList = mClassList(elmOverlay);
props.document.body.appendChild(elmOverlay); // Move to last (for same z-index)
var targetElements = getTargetElements(props);
window.targetElements = targetElements; // [DEBUG/]
elmOverlayClassList.remove(STYLE_CLASS_HIDE); // Before `getBoundingClientRect` (`position`).
if (!props.isDoc) {
var elmTargetBody = props.elmTargetBody;
if (props.window.getComputedStyle(elmTargetBody, '').display === 'inline') {
setStyle(elmTargetBody, {
display: 'inline-block'
}, props.savedStyleTargetBody);
}
_position(props, getBBox(elmTargetBody, props.window));
}
props.savedElementsScroll = getScroll(targetElements, props.isDoc);
props.disabledDocBars = false; // savedElementsScroll is empty when document is disconnected.
if (props.isDoc && props.savedElementsScroll.length && props.savedElementsScroll[0].isDoc) {
props.disabledDocBars = disableDocBars(props);
}
props.savedElementsAccKeys = disableAccKeys(targetElements, props.isDoc);
props.activeElement = props.document.activeElement;
if (props.activeElement) {
avoidFocus(props, props.activeElement);
}
avoidSelect(props);
elmOverlay.offsetWidth;
/* force reflow */
// eslint-disable-line no-unused-expressions
if (props.options.onPosition) {
props.options.onPosition.call(props.ins);
}
}
props.transition.on(force);
props.state = STATE_SHOWING;
traceLog.push("state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
if (force) {
finishShowing(props);
}
traceLog.push("_id:".concat(props._id), '</show>'); // [DEBUG/]
}
/**
* @param {props} props - `props` of instance.
* @param {boolean} [force] - Skip effect.
* @param {boolean} [sync] - sync-mode
* @returns {void}
*/
function _hide(props, force, sync) {
// sync-mode (both `force` and `sync` are `true`)
traceLog.push('<hide>', "_id:".concat(props._id), "state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
traceLog.push("force:".concat(!!force)); // [DEBUG/]
traceLog.push("sync:".concat(!!sync)); // [DEBUG/]
if (props.state === STATE_HIDDEN || props.state === STATE_HIDING && !force || props.state !== STATE_HIDING && props.options.onBeforeHide && props.options.onBeforeHide.call(props.ins) === false) {
traceLog.push('CANCEL', '</hide>'); // [DEBUG/]
return;
} // blur
if (props.filterElements) {
props.filterElements.forEach(function (filterElement) {
restoreStyle(filterElement.element, filterElement.savedStyle);
});
props.filterElements = null;
} // In Gecko, hidden element can be activeElement.
var element = props.document.activeElement;
if (element && element !== element.ownerDocument.body && props.elmOverlay.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_CONTAINED_BY) {
if (element.blur) {
// Trident and Edge don't support SVG#blur
element.blur();
} else {
element.ownerDocument.body.focus();
}
}
props.transition.off(force);
props.state = STATE_HIDING;
traceLog.push("state:".concat(STATE_TEXT[props.state])); // [DEBUG/]
if (force) {
finishHiding(props, sync);
}
traceLog.push("_id:".concat(props._id), '</hide>'); // [DEBUG/]
}
/**
* @param {props} props - `props` of instance.
* @param {Object} newOptions - New options.
* @returns {void}
*/
function _setOptions(props, newOptions) {
var options = props.options; // face
if (newOptions.hasOwnProperty('face') && (newOptions.face == null ? void 0 : newOptions.face) !== options.face) {
var elmOverlayBody = props.elmOverlayBody; // Clear
while (elmOverlayBody.firstChild) {
elmOverlayBody.removeChild(elmOverlayBody.firstChild);
}
if (newOptions.face === false) {
// No face
options.face = false;
} else if (newOptions.face && newOptions.face.nodeType === Node.ELEMENT_NODE) {
// Specific face
options.face = newOptions.face;
elmOverlayBody.appendChild(newOptions.face);
} else if (newOptions.face == null) {
// Builtin face
// [FACE]
var elmDocument = props.document;
if (!elmDocument.getElementById(FACE_DEFS_ELEMENT_ID)) {
// Add svg defs
var defsSvg = new props.window.DOMParser().parseFromString(FACE_DEFS, 'image/svg+xml');
elmDocument.body.appendChild(defsSvg.documentElement);
} // [/FACE]
options.face = void 0;
elmOverlayBody.innerHTML = FACE_01; // [FACE/]
}
} // duration