aberdeen 1.10.2 → 1.11.1

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.
Files changed (77) hide show
  1. package/dist/src/aberdeen.d.ts +7 -6
  2. package/dist/src/aberdeen.js +116 -36
  3. package/dist/src/aberdeen.js.map +3 -3
  4. package/dist/src/aberdeen.min.js +8 -8
  5. package/dist/src/aberdeen.min.js.map +3 -3
  6. package/dist-docs/Tutorial/index.html +9 -5
  7. package/dist-docs/aberdeen/A/index.html +2 -2
  8. package/dist-docs/aberdeen/NO_COPY/index.html +2 -2
  9. package/dist-docs/aberdeen/PromiseProxy/index.html +5 -5
  10. package/dist-docs/aberdeen/clean/index.html +2 -2
  11. package/dist-docs/aberdeen/clone/index.html +2 -2
  12. package/dist-docs/aberdeen/copy/index.html +3 -3
  13. package/dist-docs/aberdeen/count/index.html +4 -4
  14. package/dist-docs/aberdeen/cssVars/index.html +2 -2
  15. package/dist-docs/aberdeen/darkMode/index.html +2 -2
  16. package/dist-docs/aberdeen/default/index.html +8 -8
  17. package/dist-docs/aberdeen/derive/index.html +2 -2
  18. package/dist-docs/aberdeen/disableCreateDestroy/index.html +2 -2
  19. package/dist-docs/aberdeen/dump/index.html +2 -2
  20. package/dist-docs/aberdeen/index.html +5 -5
  21. package/dist-docs/aberdeen/insertCss/index.html +2 -2
  22. package/dist-docs/aberdeen/insertGlobalCss/index.html +2 -2
  23. package/dist-docs/aberdeen/invertString/index.html +2 -2
  24. package/dist-docs/aberdeen/isEmpty/index.html +4 -4
  25. package/dist-docs/aberdeen/map/index.html +4 -4
  26. package/dist-docs/aberdeen/merge/index.html +3 -3
  27. package/dist-docs/aberdeen/mount/index.html +2 -2
  28. package/dist-docs/aberdeen/multiMap/index.html +4 -4
  29. package/dist-docs/aberdeen/onEach/index.html +8 -5
  30. package/dist-docs/aberdeen/partition/index.html +4 -4
  31. package/dist-docs/aberdeen/peek/index.html +5 -5
  32. package/dist-docs/aberdeen/proxy/index.html +7 -4
  33. package/dist-docs/aberdeen/ref/index.html +2 -2
  34. package/dist-docs/aberdeen/runQueue/index.html +2 -2
  35. package/dist-docs/aberdeen/setErrorHandler/index.html +2 -2
  36. package/dist-docs/aberdeen/setSpacingCssVars/index.html +2 -2
  37. package/dist-docs/aberdeen/unmountAll/index.html +2 -2
  38. package/dist-docs/aberdeen/unproxy/index.html +2 -2
  39. package/dist-docs/assets/aberdeen/aberdeen.d.ts +7 -6
  40. package/dist-docs/assets/aberdeen/aberdeen.js +116 -36
  41. package/dist-docs/assets/aberdeen/aberdeen.js.map +3 -3
  42. package/dist-docs/assets/aberdeen/aberdeen.min.js +8 -8
  43. package/dist-docs/assets/aberdeen/aberdeen.min.js.map +3 -3
  44. package/dist-docs/assets/search.js +1 -1
  45. package/dist-docs/dispatcher/Dispatcher/index.html +4 -4
  46. package/dist-docs/dispatcher/MATCH_FAILED/index.html +2 -2
  47. package/dist-docs/dispatcher/MATCH_REST/index.html +2 -2
  48. package/dist-docs/dispatcher/index.html +2 -2
  49. package/dist-docs/hierarchy.html +1 -1
  50. package/dist-docs/index.html +2 -2
  51. package/dist-docs/media/CHANGELOG.md +20 -0
  52. package/dist-docs/modules.html +1 -1
  53. package/dist-docs/prediction/applyCanon/index.html +2 -2
  54. package/dist-docs/prediction/applyPrediction/index.html +2 -2
  55. package/dist-docs/prediction/index.html +2 -2
  56. package/dist-docs/route/Route/index.html +9 -9
  57. package/dist-docs/route/back/index.html +2 -2
  58. package/dist-docs/route/current/index.html +2 -2
  59. package/dist-docs/route/go/index.html +2 -2
  60. package/dist-docs/route/index.html +2 -2
  61. package/dist-docs/route/interceptLinks/index.html +2 -2
  62. package/dist-docs/route/persistScroll/index.html +2 -2
  63. package/dist-docs/route/push/index.html +2 -2
  64. package/dist-docs/route/setLog/index.html +2 -2
  65. package/dist-docs/route/up/index.html +2 -2
  66. package/dist-docs/sitemap.xml +56 -56
  67. package/dist-docs/transitions/grow/index.html +2 -2
  68. package/dist-docs/transitions/index.html +2 -2
  69. package/dist-docs/transitions/shrink/index.html +2 -2
  70. package/package.json +2 -2
  71. package/skill/SKILL.md +21 -3
  72. package/skill/aberdeen.md +152 -76
  73. package/skill/dispatcher.md +6 -6
  74. package/skill/prediction.md +3 -3
  75. package/skill/route.md +17 -17
  76. package/skill/transitions.md +3 -3
  77. package/src/aberdeen.ts +168 -71
