aberdeen 1.0.5 → 1.0.6

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;
@@ -132,7 +132,7 @@ function runQueue() {
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();
@@ -425,7 +425,7 @@ class OnEachScope extends Scope {
425
425
  }, 1);
426
426
  }
427
427
  getLastNode() {
428
- for (let scope of this.sortedSet) {
428
+ for (const scope of this.sortedSet) {
429
429
  const node = scope.getActualLastNode();
430
430
  if (node)
431
431
  return node;
@@ -486,12 +486,12 @@ class OnEachItemScope extends ContentScope {
486
486
  }
487
487
  redraw() {
488
488
  const value = optProxy(this.parent.target[this.itemIndex]);
489
- let savedScope = currentScope;
489
+ const savedScope = currentScope;
490
490
  currentScope = this;
491
491
  let sortKey;
492
492
  try {
493
493
  if (this.parent.makeSortKey) {
494
- let rawSortKey = this.parent.makeSortKey(value, this.itemIndex);
494
+ const rawSortKey = this.parent.makeSortKey(value, this.itemIndex);
495
495
  if (rawSortKey != null)
496
496
  sortKey = rawSortKey instanceof Array ? rawSortKey.map(partToStr).join("") : rawSortKey;
497
497
  } else {
@@ -555,7 +555,7 @@ function subscribe(target, index, observer = currentScope) {
555
555
  if (observer === currentScope) {
556
556
  currentScope.cleaners.push(byIndex);
557
557
  } else {
558
- currentScope.cleaners.push(function() {
558
+ currentScope.cleaners.push(() => {
559
559
  byIndex.delete(observer);
560
560
  });
561
561
  }
@@ -567,7 +567,7 @@ function onEach(target, render, makeKey) {
567
567
  new OnEachScope(target, render, makeKey);
568
568
  }
569
569
  function isObjEmpty(obj) {
570
- for (let k in obj)
570
+ for (const k in obj)
571
571
  return false;
572
572
  return true;
573
573
  }
@@ -575,30 +575,29 @@ function isEmpty(proxied) {
575
575
  const target = proxied[TARGET_SYMBOL] || proxied;
576
576
  const scope = currentScope;
577
577
  if (target instanceof Array) {
578
- subscribe(target, "length", function(index, newData, oldData) {
578
+ subscribe(target, "length", (index, newData, oldData) => {
579
579
  if (!newData !== !oldData)
580
580
  queue(scope);
581
581
  });
582
582
  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
583
  }
584
+ const result = isObjEmpty(target);
585
+ subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
586
+ if (result ? oldData === undefined : newData === undefined)
587
+ queue(scope);
588
+ });
589
+ return result;
591
590
  }
592
591
  function count(proxied) {
593
592
  if (proxied instanceof Array)
594
593
  return ref(proxied, "length");
595
594
  const target = proxied[TARGET_SYMBOL] || proxied;
596
595
  let cnt = 0;
597
- for (let k in target)
596
+ for (const k in target)
598
597
  if (target[k] !== undefined)
599
598
  cnt++;
600
599
  const result = proxy(cnt);
601
- subscribe(target, ANY_SYMBOL, function(index, newData, oldData) {
600
+ subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
602
601
  if (oldData === newData) {} else if (oldData === undefined)
603
602
  result.value = ++cnt;
604
603
  else if (newData === undefined)
@@ -613,9 +612,9 @@ function defaultEmitHandler(target, index, newData, oldData) {
613
612
  if (byTarget === undefined)
614
613
  return;
615
614
  for (const what of [index, ANY_SYMBOL]) {
616
- let byIndex = byTarget.get(what);
615
+ const byIndex = byTarget.get(what);
617
616
  if (byIndex) {
618
- for (let observer of byIndex) {
617
+ for (const observer of byIndex) {
619
618
  if (typeof observer === "function")
620
619
  observer(index, newData, oldData);
621
620
  else
@@ -665,14 +664,14 @@ function arraySet(target, prop, newData) {
665
664
  newData = newData[TARGET_SYMBOL] || newData;
666
665
  const oldData = target[prop];
667
666
  if (newData !== oldData) {
668
- let oldLength = target.length;
667
+ const oldLength = target.length;
669
668
  if (prop === "length") {
670
669
  target.length = newData;
671
670
  for (let i = newData;i < oldLength; i++) {
672
671
  emit(target, i, undefined, target[i]);
673
672
  }
674
673
  } else {
675
- const intProp = parseInt(prop);
674
+ const intProp = Number.parseInt(prop);
676
675
  if (intProp.toString() === prop)
677
676
  prop = intProp;
678
677
  target[prop] = newData;
@@ -691,7 +690,7 @@ var arrayHandler = {
691
690
  return target;
692
691
  let subProp = prop;
693
692
  if (typeof prop !== "symbol") {
694
- const intProp = parseInt(prop);
693
+ const intProp = Number.parseInt(prop);
695
694
  if (intProp.toString() === prop)
696
695
  subProp = intProp;
697
696
  }
@@ -776,11 +775,11 @@ function copyRecurse(dst, src, flags) {
776
775
  }
777
776
  }
778
777
  } else {
779
- for (let k in src) {
778
+ for (const k in src) {
780
779
  copyValue(dst, src, k, flags);
781
780
  }
782
781
  if (!(flags & MERGE)) {
783
- for (let k in dst) {
782
+ for (const k in dst) {
784
783
  if (!(k in src)) {
785
784
  const old = dst[k];
786
785
  delete dst[k];
@@ -793,7 +792,7 @@ function copyRecurse(dst, src, flags) {
793
792
  }
794
793
  }
795
794
  function copyValue(dst, src, index, flags) {
796
- let dstValue = dst[index];
795
+ const dstValue = dst[index];
797
796
  let srcValue = src[index];
798
797
  if (srcValue !== dstValue) {
799
798
  if (srcValue && dstValue && typeof srcValue === "object" && typeof dstValue === "object" && (srcValue.constructor === dstValue.constructor || flags & MERGE && dstValue instanceof Array)) {
@@ -801,7 +800,7 @@ function copyValue(dst, src, index, flags) {
801
800
  return;
802
801
  }
803
802
  if (!(flags & SHALLOW) && srcValue && typeof srcValue === "object") {
804
- let copy2 = Object.create(Object.getPrototypeOf(srcValue));
803
+ const copy2 = Object.create(Object.getPrototypeOf(srcValue));
805
804
  copyRecurse(copy2, srcValue, 0);
806
805
  srcValue = copy2;
807
806
  }
@@ -837,23 +836,31 @@ function ref(target, index) {
837
836
  function applyBind(el, target) {
838
837
  let onProxyChange;
839
838
  let onInputChange;
840
- let type = el.getAttribute("type");
841
- let value = unproxy(target).value;
839
+ const type = el.getAttribute("type");
840
+ const value = unproxy(target).value;
842
841
  if (type === "checkbox") {
843
842
  if (value === undefined)
844
843
  target.value = el.checked;
845
- onProxyChange = () => el.checked = target.value;
846
- onInputChange = () => target.value = el.checked;
844
+ onProxyChange = () => {
845
+ el.checked = target.value;
846
+ };
847
+ onInputChange = () => {
848
+ target.value = el.checked;
849
+ };
847
850
  } else if (type === "radio") {
848
851
  if (value === undefined && el.checked)
849
852
  target.value = el.value;
850
- onProxyChange = () => el.checked = target.value === el.value;
853
+ onProxyChange = () => {
854
+ el.checked = target.value === el.value;
855
+ };
851
856
  onInputChange = () => {
852
857
  if (el.checked)
853
858
  target.value = el.value;
854
859
  };
855
860
  } else {
856
- onInputChange = () => target.value = type === "number" || type === "range" ? el.value === "" ? null : +el.value : el.value;
861
+ onInputChange = () => {
862
+ target.value = type === "number" || type === "range" ? el.value === "" ? null : +el.value : el.value;
863
+ };
857
864
  if (value === undefined)
858
865
  onInputChange();
859
866
  onProxyChange = () => {
@@ -869,7 +876,7 @@ function applyBind(el, target) {
869
876
  });
870
877
  }
871
878
  var SPECIAL_PROPS = {
872
- create: function(value) {
879
+ create: (value) => {
873
880
  const el = currentScope.parentElement;
874
881
  if (currentScope !== topRedrawScope)
875
882
  return;
@@ -878,26 +885,26 @@ var SPECIAL_PROPS = {
878
885
  } else {
879
886
  const classes = value.split(".").filter((c) => c);
880
887
  el.classList.add(...classes);
881
- (async function() {
888
+ (async () => {
882
889
  el.offsetHeight;
883
890
  el.classList.remove(...classes);
884
891
  })();
885
892
  }
886
893
  },
887
- destroy: function(value) {
894
+ destroy: (value) => {
888
895
  const el = currentScope.parentElement;
889
896
  onDestroyMap.set(el, value);
890
897
  },
891
- html: function(value) {
892
- let tmpParent = document.createElement(currentScope.parentElement.tagName);
893
- tmpParent.innerHTML = "" + value;
898
+ html: (value) => {
899
+ const tmpParent = document.createElement(currentScope.parentElement.tagName);
900
+ tmpParent.innerHTML = `${value}`;
894
901
  while (tmpParent.firstChild)
895
902
  addNode(tmpParent.firstChild);
896
903
  },
897
- text: function(value) {
904
+ text: (value) => {
898
905
  addNode(document.createTextNode(value));
899
906
  },
900
- element: function(value) {
907
+ element: (value) => {
901
908
  if (!(value instanceof Node))
902
909
  throw new Error(`Unexpected element-argument: ${JSON.parse(value)}`);
903
910
  addNode(value);
@@ -911,7 +918,8 @@ function $(...args) {
911
918
  if (arg == null || arg === false)
912
919
  continue;
913
920
  if (typeof arg === "string") {
914
- let text, classes;
921
+ let text;
922
+ let classes;
915
923
  const textPos = arg.indexOf(":");
916
924
  if (textPos >= 0) {
917
925
  text = arg.substring(textPos + 1);
@@ -945,7 +953,7 @@ function $(...args) {
945
953
  if (!savedCurrentScope) {
946
954
  savedCurrentScope = currentScope;
947
955
  }
948
- let newScope = new ChainedScope(result, true);
956
+ const newScope = new ChainedScope(result, true);
949
957
  newScope.lastChild = result.lastChild || undefined;
950
958
  if (topRedrawScope === currentScope)
951
959
  topRedrawScope = newScope;
@@ -976,10 +984,10 @@ function $(...args) {
976
984
  }
977
985
  var cssCount = 0;
978
986
  function insertCss(style, global = false) {
979
- const prefix = global ? "" : ".AbdStl" + ++cssCount;
980
- let css = styleToCss(style, prefix);
987
+ const prefix = global ? "" : `.AbdStl${++cssCount}`;
988
+ const css = styleToCss(style, prefix);
981
989
  if (css)
982
- $("style:" + css);
990
+ $(`style:${css}`);
983
991
  return prefix;
984
992
  }
985
993
  function styleToCss(style, prefix) {
@@ -990,20 +998,20 @@ function styleToCss(style, prefix) {
990
998
  for (const k of kOr.split(/, ?/g)) {
991
999
  if (v && typeof v === "object") {
992
1000
  if (k.startsWith("@")) {
993
- rules += k + `{
994
- ` + styleToCss(v, prefix) + `}
1001
+ rules += `${k}{
1002
+ ${styleToCss(v, prefix)}}
995
1003
  `;
996
1004
  } else {
997
- rules += styleToCss(v, k.includes("&") ? k.replace(/&/g, prefix) : prefix + " " + k);
1005
+ rules += styleToCss(v, k.includes("&") ? k.replace(/&/g, prefix) : `${prefix} ${k}`);
998
1006
  }
999
1007
  } else {
1000
- props += k.replace(/[A-Z]/g, (letter) => "-" + letter.toLowerCase()) + ":" + v + ";";
1008
+ props += `${k.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}:${v};`;
1001
1009
  }
1002
1010
  }
1003
1011
  }
1004
1012
  if (props)
1005
- rules = (prefix.trimStart() || "*") + "{" + props + `}
1006
- ` + rules;
1013
+ rules = `${prefix.trimStart() || "*"}{${props}}
1014
+ ${rules}`;
1007
1015
  return rules;
1008
1016
  }
1009
1017
  function applyArg(key, value) {
@@ -1025,7 +1033,7 @@ function applyArg(key, value) {
1025
1033
  if (value == null || value === false)
1026
1034
  el.style[name] = "";
1027
1035
  else
1028
- el.style[name] = "" + value;
1036
+ el.style[name] = `${value}`;
1029
1037
  } else if (value == null) {} else if (key in SPECIAL_PROPS) {
1030
1038
  SPECIAL_PROPS[key](value);
1031
1039
  } else if (typeof value === "function") {
@@ -1073,9 +1081,9 @@ function peek(func) {
1073
1081
  }
1074
1082
  }
1075
1083
  function map(source, func) {
1076
- let out = optProxy(source instanceof Array ? [] : {});
1084
+ const out = optProxy(source instanceof Array ? [] : {});
1077
1085
  onEach(source, (item, key) => {
1078
- let value = func(item, key);
1086
+ const value = func(item, key);
1079
1087
  if (value !== undefined) {
1080
1088
  out[key] = value;
1081
1089
  clean(() => {
@@ -1086,14 +1094,14 @@ function map(source, func) {
1086
1094
  return out;
1087
1095
  }
1088
1096
  function multiMap(source, func) {
1089
- let out = optProxy({});
1097
+ const out = optProxy({});
1090
1098
  onEach(source, (item, key) => {
1091
- let pairs = func(item, key);
1099
+ const pairs = func(item, key);
1092
1100
  if (pairs) {
1093
- for (let key2 in pairs)
1101
+ for (const key2 in pairs)
1094
1102
  out[key2] = pairs[key2];
1095
1103
  clean(() => {
1096
- for (let key2 in pairs)
1104
+ for (const key2 in pairs)
1097
1105
  delete out[key2];
1098
1106
  });
1099
1107
  }
@@ -1104,18 +1112,18 @@ function partition(source, func) {
1104
1112
  const unproxiedOut = {};
1105
1113
  const out = proxy(unproxiedOut);
1106
1114
  onEach(source, (item, key) => {
1107
- let rsp = func(item, key);
1115
+ const rsp = func(item, key);
1108
1116
  if (rsp != null) {
1109
1117
  const buckets = rsp instanceof Array ? rsp : [rsp];
1110
1118
  if (buckets.length) {
1111
- for (let bucket of buckets) {
1119
+ for (const bucket of buckets) {
1112
1120
  if (unproxiedOut[bucket])
1113
1121
  out[bucket][key] = item;
1114
1122
  else
1115
1123
  out[bucket] = { [key]: item };
1116
1124
  }
1117
1125
  clean(() => {
1118
- for (let bucket of buckets) {
1126
+ for (const bucket of buckets) {
1119
1127
  delete out[bucket][key];
1120
1128
  if (isObjEmpty(unproxiedOut[bucket]))
1121
1129
  delete out[bucket];
@@ -1131,7 +1139,7 @@ function dump(data) {
1131
1139
  $({ text: data instanceof Array ? "<array>" : "<object>" });
1132
1140
  $("ul", () => {
1133
1141
  onEach(data, (value, key) => {
1134
- $("li:" + JSON.stringify(key) + ": ", () => {
1142
+ $(`li:${JSON.stringify(key)}: `, () => {
1135
1143
  dump(value);
1136
1144
  });
1137
1145
  });
@@ -1142,7 +1150,7 @@ function dump(data) {
1142
1150
  return data;
1143
1151
  }
1144
1152
  function internalError(code) {
1145
- throw new Error("Aberdeen internal error " + code);
1153
+ throw new Error(`Aberdeen internal error ${code}`);
1146
1154
  }
1147
1155
  function handleError(e, showMessage) {
1148
1156
  try {
@@ -1165,10 +1173,6 @@ function withEmitHandler(handler, func) {
1165
1173
  emit = oldEmitHandler;
1166
1174
  }
1167
1175
  }
1168
- if (!String.prototype.replaceAll)
1169
- String.prototype.replaceAll = function(from, to) {
1170
- return this.split(from).join(to);
1171
- };
1172
1176
  export {
1173
1177
  withEmitHandler,
1174
1178
  unproxy,
@@ -1200,5 +1204,5 @@ export {
1200
1204
  $
1201
1205
  };
1202
1206
 
1203
- //# debugId=D0AD62307DFA7AC364756E2164756E21
1207
+ //# debugId=7D3AE73408804D7B64756E2164756E21
1204
1208
  //# sourceMappingURL=aberdeen.js.map