textbrowser 0.41.2 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index-es.js CHANGED
@@ -4878,979 +4878,6 @@ function getIMFFallbackResults({
4878
4878
  });
4879
4879
  }
4880
4880
 
4881
- // nb. This is for IE10 and lower _only_.
4882
- var supportCustomEvent = window.CustomEvent;
4883
-
4884
- if (!supportCustomEvent || typeof supportCustomEvent === 'object') {
4885
- supportCustomEvent = function CustomEvent(event, x) {
4886
- x = x || {};
4887
- var ev = document.createEvent('CustomEvent');
4888
- ev.initCustomEvent(event, !!x.bubbles, !!x.cancelable, x.detail || null);
4889
- return ev;
4890
- };
4891
-
4892
- supportCustomEvent.prototype = window.Event.prototype;
4893
- }
4894
- /**
4895
- * Dispatches the passed event to both an "on<type>" handler as well as via the
4896
- * normal dispatch operation. Does not bubble.
4897
- *
4898
- * @param {!EventTarget} target
4899
- * @param {!Event} event
4900
- * @return {boolean}
4901
- */
4902
-
4903
-
4904
- function safeDispatchEvent(target, event) {
4905
- var check = 'on' + event.type.toLowerCase();
4906
-
4907
- if (typeof target[check] === 'function') {
4908
- target[check](event);
4909
- }
4910
-
4911
- return target.dispatchEvent(event);
4912
- }
4913
- /**
4914
- * @param {Element} el to check for stacking context
4915
- * @return {boolean} whether this el or its parents creates a stacking context
4916
- */
4917
-
4918
-
4919
- function createsStackingContext(el) {
4920
- while (el && el !== document.body) {
4921
- var s = window.getComputedStyle(el);
4922
-
4923
- var invalid = function (k, ok) {
4924
- return !(s[k] === undefined || s[k] === ok);
4925
- };
4926
-
4927
- if (s.opacity < 1 || invalid('zIndex', 'auto') || invalid('transform', 'none') || invalid('mixBlendMode', 'normal') || invalid('filter', 'none') || invalid('perspective', 'none') || s['isolation'] === 'isolate' || s.position === 'fixed' || s.webkitOverflowScrolling === 'touch') {
4928
- return true;
4929
- }
4930
-
4931
- el = el.parentElement;
4932
- }
4933
-
4934
- return false;
4935
- }
4936
- /**
4937
- * Finds the nearest <dialog> from the passed element.
4938
- *
4939
- * @param {Element} el to search from
4940
- * @return {HTMLDialogElement} dialog found
4941
- */
4942
-
4943
-
4944
- function findNearestDialog(el) {
4945
- while (el) {
4946
- if (el.localName === 'dialog') {
4947
- return (
4948
- /** @type {HTMLDialogElement} */
4949
- el
4950
- );
4951
- }
4952
-
4953
- if (el.parentElement) {
4954
- el = el.parentElement;
4955
- } else if (el.parentNode) {
4956
- el = el.parentNode.host;
4957
- } else {
4958
- el = null;
4959
- }
4960
- }
4961
-
4962
- return null;
4963
- }
4964
- /**
4965
- * Blur the specified element, as long as it's not the HTML body element.
4966
- * This works around an IE9/10 bug - blurring the body causes Windows to
4967
- * blur the whole application.
4968
- *
4969
- * @param {Element} el to blur
4970
- */
4971
-
4972
-
4973
- function safeBlur(el) {
4974
- // Find the actual focused element when the active element is inside a shadow root
4975
- while (el && el.shadowRoot && el.shadowRoot.activeElement) {
4976
- el = el.shadowRoot.activeElement;
4977
- }
4978
-
4979
- if (el && el.blur && el !== document.body) {
4980
- el.blur();
4981
- }
4982
- }
4983
- /**
4984
- * @param {!NodeList} nodeList to search
4985
- * @param {Node} node to find
4986
- * @return {boolean} whether node is inside nodeList
4987
- */
4988
-
4989
-
4990
- function inNodeList(nodeList, node) {
4991
- for (var i = 0; i < nodeList.length; ++i) {
4992
- if (nodeList[i] === node) {
4993
- return true;
4994
- }
4995
- }
4996
-
4997
- return false;
4998
- }
4999
- /**
5000
- * @param {HTMLFormElement} el to check
5001
- * @return {boolean} whether this form has method="dialog"
5002
- */
5003
-
5004
-
5005
- function isFormMethodDialog(el) {
5006
- if (!el || !el.hasAttribute('method')) {
5007
- return false;
5008
- }
5009
-
5010
- return el.getAttribute('method').toLowerCase() === 'dialog';
5011
- }
5012
- /**
5013
- * @param {!DocumentFragment|!Element} hostElement
5014
- * @return {?Element}
5015
- */
5016
-
5017
-
5018
- function findFocusableElementWithin(hostElement) {
5019
- // Note that this is 'any focusable area'. This list is probably not exhaustive, but the
5020
- // alternative involves stepping through and trying to focus everything.
5021
- var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
5022
- var query = opts.map(function (el) {
5023
- return el + ':not([disabled])';
5024
- }); // TODO(samthor): tabindex values that are not numeric are not focusable.
5025
-
5026
- query.push('[tabindex]:not([disabled]):not([tabindex=""])'); // tabindex != "", not disabled
5027
-
5028
- var target = hostElement.querySelector(query.join(', '));
5029
-
5030
- if (!target && 'attachShadow' in Element.prototype) {
5031
- // If we haven't found a focusable target, see if the host element contains an element
5032
- // which has a shadowRoot.
5033
- // Recursively search for the first focusable item in shadow roots.
5034
- var elems = hostElement.querySelectorAll('*');
5035
-
5036
- for (var i = 0; i < elems.length; i++) {
5037
- if (elems[i].tagName && elems[i].shadowRoot) {
5038
- target = findFocusableElementWithin(elems[i].shadowRoot);
5039
-
5040
- if (target) {
5041
- break;
5042
- }
5043
- }
5044
- }
5045
- }
5046
-
5047
- return target;
5048
- }
5049
- /**
5050
- * Determines if an element is attached to the DOM.
5051
- * @param {Element} element to check
5052
- * @return {boolean} whether the element is in DOM
5053
- */
5054
-
5055
-
5056
- function isConnected(element) {
5057
- return element.isConnected || document.body.contains(element);
5058
- }
5059
- /**
5060
- * @param {!Event} event
5061
- * @return {?Element}
5062
- */
5063
-
5064
-
5065
- function findFormSubmitter(event) {
5066
- if (event.submitter) {
5067
- return event.submitter;
5068
- }
5069
-
5070
- var form = event.target;
5071
-
5072
- if (!(form instanceof HTMLFormElement)) {
5073
- return null;
5074
- }
5075
-
5076
- var submitter = dialogPolyfill.formSubmitter;
5077
-
5078
- if (!submitter) {
5079
- var target = event.target;
5080
- var root = 'getRootNode' in target && target.getRootNode() || document;
5081
- submitter = root.activeElement;
5082
- }
5083
-
5084
- if (!submitter || submitter.form !== form) {
5085
- return null;
5086
- }
5087
-
5088
- return submitter;
5089
- }
5090
- /**
5091
- * @param {!Event} event
5092
- */
5093
-
5094
-
5095
- function maybeHandleSubmit(event) {
5096
- if (event.defaultPrevented) {
5097
- return;
5098
- }
5099
-
5100
- var form =
5101
- /** @type {!HTMLFormElement} */
5102
- event.target; // We'd have a value if we clicked on an imagemap.
5103
-
5104
- var value = dialogPolyfill.imagemapUseValue;
5105
- var submitter = findFormSubmitter(event);
5106
-
5107
- if (value === null && submitter) {
5108
- value = submitter.value;
5109
- } // There should always be a dialog as this handler is added specifically on them, but check just
5110
- // in case.
5111
-
5112
-
5113
- var dialog = findNearestDialog(form);
5114
-
5115
- if (!dialog) {
5116
- return;
5117
- } // Prefer formmethod on the button.
5118
-
5119
-
5120
- var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
5121
-
5122
- if (formmethod !== 'dialog') {
5123
- return;
5124
- }
5125
-
5126
- event.preventDefault();
5127
-
5128
- if (value != null) {
5129
- // nb. we explicitly check against null/undefined
5130
- dialog.close(value);
5131
- } else {
5132
- dialog.close();
5133
- }
5134
- }
5135
- /**
5136
- * @param {!HTMLDialogElement} dialog to upgrade
5137
- * @constructor
5138
- */
5139
-
5140
-
5141
- function dialogPolyfillInfo(dialog) {
5142
- this.dialog_ = dialog;
5143
- this.replacedStyleTop_ = false;
5144
- this.openAsModal_ = false; // Set a11y role. Browsers that support dialog implicitly know this already.
5145
-
5146
- if (!dialog.hasAttribute('role')) {
5147
- dialog.setAttribute('role', 'dialog');
5148
- }
5149
-
5150
- dialog.show = this.show.bind(this);
5151
- dialog.showModal = this.showModal.bind(this);
5152
- dialog.close = this.close.bind(this);
5153
- dialog.addEventListener('submit', maybeHandleSubmit, false);
5154
-
5155
- if (!('returnValue' in dialog)) {
5156
- dialog.returnValue = '';
5157
- }
5158
-
5159
- if ('MutationObserver' in window) {
5160
- var mo = new MutationObserver(this.maybeHideModal.bind(this));
5161
- mo.observe(dialog, {
5162
- attributes: true,
5163
- attributeFilter: ['open']
5164
- });
5165
- } else {
5166
- // IE10 and below support. Note that DOMNodeRemoved etc fire _before_ removal. They also
5167
- // seem to fire even if the element was removed as part of a parent removal. Use the removed
5168
- // events to force downgrade (useful if removed/immediately added).
5169
- var removed = false;
5170
-
5171
- var cb = function () {
5172
- removed ? this.downgradeModal() : this.maybeHideModal();
5173
- removed = false;
5174
- }.bind(this);
5175
-
5176
- var timeout;
5177
-
5178
- var delayModel = function (ev) {
5179
- if (ev.target !== dialog) {
5180
- return;
5181
- } // not for a child element
5182
-
5183
-
5184
- var cand = 'DOMNodeRemoved';
5185
- removed |= ev.type.substr(0, cand.length) === cand;
5186
- window.clearTimeout(timeout);
5187
- timeout = window.setTimeout(cb, 0);
5188
- };
5189
-
5190
- ['DOMAttrModified', 'DOMNodeRemoved', 'DOMNodeRemovedFromDocument'].forEach(function (name) {
5191
- dialog.addEventListener(name, delayModel);
5192
- });
5193
- } // Note that the DOM is observed inside DialogManager while any dialog
5194
- // is being displayed as a modal, to catch modal removal from the DOM.
5195
-
5196
-
5197
- Object.defineProperty(dialog, 'open', {
5198
- set: this.setOpen.bind(this),
5199
- get: dialog.hasAttribute.bind(dialog, 'open')
5200
- });
5201
- this.backdrop_ = document.createElement('div');
5202
- this.backdrop_.className = 'backdrop';
5203
- this.backdrop_.addEventListener('mouseup', this.backdropMouseEvent_.bind(this));
5204
- this.backdrop_.addEventListener('mousedown', this.backdropMouseEvent_.bind(this));
5205
- this.backdrop_.addEventListener('click', this.backdropMouseEvent_.bind(this));
5206
- }
5207
-
5208
- dialogPolyfillInfo.prototype =
5209
- /** @type {HTMLDialogElement.prototype} */
5210
- {
5211
- get dialog() {
5212
- return this.dialog_;
5213
- },
5214
-
5215
- /**
5216
- * Maybe remove this dialog from the modal top layer. This is called when
5217
- * a modal dialog may no longer be tenable, e.g., when the dialog is no
5218
- * longer open or is no longer part of the DOM.
5219
- */
5220
- maybeHideModal: function () {
5221
- if (this.dialog_.hasAttribute('open') && isConnected(this.dialog_)) {
5222
- return;
5223
- }
5224
-
5225
- this.downgradeModal();
5226
- },
5227
-
5228
- /**
5229
- * Remove this dialog from the modal top layer, leaving it as a non-modal.
5230
- */
5231
- downgradeModal: function () {
5232
- if (!this.openAsModal_) {
5233
- return;
5234
- }
5235
-
5236
- this.openAsModal_ = false;
5237
- this.dialog_.style.zIndex = ''; // This won't match the native <dialog> exactly because if the user set top on a centered
5238
- // polyfill dialog, that top gets thrown away when the dialog is closed. Not sure it's
5239
- // possible to polyfill this perfectly.
5240
-
5241
- if (this.replacedStyleTop_) {
5242
- this.dialog_.style.top = '';
5243
- this.replacedStyleTop_ = false;
5244
- } // Clear the backdrop and remove from the manager.
5245
-
5246
-
5247
- this.backdrop_.parentNode && this.backdrop_.parentNode.removeChild(this.backdrop_);
5248
- dialogPolyfill.dm.removeDialog(this);
5249
- },
5250
-
5251
- /**
5252
- * @param {boolean} value whether to open or close this dialog
5253
- */
5254
- setOpen: function (value) {
5255
- if (value) {
5256
- this.dialog_.hasAttribute('open') || this.dialog_.setAttribute('open', '');
5257
- } else {
5258
- this.dialog_.removeAttribute('open');
5259
- this.maybeHideModal(); // nb. redundant with MutationObserver
5260
- }
5261
- },
5262
-
5263
- /**
5264
- * Handles mouse events ('mouseup', 'mousedown', 'click') on the fake .backdrop element, redirecting them as if
5265
- * they were on the dialog itself.
5266
- *
5267
- * @param {!Event} e to redirect
5268
- */
5269
- backdropMouseEvent_: function (e) {
5270
- if (!this.dialog_.hasAttribute('tabindex')) {
5271
- // Clicking on the backdrop should move the implicit cursor, even if dialog cannot be
5272
- // focused. Create a fake thing to focus on. If the backdrop was _before_ the dialog, this
5273
- // would not be needed - clicks would move the implicit cursor there.
5274
- var fake = document.createElement('div');
5275
- this.dialog_.insertBefore(fake, this.dialog_.firstChild);
5276
- fake.tabIndex = -1;
5277
- fake.focus();
5278
- this.dialog_.removeChild(fake);
5279
- } else {
5280
- this.dialog_.focus();
5281
- }
5282
-
5283
- var redirectedEvent = document.createEvent('MouseEvents');
5284
- redirectedEvent.initMouseEvent(e.type, e.bubbles, e.cancelable, window, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
5285
- this.dialog_.dispatchEvent(redirectedEvent);
5286
- e.stopPropagation();
5287
- },
5288
-
5289
- /**
5290
- * Focuses on the first focusable element within the dialog. This will always blur the current
5291
- * focus, even if nothing within the dialog is found.
5292
- */
5293
- focus_: function () {
5294
- // Find element with `autofocus` attribute, or fall back to the first form/tabindex control.
5295
- var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
5296
-
5297
- if (!target && this.dialog_.tabIndex >= 0) {
5298
- target = this.dialog_;
5299
- }
5300
-
5301
- if (!target) {
5302
- target = findFocusableElementWithin(this.dialog_);
5303
- }
5304
-
5305
- safeBlur(document.activeElement);
5306
- target && target.focus();
5307
- },
5308
-
5309
- /**
5310
- * Sets the zIndex for the backdrop and dialog.
5311
- *
5312
- * @param {number} dialogZ
5313
- * @param {number} backdropZ
5314
- */
5315
- updateZIndex: function (dialogZ, backdropZ) {
5316
- if (dialogZ < backdropZ) {
5317
- throw new Error('dialogZ should never be < backdropZ');
5318
- }
5319
-
5320
- this.dialog_.style.zIndex = dialogZ;
5321
- this.backdrop_.style.zIndex = backdropZ;
5322
- },
5323
-
5324
- /**
5325
- * Shows the dialog. If the dialog is already open, this does nothing.
5326
- */
5327
- show: function () {
5328
- if (!this.dialog_.open) {
5329
- this.setOpen(true);
5330
- this.focus_();
5331
- }
5332
- },
5333
-
5334
- /**
5335
- * Show this dialog modally.
5336
- */
5337
- showModal: function () {
5338
- if (this.dialog_.hasAttribute('open')) {
5339
- throw new Error('Failed to execute \'showModal\' on dialog: The element is already open, and therefore cannot be opened modally.');
5340
- }
5341
-
5342
- if (!isConnected(this.dialog_)) {
5343
- throw new Error('Failed to execute \'showModal\' on dialog: The element is not in a Document.');
5344
- }
5345
-
5346
- if (!dialogPolyfill.dm.pushDialog(this)) {
5347
- throw new Error('Failed to execute \'showModal\' on dialog: There are too many open modal dialogs.');
5348
- }
5349
-
5350
- if (createsStackingContext(this.dialog_.parentElement)) {
5351
- console.warn('A dialog is being shown inside a stacking context. ' + 'This may cause it to be unusable. For more information, see this link: ' + 'https://github.com/GoogleChrome/dialog-polyfill/#stacking-context');
5352
- }
5353
-
5354
- this.setOpen(true);
5355
- this.openAsModal_ = true; // Optionally center vertically, relative to the current viewport.
5356
-
5357
- if (dialogPolyfill.needsCentering(this.dialog_)) {
5358
- dialogPolyfill.reposition(this.dialog_);
5359
- this.replacedStyleTop_ = true;
5360
- } else {
5361
- this.replacedStyleTop_ = false;
5362
- } // Insert backdrop.
5363
-
5364
-
5365
- this.dialog_.parentNode.insertBefore(this.backdrop_, this.dialog_.nextSibling); // Focus on whatever inside the dialog.
5366
-
5367
- this.focus_();
5368
- },
5369
-
5370
- /**
5371
- * Closes this HTMLDialogElement. This is optional vs clearing the open
5372
- * attribute, however this fires a 'close' event.
5373
- *
5374
- * @param {string=} opt_returnValue to use as the returnValue
5375
- */
5376
- close: function (opt_returnValue) {
5377
- if (!this.dialog_.hasAttribute('open')) {
5378
- throw new Error('Failed to execute \'close\' on dialog: The element does not have an \'open\' attribute, and therefore cannot be closed.');
5379
- }
5380
-
5381
- this.setOpen(false); // Leave returnValue untouched in case it was set directly on the element
5382
-
5383
- if (opt_returnValue !== undefined) {
5384
- this.dialog_.returnValue = opt_returnValue;
5385
- } // Triggering "close" event for any attached listeners on the <dialog>.
5386
-
5387
-
5388
- var closeEvent = new supportCustomEvent('close', {
5389
- bubbles: false,
5390
- cancelable: false
5391
- });
5392
- safeDispatchEvent(this.dialog_, closeEvent);
5393
- }
5394
- };
5395
- var dialogPolyfill = {};
5396
-
5397
- dialogPolyfill.reposition = function (element) {
5398
- var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
5399
- var topValue = scrollTop + (window.innerHeight - element.offsetHeight) / 2;
5400
- element.style.top = Math.max(scrollTop, topValue) + 'px';
5401
- };
5402
-
5403
- dialogPolyfill.isInlinePositionSetByStylesheet = function (element) {
5404
- for (var i = 0; i < document.styleSheets.length; ++i) {
5405
- var styleSheet = document.styleSheets[i];
5406
- var cssRules = null; // Some browsers throw on cssRules.
5407
-
5408
- try {
5409
- cssRules = styleSheet.cssRules;
5410
- } catch (e) {}
5411
-
5412
- if (!cssRules) {
5413
- continue;
5414
- }
5415
-
5416
- for (var j = 0; j < cssRules.length; ++j) {
5417
- var rule = cssRules[j];
5418
- var selectedNodes = null; // Ignore errors on invalid selector texts.
5419
-
5420
- try {
5421
- selectedNodes = document.querySelectorAll(rule.selectorText);
5422
- } catch (e) {}
5423
-
5424
- if (!selectedNodes || !inNodeList(selectedNodes, element)) {
5425
- continue;
5426
- }
5427
-
5428
- var cssTop = rule.style.getPropertyValue('top');
5429
- var cssBottom = rule.style.getPropertyValue('bottom');
5430
-
5431
- if (cssTop && cssTop !== 'auto' || cssBottom && cssBottom !== 'auto') {
5432
- return true;
5433
- }
5434
- }
5435
- }
5436
-
5437
- return false;
5438
- };
5439
-
5440
- dialogPolyfill.needsCentering = function (dialog) {
5441
- var computedStyle = window.getComputedStyle(dialog);
5442
-
5443
- if (computedStyle.position !== 'absolute') {
5444
- return false;
5445
- } // We must determine whether the top/bottom specified value is non-auto. In
5446
- // WebKit/Blink, checking computedStyle.top == 'auto' is sufficient, but
5447
- // Firefox returns the used value. So we do this crazy thing instead: check
5448
- // the inline style and then go through CSS rules.
5449
-
5450
-
5451
- if (dialog.style.top !== 'auto' && dialog.style.top !== '' || dialog.style.bottom !== 'auto' && dialog.style.bottom !== '') {
5452
- return false;
5453
- }
5454
-
5455
- return !dialogPolyfill.isInlinePositionSetByStylesheet(dialog);
5456
- };
5457
- /**
5458
- * @param {!Element} element to force upgrade
5459
- */
5460
-
5461
-
5462
- dialogPolyfill.forceRegisterDialog = function (element) {
5463
- if (window.HTMLDialogElement || element.showModal) {
5464
- console.warn('This browser already supports <dialog>, the polyfill ' + 'may not work correctly', element);
5465
- }
5466
-
5467
- if (element.localName !== 'dialog') {
5468
- throw new Error('Failed to register dialog: The element is not a dialog.');
5469
- }
5470
-
5471
- new dialogPolyfillInfo(
5472
- /** @type {!HTMLDialogElement} */
5473
- element);
5474
- };
5475
- /**
5476
- * @param {!Element} element to upgrade, if necessary
5477
- */
5478
-
5479
-
5480
- dialogPolyfill.registerDialog = function (element) {
5481
- if (!element.showModal) {
5482
- dialogPolyfill.forceRegisterDialog(element);
5483
- }
5484
- };
5485
- /**
5486
- * @constructor
5487
- */
5488
-
5489
-
5490
- dialogPolyfill.DialogManager = function () {
5491
- /** @type {!Array<!dialogPolyfillInfo>} */
5492
- this.pendingDialogStack = [];
5493
- var checkDOM = this.checkDOM_.bind(this); // The overlay is used to simulate how a modal dialog blocks the document.
5494
- // The blocking dialog is positioned on top of the overlay, and the rest of
5495
- // the dialogs on the pending dialog stack are positioned below it. In the
5496
- // actual implementation, the modal dialog stacking is controlled by the
5497
- // top layer, where z-index has no effect.
5498
-
5499
- this.overlay = document.createElement('div');
5500
- this.overlay.className = '_dialog_overlay';
5501
- this.overlay.addEventListener('click', function (e) {
5502
- this.forwardTab_ = undefined;
5503
- e.stopPropagation();
5504
- checkDOM([]); // sanity-check DOM
5505
- }.bind(this));
5506
- this.handleKey_ = this.handleKey_.bind(this);
5507
- this.handleFocus_ = this.handleFocus_.bind(this);
5508
- this.zIndexLow_ = 100000;
5509
- this.zIndexHigh_ = 100000 + 150;
5510
- this.forwardTab_ = undefined;
5511
-
5512
- if ('MutationObserver' in window) {
5513
- this.mo_ = new MutationObserver(function (records) {
5514
- var removed = [];
5515
- records.forEach(function (rec) {
5516
- for (var i = 0, c; c = rec.removedNodes[i]; ++i) {
5517
- if (!(c instanceof Element)) {
5518
- continue;
5519
- } else if (c.localName === 'dialog') {
5520
- removed.push(c);
5521
- }
5522
-
5523
- removed = removed.concat(c.querySelectorAll('dialog'));
5524
- }
5525
- });
5526
- removed.length && checkDOM(removed);
5527
- });
5528
- }
5529
- };
5530
- /**
5531
- * Called on the first modal dialog being shown. Adds the overlay and related
5532
- * handlers.
5533
- */
5534
-
5535
-
5536
- dialogPolyfill.DialogManager.prototype.blockDocument = function () {
5537
- document.documentElement.addEventListener('focus', this.handleFocus_, true);
5538
- document.addEventListener('keydown', this.handleKey_);
5539
- this.mo_ && this.mo_.observe(document, {
5540
- childList: true,
5541
- subtree: true
5542
- });
5543
- };
5544
- /**
5545
- * Called on the first modal dialog being removed, i.e., when no more modal
5546
- * dialogs are visible.
5547
- */
5548
-
5549
-
5550
- dialogPolyfill.DialogManager.prototype.unblockDocument = function () {
5551
- document.documentElement.removeEventListener('focus', this.handleFocus_, true);
5552
- document.removeEventListener('keydown', this.handleKey_);
5553
- this.mo_ && this.mo_.disconnect();
5554
- };
5555
- /**
5556
- * Updates the stacking of all known dialogs.
5557
- */
5558
-
5559
-
5560
- dialogPolyfill.DialogManager.prototype.updateStacking = function () {
5561
- var zIndex = this.zIndexHigh_;
5562
-
5563
- for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
5564
- dpi.updateZIndex(--zIndex, --zIndex);
5565
-
5566
- if (i === 0) {
5567
- this.overlay.style.zIndex = --zIndex;
5568
- }
5569
- } // Make the overlay a sibling of the dialog itself.
5570
-
5571
-
5572
- var last = this.pendingDialogStack[0];
5573
-
5574
- if (last) {
5575
- var p = last.dialog.parentNode || document.body;
5576
- p.appendChild(this.overlay);
5577
- } else if (this.overlay.parentNode) {
5578
- this.overlay.parentNode.removeChild(this.overlay);
5579
- }
5580
- };
5581
- /**
5582
- * @param {Element} candidate to check if contained or is the top-most modal dialog
5583
- * @return {boolean} whether candidate is contained in top dialog
5584
- */
5585
-
5586
-
5587
- dialogPolyfill.DialogManager.prototype.containedByTopDialog_ = function (candidate) {
5588
- while (candidate = findNearestDialog(candidate)) {
5589
- for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
5590
- if (dpi.dialog === candidate) {
5591
- return i === 0; // only valid if top-most
5592
- }
5593
- }
5594
-
5595
- candidate = candidate.parentElement;
5596
- }
5597
-
5598
- return false;
5599
- };
5600
-
5601
- dialogPolyfill.DialogManager.prototype.handleFocus_ = function (event) {
5602
- var target = event.composedPath ? event.composedPath()[0] : event.target;
5603
-
5604
- if (this.containedByTopDialog_(target)) {
5605
- return;
5606
- }
5607
-
5608
- if (document.activeElement === document.documentElement) {
5609
- return;
5610
- }
5611
-
5612
- event.preventDefault();
5613
- event.stopPropagation();
5614
- safeBlur(
5615
- /** @type {Element} */
5616
- target);
5617
-
5618
- if (this.forwardTab_ === undefined) {
5619
- return;
5620
- } // move focus only from a tab key
5621
-
5622
-
5623
- var dpi = this.pendingDialogStack[0];
5624
- var dialog = dpi.dialog;
5625
- var position = dialog.compareDocumentPosition(target);
5626
-
5627
- if (position & Node.DOCUMENT_POSITION_PRECEDING) {
5628
- if (this.forwardTab_) {
5629
- // forward
5630
- dpi.focus_();
5631
- } else if (target !== document.documentElement) {
5632
- // backwards if we're not already focused on <html>
5633
- document.documentElement.focus();
5634
- }
5635
- }
5636
-
5637
- return false;
5638
- };
5639
-
5640
- dialogPolyfill.DialogManager.prototype.handleKey_ = function (event) {
5641
- this.forwardTab_ = undefined;
5642
-
5643
- if (event.keyCode === 27) {
5644
- event.preventDefault();
5645
- event.stopPropagation();
5646
- var cancelEvent = new supportCustomEvent('cancel', {
5647
- bubbles: false,
5648
- cancelable: true
5649
- });
5650
- var dpi = this.pendingDialogStack[0];
5651
-
5652
- if (dpi && safeDispatchEvent(dpi.dialog, cancelEvent)) {
5653
- dpi.dialog.close();
5654
- }
5655
- } else if (event.keyCode === 9) {
5656
- this.forwardTab_ = !event.shiftKey;
5657
- }
5658
- };
5659
- /**
5660
- * Finds and downgrades any known modal dialogs that are no longer displayed. Dialogs that are
5661
- * removed and immediately readded don't stay modal, they become normal.
5662
- *
5663
- * @param {!Array<!HTMLDialogElement>} removed that have definitely been removed
5664
- */
5665
-
5666
-
5667
- dialogPolyfill.DialogManager.prototype.checkDOM_ = function (removed) {
5668
- // This operates on a clone because it may cause it to change. Each change also calls
5669
- // updateStacking, which only actually needs to happen once. But who removes many modal dialogs
5670
- // at a time?!
5671
- var clone = this.pendingDialogStack.slice();
5672
- clone.forEach(function (dpi) {
5673
- if (removed.indexOf(dpi.dialog) !== -1) {
5674
- dpi.downgradeModal();
5675
- } else {
5676
- dpi.maybeHideModal();
5677
- }
5678
- });
5679
- };
5680
- /**
5681
- * @param {!dialogPolyfillInfo} dpi
5682
- * @return {boolean} whether the dialog was allowed
5683
- */
5684
-
5685
-
5686
- dialogPolyfill.DialogManager.prototype.pushDialog = function (dpi) {
5687
- var allowed = (this.zIndexHigh_ - this.zIndexLow_) / 2 - 1;
5688
-
5689
- if (this.pendingDialogStack.length >= allowed) {
5690
- return false;
5691
- }
5692
-
5693
- if (this.pendingDialogStack.unshift(dpi) === 1) {
5694
- this.blockDocument();
5695
- }
5696
-
5697
- this.updateStacking();
5698
- return true;
5699
- };
5700
- /**
5701
- * @param {!dialogPolyfillInfo} dpi
5702
- */
5703
-
5704
-
5705
- dialogPolyfill.DialogManager.prototype.removeDialog = function (dpi) {
5706
- var index = this.pendingDialogStack.indexOf(dpi);
5707
-
5708
- if (index === -1) {
5709
- return;
5710
- }
5711
-
5712
- this.pendingDialogStack.splice(index, 1);
5713
-
5714
- if (this.pendingDialogStack.length === 0) {
5715
- this.unblockDocument();
5716
- }
5717
-
5718
- this.updateStacking();
5719
- };
5720
-
5721
- dialogPolyfill.dm = new dialogPolyfill.DialogManager();
5722
- dialogPolyfill.formSubmitter = null;
5723
- dialogPolyfill.imagemapUseValue = null;
5724
- /**
5725
- * Installs global handlers, such as click listers and native method overrides. These are needed
5726
- * even if a no dialog is registered, as they deal with <form method="dialog">.
5727
- */
5728
-
5729
- if (window.HTMLDialogElement === undefined) {
5730
- /**
5731
- * If HTMLFormElement translates method="DIALOG" into 'get', then replace the descriptor with
5732
- * one that returns the correct value.
5733
- */
5734
- var testForm = document.createElement('form');
5735
- testForm.setAttribute('method', 'dialog');
5736
-
5737
- if (testForm.method !== 'dialog') {
5738
- var methodDescriptor = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'method');
5739
-
5740
- if (methodDescriptor) {
5741
- // nb. Some older iOS and older PhantomJS fail to return the descriptor. Don't do anything
5742
- // and don't bother to update the element.
5743
- var realGet = methodDescriptor.get;
5744
-
5745
- methodDescriptor.get = function () {
5746
- if (isFormMethodDialog(this)) {
5747
- return 'dialog';
5748
- }
5749
-
5750
- return realGet.call(this);
5751
- };
5752
-
5753
- var realSet = methodDescriptor.set;
5754
- /** @this {HTMLElement} */
5755
-
5756
- methodDescriptor.set = function (v) {
5757
- if (typeof v === 'string' && v.toLowerCase() === 'dialog') {
5758
- return this.setAttribute('method', v);
5759
- }
5760
-
5761
- return realSet.call(this, v);
5762
- };
5763
-
5764
- Object.defineProperty(HTMLFormElement.prototype, 'method', methodDescriptor);
5765
- }
5766
- }
5767
- /**
5768
- * Global 'click' handler, to capture the <input type="submit"> or <button> element which has
5769
- * submitted a <form method="dialog">. Needed as Safari and others don't report this inside
5770
- * document.activeElement.
5771
- */
5772
-
5773
-
5774
- document.addEventListener('click', function (ev) {
5775
- dialogPolyfill.formSubmitter = null;
5776
- dialogPolyfill.imagemapUseValue = null;
5777
-
5778
- if (ev.defaultPrevented) {
5779
- return;
5780
- } // e.g. a submit which prevents default submission
5781
-
5782
-
5783
- var target =
5784
- /** @type {Element} */
5785
- ev.target;
5786
-
5787
- if ('composedPath' in ev) {
5788
- var path = ev.composedPath();
5789
- target = path.shift() || target;
5790
- }
5791
-
5792
- if (!target || !isFormMethodDialog(target.form)) {
5793
- return;
5794
- }
5795
-
5796
- var valid = target.type === 'submit' && ['button', 'input'].indexOf(target.localName) > -1;
5797
-
5798
- if (!valid) {
5799
- if (!(target.localName === 'input' && target.type === 'image')) {
5800
- return;
5801
- } // this is a <input type="image">, which can submit forms
5802
-
5803
-
5804
- dialogPolyfill.imagemapUseValue = ev.offsetX + ',' + ev.offsetY;
5805
- }
5806
-
5807
- var dialog = findNearestDialog(target);
5808
-
5809
- if (!dialog) {
5810
- return;
5811
- }
5812
-
5813
- dialogPolyfill.formSubmitter = target;
5814
- }, false);
5815
- /**
5816
- * Global 'submit' handler. This handles submits of `method="dialog"` which are invalid, i.e.,
5817
- * outside a dialog. They get prevented.
5818
- */
5819
-
5820
- document.addEventListener('submit', function (ev) {
5821
- var form = ev.target;
5822
- var dialog = findNearestDialog(form);
5823
-
5824
- if (dialog) {
5825
- return; // ignore, handle there
5826
- }
5827
-
5828
- var submitter = findFormSubmitter(ev);
5829
- var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
5830
-
5831
- if (formmethod === 'dialog') {
5832
- ev.preventDefault();
5833
- }
5834
- });
5835
- /**
5836
- * Replace the native HTMLFormElement.submit() method, as it won't fire the
5837
- * submit event and give us a chance to respond.
5838
- */
5839
-
5840
- var nativeFormSubmit = HTMLFormElement.prototype.submit;
5841
-
5842
- var replacementFormSubmit = function () {
5843
- if (!isFormMethodDialog(this)) {
5844
- return nativeFormSubmit.call(this);
5845
- }
5846
-
5847
- var dialog = findNearestDialog(this);
5848
- dialog && dialog.close();
5849
- };
5850
-
5851
- HTMLFormElement.prototype.submit = replacementFormSubmit;
5852
- }
5853
-
5854
4881
  /*
5855
4882
  Possible todos:
5856
4883
  0. Add XSLT to JML-string stylesheet (or even vice versa)
@@ -7801,7 +6828,6 @@ class Dialog {
7801
6828
  }
7802
6829
 
7803
6830
  const dialog = jml('dialog', atts, children, $$1('#main'));
7804
- dialogPolyfill.registerDialog(dialog);
7805
6831
  dialog.showModal();
7806
6832
 
7807
6833
  if (remove) {
@@ -7896,7 +6922,6 @@ class Dialog {
7896
6922
 
7897
6923
  }
7898
6924
  }, [this.localeStrings.ok]]]]] : [])], $$1('#main'));
7899
- dialogPolyfill.registerDialog(dialog);
7900
6925
  dialog.showModal();
7901
6926
  });
7902
6927
  }
@@ -7970,7 +6995,6 @@ class Dialog {
7970
6995
 
7971
6996
  }
7972
6997
  }, [this.localeStrings.cancel]]]]], $$1('#main'));
7973
- dialogPolyfill.registerDialog(dialog);
7974
6998
  dialog.showModal();
7975
6999
  });
7976
7000
  }
@@ -15472,15 +14496,6 @@ class PluginsForWork {
15472
14496
 
15473
14497
  }
15474
14498
 
15475
- let path, babelRegister;
15476
-
15477
- if (typeof process !== 'undefined') {
15478
- /* eslint-disable node/global-require */
15479
- path = require('path');
15480
- babelRegister = require('@babel/register');
15481
- /* eslint-enable node/global-require */
15482
- }
15483
-
15484
14499
  const getWorkFiles = async function getWorkFiles(files = this.files) {
15485
14500
  const filesObj = await getJSON$1(files);
15486
14501
  const dataFiles = [];
@@ -15625,20 +14640,7 @@ const getWorkData = async function ({
15625
14640
 
15626
14641
  const pluginFieldMappings = pluginFieldMappingForWork;
15627
14642
  const [schemaObj, pluginObjects] = await Promise.all([getMetadata(schemaFile, schemaProperty, basePath), getPlugins ? Promise.all(pluginPaths.map(pluginPath => {
15628
- if (typeof process !== 'undefined') {
15629
- pluginPath = path.resolve(path.join(process.cwd(), 'node_modules/textbrowser/server', pluginPath));
15630
- babelRegister({
15631
- presets: ['@babel/env']
15632
- });
15633
- return Promise.resolve().then(() => {
15634
- return require(pluginPath); // eslint-disable-line node/global-require, import/no-dynamic-require
15635
- }).catch(err => {
15636
- // E.g., with tooltips plugin
15637
- console.log('err', err);
15638
- });
15639
- } // eslint-disable-next-line no-unsanitized/method
15640
-
15641
-
14643
+ // eslint-disable-next-line no-unsanitized/method
15642
14644
  return import(pluginPath);
15643
14645
  })) : null]);
15644
14646
  const pluginsForWork = new PluginsForWork({
@@ -18288,6 +17290,9 @@ var rtlDetect_1 = {
18288
17290
  getLangDir: rtlDetect.getLangDir
18289
17291
  };
18290
17292
 
17293
+ const {
17294
+ getLangDir
17295
+ } = rtlDetect_1;
18291
17296
  const fieldValueAliasRegex = /^.* \((.*?)\)$/;
18292
17297
 
18293
17298
  const getRawFieldValue = v => {
@@ -19188,7 +18193,7 @@ const resultsDisplayServerOrClient = async function resultsDisplayServerOrClient
19188
18193
  applicableFieldIdx,
19189
18194
  applicableFieldText,
19190
18195
  fieldLang,
19191
- getLangDir: rtlDetect_1.getLangDir,
18196
+ getLangDir,
19192
18197
  meta,
19193
18198
  metaApplicableField,
19194
18199
  $p,
@@ -19199,13 +18204,13 @@ const resultsDisplayServerOrClient = async function resultsDisplayServerOrClient
19199
18204
  });
19200
18205
  }
19201
18206
 
19202
- const localeDir = rtlDetect_1.getLangDir(preferredLocale);
18207
+ const localeDir = getLangDir(preferredLocale);
19203
18208
  const fieldDirs = fieldLangs.map(langCode => {
19204
18209
  if (!langCode) {
19205
18210
  return null;
19206
18211
  }
19207
18212
 
19208
- const langDir = rtlDetect_1.getLangDir(langCode);
18213
+ const langDir = getLangDir(langCode);
19209
18214
  return langDir !== localeDir ? langDir : null;
19210
18215
  });
19211
18216
  const templateArgs = {
@@ -19427,7 +18432,7 @@ class TextBrowser {
19427
18432
  const builtinIndex = stylesheets.indexOf('@builtin');
19428
18433
 
19429
18434
  if (builtinIndex !== -1) {
19430
- stylesheets.splice(builtinIndex, 1, new URL('index.css', moduleURL).href, new URL('../../dialog-polyfill/dist/dialog-polyfill.css', moduleURL).href);
18435
+ stylesheets.splice(builtinIndex, 1, new URL('index.css', moduleURL).href);
19431
18436
  }
19432
18437
 
19433
18438
  this.stylesheets = stylesheets;