aberdeen 1.0.5 → 1.0.7

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.
@@ -222,7 +222,7 @@ export declare function unproxy<T>(target: T): T;
222
222
  * console.log(source.nested); // [1, 2, 3] (source was modified)
223
223
  * ```
224
224
  */
225
- export declare function copy<T extends object>(dst: T, src: T, flags?: number): void;
225
+ export declare function copy<T extends object>(dst: T, src: Partial<T>, flags?: number): void;
226
226
  /** Flag to {@link copy} causing it to use merge semantics. See {@link copy} for details. */
227
227
  export declare const MERGE = 1;
228
228
  /** Flag to {@link copy} and {@link clone} causing them to create a shallow copy (instead of the deep copy done by default).*/
@@ -358,7 +358,7 @@ export declare function ref<T extends TargetType, K extends keyof T>(target: T,
358
358
  * });
359
359
  * ```
360
360
  */
361
- export declare function $(...args: (string | null | undefined | false | (() => void) | Record<string, any>)[]): void | Element;
361
+ export declare function $(...args: (string | null | undefined | false | (() => void) | Record<string, any>)[]): undefined | Element;
362
362
  /**
363
363
  * Inserts CSS rules into the document, optionally scoping them with a unique class name.
364
364
  *
@@ -579,7 +579,7 @@ export declare function clean(cleaner: () => void): void;
579
579
  * @overload
580
580
  * @param func Func without a return value.
581
581
  */
582
- export declare function observe<T extends (DatumType | void)>(func: () => T): ValueRef<T>;
582
+ export declare function observe<T>(func: () => T): ValueRef<T>;
583
583
  /**
584
584
  * Similar to {@link observe}, creates a reactive scope that re-executes the function
585
585
  * when its proxied dependencies change.
@@ -728,8 +728,3 @@ export declare function partition<IN_K extends string | number | symbol, OUT_K e
728
728
  * ```
729
729
  */
730
730
  export declare function dump<T>(data: T): T;
731
- declare global {
732
- interface String {
733
- replaceAll(from: string, to: string): string;
734
- }
735
- }
package/dist/aberdeen.js CHANGED
@@ -33,7 +33,7 @@ class ReverseSortedSet {
33
33
  return this.symbols[0] in item;
34
34
  }