@@ -59,12 +59,13 @@ export declare function runQueue(): void;
59
59
  */
60
60
  export declare function invertString(input: string): string;
61
61
  export declare function onEach<K, T>(target: Map<K, undefined | T>, render: (value: T, key: K) => void, makeKey?: (value: T, key: K) => SortKeyType): void;
62
+ export declare function onEach<T>(target: Set<T>, render: (value: T) => void, makeKey?: (value: T) => SortKeyType): void;
62
63
  export declare function onEach<T>(target: ReadonlyArray<undefined | T>, render: (value: T, index: number) => void, makeKey?: (value: T, index: number) => SortKeyType): void;
63
64
  export declare function onEach<K extends string | number | symbol, T>(target: Record<K, undefined | T>, render: (value: T, index: KeyToString<K>) => void, makeKey?: (value: T, index: KeyToString<K>) => SortKeyType): void;
64
65
  /** @private */
65
66
  export declare const EMPTY: unique symbol;
66
67
  /**
67
- * Reactively checks if an observable array or object is empty.
68
+ * Reactively checks if an observable array, object, Map, or Set is empty.
68
69
  *
69
70
  * This function not only returns the current emptiness state but also establishes
70
71
  * a reactive dependency. If the emptiness state of the `proxied` object or array
@@ -72,8 +73,8 @@ export declare const EMPTY: unique symbol;
72
73
  * is deleted from an object), the scope that called `isEmpty` will be automatically
73
74
  * scheduled for re-evaluation.
74
75
  *
75
- * @param proxied The observable array or object to check.
76
- * @returns `true` if the array has length 0 or the object has no own enumerable properties, `false` otherwise.
76
+ * @param proxied The observable array, object, Map, or Set to check.
77
+ * @returns `true` if the array has length 0, the Map/Set has size 0, or the object has no own enumerable properties, `false` otherwise.
77
78
  *
78
79
  * @example
79
80
  * ```typescript
@@ -101,10 +102,10 @@ export interface ValueRef<T> {
101
102
  value: T;
102
103
  }
103
104
  /**
104
- * Reactively counts the number of properties in an objects.
105
+ * Reactively counts the number of properties in an object.
105
106
  *
106
- * @param proxied The observable object to count. In case an `array` is passed in, a {@link ref} to its `.length` will be returned.
107
- * @returns an observable object for which the `value` property reflects the number of properties in `proxied` with a value other than `undefined`.
107
+ * @param proxied The observable object to count. In case an `array`, `Map`, or `Set` is passed in, a {@link ref} to its `.length` or `.size` will be returned.
108
+ * @returns an observable object for which the `value` property reflects the number of properties in `proxied` with a value other than `undefined`, or the collection size for arrays, Maps, and Sets.
108
109
  *
109
110
  * @example
110
111
  * ```typescript
@@ -130,18 +130,26 @@ function runQueue() {
130
130
  if (time > 9)
131
131
  console.debug(`Aberdeen queue took ${time}ms`);
132
132
  }
133
- function partToStr(part) {
134
- if (typeof part === "string") {
135
- return `${part}\x01`;
136
- }
133
+ function arrayToStr(parts) {
137
134
  let result = "";
138
- let num = Math.abs(Math.round(part));
139
- const negative = part < 0;
140
- while (num > 0) {
141
- result = String.fromCharCode(negative ? 65534 - num % 65533 : 2 + num % 65533) + result;
142
- num = Math.floor(num / 65533);
135
+ for (const part of parts) {
136
+ if (typeof part === "string") {
137
+ result += `${part}\x01`;
138
+ continue;
139
+ }
140
+ if (typeof part !== "number") {
141
+ throw new Error("onEach() sort key must be a string, number or an array of such");
142
+ }
143
+ let digits = "";
144
+ let num = Math.abs(Math.round(part));
145
+ const negative = part < 0;
146
+ while (num > 0) {
147
+ digits = String.fromCharCode(negative ? 65534 - num % 65533 : 2 + num % 65533) + digits;
148
+ num = Math.floor(num / 65533);
149
+ }
150
+ result += String.fromCharCode(128 + (negative ? -digits.length : digits.length)) + digits;
143
151
  }
144
- return String.fromCharCode(128 + (negative ? -result.length : result.length)) + result;
152
+ return result;
145
153
  }
146
154
  function invertString(input) {
147
155
  let result = "";
@@ -403,7 +411,7 @@ class OnEachScope extends Scope {
403
411
  new OnEachItemScope(this, i, false);
404
412
  }
405
413
  } else {
406
- for (const key of target instanceof Map ? target.keys() : Object.keys(target)) {
414
+ for (const key of target instanceof Map ? target.keys() : target instanceof Set ? target.values() : Object.keys(target)) {
407
415
  new OnEachItemScope(this, key, false);
408
416
  }
409
417
  }
@@ -430,7 +438,7 @@ class OnEachScope extends Scope {
430
438
  const oldScope = this.byIndex.get(index);
431
439
  if (oldScope)
432
440
  oldScope.remove();
433
- if (this.target instanceof Map ? this.target.has(index) : (index in this.target)) {
441
+ if (this.target instanceof Set || this.target instanceof Map ? this.target.has(index) : (index in this.target)) {
434
442
  new OnEachItemScope(this, index, true);
435
443
  } else {
436
444
  this.byIndex.delete(index);
@@ -516,7 +524,9 @@ class OnEachItemScope extends ContentScope {
516
524
  let value;
517
525
  const target = this.parent.target;
518
526
  let itemIndex = this.itemIndex;
519
- if (target instanceof Map) {
527
+ if (target instanceof Set) {
528
+ value = itemIndex = optProxy(itemIndex);
529
+ } else if (target instanceof Map) {
520
530
  value = optProxy(target.get(itemIndex));
521
531
  itemIndex = optProxy(itemIndex);
522
532
  } else {
@@ -527,14 +537,14 @@ class OnEachItemScope extends ContentScope {
527
537
  let sortKey;
528
538
  try {
529
539
  if (this.parent.makeSortKey) {
530
- const rawSortKey = this.parent.makeSortKey(value, itemIndex);
531
- if (rawSortKey != null)
532
- sortKey = rawSortKey instanceof Array ? rawSortKey.map(partToStr).join("") : rawSortKey;
540
+ sortKey = this.parent.makeSortKey(value, itemIndex);
533
541
  } else {
534
542
  sortKey = itemIndex;
535
543
  }
536
- if (typeof sortKey === "number")
537
- sortKey = partToStr(sortKey);
544
+ if (sortKey instanceof Array)
545
+ sortKey = arrayToStr(sortKey);
546
+ else if (typeof sortKey !== "string" && sortKey != null)
547
+ sortKey = arrayToStr([sortKey]);
538
548
  if (this.sortKey !== sortKey) {
539
549
  this.parent.sortedSet.remove(this);
540
550
  this.sortKey = sortKey;
@@ -632,7 +642,7 @@ function isEmpty(proxied) {
632
642
  });
633
643
  return !target.length;
634
644
  }
635
- if (target instanceof Map) {
645
+ if (target instanceof Map || target instanceof Set) {
636
646
  subscribe(target, MAP_SIZE_SYMBOL, (index, newData, oldData) => {
637
647
  if (!newData !== !oldData)
638
648
  scope.onChange(target, EMPTY, !newData, !oldData);
@@ -652,7 +662,7 @@ function isEmpty(proxied) {
652
662
  function count(proxied) {
653
663
  if (proxied instanceof Array)
654
664
  return ref(proxied, "length");
655
- if (proxied instanceof Map)
665
+ if (proxied instanceof Map || proxied instanceof Set)
656
666
  return ref(proxied, "size");
657
667
  const target = proxied[TARGET_SYMBOL] || proxied;
658
668
  let cnt = 0;
@@ -807,22 +817,20 @@ function wrapIteratorPair(iterator) {
807
817
  }
808
818
  };
809
819
  }
820
+ function unproxyCollectionValue(value) {
821
+ return typeof value === "object" && value ? value[TARGET_SYMBOL] || value : value;
822
+ }
810
823
  var mapMethodHandlers = {
811
824
  get(key) {
812
825
  const target = this[TARGET_SYMBOL];
813
- if (typeof key === "object" && key)
814
- key = key[TARGET_SYMBOL] || key;
826
+ key = unproxyCollectionValue(key);
815
827
  subscribe(target, key);
816
828
  return optProxy(target.get(key));
817
829
  },
818
830
  set(key, newData) {
819
831
  const target = this[TARGET_SYMBOL];
820
- if (typeof key === "object" && key) {
821
- key = key[TARGET_SYMBOL] || key;
822
- }
823
- if (typeof newData === "object" && newData) {
824
- newData = newData[TARGET_SYMBOL] || newData;
825
- }
832
+ key = unproxyCollectionValue(key);
833
+ newData = unproxyCollectionValue(newData);
826
834
  let oldData = target.get(key);
827
835
  if (oldData === undefined && !target.has(key))
828
836
  oldData = EMPTY;
@@ -836,9 +844,7 @@ var mapMethodHandlers = {
836
844
  },
837
845
  delete(key) {
838
846
  const target = this[TARGET_SYMBOL];
839
- if (typeof key === "object" && key) {
840
- key = key[TARGET_SYMBOL] || key;
841
- }
847
+ key = unproxyCollectionValue(key);
842
848
  let oldData = target.get(key);
843
849
  if (oldData === undefined && !target.has(key))
844
850
  oldData = EMPTY;
@@ -860,9 +866,7 @@ var mapMethodHandlers = {
860
866
  },
861
867
  has(key) {
862
868
  const target = this[TARGET_SYMBOL];
863
- if (typeof key === "object" && key) {
864
- key = key[TARGET_SYMBOL] || key;
865
- }
869
+ key = unproxyCollectionValue(key);
866
870
  subscribe(target, key);
867
871
  return target.has(key);
868
872
  },
@@ -887,6 +891,66 @@ var mapMethodHandlers = {
887
891
  return wrapIteratorPair(target[Symbol.iterator]());
888
892
  }
889
893
  };
894
+ var setMethodHandlers = {
895
+ add(value) {
896
+ const target = this[TARGET_SYMBOL];
897
+ value = unproxyCollectionValue(value);
898
+ if (!target.has(value)) {
899
+ const oldSize = target.size;
900
+ target.add(value);
901
+ emit(target, value, value, EMPTY);
902
+ emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
903
+ }
904
+ return this;
905
+ },
906
+ delete(value) {
907
+ const target = this[TARGET_SYMBOL];
908
+ value = unproxyCollectionValue(value);
909
+ if (!target.has(value))
910
+ return false;
911
+ const oldSize = target.size;
912
+ target.delete(value);
913
+ emit(target, value, EMPTY, value);
914
+ emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
915
+ return true;
916
+ },
917
+ clear() {
918
+ const target = this[TARGET_SYMBOL];
919
+ const oldSize = target.size;
920
+ if (!oldSize)
921
+ return;
922
+ for (const value of target.values())
923
+ emit(target, value, EMPTY, value);
924
+ target.clear();
925
+ emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
926
+ },
927
+ has(value) {
928
+ const target = this[TARGET_SYMBOL];
929
+ value = unproxyCollectionValue(value);
930
+ subscribe(target, value);
931
+ return target.has(value);
932
+ },
933
+ keys() {
934
+ const target = this[TARGET_SYMBOL];
935
+ subscribe(target, ANY_SYMBOL);
936
+ return wrapIteratorSingle(target.keys());
937
+ },
938
+ values() {
939
+ const target = this[TARGET_SYMBOL];
940
+ subscribe(target, ANY_SYMBOL);
941
+ return wrapIteratorSingle(target.values());
942
+ },
943
+ entries() {
944
+ const target = this[TARGET_SYMBOL];
945
+ subscribe(target, ANY_SYMBOL);
946
+ return wrapIteratorPair(target.entries());
947
+ },
948
+ [Symbol.iterator]() {
949
+ const target = this[TARGET_SYMBOL];
950
+ subscribe(target, ANY_SYMBOL);
951
+ return wrapIteratorSingle(target[Symbol.iterator]());
952
+ }
953
+ };
890
954
  var mapHandler = {
891
955
  get(target, prop) {
892
956
  if (prop === TARGET_SYMBOL)
@@ -901,6 +965,20 @@ var mapHandler = {
901
965
  return target[prop];
902
966
  }
903
967
  };
968
+ var setHandler = {
969
+ get(target, prop) {
970
+ if (prop === TARGET_SYMBOL)
971
+ return target;
972
+ if (setMethodHandlers.hasOwnProperty(prop)) {
973
+ return setMethodHandlers[prop];
974
+ }
975
+ if (prop === "size") {
976
+ subscribe(target, MAP_SIZE_SYMBOL);
977
+ return target.size;
978
+ }
979
+ return target[prop];
980
+ }
981
+ };
904
982
  var proxyMap = new WeakMap;
905
983
  function optProxy(value) {
906
984
  if (typeof value !== "object" || !value || value[TARGET_SYMBOL] !== undefined || NO_COPY in value) {
@@ -914,6 +992,8 @@ function optProxy(value) {
914
992
  handler = arrayHandler;
915
993
  } else if (value instanceof Map) {
916
994
  handler = mapHandler;
995
+ } else if (value instanceof Set) {
996
+ handler = setHandler;
917
997
  } else {
918
998
  handler = objectHandler;
919
999
  }
@@ -1107,7 +1187,7 @@ function setSpacingCssVars(base = 1, unit = "rem") {
1107
1187
  cssVars[i] = 2 ** (i - 3) * base + unit;
1108
1188
  }
1109
1189
  }
1110
- var CSS_VAR_PATTERN = /(\burl\([^)]*\))|("[^"]*")|(^| )\$(\w+)/g;
1190
+ var CSS_VAR_PATTERN = /(\burl\([^)]*\))|("[^"]*")|(^| )\$([\w-]+)/g;
1111
1191
  var DIGIT_FIRST = /^\d/;
1112
1192
  function cssVarRef(value) {
1113
1193
  if (value.indexOf("$") < 0)
@@ -1788,5 +1868,5 @@ export {
1788
1868
  A
1789
1869
  };
1790
1870
 
1791
- //# debugId=3B0B71E6E017014564756E2164756E21
1871
+ //# debugId=CEB17464CFEBA2F464756E2164756E21
1792
1872
  //# sourceMappingURL=aberdeen.js.map