@jackens/nnn 2026.4.11 → 2026.4.12
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/nnn.js +73 -70
- package/package.json +1 -1
- package/readme.md +1 -1
package/nnn.js
CHANGED
|
@@ -67,62 +67,65 @@ var isRecord = (arg) => typeof arg === "object" && arg != null && !isArray(arg);
|
|
|
67
67
|
|
|
68
68
|
// src/nnn/h.ts
|
|
69
69
|
var XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
70
|
-
var
|
|
70
|
+
var newH = (namespaceUri) => {
|
|
71
71
|
const createElement = namespaceUri == null ? (tag) => document.createElement(tag) : (tag) => document.createElementNS(namespaceUri, tag);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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 {
|
|
96
106
|
if (value === true) {
|
|
97
|
-
node.
|
|
107
|
+
node.setAttribute(name, "");
|
|
98
108
|
} else if (value === false) {
|
|
99
|
-
node.
|
|
109
|
+
node.removeAttribute(name);
|
|
100
110
|
} else {
|
|
101
|
-
node.
|
|
111
|
+
node.setAttribute(name, "" + value);
|
|
102
112
|
}
|
|
103
113
|
}
|
|
104
|
-
} else {
|
|
105
|
-
if (value === true) {
|
|
106
|
-
node.setAttribute(name, "");
|
|
107
|
-
} else if (value === false) {
|
|
108
|
-
node.removeAttribute(name);
|
|
109
|
-
} else {
|
|
110
|
-
node.setAttribute(name, "" + value);
|
|
111
|
-
}
|
|
112
114
|
}
|
|
113
115
|
}
|
|
116
|
+
} else if (isString(arg) || isNumber(arg)) {
|
|
117
|
+
child = document.createTextNode(arg);
|
|
114
118
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return node;
|
|
119
|
+
if (child != null) {
|
|
120
|
+
node.appendChild(child);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return node;
|
|
124
|
+
};
|
|
125
|
+
return h;
|
|
123
126
|
};
|
|
124
|
-
var h =
|
|
125
|
-
var s =
|
|
127
|
+
var h = newH(null);
|
|
128
|
+
var s = newH("http://www.w3.org/2000/svg");
|
|
126
129
|
var svgUse = (id, ...args) => s("svg", ["use", { "xlink:href": "#" + id }], ...args);
|
|
127
130
|
|
|
128
131
|
// src/nnn/fixPlTypography.ts
|
|
@@ -304,31 +307,9 @@ var newNounForm = (locale, forms) => (value) => forms[(PLURAL_RULES[locale] ??=
|
|
|
304
307
|
var omit = (ref, keys) => Object.fromEntries(Object.entries(ref).filter(([key]) => !keys.includes(key)));
|
|
305
308
|
// src/nnn/pick.ts
|
|
306
309
|
var pick = (ref, keys) => Object.fromEntries(Object.entries(ref).filter(([key]) => keys.includes(key)));
|
|
307
|
-
// src/nnn/vivify.ts
|
|
308
|
-
var ARRAY_INDEX_REGEXP = /^(0|[1-9]\d*)$/;
|
|
309
|
-
var isObject = (ref) => typeof ref === "object";
|
|
310
|
-
var getTarget = (parent, parentKey, key) => parent[parentKey] ??= isString(key) && ARRAY_INDEX_REGEXP.test(key) ? [] : {};
|
|
311
|
-
var _vivify = (parent, parentKey) => new Proxy(parent, {
|
|
312
|
-
get(_, key) {
|
|
313
|
-
const target = getTarget(parent, parentKey, key);
|
|
314
|
-
const value = target[key];
|
|
315
|
-
return isString(key) && isObject(target) && (value == null || isObject(value)) ? _vivify(target, key) : value;
|
|
316
|
-
},
|
|
317
|
-
set(_, key, value) {
|
|
318
|
-
const target = getTarget(parent, parentKey, key);
|
|
319
|
-
target[key] = value;
|
|
320
|
-
return true;
|
|
321
|
-
},
|
|
322
|
-
deleteProperty(_, key) {
|
|
323
|
-
const target = getTarget(parent, parentKey, key);
|
|
324
|
-
return delete target[key];
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
var vivify = (ref) => _vivify({ _: ref }, "_");
|
|
328
|
-
|
|
329
310
|
// src/nnn/rwd.ts
|
|
330
311
|
var rwd = (root, selector, cellWidthPx, cellHeightPx, ...specs) => {
|
|
331
|
-
const main =
|
|
312
|
+
const main = root[selector] ??= {};
|
|
332
313
|
main.boxSizing = "border-box";
|
|
333
314
|
main.display = "block";
|
|
334
315
|
main.float = "left";
|
|
@@ -336,7 +317,8 @@ var rwd = (root, selector, cellWidthPx, cellHeightPx, ...specs) => {
|
|
|
336
317
|
main.height = `${cellHeightPx}px`;
|
|
337
318
|
specs.sort(([a], [b]) => a - b);
|
|
338
319
|
for (let [maxWidth, width, height] of specs) {
|
|
339
|
-
const
|
|
320
|
+
const mediaSelector = `@media(min-width:${cellWidthPx * maxWidth}px)`;
|
|
321
|
+
const node = maxWidth === 1 ? main : (root[mediaSelector] ??= {})[selector] ??= {};
|
|
340
322
|
width ??= 1;
|
|
341
323
|
height ??= 1;
|
|
342
324
|
let gcd = 100 * width;
|
|
@@ -357,6 +339,27 @@ var uuidV1 = (date = new Date, node = Math.random().toString(16).slice(2)) => {
|
|
|
357
339
|
counter = counter + 1 & 16383;
|
|
358
340
|
return time.slice(-8).concat("-", time.slice(-12, -8), -1, time.slice(-15, -12), "-", (8 | counter >> 12).toString(16), (ZEROS + (counter & 4095).toString(16)).slice(-3), "-", (ZEROS + node).slice(-12));
|
|
359
341
|
};
|
|
342
|
+
// src/nnn/vivify.ts
|
|
343
|
+
var ARRAY_INDEX_REGEXP = /^(0|[1-9]\d*)$/;
|
|
344
|
+
var isObject = (ref) => typeof ref === "object";
|
|
345
|
+
var getTarget = (parent, parentKey, key) => parent[parentKey] ??= isString(key) && ARRAY_INDEX_REGEXP.test(key) ? [] : {};
|
|
346
|
+
var _vivify = (parent, parentKey) => new Proxy(parent, {
|
|
347
|
+
get(_, key) {
|
|
348
|
+
const target = getTarget(parent, parentKey, key);
|
|
349
|
+
const value = target[key];
|
|
350
|
+
return isString(key) && isObject(target) && (value == null || isObject(value)) ? _vivify(target, key) : value;
|
|
351
|
+
},
|
|
352
|
+
set(_, key, value) {
|
|
353
|
+
const target = getTarget(parent, parentKey, key);
|
|
354
|
+
target[key] = value;
|
|
355
|
+
return true;
|
|
356
|
+
},
|
|
357
|
+
deleteProperty(_, key) {
|
|
358
|
+
const target = getTarget(parent, parentKey, key);
|
|
359
|
+
return delete target[key];
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
var vivify = (ref) => _vivify({ _: ref }, "_");
|
|
360
363
|
export {
|
|
361
364
|
vivify,
|
|
362
365
|
uuidV1,
|
package/package.json
CHANGED