35
35
  fetchLast() {
36
- let item = this.tail[this.symbols[0]];
36
+ const item = this.tail[this.symbols[0]];
37
37
  if (item) {
38
38
  this.remove(item);
39
39
  return item;
@@ -54,7 +54,7 @@ class ReverseSortedSet {
54
54
  return current[this.symbols[0]]?.[keyProp] === indexValue ? current[this.symbols[0]] : undefined;
55
55
  }
56
56
  *[Symbol.iterator]() {
57
- let symbol = this.symbols[0];
57
+ const symbol = this.symbols[0];
58
58
  let node = this.tail[symbol];
59
59
  while (node) {
60
60
  yield node;
@@ -127,12 +127,12 @@ function runQueue() {
127
127
  sortedQueue = undefined;
128
128
  runQueueDepth = 0;
129
129
  time = Date.now() - time;
130
- if (time > 1)
130
+ if (time > 9)
131
131
  console.debug(`Aberdeen queue took ${time}ms`);
132
132
  }
133
133
  function partToStr(part) {
134
134
  if (typeof part === "string") {
135
- return part + "\x01";
135
+ return `${part}\x01`;
136
136
  }
137
137
  let result = "";
138
138
  let num = Math.abs(Math.round(part));
@@ -174,7 +174,7 @@ class ContentScope extends Scope {
174
174
  return findLastNodeInPrevSiblings(this.lastChild);
175
175
  }
176
176
  delete() {
177
- for (let cleaner of this.cleaners) {
177
+ for (const cleaner of this.cleaners) {
178
178
  if (typeof cleaner === "function")
179
179
  cleaner();
180
180
  else
@@ -230,7 +230,7 @@ class RegularScope extends ChainedScope {
230
230
  this.redraw();
231
231
  }
232
232
  redraw() {
233
- let savedScope = currentScope;
233
+ const savedScope = currentScope;
234
234
  currentScope = this;
235
235
  try {
236
236
  this.renderer();
@@ -275,7 +275,7 @@ class MountScope extends ContentScope {
275
275
  function removeNodes(node, preNode) {
276
276
  while (node && node !== preNode) {
277
277
  const prevNode = node.previousSibling;
278
- let onDestroy = onDestroyMap.get(node);
278
+ const onDestroy = onDestroyMap.get(node);
279
279
  if (onDestroy && node instanceof Element) {
280
280
  if (onDestroy !== true) {
281
281
  if (typeof onDestroy === "function") {
@@ -306,7 +306,7 @@ class ResultScope extends ChainedScope {
306
306
  this.redraw();
307
307
  }
308
308
  redraw() {
309
- let savedScope = currentScope;
309
+ const savedScope = currentScope;
310
310
  currentScope = this;
311
311
  try {
312
312
  this.result.value = this.renderer();
@@ -327,7 +327,7 @@ class SetArgScope extends ChainedScope {
327
327
  this.redraw();
328
328
  }
329
329
  redraw() {
330
- let savedScope = currentScope;
330
+ const savedScope = currentScope;
331
331
  currentScope = this;
332
332
  applyArg(this.key, this.target.value);
333
333
  currentScope = savedScope;
@@ -348,7 +348,7 @@ function runImmediateQueue() {
348
348
  throw new Error("Too many immediate-mode recursive updates");
349
349
  }
350
350
  immediateQueueRunning = true;
351
- let copy = immediateQueue;
351
+ const copy = immediateQueue;
352
352
  immediateQueue = new ReverseSortedSet("prio");
353
353
  try {
354
354
  for (const scope of copy) {
@@ -401,9 +401,9 @@ class OnEachScope extends Scope {
401
401
  queue(this);
402
402
  }
403
403
  queueRun() {
404
- let indexes = this.changedIndexes;
404
+ const indexes = this.changedIndexes;
405
405
  this.changedIndexes = new Set;
406
- for (let index of indexes) {
406
+ for (const index of indexes) {
407
407
  const oldScope = this.byIndex.get(index);
408
408
  if (oldScope)
409
409
  oldScope.remove();
@@ -419,13 +419,14 @@ class OnEachScope extends Scope {
419
419
  for (const scope of this.byIndex.values()) {
420
420
  scope.delete();
421
421
  }
422
+ sortedQueue?.remove(this);
422
423
  this.byIndex.clear();
423
424
  setTimeout(() => {
424
425
  this.sortedSet.clear();
425
426
  }, 1);
426
427
  }
427
428
  getLastNode() {
428
- for (let scope of this.sortedSet) {
429
+ for (const scope of this.sortedSet) {
429
430
  const node = scope.getActualLastNode();
430
431
  if (node)
431
432
  return node;
@@ -486,12 +487,12 @@ class OnEachItemScope extends ContentScope {
486
487
  }
487
488
  redraw() {
488
489
  const value = optProxy(this.parent.target[this.itemIndex]);
489
- let savedScope = currentScope;
490
+ const savedScope = currentScope;
490
491
  currentScope = this;
491
492
  let sortKey;
492
493
  try {
493
494
  if (this.parent.makeSortKey) {
494
- let rawSortKey = this.parent.makeSortKey(value, this.itemIndex);
495
+ const rawSortKey = this.parent.makeSortKey(value, this.itemIndex);
495
496
  if (rawSortKey != null)
496
497
  sortKey = rawSortKey instanceof Array ? rawSortKey.map(partToStr).join("") : rawSortKey;
497
498
  } else {
@@ -555,7 +556,7 @@ function subscribe(target, index, observer = currentScope) {
555
556
  if (observer === currentScope) {
556
557
  currentScope.cleaners.push(byIndex);
557
558
  } else {
558
- currentScope.cleaners.push(function() {
559
+ currentScope.cleaners.push(() => {
559
560
  byIndex.delete(observer);
560
561
  });
561
562
  }
@@ -567,7 +568,7 @@ function onEach(target, render, makeKey) {
567
568
  new OnEachScope(target, render, makeKey);
568
569
  }
569
570
  function isObjEmpty(obj) {
570
- for (let k in obj)
571
+ for (const k in obj)
571
572
  return false;
572
573
  return true;
573
574
  }
@@ -575,30 +576,29 @@ function isEmpty(proxied) {
575
576
  const target = proxied[TARGET_SYMBOL] || proxied;
576
577
  const scope = currentScope;
577
578
  if (target instanceof Array) {
578
- subscribe(target, "length", function(index, newData, oldData) {
579
+ subscribe(target, "length", (index, newData, oldData) => {
579
580
  if (!newData !== !oldData)
580
581
  queue(scope);
581
582
  });
582
583
  return !target.length;
583
- } else {
584
- const result = isObjEmpty(target);
585
- subscribe(target, ANY_SYMBOL, function(index, newData, oldData) {
586
- if (result ? oldData === undefined : newData === undefined)
587
- queue(scope);
588
- });
589
- return result;
590
584
  }
585
+ const result = isObjEmpty(target);
586
+ subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
587
+ if (result ? oldData === undefined : newData === undefined)
588
+ queue(scope);
589
+ });
590
+ return result;
591
591
  }
592
592
  function count(proxied) {
593
593
  if (proxied instanceof Array)
594
594
  return ref(proxied, "length");
595
595
  const target = proxied[TARGET_SYMBOL] || proxied;
596
596
  let cnt = 0;
597
- for (let k in target)
597
+ for (const k in target)
598
598
  if (target[k] !== undefined)
599
599
  cnt++;
600
600
  const result = proxy(cnt);
601
- subscribe(target, ANY_SYMBOL, function(index, newData, oldData) {
601
+ subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
602
602
  if (oldData === newData) {} else if (oldData === undefined)
603
603
  result.value = ++cnt;
604
604
  else if (newData === undefined)
@@ -613,9 +613,9 @@ function defaultEmitHandler(target, index, newData, oldData) {
613
613
  if (byTarget === undefined)
614
614
  return;
615
615
  for (const what of [index, ANY_SYMBOL]) {
616
- let byIndex = byTarget.get(what);
616
+ const byIndex = byTarget.get(what);
617
617
  if (byIndex) {
618
- for (let observer of byIndex) {
618
+ for (const observer of byIndex) {
619
619
  if (typeof observer === "function")
620
620
  observer(index, newData, oldData);
621
621
  else
@@ -665,14 +665,14 @@ function arraySet(target, prop, newData) {
665
665
  newData = newData[TARGET_SYMBOL] || newData;
666
666
  const oldData = target[prop];
667
667
  if (newData !== oldData) {
668
- let oldLength = target.length;
668
+ const oldLength = target.length;
669
669
  if (prop === "length") {
670
670
  target.length = newData;
671
671
  for (let i = newData;i < oldLength; i++) {
672
672
  emit(target, i, undefined, target[i]);
673
673
  }
674
674
  } else {
675
- const intProp = parseInt(prop);
675
+ const intProp = Number.parseInt(prop);
676
676
  if (intProp.toString() === prop)
677
677
  prop = intProp;
678
678
  target[prop] = newData;
@@ -691,7 +691,7 @@ var arrayHandler = {
691
691
  return target;
692
692
  let subProp = prop;
693
693
  if (typeof prop !== "symbol") {
694
- const intProp = parseInt(prop);
694
+ const intProp = Number.parseInt(prop);
695
695
  if (intProp.toString() === prop)
696
696
  subProp = intProp;
697
697
  }
@@ -776,11 +776,11 @@ function copyRecurse(dst, src, flags) {
776
776
  }
777
777
  }
778
778
  } else {
779
- for (let k in src) {
779
+ for (const k in src) {
780
780
  copyValue(dst, src, k, flags);
781
781
  }
782
782
  if (!(flags & MERGE)) {
783
- for (let k in dst) {
783
+ for (const k in dst) {
784
784
  if (!(k in src)) {
785
785
  const old = dst[k];
786
786
  delete dst[k];
@@ -793,7 +793,7 @@ function copyRecurse(dst, src, flags) {
793
793
  }
794
794
  }
795
795
  function copyValue(dst, src, index, flags) {
796
- let dstValue = dst[index];
796
+ const dstValue = dst[index];
797
797
  let srcValue = src[index];
798
798
  if (srcValue !== dstValue) {
799
799
  if (srcValue && dstValue && typeof srcValue === "object" && typeof dstValue === "object" && (srcValue.constructor === dstValue.constructor || flags & MERGE && dstValue instanceof Array)) {
@@ -801,7 +801,7 @@ function copyValue(dst, src, index, flags) {
801
801
  return;
802
802
  }
803
803
  if (!(flags & SHALLOW) && srcValue && typeof srcValue === "object") {
804
- let copy2 = Object.create(Object.getPrototypeOf(srcValue));
804
+ const copy2 = Object.create(Object.getPrototypeOf(srcValue));
805
805
  copyRecurse(copy2, srcValue, 0);
806
806
  srcValue = copy2;
807
807
  }
@@ -837,23 +837,31 @@ function ref(target, index) {
837
837
  function applyBind(el, target) {
838
838
  let onProxyChange;
839
839
  let onInputChange;
840
- let type = el.getAttribute("type");
841
- let value = unproxy(target).value;
840
+ const type = el.getAttribute("type");
841
+ const value = unproxy(target).value;
842
842
  if (type === "checkbox") {
843
843
  if (value === undefined)
844
844
  target.value = el.checked;
845
- onProxyChange = () => el.checked = target.value;
846
- onInputChange = () => target.value = el.checked;
845
+ onProxyChange = () => {
846
+ el.checked = target.value;
847
+ };
848
+ onInputChange = () => {
849
+ target.value = el.checked;
850
+ };
847
851
  } else if (type === "radio") {
848
852
  if (value === undefined && el.checked)
849
853
  target.value = el.value;
850
- onProxyChange = () => el.checked = target.value === el.value;
854
+ onProxyChange = () => {
855
+ el.checked = target.value === el.value;
856
+ };
851
857
  onInputChange = () => {
852
858
  if (el.checked)
853
859
  target.value = el.value;
854
860
  };
855
861
  } else {
856
- onInputChange = () => target.value = type === "number" || type === "range" ? el.value === "" ? null : +el.value : el.value;
862
+ onInputChange = () => {
863
+ target.value = type === "number" || type === "range" ? el.value === "" ? null : +el.value : el.value;
864
+ };
857
865
  if (value === undefined)
858
866
  onInputChange();
859
867
  onProxyChange = () => {
@@ -869,7 +877,7 @@ function applyBind(el, target) {
869
877
  });
870
878
  }
871
879
  var SPECIAL_PROPS = {
872
- create: function(value) {
880
+ create: (value) => {
873
881
  const el = currentScope.parentElement;
874
882
  if (currentScope !== topRedrawScope)
875
883
  return;
@@ -878,26 +886,26 @@ var SPECIAL_PROPS = {
878
886
  } else {
879
887
  const classes = value.split(".").filter((c) => c);
880
888
  el.classList.add(...classes);
881
- (async function() {
889
+ (async () => {
882
890
  el.offsetHeight;
883
891
  el.classList.remove(...classes);
884
892
  })();
885
893
  }
886
894
  },
887
- destroy: function(value) {
895
+ destroy: (value) => {
888
896
  const el = currentScope.parentElement;
889
897
  onDestroyMap.set(el, value);
890
898
  },
891
- html: function(value) {
892
- let tmpParent = document.createElement(currentScope.parentElement.tagName);
893
- tmpParent.innerHTML = "" + value;
899
+ html: (value) => {
900
+ const tmpParent = document.createElement(currentScope.parentElement.tagName);
901
+ tmpParent.innerHTML = `${value}`;
894
902
  while (tmpParent.firstChild)
895
903
  addNode(tmpParent.firstChild);
896
904
  },
897
- text: function(value) {
905
+ text: (value) => {
898
906
  addNode(document.createTextNode(value));
899
907
  },
900
- element: function(value) {
908
+ element: (value) => {
901
909
  if (!(value instanceof Node))
902
910
  throw new Error(`Unexpected element-argument: ${JSON.parse(value)}`);
903
911
  addNode(value);
@@ -911,7 +919,8 @@ function $(...args) {
911
919
  if (arg == null || arg === false)
912
920
  continue;
913
921
  if (typeof arg === "string") {
914
- let text, classes;
922
+ let text;
923
+ let classes;
915
924
  const textPos = arg.indexOf(":");
916
925
  if (textPos >= 0) {
917
926
  text = arg.substring(textPos + 1);
@@ -945,7 +954,7 @@ function $(...args) {
945
954
  if (!savedCurrentScope) {
946
955
  savedCurrentScope = currentScope;
947
956
  }
948
- let newScope = new ChainedScope(result, true);
957
+ const newScope = new ChainedScope(result, true);
949
958
  newScope.lastChild = result.lastChild || undefined;
950
959
  if (topRedrawScope === currentScope)
951
960
  topRedrawScope = newScope;
@@ -976,10 +985,10 @@ function $(...args) {
976
985
  }
977
986
  var cssCount = 0;
978
987
  function insertCss(style, global = false) {
979
- const prefix = global ? "" : ".AbdStl" + ++cssCount;
980
- let css = styleToCss(style, prefix);
988
+ const prefix = global ? "" : `.AbdStl${++cssCount}`;
989
+ const css = styleToCss(style, prefix);
981
990
  if (css)
982
- $("style:" + css);
991
+ $(`style:${css}`);
983
992
  return prefix;
984
993
  }
985
994
  function styleToCss(style, prefix) {
@@ -990,20 +999,20 @@ function styleToCss(style, prefix) {
990
999
  for (const k of kOr.split(/, ?/g)) {
991
1000
  if (v && typeof v === "object") {
992
1001
  if (k.startsWith("@")) {
993
- rules += k + `{
994
- ` + styleToCss(v, prefix) + `}
1002
+ rules += `${k}{
1003
+ ${styleToCss(v, prefix)}}
995
1004
  `;
996
1005
  } else {
997
- rules += styleToCss(v, k.includes("&") ? k.replace(/&/g, prefix) : prefix + " " + k);
1006
+ rules += styleToCss(v, k.includes("&") ? k.replace(/&/g, prefix) : `${prefix} ${k}`);
998
1007
  }
999
1008
  } else {
1000
- props += k.replace(/[A-Z]/g, (letter) => "-" + letter.toLowerCase()) + ":" + v + ";";
1009
+ props += `${k.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}:${v};`;
1001
1010
  }
1002
1011
  }
1003
1012
  }
1004
1013
  if (props)
1005
- rules = (prefix.trimStart() || "*") + "{" + props + `}
1006
- ` + rules;
1014
+ rules = `${prefix.trimStart() || "*"}{${props}}
1015
+ ${rules}`;
1007
1016
  return rules;
1008
1017
  }
1009
1018
  function applyArg(key, value) {
@@ -1025,7 +1034,7 @@ function applyArg(key, value) {
1025
1034
  if (value == null || value === false)
1026
1035
  el.style[name] = "";
1027
1036
  else
1028
- el.style[name] = "" + value;
1037
+ el.style[name] = `${value}`;
1029
1038
  } else if (value == null) {} else if (key in SPECIAL_PROPS) {
1030
1039
  SPECIAL_PROPS[key](value);
1031
1040
  } else if (typeof value === "function") {
@@ -1073,9 +1082,9 @@ function peek(func) {
1073
1082
  }
1074
1083
  }
1075
1084
  function map(source, func) {
1076
- let out = optProxy(source instanceof Array ? [] : {});
1085
+ const out = optProxy(source instanceof Array ? [] : {});
1077
1086
  onEach(source, (item, key) => {
1078
- let value = func(item, key);
1087
+ const value = func(item, key);
1079
1088
  if (value !== undefined) {
1080
1089
  out[key] = value;
1081
1090
  clean(() => {
@@ -1086,14 +1095,14 @@ function map(source, func) {
1086
1095
  return out;
1087
1096
  }
1088
1097
  function multiMap(source, func) {
1089
- let out = optProxy({});
1098
+ const out = optProxy({});
1090
1099
  onEach(source, (item, key) => {
1091
- let pairs = func(item, key);
1100
+ const pairs = func(item, key);
1092
1101
  if (pairs) {
1093
- for (let key2 in pairs)
1102
+ for (const key2 in pairs)
1094
1103
  out[key2] = pairs[key2];
1095
1104
  clean(() => {
1096
- for (let key2 in pairs)
1105
+ for (const key2 in pairs)
1097
1106
  delete out[key2];
1098
1107
  });
1099
1108
  }
@@ -1104,18 +1113,18 @@ function partition(source, func) {
1104
1113
  const unproxiedOut = {};
1105
1114
  const out = proxy(unproxiedOut);
1106
1115
  onEach(source, (item, key) => {
1107
- let rsp = func(item, key);
1116
+ const rsp = func(item, key);
1108
1117
  if (rsp != null) {
1109
1118
  const buckets = rsp instanceof Array ? rsp : [rsp];
1110
1119
  if (buckets.length) {
1111
- for (let bucket of buckets) {
1120
+ for (const bucket of buckets) {
1112
1121
  if (unproxiedOut[bucket])
1113
1122
  out[bucket][key] = item;
1114
1123
  else
1115
1124
  out[bucket] = { [key]: item };
1116
1125
  }
1117
1126
  clean(() => {
1118
- for (let bucket of buckets) {
1127
+ for (const bucket of buckets) {
1119
1128
  delete out[bucket][key];
1120
1129
  if (isObjEmpty(unproxiedOut[bucket]))
1121
1130
  delete out[bucket];
@@ -1131,7 +1140,7 @@ function dump(data) {
1131
1140
  $({ text: data instanceof Array ? "<array>" : "<object>" });
1132
1141
  $("ul", () => {
1133
1142
  onEach(data, (value, key) => {
1134
- $("li:" + JSON.stringify(key) + ": ", () => {
1143
+ $(`li:${JSON.stringify(key)}: `, () => {
1135
1144
  dump(value);
1136
1145
  });
1137
1146
  });
@@ -1142,7 +1151,7 @@ function dump(data) {
1142
1151
  return data;
1143
1152
  }
1144
1153
  function internalError(code) {
1145
- throw new Error("Aberdeen internal error " + code);
1154
+ throw new Error(`Aberdeen internal error ${code}`);
1146
1155
  }
1147
1156
  function handleError(e, showMessage) {
1148
1157
  try {
@@ -1165,10 +1174,6 @@ function withEmitHandler(handler, func) {
1165
1174
  emit = oldEmitHandler;
1166
1175
  }
1167
1176
  }
1168
- if (!String.prototype.replaceAll)
1169
- String.prototype.replaceAll = function(from, to) {
1170
- return this.split(from).join(to);
1171
- };
1172
1177
  export {
1173
1178
  withEmitHandler,
1174
1179
  unproxy,
@@ -1200,5 +1205,5 @@ export {
1200
1205
  $
1201
1206
  };
1202
1207
 
1203
- //# debugId=D0AD62307DFA7AC364756E2164756E21
1208
+ //# debugId=22FD247DC29D103664756E2164756E21
1204
1209
  //# sourceMappingURL=aberdeen.js.map