@descope/web-components-ui 1.0.192 → 1.0.193

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,6 @@
3
3
  var merge = require('lodash.merge');
4
4
  var set = require('lodash.set');
5
5
  var Color = require('color');
6
- require('element-internals-polyfill');
7
6
 
8
7
  const DESCOPE_PREFIX = 'descope';
9
8
  const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3;
@@ -1032,6 +1031,813 @@ const createProxy = ({
1032
1031
  return ProxyClass;
1033
1032
  };
1034
1033
 
1034
+ (function () {
1035
+
1036
+ const refMap = new WeakMap();
1037
+ const validityMap = new WeakMap();
1038
+ const hiddenInputMap = new WeakMap();
1039
+ const internalsMap = new WeakMap();
1040
+ const validationMessageMap = new WeakMap();
1041
+ const formsMap = new WeakMap();
1042
+ const shadowHostsMap = new WeakMap();
1043
+ const formElementsMap = new WeakMap();
1044
+ const refValueMap = new WeakMap();
1045
+ const upgradeMap = new WeakMap();
1046
+ const shadowRootMap = new WeakMap();
1047
+ const validationAnchorMap = new WeakMap();
1048
+ const documentFragmentMap = new WeakMap();
1049
+ const connectedCallbackMap = new WeakMap();
1050
+ const validityUpgradeMap = new WeakMap();
1051
+
1052
+ const aom = {
1053
+ ariaAtomic: 'aria-atomic',
1054
+ ariaAutoComplete: 'aria-autocomplete',
1055
+ ariaBusy: 'aria-busy',
1056
+ ariaChecked: 'aria-checked',
1057
+ ariaColCount: 'aria-colcount',
1058
+ ariaColIndex: 'aria-colindex',
1059
+ ariaColIndexText: 'aria-colindextext',
1060
+ ariaColSpan: 'aria-colspan',
1061
+ ariaCurrent: 'aria-current',
1062
+ ariaDisabled: 'aria-disabled',
1063
+ ariaExpanded: 'aria-expanded',
1064
+ ariaHasPopup: 'aria-haspopup',
1065
+ ariaHidden: 'aria-hidden',
1066
+ ariaInvalid: 'aria-invalid',
1067
+ ariaKeyShortcuts: 'aria-keyshortcuts',
1068
+ ariaLabel: 'aria-label',
1069
+ ariaLevel: 'aria-level',
1070
+ ariaLive: 'aria-live',
1071
+ ariaModal: 'aria-modal',
1072
+ ariaMultiLine: 'aria-multiline',
1073
+ ariaMultiSelectable: 'aria-multiselectable',
1074
+ ariaOrientation: 'aria-orientation',
1075
+ ariaPlaceholder: 'aria-placeholder',
1076
+ ariaPosInSet: 'aria-posinset',
1077
+ ariaPressed: 'aria-pressed',
1078
+ ariaReadOnly: 'aria-readonly',
1079
+ ariaRelevant: 'aria-relevant',
1080
+ ariaRequired: 'aria-required',
1081
+ ariaRoleDescription: 'aria-roledescription',
1082
+ ariaRowCount: 'aria-rowcount',
1083
+ ariaRowIndex: 'aria-rowindex',
1084
+ ariaRowIndexText: 'aria-rowindextext',
1085
+ ariaRowSpan: 'aria-rowspan',
1086
+ ariaSelected: 'aria-selected',
1087
+ ariaSetSize: 'aria-setsize',
1088
+ ariaSort: 'aria-sort',
1089
+ ariaValueMax: 'aria-valuemax',
1090
+ ariaValueMin: 'aria-valuemin',
1091
+ ariaValueNow: 'aria-valuenow',
1092
+ ariaValueText: 'aria-valuetext',
1093
+ role: 'role'
1094
+ };
1095
+ const initAom = (ref, internals) => {
1096
+ for (let key in aom) {
1097
+ internals[key] = null;
1098
+ let closureValue = null;
1099
+ const attributeName = aom[key];
1100
+ Object.defineProperty(internals, key, {
1101
+ get() {
1102
+ return closureValue;
1103
+ },
1104
+ set(value) {
1105
+ closureValue = value;
1106
+ if (ref.isConnected) {
1107
+ ref.setAttribute(attributeName, value);
1108
+ }
1109
+ else {
1110
+ upgradeMap.set(ref, internals);
1111
+ }
1112
+ }
1113
+ });
1114
+ }
1115
+ };
1116
+
1117
+ function initNode(node) {
1118
+ const internals = internalsMap.get(node);
1119
+ const { form } = internals;
1120
+ initForm(node, form, internals);
1121
+ initLabels(node, internals.labels);
1122
+ }
1123
+ const walkFieldset = (node, firstRender = false) => {
1124
+ const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, {
1125
+ acceptNode(node) {
1126
+ return internalsMap.has(node) ?
1127
+ NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
1128
+ }
1129
+ });
1130
+ let current = walker.nextNode();
1131
+ const isCallNecessary = (!firstRender || node.disabled);
1132
+ while (current) {
1133
+ if (current.formDisabledCallback && isCallNecessary) {
1134
+ setDisabled(current, node.disabled);
1135
+ }
1136
+ current = walker.nextNode();
1137
+ }
1138
+ };
1139
+ const disabledOrNameObserverConfig = { attributes: true, attributeFilter: ['disabled', 'name'] };
1140
+ const disabledOrNameObserver = mutationObserverExists() ? new MutationObserver((mutationsList) => {
1141
+ for (const mutation of mutationsList) {
1142
+ const target = mutation.target;
1143
+ if (mutation.attributeName === 'disabled') {
1144
+ if (target.constructor['formAssociated']) {
1145
+ setDisabled(target, target.hasAttribute('disabled'));
1146
+ }
1147
+ else if (target.localName === 'fieldset') {
1148
+ walkFieldset(target);
1149
+ }
1150
+ }
1151
+ if (mutation.attributeName === 'name') {
1152
+ if (target.constructor['formAssociated']) {
1153
+ const internals = internalsMap.get(target);
1154
+ const value = refValueMap.get(target);
1155
+ internals.setFormValue(value);
1156
+ }
1157
+ }
1158
+ }
1159
+ }) : {};
1160
+ function observerCallback(mutationList) {
1161
+ mutationList.forEach(mutationRecord => {
1162
+ const { addedNodes, removedNodes } = mutationRecord;
1163
+ const added = Array.from(addedNodes);
1164
+ const removed = Array.from(removedNodes);
1165
+ added.forEach(node => {
1166
+ if (internalsMap.has(node) && node.constructor['formAssociated']) {
1167
+ initNode(node);
1168
+ }
1169
+ if (upgradeMap.has(node)) {
1170
+ const internals = upgradeMap.get(node);
1171
+ const aomKeys = Object.keys(aom);
1172
+ aomKeys
1173
+ .filter(key => internals[key] !== null)
1174
+ .forEach(key => {
1175
+ node.setAttribute(aom[key], internals[key]);
1176
+ });
1177
+ upgradeMap.delete(node);
1178
+ }
1179
+ if (validityUpgradeMap.has(node)) {
1180
+ const internals = validityUpgradeMap.get(node);
1181
+ node.setAttribute('internals-valid', internals.validity.valid.toString());
1182
+ node.setAttribute('internals-invalid', (!internals.validity.valid).toString());
1183
+ node.setAttribute('aria-invalid', (!internals.validity.valid).toString());
1184
+ validityUpgradeMap.delete(node);
1185
+ }
1186
+ if (node.localName === 'form') {
1187
+ const formElements = formElementsMap.get(node);
1188
+ const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, {
1189
+ acceptNode(node) {
1190
+ return (internalsMap.has(node) && node.constructor['formAssociated'] && !(formElements && formElements.has(node))) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
1191
+ }
1192
+ });
1193
+ let current = walker.nextNode();
1194
+ while (current) {
1195
+ initNode(current);
1196
+ current = walker.nextNode();
1197
+ }
1198
+ }
1199
+ if (node.localName === 'fieldset') {
1200
+ disabledOrNameObserver.observe?.(node, disabledOrNameObserverConfig);
1201
+ walkFieldset(node, true);
1202
+ }
1203
+ });
1204
+ removed.forEach(node => {
1205
+ const internals = internalsMap.get(node);
1206
+ if (internals && hiddenInputMap.get(internals)) {
1207
+ removeHiddenInputs(internals);
1208
+ }
1209
+ if (shadowHostsMap.has(node)) {
1210
+ const observer = shadowHostsMap.get(node);
1211
+ observer.disconnect();
1212
+ }
1213
+ });
1214
+ });
1215
+ }
1216
+ function fragmentObserverCallback(mutationList) {
1217
+ mutationList.forEach(mutation => {
1218
+ const { removedNodes } = mutation;
1219
+ removedNodes.forEach(node => {
1220
+ const observer = documentFragmentMap.get(mutation.target);
1221
+ if (internalsMap.has(node)) {
1222
+ upgradeInternals(node);
1223
+ }
1224
+ observer.disconnect();
1225
+ });
1226
+ });
1227
+ }
1228
+ const deferUpgrade = (fragment) => {
1229
+ const observer = new MutationObserver(fragmentObserverCallback);
1230
+ observer.observe?.(fragment, { childList: true });
1231
+ documentFragmentMap.set(fragment, observer);
1232
+ };
1233
+ mutationObserverExists() ? new MutationObserver(observerCallback) : {};
1234
+ const observerConfig = {
1235
+ childList: true,
1236
+ subtree: true
1237
+ };
1238
+
1239
+ const setDisabled = (ref, disabled) => {
1240
+ ref.toggleAttribute('internals-disabled', disabled);
1241
+ if (disabled) {
1242
+ ref.setAttribute('aria-disabled', 'true');
1243
+ }
1244
+ else {
1245
+ ref.removeAttribute('aria-disabled');
1246
+ }
1247
+ if (ref.formDisabledCallback) {
1248
+ ref.formDisabledCallback.apply(ref, [disabled]);
1249
+ }
1250
+ };
1251
+ const removeHiddenInputs = (internals) => {
1252
+ const hiddenInputs = hiddenInputMap.get(internals);
1253
+ hiddenInputs.forEach(hiddenInput => {
1254
+ hiddenInput.remove();
1255
+ });
1256
+ hiddenInputMap.set(internals, []);
1257
+ };
1258
+ const createHiddenInput = (ref, internals) => {
1259
+ const input = document.createElement('input');
1260
+ input.type = 'hidden';
1261
+ input.name = ref.getAttribute('name');
1262
+ ref.after(input);
1263
+ hiddenInputMap.get(internals).push(input);
1264
+ return input;
1265
+ };
1266
+ const initRef = (ref, internals) => {
1267
+ hiddenInputMap.set(internals, []);
1268
+ disabledOrNameObserver.observe?.(ref, disabledOrNameObserverConfig);
1269
+ };
1270
+ const initLabels = (ref, labels) => {
1271
+ if (labels.length) {
1272
+ Array.from(labels).forEach(label => label.addEventListener('click', ref.click.bind(ref)));
1273
+ let firstLabelId = labels[0].id;
1274
+ if (!labels[0].id) {
1275
+ firstLabelId = `${labels[0].htmlFor}_Label`;
1276
+ labels[0].id = firstLabelId;
1277
+ }
1278
+ ref.setAttribute('aria-labelledby', firstLabelId);
1279
+ }
1280
+ };
1281
+ const setFormValidity = (form) => {
1282
+ const nativeControlValidity = Array.from(form.elements)
1283
+ .filter((element) => !element.tagName.includes('-') && element.validity)
1284
+ .map((element) => element.validity.valid);
1285
+ const polyfilledElements = formElementsMap.get(form) || [];
1286
+ const polyfilledValidity = Array.from(polyfilledElements)
1287
+ .filter(control => control.isConnected)
1288
+ .map((control) => internalsMap.get(control).validity.valid);
1289
+ const hasInvalid = [...nativeControlValidity, ...polyfilledValidity].includes(false);
1290
+ form.toggleAttribute('internals-invalid', hasInvalid);
1291
+ form.toggleAttribute('internals-valid', !hasInvalid);
1292
+ };
1293
+ const formInputCallback = (event) => {
1294
+ setFormValidity(findParentForm(event.target));
1295
+ };
1296
+ const formChangeCallback = (event) => {
1297
+ setFormValidity(findParentForm(event.target));
1298
+ };
1299
+ const wireSubmitLogic = (form) => {
1300
+ const submitButtonSelector = ['button[type=submit]', 'input[type=submit]', 'button:not([type])']
1301
+ .map(sel => `${sel}:not([disabled])`)
1302
+ .map(sel => `${sel}:not([form])${form.id ? `,${sel}[form='${form.id}']` : ''}`)
1303
+ .join(',');
1304
+ form.addEventListener('click', event => {
1305
+ const target = event.target;
1306
+ if (target.closest(submitButtonSelector)) {
1307
+ const elements = formElementsMap.get(form);
1308
+ if (form.noValidate) {
1309
+ return;
1310
+ }
1311
+ if (elements.size) {
1312
+ const nodes = Array.from(elements);
1313
+ const validityList = nodes
1314
+ .reverse()
1315
+ .map(node => {
1316
+ const internals = internalsMap.get(node);
1317
+ return internals.reportValidity();
1318
+ });
1319
+ if (validityList.includes(false)) {
1320
+ event.preventDefault();
1321
+ }
1322
+ }
1323
+ }
1324
+ });
1325
+ };
1326
+ const formResetCallback = (event) => {
1327
+ const elements = formElementsMap.get(event.target);
1328
+ if (elements && elements.size) {
1329
+ elements.forEach(element => {
1330
+ if (element.constructor.formAssociated && element.formResetCallback) {
1331
+ element.formResetCallback.apply(element);
1332
+ }
1333
+ });
1334
+ }
1335
+ };
1336
+ const initForm = (ref, form, internals) => {
1337
+ if (form) {
1338
+ const formElements = formElementsMap.get(form);
1339
+ if (formElements) {
1340
+ formElements.add(ref);
1341
+ }
1342
+ else {
1343
+ const initSet = new Set();
1344
+ initSet.add(ref);
1345
+ formElementsMap.set(form, initSet);
1346
+ wireSubmitLogic(form);
1347
+ form.addEventListener('reset', formResetCallback);
1348
+ form.addEventListener('input', formInputCallback);
1349
+ form.addEventListener('change', formChangeCallback);
1350
+ }
1351
+ formsMap.set(form, { ref, internals });
1352
+ if (ref.constructor['formAssociated'] && ref.formAssociatedCallback) {
1353
+ setTimeout(() => {
1354
+ ref.formAssociatedCallback.apply(ref, [form]);
1355
+ }, 0);
1356
+ }
1357
+ setFormValidity(form);
1358
+ }
1359
+ };
1360
+ const findParentForm = (elem) => {
1361
+ let parent = elem.parentNode;
1362
+ if (parent && parent.tagName !== 'FORM') {
1363
+ parent = findParentForm(parent);
1364
+ }
1365
+ return parent;
1366
+ };
1367
+ const throwIfNotFormAssociated = (ref, message, ErrorType = DOMException) => {
1368
+ if (!ref.constructor['formAssociated']) {
1369
+ throw new ErrorType(message);
1370
+ }
1371
+ };
1372
+ const overrideFormMethod = (form, returnValue, method) => {
1373
+ const elements = formElementsMap.get(form);
1374
+ if (elements && elements.size) {
1375
+ elements.forEach(element => {
1376
+ const internals = internalsMap.get(element);
1377
+ const valid = internals[method]();
1378
+ if (!valid) {
1379
+ returnValue = false;
1380
+ }
1381
+ });
1382
+ }
1383
+ return returnValue;
1384
+ };
1385
+ const upgradeInternals = (ref) => {
1386
+ if (ref.constructor['formAssociated']) {
1387
+ const internals = internalsMap.get(ref);
1388
+ const { labels, form } = internals;
1389
+ initLabels(ref, labels);
1390
+ initForm(ref, form, internals);
1391
+ }
1392
+ };
1393
+ function mutationObserverExists() {
1394
+ return typeof MutationObserver !== 'undefined';
1395
+ }
1396
+
1397
+ class ValidityState {
1398
+ constructor() {
1399
+ this.badInput = false;
1400
+ this.customError = false;
1401
+ this.patternMismatch = false;
1402
+ this.rangeOverflow = false;
1403
+ this.rangeUnderflow = false;
1404
+ this.stepMismatch = false;
1405
+ this.tooLong = false;
1406
+ this.tooShort = false;
1407
+ this.typeMismatch = false;
1408
+ this.valid = true;
1409
+ this.valueMissing = false;
1410
+ Object.seal(this);
1411
+ }
1412
+ }
1413
+ const setValid = (validityObject) => {
1414
+ validityObject.badInput = false;
1415
+ validityObject.customError = false;
1416
+ validityObject.patternMismatch = false;
1417
+ validityObject.rangeOverflow = false;
1418
+ validityObject.rangeUnderflow = false;
1419
+ validityObject.stepMismatch = false;
1420
+ validityObject.tooLong = false;
1421
+ validityObject.tooShort = false;
1422
+ validityObject.typeMismatch = false;
1423
+ validityObject.valid = true;
1424
+ validityObject.valueMissing = false;
1425
+ return validityObject;
1426
+ };
1427
+ const reconcileValidity = (validityObject, newState, form) => {
1428
+ validityObject.valid = isValid(newState);
1429
+ Object.keys(newState).forEach(key => validityObject[key] = newState[key]);
1430
+ if (form) {
1431
+ setFormValidity(form);
1432
+ }
1433
+ return validityObject;
1434
+ };
1435
+ const isValid = (validityState) => {
1436
+ let valid = true;
1437
+ for (let key in validityState) {
1438
+ if (key !== 'valid' && validityState[key] !== false) {
1439
+ valid = false;
1440
+ }
1441
+ }
1442
+ return valid;
1443
+ };
1444
+
1445
+ const customStateMap = new WeakMap();
1446
+ function addState(ref, stateName) {
1447
+ ref.toggleAttribute(stateName, true);
1448
+ if (ref.part) {
1449
+ ref.part.add(stateName);
1450
+ }
1451
+ }
1452
+ class CustomStateSet extends Set {
1453
+ static get isPolyfilled() {
1454
+ return true;
1455
+ }
1456
+ constructor(ref) {
1457
+ super();
1458
+ if (!ref || !ref.tagName || ref.tagName.indexOf('-') === -1) {
1459
+ throw new TypeError('Illegal constructor');
1460
+ }
1461
+ customStateMap.set(this, ref);
1462
+ }
1463
+ add(state) {
1464
+ if (!/^--/.test(state) || typeof state !== 'string') {
1465
+ throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${state} must start with '--'.`);
1466
+ }
1467
+ const result = super.add(state);
1468
+ const ref = customStateMap.get(this);
1469
+ const stateName = `state${state}`;
1470
+ if (ref.isConnected) {
1471
+ addState(ref, stateName);
1472
+ }
1473
+ else {
1474
+ setTimeout(() => {
1475
+ addState(ref, stateName);
1476
+ });
1477
+ }
1478
+ return result;
1479
+ }
1480
+ clear() {
1481
+ for (let [entry] of this.entries()) {
1482
+ this.delete(entry);
1483
+ }
1484
+ super.clear();
1485
+ }
1486
+ delete(state) {
1487
+ const result = super.delete(state);
1488
+ const ref = customStateMap.get(this);
1489
+ if (ref.isConnected) {
1490
+ ref.toggleAttribute(`state${state}`, false);
1491
+ if (ref.part) {
1492
+ ref.part.remove(`state${state}`);
1493
+ }
1494
+ }
1495
+ else {
1496
+ setTimeout(() => {
1497
+ ref.toggleAttribute(`state${state}`, false);
1498
+ if (ref.part) {
1499
+ ref.part.remove(`state${state}`);
1500
+ }
1501
+ });
1502
+ }
1503
+ return result;
1504
+ }
1505
+ }
1506
+
1507
+ function __classPrivateFieldGet(receiver, state, kind, f) {
1508
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1509
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1510
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1511
+ }
1512
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
1513
+ if (kind === "m") throw new TypeError("Private method is not writable");
1514
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1515
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1516
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1517
+ }
1518
+
1519
+ var _HTMLFormControlsCollection_elements;
1520
+ class HTMLFormControlsCollection {
1521
+ constructor(elements) {
1522
+ _HTMLFormControlsCollection_elements.set(this, void 0);
1523
+ __classPrivateFieldSet(this, _HTMLFormControlsCollection_elements, elements, "f");
1524
+ for (let i = 0; i < elements.length; i++) {
1525
+ let element = elements[i];
1526
+ this[i] = element;
1527
+ if (element.hasAttribute('name')) {
1528
+ this[element.getAttribute('name')] = element;
1529
+ }
1530
+ }
1531
+ Object.freeze(this);
1532
+ }
1533
+ get length() {
1534
+ return __classPrivateFieldGet(this, _HTMLFormControlsCollection_elements, "f").length;
1535
+ }
1536
+ [(_HTMLFormControlsCollection_elements = new WeakMap(), Symbol.iterator)]() {
1537
+ return __classPrivateFieldGet(this, _HTMLFormControlsCollection_elements, "f")[Symbol.iterator]();
1538
+ }
1539
+ item(i) {
1540
+ return this[i] == null ? null : this[i];
1541
+ }
1542
+ namedItem(name) {
1543
+ return this[name] == null ? null : this[name];
1544
+ }
1545
+ }
1546
+
1547
+ function patchFormPrototype() {
1548
+ const checkValidity = HTMLFormElement.prototype.checkValidity;
1549
+ HTMLFormElement.prototype.checkValidity = checkValidityOverride;
1550
+ const reportValidity = HTMLFormElement.prototype.reportValidity;
1551
+ HTMLFormElement.prototype.reportValidity = reportValidityOverride;
1552
+ function checkValidityOverride(...args) {
1553
+ let returnValue = checkValidity.apply(this, args);
1554
+ return overrideFormMethod(this, returnValue, 'checkValidity');
1555
+ }
1556
+ function reportValidityOverride(...args) {
1557
+ let returnValue = reportValidity.apply(this, args);
1558
+ return overrideFormMethod(this, returnValue, 'reportValidity');
1559
+ }
1560
+ const { get } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'elements');
1561
+ Object.defineProperty(HTMLFormElement.prototype, 'elements', {
1562
+ get(...args) {
1563
+ const elements = get.call(this, ...args);
1564
+ const polyfilledElements = Array.from(formElementsMap.get(this) || []);
1565
+ if (polyfilledElements.length === 0) {
1566
+ return elements;
1567
+ }
1568
+ const orderedElements = Array.from(elements).concat(polyfilledElements).sort((a, b) => {
1569
+ if (a.compareDocumentPosition) {
1570
+ return a.compareDocumentPosition(b) & 2 ? 1 : -1;
1571
+ }
1572
+ return 0;
1573
+ });
1574
+ return new HTMLFormControlsCollection(orderedElements);
1575
+ },
1576
+ });
1577
+ }
1578
+
1579
+ class ElementInternals {
1580
+ static get isPolyfilled() {
1581
+ return true;
1582
+ }
1583
+ constructor(ref) {
1584
+ if (!ref || !ref.tagName || ref.tagName.indexOf('-') === -1) {
1585
+ throw new TypeError('Illegal constructor');
1586
+ }
1587
+ const rootNode = ref.getRootNode();
1588
+ const validity = new ValidityState();
1589
+ this.states = new CustomStateSet(ref);
1590
+ refMap.set(this, ref);
1591
+ validityMap.set(this, validity);
1592
+ internalsMap.set(ref, this);
1593
+ initAom(ref, this);
1594
+ initRef(ref, this);
1595
+ Object.seal(this);
1596
+ if (rootNode instanceof DocumentFragment) {
1597
+ deferUpgrade(rootNode);
1598
+ }
1599
+ }
1600
+ checkValidity() {
1601
+ const ref = refMap.get(this);
1602
+ throwIfNotFormAssociated(ref, `Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
1603
+ if (!this.willValidate) {
1604
+ return true;
1605
+ }
1606
+ const validity = validityMap.get(this);
1607
+ if (!validity.valid) {
1608
+ const validityEvent = new Event('invalid', {
1609
+ bubbles: false,
1610
+ cancelable: true,
1611
+ composed: false
1612
+ });
1613
+ ref.dispatchEvent(validityEvent);
1614
+ }
1615
+ return validity.valid;
1616
+ }
1617
+ get form() {
1618
+ const ref = refMap.get(this);
1619
+ throwIfNotFormAssociated(ref, `Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.`);
1620
+ let form;
1621
+ if (ref.constructor['formAssociated'] === true) {
1622
+ form = findParentForm(ref);
1623
+ }
1624
+ return form;
1625
+ }
1626
+ get labels() {
1627
+ const ref = refMap.get(this);
1628
+ throwIfNotFormAssociated(ref, `Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.`);
1629
+ const id = ref.getAttribute('id');
1630
+ const hostRoot = ref.getRootNode();
1631
+ if (hostRoot && id) {
1632
+ return hostRoot.querySelectorAll(`[for="${id}"]`);
1633
+ }
1634
+ return [];
1635
+ }
1636
+ reportValidity() {
1637
+ const ref = refMap.get(this);
1638
+ throwIfNotFormAssociated(ref, `Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
1639
+ if (!this.willValidate) {
1640
+ return true;
1641
+ }
1642
+ const valid = this.checkValidity();
1643
+ const anchor = validationAnchorMap.get(this);
1644
+ if (anchor && !ref.constructor['formAssociated']) {
1645
+ throw new DOMException(`Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
1646
+ }
1647
+ if (!valid && anchor) {
1648
+ ref.focus();
1649
+ anchor.focus();
1650
+ }
1651
+ return valid;
1652
+ }
1653
+ setFormValue(value) {
1654
+ const ref = refMap.get(this);
1655
+ throwIfNotFormAssociated(ref, `Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element.`);
1656
+ removeHiddenInputs(this);
1657
+ if (value != null && !(value instanceof FormData)) {
1658
+ if (ref.getAttribute('name')) {
1659
+ const hiddenInput = createHiddenInput(ref, this);
1660
+ hiddenInput.value = value;
1661
+ }
1662
+ }
1663
+ else if (value != null && value instanceof FormData) {
1664
+ Array.from(value).reverse().forEach(([formDataKey, formDataValue]) => {
1665
+ if (typeof formDataValue === 'string') {
1666
+ const hiddenInput = createHiddenInput(ref, this);
1667
+ hiddenInput.name = formDataKey;
1668
+ hiddenInput.value = formDataValue;
1669
+ }
1670
+ });
1671
+ }
1672
+ refValueMap.set(ref, value);
1673
+ }
1674
+ setValidity(validityChanges, validationMessage, anchor) {
1675
+ const ref = refMap.get(this);
1676
+ throwIfNotFormAssociated(ref, `Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
1677
+ if (!validityChanges) {
1678
+ throw new TypeError('Failed to execute \'setValidity\' on \'ElementInternals\': 1 argument required, but only 0 present.');
1679
+ }
1680
+ validationAnchorMap.set(this, anchor);
1681
+ const validity = validityMap.get(this);
1682
+ const validityChangesObj = {};
1683
+ for (const key in validityChanges) {
1684
+ validityChangesObj[key] = validityChanges[key];
1685
+ }
1686
+ if (Object.keys(validityChangesObj).length === 0) {
1687
+ setValid(validity);
1688
+ }
1689
+ const check = { ...validity, ...validityChangesObj };
1690
+ delete check.valid;
1691
+ const { valid } = reconcileValidity(validity, check, this.form);
1692
+ if (!valid && !validationMessage) {
1693
+ throw new DOMException(`Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.`);
1694
+ }
1695
+ validationMessageMap.set(this, valid ? '' : validationMessage);
1696
+ if (ref.isConnected) {
1697
+ ref.toggleAttribute('internals-invalid', !valid);
1698
+ ref.toggleAttribute('internals-valid', valid);
1699
+ ref.setAttribute('aria-invalid', `${!valid}`);
1700
+ }
1701
+ else {
1702
+ validityUpgradeMap.set(ref, this);
1703
+ }
1704
+ }
1705
+ get shadowRoot() {
1706
+ const ref = refMap.get(this);
1707
+ const shadowRoot = shadowRootMap.get(ref);
1708
+ if (shadowRoot) {
1709
+ return shadowRoot;
1710
+ }
1711
+ return null;
1712
+ }
1713
+ get validationMessage() {
1714
+ const ref = refMap.get(this);
1715
+ throwIfNotFormAssociated(ref, `Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element.`);
1716
+ return validationMessageMap.get(this);
1717
+ }
1718
+ get validity() {
1719
+ const ref = refMap.get(this);
1720
+ throwIfNotFormAssociated(ref, `Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element.`);
1721
+ const validity = validityMap.get(this);
1722
+ return validity;
1723
+ }
1724
+ get willValidate() {
1725
+ const ref = refMap.get(this);
1726
+ throwIfNotFormAssociated(ref, `Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element.`);
1727
+ if ((ref.disabled || ref.hasAttribute('disabled')) ||
1728
+ ref.hasAttribute('readonly')) {
1729
+ return false;
1730
+ }
1731
+ return true;
1732
+ }
1733
+ }
1734
+ function isElementInternalsSupported() {
1735
+ if (typeof window === 'undefined' || !window.ElementInternals || !HTMLElement.prototype.attachInternals) {
1736
+ return false;
1737
+ }
1738
+ class ElementInternalsFeatureDetection extends HTMLElement {
1739
+ constructor() {
1740
+ super();
1741
+ this.internals = this.attachInternals();
1742
+ }
1743
+ }
1744
+ const randomName = `element-internals-feature-detection-${Math.random().toString(36).replace(/[^a-z]+/g, '')}`;
1745
+ customElements.define(randomName, ElementInternalsFeatureDetection);
1746
+ const featureDetectionElement = new ElementInternalsFeatureDetection();
1747
+ return [
1748
+ 'shadowRoot',
1749
+ 'form',
1750
+ 'willValidate',
1751
+ 'validity',
1752
+ 'validationMessage',
1753
+ 'labels',
1754
+ 'setFormValue',
1755
+ 'setValidity',
1756
+ 'checkValidity',
1757
+ 'reportValidity'
1758
+ ].every(prop => prop in featureDetectionElement.internals);
1759
+ }
1760
+ if (!isElementInternalsSupported()) {
1761
+ if (typeof window !== 'undefined') {
1762
+ window.ElementInternals = ElementInternals;
1763
+ }
1764
+ if (typeof CustomElementRegistry !== 'undefined') {
1765
+ const define = CustomElementRegistry.prototype.define;
1766
+ CustomElementRegistry.prototype.define = function (name, constructor, options) {
1767
+ if (constructor.formAssociated) {
1768
+ const connectedCallback = constructor.prototype.connectedCallback;
1769
+ constructor.prototype.connectedCallback = function () {
1770
+ if (!connectedCallbackMap.has(this)) {
1771
+ connectedCallbackMap.set(this, true);
1772
+ if (this.hasAttribute('disabled')) {
1773
+ setDisabled(this, true);
1774
+ }
1775
+ }
1776
+ if (connectedCallback != null) {
1777
+ connectedCallback.apply(this);
1778
+ }
1779
+ upgradeInternals(this);
1780
+ };
1781
+ }
1782
+ define.call(this, name, constructor, options);
1783
+ };
1784
+ }
1785
+ if (typeof HTMLElement !== 'undefined') {
1786
+ HTMLElement.prototype.attachInternals = function () {
1787
+ if (!this.tagName) {
1788
+ return {};
1789
+ }
1790
+ else if (this.tagName.indexOf('-') === -1) {
1791
+ throw new Error(`Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.`);
1792
+ }
1793
+ if (internalsMap.has(this)) {
1794
+ throw new DOMException(`DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.`);
1795
+ }
1796
+ return new ElementInternals(this);
1797
+ };
1798
+ }
1799
+ if (typeof Element !== 'undefined') {
1800
+ function attachShadowObserver(...args) {
1801
+ const shadowRoot = attachShadow.apply(this, args);
1802
+ shadowRootMap.set(this, shadowRoot);
1803
+ if (mutationObserverExists()) {
1804
+ const observer = new MutationObserver(observerCallback);
1805
+ if (window.ShadyDOM) {
1806
+ observer.observe(this, observerConfig);
1807
+ }
1808
+ else {
1809
+ observer.observe(shadowRoot, observerConfig);
1810
+ }
1811
+ shadowHostsMap.set(this, observer);
1812
+ }
1813
+ return shadowRoot;
1814
+ }
1815
+ const attachShadow = Element.prototype.attachShadow;
1816
+ Element.prototype.attachShadow = attachShadowObserver;
1817
+ }
1818
+ if (mutationObserverExists() && typeof document !== 'undefined') {
1819
+ const documentObserver = new MutationObserver(observerCallback);
1820
+ documentObserver.observe(document.documentElement, observerConfig);
1821
+ }
1822
+ if (typeof HTMLFormElement !== 'undefined') {
1823
+ patchFormPrototype();
1824
+ }
1825
+ if (typeof window !== 'undefined' && !window.CustomStateSet) {
1826
+ window.CustomStateSet = CustomStateSet;
1827
+ }
1828
+ }
1829
+ else if (typeof window !== 'undefined' && !window.CustomStateSet) {
1830
+ window.CustomStateSet = CustomStateSet;
1831
+ const attachInternals = HTMLElement.prototype.attachInternals;
1832
+ HTMLElement.prototype.attachInternals = function (...args) {
1833
+ const internals = attachInternals.call(this, args);
1834
+ internals.states = new CustomStateSet(this);
1835
+ return internals;
1836
+ };
1837
+ }
1838
+
1839
+ })();
1840
+
1035
1841
  const observedAttributes$4 = ['required', 'pattern'];
1036
1842
 
1037
1843
  const errorAttributes = {