@jackens/nnn 2026.4.12 → 2026.4.14

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 (4) hide show
  1. package/nnn.d.ts +213 -104
  2. package/nnn.js +59 -63
  3. package/package.json +1 -1
  4. package/readme.md +522 -236
package/nnn.js CHANGED
@@ -1,11 +1,9 @@
1
- // src/nnn/isArray.ts
1
+ // src/nnn/is.ts
2
2
  var isArray = Array.isArray;
3
-
4
- // src/nnn/isNumber.ts
5
3
  var isNumber = (arg) => typeof arg === "number";
6
-
7
- // src/nnn/isString.ts
4
+ var isFiniteNumber = Number.isFinite;
8
5
  var isString = (arg) => typeof arg === "string";
6
+ var isRecord = (arg) => typeof arg === "object" && arg != null && !isArray(arg);
9
7
 
10
8
  // src/nnn/c.ts
11
9
  var _c = (node, prefix, result, splitter) => {
@@ -62,74 +60,73 @@ var csvParse = (csv, separator = ",") => {
62
60
  const linePattern = new RegExp(`${separator}|(?<!")\\s*"((?:[^"]|"")*)"\\s*(?!")`, "g");
63
61
  return csv.replace(/\r/g, "").replace(/\n+$/, "").replace(MAIN_PATTERN, (_, chunk) => chunk ?? "\r").split("\r").map((line) => line.replace(linePattern, (_, chunk) => chunk == null ? "\r" : chunk.replace(/""/g, '"')).split("\r"));
64
62
  };
65
- // src/nnn/isRecord.ts
66
- var isRecord = (arg) => typeof arg === "object" && arg != null && !isArray(arg);
67
-
68
63
  // src/nnn/h.ts
69
64
  var XLINK_NS = "http://www.w3.org/1999/xlink";
70
- var newH = (namespaceUri) => {
71
- const createElement = namespaceUri == null ? (tag) => document.createElement(tag) : (tag) => document.createElementNS(namespaceUri, tag);
72
- const h = (tagOrNode, ...args) => {
73
- const node = isString(tagOrNode) ? createElement(tagOrNode) : tagOrNode;
74
- args.forEach((arg) => {
75
- let child = null;
76
- if (arg instanceof Node) {
77
- child = arg;
78
- } else if (isArray(arg)) {
79
- child = h(...arg);
80
- } else if (isRecord(arg)) {
81
- for (const name in arg) {
82
- const value = arg[name];
83
- if (name[0] === "$") {
84
- const name1 = name.slice(1);
85
- if (isRecord(value)) {
86
- node[name1] ??= {};
87
- Object.assign(node[name1], value);
88
- } else {
89
- node[name1] = value;
90
- }
91
- } else if (node instanceof Element) {
92
- const indexOfColon = name.indexOf(":");
93
- if (indexOfColon >= 0) {
94
- const nsKey = name.slice(0, indexOfColon);
95
- if (nsKey === "xlink") {
96
- const basename = name.slice(indexOfColon + 1);
97
- if (value === true) {
98
- node.setAttributeNS(XLINK_NS, basename, "");
99
- } else if (value === false) {
100
- node.removeAttributeNS(XLINK_NS, basename);
101
- } else {
102
- node.setAttributeNS(XLINK_NS, basename, "" + value);
103
- }
104
- }
105
- } else {
65
+ var _h = (createElement, tagOrNode, ...args) => {
66
+ const node = isString(tagOrNode) ? createElement(tagOrNode) : tagOrNode;
67
+ args.forEach((arg) => {
68
+ let child = null;
69
+ if (arg instanceof Node) {
70
+ child = arg;
71
+ } else if (isArray(arg)) {
72
+ child = _h(createElement, ...arg);
73
+ } else if (isRecord(arg)) {
74
+ for (const name in arg) {
75
+ const value = arg[name];
76
+ if (name[0] === "$") {
77
+ const name1 = name.slice(1);
78
+ if (isRecord(value)) {
79
+ Object.assign(node[name1] ??= {}, value);
80
+ } else {
81
+ node[name1] = value;
82
+ }
83
+ } else if (node instanceof Element) {
84
+ const indexOfColon = name.indexOf(":");
85
+ if (indexOfColon >= 0) {
86
+ const nsKey = name.slice(0, indexOfColon);
87
+ if (nsKey === "xlink") {
88
+ const basename = name.slice(indexOfColon + 1);
106
89
  if (value === true) {
107
- node.setAttribute(name, "");
90
+ node.setAttributeNS(XLINK_NS, basename, "");
108
91
  } else if (value === false) {
109
- node.removeAttribute(name);
92
+ node.removeAttributeNS(XLINK_NS, basename);
110
93
  } else {
111
- node.setAttribute(name, "" + value);
94
+ node.setAttributeNS(XLINK_NS, basename, "" + value);
112
95
  }
113
96
  }
97
+ } else {
98
+ if (value === true) {
99
+ node.setAttribute(name, "");
100
+ } else if (value === false) {
101
+ node.removeAttribute(name);
102
+ } else {
103
+ node.setAttribute(name, "" + value);
104
+ }
114
105
  }
115
106
  }
116
- } else if (isString(arg) || isNumber(arg)) {
117
- child = document.createTextNode(arg);
118
107
  }
119
- if (child != null) {
120
- node.appendChild(child);
121
- }
122
- });
123
- return node;
124
- };
125
- return h;
108
+ } else if (isString(arg) || isNumber(arg)) {
109
+ child = document.createTextNode(arg);
110
+ }
111
+ if (child != null) {
112
+ node.appendChild(child);
113
+ }
114
+ });
115
+ return node;
126
116
  };
127
- var h = newH(null);
128
- var s = newH("http://www.w3.org/2000/svg");
117
+ var h = _h.bind(null, (tag) => document.createElement(tag));
118
+ var s = _h.bind(null, (tag) => document.createElementNS("http://www.w3.org/2000/svg", tag));
129
119
  var svgUse = (id, ...args) => s("svg", ["use", { "xlink:href": "#" + id }], ...args);
130
120
 
131
121
  // src/nnn/fixPlTypography.ts
132
- var TAGS_TO_SKIP = ["IFRAME", "NOSCRIPT", "PRE", "SCRIPT", "STYLE", "TEXTAREA"];
122
+ var TAGS_TO_SKIP = [
123
+ "IFRAME",
124
+ "NOSCRIPT",
125
+ "PRE",
126
+ "SCRIPT",
127
+ "STYLE",
128
+ "TEXTAREA"
129
+ ];
133
130
  var fixPlTypography = (node) => {
134
131
  const queue = [node];
135
132
  while (queue.length > 0) {
@@ -148,7 +145,7 @@ var fixPlTypography = (node) => {
148
145
  let previousNode = node0;
149
146
  nodeValue.split(/(\s|\(|„)([aiouwz—]\s)/gi).forEach((chunk, i) => {
150
147
  i %= 3;
151
- const currentNode = i === 2 ? h("span", { style: "white-space:nowrap" }, chunk) : i === 1 ? document.createTextNode(chunk) : document.createTextNode(chunk.replace(/(\/(?=[^/\s])|\.(?=[^\s]))/g, "$1​"));
148
+ const currentNode = i === 2 ? h("span", { style: "white-space:nowrap" }, chunk) : document.createTextNode(i === 1 ? chunk : chunk.replace(/(\/(?=[^/\s])|\.(?=[^\s]))/g, "$1​"));
152
149
  if (node0.parentNode != null) {
153
150
  node0.parentNode.insertBefore(currentNode, previousNode.nextSibling);
154
151
  }
@@ -161,8 +158,6 @@ var fixPlTypography = (node) => {
161
158
  };
162
159
  // src/nnn/hasOwn.ts
163
160
  var hasOwn = (ref, key) => ref != null && Object.hasOwn(ref, key);
164
- // src/nnn/isFiniteNumber.ts
165
- var isFiniteNumber = Number.isFinite;
166
161
  // src/nnn/jsOnParse.ts
167
162
  var jsOnParse = (handlers, text) => JSON.parse(text, (key, value) => {
168
163
  if (isRecord(value)) {
@@ -182,6 +177,7 @@ var jsOnParse = (handlers, text) => JSON.parse(text, (key, value) => {
182
177
  return value;
183
178
  });
184
179
  // src/nnn/monokai.ts
180
+ var darkKey = "@media only screen and (prefers-color-scheme: dark)" + "$$monokai";
185
181
  var monokai = {
186
182
  ":root$$monokai": {
187
183
  __bg: "#faf4f2",
@@ -226,7 +222,7 @@ var monokai = {
226
222
  punctuation: { color: "var(--punctuation)" },
227
223
  string: { color: "var(--string)" }
228
224
  },
229
- "@media only screen and (prefers-color-scheme: dark)$$monokai": {
225
+ [darkKey]: {
230
226
  ":root": {
231
227
  __bg: "#2d2a2e",
232
228
  __fg: "#fcfcfa",
package/package.json CHANGED
@@ -44,5 +44,5 @@
44
44
  "name": "@jackens/nnn",
45
45
  "type": "module",
46
46
  "types": "nnn.d.ts",
47
- "version": "2026.4.12"
47
+ "version": "2026.4.14"
48
48
  }