nesquick 1.3.0 → 1.5.0
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/lib/For/getMap.js +5 -3
- package/lib/Nesquick.js +16 -4
- package/lib/NesquickComponent.js +17 -18
- package/lib/cli/nesquick-tsc.js +12 -0
- package/lib/cli/processArgv.js +19 -0
- package/lib/cli/transformer.js +143 -0
- package/lib/cli/tsc.js +56 -0
- package/lib/index.js +3 -0
- package/lib/jsx-runtime.js +7 -16
- package/lib/plugins/viteTransformerPlugin.js +28 -0
- package/lib/types/For/For.d.ts +3 -3
- package/lib/types/Nesquick.d.ts +1 -64
- package/lib/types/NesquickComponent.d.ts +0 -1
- package/lib/types/cli/nesquick-tsc.d.ts +2 -0
- package/lib/types/cli/processArgv.d.ts +1 -0
- package/lib/types/cli/transformer.d.ts +2 -0
- package/lib/types/cli/tsc.d.ts +7 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/jsx-runtime.d.ts +61 -3
- package/lib/types/plugins/viteTransformerPlugin.d.ts +8 -0
- package/package.json +31 -7
package/lib/For/getMap.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMap = getMap;
|
|
4
4
|
function getMap(props) {
|
|
5
|
-
|
|
5
|
+
const idsCallback = "ids" in props && props.ids?.();
|
|
6
|
+
if (idsCallback) {
|
|
6
7
|
const childrenMap = new Map();
|
|
7
8
|
let idLength = 0;
|
|
8
9
|
return {
|
|
9
10
|
getId(item, i) {
|
|
10
|
-
const ids =
|
|
11
|
+
const ids = idsCallback(item, i);
|
|
11
12
|
if (!ids || ids.length === 0) {
|
|
12
13
|
throw new Error(`Invalid ids array length. ids() should not return an empty array`);
|
|
13
14
|
}
|
|
@@ -77,8 +78,9 @@ function getMap(props) {
|
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
79
80
|
const childrenMap = new Map();
|
|
81
|
+
const idCallback = "id" in props && props.id?.() || (item => item);
|
|
80
82
|
return {
|
|
81
|
-
getId:
|
|
83
|
+
getId: idCallback,
|
|
82
84
|
equalsId(a, b) {
|
|
83
85
|
return a === b;
|
|
84
86
|
},
|
package/lib/Nesquick.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
17
|
+
exports.Nesquick = void 0;
|
|
4
18
|
var Nesquick;
|
|
5
19
|
(function (Nesquick) {
|
|
6
20
|
function render(component, parent) {
|
|
@@ -14,6 +28,4 @@ var Nesquick;
|
|
|
14
28
|
Nesquick.render = render;
|
|
15
29
|
})(Nesquick || (exports.Nesquick = Nesquick = {}));
|
|
16
30
|
exports.default = Nesquick;
|
|
17
|
-
|
|
18
|
-
(function (JSX) {
|
|
19
|
-
})(JSX || (exports.JSX = JSX = {}));
|
|
31
|
+
__exportStar(require("./jsx-runtime"), exports);
|
package/lib/NesquickComponent.js
CHANGED
|
@@ -6,6 +6,21 @@ const SVGNamespaces = new Map([
|
|
|
6
6
|
["xlink", "http://www.w3.org/1999/xlink"],
|
|
7
7
|
["xml", "http://www.w3.org/XML/1998/namespace"]
|
|
8
8
|
]);
|
|
9
|
+
function getAttributeNs(attributes, k) {
|
|
10
|
+
const index = k.indexOf(":");
|
|
11
|
+
if (index > -1) {
|
|
12
|
+
const ns = k.substring(0, index);
|
|
13
|
+
const name = k.substring(index + 1);
|
|
14
|
+
const namespace = attributes.get(ns);
|
|
15
|
+
if (namespace != null) {
|
|
16
|
+
return {
|
|
17
|
+
namespace: namespace,
|
|
18
|
+
name: name
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
9
24
|
class NesquickComponent {
|
|
10
25
|
constructor(_render, props) {
|
|
11
26
|
this._render = _render;
|
|
@@ -14,7 +29,6 @@ class NesquickComponent {
|
|
|
14
29
|
this._styleSubscriptions = null;
|
|
15
30
|
this._xmlns = null;
|
|
16
31
|
this._children = [];
|
|
17
|
-
this.props = props;
|
|
18
32
|
}
|
|
19
33
|
render(document) {
|
|
20
34
|
State_1.subscriptions.set(this._subscriptions);
|
|
@@ -72,21 +86,6 @@ class NesquickComponent {
|
|
|
72
86
|
setXmlns(xmlns) {
|
|
73
87
|
this._xmlns = xmlns;
|
|
74
88
|
}
|
|
75
|
-
_getAttributeNs(attributes, k) {
|
|
76
|
-
const index = k.indexOf(":");
|
|
77
|
-
if (index > -1) {
|
|
78
|
-
const ns = k.substring(0, index);
|
|
79
|
-
const name = k.substring(index + 1);
|
|
80
|
-
const namespace = attributes.get(ns);
|
|
81
|
-
if (namespace != null) {
|
|
82
|
-
return {
|
|
83
|
-
namespace: namespace,
|
|
84
|
-
name: name
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
89
|
_renderPropsNs(attributes, element, props) {
|
|
91
90
|
for (const k in props) {
|
|
92
91
|
if (k !== "children" && k !== "xmlns" && k !== "ref") {
|
|
@@ -98,7 +97,7 @@ class NesquickComponent {
|
|
|
98
97
|
element[k.toLowerCase()] = props[k];
|
|
99
98
|
}
|
|
100
99
|
else {
|
|
101
|
-
const attribute =
|
|
100
|
+
const attribute = getAttributeNs(attributes, k);
|
|
102
101
|
if (attribute) {
|
|
103
102
|
(0, State_1.useRender)(props[k], v => {
|
|
104
103
|
element.setAttributeNS(attribute.namespace, attribute.name, String(v));
|
|
@@ -112,7 +111,7 @@ class NesquickComponent {
|
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
else {
|
|
115
|
-
const attribute =
|
|
114
|
+
const attribute = getAttributeNs(attributes, k);
|
|
116
115
|
if (attribute) {
|
|
117
116
|
element.setAttributeNS(attribute.namespace, attribute.name, String(props[k]));
|
|
118
117
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tsc_1 = require("./tsc");
|
|
5
|
+
const transformer_1 = require("./transformer");
|
|
6
|
+
(0, tsc_1.tsc)({
|
|
7
|
+
argv: process.argv,
|
|
8
|
+
cwd: process.cwd(),
|
|
9
|
+
transformers: {
|
|
10
|
+
before: [transformer_1.transformer]
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProject = getProject;
|
|
4
|
+
const Path = require("path");
|
|
5
|
+
function getProject(argv) {
|
|
6
|
+
let nextIsProject = false;
|
|
7
|
+
for (let i = 0; i < argv.length; i++) {
|
|
8
|
+
if (argv[i].startsWith("--")) {
|
|
9
|
+
nextIsProject = argv[i].substring(2) === "project";
|
|
10
|
+
}
|
|
11
|
+
else if (argv[i].startsWith("-")) {
|
|
12
|
+
nextIsProject = argv[i].substring(1) === "p";
|
|
13
|
+
}
|
|
14
|
+
else if (nextIsProject) {
|
|
15
|
+
return Path.resolve(process.cwd(), argv[i]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformer = void 0;
|
|
4
|
+
const TS = require("typescript");
|
|
5
|
+
function getSingleIdentifier(node) {
|
|
6
|
+
let identifier = null;
|
|
7
|
+
node.forEachChild(node => {
|
|
8
|
+
if (TS.isIdentifier(node)) {
|
|
9
|
+
if (identifier != null) {
|
|
10
|
+
return node;
|
|
11
|
+
}
|
|
12
|
+
identifier = node;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return identifier;
|
|
16
|
+
}
|
|
17
|
+
function getSingleBody(node) {
|
|
18
|
+
let body = null;
|
|
19
|
+
node.forEachChild(node => {
|
|
20
|
+
if (body != null) {
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
body = node;
|
|
24
|
+
});
|
|
25
|
+
return body;
|
|
26
|
+
}
|
|
27
|
+
function createSpreadCheckFunction(fName) {
|
|
28
|
+
const obj = TS.factory.createIdentifier("obj");
|
|
29
|
+
const check = TS.factory.createIdentifier("check");
|
|
30
|
+
const res = TS.factory.createIdentifier("res");
|
|
31
|
+
const k = TS.factory.createIdentifier("k");
|
|
32
|
+
const v = TS.factory.createIdentifier("v");
|
|
33
|
+
return TS.factory.createFunctionDeclaration(void 0, void 0, fName, void 0, [
|
|
34
|
+
TS.factory.createParameterDeclaration(void 0, void 0, obj),
|
|
35
|
+
TS.factory.createParameterDeclaration(void 0, void 0, check)
|
|
36
|
+
], void 0, TS.factory.createBlock([
|
|
37
|
+
TS.factory.createVariableStatement(void 0, TS.factory.createVariableDeclarationList([
|
|
38
|
+
TS.factory.createVariableDeclaration(res, void 0, void 0, TS.factory.createCallExpression(TS.factory.createPropertyAccessExpression(TS.factory.createIdentifier("Object"), "create"), void 0, [TS.factory.createNull()]))
|
|
39
|
+
], TS.NodeFlags.Const)),
|
|
40
|
+
TS.factory.createForInStatement(TS.factory.createVariableDeclarationList([TS.factory.createVariableDeclaration(k)], TS.NodeFlags.Const), obj, TS.factory.createBlock([
|
|
41
|
+
TS.factory.createVariableStatement(void 0, TS.factory.createVariableDeclarationList([
|
|
42
|
+
TS.factory.createVariableDeclaration(v, void 0, void 0, TS.factory.createElementAccessExpression(obj, k))
|
|
43
|
+
], TS.NodeFlags.Const)),
|
|
44
|
+
TS.factory.createIfStatement(TS.factory.createBinaryExpression(TS.factory.createPrefixUnaryExpression(TS.SyntaxKind.ExclamationToken, check), TS.factory.createToken(TS.SyntaxKind.BarBarToken), TS.factory.createBinaryExpression(TS.factory.createTypeOfExpression(v), TS.factory.createToken(TS.SyntaxKind.ExclamationEqualsEqualsToken), TS.factory.createStringLiteral("function"))), TS.factory.createBlock([
|
|
45
|
+
TS.factory.createExpressionStatement(TS.factory.createBinaryExpression(TS.factory.createElementAccessExpression(res, k), TS.factory.createToken(TS.SyntaxKind.EqualsToken), TS.factory.createArrowFunction(void 0, void 0, [], void 0, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), v)))
|
|
46
|
+
], true), TS.factory.createBlock([
|
|
47
|
+
TS.factory.createExpressionStatement(TS.factory.createBinaryExpression(TS.factory.createElementAccessExpression(res, k), TS.factory.createToken(TS.SyntaxKind.EqualsToken), v))
|
|
48
|
+
], true))
|
|
49
|
+
], true)),
|
|
50
|
+
TS.factory.createReturnStatement(res)
|
|
51
|
+
], true));
|
|
52
|
+
}
|
|
53
|
+
const transformer = context => {
|
|
54
|
+
return sourceFile => {
|
|
55
|
+
let hasSpreadChecker = false;
|
|
56
|
+
const spreadCheckerName = TS.factory.createUniqueName("_spread");
|
|
57
|
+
const processNode = (node, options) => {
|
|
58
|
+
let hasCallExpression = false;
|
|
59
|
+
node = TS.visitEachChild(node, node => {
|
|
60
|
+
const res = visitGeneric(node, options);
|
|
61
|
+
hasCallExpression = hasCallExpression || res.hasCallExpression;
|
|
62
|
+
return res.node;
|
|
63
|
+
}, context);
|
|
64
|
+
return { node, hasCallExpression };
|
|
65
|
+
};
|
|
66
|
+
const visitGeneric = (node, options) => {
|
|
67
|
+
let hasCallExpression = TS.isCallExpression(node);
|
|
68
|
+
if (TS.isJsxSpreadAttribute(node)) {
|
|
69
|
+
hasSpreadChecker = true;
|
|
70
|
+
const expression = visitGeneric(node.expression, {}).node;
|
|
71
|
+
if (TS.isExpression(expression)) {
|
|
72
|
+
const callExpression = TS.factory.createCallExpression(spreadCheckerName, void 0, [expression, options.userComponent ? TS.factory.createFalse() : TS.factory.createTrue()]);
|
|
73
|
+
node = TS.factory.updateJsxSpreadAttribute(node, callExpression);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (TS.isJsxOpeningLikeElement(node)) {
|
|
77
|
+
const firstLetter = node.tagName.getText()[0];
|
|
78
|
+
const userComponent = firstLetter !== firstLetter.toLowerCase();
|
|
79
|
+
const res = processNode(node, { userComponent });
|
|
80
|
+
node = res.node;
|
|
81
|
+
hasCallExpression = hasCallExpression || res.hasCallExpression;
|
|
82
|
+
}
|
|
83
|
+
else if (TS.isJsxAttribute(node)) {
|
|
84
|
+
node = TS.visitEachChild(node, node => {
|
|
85
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: true });
|
|
86
|
+
hasCallExpression = hasCallExpression || res.hasCallExpression;
|
|
87
|
+
return res.node;
|
|
88
|
+
}, context);
|
|
89
|
+
}
|
|
90
|
+
else if (TS.isJsxExpression(node)) {
|
|
91
|
+
node = TS.visitEachChild(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), context);
|
|
92
|
+
}
|
|
93
|
+
else if (options.isJsxAttribute && TS.isStringLiteral(node)) {
|
|
94
|
+
const returnNode = TS.visitNode(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), TS.isExpression);
|
|
95
|
+
if (TS.isStringLiteral(returnNode)) {
|
|
96
|
+
node = returnNode;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
node = TS.factory.createJsxExpression(void 0, returnNode);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
node = TS.visitEachChild(node, node => {
|
|
104
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: false });
|
|
105
|
+
hasCallExpression = hasCallExpression || res.hasCallExpression;
|
|
106
|
+
return res.node;
|
|
107
|
+
}, context);
|
|
108
|
+
}
|
|
109
|
+
return { node, hasCallExpression };
|
|
110
|
+
};
|
|
111
|
+
const visitorExpression = (node, options) => {
|
|
112
|
+
if (TS.isParenthesizedExpression(node)) {
|
|
113
|
+
const body = getSingleBody(node);
|
|
114
|
+
if (body) {
|
|
115
|
+
node = body;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (TS.isCallExpression(node)) {
|
|
119
|
+
let identifier = null;
|
|
120
|
+
if (node.arguments.length === 0 && (identifier = getSingleIdentifier(node)) != null) {
|
|
121
|
+
return visitGeneric(identifier, {}).node;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const res = visitGeneric(node, {});
|
|
125
|
+
node = res.node;
|
|
126
|
+
if (TS.isExpression(node)) {
|
|
127
|
+
if (options.userComponent || (res.hasCallExpression && !TS.isFunctionLike(node) && !TS.isJsxElement(node) && !TS.isJsxOpeningLikeElement(node))) {
|
|
128
|
+
node = TS.factory.createArrowFunction(void 0, void 0, [], void 0, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return node;
|
|
132
|
+
};
|
|
133
|
+
sourceFile = TS.visitNode(sourceFile, node => visitGeneric(node, {}).node, TS.isSourceFile);
|
|
134
|
+
if (hasSpreadChecker) {
|
|
135
|
+
sourceFile = TS.factory.updateSourceFile(sourceFile, [
|
|
136
|
+
...sourceFile.statements,
|
|
137
|
+
createSpreadCheckFunction(spreadCheckerName)
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
return sourceFile;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
exports.transformer = transformer;
|
package/lib/cli/tsc.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsc = tsc;
|
|
4
|
+
const TS = require("typescript");
|
|
5
|
+
const processArgv_1 = require("./processArgv");
|
|
6
|
+
function tsc(options) {
|
|
7
|
+
const oldDir = process.cwd();
|
|
8
|
+
try {
|
|
9
|
+
if (options.cwd !== oldDir) {
|
|
10
|
+
process.chdir(options.cwd);
|
|
11
|
+
}
|
|
12
|
+
let project = (0, processArgv_1.getProject)(options.argv);
|
|
13
|
+
if (project == null) {
|
|
14
|
+
const configPath = TS.findConfigFile(options.cwd, TS.sys.fileExists, "tsconfig.json");
|
|
15
|
+
if (configPath != null) {
|
|
16
|
+
project = configPath;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!project) {
|
|
20
|
+
throw new Error("tsconfig.json not found");
|
|
21
|
+
}
|
|
22
|
+
const res = TS.readConfigFile(project, TS.sys.readFile);
|
|
23
|
+
const formatHost = {
|
|
24
|
+
getCanonicalFileName: f => f,
|
|
25
|
+
getCurrentDirectory: TS.sys.getCurrentDirectory,
|
|
26
|
+
getNewLine: () => TS.sys.newLine,
|
|
27
|
+
};
|
|
28
|
+
if (res.error) {
|
|
29
|
+
console.error(TS.formatDiagnosticsWithColorAndContext([res.error], formatHost));
|
|
30
|
+
throw new Error(`Error reading ${project}`);
|
|
31
|
+
}
|
|
32
|
+
else if (res.config == null) {
|
|
33
|
+
throw new Error(`Error reading ${project}`);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const jsonConfig = TS.parseJsonConfigFileContent(res.config, TS.sys, options.cwd, {}, project);
|
|
37
|
+
const program = TS.createProgram({
|
|
38
|
+
options: jsonConfig.options,
|
|
39
|
+
rootNames: jsonConfig.fileNames,
|
|
40
|
+
configFileParsingDiagnostics: jsonConfig.errors
|
|
41
|
+
});
|
|
42
|
+
const preDiagnostics = TS.getPreEmitDiagnostics(program);
|
|
43
|
+
const programEmit = program.emit(void 0, void 0, void 0, void 0, options.transformers);
|
|
44
|
+
const allDiagnostics = [...preDiagnostics, ...programEmit.diagnostics, ...jsonConfig.errors];
|
|
45
|
+
if (allDiagnostics.length) {
|
|
46
|
+
console.error(TS.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost));
|
|
47
|
+
throw new Error(`Error compiling project`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
if (options.cwd !== oldDir) {
|
|
53
|
+
process.chdir(oldDir);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -16,6 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Nesquick"), exports);
|
|
18
18
|
__exportStar(require("./For/For"), exports);
|
|
19
|
+
__exportStar(require("./cli/transformer"), exports);
|
|
19
20
|
__exportStar(require("./State"), exports);
|
|
20
21
|
__exportStar(require("./NesquickFragment"), exports);
|
|
21
22
|
__exportStar(require("./NesquickComponent"), exports);
|
|
23
|
+
__exportStar(require("./jsx-runtime"), exports);
|
|
24
|
+
__exportStar(require("./plugins/viteTransformerPlugin"), exports);
|
package/lib/jsx-runtime.js
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jsx = void 0;
|
|
4
|
-
exports.functionizeProps = functionizeProps;
|
|
3
|
+
exports.JSX = exports.jsx = exports.Fragment = void 0;
|
|
5
4
|
exports.jsxs = jsxs;
|
|
6
5
|
const NesquickComponent_1 = require("./NesquickComponent");
|
|
7
6
|
const NesquickFragment_1 = require("./NesquickFragment");
|
|
8
|
-
|
|
9
|
-
function functionizeProps(props) {
|
|
10
|
-
for (const k in props) {
|
|
11
|
-
if (typeof props[k] !== "function") {
|
|
12
|
-
const v = props[k];
|
|
13
|
-
props[k] = () => v;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
7
|
+
exports.Fragment = Symbol();
|
|
17
8
|
function jsxs(type, props, key) {
|
|
18
|
-
if (type === Fragment) {
|
|
9
|
+
if (type === exports.Fragment) {
|
|
19
10
|
return new NesquickFragment_1.NesquickFragment(props.children);
|
|
20
11
|
}
|
|
21
|
-
if (
|
|
22
|
-
functionizeProps(props);
|
|
23
|
-
}
|
|
24
|
-
else if (key !== undefined) {
|
|
12
|
+
if (key !== undefined) {
|
|
25
13
|
props.key = key;
|
|
26
14
|
}
|
|
27
15
|
return new NesquickComponent_1.NesquickComponent(type, props);
|
|
28
16
|
}
|
|
29
17
|
exports.jsx = jsxs;
|
|
18
|
+
var JSX;
|
|
19
|
+
(function (JSX) {
|
|
20
|
+
})(JSX || (exports.JSX = JSX = {}));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.viteTransformerPlugin = void 0;
|
|
4
|
+
const TS = require("typescript");
|
|
5
|
+
const transformer_1 = require("../cli/transformer");
|
|
6
|
+
exports.viteTransformerPlugin = {
|
|
7
|
+
name: "nesquick-transformer",
|
|
8
|
+
enforce: "pre",
|
|
9
|
+
transform(code, id) {
|
|
10
|
+
if (id.endsWith(".ts") || id.endsWith(".tsx")) {
|
|
11
|
+
const result = TS.transpileModule(code, {
|
|
12
|
+
compilerOptions: {
|
|
13
|
+
target: TS.ScriptTarget.ESNext,
|
|
14
|
+
module: TS.ModuleKind.ESNext,
|
|
15
|
+
jsx: TS.JsxEmit.Preserve,
|
|
16
|
+
},
|
|
17
|
+
transformers: {
|
|
18
|
+
before: [transformer_1.transformer],
|
|
19
|
+
},
|
|
20
|
+
fileName: id
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
code: result.outputText,
|
|
24
|
+
map: result.sourceMapText ? JSON.parse(result.sourceMapText) : null
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
package/lib/types/For/For.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { NesquickFragment } from "../NesquickFragment";
|
|
|
3
3
|
type ChildRender<T> = (item: T, i: () => number) => JSX.Element;
|
|
4
4
|
export type ForProps<T> = {
|
|
5
5
|
each: T[];
|
|
6
|
-
children: ChildRender<T
|
|
6
|
+
children: ChildRender<NoInfer<T>>;
|
|
7
7
|
} & ({
|
|
8
8
|
ids?: never;
|
|
9
|
-
id: (item: T
|
|
9
|
+
id: (item: NoInfer<T>, i: number) => unknown;
|
|
10
10
|
} | {
|
|
11
|
-
ids: (item: T
|
|
11
|
+
ids: (item: NoInfer<T>, i: number) => unknown[];
|
|
12
12
|
id?: never;
|
|
13
13
|
} | {
|
|
14
14
|
ids?: never;
|
package/lib/types/Nesquick.d.ts
CHANGED
|
@@ -4,67 +4,4 @@ export declare namespace Nesquick {
|
|
|
4
4
|
}
|
|
5
5
|
export { Children, Child };
|
|
6
6
|
export default Nesquick;
|
|
7
|
-
|
|
8
|
-
[L in K]-?: T[K] | undefined;
|
|
9
|
-
} extends {
|
|
10
|
-
[L in K]?: T[K];
|
|
11
|
-
} ? undefined extends T[K] ? true : false : false;
|
|
12
|
-
declare const WrappedFunctionType: unique symbol;
|
|
13
|
-
type WrappedFunction<T> = (() => T) & {
|
|
14
|
-
readonly [WrappedFunctionType]?: T;
|
|
15
|
-
};
|
|
16
|
-
type UserProp<T> = T extends (...args: any[]) => any ? T : WrappedFunction<T>;
|
|
17
|
-
type UserProps<T> = {
|
|
18
|
-
readonly [K in keyof T]: K extends keyof JSX.ElementChildrenAttribute ? T[K] : HasUndefined<T, K> extends true ? UserProp<T[K] | undefined> : UserProp<Exclude<T[K], undefined>>;
|
|
19
|
-
};
|
|
20
|
-
type JSXProp<T> = T extends {
|
|
21
|
-
readonly [WrappedFunctionType]?: infer R;
|
|
22
|
-
} ? R : T;
|
|
23
|
-
type JSXProps<T> = keyof T extends never ? {} : {
|
|
24
|
-
[K in keyof T]: JSXProp<T[K]>;
|
|
25
|
-
};
|
|
26
|
-
export type Generic<T> = T extends (...args: any) => infer R ? R : T;
|
|
27
|
-
export { UserProps as Props };
|
|
28
|
-
export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
|
|
29
|
-
export declare namespace JSX {
|
|
30
|
-
export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
|
|
31
|
-
currentTarget: T2;
|
|
32
|
-
};
|
|
33
|
-
export type JSXHTMLEvent<T extends EventTarget> = {
|
|
34
|
-
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<HTMLElementEventMap[K], T>) => void;
|
|
35
|
-
};
|
|
36
|
-
export type JSXSVGEvent<T extends EventTarget> = {
|
|
37
|
-
[K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
|
|
38
|
-
};
|
|
39
|
-
export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
|
|
40
|
-
[k: string]: any;
|
|
41
|
-
style?: Style;
|
|
42
|
-
xmlns?: string | null;
|
|
43
|
-
ref?: ((el: T) => void) | null;
|
|
44
|
-
}
|
|
45
|
-
export type Style = StyleProps | string;
|
|
46
|
-
export type StyleProps = {
|
|
47
|
-
[K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
|
|
48
|
-
};
|
|
49
|
-
export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
|
|
50
|
-
export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
|
|
51
|
-
export type IntrinsicElements = {
|
|
52
|
-
[K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
|
|
53
|
-
} & {
|
|
54
|
-
[K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
|
|
55
|
-
};
|
|
56
|
-
export type Element = NesquickComponent<any>;
|
|
57
|
-
export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickComponent<any>;
|
|
58
|
-
const NotEmptyObject: unique symbol;
|
|
59
|
-
export type IntrinsicAttributes = {
|
|
60
|
-
[NotEmptyObject]?: typeof NotEmptyObject;
|
|
61
|
-
};
|
|
62
|
-
export interface ElementAttributesProperty {
|
|
63
|
-
props: {};
|
|
64
|
-
}
|
|
65
|
-
export interface ElementChildrenAttribute {
|
|
66
|
-
children: {};
|
|
67
|
-
}
|
|
68
|
-
export type LibraryManagedAttributes<_, P> = JSXProps<P>;
|
|
69
|
-
export {};
|
|
70
|
-
}
|
|
7
|
+
export * from "./jsx-runtime";
|
|
@@ -32,7 +32,6 @@ export declare class NesquickComponent<P extends ComponentProps = {}> {
|
|
|
32
32
|
constructor(_render: string | FunctionComponent<P>, props: P);
|
|
33
33
|
render(document: VeactDocument): Node;
|
|
34
34
|
setXmlns(xmlns: XmlNs | null): void;
|
|
35
|
-
private _getAttributeNs;
|
|
36
35
|
private _renderPropsNs;
|
|
37
36
|
private _renderProps;
|
|
38
37
|
private _renderStyles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getProject(argv: string[]): string | null;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export * from "./Nesquick";
|
|
2
2
|
export * from "./For/For";
|
|
3
|
+
export * from "./cli/transformer";
|
|
3
4
|
export * from "./State";
|
|
4
5
|
export * from "./NesquickFragment";
|
|
5
6
|
export * from "./NesquickComponent";
|
|
7
|
+
export * from "./jsx-runtime";
|
|
8
|
+
export * from "./plugins/viteTransformerPlugin";
|
|
@@ -1,7 +1,65 @@
|
|
|
1
1
|
import { FunctionComponent, ComponentProps, NesquickComponent } from "./NesquickComponent";
|
|
2
2
|
import { NesquickFragment } from "./NesquickFragment";
|
|
3
|
-
declare const Fragment: unique symbol;
|
|
4
|
-
export declare function functionizeProps(props: ComponentProps): void;
|
|
3
|
+
export declare const Fragment: unique symbol;
|
|
5
4
|
export declare function jsxs<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
|
|
6
5
|
export declare const jsx: typeof jsxs;
|
|
7
|
-
|
|
6
|
+
type HasUndefined<T, K extends keyof T> = {
|
|
7
|
+
[L in K]-?: T[L] | undefined;
|
|
8
|
+
} extends {
|
|
9
|
+
[L in K]?: T[L];
|
|
10
|
+
} ? undefined extends T[K] ? true : false : false;
|
|
11
|
+
declare const WrappedFunctionType: unique symbol;
|
|
12
|
+
type WrappedFunction<T> = (() => T) & {
|
|
13
|
+
readonly [WrappedFunctionType]?: T;
|
|
14
|
+
};
|
|
15
|
+
type UserProps<T> = {
|
|
16
|
+
readonly [K in keyof T]: K extends keyof JSX.ElementChildrenAttribute ? T[K] : WrappedFunction<HasUndefined<T, K> extends true ? T[K] : Exclude<T[K], undefined>>;
|
|
17
|
+
};
|
|
18
|
+
type JSXProp<T> = T extends WrappedFunction<infer R> ? R : T;
|
|
19
|
+
type JSXProps<T> = keyof T extends never ? {} : {
|
|
20
|
+
[K in keyof T]: JSXProp<T[K]>;
|
|
21
|
+
};
|
|
22
|
+
export { UserProps as Props };
|
|
23
|
+
export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
|
|
24
|
+
export declare namespace JSX {
|
|
25
|
+
export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
|
|
26
|
+
currentTarget: T2;
|
|
27
|
+
};
|
|
28
|
+
export type JSXHTMLEvent<T extends EventTarget> = {
|
|
29
|
+
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<HTMLElementEventMap[K], T>) => void;
|
|
30
|
+
};
|
|
31
|
+
export type JSXSVGEvent<T extends EventTarget> = {
|
|
32
|
+
[K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
|
|
33
|
+
};
|
|
34
|
+
export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
|
|
35
|
+
[k: string]: any;
|
|
36
|
+
style?: Style;
|
|
37
|
+
xmlns?: string | null;
|
|
38
|
+
ref?: ((el: T) => void) | null;
|
|
39
|
+
}
|
|
40
|
+
export type Style = StyleProps | string;
|
|
41
|
+
export type StyleProps = {
|
|
42
|
+
[K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
|
|
43
|
+
};
|
|
44
|
+
export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
|
|
45
|
+
export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
|
|
46
|
+
export type IntrinsicElements = {
|
|
47
|
+
[K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
|
|
48
|
+
} & {
|
|
49
|
+
[K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
|
|
50
|
+
};
|
|
51
|
+
export type Element = NesquickComponent<any>;
|
|
52
|
+
export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickComponent<any>;
|
|
53
|
+
const NotEmptyObject: unique symbol;
|
|
54
|
+
export type IntrinsicAttributes = {
|
|
55
|
+
[NotEmptyObject]?: typeof NotEmptyObject;
|
|
56
|
+
};
|
|
57
|
+
export interface ElementAttributesProperty {
|
|
58
|
+
props: {};
|
|
59
|
+
}
|
|
60
|
+
export interface ElementChildrenAttribute {
|
|
61
|
+
children: {};
|
|
62
|
+
}
|
|
63
|
+
export type LibraryManagedAttributes<_, P> = JSXProps<P>;
|
|
64
|
+
export {};
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nesquick",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "React-like library with focus on drawing performance",
|
|
5
|
-
"types": "./lib/types",
|
|
6
|
-
"main": "./lib",
|
|
5
|
+
"types": "./lib/types/index.d.ts",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
7
|
"typesVersions": {
|
|
8
8
|
"*": {
|
|
9
|
-
"
|
|
10
|
-
|
|
9
|
+
".": [
|
|
10
|
+
"./lib/types/index.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"jsx-runtime": [
|
|
13
|
+
"./lib/types/jsx-runtime.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"jsx-dev-runtime": [
|
|
16
|
+
"./lib/types/jsx-dev-runtime.d.ts"
|
|
17
|
+
]
|
|
11
18
|
}
|
|
12
19
|
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./lib/types/index.d.ts",
|
|
23
|
+
"default": "./lib/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./jsx-runtime": {
|
|
26
|
+
"types": "./lib/types/jsx-runtime.d.ts",
|
|
27
|
+
"default": "./lib/jsx-runtime.js"
|
|
28
|
+
},
|
|
29
|
+
"./jsx-dev-runtime": {
|
|
30
|
+
"types": "./lib/types/jsx-dev-runtime.d.ts",
|
|
31
|
+
"default": "./lib/jsx-dev-runtime.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"nesquick-tsc": "lib/cli/nesquick-tsc.js",
|
|
36
|
+
"ntsc": "lib/cli/nesquick-tsc.js"
|
|
37
|
+
},
|
|
13
38
|
"sideEffects": false,
|
|
14
39
|
"files": [
|
|
15
40
|
"lib/",
|
|
16
|
-
"no-transformer/",
|
|
17
41
|
"jsx-runtime.js",
|
|
18
42
|
"jsx-dev-runtime.js"
|
|
19
43
|
],
|
|
@@ -41,7 +65,7 @@
|
|
|
41
65
|
"devDependencies": {
|
|
42
66
|
"@types/jsdom": "^21.1.7",
|
|
43
67
|
"@types/node": "^22.7.8",
|
|
44
|
-
"arrange-act-assert": "^2.
|
|
68
|
+
"arrange-act-assert": "^2.10.0",
|
|
45
69
|
"jsdom": "^26.1.0",
|
|
46
70
|
"typescript": "^5.6.3"
|
|
47
71
|
}
|