unpoly-rails 3.0.0.rc2 → 3.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
  /***/ (() => {
6
6
 
7
7
  window.up = {
8
- version: '3.0.0-rc2'
8
+ version: '3.0.0-rc4'
9
9
  };
10
10
 
11
11
 
@@ -111,15 +111,15 @@ up.util = (function () {
111
111
  return block;
112
112
  }
113
113
  }
114
- function map(array, block) {
115
- if (array.length === 0) {
114
+ function map(list, block) {
115
+ if (list.length === 0) {
116
116
  return [];
117
117
  }
118
118
  block = iteratee(block);
119
119
  let mapped = [];
120
- for (let i = 0; i < array.length; i++) {
121
- let element = array[i];
122
- mapped.push(block(element, i));
120
+ let i = 0;
121
+ for (let item of list) {
122
+ mapped.push(block(item, i++));
123
123
  }
124
124
  return mapped;
125
125
  }
@@ -131,8 +131,9 @@ up.util = (function () {
131
131
  return map(array, pairer).reduce(merger, {});
132
132
  }
133
133
  function each(array, block) {
134
- for (let i = 0; i < array.length; i++) {
135
- block(array[i], i);
134
+ let i = 0;
135
+ for (let item of array) {
136
+ block(item, i++);
136
137
  }
137
138
  }
138
139
  function isNull(object) {
@@ -309,10 +310,11 @@ up.util = (function () {
309
310
  function some(list, tester) {
310
311
  return !!findResult(list, tester);
311
312
  }
312
- function findResult(array, tester) {
313
+ function findResult(list, tester) {
313
314
  tester = iteratee(tester);
314
- for (let i = 0; i < array.length; i++) {
315
- const result = tester(array[i], i);
315
+ let i = 0;
316
+ for (let item of list) {
317
+ const result = tester(item, i++);
316
318
  if (result) {
317
319
  return result;
318
320
  }
@@ -321,8 +323,9 @@ up.util = (function () {
321
323
  function every(list, tester) {
322
324
  tester = iteratee(tester);
323
325
  let match = true;
324
- for (let i = 0; i < list.length; i++) {
325
- if (!tester(list[i], i)) {
326
+ let i = 0;
327
+ for (let item of list) {
328
+ if (!tester(item, i++)) {
326
329
  match = false;
327
330
  break;
328
331
  }
@@ -494,7 +497,7 @@ up.util = (function () {
494
497
  function flatMap(array, block) {
495
498
  return flatten(map(array, block));
496
499
  }
497
- function always(promise, callback) {
500
+ function always(promise, callback = identity) {
498
501
  return promise.then(callback, callback);
499
502
  }
500
503
  function newDeferred() {
@@ -596,7 +599,7 @@ up.util = (function () {
596
599
  Object.defineProperty(object, prop, { get });
597
600
  }
598
601
  function defineDelegates(object, props, targetProvider) {
599
- wrapList(props).forEach(function (prop) {
602
+ for (let prop of props) {
600
603
  Object.defineProperty(object, prop, {
601
604
  get() {
602
605
  const target = targetProvider.call(this);
@@ -611,7 +614,7 @@ up.util = (function () {
611
614
  target[prop] = newValue;
612
615
  }
613
616
  });
614
- });
617
+ }
615
618
  }
616
619
  function stringifyArg(arg) {
617
620
  let string;
@@ -706,6 +709,14 @@ up.util = (function () {
706
709
  };
707
710
  }
708
711
  }
712
+ function safeStringifyJSON(value) {
713
+ let json = JSON.stringify(value);
714
+ return escapeHighASCII(json);
715
+ }
716
+ function escapeHighASCII(string) {
717
+ let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0');
718
+ return string.replace(/[^\x00-\x7F]/g, unicodeEscape);
719
+ }
709
720
  return {
710
721
  parseURL,
711
722
  normalizeURL,
@@ -801,7 +812,8 @@ up.util = (function () {
801
812
  sprintf,
802
813
  renameKeys,
803
814
  negate,
804
- memoizeMethod
815
+ memoizeMethod,
816
+ safeStringifyJSON,
805
817
  };
806
818
  })();
807
819
 
@@ -1162,9 +1174,17 @@ up.element = (function () {
1162
1174
  klass = klass.replace(/:/g, '\\:');
1163
1175
  return `.${klass}`;
1164
1176
  }
1165
- function createDocumentFromHTML(html) {
1177
+ function createBrokenDocumentFromHTML(html) {
1166
1178
  return new DOMParser().parseFromString(html, 'text/html');
1167
1179
  }
1180
+ function fixScriptish(scriptish) {
1181
+ let clone = document.createElement(scriptish.tagName);
1182
+ for (let { name, value } of scriptish.attributes) {
1183
+ clone.setAttribute(name, value);
1184
+ }
1185
+ clone.textContent = scriptish.innerHTML;
1186
+ scriptish.replaceWith(clone);
1187
+ }
1168
1188
  function createFromHTML(html) {
1169
1189
  const range = document.createRange();
1170
1190
  range.setStart(document.body, 0);
@@ -1427,7 +1447,8 @@ up.element = (function () {
1427
1447
  isSingleton,
1428
1448
  attrSelector,
1429
1449
  tagName: elementTagName,
1430
- createDocumentFromHTML,
1450
+ createBrokenDocumentFromHTML,
1451
+ fixScriptish,
1431
1452
  createFromHTML,
1432
1453
  get root() { return getRoot(); },
1433
1454
  paint,
@@ -1624,82 +1645,26 @@ up.LogConfig = class LogConfig extends up.Config {
1624
1645
  /***/ (() => {
1625
1646
 
1626
1647
  const u = up.util;
1627
- up.Cache = class Cache {
1628
- constructor(config = {}) {
1629
- this.config = config;
1648
+ up.FIFOCache = class FIFOCache {
1649
+ constructor({ capacity = 10, normalizeKey = u.identity } = {}) {
1630
1650
  this.map = new Map();
1651
+ this.capacity = capacity;
1652
+ this.normalizeKey = normalizeKey;
1631
1653
  }
1632
- size() {
1633
- return this.map.size;
1634
- }
1635
- maxSize() {
1636
- return u.evalOption(this.config.size);
1637
- }
1638
- evictAge() {
1639
- return u.evalOption(this.config.evictAge);
1640
- }
1641
- normalizeStoreKey(key) {
1642
- return key;
1643
- }
1644
- isDisabled() {
1645
- return this.maxSize() === 0 || this.evictAge() === 0;
1646
- }
1647
- evict() {
1648
- this.map.clear();
1649
- }
1650
- records() {
1651
- return this.map.values();
1652
- }
1653
- makeRoomForAnotherRecord() {
1654
- const maxSize = this.maxSize();
1655
- const currentSize = this.size();
1656
- if (!maxSize || currentSize < maxSize)
1657
- return;
1658
- let records = Array.from(this.records());
1659
- records.sort((a, b) => b.createdAt - a.createdAt);
1660
- const overflow = currentSize - maxSize + 1;
1661
- for (let i = 0; i < overflow; i++) {
1662
- let key = records.pop().key;
1663
- this.map.delete(key);
1664
- }
1665
- }
1666
- alias(oldKey, newKey) {
1667
- const value = this.get(oldKey);
1668
- if (u.isDefined(value)) {
1669
- this.set(newKey, value);
1670
- }
1654
+ get(key) {
1655
+ key = this.normalizeKey(key);
1656
+ return this.map.get(key);
1671
1657
  }
1672
1658
  set(key, value) {
1673
- if (this.isDisabled())
1674
- return;
1675
- this.makeRoomForAnotherRecord();
1676
- key = this.normalizeStoreKey(key);
1677
- const createdAt = new Date();
1678
- const record = { key, value, createdAt };
1679
- this.map.set(key, record);
1680
- }
1681
- remove(key) {
1682
- key = this.normalizeStoreKey(key);
1683
- this.map.delete(key);
1684
- }
1685
- isUsable(record) {
1686
- const evictAge = this.evictAge();
1687
- if (!evictAge)
1688
- return true;
1689
- const age = new Date() - record.createdAt;
1690
- return age < evictAge;
1691
- }
1692
- get(key) {
1693
- const storeKey = this.normalizeStoreKey(key);
1694
- let record = this.map.get(storeKey);
1695
- if (record) {
1696
- if (this.isUsable(record)) {
1697
- return record.value;
1698
- }
1699
- else {
1700
- this.remove(key);
1701
- }
1659
+ if (this.map.size === this.capacity) {
1660
+ let oldestKey = this.map.keys().next().value;
1661
+ this.map.delete(oldestKey);
1702
1662
  }
1663
+ key = this.normalizeKey(key);
1664
+ this.map.set(key, value);
1665
+ }
1666
+ clear() {
1667
+ this.map.clear();
1703
1668
  }
1704
1669
  };
1705
1670
 
@@ -4161,44 +4126,6 @@ up.FragmentScrolling = class FragmentScrolling extends up.FragmentProcessor {
4161
4126
  /* 47 */
4162
4127
  /***/ (() => {
4163
4128
 
4164
- const u = up.util;
4165
- const e = up.element;
4166
- up.HTMLWrapper = class HTMLWrapper {
4167
- constructor(tagName) {
4168
- this.tagName = tagName;
4169
- const openTag = `<${this.tagName}[^>]*>`;
4170
- const closeTag = `</${this.tagName}>`;
4171
- const innerHTML = "(.|\\s)*?";
4172
- this.pattern = new RegExp(openTag + innerHTML + closeTag, 'ig');
4173
- this.attrName = `up-wrapped-${this.tagName}`;
4174
- }
4175
- strip(html) {
4176
- return html.replace(this.pattern, '');
4177
- }
4178
- wrap(html) {
4179
- return html.replace(this.pattern, this.wrapMatch.bind(this));
4180
- }
4181
- wrapMatch(match) {
4182
- this.didWrap = true;
4183
- return '<meta name="' + this.attrName + '" value="' + u.escapeHTML(match) + '">';
4184
- }
4185
- unwrap(element) {
4186
- if (!this.didWrap) {
4187
- return;
4188
- }
4189
- for (let wrappedChild of element.querySelectorAll(`meta[name='${this.attrName}']`)) {
4190
- const originalHTML = wrappedChild.getAttribute('value');
4191
- const restoredElement = e.createFromHTML(originalHTML);
4192
- wrappedChild.replaceWith(restoredElement);
4193
- }
4194
- }
4195
- };
4196
-
4197
-
4198
- /***/ }),
4199
- /* 48 */
4200
- /***/ (() => {
4201
-
4202
4129
  const e = up.element;
4203
4130
  const u = up.util;
4204
4131
  up.Layer = class Layer extends up.Record {
@@ -4412,11 +4339,14 @@ up.Layer = class Layer extends up.Record {
4412
4339
  let focusedElement = document.activeElement;
4413
4340
  return focusedElement !== document.body && this.element.contains(focusedElement);
4414
4341
  }
4342
+ reset() {
4343
+ Object.assign(this, this.defaults());
4344
+ }
4415
4345
  };
4416
4346
 
4417
4347
 
4418
4348
  /***/ }),
4419
- /* 49 */
4349
+ /* 48 */
4420
4350
  /***/ (() => {
4421
4351
 
4422
4352
  const e = up.element;
@@ -4696,7 +4626,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4696
4626
 
4697
4627
 
4698
4628
  /***/ }),
4699
- /* 50 */
4629
+ /* 49 */
4700
4630
  /***/ (() => {
4701
4631
 
4702
4632
  up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
@@ -4733,7 +4663,7 @@ up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
4733
4663
 
4734
4664
 
4735
4665
  /***/ }),
4736
- /* 51 */
4666
+ /* 50 */
4737
4667
  /***/ (() => {
4738
4668
 
4739
4669
  var _a;
@@ -4771,7 +4701,7 @@ up.Layer.OverlayWithViewport = (_a = class OverlayWithViewport extends up.Layer.
4771
4701
 
4772
4702
 
4773
4703
  /***/ }),
4774
- /* 52 */
4704
+ /* 51 */
4775
4705
  /***/ (() => {
4776
4706
 
4777
4707
  var _a;
@@ -4808,9 +4738,6 @@ up.Layer.Root = (_a = class Root extends up.Layer {
4808
4738
  cannotCloseRoot() {
4809
4739
  up.fail('Cannot close the root layer');
4810
4740
  }
4811
- reset() {
4812
- Object.assign(this, this.defaults());
4813
- }
4814
4741
  toString() {
4815
4742
  return "root layer";
4816
4743
  }
@@ -4820,7 +4747,7 @@ up.Layer.Root = (_a = class Root extends up.Layer {
4820
4747
 
4821
4748
 
4822
4749
  /***/ }),
4823
- /* 53 */
4750
+ /* 52 */
4824
4751
  /***/ (() => {
4825
4752
 
4826
4753
  var _a;
@@ -4831,7 +4758,7 @@ up.Layer.Modal = (_a = class Modal extends up.Layer.OverlayWithViewport {
4831
4758
 
4832
4759
 
4833
4760
  /***/ }),
4834
- /* 54 */
4761
+ /* 53 */
4835
4762
  /***/ (() => {
4836
4763
 
4837
4764
  var _a;
@@ -4842,7 +4769,7 @@ up.Layer.Popup = (_a = class Popup extends up.Layer.OverlayWithTether {
4842
4769
 
4843
4770
 
4844
4771
  /***/ }),
4845
- /* 55 */
4772
+ /* 54 */
4846
4773
  /***/ (() => {
4847
4774
 
4848
4775
  var _a;
@@ -4853,7 +4780,7 @@ up.Layer.Drawer = (_a = class Drawer extends up.Layer.OverlayWithViewport {
4853
4780
 
4854
4781
 
4855
4782
  /***/ }),
4856
- /* 56 */
4783
+ /* 55 */
4857
4784
  /***/ (() => {
4858
4785
 
4859
4786
  var _a;
@@ -4864,7 +4791,7 @@ up.Layer.Cover = (_a = class Cover extends up.Layer.OverlayWithViewport {
4864
4791
 
4865
4792
 
4866
4793
  /***/ }),
4867
- /* 57 */
4794
+ /* 56 */
4868
4795
  /***/ (() => {
4869
4796
 
4870
4797
  const u = up.util;
@@ -4954,7 +4881,7 @@ up.LayerLookup = class LayerLookup {
4954
4881
 
4955
4882
 
4956
4883
  /***/ }),
4957
- /* 58 */
4884
+ /* 57 */
4958
4885
  /***/ (() => {
4959
4886
 
4960
4887
  const u = up.util;
@@ -5067,7 +4994,7 @@ up.LayerStack = class LayerStack extends Array {
5067
4994
 
5068
4995
 
5069
4996
  /***/ }),
5070
- /* 59 */
4997
+ /* 58 */
5071
4998
  /***/ (() => {
5072
4999
 
5073
5000
  up.LinkFeedbackURLs = class LinkFeedbackURLs {
@@ -5098,7 +5025,7 @@ up.LinkFeedbackURLs = class LinkFeedbackURLs {
5098
5025
 
5099
5026
 
5100
5027
  /***/ }),
5101
- /* 60 */
5028
+ /* 59 */
5102
5029
  /***/ (() => {
5103
5030
 
5104
5031
  const u = up.util;
@@ -5168,7 +5095,7 @@ up.LinkPreloader = class LinkPreloader {
5168
5095
 
5169
5096
 
5170
5097
  /***/ }),
5171
- /* 61 */
5098
+ /* 60 */
5172
5099
  /***/ (function() {
5173
5100
 
5174
5101
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -5277,7 +5204,7 @@ up.MotionController = class MotionController {
5277
5204
 
5278
5205
 
5279
5206
  /***/ }),
5280
- /* 62 */
5207
+ /* 61 */
5281
5208
  /***/ (() => {
5282
5209
 
5283
5210
  const u = up.util;
@@ -5369,7 +5296,7 @@ up.NonceableCallback = class NonceableCallback {
5369
5296
 
5370
5297
 
5371
5298
  /***/ }),
5372
- /* 63 */
5299
+ /* 62 */
5373
5300
  /***/ (() => {
5374
5301
 
5375
5302
  const u = up.util;
@@ -5447,7 +5374,7 @@ up.OptionsParser = class OptionsParser {
5447
5374
 
5448
5375
 
5449
5376
  /***/ }),
5450
- /* 64 */
5377
+ /* 63 */
5451
5378
  /***/ (() => {
5452
5379
 
5453
5380
  const e = up.element;
@@ -5515,7 +5442,7 @@ up.OverlayFocus = class OverlayFocus {
5515
5442
 
5516
5443
 
5517
5444
  /***/ }),
5518
- /* 65 */
5445
+ /* 64 */
5519
5446
  /***/ (() => {
5520
5447
 
5521
5448
  const u = up.util;
@@ -5746,7 +5673,7 @@ up.Params = class Params {
5746
5673
 
5747
5674
 
5748
5675
  /***/ }),
5749
- /* 66 */
5676
+ /* 65 */
5750
5677
  /***/ (() => {
5751
5678
 
5752
5679
  const e = up.element;
@@ -5796,7 +5723,7 @@ up.ProgressBar = class ProgressBar {
5796
5723
 
5797
5724
 
5798
5725
  /***/ }),
5799
- /* 67 */
5726
+ /* 66 */
5800
5727
  /***/ (() => {
5801
5728
 
5802
5729
  const u = up.util;
@@ -5913,7 +5840,7 @@ up.RenderOptions = (function () {
5913
5840
 
5914
5841
 
5915
5842
  /***/ }),
5916
- /* 68 */
5843
+ /* 67 */
5917
5844
  /***/ (() => {
5918
5845
 
5919
5846
  up.RenderResult = class RenderResult extends up.Record {
@@ -5941,7 +5868,7 @@ up.RenderResult = class RenderResult extends up.Record {
5941
5868
 
5942
5869
 
5943
5870
  /***/ }),
5944
- /* 69 */
5871
+ /* 68 */
5945
5872
  /***/ (() => {
5946
5873
 
5947
5874
  var _a;
@@ -5954,7 +5881,7 @@ up.Request = (_a = class Request extends up.Record {
5954
5881
  if (this.wrapMethod == null) {
5955
5882
  this.wrapMethod = up.network.config.wrapMethod;
5956
5883
  }
5957
- this.normalizeForCaching();
5884
+ this.normalize();
5958
5885
  if ((this.target || this.layer || this.origin) && !options.basic) {
5959
5886
  const layerLookupOptions = { origin: this.origin };
5960
5887
  this.layer = up.layer.get(this.layer, layerLookupOptions);
@@ -5966,6 +5893,7 @@ up.Request = (_a = class Request extends up.Record {
5966
5893
  }
5967
5894
  this.deferred = u.newDeferred();
5968
5895
  (_a = this.badResponseTime) !== null && _a !== void 0 ? _a : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5896
+ this.addAutoHeaders();
5969
5897
  }
5970
5898
  keys() {
5971
5899
  return [
@@ -5977,7 +5905,6 @@ up.Request = (_a = class Request extends up.Record {
5977
5905
  'failTarget',
5978
5906
  'headers',
5979
5907
  'timeout',
5980
- 'preload',
5981
5908
  'background',
5982
5909
  'cache',
5983
5910
  'expireCache',
@@ -5990,11 +5917,12 @@ up.Request = (_a = class Request extends up.Record {
5990
5917
  'failContext',
5991
5918
  'origin',
5992
5919
  'fragments',
5993
- 'queuedAt',
5920
+ 'builtAt',
5994
5921
  'wrapMethod',
5995
5922
  'contentType',
5996
5923
  'payload',
5997
5924
  'onQueued',
5925
+ 'onLoading',
5998
5926
  'fail',
5999
5927
  'abortable',
6000
5928
  'badResponseTime',
@@ -6005,7 +5933,8 @@ up.Request = (_a = class Request extends up.Record {
6005
5933
  state: 'new',
6006
5934
  abortable: true,
6007
5935
  headers: {},
6008
- timeout: up.network.config.timeout
5936
+ timeout: up.network.config.timeout,
5937
+ builtAt: new Date(),
6009
5938
  };
6010
5939
  }
6011
5940
  get xhr() {
@@ -6028,10 +5957,7 @@ up.Request = (_a = class Request extends up.Record {
6028
5957
  var _a;
6029
5958
  return (_a = this.fragments) === null || _a === void 0 ? void 0 : _a[0];
6030
5959
  }
6031
- followState(sourceRequest) {
6032
- u.delegate(this, ['deferred', 'state', 'preload', 'expired'], () => sourceRequest);
6033
- }
6034
- normalizeForCaching() {
5960
+ normalize() {
6035
5961
  this.method = u.normalizeMethod(this.method);
6036
5962
  this.extractHashFromURL();
6037
5963
  this.transferParamsToURL();
@@ -6078,16 +6004,29 @@ up.Request = (_a = class Request extends up.Record {
6078
6004
  (_a = this.onQueued) === null || _a === void 0 ? void 0 : _a.call(this, this);
6079
6005
  }
6080
6006
  load() {
6007
+ var _a;
6081
6008
  if (this.state !== 'new')
6082
6009
  return;
6083
- this.state = 'loading';
6084
- this.expired = false;
6085
- new up.Request.XHRRenderer(this).buildAndSend({
6086
- onload: () => this.onXHRLoad(),
6087
- onerror: () => this.onXHRError(),
6088
- ontimeout: () => this.onXHRTimeout(),
6089
- onabort: () => this.onXHRAbort()
6090
- });
6010
+ if (this.emitLoad()) {
6011
+ this.state = 'loading';
6012
+ this.normalize();
6013
+ (_a = this.onLoading) === null || _a === void 0 ? void 0 : _a.call(this);
6014
+ this.expired = false;
6015
+ new up.Request.XHRRenderer(this).buildAndSend({
6016
+ onload: () => this.onXHRLoad(),
6017
+ onerror: () => this.onXHRError(),
6018
+ ontimeout: () => this.onXHRTimeout(),
6019
+ onabort: () => this.onXHRAbort()
6020
+ });
6021
+ return true;
6022
+ }
6023
+ else {
6024
+ this.abort({ reason: 'Prevented by event listener' });
6025
+ }
6026
+ }
6027
+ emitLoad() {
6028
+ let event = this.emit('up:request:load', { log: ['Loading %s', this.description] });
6029
+ return !event.defaultPrevented;
6091
6030
  }
6092
6031
  loadPage() {
6093
6032
  up.network.abort();
@@ -6131,18 +6070,19 @@ up.Request = (_a = class Request extends up.Record {
6131
6070
  this.emit('up:request:offline', { log: message });
6132
6071
  }
6133
6072
  respondWith(response) {
6134
- if (this.state !== 'loading')
6073
+ this.response = response;
6074
+ if (this.isSettled())
6135
6075
  return;
6136
6076
  this.state = 'loaded';
6137
6077
  if (response.ok) {
6138
- return this.deferred.resolve(response);
6078
+ this.deferred.resolve(response);
6139
6079
  }
6140
6080
  else {
6141
- return this.deferred.reject(response);
6081
+ this.deferred.reject(response);
6142
6082
  }
6143
6083
  }
6144
6084
  isSettled() {
6145
- return (this.state !== 'new') && (this.state !== 'loading');
6085
+ return (this.state !== 'new') && (this.state !== 'loading') && (this.state !== 'tracking');
6146
6086
  }
6147
6087
  csrfHeader() {
6148
6088
  return up.protocol.csrfHeader();
@@ -6189,24 +6129,6 @@ up.Request = (_a = class Request extends up.Record {
6189
6129
  }
6190
6130
  return new up.Response(responseAttrs);
6191
6131
  }
6192
- cacheKey() {
6193
- return JSON.stringify([
6194
- this.method,
6195
- this.url,
6196
- this.params.toQuery(),
6197
- this.metaProps()
6198
- ]);
6199
- }
6200
- metaProps() {
6201
- const props = {};
6202
- for (let key of u.evalOption(up.network.config.requestMetaKeys, this)) {
6203
- const value = this[key];
6204
- if (u.isGiven(value)) {
6205
- props[key] = value;
6206
- }
6207
- }
6208
- return props;
6209
- }
6210
6132
  buildEventEmitter(args) {
6211
6133
  return up.EventEmitter.fromEmitArgs(args, {
6212
6134
  layer: this.layer,
@@ -6232,9 +6154,30 @@ up.Request = (_a = class Request extends up.Record {
6232
6154
  return u.some(subtreeElements, (subtreeElement) => subtreeElement.contains(fragment));
6233
6155
  });
6234
6156
  }
6235
- get queueAge() {
6236
- const now = new Date();
6237
- return now - this.queuedAt;
6157
+ get age() {
6158
+ return new Date() - this.builtAt;
6159
+ }
6160
+ header(name) {
6161
+ return this.headers[name];
6162
+ }
6163
+ addAutoHeaders() {
6164
+ for (let key of ['target', 'failTarget', 'mode', 'failMode', 'context', 'failContext']) {
6165
+ this.addAutoHeader(up.protocol.headerize(key), this[key]);
6166
+ }
6167
+ let csrfHeader, csrfToken;
6168
+ if ((csrfHeader = this.csrfHeader()) && (csrfToken = this.csrfToken())) {
6169
+ this.addAutoHeader(csrfHeader, csrfToken);
6170
+ }
6171
+ this.addAutoHeader(up.protocol.headerize('version'), up.version);
6172
+ }
6173
+ addAutoHeader(name, value) {
6174
+ if (u.isMissing(value)) {
6175
+ return;
6176
+ }
6177
+ if (u.isOptions(value) || u.isArray(value)) {
6178
+ value = u.safeStringifyJSON(value);
6179
+ }
6180
+ this.headers[name] = value;
6238
6181
  }
6239
6182
  static tester(condition, { except } = {}) {
6240
6183
  let testFn;
@@ -6252,8 +6195,7 @@ up.Request = (_a = class Request extends up.Record {
6252
6195
  testFn = (_request) => condition;
6253
6196
  }
6254
6197
  if (except) {
6255
- let exceptCacheKey = except.cacheKey();
6256
- return (request) => (request.cacheKey() !== exceptCacheKey) && testFn(request);
6198
+ return (request) => !up.cache.willHaveSameResponse(request, except) && testFn(request);
6257
6199
  }
6258
6200
  else {
6259
6201
  return testFn;
@@ -6267,39 +6209,160 @@ up.Request = (_a = class Request extends up.Record {
6267
6209
 
6268
6210
 
6269
6211
  /***/ }),
6270
- /* 70 */
6271
- /***/ (() => {
6212
+ /* 69 */
6213
+ /***/ (function() {
6272
6214
 
6273
- let u = up.util;
6274
- up.Request.Cache = class Cache extends up.Cache {
6275
- maxSize() {
6215
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6216
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6217
+ return new (P || (P = Promise))(function (resolve, reject) {
6218
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6219
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6220
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
6221
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
6222
+ });
6223
+ };
6224
+ const u = up.util;
6225
+ up.Request.Cache = class Cache {
6226
+ constructor() {
6227
+ this.reset();
6228
+ }
6229
+ reset() {
6230
+ this.varyInfo = {};
6231
+ this.map = new Map();
6232
+ }
6233
+ cacheKey(request) {
6234
+ let influencingHeaders = this.getPreviousInfluencingHeaders(request);
6235
+ let varyPart = u.flatMap(influencingHeaders, (headerName) => [headerName, request.header(headerName)]);
6236
+ return [request.description, ...varyPart].join(':');
6237
+ }
6238
+ getPreviousInfluencingHeaders(request) {
6239
+ var _a, _b;
6240
+ return ((_a = this.varyInfo)[_b = request.description] || (_a[_b] = new Set()));
6241
+ }
6242
+ get(request) {
6243
+ request = this.wrap(request);
6244
+ let cacheKey = this.cacheKey(request);
6245
+ let cachedRequest = this.map.get(cacheKey);
6246
+ if (cachedRequest) {
6247
+ if (this.isUsable(cachedRequest)) {
6248
+ return cachedRequest;
6249
+ }
6250
+ else {
6251
+ this.map.delete(cacheKey);
6252
+ }
6253
+ }
6254
+ }
6255
+ get capacity() {
6276
6256
  return up.network.config.cacheSize;
6277
6257
  }
6278
- evictAge() {
6279
- return up.network.config.cacheEvictAge;
6258
+ isUsable(request) {
6259
+ return request.age < up.network.config.cacheEvictAge;
6280
6260
  }
6281
- normalizeStoreKey(request) {
6282
- return u.wrapValue(up.Request, request).cacheKey();
6261
+ put(request) {
6262
+ return __awaiter(this, void 0, void 0, function* () {
6263
+ request = this.wrap(request);
6264
+ this.makeRoom();
6265
+ let cacheKey = this.updateCacheKey(request);
6266
+ this.map.set(cacheKey, request);
6267
+ });
6268
+ }
6269
+ updateCacheKey(request) {
6270
+ let oldCacheKey = this.cacheKey(request);
6271
+ let { response } = request;
6272
+ if (response) {
6273
+ this.mergePreviousHeaderNames(request, response);
6274
+ let newCacheKey = this.cacheKey(request);
6275
+ this.renameMapKey(oldCacheKey, newCacheKey);
6276
+ return newCacheKey;
6277
+ }
6278
+ else {
6279
+ return oldCacheKey;
6280
+ }
6281
+ }
6282
+ renameMapKey(oldKey, newKey) {
6283
+ if (oldKey !== newKey && this.map.has(oldKey)) {
6284
+ this.map.set(newKey, this.map.get(oldKey));
6285
+ this.map.delete(oldKey);
6286
+ }
6287
+ }
6288
+ mergePreviousHeaderNames(request, response) {
6289
+ let headersInfluencingResponse = response.ownInfluncingHeaders;
6290
+ if (headersInfluencingResponse.length) {
6291
+ let previousInfluencingHeaders = this.getPreviousInfluencingHeaders(request);
6292
+ for (let headerName of headersInfluencingResponse) {
6293
+ previousInfluencingHeaders.add(headerName);
6294
+ }
6295
+ }
6296
+ }
6297
+ alias(existingCachedRequest, newRequest) {
6298
+ existingCachedRequest = this.get(existingCachedRequest);
6299
+ if (!existingCachedRequest)
6300
+ return;
6301
+ newRequest = this.wrap(newRequest);
6302
+ this.track(existingCachedRequest, newRequest, { force: true });
6303
+ this.put(newRequest);
6304
+ return newRequest;
6305
+ }
6306
+ track(existingRequest, newRequest, options = {}) {
6307
+ var _a;
6308
+ return __awaiter(this, void 0, void 0, function* () {
6309
+ newRequest.trackedRequest = existingRequest;
6310
+ newRequest.state = 'tracking';
6311
+ let value = yield u.always(existingRequest);
6312
+ if (value instanceof up.Response) {
6313
+ if (options.force || this.isCacheCompatible(existingRequest, newRequest)) {
6314
+ newRequest.fromCache = true;
6315
+ newRequest.respondWith(value);
6316
+ u.delegate(newRequest, ['expired', 'state'], () => existingRequest);
6317
+ }
6318
+ else {
6319
+ delete newRequest.trackedRequest;
6320
+ newRequest.state = 'new';
6321
+ (_a = options.onIncompatible) === null || _a === void 0 ? void 0 : _a.call(options, newRequest);
6322
+ }
6323
+ }
6324
+ else {
6325
+ newRequest.state = existingRequest.state;
6326
+ newRequest.deferred.reject(value);
6327
+ }
6328
+ });
6329
+ }
6330
+ willHaveSameResponse(existingRequest, newRequest) {
6331
+ return existingRequest === newRequest || existingRequest === newRequest.trackedRequest;
6332
+ }
6333
+ delete(request) {
6334
+ request = this.wrap(request);
6335
+ let cacheKey = this.cacheKey(request);
6336
+ this.map.delete(cacheKey);
6283
6337
  }
6284
6338
  evict(condition = true, testerOptions) {
6285
- this.eachMatch(condition, testerOptions, ({ key }) => this.map.delete(key));
6339
+ this.eachMatch(condition, testerOptions, (request) => this.delete(request));
6286
6340
  }
6287
6341
  expire(condition = true, testerOptions) {
6288
- this.eachMatch(condition, testerOptions, ({ value: request }) => request.expired = true);
6342
+ this.eachMatch(condition, testerOptions, (request) => request.expired = true);
6343
+ }
6344
+ makeRoom() {
6345
+ while (this.map.size >= this.capacity) {
6346
+ let oldestKey = this.map.keys().next().value;
6347
+ this.map.delete(oldestKey);
6348
+ }
6289
6349
  }
6290
6350
  eachMatch(condition = true, testerOptions, fn) {
6291
6351
  let tester = up.Request.tester(condition, testerOptions);
6292
- for (let record of this.records()) {
6293
- if (tester(record.value)) {
6294
- fn(record);
6295
- }
6296
- }
6352
+ let results = u.filter(this.map.values(), tester);
6353
+ u.each(results, fn);
6354
+ }
6355
+ isCacheCompatible(request1, request2) {
6356
+ return this.cacheKey(request1) === this.cacheKey(request2);
6357
+ }
6358
+ wrap(requestOrOptions) {
6359
+ return u.wrapValue(up.Request, requestOrOptions);
6297
6360
  }
6298
6361
  };
6299
6362
 
6300
6363
 
6301
6364
  /***/ }),
6302
- /* 71 */
6365
+ /* 70 */
6303
6366
  /***/ (() => {
6304
6367
 
6305
6368
  const u = up.util;
@@ -6318,7 +6381,6 @@ up.Request.Queue = class Queue {
6318
6381
  asap(request) {
6319
6382
  request.runQueuedCallbacks();
6320
6383
  u.always(request, responseOrError => this.onRequestSettled(request, responseOrError));
6321
- request.queuedAt = new Date();
6322
6384
  this.scheduleSlowTimer(request);
6323
6385
  this.queueRequest(request);
6324
6386
  u.microtask(() => this.poke());
@@ -6330,7 +6392,7 @@ up.Request.Queue = class Queue {
6330
6392
  }
6331
6393
  }
6332
6394
  scheduleSlowTimer(request) {
6333
- let timeUntilLate = Math.max(request.badResponseTime - request.queueAge, 0);
6395
+ let timeUntilLate = Math.max(request.badResponseTime - request.age, 0);
6334
6396
  u.timer(timeUntilLate, () => this.checkLate());
6335
6397
  }
6336
6398
  getMaxConcurrency() {
@@ -6352,13 +6414,8 @@ up.Request.Queue = class Queue {
6352
6414
  return u.remove(this.queuedRequests, request);
6353
6415
  }
6354
6416
  sendRequestNow(request) {
6355
- if (request.emit('up:request:load', { log: ['Loading %s %s', request.method, request.url] }).defaultPrevented) {
6356
- request.abort({ reason: 'Prevented by event listener' });
6357
- }
6358
- else {
6359
- request.normalizeForCaching();
6417
+ if (request.load()) {
6360
6418
  this.currentRequests.push(request);
6361
- request.load();
6362
6419
  }
6363
6420
  }
6364
6421
  onRequestSettled(request, responseOrError) {
@@ -6408,13 +6465,13 @@ up.Request.Queue = class Queue {
6408
6465
  isLate() {
6409
6466
  const allForegroundRequests = u.reject(this.allRequests, 'background');
6410
6467
  const timerTolerance = 1;
6411
- return u.some(allForegroundRequests, request => request.queueAge >= (request.badResponseTime - timerTolerance));
6468
+ return u.some(allForegroundRequests, (request) => request.age >= (request.badResponseTime - timerTolerance));
6412
6469
  }
6413
6470
  };
6414
6471
 
6415
6472
 
6416
6473
  /***/ }),
6417
- /* 72 */
6474
+ /* 71 */
6418
6475
  /***/ (() => {
6419
6476
 
6420
6477
  const u = up.util;
@@ -6453,7 +6510,7 @@ up.Request.FormRenderer = class FormRenderer {
6453
6510
 
6454
6511
 
6455
6512
  /***/ }),
6456
- /* 73 */
6513
+ /* 72 */
6457
6514
  /***/ (() => {
6458
6515
 
6459
6516
  var _a;
@@ -6471,21 +6528,13 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6471
6528
  xhr.timeout = this.request.timeout;
6472
6529
  }
6473
6530
  xhr.open(this.getMethod(), this.request.url);
6474
- const metaProps = this.request.metaProps();
6475
- for (let key in metaProps) {
6476
- this.addHeader(xhr, up.protocol.headerize(key), metaProps[key]);
6477
- }
6478
- for (let header in this.request.headers) {
6479
- this.addHeader(xhr, header, this.request.headers[header]);
6480
- }
6481
- let csrfHeader, csrfToken;
6482
- if ((csrfHeader = this.request.csrfHeader()) && (csrfToken = this.request.csrfToken())) {
6483
- this.addHeader(xhr, csrfHeader, csrfToken);
6484
- }
6485
- this.addHeader(xhr, up.protocol.headerize('version'), up.version);
6486
6531
  let contentType = this.getContentType();
6487
6532
  if (contentType) {
6488
- this.addHeader(xhr, 'Content-Type', contentType);
6533
+ xhr.setRequestHeader('Content-Type', contentType);
6534
+ }
6535
+ for (let headerName in this.request.headers) {
6536
+ let headerValue = this.request.headers[headerName];
6537
+ xhr.setRequestHeader(headerName, headerValue);
6489
6538
  }
6490
6539
  Object.assign(xhr, handlers);
6491
6540
  xhr.send(this.getPayload());
@@ -6507,12 +6556,6 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6507
6556
  this.finalizePayload();
6508
6557
  return this.payload;
6509
6558
  }
6510
- addHeader(xhr, header, value) {
6511
- if (u.isOptions(value) || u.isArray(value)) {
6512
- value = JSON.stringify(value);
6513
- }
6514
- xhr.setRequestHeader(header, value);
6515
- }
6516
6559
  finalizePayload() {
6517
6560
  this.payload = this.request.payload;
6518
6561
  this.contentType = this.request.contentType;
@@ -6539,7 +6582,7 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6539
6582
 
6540
6583
 
6541
6584
  /***/ }),
6542
- /* 74 */
6585
+ /* 73 */
6543
6586
  /***/ (() => {
6544
6587
 
6545
6588
  const u = up.util;
@@ -6579,6 +6622,10 @@ up.Response = class Response extends up.Record {
6579
6622
  var _a;
6580
6623
  return this.headers[name] || ((_a = this.xhr) === null || _a === void 0 ? void 0 : _a.getResponseHeader(name));
6581
6624
  }
6625
+ get ownInfluncingHeaders() {
6626
+ let influencingHeaders = up.protocol.influencingHeadersFromResponse(this);
6627
+ return u.filter(influencingHeaders, (headerName) => this.request.header(headerName));
6628
+ }
6582
6629
  get contentType() {
6583
6630
  return this.header('Content-Type');
6584
6631
  }
@@ -6612,7 +6659,7 @@ up.Response = class Response extends up.Record {
6612
6659
 
6613
6660
 
6614
6661
  /***/ }),
6615
- /* 75 */
6662
+ /* 74 */
6616
6663
  /***/ (() => {
6617
6664
 
6618
6665
  var _a;
@@ -6620,12 +6667,13 @@ const u = up.util;
6620
6667
  const e = up.element;
6621
6668
  up.ResponseDoc = (_a = class ResponseDoc {
6622
6669
  constructor(options) {
6623
- this.noscriptWrapper = new up.HTMLWrapper('noscript');
6624
- this.scriptWrapper = new up.HTMLWrapper('script');
6625
6670
  this.root =
6626
6671
  this.parseDocument(options) ||
6627
6672
  this.parseFragment(options) ||
6628
6673
  this.parseContent(options);
6674
+ if (!up.fragment.config.runScripts) {
6675
+ this.root.querySelectorAll('script').forEach((e) => e.remove());
6676
+ }
6629
6677
  this.cspNonces = options.cspNonces;
6630
6678
  if (options.origin) {
6631
6679
  let originSelector = up.fragment.tryToTarget(options.origin);
@@ -6635,7 +6683,11 @@ up.ResponseDoc = (_a = class ResponseDoc {
6635
6683
  }
6636
6684
  }
6637
6685
  parseDocument(options) {
6638
- return this.parse(options.document, e.createDocumentFromHTML);
6686
+ let document = this.parse(options.document, e.createBrokenDocumentFromHTML);
6687
+ if (document) {
6688
+ this.scriptishNeedFix = true;
6689
+ return document;
6690
+ }
6639
6691
  }
6640
6692
  parseContent(options) {
6641
6693
  let content = options.content || '';
@@ -6643,7 +6695,6 @@ up.ResponseDoc = (_a = class ResponseDoc {
6643
6695
  target = u.map(up.fragment.parseTargetSteps(target), 'selector').join(',');
6644
6696
  const matchingElement = e.createFromSelector(target);
6645
6697
  if (u.isString(content)) {
6646
- content = this.wrapHTML(content);
6647
6698
  matchingElement.innerHTML = content;
6648
6699
  }
6649
6700
  else {
@@ -6656,7 +6707,6 @@ up.ResponseDoc = (_a = class ResponseDoc {
6656
6707
  }
6657
6708
  parse(value, parseFn = e.createFromHTML) {
6658
6709
  if (u.isString(value)) {
6659
- value = this.wrapHTML(value);
6660
6710
  value = parseFn(value);
6661
6711
  }
6662
6712
  return value;
@@ -6664,19 +6714,9 @@ up.ResponseDoc = (_a = class ResponseDoc {
6664
6714
  rootSelector() {
6665
6715
  return up.fragment.toTarget(this.root);
6666
6716
  }
6667
- wrapHTML(html) {
6668
- html = this.noscriptWrapper.wrap(html);
6669
- if (up.fragment.config.runScripts) {
6670
- html = this.scriptWrapper.wrap(html);
6671
- }
6672
- else {
6673
- html = this.scriptWrapper.strip(html);
6674
- }
6675
- return html;
6676
- }
6677
6717
  getTitle() {
6678
6718
  var _a;
6679
- return (_a = this.root.querySelector("head title")) === null || _a === void 0 ? void 0 : _a.textContent;
6719
+ return (_a = this.root.querySelector('head title')) === null || _a === void 0 ? void 0 : _a.textContent;
6680
6720
  }
6681
6721
  select(selector) {
6682
6722
  let finder = new up.FragmentFinder({
@@ -6687,9 +6727,10 @@ up.ResponseDoc = (_a = class ResponseDoc {
6687
6727
  return finder.find();
6688
6728
  }
6689
6729
  finalizeElement(element) {
6690
- this.noscriptWrapper.unwrap(element);
6691
6730
  up.NonceableCallback.adoptNonces(element, this.cspNonces);
6692
- this.scriptWrapper.unwrap(element);
6731
+ if (this.scriptishNeedFix) {
6732
+ element.querySelectorAll('noscript, script').forEach(e.fixScriptish);
6733
+ }
6693
6734
  }
6694
6735
  },
6695
6736
  (() => {
@@ -6699,7 +6740,7 @@ up.ResponseDoc = (_a = class ResponseDoc {
6699
6740
 
6700
6741
 
6701
6742
  /***/ }),
6702
- /* 76 */
6743
+ /* 75 */
6703
6744
  /***/ (() => {
6704
6745
 
6705
6746
  const e = up.element;
@@ -6794,7 +6835,7 @@ up.RevealMotion = class RevealMotion {
6794
6835
 
6795
6836
 
6796
6837
  /***/ }),
6797
- /* 77 */
6838
+ /* 76 */
6798
6839
  /***/ (() => {
6799
6840
 
6800
6841
  const u = up.util;
@@ -6835,7 +6876,7 @@ up.Selector = class Selector {
6835
6876
 
6836
6877
 
6837
6878
  /***/ }),
6838
- /* 78 */
6879
+ /* 77 */
6839
6880
  /***/ (() => {
6840
6881
 
6841
6882
  const u = up.util;
@@ -6956,7 +6997,7 @@ up.Tether = class Tether {
6956
6997
 
6957
6998
 
6958
6999
  /***/ }),
6959
- /* 79 */
7000
+ /* 78 */
6960
7001
  /***/ (() => {
6961
7002
 
6962
7003
  const u = up.util;
@@ -7037,7 +7078,7 @@ up.URLPattern = class URLPattern {
7037
7078
 
7038
7079
 
7039
7080
  /***/ }),
7040
- /* 80 */
7081
+ /* 79 */
7041
7082
  /***/ (() => {
7042
7083
 
7043
7084
  up.framework = (function () {
@@ -7121,7 +7162,7 @@ up.boot = up.framework.boot;
7121
7162
 
7122
7163
 
7123
7164
  /***/ }),
7124
- /* 81 */
7165
+ /* 80 */
7125
7166
  /***/ (() => {
7126
7167
 
7127
7168
  up.event = (function () {
@@ -7224,7 +7265,7 @@ up.emit = up.event.emit;
7224
7265
 
7225
7266
 
7226
7267
  /***/ }),
7227
- /* 82 */
7268
+ /* 81 */
7228
7269
  /***/ (() => {
7229
7270
 
7230
7271
  up.protocol = (function () {
@@ -7240,6 +7281,9 @@ up.protocol = (function () {
7240
7281
  return parseFn(value);
7241
7282
  }
7242
7283
  };
7284
+ function targetFromXHR(xhr) {
7285
+ return extractHeader(xhr, 'target');
7286
+ }
7243
7287
  function parseModifyCacheValue(value) {
7244
7288
  if (value === 'false') {
7245
7289
  return false;
@@ -7261,6 +7305,10 @@ up.protocol = (function () {
7261
7305
  function methodFromXHR(xhr) {
7262
7306
  return extractHeader(xhr, 'method', u.normalizeMethod);
7263
7307
  }
7308
+ function titleFromXHR(xhr) {
7309
+ var _a, _b, _c;
7310
+ 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);
7311
+ }
7264
7312
  function eventPlansFromXHR(xhr) {
7265
7313
  return extractHeader(xhr, 'events', JSON.parse);
7266
7314
  }
@@ -7276,11 +7324,9 @@ up.protocol = (function () {
7276
7324
  function locationFromXHR(xhr) {
7277
7325
  return extractHeader(xhr, 'location') || xhr.responseURL;
7278
7326
  }
7279
- function titleFromXHR(xhr) {
7280
- return extractHeader(xhr, 'title');
7281
- }
7282
- function targetFromXHR(xhr) {
7283
- return extractHeader(xhr, 'target');
7327
+ function influencingHeadersFromResponse(response) {
7328
+ let varyHeaderValue = response.header('Vary');
7329
+ return u.parseTokens(varyHeaderValue, { separator: 'comma' });
7284
7330
  }
7285
7331
  const config = new up.Config(() => ({
7286
7332
  methodParam: '_method',
@@ -7356,12 +7402,13 @@ up.protocol = (function () {
7356
7402
  headerize,
7357
7403
  wrapMethod,
7358
7404
  cspNoncesFromHeader,
7405
+ influencingHeadersFromResponse,
7359
7406
  };
7360
7407
  })();
7361
7408
 
7362
7409
 
7363
7410
  /***/ }),
7364
- /* 83 */
7411
+ /* 82 */
7365
7412
  /***/ (() => {
7366
7413
 
7367
7414
  up.log = (function () {
@@ -7447,7 +7494,7 @@ up.warn = up.log.warn;
7447
7494
 
7448
7495
 
7449
7496
  /***/ }),
7450
- /* 84 */
7497
+ /* 83 */
7451
7498
  /***/ (() => {
7452
7499
 
7453
7500
  up.syntax = (function () {
@@ -7593,7 +7640,7 @@ up.hello = up.syntax.hello;
7593
7640
 
7594
7641
 
7595
7642
  /***/ }),
7596
- /* 85 */
7643
+ /* 84 */
7597
7644
  /***/ (() => {
7598
7645
 
7599
7646
  up.history = (function () {
@@ -7663,7 +7710,7 @@ up.history = (function () {
7663
7710
  }
7664
7711
  function restoreStateOnPop(state) {
7665
7712
  if (!(state === null || state === void 0 ? void 0 : state.up)) {
7666
- up.puts('pop', 'Ignoring a history state not owned by Unpoly');
7713
+ up.puts('popstate', 'Ignoring a history state not owned by Unpoly');
7667
7714
  return;
7668
7715
  }
7669
7716
  let location = currentLocation();
@@ -7730,10 +7777,10 @@ up.history = (function () {
7730
7777
 
7731
7778
 
7732
7779
  /***/ }),
7733
- /* 86 */
7780
+ /* 85 */
7734
7781
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
7735
7782
 
7736
- __webpack_require__(87);
7783
+ __webpack_require__(86);
7737
7784
  const u = up.util;
7738
7785
  const e = up.element;
7739
7786
  up.fragment = (function () {
@@ -7784,7 +7831,7 @@ up.fragment = (function () {
7784
7831
  autoRevalidate: (response) => response.expired,
7785
7832
  skipResponse: defaultSkipResponse
7786
7833
  }));
7787
- u.delegate(config, 'mainTargets', () => up.layer.config.any);
7834
+ u.delegate(config, ['mainTargets'], () => up.layer.config.any);
7788
7835
  function reset() {
7789
7836
  config.reset();
7790
7837
  }
@@ -8251,20 +8298,20 @@ up.destroy = up.fragment.destroy;
8251
8298
  up.render = up.fragment.render;
8252
8299
  up.navigate = up.fragment.navigate;
8253
8300
  up.visit = up.fragment.visit;
8254
- u.delegate(up, 'context', () => up.layer.current);
8301
+ u.delegate(up, ['context'], () => up.layer.current);
8255
8302
 
8256
8303
 
8257
8304
  /***/ }),
8258
- /* 87 */
8305
+ /* 86 */
8259
8306
  /***/ (() => {
8260
8307
 
8261
8308
 
8262
8309
 
8263
8310
  /***/ }),
8264
- /* 88 */
8311
+ /* 87 */
8265
8312
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8266
8313
 
8267
- __webpack_require__(89);
8314
+ __webpack_require__(88);
8268
8315
  up.viewport = (function () {
8269
8316
  const u = up.util;
8270
8317
  const e = up.element;
@@ -8447,7 +8494,7 @@ up.viewport = (function () {
8447
8494
  }
8448
8495
  }
8449
8496
  function newStateCache() {
8450
- return new up.Cache({ size: 30, key: up.history.normalizeURL });
8497
+ return new up.FIFOCache({ capacity: 30, normalizeKey: up.history.normalizeURL });
8451
8498
  }
8452
8499
  function parseOptions(args) {
8453
8500
  const options = u.copy(u.extractOptions(args));
@@ -8586,13 +8633,13 @@ up.reveal = up.viewport.reveal;
8586
8633
 
8587
8634
 
8588
8635
  /***/ }),
8589
- /* 89 */
8636
+ /* 88 */
8590
8637
  /***/ (() => {
8591
8638
 
8592
8639
 
8593
8640
 
8594
8641
  /***/ }),
8595
- /* 90 */
8642
+ /* 89 */
8596
8643
  /***/ (function() {
8597
8644
 
8598
8645
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -8858,10 +8905,10 @@ up.animate = up.motion.animate;
8858
8905
 
8859
8906
 
8860
8907
  /***/ }),
8861
- /* 91 */
8908
+ /* 90 */
8862
8909
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8863
8910
 
8864
- __webpack_require__(92);
8911
+ __webpack_require__(91);
8865
8912
  const u = up.util;
8866
8913
  up.network = (function () {
8867
8914
  const config = new up.Config(() => ({
@@ -8877,7 +8924,6 @@ up.network = (function () {
8877
8924
  autoCache(request) { return request.isSafe(); },
8878
8925
  expireCache(request, _response) { return !request.isSafe(); },
8879
8926
  evictCache: false,
8880
- requestMetaKeys: ['target', 'failTarget', 'mode', 'failMode', 'context', 'failContext'],
8881
8927
  progressBar: true,
8882
8928
  timeout: 90000,
8883
8929
  }));
@@ -8888,14 +8934,14 @@ up.network = (function () {
8888
8934
  abortRequests();
8889
8935
  queue.reset();
8890
8936
  config.reset();
8891
- cache.evict();
8937
+ cache.reset();
8892
8938
  progressBar === null || progressBar === void 0 ? void 0 : progressBar.destroy();
8893
8939
  progressBar = null;
8894
8940
  }
8895
8941
  function makeRequest(...args) {
8896
8942
  const options = parseRequestOptions(args);
8897
8943
  const request = new up.Request(options);
8898
- useCachedRequest(request) || queueRequest(request);
8944
+ processRequest(request);
8899
8945
  return request;
8900
8946
  }
8901
8947
  function parseRequestOptions(args) {
@@ -8907,31 +8953,31 @@ up.network = (function () {
8907
8953
  (_b = (_a = up.migrate).handleRequestOptions) === null || _b === void 0 ? void 0 : _b.call(_a, options);
8908
8954
  return options;
8909
8955
  }
8910
- function useCachedRequest(request) {
8956
+ function processRequest(request) {
8957
+ useCachedRequest(request) || queueRequest(request);
8958
+ }
8959
+ function useCachedRequest(newRequest) {
8911
8960
  let cachedRequest;
8912
- if (request.willCache() && (cachedRequest = cache.get(request))) {
8913
- up.puts('up.request()', 'Re-using previous request to %s %s', request.method, request.url);
8914
- if (!request.preload) {
8961
+ if (newRequest.willCache() && (cachedRequest = cache.get(newRequest))) {
8962
+ up.puts('up.request()', 'Re-using previous request to %s', newRequest.description);
8963
+ if (!newRequest.background) {
8915
8964
  queue.promoteToForeground(cachedRequest);
8916
8965
  }
8917
- request.followState(cachedRequest);
8918
- request.fromCache = true;
8966
+ cache.track(cachedRequest, newRequest, { onIncompatible: processRequest });
8919
8967
  return true;
8920
8968
  }
8921
8969
  }
8922
8970
  function queueRequest(request) {
8923
- if (request.preload && !request.isSafe()) {
8924
- up.fail('Will not preload request to %s', request.description);
8925
- }
8926
8971
  handleCaching(request);
8927
8972
  queue.asap(request);
8928
8973
  return true;
8929
8974
  }
8930
8975
  function handleCaching(request) {
8931
8976
  if (request.willCache()) {
8932
- cache.set(request, request);
8977
+ cache.put(request);
8978
+ request.onLoading = () => cache.put(request);
8933
8979
  }
8934
- return u.always(request, function (response) {
8980
+ u.always(request, function (response) {
8935
8981
  var _a, _b, _c, _d;
8936
8982
  let expireCache = (_b = (_a = response.expireCache) !== null && _a !== void 0 ? _a : request.expireCache) !== null && _b !== void 0 ? _b : u.evalOption(config.expireCache, request, response);
8937
8983
  if (expireCache) {
@@ -8942,7 +8988,7 @@ up.network = (function () {
8942
8988
  cache.evict(evictCache, { except: request });
8943
8989
  }
8944
8990
  if (cache.get(request)) {
8945
- cache.set(request, request);
8991
+ cache.put(request);
8946
8992
  }
8947
8993
  if (!response.ok) {
8948
8994
  cache.evict(request);
@@ -9008,13 +9054,13 @@ up.cache = up.network.cache;
9008
9054
 
9009
9055
 
9010
9056
  /***/ }),
9011
- /* 92 */
9057
+ /* 91 */
9012
9058
  /***/ (() => {
9013
9059
 
9014
9060
 
9015
9061
 
9016
9062
  /***/ }),
9017
- /* 93 */
9063
+ /* 92 */
9018
9064
  /***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
9019
9065
 
9020
9066
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -9026,7 +9072,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9026
9072
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9027
9073
  });
9028
9074
  };
9029
- __webpack_require__(94);
9075
+ __webpack_require__(93);
9030
9076
  const u = up.util;
9031
9077
  const e = up.element;
9032
9078
  up.layer = (function () {
@@ -9267,16 +9313,16 @@ up.layer = (function () {
9267
9313
 
9268
9314
 
9269
9315
  /***/ }),
9270
- /* 94 */
9316
+ /* 93 */
9271
9317
  /***/ (() => {
9272
9318
 
9273
9319
 
9274
9320
 
9275
9321
  /***/ }),
9276
- /* 95 */
9322
+ /* 94 */
9277
9323
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
9278
9324
 
9279
- __webpack_require__(96);
9325
+ __webpack_require__(95);
9280
9326
  up.link = (function () {
9281
9327
  const u = up.util;
9282
9328
  const e = up.element;
@@ -9425,16 +9471,22 @@ up.link = (function () {
9425
9471
  }
9426
9472
  function preload(link, options) {
9427
9473
  link = up.fragment.get(link);
9428
- if (!shouldPreload()) {
9429
- return Promise.reject(new up.Error('Link preloading is disabled'));
9474
+ let issue = preloadIssue(link);
9475
+ if (issue) {
9476
+ return Promise.reject(new up.Error(issue));
9430
9477
  }
9431
9478
  const guardEvent = up.event.build('up:link:preload', { log: ['Preloading link %o', link] });
9432
9479
  return follow(link, Object.assign(Object.assign({ abortable: false }, options), { guardEvent, preload: true }));
9433
9480
  }
9434
- function shouldPreload() {
9435
- let goodConnection = u.negate(up.network.shouldReduceRequests);
9436
- return u.evalAutoOption(config.preloadEnabled, goodConnection);
9481
+ function preloadIssue(link) {
9482
+ if (!u.evalAutoOption(config.preloadEnabled, autoPreloadEnabled, link)) {
9483
+ return 'Preloading is disabled';
9484
+ }
9485
+ else if (!isSafe(link)) {
9486
+ return 'Will not preload an unsafe link';
9487
+ }
9437
9488
  }
9489
+ const autoPreloadEnabled = u.negate(up.network.shouldReduceRequests);
9438
9490
  function followMethod(link, options = {}) {
9439
9491
  return u.normalizeMethod(options.method || link.getAttribute('up-method') || link.getAttribute('data-method'));
9440
9492
  }
@@ -9561,13 +9613,13 @@ up.follow = up.link.follow;
9561
9613
 
9562
9614
 
9563
9615
  /***/ }),
9564
- /* 96 */
9616
+ /* 95 */
9565
9617
  /***/ (() => {
9566
9618
 
9567
9619
 
9568
9620
 
9569
9621
  /***/ }),
9570
- /* 97 */
9622
+ /* 96 */
9571
9623
  /***/ (() => {
9572
9624
 
9573
9625
  up.form = (function () {
@@ -9967,7 +10019,7 @@ up.validate = up.form.validate;
9967
10019
 
9968
10020
 
9969
10021
  /***/ }),
9970
- /* 98 */
10022
+ /* 97 */
9971
10023
  /***/ (() => {
9972
10024
 
9973
10025
  up.feedback = (function () {
@@ -10084,7 +10136,7 @@ up.feedback = (function () {
10084
10136
 
10085
10137
 
10086
10138
  /***/ }),
10087
- /* 99 */
10139
+ /* 98 */
10088
10140
  /***/ (() => {
10089
10141
 
10090
10142
  up.radio = (function () {
@@ -10162,7 +10214,7 @@ up.radio = (function () {
10162
10214
 
10163
10215
 
10164
10216
  /***/ }),
10165
- /* 100 */
10217
+ /* 99 */
10166
10218
  /***/ (() => {
10167
10219
 
10168
10220
  (function () {
@@ -10300,16 +10352,15 @@ __webpack_require__(82);
10300
10352
  __webpack_require__(83);
10301
10353
  __webpack_require__(84);
10302
10354
  __webpack_require__(85);
10303
- __webpack_require__(86);
10304
- __webpack_require__(88);
10355
+ __webpack_require__(87);
10356
+ __webpack_require__(89);
10305
10357
  __webpack_require__(90);
10306
- __webpack_require__(91);
10307
- __webpack_require__(93);
10308
- __webpack_require__(95);
10358
+ __webpack_require__(92);
10359
+ __webpack_require__(94);
10360
+ __webpack_require__(96);
10309
10361
  __webpack_require__(97);
10310
10362
  __webpack_require__(98);
10311
10363
  __webpack_require__(99);
10312
- __webpack_require__(100);
10313
10364
  up.framework.onEvaled();
10314
10365
 
10315
10366
  })();