@thi.ng/hdom 9.4.33 → 9.4.35

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:18Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [9.4.35](https://github.com/thi-ng/umbrella/tree/@thi.ng/hdom@9.4.35) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - split up internal normalizeTree() ([1fbca7b](https://github.com/thi-ng/umbrella/commit/1fbca7b))
17
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
18
+
12
19
  ### [9.4.14](https://github.com/thi-ng/umbrella/tree/@thi.ng/hdom@9.4.14) (2024-02-16)
13
20
 
14
21
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -161,7 +161,7 @@ yarn install
161
161
  yarn start
162
162
  ```
163
163
 
164
- Package sizes (brotli'd, pre-treeshake): ESM: 3.48 KB
164
+ Package sizes (brotli'd, pre-treeshake): ESM: 3.49 KB
165
165
 
166
166
  ## Dependencies
167
167
 
package/diff.js CHANGED
@@ -20,7 +20,7 @@ const INDEX = (() => {
20
20
  }
21
21
  return res;
22
22
  })();
23
- const buildIndex = (n) => {
23
+ const __buildIndex = (n) => {
24
24
  if (n <= INDEX.length) {
25
25
  return INDEX.slice(0, n);
26
26
  }
@@ -75,14 +75,13 @@ const diffTree = (opts, impl, parent, prev, curr, child = 0) => {
75
75
  }
76
76
  const numEdits = edits.length;
77
77
  const prevLength = prev.length - 1;
78
- const equivKeys = extractEquivElements(edits);
79
- const offsets = buildIndex(prevLength + 1);
78
+ const equivKeys = __extractEquivElements(edits);
79
+ const offsets = __buildIndex(prevLength + 1);
80
80
  for (i = 2, ii = 6; ii < numEdits; i++, ii += 3) {
81
81
  status = edits[ii];
82
- if (!status)
83
- continue;
82
+ if (!status) continue;
84
83
  if (status === -1) {
85
- diffDeleted(
84
+ __diffDeleted(
86
85
  opts,
87
86
  impl,
88
87
  el,
@@ -95,7 +94,7 @@ const diffTree = (opts, impl, parent, prev, curr, child = 0) => {
95
94
  prevLength
96
95
  );
97
96
  } else {
98
- diffAdded(
97
+ __diffAdded(
99
98
  opts,
100
99
  impl,
101
100
  el,
@@ -111,7 +110,7 @@ const diffTree = (opts, impl, parent, prev, curr, child = 0) => {
111
110
  val.apply(curr, [el, ...curr.__args]);
112
111
  }
113
112
  };
114
- const diffDeleted = (opts, impl, el, prev, curr, edits, ii, equivKeys, offsets, prevLength) => {
113
+ const __diffDeleted = (opts, impl, el, prev, curr, edits, ii, equivKeys, offsets, prevLength) => {
115
114
  const val = edits[ii + 2];
116
115
  if (isArray(val)) {
117
116
  let k = val[1].key;
@@ -123,13 +122,13 @@ const diffDeleted = (opts, impl, el, prev, curr, edits, ii, equivKeys, offsets,
123
122
  const idx = edits[ii + 1];
124
123
  releaseTree(val);
125
124
  impl.removeChild(el, offsets[idx]);
126
- incOffsets(offsets, prevLength, idx);
125
+ __incOffsets(offsets, prevLength, idx);
127
126
  }
128
127
  } else if (typeof val === STR) {
129
128
  impl.setContent(el, "");
130
129
  }
131
130
  };
132
- const diffAdded = (opts, impl, el, edits, ii, equivKeys, offsets, prevLength) => {
131
+ const __diffAdded = (opts, impl, el, edits, ii, equivKeys, offsets, prevLength) => {
133
132
  const val = edits[ii + 2];
134
133
  if (typeof val === STR) {
135
134
  impl.setContent(el, val);
@@ -138,16 +137,16 @@ const diffAdded = (opts, impl, el, edits, ii, equivKeys, offsets, prevLength) =>
138
137
  if (k === void 0 || equivKeys[k][0] === void 0) {
139
138
  const idx = edits[ii + 1];
140
139
  impl.createTree(opts, el, val, offsets[idx]);
141
- decOffsets(offsets, prevLength, idx);
140
+ __decOffsets(offsets, prevLength, idx);
142
141
  }
143
142
  }
144
143
  };
145
- const incOffsets = (offsets, j, idx) => {
144
+ const __incOffsets = (offsets, j, idx) => {
146
145
  for (; j > idx; j--) {
147
146
  offsets[j] = max(offsets[j] - 1, 0);
148
147
  }
149
148
  };
150
- const decOffsets = (offsets, j, idx) => {
149
+ const __decOffsets = (offsets, j, idx) => {
151
150
  for (; j >= idx; j--) {
152
151
  offsets[j]++;
153
152
  }
@@ -183,7 +182,7 @@ const releaseTree = (tree) => {
183
182
  }
184
183
  }
185
184
  };
186
- const extractEquivElements = (edits) => {
185
+ const __extractEquivElements = (edits) => {
187
186
  let k;
188
187
  let val;
189
188
  let ek;
package/dom.js CHANGED
@@ -6,7 +6,7 @@ import { ATTRIB_JOIN_DELIMS, SVG_TAGS } from "@thi.ng/hiccup/api";
6
6
  import { css } from "@thi.ng/hiccup/css";
7
7
  import { formatPrefixes } from "@thi.ng/hiccup/prefix";
8
8
  import { XML_SVG } from "@thi.ng/prefixes/xml";
9
- const maybeInitElement = (el, tree) => tree.__init && tree.__init.apply(tree.__this, [el, ...tree.__args]);
9
+ const __maybeInitElement = (el, tree) => tree.__init && tree.__init.apply(tree.__this, [el, ...tree.__args]);
10
10
  const createTree = (opts, impl, parent, tree, insert, init = true) => {
11
11
  if (isArray(tree)) {
12
12
  const tag = tree[0];
@@ -36,7 +36,7 @@ const createTree = (opts, impl, parent, tree, insert, init = true) => {
36
36
  createTree(opts, impl, el, tree[i], void 0, init);
37
37
  }
38
38
  }
39
- init && maybeInitElement(el, tree);
39
+ init && __maybeInitElement(el, tree);
40
40
  return el;
41
41
  }
42
42
  if (isNotStringAndIterable(tree)) {
@@ -72,7 +72,7 @@ const hydrateTree = (opts, impl, parent, tree, index = 0) => {
72
72
  index
73
73
  );
74
74
  }
75
- maybeInitElement(el, tree);
75
+ __maybeInitElement(el, tree);
76
76
  for (let a in attribs) {
77
77
  a[0] === "o" && a[1] === "n" && impl.setAttrib(el, a, attribs[a]);
78
78
  }
@@ -110,8 +110,7 @@ const setAttribs = (el, attribs) => {
110
110
  };
111
111
  const setAttrib = (el, id, val, attribs) => {
112
112
  implementsFunction(val, "deref") && (val = val.deref());
113
- if (id.startsWith("__"))
114
- return;
113
+ if (id.startsWith("__")) return;
115
114
  const isListener = id[0] === "o" && id[1] === "n";
116
115
  if (isListener) {
117
116
  if (isString(val)) {
@@ -122,10 +121,8 @@ const setAttrib = (el, id, val, attribs) => {
122
121
  }
123
122
  return el;
124
123
  }
125
- if (typeof val === "function")
126
- val = val(attribs);
127
- if (isArray(val))
128
- val = val.join(ATTRIB_JOIN_DELIMS[id] || " ");
124
+ if (typeof val === "function") val = val(attribs);
125
+ if (isArray(val)) val = val.join(ATTRIB_JOIN_DELIMS[id] || " ");
129
126
  switch (id) {
130
127
  case "style":
131
128
  setStyle(el, val);
package/normalize.js CHANGED
@@ -27,7 +27,7 @@ const normalizeElement = (spec, keys) => {
27
27
  );
28
28
  return attribs.__skip && spec.length < 3 ? [name, attribs] : [name, attribs, ...spec.slice(hasAttribs ? 2 : 1)];
29
29
  };
30
- const normalizeTree = (opts, tree) => _normalizeTree(
30
+ const normalizeTree = (opts, tree) => __normalizeTree(
31
31
  tree,
32
32
  opts,
33
33
  opts.ctx,
@@ -35,60 +35,53 @@ const normalizeTree = (opts, tree) => _normalizeTree(
35
35
  opts.keys !== false,
36
36
  opts.span !== false
37
37
  );
38
- const _normalizeTree = (tree, opts, ctx, path, keys, span) => {
39
- if (tree == null) {
40
- return;
38
+ const __normalizeTree = (tree, opts, ctx, path, keys, span) => tree == null ? void 0 : isArray(tree) ? __normalizeArray(tree, opts, ctx, path, keys, span) : typeof tree === "function" ? __normalizeTree(tree(ctx), opts, ctx, path, keys, span) : typeof tree.toHiccup === "function" ? __normalizeTree(tree.toHiccup(opts.ctx), opts, ctx, path, keys, span) : typeof tree.deref === "function" ? __normalizeTree(tree.deref(), opts, ctx, path, keys, span) : span ? ["span", keys ? { key: path.join("-") } : {}, tree.toString()] : tree.toString();
39
+ const __normalizeArray = (tree, opts, ctx, path, keys, span) => {
40
+ if (tree.length === 0) return;
41
+ let norm, nattribs = tree[1], impl;
42
+ if (nattribs && (impl = nattribs.__impl) && (impl = impl.normalizeTree)) {
43
+ return impl(opts, tree);
41
44
  }
42
- if (isArray(tree)) {
43
- if (tree.length === 0) {
44
- return;
45
- }
46
- let norm, nattribs = tree[1], impl;
47
- if (nattribs && (impl = nattribs.__impl) && (impl = impl.normalizeTree)) {
48
- return impl(opts, tree);
49
- }
50
- const tag = tree[0];
51
- if (typeof tag === "function") {
52
- return _normalizeTree(
53
- tag.apply(null, [ctx, ...tree.slice(1)]),
54
- opts,
55
- ctx,
56
- path,
57
- keys,
58
- span
59
- );
60
- }
61
- if (typeof tag.render === "function") {
62
- const args = [ctx, ...tree.slice(1)];
63
- norm = _normalizeTree(
64
- tag.render.apply(tag, args),
65
- opts,
66
- ctx,
67
- path,
68
- keys,
69
- span
70
- );
71
- if (isArray(norm)) {
72
- norm.__this = tag;
73
- norm.__init = tag.init;
74
- norm.__release = tag.release;
75
- norm.__args = args;
76
- }
77
- return norm;
78
- }
79
- norm = normalizeElement(tree, keys);
80
- nattribs = norm[1];
81
- if (nattribs.__normalize === false) {
82
- return norm;
83
- }
84
- if (keys && nattribs.key === void 0) {
85
- nattribs.key = path.join("-");
45
+ const tag = tree[0];
46
+ if (typeof tag === "function") {
47
+ return __normalizeTree(
48
+ tag.apply(null, [ctx, ...tree.slice(1)]),
49
+ opts,
50
+ ctx,
51
+ path,
52
+ keys,
53
+ span
54
+ );
55
+ }
56
+ if (typeof tag.render === "function") {
57
+ const args = [ctx, ...tree.slice(1)];
58
+ norm = __normalizeTree(
59
+ tag.render.apply(tag, args),
60
+ opts,
61
+ ctx,
62
+ path,
63
+ keys,
64
+ span
65
+ );
66
+ if (isArray(norm)) {
67
+ norm.__this = tag;
68
+ norm.__init = tag.init;
69
+ norm.__release = tag.release;
70
+ norm.__args = args;
86
71
  }
87
- return norm.length > 2 ? normalizeChildren(norm, nattribs, opts, ctx, path, keys, span) : norm;
72
+ return norm;
73
+ }
74
+ norm = normalizeElement(tree, keys);
75
+ nattribs = norm[1];
76
+ if (nattribs.__normalize === false) {
77
+ return norm;
78
+ }
79
+ if (keys && nattribs.key === void 0) {
80
+ nattribs.key = path.join("-");
88
81
  }
89
- return typeof tree === "function" ? _normalizeTree(tree(ctx), opts, ctx, path, keys, span) : typeof tree.toHiccup === "function" ? _normalizeTree(tree.toHiccup(opts.ctx), opts, ctx, path, keys, span) : typeof tree.deref === "function" ? _normalizeTree(tree.deref(), opts, ctx, path, keys, span) : span ? ["span", keys ? { key: path.join("-") } : {}, tree.toString()] : tree.toString();
82
+ return norm.length > 2 ? __normalizeChildren(norm, nattribs, opts, ctx, path, keys, span) : norm;
90
83
  };
91
- const normalizeChildren = (norm, nattribs, opts, ctx, path, keys, span) => {
84
+ const __normalizeChildren = (norm, nattribs, opts, ctx, path, keys, span) => {
92
85
  const tag = norm[0];
93
86
  const res = [tag, nattribs];
94
87
  span = span && !NO_SPANS[tag];
@@ -98,7 +91,7 @@ const normalizeChildren = (norm, nattribs, opts, ctx, path, keys, span) => {
98
91
  const isarray = isArray(el);
99
92
  if (isarray && isArray(el[0]) || !isarray && isNotStringAndIterable(el)) {
100
93
  for (let c of el) {
101
- c = _normalizeTree(
94
+ c = __normalizeTree(
102
95
  c,
103
96
  opts,
104
97
  ctx,
@@ -112,7 +105,7 @@ const normalizeChildren = (norm, nattribs, opts, ctx, path, keys, span) => {
112
105
  k++;
113
106
  }
114
107
  } else {
115
- el = _normalizeTree(el, opts, ctx, path.concat(k), keys, span);
108
+ el = __normalizeTree(el, opts, ctx, path.concat(k), keys, span);
116
109
  if (el !== void 0) {
117
110
  res[j++] = el;
118
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hdom",
3
- "version": "9.4.33",
3
+ "version": "9.4.35",
4
4
  "description": "Lightweight vanilla ES6 UI component trees with customizable branch-local behaviors",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/hdom#readme",
13
+ "homepage": "https://thi.ng/hdom",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -39,21 +39,21 @@
39
39
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@thi.ng/api": "^8.11.1",
43
- "@thi.ng/checks": "^3.6.3",
44
- "@thi.ng/diff": "^5.1.68",
45
- "@thi.ng/equiv": "^2.1.57",
46
- "@thi.ng/errors": "^2.5.6",
47
- "@thi.ng/hiccup": "^5.2.0",
48
- "@thi.ng/logger": "^3.0.11",
49
- "@thi.ng/prefixes": "^2.3.18"
42
+ "@thi.ng/api": "^8.11.3",
43
+ "@thi.ng/checks": "^3.6.5",
44
+ "@thi.ng/diff": "^5.1.70",
45
+ "@thi.ng/equiv": "^2.1.59",
46
+ "@thi.ng/errors": "^2.5.8",
47
+ "@thi.ng/hiccup": "^5.2.2",
48
+ "@thi.ng/logger": "^3.0.13",
49
+ "@thi.ng/prefixes": "^2.3.20"
50
50
  },
51
51
  "devDependencies": {
52
- "@microsoft/api-extractor": "^7.43.0",
53
- "@thi.ng/atom": "^5.2.45",
54
- "esbuild": "^0.20.2",
55
- "typedoc": "^0.25.12",
56
- "typescript": "^5.4.3"
52
+ "@microsoft/api-extractor": "^7.47.0",
53
+ "@thi.ng/atom": "^5.3.1",
54
+ "esbuild": "^0.21.5",
55
+ "typedoc": "^0.25.13",
56
+ "typescript": "^5.5.2"
57
57
  },
58
58
  "keywords": [
59
59
  "array",
@@ -131,5 +131,5 @@
131
131
  "status": "completed",
132
132
  "year": 2015
133
133
  },
134
- "gitHead": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
134
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
135
135
  }
package/render-once.js CHANGED
@@ -6,8 +6,7 @@ const renderOnce = (tree, opts = {}, impl = DEFAULT_IMPL) => {
6
6
  opts.ctx = derefContext(opts.ctx, opts.autoDerefKeys);
7
7
  const root = resolveRoot(opts.root, impl);
8
8
  tree = impl.normalizeTree(opts, tree);
9
- if (!tree)
10
- return;
9
+ if (!tree) return;
11
10
  opts.hydrate ? impl.hydrateTree(opts, root, tree) : impl.createTree(opts, root, tree);
12
11
  };
13
12
  export {