unpoly-rails 3.9.5 → 3.10.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.
@@ -5,7 +5,7 @@
5
5
  /***/ (() => {
6
6
 
7
7
  window.up = {
8
- version: '3.9.5'
8
+ version: '3.10.0'
9
9
  };
10
10
 
11
11
 
@@ -202,6 +202,9 @@ up.util = (function () {
202
202
  function isElement(object) {
203
203
  return object instanceof Element;
204
204
  }
205
+ function isTextNode(object) {
206
+ return object instanceof Text;
207
+ }
205
208
  function isRegExp(object) {
206
209
  return object instanceof RegExp;
207
210
  }
@@ -211,9 +214,9 @@ up.util = (function () {
211
214
  function isJQuery(object) {
212
215
  return up.browser.canJQuery() && object instanceof jQuery;
213
216
  }
214
- function isElementish(object) {
217
+ function isElementLike(object) {
215
218
  var _a;
216
- return !!(object && (object.addEventListener || ((_a = object[0]) === null || _a === void 0 ? void 0 : _a.addEventListener)));
219
+ return !!(object && (object.addEventListener || (isJQuery(object) && ((_a = object[0]) === null || _a === void 0 ? void 0 : _a.addEventListener))));
217
220
  }
218
221
  function isPromise(object) {
219
222
  return isObject(object) && isFunction(object.then);
@@ -241,6 +244,9 @@ up.util = (function () {
241
244
  function isArguments(value) {
242
245
  return Object.prototype.toString.call(value) === '[object Arguments]';
243
246
  }
247
+ function isAdjacentPosition(value) {
248
+ return /^(before|after)/.test(value);
249
+ }
244
250
  function wrapList(value) {
245
251
  if (isList(value)) {
246
252
  return value;
@@ -298,10 +304,9 @@ up.util = (function () {
298
304
  }
299
305
  }
300
306
  function parseArgIntoOptions(args, argKey) {
301
- let options = extractOptions(args);
302
- if (isDefined(args[0])) {
303
- options = copy(options);
304
- options[argKey] = args[0];
307
+ let [positionalArg, options] = parseArgs(args, 'val', 'options');
308
+ if (isDefined(positionalArg)) {
309
+ options[argKey] = positionalArg;
305
310
  }
306
311
  return options;
307
312
  }
@@ -469,7 +474,9 @@ up.util = (function () {
469
474
  return value;
470
475
  }
471
476
  function renameKey(object, oldKey, newKey) {
472
- return object[newKey] = pluckKey(object, oldKey);
477
+ if (oldKey in object) {
478
+ object[newKey] = pluckKey(object, oldKey);
479
+ }
473
480
  }
474
481
  function extractLastArg(args, tester) {
475
482
  if (tester(last(args))) {
@@ -555,26 +562,35 @@ up.util = (function () {
555
562
  function isEqualList(a, b) {
556
563
  return (a.length === b.length) && every(a, (elem, index) => isEqual(elem, b[index]));
557
564
  }
558
- const PARSE_TOKEN_PATTERNS = {
559
- 'space/or': /\s+(?:or\s+)?/,
560
- 'or': /\s+or\s+/,
561
- 'comma': /\s*,\s*/
562
- };
563
- function parseTokens(value, options = {}) {
564
- if (isString(value)) {
565
- value = value.trim();
566
- if (options.json && /^\[.*]$/.test(value)) {
567
- return JSON.parse(value);
568
- }
569
- else {
570
- let separator = options.separator || 'space/or';
571
- let pattern = PARSE_TOKEN_PATTERNS[separator];
572
- return value.split(pattern);
573
- }
565
+ function getSimpleTokens(value, { json = false, separator = /[,\s]/ } = {}) {
566
+ if (!isString(value)) {
567
+ return wrapList(value);
568
+ }
569
+ else if (json && /^\[.*]$/.test(value)) {
570
+ return parseRelaxedJSON(value);
574
571
  }
575
572
  else {
573
+ return splitSimpleTokenString(value, separator);
574
+ }
575
+ }
576
+ function splitSimpleTokenString(value, separator) {
577
+ var _a, _b;
578
+ let parts = ((_b = (_a = up.migrate).splitAtOr) === null || _b === void 0 ? void 0 : _b.call(_a, value)) || value.split(separator);
579
+ return parts.map((s) => s.trim()).filter(identity);
580
+ }
581
+ function getComplexTokens(value) {
582
+ if (!isString(value)) {
576
583
  return wrapList(value);
577
584
  }
585
+ else {
586
+ let { maskedTokens, restore } = complexTokenOutlines(value);
587
+ return maskedTokens.map((token) => restore(token));
588
+ }
589
+ }
590
+ function complexTokenOutlines(string) {
591
+ let { masked, restore } = expressionOutline(string);
592
+ let maskedTokens = splitSimpleTokenString(masked, ',');
593
+ return { maskedTokens, restore };
578
594
  }
579
595
  function wrapValue(constructor, ...args) {
580
596
  return (args[0] instanceof constructor) ? args[0] : new constructor(...args);
@@ -586,18 +602,13 @@ up.util = (function () {
586
602
  function reverse(list) {
587
603
  return copy(list).reverse();
588
604
  }
589
- function replaceValue(value, matchValue, replacementValue) {
590
- if (value === matchValue) {
591
- return replacementValue;
592
- }
593
- else {
594
- return value;
595
- }
596
- }
597
- function renameKeys(object, renameKeyFn) {
605
+ function withRenamedKeys(object, renameKeyFn) {
598
606
  const renamed = {};
599
607
  for (let key in object) {
600
- renamed[renameKeyFn(key)] = object[key];
608
+ let transformed = renameKeyFn(key);
609
+ if (isGiven(transformed)) {
610
+ renamed[transformed] = object[key];
611
+ }
601
612
  }
602
613
  return renamed;
603
614
  }
@@ -628,6 +639,9 @@ up.util = (function () {
628
639
  });
629
640
  }
630
641
  }
642
+ function delegatePromise(object, promiseProp) {
643
+ return defineDelegates(object, ['then', 'catch', 'finally'], function () { return this[promiseProp]; });
644
+ }
631
645
  function stringifyArg(arg, placeholder = '%o') {
632
646
  let string;
633
647
  const maxLength = 200;
@@ -738,6 +752,122 @@ up.util = (function () {
738
752
  Object.assign(variant, changes);
739
753
  return variant;
740
754
  }
755
+ function parseArgs(args, ...specs) {
756
+ let results = [];
757
+ while (specs.length) {
758
+ let lastSpec = specs.pop();
759
+ if (lastSpec === 'options') {
760
+ results.unshift(extractOptions(args));
761
+ }
762
+ else if (lastSpec === 'callback') {
763
+ results.unshift(extractCallback(args));
764
+ }
765
+ else if (lastSpec === 'val') {
766
+ results.unshift(args.pop());
767
+ }
768
+ else if (isFunction(lastSpec)) {
769
+ let value = lastSpec(last(args)) ? args.pop() : undefined;
770
+ results.unshift(value);
771
+ }
772
+ }
773
+ return results;
774
+ }
775
+ function scanFunctions(...values) {
776
+ return values.flat().filter(isFunction);
777
+ }
778
+ function cleaner() {
779
+ let fns = [];
780
+ let track = function (values, transform) {
781
+ values = scanFunctions(...values).map(transform);
782
+ fns.push(...scanFunctions(...values));
783
+ };
784
+ let api = function (...values) {
785
+ track(values, identity);
786
+ };
787
+ api.guard = function (...values) {
788
+ track(values, up.error.guardFn);
789
+ };
790
+ api.clean = function (...args) {
791
+ let { length } = fns;
792
+ for (let i = length - 1; i >= 0; i--)
793
+ fns[i](...args);
794
+ fns = [];
795
+ };
796
+ return api;
797
+ }
798
+ function maskPattern(str, patterns, { keepDelimiters = false } = {}) {
799
+ let maskCount = 0;
800
+ let maskPattern = /§(\d+)/g;
801
+ let matches = [];
802
+ let replaceLayers = 0;
803
+ let replace = (replacePattern) => {
804
+ let didReplace = false;
805
+ str = str.replaceAll(replacePattern, function (match) {
806
+ didReplace = true;
807
+ let glyph = '§' + (maskCount++);
808
+ let mask;
809
+ let masked;
810
+ if (keepDelimiters) {
811
+ let startDelimiter = match[0];
812
+ let endDelimiter = match.slice(-1);
813
+ masked = match.slice(1, -1);
814
+ mask = startDelimiter + glyph + endDelimiter;
815
+ }
816
+ else {
817
+ masked = match;
818
+ mask = glyph;
819
+ }
820
+ matches.push(masked);
821
+ return mask;
822
+ });
823
+ if (didReplace)
824
+ replaceLayers++;
825
+ };
826
+ [maskPattern, ...patterns].forEach(replace);
827
+ let restore = (s, transform = identity) => {
828
+ for (let i = 0; i < replaceLayers; i++) {
829
+ s = s.replace(maskPattern, (match, placeholderIndex) => transform(matches[placeholderIndex]));
830
+ }
831
+ return s;
832
+ };
833
+ return { masked: str, restore };
834
+ }
835
+ const QUOTED_STRING_PATTERN = /'(?:\\\\|\\'|[^'])*'|"(?:\\\\|\\"|[^"])*"/g;
836
+ const NESTED_GROUP_PATTERN = /{(?:[^{}]|{[^{}]*})*}|\((?:[^\(\)]|\([^\(\)]*\))*\)|\[(?:[^\[\]]|\[[^\[\]]*\])*\]/g;
837
+ function expressionOutline(str) {
838
+ return maskPattern(str, [QUOTED_STRING_PATTERN, NESTED_GROUP_PATTERN], { keepDelimiters: true });
839
+ }
840
+ function ensureDoubleQuotes(str) {
841
+ if (str[0] === '"')
842
+ return str;
843
+ str = str.slice(1, -1);
844
+ let transformed = str.replace(/(\\\\)|(\\')|(\\")|(")/g, function (_match, escapedBackslash, escapedSingleQuote, _doubleQuote) {
845
+ return escapedBackslash
846
+ || (escapedSingleQuote && "'")
847
+ || '\\"';
848
+ });
849
+ return '"' + transformed + '"';
850
+ }
851
+ function parseString(value) {
852
+ return JSON.parse(ensureDoubleQuotes(value));
853
+ }
854
+ function parseRelaxedJSON(str) {
855
+ let { masked, restore } = maskPattern(str, [QUOTED_STRING_PATTERN]);
856
+ masked = masked.replace(/([a-z_$][\w$]*:)/gi, (unquotedProperty) => ('"' + unquotedProperty.slice(0, -1) + '":'));
857
+ masked = masked.replace(/,\s*([}\]])/g, '$1');
858
+ masked = restore(masked, ensureDoubleQuotes);
859
+ return JSON.parse(masked);
860
+ }
861
+ function parseScalarJSONPairs(str) {
862
+ let { maskedTokens, restore } = complexTokenOutlines(str);
863
+ return maskedTokens.map((maskedToken) => {
864
+ let [_match, string, json] = maskedToken.match(/([^{]+)({[^}]*})?/);
865
+ return [
866
+ restore(string.trim()),
867
+ json && parseRelaxedJSON(restore(json))
868
+ ];
869
+ });
870
+ }
741
871
  return {
742
872
  parseURL,
743
873
  normalizeURL,
@@ -781,14 +911,16 @@ up.util = (function () {
781
911
  isBoolean,
782
912
  isNumber,
783
913
  isElement,
914
+ isTextNode,
784
915
  isJQuery,
785
- isElementish,
916
+ isElementLike,
786
917
  isPromise,
787
918
  isOptions,
788
919
  isArray,
789
920
  isFormData,
790
921
  isList,
791
922
  isRegExp,
923
+ isAdjacentPosition,
792
924
  timer: scheduleTimer,
793
925
  contains,
794
926
  containsAll,
@@ -819,21 +951,30 @@ up.util = (function () {
819
951
  isCrossOrigin,
820
952
  task: queueTask,
821
953
  isEqual,
822
- parseTokens,
954
+ getSimpleTokens,
955
+ getComplexTokens,
823
956
  wrapList,
824
957
  wrapValue,
825
958
  uid,
826
959
  upperCaseFirst,
827
960
  lowerCaseFirst,
828
961
  delegate: defineDelegates,
962
+ delegatePromise,
829
963
  reverse,
830
964
  camelToKebabCase,
831
- replaceValue,
832
965
  sprintf,
833
- renameKeys,
966
+ withRenamedKeys,
834
967
  memoizeMethod,
835
968
  safeStringifyJSON,
836
969
  variant,
970
+ cleaner,
971
+ scanFunctions,
972
+ args: parseArgs,
973
+ parseRelaxedJSON,
974
+ parseScalarJSONPairs,
975
+ maskPattern,
976
+ expressionOutline,
977
+ parseString,
837
978
  };
838
979
  })();
839
980
 
@@ -865,17 +1006,12 @@ up.error = (function () {
865
1006
  throw value;
866
1007
  }
867
1008
  }
868
- function report(error) {
869
- console.error('Uncaught %o', error);
870
- let event = new ErrorEvent('error', { error, message: 'Uncaught ' + error });
871
- window.dispatchEvent(event);
872
- }
873
- function guard(fn) {
1009
+ function guard(fn, ...args) {
874
1010
  try {
875
- return fn();
1011
+ return fn(...args);
876
1012
  }
877
1013
  catch (error) {
878
- report(error);
1014
+ reportError(error);
879
1015
  }
880
1016
  }
881
1017
  function guardFn(fn) {
@@ -907,7 +1043,6 @@ up.migrate = {
907
1043
  /***/ (() => {
908
1044
 
909
1045
  up.browser = (function () {
910
- const u = up.util;
911
1046
  function submitForm(form) {
912
1047
  form.submit();
913
1048
  }
@@ -917,7 +1052,6 @@ up.browser = (function () {
917
1052
  function canJQuery() {
918
1053
  return !!window.jQuery;
919
1054
  }
920
- const canHasSelector = u.memoize(() => CSS.supports('selector(:has(*))'));
921
1055
  function popCookie(name) {
922
1056
  var _a;
923
1057
  let value = (_a = document.cookie.match(new RegExp(name + "=(\\w+)"))) === null || _a === void 0 ? void 0 : _a[1];
@@ -939,7 +1073,6 @@ up.browser = (function () {
939
1073
  canJQuery,
940
1074
  assertConfirmed,
941
1075
  popCookie,
942
- canHasSelector,
943
1076
  };
944
1077
  })();
945
1078
 
@@ -952,18 +1085,23 @@ __webpack_require__(8);
952
1085
  up.element = (function () {
953
1086
  const u = up.util;
954
1087
  function first(...args) {
955
- const selector = args.pop();
956
- const root = args[0] || document;
1088
+ let [root = document, selector] = u.args(args, 'val', 'val');
957
1089
  return root.querySelector(selector);
958
1090
  }
959
1091
  function subtree(root, selector) {
960
1092
  const results = [];
961
- if (root.matches(selector)) {
1093
+ if (elementLikeMatches(root, selector)) {
962
1094
  results.push(root);
963
1095
  }
964
1096
  results.push(...root.querySelectorAll(selector));
965
1097
  return results;
966
1098
  }
1099
+ function subtreeFirst(root, selector) {
1100
+ return elementLikeMatches(root, selector) ? root : root.querySelector(selector);
1101
+ }
1102
+ function elementLikeMatches(elementLike, selector) {
1103
+ return u.isElement(elementLike) && elementLike.matches(selector);
1104
+ }
967
1105
  function contains(root, selectorOrElement) {
968
1106
  const element = getOne(selectorOrElement);
969
1107
  return Node.prototype.contains.call(root, element);
@@ -1005,24 +1143,38 @@ up.element = (function () {
1005
1143
  }
1006
1144
  }
1007
1145
  function hide(element) {
1008
- element.setAttribute('hidden', '');
1146
+ setVisible(element, false);
1009
1147
  }
1010
1148
  function show(element) {
1011
- element.removeAttribute('hidden');
1012
- if (element.style.display === 'none') {
1013
- element.style.display = '';
1014
- }
1149
+ setVisible(element, true);
1015
1150
  }
1016
- function toggle(element, newVisible) {
1017
- if (newVisible == null) {
1018
- newVisible = !isVisible(element);
1019
- }
1020
- (newVisible ? show : hide)(element);
1151
+ function showTemp(element) {
1152
+ return setVisibleTemp(element, true);
1153
+ }
1154
+ function hideTemp(element) {
1155
+ return setVisibleTemp(element, false);
1021
1156
  }
1022
- function toggleAttr(element, attr, value, newPresent) {
1023
- if (newPresent == null) {
1024
- newPresent = !element.hasAttribute(attr);
1157
+ function setVisibleTemp(element, newVisible) {
1158
+ if (newVisible === isVisible(element))
1159
+ return u.noop;
1160
+ setVisible(element, newVisible);
1161
+ return () => setVisible(element, !newVisible);
1162
+ }
1163
+ function setVisible(element, newVisible) {
1164
+ if (newVisible) {
1165
+ element.removeAttribute('hidden');
1166
+ if (element.style.display === 'none') {
1167
+ element.style.display = '';
1168
+ }
1169
+ }
1170
+ else {
1171
+ element.setAttribute('hidden', '');
1025
1172
  }
1173
+ }
1174
+ function toggle(element, newVisible = !isVisible(element)) {
1175
+ setVisible(element, newVisible);
1176
+ }
1177
+ function setAttrPresence(element, attr, value, newPresent) {
1026
1178
  if (newPresent) {
1027
1179
  return element.setAttribute(attr, value);
1028
1180
  }
@@ -1041,11 +1193,9 @@ up.element = (function () {
1041
1193
  }
1042
1194
  }
1043
1195
  }
1044
- function setTemporaryAttrs(element, attrs) {
1045
- const oldAttrs = {};
1046
- for (let key of Object.keys(attrs)) {
1047
- oldAttrs[key] = element.getAttribute(key);
1048
- }
1196
+ function setAttrsTemp(element, attrs) {
1197
+ let keys = Object.keys(attrs);
1198
+ let oldAttrs = pickAttrs(element, keys);
1049
1199
  setAttrs(element, attrs);
1050
1200
  return () => setAttrs(element, oldAttrs);
1051
1201
  }
@@ -1054,8 +1204,8 @@ up.element = (function () {
1054
1204
  const selector = "meta" + attrSelector('name', name);
1055
1205
  return (_a = first(selector)) === null || _a === void 0 ? void 0 : _a.getAttribute('content');
1056
1206
  }
1057
- function insertBefore(existingElement, newElement) {
1058
- existingElement.insertAdjacentElement('beforebegin', newElement);
1207
+ function insertBefore(existingNode, newNode) {
1208
+ existingNode.parentNode.insertBefore(newNode, existingNode);
1059
1209
  }
1060
1210
  function createFromSelector(selector, attrs = {}) {
1061
1211
  let { includePath } = parseSelector(selector);
@@ -1063,7 +1213,7 @@ up.element = (function () {
1063
1213
  let depthElement;
1064
1214
  let previousElement;
1065
1215
  for (let includeSegment of includePath) {
1066
- let { tagName, id, classNames, attributes } = includeSegment;
1216
+ let { tagName } = includeSegment;
1067
1217
  if (!tagName || tagName === '*') {
1068
1218
  tagName = 'div';
1069
1219
  }
@@ -1071,25 +1221,14 @@ up.element = (function () {
1071
1221
  if (!rootElement) {
1072
1222
  rootElement = depthElement;
1073
1223
  }
1074
- if (id) {
1075
- depthElement.id = id;
1076
- }
1077
- for (let className of classNames) {
1078
- depthElement.classList.add(className);
1079
- }
1080
- for (let attributeName in attributes) {
1081
- let attributeValue = attributes[attributeName];
1082
- depthElement.setAttribute(attributeName, attributeValue || '');
1083
- }
1224
+ makeVariation(depthElement, includeSegment);
1084
1225
  previousElement === null || previousElement === void 0 ? void 0 : previousElement.appendChild(depthElement);
1085
1226
  previousElement = depthElement;
1086
1227
  }
1087
1228
  for (let key in attrs) {
1088
1229
  let value = attrs[key];
1089
1230
  if (key === 'class') {
1090
- for (let klass of u.wrapList(value)) {
1091
- rootElement.classList.add(klass);
1092
- }
1231
+ addClasses(rootElement, u.wrapList(value));
1093
1232
  }
1094
1233
  else if (key === 'style') {
1095
1234
  setInlineStyle(rootElement, value);
@@ -1098,7 +1237,12 @@ up.element = (function () {
1098
1237
  rootElement.textContent = value;
1099
1238
  }
1100
1239
  else if (key === 'content') {
1101
- rootElement.innerHTML = value;
1240
+ if (u.isString(value)) {
1241
+ rootElement.innerHTML = value;
1242
+ }
1243
+ else {
1244
+ rootElement.append(...u.wrapList(value));
1245
+ }
1102
1246
  }
1103
1247
  else {
1104
1248
  rootElement.setAttribute(key, value);
@@ -1106,14 +1250,24 @@ up.element = (function () {
1106
1250
  }
1107
1251
  return rootElement;
1108
1252
  }
1109
- function parseSelector(selector) {
1253
+ function makeVariation(element, { id, classNames, attributes }) {
1254
+ if (id) {
1255
+ element.id = id;
1256
+ }
1257
+ for (let [name, value] of Object.entries(attributes)) {
1258
+ element.setAttribute(name, value);
1259
+ }
1260
+ addClasses(element, classNames);
1261
+ }
1262
+ function parseSelector(rawSelector) {
1110
1263
  let excludeRaw;
1111
- const includeRaw = selector.replace(/:not\([^)]+\)/, function (match) {
1112
- excludeRaw = match;
1264
+ const { masked: selectorOutline, restore: restoreSelectorLiterals, } = u.expressionOutline(rawSelector);
1265
+ const includeWithoutAttrs = selectorOutline.replace(/:not\([^)]*\)/, function (match) {
1266
+ excludeRaw = restoreSelectorLiterals(match);
1113
1267
  return '';
1114
1268
  });
1115
- const [includeSelectorWithoutAttrValues, attrValues] = removeAttrSelectorValues(includeRaw);
1116
- const includeSegments = includeSelectorWithoutAttrValues.split(/[ >]+/);
1269
+ let includeRaw = restoreSelectorLiterals(includeWithoutAttrs);
1270
+ const includeSegments = includeWithoutAttrs.split(/[ >]+/);
1117
1271
  let includePath = includeSegments.map(function (depthSelector) {
1118
1272
  let parsed = {
1119
1273
  tagName: null,
@@ -1133,14 +1287,15 @@ up.element = (function () {
1133
1287
  parsed.classNames.push(className);
1134
1288
  return '';
1135
1289
  });
1136
- if (attrValues.length) {
1137
- depthSelector = replaceAttrSelectors(depthSelector, function ({ name }) {
1138
- parsed.attributes[name] = attrValues.shift();
1139
- return '';
1140
- });
1141
- }
1290
+ depthSelector = depthSelector.replace(/\[[^\]]*]/g, function (attr) {
1291
+ attr = restoreSelectorLiterals(attr);
1292
+ let [_raw, name, _operator, quote, value] = attr.match(/\[([\w-]+)(?:([~|^$*]?=)(["'])?([^\3\]]*?)\3)?]/);
1293
+ quote || (quote = '"');
1294
+ parsed.attributes[name] = value ? u.parseString(quote + value + quote) : '';
1295
+ return '';
1296
+ });
1142
1297
  if (depthSelector) {
1143
- up.fail('Cannot parse selector: ' + selector);
1298
+ up.fail('Cannot parse selector: ' + rawSelector);
1144
1299
  }
1145
1300
  return parsed;
1146
1301
  });
@@ -1150,33 +1305,8 @@ up.element = (function () {
1150
1305
  excludeRaw,
1151
1306
  };
1152
1307
  }
1153
- const ATTR_SELECTOR_PATTERN = /\[([\w-]+)(?:([~|^$*]?=)(["'])?([^\3\]]*?)\3)?]/g;
1154
- function replaceAttrSelectors(string, replacement) {
1155
- return string.replace(ATTR_SELECTOR_PATTERN, function (_match, name, operator, quote, value) {
1156
- if (value) {
1157
- value = value.replace(/\\([\\"'])/, '$1');
1158
- }
1159
- return replacement({ name, operator, quote, value });
1160
- });
1161
- }
1162
- function removeAttrSelectorValues(selector) {
1163
- let values = [];
1164
- selector = replaceAttrSelectors(selector, function ({ name, value }) {
1165
- values.push(value);
1166
- return `[${name}]`;
1167
- });
1168
- return [selector, values];
1169
- }
1170
- function affix(parent, ...args) {
1171
- let position, selector;
1172
- const attributes = u.extractOptions(args);
1173
- if (args.length === 2) {
1174
- [position, selector] = args;
1175
- }
1176
- else {
1177
- position = 'beforeend';
1178
- selector = args[0];
1179
- }
1308
+ function affix(...args) {
1309
+ let [parent, position = 'beforeend', selector, attributes] = u.args(args, 'val', u.isAdjacentPosition, 'val', 'options');
1180
1310
  const element = createFromSelector(selector, attributes);
1181
1311
  parent.insertAdjacentElement(position, element);
1182
1312
  return element;
@@ -1215,14 +1345,22 @@ up.element = (function () {
1215
1345
  scriptish.replaceWith(clone);
1216
1346
  }
1217
1347
  function createFromHTML(html) {
1348
+ return extractSingular(createNodesFromHTML(html));
1349
+ }
1350
+ function extractSingular(nodes) {
1351
+ if (nodes.length === 1 && u.isElementLike(nodes[0])) {
1352
+ return nodes[0];
1353
+ }
1354
+ else {
1355
+ up.fail('Expected a single element, but got %d elements', nodes.length);
1356
+ }
1357
+ }
1358
+ function createNodesFromHTML(html) {
1359
+ html = html.trim();
1218
1360
  const range = document.createRange();
1219
1361
  range.setStart(document.body, 0);
1220
- const fragment = range.createContextualFragment(html.trim());
1221
- let elements = fragment.childNodes;
1222
- if (elements.length !== 1) {
1223
- throw new Error('HTML must have a single root element');
1224
- }
1225
- return elements[0];
1362
+ const fragment = range.createContextualFragment(html);
1363
+ return fragment.childNodes;
1226
1364
  }
1227
1365
  function getRoot() {
1228
1366
  return document.documentElement;
@@ -1231,7 +1369,7 @@ up.element = (function () {
1231
1369
  element.offsetHeight;
1232
1370
  }
1233
1371
  function concludeCSSTransition(element) {
1234
- const undo = setTemporaryStyle(element, { transition: 'none' });
1372
+ const undo = setStyleTemp(element, { transition: 'none' });
1235
1373
  paint(element);
1236
1374
  return undo;
1237
1375
  }
@@ -1264,19 +1402,28 @@ up.element = (function () {
1264
1402
  }
1265
1403
  function unwrap(wrapper) {
1266
1404
  preservingFocus(function () {
1267
- const parent = wrapper.parentNode;
1268
- const wrappedNodes = u.toArray(wrapper.childNodes);
1269
- u.each(wrappedNodes, wrappedNode => parent.insertBefore(wrappedNode, wrapper));
1270
- parent.removeChild(wrapper);
1405
+ let childNodes = [...wrapper.childNodes];
1406
+ for (let child of childNodes)
1407
+ insertBefore(wrapper, child);
1408
+ wrapper.remove();
1271
1409
  });
1272
1410
  }
1273
- function wrapChildren(element) {
1274
- let childNode;
1411
+ function wrapNodes(nodeOrNodes) {
1275
1412
  const wrapper = document.createElement('up-wrapper');
1276
- while ((childNode = element.firstChild)) {
1277
- wrapper.appendChild(childNode);
1413
+ wrapper.append(...u.wrapList(nodeOrNodes));
1414
+ return wrapper;
1415
+ }
1416
+ function wrapIfRequired(nodes) {
1417
+ if (nodes.length === 1 && u.isElement(nodes[0])) {
1418
+ return nodes[0];
1419
+ }
1420
+ else {
1421
+ return wrapNodes(nodes);
1278
1422
  }
1279
- element.appendChild(wrapper);
1423
+ }
1424
+ function wrapChildren(element) {
1425
+ const wrapper = wrapNodes(element.childNodes);
1426
+ element.append(wrapper);
1280
1427
  return wrapper;
1281
1428
  }
1282
1429
  function preservingFocus(fn) {
@@ -1290,77 +1437,91 @@ up.element = (function () {
1290
1437
  }
1291
1438
  }
1292
1439
  }
1440
+ function parseAttr(element, attribute, ...parsers) {
1441
+ var _a;
1442
+ if (!((_a = element.hasAttribute) === null || _a === void 0 ? void 0 : _a.call(element, attribute)))
1443
+ return undefined;
1444
+ let rawValue = element.getAttribute(attribute);
1445
+ for (let parser of parsers) {
1446
+ let parserResult = parser(rawValue, attribute, element);
1447
+ if (u.isDefined(parserResult))
1448
+ return parserResult;
1449
+ }
1450
+ }
1293
1451
  function stringAttr(element, attribute) {
1294
- let value = element.getAttribute(attribute);
1295
- return u.replaceValue(value, null, undefined);
1452
+ return parseAttr(element, attribute, tryParseString);
1296
1453
  }
1297
- function booleanAttr(element, attribute, pass) {
1298
- if (!element.hasAttribute(attribute))
1299
- return;
1300
- const value = stringAttr(element, attribute);
1454
+ let tryParseString = u.identity;
1455
+ function booleanAttr(element, attribute) {
1456
+ return parseAttr(element, attribute, tryParseBoolean);
1457
+ }
1458
+ function tryParseBoolean(value, attribute) {
1301
1459
  switch (value) {
1302
1460
  case 'false': {
1303
1461
  return false;
1304
1462
  }
1305
1463
  case 'true':
1306
1464
  case '':
1307
- case attribute: {
1308
- return true;
1309
- }
1310
- default: {
1311
- if (pass) {
1312
- return value;
1313
- }
1314
- else {
1465
+ case attribute:
1466
+ {
1315
1467
  return true;
1316
1468
  }
1317
- }
1318
1469
  }
1319
1470
  }
1320
- function booleanOrStringAttr(element, attribute, trueValue = true) {
1321
- let value = booleanAttr(element, attribute, true);
1322
- return value === true ? trueValue : value;
1471
+ function booleanOrStringAttr(element, attribute) {
1472
+ return parseAttr(element, attribute, tryParseBoolean, tryParseString);
1473
+ }
1474
+ function booleanOrNumberAttr(element, attribute) {
1475
+ return parseAttr(element, attribute, tryParseBoolean, tryParseNumber);
1323
1476
  }
1324
1477
  function numberAttr(element, attribute) {
1325
- let value = element.getAttribute(attribute);
1326
- if (value) {
1327
- value = value.replace(/_/g, '');
1328
- if (value.match(/^-?[\d.]+$/)) {
1329
- return parseFloat(value);
1330
- }
1478
+ return parseAttr(element, attribute, tryParseNumber);
1479
+ }
1480
+ function tryParseNumber(value) {
1481
+ value = value.replaceAll('_', '');
1482
+ if (value.match(/^-?[\d.]+$/)) {
1483
+ return parseFloat(value);
1331
1484
  }
1332
1485
  }
1333
1486
  function jsonAttr(element, attribute) {
1334
- var _a, _b;
1335
- let json = (_b = (_a = element.getAttribute) === null || _a === void 0 ? void 0 : _a.call(element, attribute)) === null || _b === void 0 ? void 0 : _b.trim();
1336
- if (json) {
1337
- return JSON.parse(json);
1338
- }
1339
- }
1340
- function callbackAttr(link, attr, { exposedKeys = [], mainKey = 'event' } = {}) {
1341
- let code = link.getAttribute(attr);
1342
- if (code) {
1343
- const callback = up.NonceableCallback.fromString(code).toFunction(mainKey, ...exposedKeys);
1344
- return function (event) {
1345
- const exposedValues = Object.values(u.pick(event, exposedKeys));
1346
- return callback.call(link, event, ...exposedValues);
1347
- };
1487
+ return parseAttr(element, attribute, tryParseJSON);
1488
+ }
1489
+ function tryParseJSON(value) {
1490
+ if (value === null || value === void 0 ? void 0 : value.trim()) {
1491
+ return u.parseRelaxedJSON(value);
1348
1492
  }
1349
1493
  }
1350
- function closestAttr(element, attr, parseFn = stringAttr) {
1494
+ function callbackAttr(link, attr, callbackOptions) {
1495
+ return parseAttr(link, attr, (value) => tryParseCallback(value, link, callbackOptions));
1496
+ }
1497
+ function tryParseCallback(code, link, { exposedKeys = [], mainKey = 'event' } = {}) {
1498
+ const callback = up.NonceableCallback.fromString(code).toFunction(mainKey, ...exposedKeys);
1499
+ return function (event) {
1500
+ const exposedValues = Object.values(u.pick(event, exposedKeys));
1501
+ return callback.call(link, event, ...exposedValues);
1502
+ };
1503
+ }
1504
+ function closestAttr(element, attr, readAttrFn = stringAttr) {
1351
1505
  let match = element.closest('[' + attr + ']');
1352
1506
  if (match) {
1353
- return parseFn(match, attr);
1507
+ return readAttrFn(match, attr);
1354
1508
  }
1355
1509
  }
1356
- function setTemporaryStyle(element, newStyles) {
1357
- const oldStyles = inlineStyle(element, Object.keys(newStyles));
1358
- setInlineStyle(element, newStyles);
1359
- return () => setInlineStyle(element, oldStyles);
1510
+ function addClasses(element, classes) {
1511
+ for (let klass of classes)
1512
+ element.classList.add(klass);
1360
1513
  }
1361
- function addTemporaryClass(element, klass) {
1362
- element.classList.add(klass);
1363
- return () => element.classList.remove(klass);
1514
+ function addClassTemp(element, klass) {
1515
+ return setClassStateTemp(element, klass, true);
1516
+ }
1517
+ function removeClassTemp(element, klass) {
1518
+ return setClassStateTemp(element, klass, false);
1519
+ }
1520
+ function setClassStateTemp(element, klass, targetState) {
1521
+ if (element.classList.contains(klass) === targetState)
1522
+ return u.noop;
1523
+ element.classList.toggle(klass, targetState);
1524
+ return () => element.classList.toggle(klass, !targetState);
1364
1525
  }
1365
1526
  function computedStyle(element, props) {
1366
1527
  const style = window.getComputedStyle(element);
@@ -1400,16 +1561,24 @@ up.element = (function () {
1400
1561
  }
1401
1562
  }
1402
1563
  }
1564
+ function setStyleTemp(element, newStyles) {
1565
+ const oldStyles = inlineStyle(element, Object.keys(newStyles));
1566
+ setInlineStyle(element, newStyles);
1567
+ return () => setInlineStyle(element, oldStyles);
1568
+ }
1403
1569
  function isVisible(element) {
1404
1570
  return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
1405
1571
  }
1406
1572
  function isUpPrefixed(string) {
1407
1573
  return /^up-/.test(string);
1408
1574
  }
1409
- function upAttrs(element) {
1410
- let attrNames = u.filter(element.getAttributeNames(), isUpPrefixed);
1575
+ function pickAttrs(element, attrNames) {
1411
1576
  return u.mapObject(attrNames, (name) => [name, element.getAttribute(name)]);
1412
1577
  }
1578
+ function upAttrs(element) {
1579
+ let attrNames = element.getAttributeNames().filter(isUpPrefixed);
1580
+ return pickAttrs(element, attrNames);
1581
+ }
1413
1582
  function upClasses(element) {
1414
1583
  return u.filter(element.classList.values(), isUpPrefixed);
1415
1584
  }
@@ -1436,8 +1605,29 @@ up.element = (function () {
1436
1605
  selector += `:not(${excludes.join()})`;
1437
1606
  return selector;
1438
1607
  }
1608
+ function matchSelectorMap(selectorMap, element) {
1609
+ let matches = [];
1610
+ if (selectorMap) {
1611
+ for (let [selector, value] of Object.entries(selectorMap)) {
1612
+ if (u.isDefined(value) && element.matches(selector)) {
1613
+ matches.push(value);
1614
+ }
1615
+ }
1616
+ }
1617
+ return matches;
1618
+ }
1619
+ function documentPosition(element) {
1620
+ let nextSibling = element.nextElementSibling;
1621
+ if (nextSibling) {
1622
+ return [nextSibling, 'beforebegin'];
1623
+ }
1624
+ else {
1625
+ return [element.parentElement, 'beforeend'];
1626
+ }
1627
+ }
1439
1628
  return {
1440
1629
  subtree,
1630
+ subtreeFirst,
1441
1631
  contains,
1442
1632
  closestAttr,
1443
1633
  ancestor,
@@ -1446,12 +1636,14 @@ up.element = (function () {
1446
1636
  list: getList,
1447
1637
  toggle,
1448
1638
  hide,
1639
+ hideTemp,
1449
1640
  show,
1641
+ showTemp,
1450
1642
  metaContent,
1451
1643
  insertBefore,
1452
1644
  createFromSelector,
1453
1645
  setAttrs,
1454
- setTemporaryAttrs,
1646
+ setAttrsTemp,
1455
1647
  affix,
1456
1648
  idSelector,
1457
1649
  classSelector,
@@ -1460,7 +1652,9 @@ up.element = (function () {
1460
1652
  tagName: elementTagName,
1461
1653
  createBrokenDocumentFromHTML,
1462
1654
  fixParserDamage,
1655
+ createNodesFromHTML,
1463
1656
  createFromHTML,
1657
+ extractSingular,
1464
1658
  get root() { return getRoot(); },
1465
1659
  paint,
1466
1660
  concludeCSSTransition,
@@ -1470,13 +1664,15 @@ up.element = (function () {
1470
1664
  setMissingAttr,
1471
1665
  unwrap,
1472
1666
  wrapChildren,
1667
+ wrapIfRequired,
1473
1668
  attr: stringAttr,
1474
1669
  booleanAttr,
1475
1670
  numberAttr,
1476
1671
  jsonAttr,
1477
1672
  callbackAttr,
1478
1673
  booleanOrStringAttr,
1479
- setTemporaryStyle,
1674
+ booleanOrNumberAttr,
1675
+ setStyleTemp,
1480
1676
  style: computedStyle,
1481
1677
  styleNumber: computedStyleNumber,
1482
1678
  inlineStyle,
@@ -1484,14 +1680,19 @@ up.element = (function () {
1484
1680
  isVisible,
1485
1681
  upAttrs,
1486
1682
  upClasses,
1487
- toggleAttr,
1488
- addTemporaryClass,
1683
+ setAttrPresence,
1684
+ addClasses,
1685
+ addClassTemp,
1686
+ removeClassTemp,
1489
1687
  cleanJQuery,
1490
1688
  parseSelector,
1491
1689
  isEmpty,
1492
1690
  crossOriginSelector,
1493
1691
  isIntersectingWindow,
1494
1692
  unionSelector,
1693
+ matchSelectorMap,
1694
+ elementLikeMatches,
1695
+ documentPosition,
1495
1696
  };
1496
1697
  })();
1497
1698
 
@@ -1685,6 +1886,9 @@ up.OptionsParser = class OptionsParser {
1685
1886
  booleanOrString(key, keyOptions) {
1686
1887
  this.parse(e.booleanOrStringAttr, key, keyOptions);
1687
1888
  }
1889
+ booleanOrNumber(key, keyOptions) {
1890
+ this.parse(e.booleanOrNumberAttr, key, keyOptions);
1891
+ }
1688
1892
  json(key, keyOptions) {
1689
1893
  this.parse(e.jsonAttr, key, keyOptions);
1690
1894
  }
@@ -1805,16 +2009,17 @@ up.Rect = class Rect extends up.Record {
1805
2009
  /***/ (() => {
1806
2010
 
1807
2011
  const e = up.element;
2012
+ const u = up.util;
1808
2013
  const SHIFT_CLASS = 'up-scrollbar-away';
1809
2014
  up.BodyShifter = class BodyShifter {
1810
2015
  constructor() {
1811
2016
  this._anchoredElements = new Set();
1812
2017
  this._stack = 0;
1813
- this._cleaners = [];
2018
+ this._cleaner = u.cleaner();
1814
2019
  }
1815
2020
  lowerStack() {
1816
2021
  if (--this._stack === 0)
1817
- this._unshiftNow();
2022
+ this._cleaner.clean();
1818
2023
  }
1819
2024
  raiseStack() {
1820
2025
  if (++this._stack === 1)
@@ -1830,7 +2035,7 @@ up.BodyShifter = class BodyShifter {
1830
2035
  }
1831
2036
  _shiftNow() {
1832
2037
  this._rootScrollbarWidth = up.viewport.rootScrollbarWidth();
1833
- this._cleaners.push(e.setTemporaryStyle(e.root, {
2038
+ this._cleaner(e.setStyleTemp(e.root, {
1834
2039
  '--up-scrollbar-width': this._rootScrollbarWidth + 'px'
1835
2040
  }));
1836
2041
  this._shiftElement(document.body, 'padding-right');
@@ -1842,13 +2047,7 @@ up.BodyShifter = class BodyShifter {
1842
2047
  if (!this._isShifted())
1843
2048
  return;
1844
2049
  let originalValue = e.style(element, styleProp);
1845
- this._cleaners.push(e.setTemporaryStyle(element, { ['--up-original-' + styleProp]: originalValue }), e.addTemporaryClass(element, SHIFT_CLASS));
1846
- }
1847
- _unshiftNow() {
1848
- let cleaner;
1849
- while (cleaner = this._cleaners.pop()) {
1850
- cleaner();
1851
- }
2050
+ this._cleaner(e.setStyleTemp(element, { ['--up-original-' + styleProp]: originalValue }), e.addClassTemp(element, SHIFT_CLASS));
1852
2051
  }
1853
2052
  };
1854
2053
 
@@ -1865,10 +2064,6 @@ up.Change = class Change {
1865
2064
  execute() {
1866
2065
  throw new up.NotImplemented();
1867
2066
  }
1868
- onFinished(renderResult) {
1869
- var _a, _b;
1870
- return (_b = (_a = this.options).onFinished) === null || _b === void 0 ? void 0 : _b.call(_a, renderResult);
1871
- }
1872
2067
  improveHistoryValue(existingValue, newValue) {
1873
2068
  if ((existingValue === false) || u.isString(existingValue)) {
1874
2069
  return existingValue;
@@ -1899,30 +2094,30 @@ up.Change.Addition = class Addition extends up.Change {
1899
2094
  }
1900
2095
  handleLayerChangeRequests() {
1901
2096
  if (this.layer.isOverlay()) {
1902
- this.tryAcceptLayerFromServer();
2097
+ this._tryAcceptLayerFromServer();
1903
2098
  this.abortWhenLayerClosed();
1904
- this.layer.tryAcceptForLocation(this.responseOption());
2099
+ this.layer.tryAcceptForLocation(this._responseOptions());
1905
2100
  this.abortWhenLayerClosed();
1906
- this.tryDismissLayerFromServer();
2101
+ this._tryDismissLayerFromServer();
1907
2102
  this.abortWhenLayerClosed();
1908
- this.layer.tryDismissForLocation(this.responseOption());
2103
+ this.layer.tryDismissForLocation(this._responseOptions());
1909
2104
  this.abortWhenLayerClosed();
1910
2105
  }
1911
2106
  this.layer.asCurrent(() => {
1912
2107
  for (let eventPlan of this._eventPlans) {
1913
- up.emit(Object.assign(Object.assign({}, eventPlan), this.responseOption()));
2108
+ up.emit(Object.assign(Object.assign({}, eventPlan), this._responseOptions()));
1914
2109
  this.abortWhenLayerClosed();
1915
2110
  }
1916
2111
  });
1917
2112
  }
1918
- tryAcceptLayerFromServer() {
2113
+ _tryAcceptLayerFromServer() {
1919
2114
  if (u.isDefined(this._acceptLayer) && this.layer.isOverlay()) {
1920
- this.layer.accept(this._acceptLayer, this.responseOption());
2115
+ this.layer.accept(this._acceptLayer, this._responseOptions());
1921
2116
  }
1922
2117
  }
1923
- tryDismissLayerFromServer() {
2118
+ _tryDismissLayerFromServer() {
1924
2119
  if (u.isDefined(this._dismissLayer) && this.layer.isOverlay()) {
1925
- this.layer.dismiss(this._dismissLayer, this.responseOption());
2120
+ this.layer.dismiss(this._dismissLayer, this._responseOptions());
1926
2121
  }
1927
2122
  }
1928
2123
  abortWhenLayerClosed(layer = this.layer) {
@@ -1930,7 +2125,7 @@ up.Change.Addition = class Addition extends up.Change {
1930
2125
  throw new up.Aborted('Layer was closed');
1931
2126
  }
1932
2127
  }
1933
- setSource({ oldElement, newElement, source }) {
2128
+ _setSource({ oldElement, newElement, source }) {
1934
2129
  if (source === 'keep') {
1935
2130
  source = (oldElement && up.fragment.source(oldElement));
1936
2131
  }
@@ -1938,18 +2133,18 @@ up.Change.Addition = class Addition extends up.Change {
1938
2133
  e.setMissingAttr(newElement, 'up-source', up.fragment.normalizeSource(source));
1939
2134
  }
1940
2135
  }
1941
- setTime({ newElement, time }) {
2136
+ _setTime({ newElement, time }) {
1942
2137
  e.setMissingAttr(newElement, 'up-time', time ? time.toUTCString() : false);
1943
2138
  }
1944
- setETag({ newElement, etag }) {
2139
+ _setETag({ newElement, etag }) {
1945
2140
  e.setMissingAttr(newElement, 'up-etag', etag || false);
1946
2141
  }
1947
2142
  setReloadAttrs(options) {
1948
- this.setSource(options);
1949
- this.setTime(options);
1950
- this.setETag(options);
2143
+ this._setSource(options);
2144
+ this._setTime(options);
2145
+ this._setETag(options);
1951
2146
  }
1952
- responseOption() {
2147
+ _responseOptions() {
1953
2148
  return { response: this._response };
1954
2149
  }
1955
2150
  executeSteps(steps, responseDoc, noneOptions) {
@@ -1984,8 +2179,10 @@ up.RenderJob = (_a = class RenderJob {
1984
2179
  _executePromise() {
1985
2180
  return __awaiter(this, void 0, void 0, function* () {
1986
2181
  try {
1987
- this._guardRender();
2182
+ this._emitGuardEvent();
1988
2183
  this.options = up.RenderOptions.preprocess(this.options);
2184
+ up.browser.assertConfirmed(this.options);
2185
+ up.RenderOptions.assertContentGiven(this.options);
1989
2186
  let result = yield this._getChange().execute();
1990
2187
  this._handleResult(result);
1991
2188
  return result;
@@ -2033,21 +2230,19 @@ up.RenderJob = (_a = class RenderJob {
2033
2230
  });
2034
2231
  }
2035
2232
  _getChange() {
2036
- if (this.options.url) {
2037
- let onRequest = (request) => this._handleAbortOption(request);
2038
- return new up.Change.FromURL(Object.assign(Object.assign({}, this.options), { onRequest }));
2233
+ let handleAbort = u.memoize((request) => this._handleAbortOption(request));
2234
+ let renderOptions = Object.assign(Object.assign({}, this.options), { handleAbort });
2235
+ if (renderOptions.url) {
2236
+ return new up.Change.FromURL(renderOptions);
2039
2237
  }
2040
- else if (this.options.response) {
2041
- let onRender = () => this._handleAbortOption(null);
2042
- return new up.Change.FromResponse(Object.assign(Object.assign({}, this.options), { onRender }));
2238
+ else if (renderOptions.response) {
2239
+ return new up.Change.FromResponse(renderOptions);
2043
2240
  }
2044
2241
  else {
2045
- let onRender = () => this._handleAbortOption(null);
2046
- return new up.Change.FromContent(Object.assign(Object.assign({}, this.options), { onRender }));
2242
+ return new up.Change.FromContent(renderOptions);
2047
2243
  }
2048
2244
  }
2049
- _guardRender() {
2050
- up.browser.assertConfirmed(this.options);
2245
+ _emitGuardEvent() {
2051
2246
  let guardEvent = u.pluckKey(this.options, 'guardEvent');
2052
2247
  if (guardEvent) {
2053
2248
  guardEvent.renderOptions = this.options;
@@ -2055,24 +2250,23 @@ up.RenderJob = (_a = class RenderJob {
2055
2250
  throw new up.Aborted(`Rendering was prevented by ${guardEvent.type} listener`);
2056
2251
  }
2057
2252
  }
2058
- up.RenderOptions.assertContentGiven(this.options);
2059
2253
  }
2060
2254
  _handleAbortOption(request) {
2061
2255
  let { abort } = this.options;
2062
2256
  if (!abort || !up.network.isBusy())
2063
2257
  return;
2064
- let { fragments, layer, origin, newLayer } = this._getChange().getPreflightProps();
2258
+ let { bindFragments, bindLayer, origin, layer } = this._getChange().getPreflightProps();
2065
2259
  let abortOptions = {
2066
2260
  except: request,
2067
2261
  logOnce: ['up.render()', 'Change with { abort } option will abort other requests'],
2068
- newLayer,
2262
+ newLayer: (layer === 'new'),
2069
2263
  origin,
2070
2264
  };
2071
2265
  if (abort === 'target') {
2072
- up.fragment.abort(fragments, abortOptions);
2266
+ up.fragment.abort(bindFragments, Object.assign({}, abortOptions));
2073
2267
  }
2074
2268
  else if (abort === 'layer') {
2075
- up.fragment.abort(Object.assign(Object.assign({}, abortOptions), { layer }));
2269
+ up.fragment.abort(Object.assign(Object.assign({}, abortOptions), { layer: bindLayer }));
2076
2270
  }
2077
2271
  else if (abort === 'all' || abort === true) {
2078
2272
  up.fragment.abort(Object.assign(Object.assign({}, abortOptions), { layer: 'any' }));
@@ -2081,12 +2275,12 @@ up.RenderJob = (_a = class RenderJob {
2081
2275
  abort(abortOptions);
2082
2276
  }
2083
2277
  else {
2084
- up.fragment.abort(abort, Object.assign(Object.assign({}, abortOptions), { layer }));
2278
+ up.fragment.abort(abort, Object.assign(Object.assign({}, abortOptions), { layer: bindLayer }));
2085
2279
  }
2086
2280
  }
2087
2281
  },
2088
2282
  (() => {
2089
- u.delegate(_a.prototype, ['then', 'catch', 'finally'], function () { return this._rendered; });
2283
+ u.delegatePromise(_a.prototype, '_rendered');
2090
2284
  u.memoizeMethod(_a.prototype, {
2091
2285
  _awaitFinished: true,
2092
2286
  _getChange: true,
@@ -2097,14 +2291,6 @@ up.RenderJob = (_a = class RenderJob {
2097
2291
 
2098
2292
  /***/ }),
2099
2293
  /* 26 */
2100
- /***/ (() => {
2101
-
2102
- up.Change.Removal = class Removal extends up.Change {
2103
- };
2104
-
2105
-
2106
- /***/ }),
2107
- /* 27 */
2108
2294
  /***/ (function() {
2109
2295
 
2110
2296
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -2116,13 +2302,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2116
2302
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2117
2303
  });
2118
2304
  };
2119
- up.Change.DestroyFragment = class DestroyFragment extends up.Change.Removal {
2305
+ up.Change.DestroyFragment = class DestroyFragment extends up.Change {
2120
2306
  constructor(options) {
2121
2307
  super(options);
2122
2308
  this._layer = up.layer.get(options) || up.layer.current;
2123
2309
  this._element = this.options.element;
2124
2310
  this._animation = this.options.animation;
2125
2311
  this._log = this.options.log;
2312
+ this._onFinished = this.options.onFinished;
2126
2313
  }
2127
2314
  execute() {
2128
2315
  this._parent = this._element.parentNode;
@@ -2135,17 +2322,19 @@ up.Change.DestroyFragment = class DestroyFragment extends up.Change.Removal {
2135
2322
  }
2136
2323
  }
2137
2324
  _destroyAfterAnimation() {
2325
+ var _a;
2138
2326
  return __awaiter(this, void 0, void 0, function* () {
2139
2327
  this._emitDestroyed();
2140
2328
  yield this._animate();
2141
2329
  this._wipe();
2142
- this.onFinished();
2330
+ (_a = this._onFinished) === null || _a === void 0 ? void 0 : _a.call(this);
2143
2331
  });
2144
2332
  }
2145
2333
  _destroyNow() {
2334
+ var _a;
2146
2335
  this._wipe();
2147
2336
  this._emitDestroyed();
2148
- this.onFinished();
2337
+ (_a = this._onFinished) === null || _a === void 0 ? void 0 : _a.call(this);
2149
2338
  }
2150
2339
  _animate() {
2151
2340
  return up.motion.animate(this._element, this._animation, this.options);
@@ -2165,7 +2354,7 @@ up.Change.DestroyFragment = class DestroyFragment extends up.Change.Removal {
2165
2354
 
2166
2355
 
2167
2356
  /***/ }),
2168
- /* 28 */
2357
+ /* 27 */
2169
2358
  /***/ (function() {
2170
2359
 
2171
2360
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -2191,9 +2380,10 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2191
2380
  context: this._buildLayer().context,
2192
2381
  origin: this.options.origin,
2193
2382
  target: this.target,
2194
- layer: this._baseLayer,
2195
- fragments: u.compact([up.fragment.get(':main', { layer: this._baseLayer })]),
2196
- newLayer: true,
2383
+ bindLayer: this._baseLayer,
2384
+ layer: 'new',
2385
+ bindFragments: u.compact([up.fragment.get(':main', { layer: this._baseLayer })]),
2386
+ fragments: [],
2197
2387
  };
2198
2388
  }
2199
2389
  execute(responseDoc, onApplicable) {
@@ -2243,7 +2433,7 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2243
2433
  fragments: [this._content],
2244
2434
  target: this.target,
2245
2435
  });
2246
- up.hello(this.layer.element, Object.assign(Object.assign({}, this.options), { layer: this.layer }));
2436
+ up.hello(this.layer.element, Object.assign(Object.assign({}, this.options), { layer: this.layer, dataRoot: this._content }));
2247
2437
  this._handleScroll();
2248
2438
  this._newOverlayResult.finished = this._finish();
2249
2439
  this.layer.opening = false;
@@ -2323,7 +2513,7 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2323
2513
 
2324
2514
 
2325
2515
  /***/ }),
2326
- /* 29 */
2516
+ /* 28 */
2327
2517
  /***/ (() => {
2328
2518
 
2329
2519
  var _a;
@@ -2339,14 +2529,16 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2339
2529
  }
2340
2530
  getPreflightProps() {
2341
2531
  this._matchPreflight();
2532
+ let fragments = this._getFragments();
2342
2533
  return {
2343
2534
  layer: this.layer,
2535
+ bindLayer: this.layer,
2344
2536
  mode: this.layer.mode,
2345
2537
  context: u.merge(this.layer.context, this._context),
2346
2538
  origin: this.options.origin,
2347
2539
  target: this._bestPreflightSelector(),
2348
- fragments: this._getFragments(),
2349
- newLayer: false,
2540
+ fragments,
2541
+ bindFragments: fragments,
2350
2542
  };
2351
2543
  }
2352
2544
  _bestPreflightSelector() {
@@ -2468,7 +2660,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2468
2660
 
2469
2661
 
2470
2662
  /***/ }),
2471
- /* 30 */
2663
+ /* 29 */
2472
2664
  /***/ (function() {
2473
2665
 
2474
2666
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -2547,7 +2739,7 @@ up.Change.UpdateSteps = class UpdateSteps extends up.Change.Addition {
2547
2739
  }, beforeDetach: () => {
2548
2740
  up.script.clean(step.oldElement, { layer: step.layer });
2549
2741
  }, afterDetach() {
2550
- up.element.cleanJQuery();
2742
+ e.cleanJQuery();
2551
2743
  up.fragment.emitDestroyed(step.oldElement, { parent, log: false });
2552
2744
  }, scrollNew: () => {
2553
2745
  this._handleFocus(step.newElement, step);
@@ -2583,7 +2775,7 @@ up.Change.UpdateSteps = class UpdateSteps extends up.Change.Addition {
2583
2775
  }
2584
2776
  }
2585
2777
  _findKeepPlan(options) {
2586
- if (!options.useKeep) {
2778
+ if (!options.keep) {
2587
2779
  return;
2588
2780
  }
2589
2781
  const { oldElement, newElement } = options;
@@ -2598,7 +2790,7 @@ up.Change.UpdateSteps = class UpdateSteps extends up.Change.Addition {
2598
2790
  partner = up.fragment.get(newElement, partnerSelector, lookupOpts);
2599
2791
  }
2600
2792
  else {
2601
- partner = up.fragment.subtree(newElement, partnerSelector, lookupOpts)[0];
2793
+ partner = e.subtreeFirst(newElement, partnerSelector, lookupOpts);
2602
2794
  }
2603
2795
  if (partner && e.booleanAttr(partner, 'up-keep') !== false) {
2604
2796
  const plan = {
@@ -2614,7 +2806,7 @@ up.Change.UpdateSteps = class UpdateSteps extends up.Change.Addition {
2614
2806
  }
2615
2807
  _preserveKeepables(step) {
2616
2808
  const keepPlans = [];
2617
- if (step.useKeep) {
2809
+ if (step.keep) {
2618
2810
  for (let keepable of step.oldElement.querySelectorAll('[up-keep]')) {
2619
2811
  let keepPlan = this._findKeepPlan(Object.assign(Object.assign({}, step), { oldElement: keepable, descendantsOnly: true }));
2620
2812
  if (keepPlan) {
@@ -2667,11 +2859,11 @@ up.Change.UpdateSteps = class UpdateSteps extends up.Change.Addition {
2667
2859
 
2668
2860
 
2669
2861
  /***/ }),
2670
- /* 31 */
2862
+ /* 30 */
2671
2863
  /***/ (() => {
2672
2864
 
2673
2865
  const u = up.util;
2674
- up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2866
+ up.Change.CloseLayer = class CloseLayer extends up.Change {
2675
2867
  constructor(options) {
2676
2868
  var _a, _b;
2677
2869
  super(options);
@@ -2745,28 +2937,38 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2745
2937
 
2746
2938
 
2747
2939
  /***/ }),
2748
- /* 32 */
2749
- /***/ (() => {
2940
+ /* 31 */
2941
+ /***/ (function() {
2750
2942
 
2943
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2944
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2945
+ return new (P || (P = Promise))(function (resolve, reject) {
2946
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2947
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2948
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2949
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2950
+ });
2951
+ };
2751
2952
  var _a;
2752
2953
  const u = up.util;
2753
2954
  up.Change.FromURL = (_a = class FromURL extends up.Change {
2754
2955
  execute() {
2755
- var _b, _c;
2756
- let _newPageReason = this._newPageReason();
2757
- if (_newPageReason) {
2758
- up.puts('up.render()', _newPageReason);
2759
- up.network.loadPage(this.options);
2760
- return u.unresolvablePromise();
2761
- }
2762
- this.request = up.request(this._getRequestAttrs());
2763
- (_c = (_b = this.options).onRequest) === null || _c === void 0 ? void 0 : _c.call(_b, this.request);
2764
- up.feedback.showAroundRequest(this.request, this.options);
2765
- up.form.disableWhile(this.request, this.options);
2766
- if (this.options.preload) {
2767
- return this.request;
2768
- }
2769
- return u.always(this.request, responseOrError => this._onRequestSettled(responseOrError));
2956
+ var _b, _c, _d, _e;
2957
+ return __awaiter(this, void 0, void 0, function* () {
2958
+ let newPageReason = this._newPageReason();
2959
+ if (newPageReason) {
2960
+ up.puts('up.render()', newPageReason);
2961
+ up.network.loadPage(this.options);
2962
+ return u.unresolvablePromise();
2963
+ }
2964
+ let request = this.request = up.request(this._getRequestAttrs());
2965
+ (_c = (_b = this.options).onRequestKnown) === null || _c === void 0 ? void 0 : _c.call(_b, request);
2966
+ if (this.options.preload)
2967
+ return request;
2968
+ (_e = (_d = this.options).handleAbort) === null || _e === void 0 ? void 0 : _e.call(_d, request);
2969
+ request.runPreviews(this.options);
2970
+ return yield u.always(request, responseOrError => this._onRequestSettled(responseOrError));
2971
+ });
2770
2972
  }
2771
2973
  _newPageReason() {
2772
2974
  if (u.isCrossOrigin(this.options.url)) {
@@ -2779,14 +2981,14 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2779
2981
  _getRequestAttrs() {
2780
2982
  const successAttrs = this._preflightPropsForRenderOptions(this.options);
2781
2983
  const failAttrs = this._preflightPropsForRenderOptions(this.deriveFailOptions(), { optional: true });
2782
- return Object.assign(Object.assign(Object.assign({}, this.options), successAttrs), u.renameKeys(failAttrs, up.fragment.failKey));
2984
+ return Object.assign(Object.assign(Object.assign({}, this.options), successAttrs), u.withRenamedKeys(failAttrs, up.fragment.failKey));
2783
2985
  }
2784
2986
  getPreflightProps() {
2785
2987
  return this._getRequestAttrs();
2786
2988
  }
2787
- _preflightPropsForRenderOptions(renderOptions, requestAttributesOptions) {
2788
- const preview = new up.Change.FromContent(Object.assign(Object.assign({}, renderOptions), { preview: true }));
2789
- return preview.getPreflightProps(requestAttributesOptions);
2989
+ _preflightPropsForRenderOptions(renderOptions, getPreflightPropsOptions) {
2990
+ const preflightChange = new up.Change.FromContent(Object.assign(Object.assign({}, renderOptions), { preflight: true }));
2991
+ return preflightChange.getPreflightProps(getPreflightPropsOptions);
2790
2992
  }
2791
2993
  _onRequestSettled(response) {
2792
2994
  if (response instanceof up.Response) {
@@ -2820,7 +3022,7 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2820
3022
 
2821
3023
 
2822
3024
  /***/ }),
2823
- /* 33 */
3025
+ /* 32 */
2824
3026
  /***/ (function() {
2825
3027
 
2826
3028
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -2887,7 +3089,7 @@ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2887
3089
  }
2888
3090
  else {
2889
3091
  up.puts('up.render()', 'Revalidating cached response for target "%s"', effectiveTarget);
2890
- let verifyResult = yield up.reload(effectiveTarget, Object.assign(Object.assign({}, originalRenderOptions), { preferOldElements: renderResult.fragments, layer: renderResult.layer, onFinished: null, scroll: false, focus: 'keep', transition: false, cache: false, confirm: false, feedback: false, abort: false, expiredResponse: this._response }));
3092
+ let verifyResult = yield up.reload(effectiveTarget, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, originalRenderOptions), up.RenderOptions.NO_MOTION), up.RenderOptions.NO_INPUT_INTERFERENCE), up.RenderOptions.NO_PREVIEWS), { preferOldElements: renderResult.fragments, layer: renderResult.layer, onFinished: null, expiredResponse: this._response, preview: this._revalidatePreview(originalRenderOptions), abort: false, cache: false, background: true }));
2891
3093
  if (!verifyResult.none) {
2892
3094
  renderResult = verifyResult;
2893
3095
  }
@@ -2895,6 +3097,14 @@ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2895
3097
  return renderResult;
2896
3098
  });
2897
3099
  }
3100
+ _revalidatePreview({ preview, revalidatePreview }) {
3101
+ if (revalidatePreview === true) {
3102
+ return preview;
3103
+ }
3104
+ else {
3105
+ return revalidatePreview;
3106
+ }
3107
+ }
2898
3108
  _loadedEventProps() {
2899
3109
  const { expiredResponse } = this.options;
2900
3110
  return {
@@ -2956,7 +3166,7 @@ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2956
3166
 
2957
3167
 
2958
3168
  /***/ }),
2959
- /* 34 */
3169
+ /* 33 */
2960
3170
  /***/ (() => {
2961
3171
 
2962
3172
  var _a;
@@ -2965,7 +3175,7 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
2965
3175
  constructor(options) {
2966
3176
  super(options);
2967
3177
  this._origin = options.origin;
2968
- this._preview = options.preview;
3178
+ this._preflight = options.preflight;
2969
3179
  this._layers = up.layer.getAll(options);
2970
3180
  }
2971
3181
  _getPlans() {
@@ -3018,11 +3228,11 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
3018
3228
  if (assets) {
3019
3229
  up.script.assertAssetsOK(assets, plan.options);
3020
3230
  }
3021
- (_c = (_b = this.options).onRender) === null || _c === void 0 ? void 0 : _c.call(_b);
3231
+ (_c = (_b = this.options).handleAbort) === null || _c === void 0 ? void 0 : _c.call(_b, null);
3022
3232
  }
3023
3233
  _getResponseDoc() {
3024
3234
  var _b, _c;
3025
- if (this._preview)
3235
+ if (this._preflight)
3026
3236
  return;
3027
3237
  const docOptions = u.pick(this.options, [
3028
3238
  'target',
@@ -3032,6 +3242,7 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
3032
3242
  'html',
3033
3243
  'cspNonces',
3034
3244
  'origin',
3245
+ 'data',
3035
3246
  ]);
3036
3247
  (_c = (_b = up.migrate).handleResponseDocOptions) === null || _c === void 0 ? void 0 : _c.call(_b, docOptions);
3037
3248
  if (this._defaultPlacement() === 'content') {
@@ -3041,7 +3252,7 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
3041
3252
  }
3042
3253
  _improveOptionsFromResponseDoc() {
3043
3254
  var _b;
3044
- if (this._preview)
3255
+ if (this._preflight)
3045
3256
  return;
3046
3257
  let responseDoc = this._getResponseDoc();
3047
3258
  if (this.options.fragment) {
@@ -3113,17 +3324,18 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
3113
3324
 
3114
3325
 
3115
3326
  /***/ }),
3116
- /* 35 */
3327
+ /* 34 */
3117
3328
  /***/ (() => {
3118
3329
 
3119
3330
  const u = up.util;
3120
3331
  up.CompilerPass = class CompilerPass {
3121
- constructor(root, compilers, { layer, data, dataMap, meta }) {
3332
+ constructor(root, compilers, { layer, data, dataRoot, dataMap, meta }) {
3122
3333
  layer || (layer = up.layer.get(root) || up.layer.current);
3123
3334
  this._root = root;
3124
3335
  this._compilers = compilers;
3125
3336
  this._layer = layer;
3126
3337
  this._data = data;
3338
+ this._dataRoot = dataRoot || root;
3127
3339
  this._dataMap = dataMap;
3128
3340
  meta || (meta = {});
3129
3341
  meta.layer = layer;
@@ -3139,7 +3351,7 @@ up.CompilerPass = class CompilerPass {
3139
3351
  }
3140
3352
  setCompileData() {
3141
3353
  if (this._data) {
3142
- this._root.upCompileData = this._data;
3354
+ this._dataRoot.upCompileData = this._data;
3143
3355
  }
3144
3356
  if (this._dataMap) {
3145
3357
  for (let selector in this._dataMap) {
@@ -3175,10 +3387,7 @@ up.CompilerPass = class CompilerPass {
3175
3387
  compileArgs.push(data, this._meta);
3176
3388
  }
3177
3389
  const result = this._applyCompilerFunction(compiler, element, compileArgs);
3178
- let destructorOrDestructors = this._destructorPresence(result);
3179
- if (destructorOrDestructors) {
3180
- up.destructor(element, destructorOrDestructors);
3181
- }
3390
+ up.destructor(element, result);
3182
3391
  }
3183
3392
  _compileBatch(compiler, elements) {
3184
3393
  const compileArgs = [elements];
@@ -3187,18 +3396,13 @@ up.CompilerPass = class CompilerPass {
3187
3396
  compileArgs.push(dataList, this._meta);
3188
3397
  }
3189
3398
  const result = this._applyCompilerFunction(compiler, elements, compileArgs);
3190
- if (this._destructorPresence(result)) {
3399
+ if (result) {
3191
3400
  up.fail('Compilers with { batch: true } cannot return destructors');
3192
3401
  }
3193
3402
  }
3194
3403
  _applyCompilerFunction(compiler, elementOrElements, compileArgs) {
3195
3404
  return up.error.guard(() => compiler.apply(elementOrElements, compileArgs));
3196
3405
  }
3197
- _destructorPresence(result) {
3198
- if (u.isFunction(result) || (u.isArray(result) && (u.every(result, u.isFunction)))) {
3199
- return result;
3200
- }
3201
- }
3202
3406
  _select(selector) {
3203
3407
  return up.fragment.subtree(this._root, u.evalOption(selector), { layer: this._layer });
3204
3408
  }
@@ -3216,7 +3420,7 @@ up.CompilerPass = class CompilerPass {
3216
3420
 
3217
3421
 
3218
3422
  /***/ }),
3219
- /* 36 */
3423
+ /* 35 */
3220
3424
  /***/ (() => {
3221
3425
 
3222
3426
  const u = up.util;
@@ -3301,7 +3505,7 @@ up.CSSTransition = class CSSTransition {
3301
3505
  if (oldTransition['transition-property'] !== 'all') {
3302
3506
  const oldTransitionProperties = oldTransition['transition-property'].split(/\s*,\s*/);
3303
3507
  const oldTransitionFrame = e.style(this._element, oldTransitionProperties);
3304
- this._setOldTransitionTargetFrame = e.setTemporaryStyle(this._element, oldTransitionFrame);
3508
+ this._setOldTransitionTargetFrame = e.setStyleTemp(this._element, oldTransitionFrame);
3305
3509
  }
3306
3510
  this._setOldTransition = e.concludeCSSTransition(this._element);
3307
3511
  }
@@ -3323,7 +3527,7 @@ up.CSSTransition = class CSSTransition {
3323
3527
 
3324
3528
 
3325
3529
  /***/ }),
3326
- /* 37 */
3530
+ /* 36 */
3327
3531
  /***/ (() => {
3328
3532
 
3329
3533
  const u = up.util;
@@ -3334,27 +3538,19 @@ up.DestructorPass = class DestructorPass {
3334
3538
  }
3335
3539
  run() {
3336
3540
  for (let cleanable of this._selectCleanables()) {
3337
- let destructors = u.pluckKey(cleanable, 'upDestructors');
3338
- if (destructors) {
3339
- for (let destructor of destructors) {
3340
- this._applyDestructorFunction(destructor, cleanable);
3341
- }
3342
- }
3343
- cleanable.classList.remove('up-can-clean');
3541
+ let registry = u.pluckKey(cleanable, 'upDestructors');
3542
+ registry === null || registry === void 0 ? void 0 : registry.clean(cleanable);
3344
3543
  }
3345
3544
  }
3346
3545
  _selectCleanables() {
3347
3546
  const selectOptions = Object.assign(Object.assign({}, this._options), { destroying: true });
3348
3547
  return up.fragment.subtree(this._fragment, '.up-can-clean', selectOptions);
3349
3548
  }
3350
- _applyDestructorFunction(destructor, element) {
3351
- up.error.guard(() => destructor(element));
3352
- }
3353
3549
  };
3354
3550
 
3355
3551
 
3356
3552
  /***/ }),
3357
- /* 38 */
3553
+ /* 37 */
3358
3554
  /***/ (() => {
3359
3555
 
3360
3556
  const u = up.util;
@@ -3417,7 +3613,7 @@ up.EventEmitter = class EventEmitter extends up.Record {
3417
3613
  var _a, _b;
3418
3614
  let options = u.extractOptions(args);
3419
3615
  options = u.merge(defaults, options);
3420
- if (u.isElementish(args[0])) {
3616
+ if (u.isElementLike(args[0])) {
3421
3617
  options.target = e.get(args.shift());
3422
3618
  }
3423
3619
  else if (args[0] instanceof up.Layer) {
@@ -3454,7 +3650,7 @@ up.EventEmitter = class EventEmitter extends up.Record {
3454
3650
 
3455
3651
 
3456
3652
  /***/ }),
3457
- /* 39 */
3653
+ /* 38 */
3458
3654
  /***/ (() => {
3459
3655
 
3460
3656
  const u = up.util;
@@ -3561,7 +3757,7 @@ up.EventListener = class EventListener extends up.Record {
3561
3757
 
3562
3758
 
3563
3759
  /***/ }),
3564
- /* 40 */
3760
+ /* 39 */
3565
3761
  /***/ (() => {
3566
3762
 
3567
3763
  const u = up.util;
@@ -3581,13 +3777,13 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3581
3777
  ];
3582
3778
  }
3583
3779
  bind() {
3584
- const unbindFns = [];
3780
+ const cleaner = u.cleaner();
3585
3781
  this._eachListenerAttributes(function (attrs) {
3586
3782
  const listener = new up.EventListener(attrs);
3587
3783
  listener.bind();
3588
- return unbindFns.push(listener.unbind.bind(listener));
3784
+ return cleaner(listener.unbind.bind(listener));
3589
3785
  });
3590
- return u.sequence(unbindFns);
3786
+ return cleaner.clean;
3591
3787
  }
3592
3788
  _eachListenerAttributes(fn) {
3593
3789
  for (let element of this.elements) {
@@ -3620,7 +3816,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3620
3816
  else {
3621
3817
  elements = [document];
3622
3818
  }
3623
- let eventTypes = u.parseTokens(args.shift());
3819
+ let eventTypes = u.getSimpleTokens(args.shift());
3624
3820
  let fixTypes = up.migrate.fixEventTypes;
3625
3821
  if (fixTypes) {
3626
3822
  eventTypes = fixTypes(eventTypes);
@@ -3634,7 +3830,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3634
3830
 
3635
3831
 
3636
3832
  /***/ }),
3637
- /* 41 */
3833
+ /* 40 */
3638
3834
  /***/ (function() {
3639
3835
 
3640
3836
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3654,26 +3850,24 @@ up.FieldWatcher = class FieldWatcher {
3654
3850
  this._scope = up.form.getScope(root);
3655
3851
  this._callback = callback;
3656
3852
  this._batch = options.batch;
3657
- this._abortable = options.abortable;
3658
3853
  }
3659
3854
  start() {
3660
3855
  this._scheduledValues = null;
3661
3856
  this._processedValues = this._readFieldValues();
3662
3857
  this._currentTimer = null;
3663
3858
  this._callbackRunning = false;
3664
- this._unbindFns = [];
3859
+ this._cleaner = u.cleaner();
3665
3860
  this._watchFieldsWithin(this._root);
3666
3861
  this._root.addEventListener('up:fragment:inserted', ({ target }) => {
3667
3862
  if (target !== this._root)
3668
3863
  this._watchFieldsWithin(target);
3669
3864
  });
3670
- this._unbindFns.push(up.fragment.onAborted(this._scope, () => this._abort()));
3671
- this._unbindFns.push(up.on(this._scope, 'reset', () => this._onFormReset()));
3865
+ this._cleaner(up.fragment.onAborted(this._scope, () => this._abort()));
3866
+ this._cleaner(up.on(this._scope, 'reset', () => this._onFormReset()));
3672
3867
  }
3673
3868
  stop() {
3674
3869
  this._abort();
3675
- for (let unbindFn of this._unbindFns)
3676
- unbindFn();
3870
+ this._cleaner.clean();
3677
3871
  }
3678
3872
  _fieldOptions(field) {
3679
3873
  let rootOptions = u.copy(this._options);
@@ -3686,7 +3880,7 @@ up.FieldWatcher = class FieldWatcher {
3686
3880
  }
3687
3881
  _watchField(field) {
3688
3882
  let fieldOptions = this._fieldOptions(field);
3689
- this._unbindFns.push(up.on(field, fieldOptions.event, () => this._check(fieldOptions)));
3883
+ this._cleaner(up.on(field, fieldOptions.event, () => this._check(fieldOptions)));
3690
3884
  }
3691
3885
  _abort() {
3692
3886
  this._scheduledValues = null;
@@ -3714,13 +3908,12 @@ up.FieldWatcher = class FieldWatcher {
3714
3908
  return;
3715
3909
  if (!this._scope.isConnected)
3716
3910
  return;
3717
- let fieldOptions = this._scheduledFieldOptions;
3911
+ let callbackOptions = u.omit(this._scheduledFieldOptions, ['event', 'delay']);
3718
3912
  const diff = this._changedValues(this._processedValues, this._scheduledValues);
3719
3913
  this._processedValues = this._scheduledValues;
3720
3914
  this._scheduledValues = null;
3721
3915
  this._callbackRunning = true;
3722
3916
  this._scheduledFieldOptions = null;
3723
- let callbackOptions = Object.assign(Object.assign({}, fieldOptions), { disable: false });
3724
3917
  const callbackReturnValues = [];
3725
3918
  if (this._batch) {
3726
3919
  callbackReturnValues.push(this._runCallback(diff, callbackOptions));
@@ -3733,7 +3926,6 @@ up.FieldWatcher = class FieldWatcher {
3733
3926
  }
3734
3927
  if (u.some(callbackReturnValues, u.isPromise)) {
3735
3928
  let callbackDone = Promise.allSettled(callbackReturnValues);
3736
- up.form.disableWhile(callbackDone, fieldOptions);
3737
3929
  yield callbackDone;
3738
3930
  }
3739
3931
  this._callbackRunning = false;
@@ -3741,7 +3933,7 @@ up.FieldWatcher = class FieldWatcher {
3741
3933
  });
3742
3934
  }
3743
3935
  _runCallback(...args) {
3744
- return up.error.guard(() => this._callback(...args));
3936
+ return up.error.guard(this._callback, ...args);
3745
3937
  }
3746
3938
  _changedValues(previous, next) {
3747
3939
  const changes = {};
@@ -3773,7 +3965,7 @@ up.FieldWatcher = class FieldWatcher {
3773
3965
 
3774
3966
 
3775
3967
  /***/ }),
3776
- /* 42 */
3968
+ /* 41 */
3777
3969
  /***/ (function() {
3778
3970
 
3779
3971
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3907,7 +4099,6 @@ up.FormValidator = class FormValidator {
3907
4099
  up.error.muteUncriticalRejection(this._doRenderDirtySolutions());
3908
4100
  }
3909
4101
  _doRenderDirtySolutions() {
3910
- var _a;
3911
4102
  return __awaiter(this, void 0, void 0, function* () {
3912
4103
  if (!this._dirtySolutions.length)
3913
4104
  return;
@@ -3915,39 +4106,11 @@ up.FormValidator = class FormValidator {
3915
4106
  return;
3916
4107
  if (this._nextRenderTimer)
3917
4108
  return;
3918
- let dirtySolutions = this._dirtySolutions;
4109
+ let options = this._mergeRenderOptions(this._dirtySolutions);
3919
4110
  this._dirtySolutions = [];
3920
- let dirtyOrigins = u.map(dirtySolutions, 'origin');
3921
- let dirtyFields = u.flatMap(dirtyOrigins, up.form.fields);
3922
- let dirtyNames = u.uniq(u.map(dirtyFields, 'name'));
3923
- let dataMap = this._buildDataMap(dirtySolutions);
3924
- let dirtyRenderOptionsList = u.map(dirtySolutions, 'renderOptions');
3925
- let options = u.mergeDefined(...dirtyRenderOptionsList, { dataMap }, up.form.destinationOptions(this._form));
3926
- options.target = u.map(dirtySolutions, 'target').join(', ');
3927
- options.feedback = u.some(dirtyRenderOptionsList, 'feedback');
3928
- options.origin = this._form;
3929
- (_a = options.focus) !== null && _a !== void 0 ? _a : (options.focus = 'keep');
3930
- options.failOptions = false;
3931
- options.defaultMaybe = true;
3932
- options.params = up.Params.merge(options.params, ...u.map(dirtyRenderOptionsList, 'params'));
3933
- options.headers = u.merge(...u.map(dirtyRenderOptionsList, 'headers'));
3934
- this._addValidateHeader(options.headers, dirtyNames);
3935
- options.guardEvent = up.event.build('up:form:validate', {
3936
- fields: dirtyFields,
3937
- log: 'Validating form',
3938
- params: options.params,
3939
- form: this._form,
3940
- });
3941
4111
  this._rendering = true;
3942
4112
  let renderingPromise = this._nextRenderPromise;
3943
4113
  this._resetNextRenderPromise();
3944
- options.disable = false;
3945
- for (let solution of dirtySolutions) {
3946
- up.form.disableWhile(renderingPromise, {
3947
- disable: solution.renderOptions.disable,
3948
- origin: solution.origin,
3949
- });
3950
- }
3951
4114
  try {
3952
4115
  renderingPromise.resolve(up.render(options));
3953
4116
  yield renderingPromise;
@@ -3958,6 +4121,40 @@ up.FormValidator = class FormValidator {
3958
4121
  }
3959
4122
  });
3960
4123
  }
4124
+ _mergeRenderOptions(dirtySolutions) {
4125
+ var _a;
4126
+ let dirtyOrigins = u.map(dirtySolutions, 'origin');
4127
+ let dirtyFields = u.flatMap(dirtyOrigins, up.form.fields);
4128
+ let dirtyNames = u.uniq(u.map(dirtyFields, 'name'));
4129
+ let dirtyRenderOptionsList = u.map(dirtySolutions, 'renderOptions');
4130
+ let options = u.mergeDefined(...dirtyRenderOptionsList, up.form.destinationOptions(this._form));
4131
+ options.target = u.map(dirtySolutions, 'target').join(', ');
4132
+ options.origin = this._form;
4133
+ (_a = options.focus) !== null && _a !== void 0 ? _a : (options.focus = 'keep');
4134
+ options.failOptions = false;
4135
+ options.defaultMaybe = true;
4136
+ options.params = up.Params.merge(options.params, ...u.map(dirtyRenderOptionsList, 'params'));
4137
+ options.headers = u.merge(options.headers, ...u.map(dirtyRenderOptionsList, 'headers'));
4138
+ this._addValidateHeader(options.headers, dirtyNames);
4139
+ options.feedback = u.some(dirtyRenderOptionsList, 'feedback');
4140
+ options.data = undefined;
4141
+ options.dataMap = u.mapObject(dirtySolutions, ({ target, element, renderOptions: { data, keepData } }) => [
4142
+ target,
4143
+ keepData ? up.data(element) : data
4144
+ ]);
4145
+ options.preview = undefined;
4146
+ options.previewMap = u.mapObject(dirtySolutions, ({ target, renderOptions: { preview } }) => [target, preview]);
4147
+ options.placeholder = undefined;
4148
+ options.placeholderMap = u.mapObject(dirtySolutions, ({ target, renderOptions: { placeholder } }) => [target, placeholder]);
4149
+ options.disable = dirtySolutions.map((solution) => up.fragment.resolveOrigin(solution.renderOptions.disable, solution));
4150
+ options.guardEvent = up.event.build('up:form:validate', {
4151
+ fields: dirtyFields,
4152
+ log: 'Validating form',
4153
+ params: options.params,
4154
+ form: this._form,
4155
+ });
4156
+ return options;
4157
+ }
3961
4158
  _addValidateHeader(headers, names) {
3962
4159
  let key = up.protocol.headerize('validate');
3963
4160
  let value = names.join(' ');
@@ -3965,20 +4162,6 @@ up.FormValidator = class FormValidator {
3965
4162
  value = ':unknown';
3966
4163
  headers[key] = value;
3967
4164
  }
3968
- _buildDataMap(solutions) {
3969
- let dataMap = {};
3970
- for (let solution of solutions) {
3971
- let data = u.pluckKey(solution.renderOptions, 'data');
3972
- let keepData = u.pluckKey(solution.renderOptions, 'keepData');
3973
- if (keepData) {
3974
- data = up.data(solution.element);
3975
- }
3976
- if (data) {
3977
- dataMap[solution.target] = data;
3978
- }
3979
- }
3980
- return dataMap;
3981
- }
3982
4165
  static forElement(element) {
3983
4166
  let form = up.form.get(element);
3984
4167
  return form.upFormValidator || (form.upFormValidator = new this(form));
@@ -3987,19 +4170,23 @@ up.FormValidator = class FormValidator {
3987
4170
 
3988
4171
 
3989
4172
  /***/ }),
3990
- /* 43 */
4173
+ /* 42 */
3991
4174
  /***/ (() => {
3992
4175
 
3993
4176
  up.FocusCapsule = class FocusCapsule {
3994
- constructor(target, cursorProps) {
4177
+ constructor(element, target, cursorProps) {
4178
+ this._element = element;
3995
4179
  this._target = target;
3996
4180
  this._cursorProps = cursorProps;
3997
4181
  }
3998
- restore(layer, options) {
4182
+ wasLost() {
4183
+ return document.activeElement !== this._element;
4184
+ }
4185
+ restore(layer, focusOptions) {
3999
4186
  let rediscoveredElement = up.fragment.get(this._target, { layer });
4000
4187
  if (rediscoveredElement) {
4001
4188
  up.viewport.copyCursorProps(this._cursorProps, rediscoveredElement);
4002
- up.focus(rediscoveredElement, options);
4189
+ up.focus(rediscoveredElement, focusOptions);
4003
4190
  return true;
4004
4191
  }
4005
4192
  }
@@ -4011,13 +4198,13 @@ up.FocusCapsule = class FocusCapsule {
4011
4198
  if (!target)
4012
4199
  return;
4013
4200
  const cursorProps = up.viewport.copyCursorProps(focusedElement);
4014
- return new this(target, cursorProps);
4201
+ return new this(focusedElement, target, cursorProps);
4015
4202
  }
4016
4203
  };
4017
4204
 
4018
4205
 
4019
4206
  /***/ }),
4020
- /* 44 */
4207
+ /* 43 */
4021
4208
  /***/ (() => {
4022
4209
 
4023
4210
  const u = up.util;
@@ -4035,14 +4222,14 @@ up.FragmentProcessor = class FragmentProcessor extends up.Record {
4035
4222
  return this.tryProcess(preprocessed);
4036
4223
  }
4037
4224
  preprocess(opt) {
4038
- return u.parseTokens(opt, { separator: 'or' });
4225
+ return u.getComplexTokens(opt);
4039
4226
  }
4040
4227
  tryProcess(opt) {
4041
4228
  if (u.isArray(opt)) {
4042
4229
  return this.processArray(opt);
4043
4230
  }
4044
4231
  if (u.isFunction(opt)) {
4045
- let result = up.error.guard(() => opt(this.fragment, this.attributes()));
4232
+ let result = up.error.guard(opt, this.fragment, this.attributes());
4046
4233
  return this.tryProcess(result);
4047
4234
  }
4048
4235
  if (u.isElement(opt)) {
@@ -4082,7 +4269,7 @@ up.FragmentProcessor = class FragmentProcessor extends up.Record {
4082
4269
 
4083
4270
 
4084
4271
  /***/ }),
4085
- /* 45 */
4272
+ /* 44 */
4086
4273
  /***/ (() => {
4087
4274
 
4088
4275
  const u = up.util;
@@ -4121,19 +4308,19 @@ up.FragmentFinder = class FragmentFinder {
4121
4308
  if (parts) {
4122
4309
  let parent = up.fragment.closest(this._origin, parts[1], this._options);
4123
4310
  if (parent) {
4124
- return up.fragment.getDumb(parent, parts[2]);
4311
+ return up.fragment.getFirstDescendant(parent, parts[2]);
4125
4312
  }
4126
4313
  }
4127
4314
  });
4128
4315
  }
4129
4316
  _findFirst() {
4130
- return up.fragment.getDumb(this._document, this._selector, this._options);
4317
+ return up.fragment.getFirstDescendant(this._document, this._selector, this._options);
4131
4318
  }
4132
4319
  };
4133
4320
 
4134
4321
 
4135
4322
  /***/ }),
4136
- /* 46 */
4323
+ /* 45 */
4137
4324
  /***/ (() => {
4138
4325
 
4139
4326
  const u = up.util;
@@ -4195,7 +4382,7 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
4195
4382
  return up.viewport.restoreFocus({ layer: this.layer });
4196
4383
  }
4197
4384
  _autofocus() {
4198
- let autofocusElement = this.fragment && e.subtree(this.fragment, '[autofocus]')[0];
4385
+ let autofocusElement = this.fragment && e.subtreeFirst(this.fragment, '[autofocus]');
4199
4386
  if (autofocusElement) {
4200
4387
  return this._focusElement(autofocusElement);
4201
4388
  }
@@ -4213,13 +4400,14 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
4213
4400
  }
4214
4401
  }
4215
4402
  _wasFocusLost() {
4216
- return !this.layer.hasFocus();
4403
+ var _a;
4404
+ return (_a = this.focusCapsule) === null || _a === void 0 ? void 0 : _a.wasLost();
4217
4405
  }
4218
4406
  };
4219
4407
 
4220
4408
 
4221
4409
  /***/ }),
4222
- /* 47 */
4410
+ /* 46 */
4223
4411
  /***/ (() => {
4224
4412
 
4225
4413
  const e = up.element;
@@ -4289,17 +4477,17 @@ up.FragmentPolling = class FragmentPolling {
4289
4477
  (this._options.ifLayer === 'any' || this._isOnFrontLayer());
4290
4478
  }
4291
4479
  _clearReloadTimer() {
4292
- clearTimeout(this.reloadTimer);
4293
- this.reloadTimer = null;
4480
+ clearTimeout(this._reloadTimer);
4481
+ this._reloadTimer = null;
4294
4482
  }
4295
4483
  _scheduleRemainingTime() {
4296
- if (!this.reloadTimer && !this._loading) {
4484
+ if (!this._reloadTimer && !this._loading) {
4297
4485
  this._clearReloadTimer();
4298
- this.reloadTimer = setTimeout(this._onTimerReached.bind(this), this._getRemainingDelay());
4486
+ this._reloadTimer = setTimeout(this._onTimerReached.bind(this), this._getRemainingDelay());
4299
4487
  }
4300
4488
  }
4301
4489
  _onTimerReached() {
4302
- this.reloadTimer = null;
4490
+ this._reloadTimer = null;
4303
4491
  this._tryReload();
4304
4492
  }
4305
4493
  _tryReload() {
@@ -4377,7 +4565,7 @@ up.FragmentPolling = class FragmentPolling {
4377
4565
 
4378
4566
 
4379
4567
  /***/ }),
4380
- /* 48 */
4568
+ /* 47 */
4381
4569
  /***/ (() => {
4382
4570
 
4383
4571
  const u = up.util;
@@ -4441,7 +4629,7 @@ up.FragmentScrolling = class FragmentScrolling extends up.FragmentProcessor {
4441
4629
 
4442
4630
 
4443
4631
  /***/ }),
4444
- /* 49 */
4632
+ /* 48 */
4445
4633
  /***/ (() => {
4446
4634
 
4447
4635
  const e = up.element;
@@ -4709,7 +4897,7 @@ up.Layer = class Layer extends up.Record {
4709
4897
 
4710
4898
 
4711
4899
  /***/ }),
4712
- /* 50 */
4900
+ /* 49 */
4713
4901
  /***/ (function() {
4714
4902
 
4715
4903
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -4721,289 +4909,298 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4721
4909
  step((generator = generator.apply(thisArg, _arguments || [])).next());
4722
4910
  });
4723
4911
  };
4912
+ var _a;
4724
4913
  const e = up.element;
4725
4914
  const u = up.util;
4726
- up.Layer.Overlay = class Overlay extends up.Layer {
4727
- keys() {
4728
- return super.keys().concat([
4729
- 'position',
4730
- 'align',
4731
- 'size',
4732
- 'origin',
4733
- 'class',
4734
- 'backdrop',
4735
- 'openAnimation',
4736
- 'closeAnimation',
4737
- 'openDuration',
4738
- 'closeDuration',
4739
- 'openEasing',
4740
- 'closeEasing',
4741
- 'backdropOpenAnimation',
4742
- 'backdropCloseAnimation',
4743
- 'dismissable',
4744
- 'dismissLabel',
4745
- 'dismissAriaLabel',
4746
- 'trapFocus',
4747
- 'onOpened',
4748
- 'onAccept',
4749
- 'onAccepted',
4750
- 'onDismiss',
4751
- 'onDismissed',
4752
- 'acceptEvent',
4753
- 'dismissEvent',
4754
- 'acceptLocation',
4755
- 'dismissLocation',
4756
- 'opening'
4757
- ]);
4758
- }
4759
- constructor(options) {
4760
- super(options);
4761
- if (this.dismissable === true) {
4762
- this.dismissable = ['button', 'key', 'outside'];
4915
+ up.Layer.Overlay = (_a = class Overlay extends up.Layer {
4916
+ keys() {
4917
+ return [
4918
+ ...super.keys(),
4919
+ ...this.constructor.VISUAL_KEYS,
4920
+ 'onOpened',
4921
+ 'onAccept',
4922
+ 'onAccepted',
4923
+ 'onDismiss',
4924
+ 'onDismissed',
4925
+ 'acceptEvent',
4926
+ 'dismissEvent',
4927
+ 'acceptLocation',
4928
+ 'dismissLocation',
4929
+ 'opening'
4930
+ ];
4763
4931
  }
4764
- else if (this.dismissable === false) {
4765
- this.dismissable = [];
4932
+ constructor(options) {
4933
+ super(options);
4934
+ if (this.dismissable === true) {
4935
+ this.dismissable = ['button', 'key', 'outside'];
4936
+ }
4937
+ else if (this.dismissable === false) {
4938
+ this.dismissable = [];
4939
+ }
4940
+ else {
4941
+ this.dismissable = u.getSimpleTokens(this.dismissable);
4942
+ }
4943
+ if (this.acceptLocation) {
4944
+ this.acceptLocation = new up.URLPattern(this.acceptLocation);
4945
+ }
4946
+ if (this.dismissLocation) {
4947
+ this.dismissLocation = new up.URLPattern(this.dismissLocation);
4948
+ }
4766
4949
  }
4767
- else {
4768
- this.dismissable = u.parseTokens(this.dismissable);
4950
+ callback(name) {
4951
+ let fn = this[name];
4952
+ if (fn) {
4953
+ return fn.bind(this);
4954
+ }
4769
4955
  }
4770
- if (this.acceptLocation) {
4771
- this.acceptLocation = new up.URLPattern(this.acceptLocation);
4956
+ createElement(parentElement) {
4957
+ this.nesting || (this.nesting = this._suggestVisualNesting());
4958
+ const elementAttrs = u.compactObject(u.pick(this, ['align', 'position', 'size', 'class', 'nesting']));
4959
+ this.element = this.affixPart(parentElement, null, elementAttrs);
4772
4960
  }
4773
- if (this.dismissLocation) {
4774
- this.dismissLocation = new up.URLPattern(this.dismissLocation);
4961
+ createBackdropElement(parentElement) {
4962
+ this.backdropElement = this.affixPart(parentElement, 'backdrop');
4775
4963
  }
4776
- }
4777
- callback(name) {
4778
- let fn = this[name];
4779
- if (fn) {
4780
- return fn.bind(this);
4964
+ createViewportElement(parentElement) {
4965
+ this.viewportElement = this.affixPart(parentElement, 'viewport', { 'up-viewport': '' });
4781
4966
  }
4782
- }
4783
- createElement(parentElement) {
4784
- this.nesting || (this.nesting = this._suggestVisualNesting());
4785
- const elementAttrs = u.compactObject(u.pick(this, ['align', 'position', 'size', 'class', 'nesting']));
4786
- this.element = this.affixPart(parentElement, null, elementAttrs);
4787
- }
4788
- createBackdropElement(parentElement) {
4789
- this.backdropElement = this.affixPart(parentElement, 'backdrop');
4790
- }
4791
- createViewportElement(parentElement) {
4792
- this.viewportElement = this.affixPart(parentElement, 'viewport', { 'up-viewport': '' });
4793
- }
4794
- createBoxElement(parentElement) {
4795
- this.boxElement = this.affixPart(parentElement, 'box');
4796
- }
4797
- createContentElement(parentElement) {
4798
- this.contentElement = this.affixPart(parentElement, 'content');
4799
- }
4800
- setContent(content) {
4801
- this.contentElement.append(content);
4802
- this.onContentSet();
4803
- }
4804
- onContentSet() {
4805
- }
4806
- createDismissElement(parentElement) {
4807
- this.dismissElement = this.affixPart(parentElement, 'dismiss', {
4808
- 'up-dismiss': '":button"',
4809
- 'aria-label': this.dismissAriaLabel
4810
- });
4811
- return e.affix(this.dismissElement, 'span[aria-hidden="true"]', { text: this.dismissLabel });
4812
- }
4813
- affixPart(parentElement, part, options = {}) {
4814
- return e.affix(parentElement, this.selector(part), options);
4815
- }
4816
- static selector(part) {
4817
- return u.compact(['up', this.mode, part]).join('-');
4818
- }
4819
- _suggestVisualNesting() {
4820
- const { parent } = this;
4821
- if (this.mode === parent.mode) {
4822
- return 1 + parent._suggestVisualNesting();
4967
+ createBoxElement(parentElement) {
4968
+ this.boxElement = this.affixPart(parentElement, 'box');
4823
4969
  }
4824
- else {
4825
- return 0;
4970
+ createContentElement(parentElement) {
4971
+ this.contentElement = this.affixPart(parentElement, 'content');
4826
4972
  }
4827
- }
4828
- setupHandlers() {
4829
- var _a, _b;
4830
- super.setupHandlers();
4831
- this.overlayFocus = new up.OverlayFocus(this);
4832
- if (this._supportsDismissMethod('button')) {
4833
- this.createDismissElement(this.getBoxElement());
4834
- }
4835
- if (this._supportsDismissMethod('outside')) {
4836
- if (this.viewportElement) {
4837
- up.on(this.viewportElement, 'up:click', event => {
4838
- if (event.target === this.viewportElement) {
4839
- this._onOutsideClicked(event, true);
4840
- }
4841
- });
4973
+ setContent(content) {
4974
+ this.contentElement.append(content);
4975
+ this.onContentSet();
4976
+ }
4977
+ onContentSet() {
4978
+ }
4979
+ createDismissElement(parentElement) {
4980
+ this.dismissElement = this.affixPart(parentElement, 'dismiss', {
4981
+ 'up-dismiss': '":button"',
4982
+ 'aria-label': this.dismissARIALabel
4983
+ });
4984
+ return e.affix(this.dismissElement, 'span[aria-hidden="true"]', { text: this.dismissLabel });
4985
+ }
4986
+ affixPart(parentElement, part, options = {}) {
4987
+ return e.affix(parentElement, this.selector(part), options);
4988
+ }
4989
+ static selector(part) {
4990
+ return u.compact(['up', this.mode, part]).join('-');
4991
+ }
4992
+ _suggestVisualNesting() {
4993
+ const { parent } = this;
4994
+ if (this.mode === parent.mode) {
4995
+ return 1 + parent._suggestVisualNesting();
4842
4996
  }
4843
4997
  else {
4844
- this.unbindParentClicked = this.parent.on('up:click', (event, element) => {
4845
- if (!up.layer.isWithinForeignOverlay(element)) {
4846
- const originClicked = this.origin && this.origin.contains(element);
4847
- this._onOutsideClicked(event, originClicked);
4848
- }
4849
- });
4998
+ return 0;
4850
4999
  }
4851
5000
  }
4852
- if (this._supportsDismissMethod('key')) {
4853
- this.unbindEscapePressed = up.event.onEscape(event => this.onEscapePressed(event));
5001
+ setupHandlers() {
5002
+ var _b, _c;
5003
+ super.setupHandlers();
5004
+ this.overlayFocus = new up.OverlayFocus(this);
5005
+ if (this._supportsDismissMethod('button')) {
5006
+ this.createDismissElement(this.getBoxElement());
5007
+ }
5008
+ if (this._supportsDismissMethod('outside')) {
5009
+ if (this.viewportElement) {
5010
+ up.on(this.viewportElement, 'up:click', event => {
5011
+ if (event.target === this.viewportElement) {
5012
+ this._onOutsideClicked(event, true);
5013
+ }
5014
+ });
5015
+ }
5016
+ else {
5017
+ this.unbindParentClicked = this.parent.on('up:click', (event, element) => {
5018
+ if (!up.layer.isWithinForeignOverlay(element)) {
5019
+ const originClicked = this.origin && this.origin.contains(element);
5020
+ this._onOutsideClicked(event, originClicked);
5021
+ }
5022
+ });
5023
+ }
5024
+ }
5025
+ if (this._supportsDismissMethod('key')) {
5026
+ this.unbindEscapePressed = up.event.onEscape(event => this.onEscapePressed(event));
5027
+ }
5028
+ this.registerClickCloser('up-accept', (value, closeOptions) => {
5029
+ this.accept(value, closeOptions);
5030
+ });
5031
+ this.registerClickCloser('up-dismiss', (value, closeOptions) => {
5032
+ this.dismiss(value, closeOptions);
5033
+ });
5034
+ (_c = (_b = up.migrate).registerLayerCloser) === null || _c === void 0 ? void 0 : _c.call(_b, this);
5035
+ this._registerEventCloser(this.acceptEvent, this.accept);
5036
+ this._registerEventCloser(this.dismissEvent, this.dismiss);
5037
+ this.on('up:click', 'label[for]', (event, label) => this._onLabelClicked(event, label));
5038
+ }
5039
+ _onLabelClicked(event, label) {
5040
+ let id = label.getAttribute('for');
5041
+ let fieldSelector = up.form.fieldSelector(e.idSelector(id));
5042
+ let fieldsAnywhere = up.fragment.all(fieldSelector, { layer: 'any' });
5043
+ let fieldsInLayer = up.fragment.all(fieldSelector, { layer: this });
5044
+ if (fieldsAnywhere.length > 1 && fieldsInLayer[0] !== fieldsAnywhere[0]) {
5045
+ event.preventDefault();
5046
+ const field = fieldsInLayer[0];
5047
+ field.focus();
5048
+ if (field.matches('input[type=checkbox], input[type=radio]')) {
5049
+ field.click();
5050
+ }
5051
+ }
4854
5052
  }
4855
- this.registerClickCloser('up-accept', (value, closeOptions) => {
4856
- this.accept(value, closeOptions);
4857
- });
4858
- this.registerClickCloser('up-dismiss', (value, closeOptions) => {
4859
- this.dismiss(value, closeOptions);
4860
- });
4861
- (_b = (_a = up.migrate).registerLayerCloser) === null || _b === void 0 ? void 0 : _b.call(_a, this);
4862
- this._registerEventCloser(this.acceptEvent, this.accept);
4863
- this._registerEventCloser(this.dismissEvent, this.dismiss);
4864
- this.on('up:click', 'label[for]', (event, label) => this._onLabelClicked(event, label));
4865
- }
4866
- _onLabelClicked(event, label) {
4867
- let id = label.getAttribute('for');
4868
- let fieldSelector = up.form.fieldSelector(e.idSelector(id));
4869
- let fieldsAnywhere = up.fragment.all(fieldSelector, { layer: 'any' });
4870
- let fieldsInLayer = up.fragment.all(fieldSelector, { layer: this });
4871
- if (fieldsAnywhere.length > 1 && fieldsInLayer[0] !== fieldsAnywhere[0]) {
4872
- event.preventDefault();
4873
- const field = fieldsInLayer[0];
4874
- field.focus();
4875
- if (field.matches('input[type=checkbox], input[type=radio]')) {
4876
- field.click();
4877
- }
4878
- }
4879
- }
4880
- _onOutsideClicked(event, halt) {
4881
- up.log.putsEvent(event);
4882
- if (halt)
4883
- up.event.halt(event);
4884
- up.error.muteUncriticalSync(() => this.dismiss(':outside', { origin: event.target }));
4885
- }
4886
- onEscapePressed(event) {
4887
- if (this.isFront()) {
4888
- let field = up.form.focusedField();
4889
- if (field) {
4890
- field.blur();
5053
+ _onOutsideClicked(event, halt) {
5054
+ up.log.putsEvent(event);
5055
+ if (halt)
5056
+ up.event.halt(event);
5057
+ up.error.muteUncriticalSync(() => this.dismiss(':outside', { origin: event.target }));
5058
+ }
5059
+ onEscapePressed(event) {
5060
+ if (this.isFront()) {
5061
+ let field = up.form.focusedField();
5062
+ if (field) {
5063
+ field.blur();
5064
+ }
5065
+ else if (this._supportsDismissMethod('key')) {
5066
+ up.event.halt(event, { log: true });
5067
+ up.error.muteUncriticalSync(() => this.dismiss(':key'));
5068
+ }
4891
5069
  }
4892
- else if (this._supportsDismissMethod('key')) {
5070
+ }
5071
+ registerClickCloser(attribute, closeFn) {
5072
+ let selector = `[${attribute}]`;
5073
+ this.on('up:click', selector, function (event) {
4893
5074
  up.event.halt(event, { log: true });
4894
- up.error.muteUncriticalSync(() => this.dismiss(':key'));
5075
+ const origin = event.target.closest(selector);
5076
+ const value = e.jsonAttr(origin, attribute);
5077
+ const closeOptions = { origin };
5078
+ const parser = new up.OptionsParser(origin, closeOptions);
5079
+ parser.booleanOrString('animation');
5080
+ parser.string('easing');
5081
+ parser.number('duration');
5082
+ parser.string('confirm');
5083
+ up.error.muteUncriticalSync(() => closeFn(value, closeOptions));
5084
+ });
5085
+ }
5086
+ _registerEventCloser(eventTypes, closeFn) {
5087
+ if (!eventTypes) {
5088
+ return;
4895
5089
  }
5090
+ return this.on(eventTypes, event => {
5091
+ event.preventDefault();
5092
+ up.error.muteUncriticalSync(() => closeFn.call(this, event, { response: event.response }));
5093
+ });
4896
5094
  }
4897
- }
4898
- registerClickCloser(attribute, closeFn) {
4899
- let selector = `[${attribute}]`;
4900
- this.on('up:click', selector, function (event) {
4901
- up.event.halt(event, { log: true });
4902
- const origin = event.target.closest(selector);
4903
- const value = e.jsonAttr(origin, attribute);
4904
- const closeOptions = { origin };
4905
- const parser = new up.OptionsParser(origin, closeOptions);
4906
- parser.booleanOrString('animation');
4907
- parser.string('easing');
4908
- parser.number('duration');
4909
- parser.string('confirm');
4910
- up.error.muteUncriticalSync(() => closeFn(value, closeOptions));
4911
- });
4912
- }
4913
- _registerEventCloser(eventTypes, closeFn) {
4914
- if (!eventTypes) {
4915
- return;
5095
+ tryAcceptForLocation(options) {
5096
+ this._tryCloseForLocation(this.acceptLocation, this.accept, options);
4916
5097
  }
4917
- return this.on(eventTypes, event => {
4918
- event.preventDefault();
4919
- up.error.muteUncriticalSync(() => closeFn.call(this, event, { response: event.response }));
4920
- });
4921
- }
4922
- tryAcceptForLocation(options) {
4923
- this._tryCloseForLocation(this.acceptLocation, this.accept, options);
4924
- }
4925
- tryDismissForLocation(options) {
4926
- this._tryCloseForLocation(this.dismissLocation, this.dismiss, options);
4927
- }
4928
- _tryCloseForLocation(urlPattern, closeFn, options) {
4929
- let location, resolution;
4930
- if (urlPattern && (location = this.location) && (resolution = urlPattern.recognize(location))) {
4931
- const closeValue = Object.assign(Object.assign({}, resolution), { location });
4932
- up.error.muteUncriticalSync(() => closeFn.call(this, closeValue, options));
5098
+ tryDismissForLocation(options) {
5099
+ this._tryCloseForLocation(this.dismissLocation, this.dismiss, options);
4933
5100
  }
4934
- }
4935
- teardownHandlers() {
4936
- var _a, _b;
4937
- super.teardownHandlers();
4938
- (_a = this.unbindParentClicked) === null || _a === void 0 ? void 0 : _a.call(this);
4939
- (_b = this.unbindEscapePressed) === null || _b === void 0 ? void 0 : _b.call(this);
4940
- this.overlayFocus.teardown();
4941
- }
4942
- destroyElements(options) {
4943
- const animation = () => this.startCloseAnimation(options);
4944
- const onFinished = () => {
4945
- var _a;
4946
- this.onElementsRemoved();
4947
- (_a = options.onFinished) === null || _a === void 0 ? void 0 : _a.call(options);
4948
- };
4949
- const destroyOptions = Object.assign(Object.assign({}, options), { animation, onFinished, log: false });
4950
- up.destroy(this.element, destroyOptions);
4951
- }
4952
- onElementsRemoved() {
4953
- }
4954
- _startAnimation(options = {}) {
4955
- const boxDone = up.animate(this.getBoxElement(), options.boxAnimation, options);
4956
- let backdropDone;
4957
- if (this.backdrop && !up.motion.isNone(options.boxAnimation)) {
4958
- backdropDone = up.animate(this.backdropElement, options.backdropAnimation, options);
5101
+ _tryCloseForLocation(urlPattern, closeFn, options) {
5102
+ let location, resolution;
5103
+ if (urlPattern && (location = this.location) && (resolution = urlPattern.recognize(location))) {
5104
+ const closeValue = Object.assign(Object.assign({}, resolution), { location });
5105
+ up.error.muteUncriticalSync(() => closeFn.call(this, closeValue, options));
5106
+ }
4959
5107
  }
4960
- return Promise.all([boxDone, backdropDone]);
4961
- }
4962
- startOpenAnimation(options = {}) {
4963
- var _a;
4964
- return __awaiter(this, void 0, void 0, function* () {
4965
- yield this._startAnimation({
4966
- boxAnimation: (_a = options.animation) !== null && _a !== void 0 ? _a : this.evalOption(this.openAnimation),
4967
- backdropAnimation: 'fade-in',
4968
- easing: options.easing || this.openEasing,
4969
- duration: options.duration || this.openDuration
5108
+ teardownHandlers() {
5109
+ var _b, _c;
5110
+ super.teardownHandlers();
5111
+ (_b = this.unbindParentClicked) === null || _b === void 0 ? void 0 : _b.call(this);
5112
+ (_c = this.unbindEscapePressed) === null || _c === void 0 ? void 0 : _c.call(this);
5113
+ this.overlayFocus.teardown();
5114
+ }
5115
+ destroyElements(options) {
5116
+ const animation = () => this.startCloseAnimation(options);
5117
+ const onFinished = () => {
5118
+ var _b;
5119
+ this.onElementsRemoved();
5120
+ (_b = options.onFinished) === null || _b === void 0 ? void 0 : _b.call(options);
5121
+ };
5122
+ const destroyOptions = Object.assign(Object.assign({}, options), { animation, onFinished, log: false });
5123
+ up.destroy(this.element, destroyOptions);
5124
+ }
5125
+ onElementsRemoved() {
5126
+ }
5127
+ _startAnimation(options = {}) {
5128
+ const boxDone = up.animate(this.getBoxElement(), options.boxAnimation, options);
5129
+ let backdropDone;
5130
+ if (this.backdrop && !up.motion.isNone(options.boxAnimation)) {
5131
+ backdropDone = up.animate(this.backdropElement, options.backdropAnimation, options);
5132
+ }
5133
+ return Promise.all([boxDone, backdropDone]);
5134
+ }
5135
+ startOpenAnimation(options = {}) {
5136
+ var _b;
5137
+ return __awaiter(this, void 0, void 0, function* () {
5138
+ let boxAnimation = (_b = options.animation) !== null && _b !== void 0 ? _b : this.evalOption(this.openAnimation);
5139
+ let backdropAnimation = 'fade-in';
5140
+ yield this._startAnimation({
5141
+ boxAnimation,
5142
+ backdropAnimation,
5143
+ easing: options.easing || this.openEasing,
5144
+ duration: options.duration || this.openDuration
5145
+ });
5146
+ this.wasEverVisible = true;
4970
5147
  });
4971
- this.wasEverVisible = true;
4972
- });
4973
- }
4974
- startCloseAnimation(options = {}) {
4975
- var _a;
4976
- return this._startAnimation({
4977
- boxAnimation: this.wasEverVisible && ((_a = options.animation) !== null && _a !== void 0 ? _a : this.evalOption(this.closeAnimation)),
4978
- backdropAnimation: this.wasEverVisible && 'fade-out',
4979
- easing: options.easing || this.closeEasing,
4980
- duration: options.duration || this.closeDuration
4981
- });
4982
- }
4983
- accept(value = null, options = {}) {
4984
- return this._executeCloseChange('accept', value, options);
4985
- }
4986
- dismiss(value = null, options = {}) {
4987
- return this._executeCloseChange('dismiss', value, options);
4988
- }
4989
- _supportsDismissMethod(method) {
4990
- return u.contains(this.dismissable, method);
4991
- }
4992
- _executeCloseChange(verb, value, options) {
4993
- options = Object.assign(Object.assign({}, options), { verb, value, layer: this });
4994
- return new up.Change.CloseLayer(options).execute();
4995
- }
4996
- getFirstSwappableElement() {
4997
- return this.getContentElement().children[0];
4998
- }
4999
- toString() {
5000
- return `${this.mode} overlay`;
5001
- }
5002
- };
5148
+ }
5149
+ startCloseAnimation(options = {}) {
5150
+ var _b;
5151
+ let boxAnimation = this.wasEverVisible && ((_b = options.animation) !== null && _b !== void 0 ? _b : this.evalOption(this.closeAnimation));
5152
+ let backdropAnimation = 'fade-out';
5153
+ return this._startAnimation({
5154
+ boxAnimation,
5155
+ backdropAnimation,
5156
+ easing: options.easing || this.closeEasing,
5157
+ duration: options.duration || this.closeDuration
5158
+ });
5159
+ }
5160
+ accept(value = null, options = {}) {
5161
+ return this._executeCloseChange('accept', value, options);
5162
+ }
5163
+ dismiss(value = null, options = {}) {
5164
+ return this._executeCloseChange('dismiss', value, options);
5165
+ }
5166
+ _supportsDismissMethod(method) {
5167
+ return u.contains(this.dismissable, method);
5168
+ }
5169
+ _executeCloseChange(verb, value, options) {
5170
+ options = Object.assign(Object.assign({}, options), { verb, value, layer: this });
5171
+ return new up.Change.CloseLayer(options).execute();
5172
+ }
5173
+ getFirstSwappableElement() {
5174
+ return this.getContentElement().children[0];
5175
+ }
5176
+ toString() {
5177
+ return `${this.mode} overlay`;
5178
+ }
5179
+ },
5180
+ _a.VISUAL_KEYS = [
5181
+ 'mode',
5182
+ 'position',
5183
+ 'align',
5184
+ 'size',
5185
+ 'origin',
5186
+ 'class',
5187
+ 'backdrop',
5188
+ 'dismissable',
5189
+ 'dismissLabel',
5190
+ 'dismissARIALabel',
5191
+ 'openAnimation',
5192
+ 'closeAnimation',
5193
+ 'openDuration',
5194
+ 'closeDuration',
5195
+ 'openEasing',
5196
+ 'closeEasing',
5197
+ 'trapFocus',
5198
+ ],
5199
+ _a);
5003
5200
 
5004
5201
 
5005
5202
  /***/ }),
5006
- /* 51 */
5203
+ /* 50 */
5007
5204
  /***/ (() => {
5008
5205
 
5009
5206
  up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
@@ -5042,7 +5239,7 @@ up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
5042
5239
 
5043
5240
 
5044
5241
  /***/ }),
5045
- /* 52 */
5242
+ /* 51 */
5046
5243
  /***/ (() => {
5047
5244
 
5048
5245
  up.Layer.OverlayWithViewport = class OverlayWithViewport extends up.Layer.Overlay {
@@ -5071,7 +5268,7 @@ up.Layer.OverlayWithViewport = class OverlayWithViewport extends up.Layer.Overla
5071
5268
 
5072
5269
 
5073
5270
  /***/ }),
5074
- /* 53 */
5271
+ /* 52 */
5075
5272
  /***/ (() => {
5076
5273
 
5077
5274
  var _a;
@@ -5117,7 +5314,7 @@ up.Layer.Root = (_a = class Root extends up.Layer {
5117
5314
 
5118
5315
 
5119
5316
  /***/ }),
5120
- /* 54 */
5317
+ /* 53 */
5121
5318
  /***/ (() => {
5122
5319
 
5123
5320
  var _a;
@@ -5128,7 +5325,7 @@ up.Layer.Modal = (_a = class Modal extends up.Layer.OverlayWithViewport {
5128
5325
 
5129
5326
 
5130
5327
  /***/ }),
5131
- /* 55 */
5328
+ /* 54 */
5132
5329
  /***/ (() => {
5133
5330
 
5134
5331
  var _a;
@@ -5139,7 +5336,7 @@ up.Layer.Popup = (_a = class Popup extends up.Layer.OverlayWithTether {
5139
5336
 
5140
5337
 
5141
5338
  /***/ }),
5142
- /* 56 */
5339
+ /* 55 */
5143
5340
  /***/ (() => {
5144
5341
 
5145
5342
  var _a;
@@ -5150,7 +5347,7 @@ up.Layer.Drawer = (_a = class Drawer extends up.Layer.OverlayWithViewport {
5150
5347
 
5151
5348
 
5152
5349
  /***/ }),
5153
- /* 57 */
5350
+ /* 56 */
5154
5351
  /***/ (() => {
5155
5352
 
5156
5353
  var _a;
@@ -5161,7 +5358,7 @@ up.Layer.Cover = (_a = class Cover extends up.Layer.OverlayWithViewport {
5161
5358
 
5162
5359
 
5163
5360
  /***/ }),
5164
- /* 58 */
5361
+ /* 57 */
5165
5362
  /***/ (() => {
5166
5363
 
5167
5364
  var _a;
@@ -5174,7 +5371,7 @@ up.LayerLookup = (_a = class LayerLookup {
5174
5371
  up.layer.normalizeOptions(options);
5175
5372
  }
5176
5373
  this._options = options;
5177
- this._values = u.parseTokens(options.layer);
5374
+ this._values = u.getSimpleTokens(options.layer);
5178
5375
  }
5179
5376
  all() {
5180
5377
  let results = u.flatMap(this._values, value => this._resolveValue(value));
@@ -5207,7 +5404,7 @@ up.LayerLookup = (_a = class LayerLookup {
5207
5404
  if (/^\d+$/.test(value)) {
5208
5405
  return this._forIndex(Number(value));
5209
5406
  }
5210
- if (u.isElementish(value)) {
5407
+ if (u.isElementLike(value)) {
5211
5408
  return this._forElement(value);
5212
5409
  }
5213
5410
  switch (value) {
@@ -5274,7 +5471,7 @@ up.LayerLookup = (_a = class LayerLookup {
5274
5471
 
5275
5472
 
5276
5473
  /***/ }),
5277
- /* 59 */
5474
+ /* 58 */
5278
5475
  /***/ (() => {
5279
5476
 
5280
5477
  const u = up.util;
@@ -5388,11 +5585,11 @@ up.LayerStack = class LayerStack {
5388
5585
 
5389
5586
 
5390
5587
  /***/ }),
5391
- /* 60 */
5588
+ /* 59 */
5392
5589
  /***/ (() => {
5393
5590
 
5394
5591
  const u = up.util;
5395
- up.LinkFeedbackURLs = class LinkFeedbackURLs {
5592
+ up.LinkCurrentURLs = class LinkCurrentURLs {
5396
5593
  constructor(link) {
5397
5594
  this._isSafe = up.link.isSafe(link);
5398
5595
  if (this._isSafe) {
@@ -5423,7 +5620,7 @@ up.LinkFeedbackURLs = class LinkFeedbackURLs {
5423
5620
 
5424
5621
 
5425
5622
  /***/ }),
5426
- /* 61 */
5623
+ /* 60 */
5427
5624
  /***/ (() => {
5428
5625
 
5429
5626
  const u = up.util;
@@ -5432,12 +5629,13 @@ up.LinkFollowIntent = class LinkFollowIntent {
5432
5629
  constructor(link, callback) {
5433
5630
  this._link = link;
5434
5631
  this._callback = callback;
5632
+ this._lastRequest = null;
5435
5633
  this._on('mouseenter mousedown touchstart', (event) => this._scheduleCallback(event));
5436
5634
  this._on('mouseleave', () => this._unscheduleCallback());
5437
5635
  up.fragment.onAborted(this._link, () => this._unscheduleCallback());
5438
5636
  }
5439
- _on(eventType, callback) {
5440
- up.on(this._link, eventType, { passive: true }, callback);
5637
+ _on(eventType, fn) {
5638
+ up.on(this._link, eventType, { passive: true }, fn);
5441
5639
  }
5442
5640
  _scheduleCallback(event) {
5443
5641
  if (!up.link.shouldFollowEvent(event, this._link))
@@ -5453,8 +5651,11 @@ up.LinkFollowIntent = class LinkFollowIntent {
5453
5651
  }
5454
5652
  }
5455
5653
  _unscheduleCallback() {
5654
+ var _a;
5456
5655
  clearTimeout(this._timer);
5457
- up.network.abort((request) => (request.origin === this._link) && request.background);
5656
+ if ((_a = this._lastRequest) === null || _a === void 0 ? void 0 : _a.background)
5657
+ this._lastRequest.abort();
5658
+ this._lastRequest = null;
5458
5659
  }
5459
5660
  _parseDelay() {
5460
5661
  var _a;
@@ -5462,13 +5663,13 @@ up.LinkFollowIntent = class LinkFollowIntent {
5462
5663
  }
5463
5664
  _runCallback(event) {
5464
5665
  up.log.putsEvent(event);
5465
- up.error.muteUncriticalRejection(this._callback());
5666
+ this._callback({ onRequestKnown: (request) => this._lastRequest = request });
5466
5667
  }
5467
5668
  };
5468
5669
 
5469
5670
 
5470
5671
  /***/ }),
5471
- /* 62 */
5672
+ /* 61 */
5472
5673
  /***/ (function() {
5473
5674
 
5474
5675
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -5577,7 +5778,7 @@ up.MotionController = class MotionController {
5577
5778
 
5578
5779
 
5579
5780
  /***/ }),
5580
- /* 63 */
5781
+ /* 62 */
5581
5782
  /***/ (() => {
5582
5783
 
5583
5784
  const u = up.util;
@@ -5592,33 +5793,34 @@ up.NonceableCallback = class NonceableCallback {
5592
5793
  return new this(match[3], match[2]);
5593
5794
  }
5594
5795
  toFunction(...argNames) {
5796
+ let script = this.script;
5595
5797
  if (this.nonce) {
5596
5798
  let callbackThis = this;
5597
5799
  return function (...args) {
5598
- return callbackThis._runAsNoncedFunction(this, argNames, args);
5800
+ return callbackThis._runAsNoncedFunction(script, this, argNames, args);
5599
5801
  };
5600
5802
  }
5601
5803
  else {
5602
- return new Function(...argNames, this.script);
5804
+ return new Function(...argNames, script);
5603
5805
  }
5604
5806
  }
5605
5807
  toString() {
5606
5808
  return `nonce-${this.nonce} ${this.script}`;
5607
5809
  }
5608
- _runAsNoncedFunction(thisArg, argNames, args) {
5810
+ _runAsNoncedFunction(script, thisArg, argNames, args) {
5609
5811
  let wrappedScript = `
5610
5812
  try {
5611
5813
  up.noncedEval.value = (function(${argNames.join()}) {
5612
- ${this.script}
5814
+ ${script}
5613
5815
  }).apply(up.noncedEval.thisArg, up.noncedEval.args)
5614
5816
  } catch (error) {
5615
5817
  up.noncedEval.error = error
5616
5818
  }
5617
5819
  `;
5618
- let script;
5820
+ let scriptElement;
5619
5821
  try {
5620
5822
  up.noncedEval = { args, thisArg: thisArg };
5621
- script = up.element.affix(document.body, 'script', { nonce: this.nonce, text: wrappedScript });
5823
+ scriptElement = e.affix(document.body, 'script', { nonce: this.nonce, text: wrappedScript });
5622
5824
  if (up.noncedEval.error) {
5623
5825
  throw up.noncedEval.error;
5624
5826
  }
@@ -5628,8 +5830,8 @@ up.NonceableCallback = class NonceableCallback {
5628
5830
  }
5629
5831
  finally {
5630
5832
  up.noncedEval = undefined;
5631
- if (script) {
5632
- script.remove();
5833
+ if (scriptElement) {
5834
+ scriptElement.remove();
5633
5835
  }
5634
5836
  }
5635
5837
  }
@@ -5663,7 +5865,7 @@ up.NonceableCallback = class NonceableCallback {
5663
5865
 
5664
5866
 
5665
5867
  /***/ }),
5666
- /* 64 */
5868
+ /* 63 */
5667
5869
  /***/ (() => {
5668
5870
 
5669
5871
  const e = up.element;
@@ -5679,7 +5881,7 @@ up.OverlayFocus = class OverlayFocus {
5679
5881
  return;
5680
5882
  }
5681
5883
  this._active = true;
5682
- this._unsetAttrs = e.setTemporaryAttrs(this._focusElement, {
5884
+ this._unsetAttrs = e.setAttrsTemp(this._focusElement, {
5683
5885
  'tabindex': '0',
5684
5886
  'role': 'dialog',
5685
5887
  'aria-modal': this._trapFocus.toString()
@@ -5736,7 +5938,7 @@ up.OverlayFocus = class OverlayFocus {
5736
5938
 
5737
5939
 
5738
5940
  /***/ }),
5739
- /* 65 */
5941
+ /* 64 */
5740
5942
  /***/ (() => {
5741
5943
 
5742
5944
  const u = up.util;
@@ -5969,6 +6171,134 @@ up.Params = class Params {
5969
6171
  };
5970
6172
 
5971
6173
 
6174
+ /***/ }),
6175
+ /* 65 */
6176
+ /***/ (() => {
6177
+
6178
+ const u = up.util;
6179
+ const e = up.element;
6180
+ up.Preview = class Preview {
6181
+ constructor({ fragment, request, renderOptions, cleaner }) {
6182
+ this.fragment = fragment;
6183
+ this.request = request;
6184
+ this.renderOptions = renderOptions;
6185
+ this._cleaner = cleaner;
6186
+ }
6187
+ undo(...args) {
6188
+ if (this.ended) {
6189
+ reportError(new up.Error('Preview used after end of request'));
6190
+ }
6191
+ else {
6192
+ this._cleaner.guard(...args);
6193
+ }
6194
+ }
6195
+ get origin() {
6196
+ return this.request.origin;
6197
+ }
6198
+ get params() {
6199
+ return this.request.params;
6200
+ }
6201
+ get layer() {
6202
+ return this.request.layer;
6203
+ }
6204
+ get ended() {
6205
+ return this.request.ended;
6206
+ }
6207
+ get expiredResponse() {
6208
+ return this.renderOptions.expiredResponse;
6209
+ }
6210
+ get revalidating() {
6211
+ return !!this.expiredResponse;
6212
+ }
6213
+ run(value, options = {}) {
6214
+ for (let fn of up.status.resolvePreviewFns(value)) {
6215
+ this.undo(up.error.guard(fn, this, options));
6216
+ }
6217
+ }
6218
+ revert() {
6219
+ this._cleaner.clean();
6220
+ }
6221
+ setAttrs(...args) {
6222
+ let [element, attrs] = this._parseMutatorArgs(args, 'val', 'val');
6223
+ this.undo(e.setAttrsTemp(element, attrs));
6224
+ }
6225
+ addClass(...args) {
6226
+ let [element, klass] = this._parseMutatorArgs(args, 'val', 'val');
6227
+ this.undo(e.addClassTemp(element, klass));
6228
+ }
6229
+ addClassBatch(elements, classes) {
6230
+ for (let element of elements) {
6231
+ for (let klass of classes) {
6232
+ this.addClass(element, klass);
6233
+ }
6234
+ }
6235
+ }
6236
+ removeClass(...args) {
6237
+ let [element, klass] = this._parseMutatorArgs(args, 'val', 'val');
6238
+ this.undo(e.removeClassTemp(element, klass));
6239
+ }
6240
+ setStyle(...args) {
6241
+ let [element, styles] = this._parseMutatorArgs(args, 'val', 'val');
6242
+ this.undo(e.setStyleTemp(element, styles));
6243
+ }
6244
+ disable(...args) {
6245
+ let [element] = this._parseMutatorArgs(args, 'val');
6246
+ this.undo(up.form.disable(element));
6247
+ }
6248
+ insert(...args) {
6249
+ let [reference, position = 'beforeend', tempValue] = this._parseMutatorArgs(args, 'val', u.isAdjacentPosition, 'val');
6250
+ this.undo(up.fragment.insertTemp(reference, position, tempValue));
6251
+ }
6252
+ show(...args) {
6253
+ let [element] = this._parseMutatorArgs(args, 'val');
6254
+ this.undo(e.showTemp(element));
6255
+ }
6256
+ hide(...args) {
6257
+ let [element] = this._parseMutatorArgs(args, 'val');
6258
+ this.undo(e.hideTemp(element));
6259
+ }
6260
+ hideContent(...args) {
6261
+ let [parent] = this._parseMutatorArgs(args, 'val');
6262
+ let wrapper = e.wrapChildren(parent);
6263
+ e.hide(wrapper);
6264
+ this.undo(() => e.unwrap(wrapper));
6265
+ }
6266
+ showPlaceholder(...args) {
6267
+ let [parent, placeholderReference] = this._parseMutatorArgs(args, 'val', 'val');
6268
+ let placeholderNodes = up.fragment.provideNodes(placeholderReference, { origin: this.origin });
6269
+ up.puts('[up-placeholder]', 'Showing placeholder %o', placeholderReference);
6270
+ if (parent) {
6271
+ this.swapContent(parent, placeholderNodes);
6272
+ }
6273
+ else if (this.layer === 'new') {
6274
+ this.openLayer(placeholderNodes, { closeAnimation: false });
6275
+ this.renderOptions.openAnimation = false;
6276
+ }
6277
+ }
6278
+ swapContent(...args) {
6279
+ let [parent, newContent] = this._parseMutatorArgs(args, 'val', 'val');
6280
+ this.hideContent(parent);
6281
+ this.insert(parent, newContent);
6282
+ }
6283
+ openLayer(content, options = {}) {
6284
+ let undoDismissValue = ':undo-preview';
6285
+ let onDismiss = ({ value }) => {
6286
+ if (value !== undoDismissValue)
6287
+ this.request.abort({ reason: 'Preview overlay dismissed' });
6288
+ };
6289
+ up.layer.open(Object.assign(Object.assign(Object.assign({}, u.pick(this.renderOptions, [...up.Layer.Overlay.VISUAL_KEYS, 'target'])), options), { content, abort: false, onDismiss }));
6290
+ let overlay = up.layer.front;
6291
+ this.undo(() => overlay.dismiss(undoDismissValue, { preventable: false }));
6292
+ return overlay;
6293
+ }
6294
+ _parseMutatorArgs(args, ...specs) {
6295
+ let [element, ...rest] = u.args(args, ...specs);
6296
+ element = up.fragment.get(element, { layer: this.layer, origin: this.origin }) || this.fragment;
6297
+ return [element, ...rest];
6298
+ }
6299
+ };
6300
+
6301
+
5972
6302
  /***/ }),
5973
6303
  /* 66 */
5974
6304
  /***/ (() => {
@@ -5981,7 +6311,7 @@ up.ProgressBar = class ProgressBar {
5981
6311
  this._element = e.affix(document.body, 'up-progress-bar');
5982
6312
  this._element.style.transition = `width ${TRANSITION_DELAY}ms ease-out`;
5983
6313
  this._moveTo(0);
5984
- up.element.paint(this._element);
6314
+ e.paint(this._element);
5985
6315
  this._width = 31;
5986
6316
  this._nextStep();
5987
6317
  }
@@ -6025,21 +6355,22 @@ up.ProgressBar = class ProgressBar {
6025
6355
 
6026
6356
  const u = up.util;
6027
6357
  up.RenderOptions = (function () {
6028
- const GLOBAL_DEFAULTS = {
6029
- useHungry: true,
6030
- useKeep: true,
6031
- saveScroll: true,
6032
- saveFocus: true,
6033
- focus: 'keep',
6034
- abort: 'target',
6035
- failOptions: true,
6358
+ const NO_PREVIEWS = {
6359
+ preview: false,
6360
+ disable: false,
6361
+ placeholder: false,
6362
+ feedback: false,
6036
6363
  };
6037
- const PRELOAD_OVERRIDES = {
6038
- abort: false,
6364
+ const NO_INPUT_INTERFERENCE = {
6365
+ scroll: false,
6366
+ focus: 'keep',
6039
6367
  confirm: false,
6040
- feedback: false,
6041
- cache: true,
6042
- background: true,
6368
+ };
6369
+ const NO_MOTION = {
6370
+ transition: false,
6371
+ animation: false,
6372
+ openAnimation: false,
6373
+ closeAnimation: false,
6043
6374
  };
6044
6375
  const PREFLIGHT_KEYS = [
6045
6376
  'url',
@@ -6053,9 +6384,13 @@ up.RenderOptions = (function () {
6053
6384
  'abortable',
6054
6385
  'confirm',
6055
6386
  'feedback',
6387
+ 'disable',
6388
+ 'placeholder',
6389
+ 'preview',
6056
6390
  'origin',
6057
6391
  'originLayer',
6058
6392
  'baseLayer',
6393
+ 'navigate',
6059
6394
  'fail',
6060
6395
  'onError',
6061
6396
  ];
@@ -6065,8 +6400,6 @@ up.RenderOptions = (function () {
6065
6400
  'history',
6066
6401
  'source',
6067
6402
  'saveScroll',
6068
- 'navigate',
6069
- 'baseLayer',
6070
6403
  ]);
6071
6404
  const CONTENT_KEYS = [
6072
6405
  'url',
@@ -6090,16 +6423,18 @@ up.RenderOptions = (function () {
6090
6423
  return { url: u.normalizeURL(url) };
6091
6424
  }
6092
6425
  }
6093
- function preloadOverrides(options) {
6094
- if (options.preload) {
6095
- return PRELOAD_OVERRIDES;
6096
- }
6426
+ function removeUsePrefix(options) {
6427
+ u.renameKey(options, 'useData', 'data');
6428
+ u.renameKey(options, 'useHungry', 'hungry');
6429
+ u.renameKey(options, 'useKeep', 'keep');
6097
6430
  }
6098
6431
  function preprocess(options) {
6099
6432
  var _a, _b;
6100
6433
  (_b = (_a = up.migrate).preprocessRenderOptions) === null || _b === void 0 ? void 0 : _b.call(_a, options);
6101
- const defaults = u.merge(GLOBAL_DEFAULTS, navigateDefaults(options));
6102
- return u.merge(u.omit(defaults, LATE_KEYS), { defaults }, { inputDevice: up.event.inputDevice }, options, normalizeURL(options), rememberOriginLayer(options), preloadOverrides(options));
6434
+ up.layer.normalizeOptions(options);
6435
+ removeUsePrefix(options);
6436
+ const defaults = u.merge(up.fragment.config.renderOptions, navigateDefaults(options));
6437
+ return u.merge(u.omit(defaults, LATE_KEYS), { defaults }, { inputDevice: up.event.inputDevice }, options, normalizeURL(options), rememberOriginLayer(options));
6103
6438
  }
6104
6439
  function rememberOriginLayer({ origin, originLayer }) {
6105
6440
  if (origin && !originLayer) {
@@ -6134,12 +6469,11 @@ up.RenderOptions = (function () {
6134
6469
  }
6135
6470
  function deriveFailOptions(preprocessedOptions) {
6136
6471
  let overrides = failOverrides(preprocessedOptions);
6137
- let layers = rememberOriginLayer(overrides);
6138
6472
  if (preprocessedOptions.failOptions) {
6139
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, preprocessedOptions.defaults), u.pick(preprocessedOptions, SHARED_KEYS)), overrides), layers), { failPrefixForced: true });
6473
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, preprocessedOptions.defaults), u.pick(preprocessedOptions, SHARED_KEYS)), overrides), { failPrefixForced: true });
6140
6474
  }
6141
6475
  else {
6142
- return Object.assign(Object.assign(Object.assign({}, preprocessedOptions), overrides), layers);
6476
+ return Object.assign(Object.assign({}, preprocessedOptions), overrides);
6143
6477
  }
6144
6478
  }
6145
6479
  return {
@@ -6147,6 +6481,9 @@ up.RenderOptions = (function () {
6147
6481
  finalize,
6148
6482
  assertContentGiven,
6149
6483
  deriveFailOptions,
6484
+ NO_PREVIEWS,
6485
+ NO_MOTION,
6486
+ NO_INPUT_INTERFERENCE,
6150
6487
  };
6151
6488
  })();
6152
6489
 
@@ -6238,7 +6575,6 @@ up.Request = (_a = class Request extends up.Record {
6238
6575
  'failMode',
6239
6576
  'failContext',
6240
6577
  'origin',
6241
- 'fragments',
6242
6578
  'builtAt',
6243
6579
  'wrapMethod',
6244
6580
  'contentType',
@@ -6246,7 +6582,8 @@ up.Request = (_a = class Request extends up.Record {
6246
6582
  'onLoading',
6247
6583
  'fail',
6248
6584
  'abortable',
6249
- 'badResponseTime',
6585
+ 'lateDelay',
6586
+ 'previews',
6250
6587
  ];
6251
6588
  }
6252
6589
  defaults() {
@@ -6256,10 +6593,11 @@ up.Request = (_a = class Request extends up.Record {
6256
6593
  headers: {},
6257
6594
  timeout: up.network.config.timeout,
6258
6595
  builtAt: new Date(),
6596
+ previews: [],
6259
6597
  };
6260
6598
  }
6261
6599
  constructor(options) {
6262
- var _b, _c, _d;
6600
+ var _b, _c;
6263
6601
  super(options);
6264
6602
  this.params = new up.Params(this.params);
6265
6603
  if (this.wrapMethod == null) {
@@ -6275,27 +6613,39 @@ up.Request = (_a = class Request extends up.Record {
6275
6613
  this.mode || (this.mode = this.layer.mode);
6276
6614
  this.failMode || (this.failMode = (_c = this.failLayer) === null || _c === void 0 ? void 0 : _c.mode);
6277
6615
  }
6278
- this.deferred = u.newDeferred();
6279
- (_d = this.badResponseTime) !== null && _d !== void 0 ? _d : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
6616
+ this.bindLayer = options.bindLayer || this.layer;
6617
+ this._fragments = options.fragments;
6618
+ this._bindFragments = options.bindFragments;
6619
+ this._deferred = u.newDeferred();
6280
6620
  this._setAutoHeaders();
6281
6621
  }
6622
+ get effectiveLateTime() {
6623
+ var _b;
6624
+ if (this.background) {
6625
+ return false;
6626
+ }
6627
+ else {
6628
+ return (_b = this.lateDelay) !== null && _b !== void 0 ? _b : u.evalOption(up.network.config.lateDelay, this);
6629
+ }
6630
+ }
6631
+ isTimed() {
6632
+ return u.isNumber(this.effectiveLateTime);
6633
+ }
6282
6634
  get xhr() {
6283
6635
  var _b;
6284
6636
  return (_b = this._xhr) !== null && _b !== void 0 ? _b : (this._xhr = new XMLHttpRequest());
6285
6637
  }
6286
6638
  get fragments() {
6287
- if (this._fragments) {
6288
- return this._fragments;
6289
- }
6290
- else {
6291
- let steps = up.fragment.parseTargetSteps(this.target);
6292
- let selectors = u.map(steps, 'selector');
6293
- let lookupOpts = { origin: this.origin, layer: this.layer };
6294
- return u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
6295
- }
6639
+ return (this._fragments || (this._fragments = this._findFragments()));
6296
6640
  }
6297
- set fragments(value) {
6298
- this._fragments = value;
6641
+ _findFragments() {
6642
+ let steps = up.fragment.parseTargetSteps(this.target);
6643
+ let lookupOpts = { origin: this.origin, layer: this.layer };
6644
+ let matches = u.map(steps, (step) => up.fragment.get(step.selector, lookupOpts));
6645
+ return u.compact(matches);
6646
+ }
6647
+ get bindFragments() {
6648
+ return this._bindFragments || this.fragments;
6299
6649
  }
6300
6650
  get fragment() {
6301
6651
  var _b;
@@ -6311,8 +6661,10 @@ up.Request = (_a = class Request extends up.Record {
6311
6661
  u.task(() => {
6312
6662
  this.layer = undefined;
6313
6663
  this.failLayer = undefined;
6664
+ this._bindLayer = undefined;
6314
6665
  this.origin = undefined;
6315
- this.fragments = undefined;
6666
+ this._fragments = undefined;
6667
+ this._bindFragments = undefined;
6316
6668
  });
6317
6669
  }
6318
6670
  _extractHashFromURL() {
@@ -6366,6 +6718,11 @@ up.Request = (_a = class Request extends up.Record {
6366
6718
  this.abort({ reason: 'Prevented by event listener' });
6367
6719
  }
6368
6720
  }
6721
+ runPreviews(renderOptions) {
6722
+ if (!this.ended && !this.fromCache) {
6723
+ this._revertPreviews = up.status.runPreviews(this, renderOptions);
6724
+ }
6725
+ }
6369
6726
  _emitLoad() {
6370
6727
  let event = this.emit('up:request:load', { log: ['Loading %s', this.description] });
6371
6728
  return !event.defaultPrevented;
@@ -6395,35 +6752,47 @@ up.Request = (_a = class Request extends up.Record {
6395
6752
  }
6396
6753
  }
6397
6754
  _setAbortedState(reason) {
6398
- if (this._isSettled())
6755
+ if (this.ended)
6399
6756
  return;
6400
6757
  let message = 'Aborted request to ' + this.description + (reason ? ': ' + reason : '');
6401
6758
  this.state = 'aborted';
6402
- this.deferred.reject(new up.Aborted(message));
6759
+ this._reject(new up.Aborted(message));
6403
6760
  this.emit('up:request:aborted', { log: message });
6404
6761
  return true;
6405
6762
  }
6406
6763
  _setOfflineState(reason) {
6407
- if (this._isSettled())
6764
+ if (this.ended)
6408
6765
  return;
6409
6766
  let message = 'Cannot load request to ' + this.description + (reason ? ': ' + reason : '');
6410
6767
  this.state = 'offline';
6411
6768
  this.emit('up:request:offline', { log: message });
6412
- this.deferred.reject(new up.Offline(message));
6769
+ this._reject(new up.Offline(message));
6413
6770
  }
6414
6771
  respondWith(response) {
6415
6772
  this.response = response;
6416
- if (this._isSettled())
6773
+ if (this.ended)
6417
6774
  return;
6418
6775
  this.state = 'loaded';
6419
6776
  if (response.ok) {
6420
- this.deferred.resolve(response);
6777
+ this._resolve(response);
6421
6778
  }
6422
6779
  else {
6423
- this.deferred.reject(response);
6780
+ this._reject(response);
6424
6781
  }
6425
6782
  }
6426
- _isSettled() {
6783
+ _resolve(response) {
6784
+ this._onSettle();
6785
+ this._deferred.resolve(response);
6786
+ }
6787
+ _reject(responseOrError) {
6788
+ this._onSettle();
6789
+ this._deferred.reject(responseOrError);
6790
+ }
6791
+ _onSettle() {
6792
+ var _b;
6793
+ (_b = this._revertPreviews) === null || _b === void 0 ? void 0 : _b.call(this);
6794
+ }
6795
+ get ended() {
6427
6796
  return (this.state !== 'new') && (this.state !== 'loading') && (this.state !== 'tracking');
6428
6797
  }
6429
6798
  csrfHeader() {
@@ -6473,7 +6842,7 @@ up.Request = (_a = class Request extends up.Record {
6473
6842
  }
6474
6843
  _buildEventEmitter(args) {
6475
6844
  return up.EventEmitter.fromEmitArgs(args, {
6476
- layer: this.layer,
6845
+ layer: this.bindLayer,
6477
6846
  request: this,
6478
6847
  origin: this.origin
6479
6848
  });
@@ -6487,12 +6856,15 @@ up.Request = (_a = class Request extends up.Record {
6487
6856
  get description() {
6488
6857
  return this.method + ' ' + this.url;
6489
6858
  }
6490
- isPartOfSubtree(subtreeElements) {
6491
- subtreeElements = u.wrapList(subtreeElements);
6492
- return u.some(this.fragments, function (fragment) {
6493
- return u.some(subtreeElements, (subtreeElement) => subtreeElement.contains(fragment));
6859
+ isBoundToSubtrees(subtreeRoots) {
6860
+ subtreeRoots = u.wrapList(subtreeRoots);
6861
+ return u.some(this.bindFragments, function (fragment) {
6862
+ return u.some(subtreeRoots, (subtreeElement) => subtreeElement.contains(fragment));
6494
6863
  });
6495
6864
  }
6865
+ isBoundToLayers(layers) {
6866
+ return u.contains(layers, this.bindLayer);
6867
+ }
6496
6868
  get age() {
6497
6869
  return new Date() - this.builtAt;
6498
6870
  }
@@ -6555,7 +6927,7 @@ up.Request = (_a = class Request extends up.Record {
6555
6927
  }
6556
6928
  },
6557
6929
  (() => {
6558
- u.delegate(_a.prototype, ['then', 'catch', 'finally'], function () { return this.deferred; });
6930
+ u.delegatePromise(_a.prototype, '_deferred');
6559
6931
  })(),
6560
6932
  _a);
6561
6933
 
@@ -6605,8 +6977,8 @@ class Route {
6605
6977
  return true;
6606
6978
  if (!newValue)
6607
6979
  return false;
6608
- let cachedTokens = u.parseTokens(cachedValue, { separator: 'comma' });
6609
- let newTokens = u.parseTokens(newValue, { separator: 'comma' });
6980
+ let cachedTokens = up.fragment.splitTarget(cachedValue);
6981
+ let newTokens = up.fragment.splitTarget(newValue);
6610
6982
  return u.containsAll(cachedTokens, newTokens);
6611
6983
  }
6612
6984
  else {
@@ -6667,7 +7039,13 @@ up.Request.Cache = class Cache {
6667
7039
  return __awaiter(this, void 0, void 0, function* () {
6668
7040
  newRequest.trackedRequest = existingRequest;
6669
7041
  newRequest.state = 'tracking';
6670
- let value = yield u.always(existingRequest);
7042
+ let value;
7043
+ if (existingRequest.ended && existingRequest.response) {
7044
+ value = existingRequest.response;
7045
+ }
7046
+ else {
7047
+ value = yield u.always(existingRequest);
7048
+ }
6671
7049
  if (value instanceof up.Response) {
6672
7050
  if (options.force || existingRequest.cacheRoute.satisfies(existingRequest, newRequest)) {
6673
7051
  newRequest.fromCache = true;
@@ -6683,7 +7061,7 @@ up.Request.Cache = class Cache {
6683
7061
  }
6684
7062
  else {
6685
7063
  newRequest.state = existingRequest.state;
6686
- newRequest.deferred.reject(value);
7064
+ newRequest._reject(value);
6687
7065
  }
6688
7066
  });
6689
7067
  }
@@ -6766,8 +7144,10 @@ up.Request.Queue = class Queue {
6766
7144
  }
6767
7145
  }
6768
7146
  _scheduleSlowTimer(request) {
6769
- let timeUntilLate = Math.max(request.badResponseTime - request.age, 0);
6770
- u.timer(timeUntilLate, () => this._checkLate());
7147
+ if (!request.isTimed())
7148
+ return;
7149
+ let timeUntilLate = Math.max(request.effectiveLateTime - request.age);
7150
+ u.timer(timeUntilLate, () => this._checkForLate());
6771
7151
  }
6772
7152
  _getMaxConcurrency() {
6773
7153
  return u.evalOption(up.network.config.concurrency);
@@ -6797,8 +7177,8 @@ up.Request.Queue = class Queue {
6797
7177
  if ((responseOrError instanceof up.Response) && responseOrError.ok) {
6798
7178
  up.network.registerAliasForRedirect(request, responseOrError);
6799
7179
  }
6800
- this._checkLate();
6801
7180
  queueMicrotask(() => this._poke());
7181
+ u.task(() => this._checkForRecover());
6802
7182
  }
6803
7183
  _poke() {
6804
7184
  let request;
@@ -6807,10 +7187,7 @@ up.Request.Queue = class Queue {
6807
7187
  }
6808
7188
  }
6809
7189
  abort(...args) {
6810
- var _a;
6811
- let options = u.extractOptions(args);
6812
- let { except, reason, logOnce } = options;
6813
- let conditions = (_a = args[0]) !== null && _a !== void 0 ? _a : true;
7190
+ let [conditions = true, { except, reason, logOnce }] = u.args(args, 'val', 'options');
6814
7191
  let tester = up.Request.tester(conditions, { except });
6815
7192
  for (let list of [this._currentRequests, this._queuedRequests]) {
6816
7193
  const abortableRequests = u.filter(list, tester);
@@ -6824,22 +7201,25 @@ up.Request.Queue = class Queue {
6824
7201
  }
6825
7202
  }
6826
7203
  }
6827
- _checkLate() {
6828
- const currentLate = this._isLate();
6829
- if (this._emittedLate !== currentLate) {
6830
- this._emittedLate = currentLate;
6831
- if (currentLate) {
6832
- up.emit('up:network:late', { log: 'Server is slow to respond' });
6833
- }
6834
- else {
6835
- up.emit('up:network:recover', { log: 'Slow requests were loaded' });
6836
- }
7204
+ _checkForLate() {
7205
+ if (!this._emittedLate && this._hasLateTimedRequests()) {
7206
+ this._emittedLate = true;
7207
+ up.emit('up:network:late', { log: 'Server is slow to respond' });
7208
+ }
7209
+ }
7210
+ _checkForRecover() {
7211
+ if (this._emittedLate && !this._timedRequests.length) {
7212
+ this._emittedLate = false;
7213
+ up.emit('up:network:recover', { log: 'Slow requests were loaded' });
6837
7214
  }
6838
7215
  }
6839
- _isLate() {
6840
- const allForegroundRequests = u.reject(this.allRequests, 'background');
7216
+ get _timedRequests() {
7217
+ return this.allRequests.filter((request) => request.isTimed());
7218
+ }
7219
+ _hasLateTimedRequests() {
6841
7220
  const timerTolerance = 1;
6842
- return u.some(allForegroundRequests, (request) => request.age >= (request.badResponseTime - timerTolerance));
7221
+ const isLate = (request) => request.age >= (request.effectiveLateTime - timerTolerance);
7222
+ return u.some(this._timedRequests, isLate);
6843
7223
  }
6844
7224
  };
6845
7225
 
@@ -7000,7 +7380,7 @@ up.Response = class Response extends up.Record {
7000
7380
  }
7001
7381
  get varyHeaderNames() {
7002
7382
  let varyHeaderValue = this.header('Vary');
7003
- return u.parseTokens(varyHeaderValue, { separator: 'comma' });
7383
+ return u.getSimpleTokens(varyHeaderValue, { separator: ',' });
7004
7384
  }
7005
7385
  get contentType() {
7006
7386
  return this.header('Content-Type');
@@ -7043,15 +7423,15 @@ const u = up.util;
7043
7423
  const e = up.element;
7044
7424
  const FULL_DOCUMENT_PATTERN = /^\s*<(html|!DOCTYPE)\b/i;
7045
7425
  up.ResponseDoc = (_a = class ResponseDoc {
7046
- constructor({ document, fragment, content, target, origin, cspNonces, match }) {
7426
+ constructor({ document, fragment, content, target, origin, data, cspNonces, match }) {
7047
7427
  if (document) {
7048
- this._parseDocument(document);
7428
+ this._parseDocument(document, origin, data);
7049
7429
  }
7050
7430
  else if (fragment) {
7051
- this._parseFragment(fragment);
7431
+ this._parseFragment(fragment, origin, data);
7052
7432
  }
7053
7433
  else {
7054
- this._parseContent(content || '', target);
7434
+ this._parseContent(content || '', origin, target, data);
7055
7435
  }
7056
7436
  this._cspNonces = cspNonces;
7057
7437
  if (origin) {
@@ -7062,46 +7442,49 @@ up.ResponseDoc = (_a = class ResponseDoc {
7062
7442
  }
7063
7443
  this._match = match;
7064
7444
  }
7065
- _parseDocument(value) {
7445
+ _parseDocument(value, origin, data) {
7066
7446
  if (value instanceof Document) {
7067
7447
  this._document = value;
7068
7448
  this._isFullDocument = true;
7069
7449
  }
7070
7450
  else if (u.isString(value)) {
7071
- this._document = e.createBrokenDocumentFromHTML(value);
7072
7451
  this._isFullDocument = FULL_DOCUMENT_PATTERN.test(value);
7073
- this._isDocumentBroken = true;
7452
+ let htmlParser = (html) => [e.createBrokenDocumentFromHTML(html)];
7453
+ let nodes = up.fragment.provideNodes(value, { origin, data, htmlParser });
7454
+ if (nodes[0] instanceof Document) {
7455
+ this._document = nodes[0];
7456
+ }
7457
+ else {
7458
+ this._document = this._buildFauxDocument(nodes);
7459
+ }
7074
7460
  }
7075
7461
  else {
7076
7462
  this._document = this._buildFauxDocument(value);
7077
- this._isFullDocument = value.matches('html');
7078
7463
  }
7079
7464
  }
7080
- _parseFragment(value) {
7081
- let parsed = u.isString(value) ? e.createFromHTML(value) : value;
7082
- this._document = this._buildFauxDocument(parsed);
7465
+ _parseDocumentFromHTML(html) {
7466
+ return e.createBrokenDocumentFromHTML(html);
7083
7467
  }
7084
- _parseContent(value, target) {
7468
+ _parseFragment(value, origin, data) {
7469
+ let element = e.extractSingular(up.fragment.provideNodes(value, { origin, data }));
7470
+ this._document = this._buildFauxDocument(element);
7471
+ }
7472
+ _parseContent(value, origin, target, data) {
7085
7473
  if (!target)
7086
7474
  up.fail("must pass a { target } when passing { content }");
7087
7475
  let simplifiedTarget = u.map(up.fragment.parseTargetSteps(target), 'selector').join();
7088
- const matchingElement = e.createFromSelector(simplifiedTarget);
7089
- if (u.isString(value)) {
7090
- matchingElement.innerHTML = value;
7091
- }
7092
- else {
7093
- matchingElement.appendChild(value);
7094
- }
7476
+ let nodes = up.fragment.provideNodes(value, { origin, data });
7477
+ let matchingElement = e.createFromSelector(simplifiedTarget, { content: nodes });
7095
7478
  this._document = this._buildFauxDocument(matchingElement);
7096
7479
  }
7097
- _buildFauxDocument(node) {
7480
+ _buildFauxDocument(nodes) {
7481
+ nodes = u.wrapList(nodes);
7098
7482
  let fauxDocument = document.createElement('up-document');
7099
- fauxDocument.append(node);
7100
- fauxDocument.documentElement = node;
7483
+ fauxDocument.append(...nodes);
7101
7484
  return fauxDocument;
7102
7485
  }
7103
7486
  rootSelector() {
7104
- return up.fragment.toTarget(this._document.documentElement);
7487
+ return up.fragment.toTarget(this._document.children[0]);
7105
7488
  }
7106
7489
  get title() {
7107
7490
  return this._fromHead(this._getTitleText);
@@ -7183,7 +7566,7 @@ up.ResponseDoc = (_a = class ResponseDoc {
7183
7566
  }
7184
7567
  finalizeElement(element) {
7185
7568
  up.NonceableCallback.adoptNonces(element, this._cspNonces);
7186
- if (this._isDocumentBroken) {
7569
+ if (this._document instanceof Document) {
7187
7570
  let brokenElements = e.subtree(element, ':is(noscript,script,audio,video):not(.up-keeping, .up-keeping *)');
7188
7571
  u.each(brokenElements, e.fixParserDamage);
7189
7572
  }
@@ -7293,17 +7676,18 @@ up.RevealMotion = class RevealMotion {
7293
7676
  /***/ (() => {
7294
7677
 
7295
7678
  const u = up.util;
7296
- const CSS_HAS_SUFFIX_PATTERN = /:has\(([^)]+)\)$/;
7679
+ const e = up.element;
7297
7680
  up.Selector = class Selector {
7298
7681
  constructor(selector, elementOrDocument, options = {}) {
7299
7682
  var _a;
7300
7683
  this._filters = [];
7301
- if (!options.destroying) {
7684
+ let matchingInExternalDocument = elementOrDocument && !document.contains(elementOrDocument);
7685
+ if (!matchingInExternalDocument && !options.destroying) {
7302
7686
  this._filters.push(up.fragment.isNotDestroying);
7303
7687
  }
7304
- let matchingInExternalDocument = elementOrDocument && !document.contains(elementOrDocument);
7688
+ this._ignoreLayers = matchingInExternalDocument || options.layer === 'any' || up.layer.count === 1;
7305
7689
  let expandTargetLayer;
7306
- if (matchingInExternalDocument || options.layer === 'any') {
7690
+ if (this._ignoreLayers) {
7307
7691
  expandTargetLayer = up.layer.root;
7308
7692
  }
7309
7693
  else {
@@ -7314,44 +7698,45 @@ up.Selector = class Selector {
7314
7698
  this._filters.push(match => u.some(this._layers, layer => layer.contains(match)));
7315
7699
  expandTargetLayer = this._layers[0];
7316
7700
  }
7317
- let expandedTargets = up.fragment.expandTargets(selector, Object.assign(Object.assign({}, options), { layer: expandTargetLayer }));
7318
- this._selectors = expandedTargets.map((target) => {
7319
- if (!up.browser.canHasSelector()) {
7320
- target = target.replace(CSS_HAS_SUFFIX_PATTERN, (match, descendantSelector) => {
7321
- this._filters.push(element => element.querySelector(descendantSelector));
7322
- return '';
7323
- });
7324
- }
7325
- return target || '*';
7326
- });
7701
+ this._selectors = up.fragment.expandTargets(selector, Object.assign(Object.assign({}, options), { layer: expandTargetLayer }));
7327
7702
  this._unionSelector = this._selectors.join() || 'match-none';
7328
7703
  }
7329
7704
  matches(element) {
7330
- return element.matches(this._unionSelector) && this._passesFilter(element);
7705
+ return e.elementLikeMatches(element, this._unionSelector) && this._passesFilter(element);
7331
7706
  }
7332
7707
  closest(element) {
7333
- let parentElement;
7334
- if (this.matches(element)) {
7335
- return element;
7708
+ return this._filterOne(element.closest(this._unionSelector));
7709
+ }
7710
+ descendants(root = document) {
7711
+ return this._filterMany(root.querySelectorAll(this._unionSelector));
7712
+ }
7713
+ firstDescendant(root) {
7714
+ if (this._ignoreLayers) {
7715
+ root || (root = document);
7716
+ return this._firstSelectorMatch((selector) => root.querySelectorAll(selector));
7336
7717
  }
7337
- else if (parentElement = element.parentElement) {
7338
- return this.closest(parentElement);
7718
+ else {
7719
+ return u.findResult(this._layers, (layer) => {
7720
+ return this._firstSelectorMatch((selector) => e.subtree(layer.element, selector));
7721
+ });
7339
7722
  }
7340
7723
  }
7724
+ subtree(root) {
7725
+ return this._filterMany(e.subtree(root, this._unionSelector));
7726
+ }
7727
+ _firstSelectorMatch(fn) {
7728
+ return u.findResult(this._selectors, (selector) => {
7729
+ return this._filterMany(fn(selector))[0];
7730
+ });
7731
+ }
7341
7732
  _passesFilter(element) {
7342
- return u.every(this._filters, filter => filter(element));
7733
+ return element && u.every(this._filters, filter => filter(element));
7343
7734
  }
7344
- descendants(root = document) {
7345
- const results = u.flatMap(this._selectors, selector => root.querySelectorAll(selector));
7346
- return u.filter(results, element => this._passesFilter(element));
7735
+ _filterOne(element) {
7736
+ return u.presence(element, this._passesFilter.bind(this));
7347
7737
  }
7348
- subtree(root) {
7349
- const results = [];
7350
- if (!(root instanceof Document) && this.matches(root)) {
7351
- results.push(root);
7352
- }
7353
- results.push(...this.descendants(root));
7354
- return results;
7738
+ _filterMany(elements) {
7739
+ return u.filter(elements, this._passesFilter.bind(this));
7355
7740
  }
7356
7741
  };
7357
7742
 
@@ -7487,7 +7872,7 @@ up.URLPattern = class URLPattern {
7487
7872
  this._groups = [];
7488
7873
  const positiveList = [];
7489
7874
  const negativeList = [];
7490
- for (let pattern of u.parseTokens(fullPattern)) {
7875
+ for (let pattern of u.getSimpleTokens(fullPattern)) {
7491
7876
  if (pattern[0] === '-') {
7492
7877
  negativeList.push(pattern.substring(1));
7493
7878
  }
@@ -7611,7 +7996,7 @@ up.framework = (function () {
7611
7996
  return !supportIssue();
7612
7997
  }
7613
7998
  function supportIssue() {
7614
- for (let feature of ['URL', 'Proxy', 'Promise', 'DOMParser', 'FormData']) {
7999
+ for (let feature of ['Promise', 'DOMParser', 'FormData', 'reportError']) {
7615
8000
  if (!window[feature]) {
7616
8001
  return `Browser doesn't support the ${feature} API`;
7617
8002
  }
@@ -7619,6 +8004,11 @@ up.framework = (function () {
7619
8004
  if (document.compatMode === 'BackCompat') {
7620
8005
  return 'Browser is in quirks mode (missing DOCTYPE?)';
7621
8006
  }
8007
+ for (let selector of [':is(*)', ':has(*)']) {
8008
+ if (!CSS.supports(`selector(${selector})`)) {
8009
+ return `Browser doesn't support the ${selector} selector`;
8010
+ }
8011
+ }
7622
8012
  }
7623
8013
  return {
7624
8014
  onEvaled,
@@ -7788,29 +8178,32 @@ up.protocol = (function () {
7788
8178
  return extractHeader(xhr, 'expireCache') || ((_b = (_a = up.migrate).clearCacheFromXHR) === null || _b === void 0 ? void 0 : _b.call(_a, xhr));
7789
8179
  }
7790
8180
  function contextFromXHR(xhr) {
7791
- return extractHeader(xhr, 'context', JSON.parse);
8181
+ return extractHeader(xhr, 'context', u.parseRelaxedJSON);
7792
8182
  }
7793
8183
  function methodFromXHR(xhr) {
7794
8184
  return extractHeader(xhr, 'method', u.normalizeMethod);
7795
8185
  }
7796
8186
  function titleFromXHR(xhr) {
7797
8187
  var _a, _b, _c;
7798
- return (_c = (_b = (_a = up.migrate).titleFromXHR) === null || _b === void 0 ? void 0 : _b.call(_a, xhr)) !== null && _c !== void 0 ? _c : extractHeader(xhr, 'title', JSON.parse);
8188
+ return (_c = (_b = (_a = up.migrate).titleFromXHR) === null || _b === void 0 ? void 0 : _b.call(_a, xhr)) !== null && _c !== void 0 ? _c : extractHeader(xhr, 'title', u.parseRelaxedJSON);
7799
8189
  }
7800
8190
  function eventPlansFromXHR(xhr) {
7801
- return extractHeader(xhr, 'events', JSON.parse);
8191
+ return extractHeader(xhr, 'events', u.parseRelaxedJSON);
7802
8192
  }
7803
8193
  function acceptLayerFromXHR(xhr) {
7804
- return extractHeader(xhr, 'acceptLayer', JSON.parse);
8194
+ return extractHeader(xhr, 'acceptLayer', u.parseRelaxedJSON);
7805
8195
  }
7806
8196
  function dismissLayerFromXHR(xhr) {
7807
- return extractHeader(xhr, 'dismissLayer', JSON.parse);
8197
+ return extractHeader(xhr, 'dismissLayer', u.parseRelaxedJSON);
7808
8198
  }
7809
8199
  const initialRequestMethod = u.memoize(function () {
7810
8200
  return u.normalizeMethod(up.browser.popCookie('_up_method'));
7811
8201
  });
7812
8202
  function locationFromXHR(xhr) {
7813
- return extractHeader(xhr, 'location') || xhr.responseURL;
8203
+ let location = extractHeader(xhr, 'location') || xhr.responseURL;
8204
+ if (location) {
8205
+ return u.normalizeURL(location);
8206
+ }
7814
8207
  }
7815
8208
  const config = new up.Config(() => ({
7816
8209
  methodParam: '_method',
@@ -7975,6 +8368,9 @@ up.script = (function () {
7975
8368
  ],
7976
8369
  nonceableAttributes: [
7977
8370
  'up-watch',
8371
+ 'up-on-keep',
8372
+ 'up-on-hungry',
8373
+ 'up-on-opened',
7978
8374
  'up-on-accepted',
7979
8375
  'up-on-dismissed',
7980
8376
  'up-on-loaded',
@@ -7984,7 +8380,10 @@ up.script = (function () {
7984
8380
  'up-on-offline',
7985
8381
  ],
7986
8382
  scriptSelectors: [
7987
- 'script'
8383
+ 'script:not([type])',
8384
+ 'script[type="text/javascript"]',
8385
+ 'script[type="module"]',
8386
+ 'script[type="importmap"]',
7988
8387
  ],
7989
8388
  noScriptSelectors: [
7990
8389
  'script[type="application/ld+json"]'
@@ -8015,10 +8414,13 @@ up.script = (function () {
8015
8414
  function registerAttrCompiler(...args) {
8016
8415
  let [attr, options, valueCallback] = parseProcessorArgs(args);
8017
8416
  let selector = `[${attr}]`;
8417
+ let { defaultValue } = options;
8018
8418
  let callback = (element) => {
8019
- let value = e.booleanOrStringAttr(element, attr, options.defaultValue);
8020
- if (!value)
8419
+ let value = e.booleanOrStringAttr(element, attr);
8420
+ if (value === false)
8021
8421
  return;
8422
+ if (u.isDefined(defaultValue) && value === true)
8423
+ value = defaultValue;
8022
8424
  return valueCallback(element, value);
8023
8425
  };
8024
8426
  registerProcessor([selector, options, callback]);
@@ -8045,11 +8447,7 @@ up.script = (function () {
8045
8447
  }
8046
8448
  }
8047
8449
  const parseProcessorArgs = function (args) {
8048
- const defaults = u.extractOptions(args);
8049
- const selector = args.shift();
8050
- const callback = args.pop();
8051
- const options = Object.assign(Object.assign({}, defaults), u.extractOptions(args));
8052
- return [selector, options, callback];
8450
+ return u.args(args, 'val', 'options', 'callback');
8053
8451
  };
8054
8452
  function buildProcessor(args, overrides) {
8055
8453
  let [selector, options, callback] = parseProcessorArgs(args);
@@ -8087,18 +8485,16 @@ up.script = (function () {
8087
8485
  pass.run();
8088
8486
  }
8089
8487
  function registerDestructor(element, destructor) {
8090
- let destructors = element.upDestructors;
8091
- if (!destructors) {
8092
- destructors = [];
8093
- element.upDestructors = destructors;
8094
- element.classList.add('up-can-clean');
8095
- }
8096
- if (u.isArray(destructor)) {
8097
- destructors.push(...destructor);
8098
- }
8099
- else {
8100
- destructors.push(destructor);
8101
- }
8488
+ let fns = u.scanFunctions(destructor);
8489
+ if (!fns.length)
8490
+ return;
8491
+ let registry = (element.upDestructors || (element.upDestructors = buildDestructorRegistry(element)));
8492
+ registry.guard(fns);
8493
+ }
8494
+ function buildDestructorRegistry(element) {
8495
+ let registry = u.cleaner();
8496
+ registry(e.addClassTemp(element, 'up-can-clean'));
8497
+ return registry;
8102
8498
  }
8103
8499
  function hello(element, options = {}) {
8104
8500
  element = up.fragment.get(element, options);
@@ -8115,18 +8511,12 @@ up.script = (function () {
8115
8511
  return element.upData || (element.upData = buildData(element));
8116
8512
  }
8117
8513
  function buildData(element) {
8118
- if (!element.getAttribute) {
8119
- return {};
8120
- }
8121
- let rawJSON = element.getAttribute('up-data');
8122
- let parsedJSON;
8123
- if (rawJSON) {
8124
- parsedJSON = JSON.parse(rawJSON);
8125
- if (!u.isOptions(parsedJSON)) {
8126
- return parsedJSON;
8127
- }
8514
+ var _a;
8515
+ let parsedJSON = (_a = e.jsonAttr(element, 'up-data')) !== null && _a !== void 0 ? _a : {};
8516
+ if (!u.isOptions(parsedJSON)) {
8517
+ return parsedJSON;
8128
8518
  }
8129
- return Object.assign(Object.assign(Object.assign({}, element.dataset), parsedJSON), element.upCompileData);
8519
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, element.upTemplateData), element.dataset), parsedJSON), element.upCompileData);
8130
8520
  }
8131
8521
  function findAssets(head = document.head) {
8132
8522
  return head.querySelectorAll(config.selector('assetSelectors'));
@@ -8146,6 +8536,9 @@ up.script = (function () {
8146
8536
  let selector = config.selector('scriptSelectors');
8147
8537
  u.each(e.subtree(root, selector), disableScript);
8148
8538
  }
8539
+ function isScript(value) {
8540
+ return config.matches(value, 'scriptSelectors');
8541
+ }
8149
8542
  function reset() {
8150
8543
  registeredCompilers = u.filter(registeredCompilers, 'isDefault');
8151
8544
  registeredMacros = u.filter(registeredMacros, 'isDefault');
@@ -8163,6 +8556,7 @@ up.script = (function () {
8163
8556
  findAssets,
8164
8557
  assertAssetsOK,
8165
8558
  disableSubtree: disableScriptsInSubtree,
8559
+ isScript,
8166
8560
  };
8167
8561
  })();
8168
8562
  up.compiler = up.script.compiler;
@@ -8312,7 +8706,7 @@ up.history = (function () {
8312
8706
  }
8313
8707
  }
8314
8708
  function updateLang(newLang) {
8315
- e.toggleAttr(e.root, 'lang', newLang, !!newLang);
8709
+ e.setAttrPresence(e.root, 'lang', newLang, !!newLang);
8316
8710
  }
8317
8711
  up.macro('[up-back]', function (link) {
8318
8712
  if (previousLocation) {
@@ -8354,14 +8748,18 @@ up.fragment = (function () {
8354
8748
  return tagName;
8355
8749
  }
8356
8750
  }
8751
+ const STRONG_TARGET_DERIVERS = [
8752
+ '[up-id]',
8753
+ '[id]',
8754
+ 'html',
8755
+ 'head',
8756
+ 'body',
8757
+ ];
8357
8758
  const config = new up.Config(() => ({
8358
8759
  badTargetClasses: [/^up-/],
8760
+ strongTargetDerivers: STRONG_TARGET_DERIVERS,
8359
8761
  targetDerivers: [
8360
- '[up-id]',
8361
- '[id]',
8362
- 'html',
8363
- 'head',
8364
- 'body',
8762
+ ...STRONG_TARGET_DERIVERS,
8365
8763
  'main',
8366
8764
  '[up-main]',
8367
8765
  upTagName,
@@ -8379,10 +8777,19 @@ up.fragment = (function () {
8379
8777
  'form',
8380
8778
  ],
8381
8779
  verifyDerivedTarget: true,
8780
+ renderOptions: {
8781
+ hungry: true,
8782
+ keep: true,
8783
+ saveScroll: true,
8784
+ saveFocus: true,
8785
+ focus: 'keep',
8786
+ abort: 'target',
8787
+ failOptions: true,
8788
+ feedback: true,
8789
+ },
8382
8790
  navigateOptions: {
8383
8791
  cache: 'auto',
8384
8792
  revalidate: 'auto',
8385
- feedback: true,
8386
8793
  fallback: true,
8387
8794
  focus: 'auto',
8388
8795
  scroll: 'auto',
@@ -8395,7 +8802,7 @@ up.fragment = (function () {
8395
8802
  autoFocus: ['hash', 'autofocus', 'main-if-main', 'keep', 'target-if-lost'],
8396
8803
  autoScroll: ['hash', 'layer-if-main'],
8397
8804
  autoRevalidate: (response) => response.expired,
8398
- skipResponse: defaultSkipResponse
8805
+ skipResponse: defaultSkipResponse,
8399
8806
  }));
8400
8807
  u.delegate(config, ['mainTargets'], () => up.layer.config.any);
8401
8808
  function defaultSkipResponse({ response, expiredResponse }) {
@@ -8455,14 +8862,12 @@ up.fragment = (function () {
8455
8862
  return fragment.isConnected && isNotDestroying(fragment);
8456
8863
  }
8457
8864
  function getSmart(...args) {
8458
- const options = u.extractOptions(args);
8459
- const selector = args.pop();
8460
- const root = args[0];
8461
- if (u.isElementish(selector)) {
8865
+ let [root, selector, options] = parseGetArgs(args);
8866
+ if (u.isElementLike(selector)) {
8462
8867
  return e.get(selector);
8463
8868
  }
8464
8869
  if (root) {
8465
- return getDumb(root, selector, options);
8870
+ return getFirstDescendant(root, selector, options);
8466
8871
  }
8467
8872
  return new up.FragmentFinder({
8468
8873
  selector,
@@ -8471,13 +8876,16 @@ up.fragment = (function () {
8471
8876
  match: options.match,
8472
8877
  }).find();
8473
8878
  }
8474
- function getDumb(...args) {
8475
- return getAll(...args)[0];
8879
+ function getFirstDescendant(...args) {
8880
+ let [root, selectorString, options] = parseGetArgs(args);
8881
+ let selector = new up.Selector(selectorString, root, options);
8882
+ return selector.firstDescendant(root);
8883
+ }
8884
+ function parseGetArgs(args) {
8885
+ return u.args(args, 'val', 'val', 'options');
8476
8886
  }
8477
8887
  function getAll(...args) {
8478
- const options = u.extractOptions(args);
8479
- let selectorString = args.pop();
8480
- const root = args[0];
8888
+ let [root, selectorString, options] = parseGetArgs(args);
8481
8889
  if (u.isElement(selectorString)) {
8482
8890
  return [selectorString];
8483
8891
  }
@@ -8585,8 +8993,9 @@ up.fragment = (function () {
8585
8993
  function cannotTarget(element) {
8586
8994
  throw new up.CannotTarget(untargetableMessage(element));
8587
8995
  }
8588
- function tryToTarget(element, options) {
8589
- return u.findResult(config.targetDerivers, function (deriver) {
8996
+ function tryToTarget(element, options = {}) {
8997
+ let derivers = options.strong ? config.strongTargetDerivers : config.targetDerivers;
8998
+ return u.findResult(derivers, function (deriver) {
8590
8999
  let target = deriveTarget(element, deriver);
8591
9000
  if (target && isGoodTarget(target, element, options)) {
8592
9001
  return target;
@@ -8612,7 +9021,7 @@ up.fragment = (function () {
8612
9021
  }
8613
9022
  }
8614
9023
  function deriveTargetFromPattern(element, deriver) {
8615
- let { includePath, excludeRaw } = up.element.parseSelector(deriver);
9024
+ let { includePath, excludeRaw } = e.parseSelector(deriver);
8616
9025
  if (includePath.length !== 1) {
8617
9026
  throw new up.CannotParse(deriver);
8618
9027
  }
@@ -8650,7 +9059,9 @@ up.fragment = (function () {
8650
9059
  return result;
8651
9060
  }
8652
9061
  function isGoodTarget(target, element, options = {}) {
8653
- return !isAlive(element) || !config.verifyDerivedTarget || up.fragment.get(target, Object.assign({ layer: element }, options)) === element;
9062
+ var _a;
9063
+ let verify = (_a = options.verify) !== null && _a !== void 0 ? _a : config.verifyDerivedTarget;
9064
+ return !isAlive(element) || !verify || up.fragment.get(target, Object.assign({ layer: element }, options)) === element;
8654
9065
  }
8655
9066
  function matchesPattern(pattern, str) {
8656
9067
  if (u.isRegExp(pattern)) {
@@ -8692,7 +9103,7 @@ up.fragment = (function () {
8692
9103
  let firstSwappableTarget = toTarget(layer.getFirstSwappableElement(), options);
8693
9104
  targets.unshift(target.replace(LAYER_PSEUDO, firstSwappableTarget));
8694
9105
  }
8695
- else if (u.isElementish(target)) {
9106
+ else if (u.isElementLike(target)) {
8696
9107
  expanded.push(toTarget(target, options));
8697
9108
  }
8698
9109
  else if (u.isString(target)) {
@@ -8719,11 +9130,13 @@ up.fragment = (function () {
8719
9130
  }
8720
9131
  });
8721
9132
  }
8722
- function resolveOrigin(...args) {
8723
- return (up.migrate.resolveOrigin || modernResolveOrigin)(...args);
9133
+ function resolveOrigin(target, options) {
9134
+ if (!u.isString(target))
9135
+ return target;
9136
+ return (up.migrate.resolveOrigin || modernResolveOrigin)(target, options);
8724
9137
  }
8725
9138
  function splitTarget(target) {
8726
- return u.parseTokens(target, { separator: 'comma' });
9139
+ return u.getComplexTokens(target);
8727
9140
  }
8728
9141
  function parseTargetSteps(target, options = {}) {
8729
9142
  var _a;
@@ -8736,7 +9149,7 @@ up.fragment = (function () {
8736
9149
  continue;
8737
9150
  let placement = defaultPlacement;
8738
9151
  let maybe = defaultMaybe;
8739
- selector = selector.replace(/\b::?(before|after)\b/, (_match, customPlacement) => {
9152
+ selector = selector.replace(/\b::?(before|after|content)\b/, (_match, customPlacement) => {
8740
9153
  placement = customPlacement;
8741
9154
  return '';
8742
9155
  });
@@ -8800,13 +9213,13 @@ up.fragment = (function () {
8800
9213
  let elements;
8801
9214
  if (options.target) {
8802
9215
  elements = getAll(options.target, options);
8803
- testFn = (request) => request.isPartOfSubtree(elements);
9216
+ testFn = (request) => request.isBoundToSubtrees(elements);
8804
9217
  reason || (reason = 'Aborting requests within fragment');
8805
9218
  }
8806
9219
  else {
8807
9220
  let layers = up.layer.getAll(options);
8808
9221
  elements = u.map(layers, 'element');
8809
- testFn = (request) => u.contains(layers, request.layer);
9222
+ testFn = (request) => request.isBoundToLayers(layers);
8810
9223
  reason || (reason = 'Aborting requests within ' + layers.join(', '));
8811
9224
  }
8812
9225
  let testFnWithAbortable = (request) => request.abortable && testFn(request);
@@ -8821,8 +9234,8 @@ up.fragment = (function () {
8821
9234
  up.destructor(fragment, unsubscribe);
8822
9235
  return unsubscribe;
8823
9236
  }
8824
- function onFirstIntersect(origin, callback, { margin = 0 } = {}) {
8825
- if (e.isIntersectingWindow(origin, { margin })) {
9237
+ function onFirstIntersect(element, callback, { margin = 0 } = {}) {
9238
+ if (e.isIntersectingWindow(element, { margin })) {
8826
9239
  callback();
8827
9240
  return;
8828
9241
  }
@@ -8837,15 +9250,63 @@ up.fragment = (function () {
8837
9250
  }
8838
9251
  let observer = new IntersectionObserver(processIntersectEntries, { rootMargin: `${margin}px` });
8839
9252
  let disconnect = () => observer.disconnect();
8840
- observer.observe(origin);
8841
- onAborted(origin, disconnect);
9253
+ observer.observe(element);
9254
+ up.destructor(element, disconnect);
9255
+ }
9256
+ const STARTS_WITH_SELECTOR = /^([\w-]+|\*)?(#|\.|[:[][a-z-]{3,})/;
9257
+ function provideNodes(value, { origin, originLayer, data, htmlParser = e.createNodesFromHTML } = {}) {
9258
+ if (u.isString(value) && STARTS_WITH_SELECTOR.test(value)) {
9259
+ let [parsedValue, parsedData] = u.parseScalarJSONPairs(value)[0];
9260
+ data = Object.assign(Object.assign({}, data), parsedData);
9261
+ value = up.fragment.get(parsedValue, { layer: 'closest', origin, originLayer }) || up.fail(`Cannot find template "%s"`, value);
9262
+ }
9263
+ if (u.isString(value)) {
9264
+ value = htmlParser(value);
9265
+ }
9266
+ if (isTemplate(value)) {
9267
+ value = cloneTemplate(value, data, { htmlParser });
9268
+ }
9269
+ return u.wrapList(value);
9270
+ }
9271
+ function isTemplate(value) {
9272
+ return u.isElement(value) && value.matches('template, script[type]') && !up.script.isScript(value);
9273
+ }
9274
+ function cloneTemplate(templateOrSelector, data = {}, { origin, htmlParser } = {}) {
9275
+ var _a;
9276
+ let template = getSmart(templateOrSelector, { origin }) || up.fail('Template not found: %o', templateOrSelector);
9277
+ let event = up.emit(template, 'up:template:clone', { data, nodes: null, log: ["Using template %o", templateOrSelector] });
9278
+ let nodes = (_a = event.nodes) !== null && _a !== void 0 ? _a : defaultTemplateNodes(template, htmlParser);
9279
+ for (let node of nodes) {
9280
+ node.upTemplateData = data;
9281
+ }
9282
+ return nodes;
9283
+ }
9284
+ function defaultTemplateNodes(template, htmlParser = e.createNodesFromHTML) {
9285
+ let templateText = template.innerHTML;
9286
+ return htmlParser(templateText);
9287
+ }
9288
+ function insertTemp(...args) {
9289
+ let [reference, position = 'beforeend', tempValue] = u.args(args, 'val', u.isAdjacentPosition, 'val');
9290
+ let tempNodes = provideNodes(tempValue, { origin: reference });
9291
+ let tempElement = e.wrapIfRequired(tempNodes);
9292
+ let oldPosition = document.contains(tempElement) && e.documentPosition(tempElement);
9293
+ reference.insertAdjacentElement(position, tempElement);
9294
+ if (oldPosition) {
9295
+ return () => {
9296
+ oldPosition[0].insertAdjacentElement(oldPosition[1], tempElement);
9297
+ };
9298
+ }
9299
+ else {
9300
+ up.hello(tempElement);
9301
+ return () => up.destroy(tempElement);
9302
+ }
8842
9303
  }
8843
9304
  up.on('up:framework:boot', function () {
8844
9305
  const { documentElement } = document;
8845
9306
  documentElement.setAttribute('up-source', normalizeSource(location.href));
8846
9307
  up.hello(documentElement);
8847
9308
  if (!up.browser.canPushState()) {
8848
- return up.warn('Cannot push history changes. Next fragment update will load in a new page.');
9309
+ return up.warn('Cannot push history changes. Next render pass with history will load a full page.');
8849
9310
  }
8850
9311
  });
8851
9312
  return {
@@ -8855,7 +9316,7 @@ up.fragment = (function () {
8855
9316
  render,
8856
9317
  navigate,
8857
9318
  get: getSmart,
8858
- getDumb,
9319
+ getFirstDescendant,
8859
9320
  all: getAll,
8860
9321
  subtree: getSubtree,
8861
9322
  contains,
@@ -8889,6 +9350,9 @@ up.fragment = (function () {
8889
9350
  targetForSteps,
8890
9351
  compressNestedSteps,
8891
9352
  containsMainPseudo,
9353
+ insertTemp,
9354
+ provideNodes,
9355
+ cloneTemplate,
8892
9356
  };
8893
9357
  })();
8894
9358
  up.reload = up.fragment.reload;
@@ -8896,6 +9360,7 @@ up.destroy = up.fragment.destroy;
8896
9360
  up.render = up.fragment.render;
8897
9361
  up.navigate = up.fragment.navigate;
8898
9362
  up.visit = up.fragment.visit;
9363
+ up.template = { clone: up.fragment.cloneTemplate };
8899
9364
  u.delegate(up, ['context'], () => up.layer.current);
8900
9365
 
8901
9366
 
@@ -8929,7 +9394,7 @@ up.viewport = (function () {
8929
9394
  up.compiler(config.selectorFn('anchoredRightSelectors'), function (element) {
8930
9395
  return bodyShifter.onAnchoredElementInserted(element);
8931
9396
  });
8932
- function reveal(element, options) {
9397
+ const reveal = up.mockable(function (element, options) {
8933
9398
  var _a, _b;
8934
9399
  options = u.options(options);
8935
9400
  element = f.get(element, options);
@@ -8942,7 +9407,7 @@ up.viewport = (function () {
8942
9407
  const motion = new up.RevealMotion(element, options);
8943
9408
  motion.start();
8944
9409
  return ((_b = (_a = up.migrate).formerlyAsync) === null || _b === void 0 ? void 0 : _b.call(_a, 'up.reveal()')) || true;
8945
- }
9410
+ });
8946
9411
  function doFocus(element, { preventScroll, force, inputDevice, focusVisible } = {}) {
8947
9412
  if (force) {
8948
9413
  if (!element.hasAttribute('tabindex') && element.tabIndex === -1) {
@@ -8975,7 +9440,7 @@ up.viewport = (function () {
8975
9440
  function revealHash(hash = location.hash, options) {
8976
9441
  let match = firstHashTarget(hash, options);
8977
9442
  if (match) {
8978
- return up.reveal(match, { top: true });
9443
+ return reveal(match, { top: true });
8979
9444
  }
8980
9445
  }
8981
9446
  function allSelector() {
@@ -9079,11 +9544,11 @@ up.viewport = (function () {
9079
9544
  return new up.FIFOCache({ capacity: 30, normalizeKey: u.matchableURL });
9080
9545
  }
9081
9546
  function parseOptions(args) {
9082
- const options = u.copy(u.extractOptions(args));
9547
+ const [reference, options] = u.args(args, 'val', 'options');
9083
9548
  options.layer = up.layer.get(options);
9084
9549
  let viewports;
9085
- if (args[0]) {
9086
- viewports = [closest(args[0], options)];
9550
+ if (reference) {
9551
+ viewports = [closest(reference, options)];
9087
9552
  }
9088
9553
  else if (options.around) {
9089
9554
  viewports = getAround(options.around, options);
@@ -9144,7 +9609,7 @@ up.viewport = (function () {
9144
9609
  function firstHashTarget(hash, options = {}) {
9145
9610
  if (hash = pureHash(hash)) {
9146
9611
  const selector = [
9147
- e.attrSelector('id', hash),
9612
+ e.idSelector(hash),
9148
9613
  'a' + e.attrSelector('name', hash)
9149
9614
  ].join();
9150
9615
  return f.get(selector, options);
@@ -9170,16 +9635,19 @@ up.viewport = (function () {
9170
9635
  }
9171
9636
  return to;
9172
9637
  }
9173
- let userScrolled = false;
9174
- up.on('scroll', { once: true, beforeBoot: true }, () => userScrolled = true);
9175
- up.on('up:framework:boot', function () {
9176
- u.task(function () {
9177
- if (!userScrolled) {
9178
- return revealHash();
9179
- }
9180
- });
9638
+ document.addEventListener('DOMContentLoaded', function () {
9639
+ revealHash();
9640
+ u.task(revealHash);
9181
9641
  });
9182
9642
  up.on(window, 'hashchange', () => revealHash());
9643
+ up.on('up:click', 'a[href^="#"]', function (event, link) {
9644
+ if (link.hash !== location.hash)
9645
+ return;
9646
+ if (up.link.isFollowable(link))
9647
+ return;
9648
+ if (revealHash(link.hash))
9649
+ up.event.halt(event);
9650
+ });
9183
9651
  return {
9184
9652
  reveal,
9185
9653
  revealHash,
@@ -9513,7 +9981,7 @@ up.network = (function () {
9513
9981
  cacheSize: 70,
9514
9982
  cacheExpireAge: 15 * 1000,
9515
9983
  cacheEvictAge: 90 * 60 * 1000,
9516
- badResponseTime: 400,
9984
+ lateDelay: 400,
9517
9985
  fail(response) { return (response.status < 200 || response.status > 299) && response.status !== 304; },
9518
9986
  autoCache(request) { return request.isSafe(); },
9519
9987
  expireCache(request, _response) { return !request.isSafe(); },
@@ -9539,10 +10007,7 @@ up.network = (function () {
9539
10007
  }
9540
10008
  function parseRequestOptions(args) {
9541
10009
  var _a, _b;
9542
- const options = u.extractOptions(args);
9543
- if (!options.url) {
9544
- options.url = args[0];
9545
- }
10010
+ let options = u.parseArgIntoOptions(args, 'url');
9546
10011
  (_b = (_a = up.migrate).handleRequestOptions) === null || _b === void 0 ? void 0 : _b.call(_a, options);
9547
10012
  return options;
9548
10013
  }
@@ -9698,7 +10163,7 @@ up.layer = (function () {
9698
10163
  openAnimation: 'fade-in',
9699
10164
  closeAnimation: 'fade-out',
9700
10165
  dismissLabel: '×',
9701
- dismissAriaLabel: 'Dismiss dialog',
10166
+ dismissARIALabel: 'Dismiss dialog',
9702
10167
  dismissable: true,
9703
10168
  history: 'auto',
9704
10169
  trapFocus: true,
@@ -9779,10 +10244,7 @@ up.layer = (function () {
9779
10244
  }
9780
10245
  }
9781
10246
  }
9782
- else if (options.mode) {
9783
- options.layer = 'new';
9784
- }
9785
- else if (u.isElementish(options.target)) {
10247
+ else if (u.isElementLike(options.target)) {
9786
10248
  options.layer = stack.get(options.target, { normalizeLayerOptions: false });
9787
10249
  }
9788
10250
  else if (options.origin) {
@@ -9980,7 +10442,7 @@ up.link = (function () {
9980
10442
  parser.boolean('abortable');
9981
10443
  parser.boolean('background');
9982
10444
  parser.string('contentType');
9983
- parser.number('badResponseTime');
10445
+ parser.booleanOrNumber('lateDelay');
9984
10446
  parser.number('timeout');
9985
10447
  return options;
9986
10448
  }
@@ -9990,7 +10452,6 @@ up.link = (function () {
9990
10452
  options = u.options(options);
9991
10453
  const parser = new up.OptionsParser(link, options, Object.assign({ fail: true }, parserOptions));
9992
10454
  parser.include(parseRequestOptions);
9993
- parser.boolean('feedback');
9994
10455
  options.origin || (options.origin = link);
9995
10456
  parser.boolean('fail');
9996
10457
  parser.boolean('navigate', { default: true });
@@ -9998,11 +10459,12 @@ up.link = (function () {
9998
10459
  parser.string('target');
9999
10460
  parser.booleanOrString('fallback');
10000
10461
  parser.string('match');
10001
- parser.string('content');
10002
- parser.string('fragment');
10003
10462
  parser.string('document');
10004
- parser.boolean('useKeep');
10005
- parser.boolean('useHungry');
10463
+ parser.string('fragment');
10464
+ parser.string('content');
10465
+ parser.boolean('keep', { attr: 'up-use-keep' });
10466
+ parser.boolean('hungry', { attr: 'up-use-hungry' });
10467
+ parser.json('data', { attr: 'up-use-data' });
10006
10468
  parser.callback('onLoaded');
10007
10469
  parser.callback('onRendered', { mainKey: 'result' });
10008
10470
  parser.callback('onFinished', { mainKey: 'result' });
@@ -10026,6 +10488,7 @@ up.link = (function () {
10026
10488
  parser.string('acceptLocation');
10027
10489
  parser.string('dismissLocation');
10028
10490
  parser.booleanOrString('history');
10491
+ parser.include(up.status.statusOptions);
10029
10492
  parser.booleanOrString('focus');
10030
10493
  parser.boolean('saveScroll');
10031
10494
  parser.boolean('saveFocus');
@@ -10051,7 +10514,7 @@ up.link = (function () {
10051
10514
  return Promise.reject(new up.Error(issue));
10052
10515
  }
10053
10516
  const guardEvent = up.event.build('up:link:preload', { log: ['Preloading link %o', link] });
10054
- return follow(link, Object.assign(Object.assign({ abortable: false }, options), { guardEvent, preload: true }));
10517
+ return follow(link, Object.assign(Object.assign(Object.assign(Object.assign({ abort: false, abortable: false, background: true, cache: true }, up.RenderOptions.NO_INPUT_INTERFERENCE), up.RenderOptions.NO_PREVIEWS), options), { guardEvent, preload: true }));
10055
10518
  }
10056
10519
  function preloadIssue(link) {
10057
10520
  if (!isSafe(link)) {
@@ -10169,7 +10632,7 @@ up.link = (function () {
10169
10632
  return follow(link, forcedOptions, { defaults });
10170
10633
  }
10171
10634
  up.attribute('up-defer', { defaultValue: 'insert' }, function (link, condition) {
10172
- let doLoad = () => up.error.muteUncriticalRejection(loadDeferred(link));
10635
+ let doLoad = (options) => up.error.muteUncriticalRejection(loadDeferred(link, options));
10173
10636
  onLoadCondition(condition, link, doLoad);
10174
10637
  });
10175
10638
  up.on('up:click', config.selectorFn('followSelectors'), function (event, link) {
@@ -10183,15 +10646,16 @@ up.link = (function () {
10183
10646
  let childLink = e.get(area, childLinkSelector);
10184
10647
  if (childLink) {
10185
10648
  e.setMissingAttrs(area, Object.assign({ 'up-href': e.attr(childLink, 'href') }, e.upAttrs(childLink)));
10186
- area.classList.add(...e.upClasses(childLink));
10649
+ e.addClasses(area, e.upClasses(childLink));
10187
10650
  makeFollowable(area);
10188
10651
  }
10189
10652
  });
10190
10653
  up.compiler(config.selectorFn('preloadSelectors'), function (link) {
10191
- var _a;
10192
10654
  if (!isPreloadDisabled(link)) {
10193
- let doPreload = () => up.error.muteUncriticalRejection(preload(link));
10194
- let condition = (_a = e.booleanOrStringAttr(link, 'up-preload', null)) !== null && _a !== void 0 ? _a : 'hover';
10655
+ let doPreload = (options) => up.error.muteUncriticalRejection(preload(link, options));
10656
+ let condition = e.booleanOrStringAttr(link, 'up-preload');
10657
+ if (condition === true || u.isUndefined(condition))
10658
+ condition = 'hover';
10195
10659
  onLoadCondition(condition, link, doPreload);
10196
10660
  }
10197
10661
  });
@@ -10229,10 +10693,11 @@ up.form = (function () {
10229
10693
  const e = up.element;
10230
10694
  const config = new up.Config(() => ({
10231
10695
  groupSelectors: ['[up-form-group]', 'fieldset', 'label', 'form'],
10232
- fieldSelectors: ['select', 'input:not([type=submit]):not([type=image])', 'button[type]:not([type=submit])', 'textarea'],
10696
+ fieldSelectors: ['select', 'input:not([type=submit], [type=image], [type=button])', 'button[type]:not([type=submit], [type=button])', 'textarea'],
10233
10697
  submitSelectors: ['form:is([up-submit], [up-target], [up-layer], [up-transition])'],
10234
10698
  noSubmitSelectors: ['[up-submit=false]', '[target]', e.crossOriginSelector('action')],
10235
10699
  submitButtonSelectors: ['input[type=submit]', 'input[type=image]', 'button[type=submit]', 'button:not([type])'],
10700
+ genericButtonSelectors: ['input[type=button]', 'button[type=button]'],
10236
10701
  watchInputEvents: ['input', 'change'],
10237
10702
  watchInputDelay: 0,
10238
10703
  watchChangeEvents: ['change'],
@@ -10257,6 +10722,9 @@ up.form = (function () {
10257
10722
  function findSubmitButtons(root) {
10258
10723
  return e.subtree(root, submitButtonSelector());
10259
10724
  }
10725
+ function findGenericButtons(root) {
10726
+ return e.subtree(root, config.selector('genericButtonSelectors'));
10727
+ }
10260
10728
  function isSubmitButton(element) {
10261
10729
  return element === null || element === void 0 ? void 0 : element.matches(submitButtonSelector());
10262
10730
  }
@@ -10272,7 +10740,6 @@ up.form = (function () {
10272
10740
  let parser = new up.OptionsParser(form, options, parserOptions);
10273
10741
  parser.include(destinationOptions);
10274
10742
  parser.string('failTarget', { default: up.fragment.tryToTarget(form) });
10275
- parser.booleanOrString('disable');
10276
10743
  options.guardEvent || (options.guardEvent = up.event.build('up:form:submit', {
10277
10744
  submitButton: options.submitButton,
10278
10745
  log: 'Submitting form',
@@ -10280,6 +10747,7 @@ up.form = (function () {
10280
10747
  form,
10281
10748
  }));
10282
10749
  options.origin || (options.origin = up.viewport.focusedElementWithin(form) || options.submitButton || form);
10750
+ options.activeElements = u.uniq([options.origin, options.submitButton, form].filter(u.isElement));
10283
10751
  parser.include(up.link.followOptions);
10284
10752
  return options;
10285
10753
  }
@@ -10287,8 +10755,7 @@ up.form = (function () {
10287
10755
  var _a;
10288
10756
  options = u.options(options);
10289
10757
  let parser = new up.OptionsParser(field, options, Object.assign(Object.assign({}, parserOptions), { closest: true, attrPrefix: 'up-watch-' }));
10290
- parser.boolean('feedback');
10291
- parser.booleanOrString('disable');
10758
+ parser.include(up.status.statusOptions);
10292
10759
  parser.string('event');
10293
10760
  parser.number('delay');
10294
10761
  let config = up.form.config;
@@ -10303,61 +10770,52 @@ up.form = (function () {
10303
10770
  return options;
10304
10771
  }
10305
10772
  function disableContainer(container) {
10306
- let focusedElement = document.activeElement;
10773
+ let controls = [
10774
+ ...findFields(container),
10775
+ ...findSubmitButtons(container),
10776
+ ...findGenericButtons(container),
10777
+ ];
10778
+ return u.sequence(u.map(controls, disableControl));
10779
+ }
10780
+ function disableControl(control) {
10781
+ if (control.disabled)
10782
+ return;
10307
10783
  let focusFallback;
10308
- let controls = [...findFields(container), ...findSubmitButtons(container)];
10309
- for (let control of controls) {
10310
- if (control === focusedElement) {
10311
- focusFallback = findGroup(focusedElement);
10312
- }
10313
- raiseDisableStack(control);
10314
- }
10315
- if (focusFallback) {
10784
+ if (document.activeElement === control) {
10785
+ focusFallback = findGroup(control);
10786
+ control.disabled = true;
10316
10787
  up.focus(focusFallback, { force: true, preventScroll: true });
10317
10788
  }
10318
- return function () {
10319
- controls.forEach(lowerDisableStack);
10320
- };
10321
- }
10322
- function raiseDisableStack(control) {
10323
- if (!control.upDisableCount) {
10324
- control.upDisableCount || (control.upDisableCount = 0);
10325
- control.upOriginalDisabled = control.disabled;
10326
- }
10327
- control.upDisableCount++;
10328
- control.disabled = true;
10329
- }
10330
- function lowerDisableStack(control) {
10331
- if (control.upDisableCount) {
10332
- if (!control.disabled) {
10333
- control.upDisableCount = 0;
10334
- }
10335
- else {
10336
- control.upDisableCount--;
10337
- if (!control.upDisableCount) {
10338
- control.disabled = control.upOriginalDisabled;
10339
- }
10340
- }
10789
+ else {
10790
+ control.disabled = true;
10341
10791
  }
10792
+ return () => { control.disabled = false; };
10342
10793
  }
10343
- function disableWhile(promise, options) {
10344
- let undoDisable = handleDisableOption(options);
10345
- u.always(promise, undoDisable);
10346
- }
10347
- function handleDisableOption({ disable, origin }) {
10348
- if (!disable)
10349
- return u.noop;
10350
- let missingOption = (key) => { up.fail("Cannot process { disable: '%s' } option without { %s }", disable, key); };
10351
- let getOrigin = () => origin || missingOption('origin');
10352
- let getOriginForm = () => getScope(getOrigin());
10353
- let containers;
10794
+ function getDisableContainers(disable, origin) {
10795
+ let originScope = () => getScope(origin);
10354
10796
  if (disable === true) {
10355
- containers = [getOriginForm()];
10797
+ return [originScope()];
10798
+ }
10799
+ else if (u.isElement(disable)) {
10800
+ return [disable];
10356
10801
  }
10357
10802
  else if (u.isString(disable)) {
10358
- containers = up.fragment.subtree(getOriginForm(), disable, { origin });
10803
+ return up.fragment.subtree(originScope(), disable, { origin });
10804
+ }
10805
+ else if (u.isArray(disable)) {
10806
+ return u.flatMap(disable, (d) => getDisableContainers(d, origin));
10359
10807
  }
10360
- return u.sequence(containers.map(disableContainer));
10808
+ else {
10809
+ return [];
10810
+ }
10811
+ }
10812
+ function getDisablePreviewFn(disable, origin) {
10813
+ return function (preview) {
10814
+ let containers = getDisableContainers(disable, origin);
10815
+ for (let container of containers) {
10816
+ preview.disable(container);
10817
+ }
10818
+ };
10361
10819
  }
10362
10820
  function destinationOptions(form, options, parserOptions) {
10363
10821
  var _a;
@@ -10386,10 +10844,10 @@ up.form = (function () {
10386
10844
  }
10387
10845
  return options;
10388
10846
  }
10389
- function watch(root, ...args) {
10847
+ function watch(...args) {
10848
+ let [root, options, callback] = u.args(args, 'val', 'options', 'callback');
10390
10849
  root = up.element.get(root);
10391
- const callback = u.extractCallback(args) || watchCallbackFromElement(root) || up.fail('No callback given for up.watch()');
10392
- let options = u.extractOptions(args);
10850
+ callback || (callback = watchCallbackFromElement(root) || up.fail('No callback given for up.watch()'));
10393
10851
  const watcher = new up.FieldWatcher(root, options, callback);
10394
10852
  watcher.start();
10395
10853
  return () => watcher.stop();
@@ -10397,12 +10855,12 @@ up.form = (function () {
10397
10855
  function watchCallbackFromElement(element) {
10398
10856
  let rawCallback = element.getAttribute('up-watch');
10399
10857
  if (rawCallback) {
10400
- return up.NonceableCallback.fromString(rawCallback).toFunction('value', 'name').bind(element);
10858
+ return up.NonceableCallback.fromString(rawCallback).toFunction('value', 'name', 'options').bind(element);
10401
10859
  }
10402
10860
  }
10403
10861
  function autosubmit(target, options = {}) {
10404
10862
  const onChange = (_diff, renderOptions) => submit(target, renderOptions);
10405
- return watch(target, { options, batch: true }, onChange);
10863
+ return watch(target, Object.assign(Object.assign({}, options), { batch: true }), onChange);
10406
10864
  }
10407
10865
  function getGroupSelectors() {
10408
10866
  var _a, _b;
@@ -10415,10 +10873,10 @@ up.form = (function () {
10415
10873
  return u.findResult(getGroupSelectors(), function (groupSelector) {
10416
10874
  let group = field.closest(groupSelector);
10417
10875
  if (group) {
10418
- let goodDerivedGroupTarget = up.fragment.tryToTarget(group);
10876
+ let strongDerivedGroupTarget = up.fragment.tryToTarget(group, { strong: true });
10419
10877
  let goodDerivedFieldTarget = up.fragment.tryToTarget(field);
10420
10878
  let groupHasFieldTarget = goodDerivedFieldTarget && (group !== field) && `${groupSelector}:has(${goodDerivedFieldTarget})`;
10421
- let target = goodDerivedGroupTarget || groupHasFieldTarget;
10879
+ let target = strongDerivedGroupTarget || groupHasFieldTarget;
10422
10880
  if (target) {
10423
10881
  return {
10424
10882
  target,
@@ -10510,7 +10968,7 @@ up.form = (function () {
10510
10968
  target.classList.add('up-switched');
10511
10969
  });
10512
10970
  function parseSwitchTokens(str) {
10513
- return u.parseTokens(str, { json: true });
10971
+ return u.getSimpleTokens(str, { json: true });
10514
10972
  }
10515
10973
  function findSwitcherForTarget(target) {
10516
10974
  const form = getScope(target);
@@ -10525,8 +10983,13 @@ up.form = (function () {
10525
10983
  const element = up.fragment.get(elementOrSelector, options);
10526
10984
  return element.form || element.closest('form');
10527
10985
  }
10528
- function getScope(element, options) {
10529
- return getForm(element, options) || up.layer.get(element).element;
10986
+ function getScope(origin, options) {
10987
+ if (origin) {
10988
+ return getForm(origin, options) || up.layer.get(origin).element;
10989
+ }
10990
+ else {
10991
+ return up.layer.current.element;
10992
+ }
10530
10993
  }
10531
10994
  function focusedField() {
10532
10995
  return u.presence(document.activeElement, isField);
@@ -10578,8 +11041,8 @@ up.form = (function () {
10578
11041
  submitButtons: findSubmitButtons,
10579
11042
  focusedField,
10580
11043
  switchTarget,
10581
- disableWhile,
10582
11044
  disable: disableContainer,
11045
+ getDisablePreviewFn,
10583
11046
  group: findGroup,
10584
11047
  groupSolution: findGroupSolution,
10585
11048
  groupSelectors: getGroupSelectors,
@@ -10597,22 +11060,24 @@ up.validate = up.form.validate;
10597
11060
  /* 98 */
10598
11061
  /***/ (() => {
10599
11062
 
10600
- up.feedback = (function () {
11063
+ up.status = (function () {
10601
11064
  const u = up.util;
10602
11065
  const e = up.element;
11066
+ let namedPreviewFns = {};
10603
11067
  const config = new up.Config(() => ({
10604
11068
  currentClasses: ['up-current'],
11069
+ activeClasses: ['up-active'],
11070
+ loadingClasses: ['up-loading'],
10605
11071
  navSelectors: ['[up-nav]', 'nav'],
10606
11072
  noNavSelectors: ['[up-nav=false]'],
10607
11073
  }));
10608
11074
  function reset() {
10609
11075
  up.layer.root.feedbackLocation = null;
11076
+ namedPreviewFns = u.pickBy(namedPreviewFns, 'isDefault');
10610
11077
  }
10611
- const CLASS_ACTIVE = 'up-active';
10612
- const CLASS_LOADING = 'up-loading';
10613
11078
  const SELECTOR_LINK = 'a, [up-href]';
10614
- function linkURLs(link) {
10615
- return link.upFeedbackURLs || (link.upFeedbackURLs = new up.LinkFeedbackURLs(link));
11079
+ function linkCurrentURLs(link) {
11080
+ return link.upCurrentURLs || (link.upCurrentURLs = new up.LinkCurrentURLs(link));
10616
11081
  }
10617
11082
  function updateFragment(fragment, { layer } = {}) {
10618
11083
  layer || (layer = up.layer.get(fragment));
@@ -10621,11 +11086,11 @@ up.feedback = (function () {
10621
11086
  const navLinkSelector = `${navSelector} :is(${SELECTOR_LINK}), ${navSelector}:is(${SELECTOR_LINK})`;
10622
11087
  const links = up.fragment.all(navLinkSelector, { layer });
10623
11088
  for (let link of links) {
10624
- const isCurrent = linkURLs(link).isCurrent(layerLocation);
11089
+ const isCurrent = linkCurrentURLs(link).isCurrent(layerLocation);
10625
11090
  for (let currentClass of config.currentClasses) {
10626
11091
  link.classList.toggle(currentClass, isCurrent);
10627
11092
  }
10628
- e.toggleAttr(link, 'aria-current', 'page', isCurrent);
11093
+ e.setAttrPresence(link, 'aria-current', 'page', isCurrent);
10629
11094
  }
10630
11095
  }
10631
11096
  function getMatchableLayerLocation(layer) {
@@ -10634,24 +11099,88 @@ up.feedback = (function () {
10634
11099
  function findActivatableArea(element) {
10635
11100
  return e.ancestor(element, SELECTOR_LINK) || element;
10636
11101
  }
10637
- function showAroundRequest(request, options) {
10638
- if (!options.feedback) {
11102
+ function runPreviews(request, renderOptions) {
11103
+ let { bindLayer } = request;
11104
+ let focusCapsule = up.FocusCapsule.preserve(bindLayer);
11105
+ let applyPreviews = () => doRunPreviews(request, renderOptions);
11106
+ let revertPreviews = bindLayer.asCurrent(applyPreviews);
11107
+ up.on('focusin', { once: true }, () => focusCapsule = null);
11108
+ return () => {
11109
+ bindLayer.asCurrent(revertPreviews);
11110
+ focusCapsule === null || focusCapsule === void 0 ? void 0 : focusCapsule.restore(bindLayer, { preventScroll: true });
11111
+ };
11112
+ }
11113
+ function doRunPreviews(request, renderOptions) {
11114
+ let { fragment, fragments, origin } = request;
11115
+ let cleaner = u.cleaner();
11116
+ let previewForFragment = (fragment) => new up.Preview({ fragment, request, renderOptions, cleaner });
11117
+ let singlePreview = previewForFragment(fragment);
11118
+ singlePreview.run(resolvePreviewFns(renderOptions.preview));
11119
+ singlePreview.run(getPlaceholderPreviewFn(renderOptions.placeholder));
11120
+ singlePreview.run(getFeedbackClassesPreviewFn(renderOptions.feedback, fragments));
11121
+ singlePreview.run(up.form.getDisablePreviewFn(renderOptions.disable, origin));
11122
+ for (let fragment of fragments) {
11123
+ let eachPreview = previewForFragment(fragment);
11124
+ eachPreview.run(e.matchSelectorMap(renderOptions.previewMap, fragment));
11125
+ eachPreview.run(e.matchSelectorMap(renderOptions.placeholderMap, fragment).flatMap(getPlaceholderPreviewFn));
11126
+ }
11127
+ return cleaner.clean;
11128
+ }
11129
+ function getPlaceholderPreviewFn(placeholder) {
11130
+ if (!placeholder)
10639
11131
  return;
11132
+ return function (preview) {
11133
+ preview.showPlaceholder(placeholder);
11134
+ };
11135
+ }
11136
+ function resolvePreviewFns(value) {
11137
+ if (u.isFunction(value)) {
11138
+ return [value];
11139
+ }
11140
+ else if (u.isString(value)) {
11141
+ return resolvePreviewString(value);
10640
11142
  }
10641
- let clean = (fn) => u.always(request, fn);
10642
- let activeElement = getActiveElementFromRenderOptions(request);
10643
- if (activeElement) {
10644
- clean(e.addTemporaryClass(activeElement, CLASS_ACTIVE));
11143
+ else if (u.isArray(value)) {
11144
+ return value.flatMap(resolvePreviewFns);
10645
11145
  }
10646
- for (let fragment of request.fragments) {
10647
- clean(e.addTemporaryClass(fragment, CLASS_LOADING));
11146
+ else {
11147
+ return [];
10648
11148
  }
10649
11149
  }
10650
- function getActiveElementFromRenderOptions(request) {
10651
- let activeElement = request.origin;
10652
- if (activeElement) {
10653
- return findActivatableArea(activeElement);
10654
- }
11150
+ function resolvePreviewString(str) {
11151
+ return u.map(u.parseScalarJSONPairs(str), ([name, parsedOptions]) => {
11152
+ let previewFn = namedPreviewFns[name] || up.fail('Unknown preview "%s"', name);
11153
+ return function (preview, runOptions) {
11154
+ up.puts('[up-preview]', 'Showing preview %o', name);
11155
+ return previewFn(preview, parsedOptions || runOptions);
11156
+ };
11157
+ });
11158
+ }
11159
+ function getActiveElements({ origin, activeElements }) {
11160
+ activeElements || (activeElements = u.wrapList(origin));
11161
+ return activeElements.map(findActivatableArea);
11162
+ }
11163
+ function registerPreview(name, previewFn) {
11164
+ previewFn.isDefault = up.framework.evaling;
11165
+ namedPreviewFns[name] = previewFn;
11166
+ }
11167
+ function getFeedbackClassesPreviewFn(feedbackOption, fragments) {
11168
+ if (!feedbackOption)
11169
+ return;
11170
+ return function (preview) {
11171
+ preview.addClassBatch(getActiveElements(preview.renderOptions), config.activeClasses);
11172
+ preview.addClassBatch(fragments, config.loadingClasses);
11173
+ };
11174
+ }
11175
+ function statusOptions(element, options, parserOptions) {
11176
+ options = u.options(options);
11177
+ const parser = new up.OptionsParser(element, options, parserOptions);
11178
+ parser.booleanOrString('disable');
11179
+ parser.boolean('feedback');
11180
+ parser.string('preview');
11181
+ parser.booleanOrString('revalidatePreview');
11182
+ parser.string('placeholder');
11183
+ return options;
10655
11184
  }
10656
11185
  function updateLayerIfLocationChanged(layer) {
10657
11186
  const processedLocation = layer.feedbackLocation;
@@ -10679,9 +11208,13 @@ up.feedback = (function () {
10679
11208
  up.on('up:framework:reset', reset);
10680
11209
  return {
10681
11210
  config,
10682
- showAroundRequest,
11211
+ preview: registerPreview,
11212
+ resolvePreviewFns,
11213
+ runPreviews,
11214
+ statusOptions,
10683
11215
  };
10684
11216
  })();
11217
+ up.preview = up.status.preview;
10685
11218
 
10686
11219
 
10687
11220
  /***/ }),
@@ -10696,9 +11229,9 @@ up.radio = (function () {
10696
11229
  pollInterval: 30000,
10697
11230
  }));
10698
11231
  function hungrySteps(renderOptions) {
10699
- let { useHungry, origin, layer: renderLayer } = renderOptions;
11232
+ let { hungry, origin, layer: renderLayer, meta } = renderOptions;
10700
11233
  let steps = { current: [], other: [] };
10701
- if (!useHungry)
11234
+ if (!hungry)
10702
11235
  return steps;
10703
11236
  let hungrySelector = config.selector('hungrySelectors');
10704
11237
  const layerPreference = [renderLayer, ...renderLayer.ancestors, ...renderLayer.descendants];
@@ -10715,7 +11248,8 @@ up.radio = (function () {
10715
11248
  let motionOptions = up.motion.motionOptions(element);
10716
11249
  let selectEvent = up.event.build('up:fragment:hungry', { log: false });
10717
11250
  let selectCallback = e.callbackAttr(element, 'up-on-hungry', { exposedKeys: ['newFragment', 'renderOptions'] });
10718
- let step = Object.assign(Object.assign({ selector, oldElement: element, layer: elementLayer, origin }, motionOptions), { placement: 'swap', useKeep: true, maybe: true, selectEvent,
11251
+ let step = Object.assign(Object.assign({ selector, oldElement: element, layer: elementLayer, origin }, motionOptions), { placement: 'swap', keep: true, maybe: true, meta,
11252
+ selectEvent,
10719
11253
  selectCallback, originalRenderOptions: renderOptions });
10720
11254
  if (applicableLayers.includes(renderLayer)) {
10721
11255
  let list = renderLayer === elementLayer ? steps.current : steps.other;
@@ -10738,6 +11272,7 @@ up.radio = (function () {
10738
11272
  parser.number('interval', { default: config.pollInterval });
10739
11273
  parser.string('ifLayer', { default: 'front' });
10740
11274
  parser.include(up.link.requestOptions);
11275
+ parser.include(up.status.statusOptions);
10741
11276
  return options;
10742
11277
  }
10743
11278
  up.attribute('up-poll', function (fragment) {