x4js 2.0.30 → 2.0.31
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/package.json +1 -1
- package/src/components/button/button.ts +4 -4
- package/src/x4.d.ts +10 -0
- package/prepack.mjs +0 -3
- package/scripts/prepack.mjs +0 -342
package/package.json
CHANGED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
15
|
**/
|
|
16
16
|
|
|
17
|
-
import { Component, ComponentEvents, ComponentProps, EvClick } from "../../core/component
|
|
18
|
-
import { EventCallback } from '../../core/core_events
|
|
19
|
-
import { class_ns, UnsafeHtml } from '../../core/core_tools
|
|
17
|
+
import { Component, ComponentEvents, ComponentProps, EvClick } from "../../core/component"
|
|
18
|
+
import { EventCallback } from '../../core/core_events';
|
|
19
|
+
import { class_ns, UnsafeHtml } from '../../core/core_tools';
|
|
20
20
|
|
|
21
|
-
import { Icon } from "../icon/icon
|
|
21
|
+
import { Icon } from "../icon/icon"
|
|
22
22
|
|
|
23
23
|
import "./button.module.scss";
|
|
24
24
|
|
package/src/x4.d.ts
ADDED
package/prepack.mjs
DELETED
package/scripts/prepack.mjs
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
import * as path from "node:path"
|
|
5
|
-
import chalk from "chalk"
|
|
6
|
-
import * as ts from 'typescript';
|
|
7
|
-
|
|
8
|
-
import { execSync } from "node:child_process";
|
|
9
|
-
|
|
10
|
-
function readJSON(fname) {
|
|
11
|
-
let cpath = process.cwd();
|
|
12
|
-
|
|
13
|
-
// check here
|
|
14
|
-
let pth = path.join(cpath, fname);
|
|
15
|
-
|
|
16
|
-
if (fs.existsSync(pth)) {
|
|
17
|
-
const raw = fs.readFileSync(pth, "utf-8");
|
|
18
|
-
return JSON.parse(raw);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
throw new Error(`cannot find ${fname}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function readPackage() {
|
|
25
|
-
return readJSON("package.json");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class DTSGenerator {
|
|
32
|
-
|
|
33
|
-
output = null;
|
|
34
|
-
|
|
35
|
-
emit( lvl, code ) {
|
|
36
|
-
this.output.write( '\t'.repeat(lvl)+code );
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
genMethodSig(node, source, ctor) {
|
|
44
|
-
|
|
45
|
-
const name = ctor ? "constructor" : (node.name ? node.name.getText(source) : 'new');
|
|
46
|
-
|
|
47
|
-
const typeParameters = node.typeParameters
|
|
48
|
-
? `<${node.typeParameters.map(param => param.getText(source)).join(', ')}>`
|
|
49
|
-
: '';
|
|
50
|
-
|
|
51
|
-
const parameters = node.parameters?.map(param => {
|
|
52
|
-
const paramName = param.name.getText(source);
|
|
53
|
-
const paramType = param.type ? param.type.getText(source) : 'any';
|
|
54
|
-
return `${paramName}: ${paramType}`;
|
|
55
|
-
}).join(', ');
|
|
56
|
-
|
|
57
|
-
const returnType = ctor ? '' : `: ${node.type ? node.type.getText(source) : 'void'}`;
|
|
58
|
-
|
|
59
|
-
this.emit( 2, `${name}${typeParameters}( ${parameters} )${returnType};\n` );
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
genPropSig( node, source ) {
|
|
67
|
-
const name = node.name ? node.name.getText(source) : 'unknown';
|
|
68
|
-
const type = node.type ? node.type.getText(source) : 'any';
|
|
69
|
-
const isOptional = node.questionToken ? '?' : '';
|
|
70
|
-
this.emit( 2, `${name}${isOptional}: ${type};\n` );
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
genClassSig(node, source) {
|
|
78
|
-
|
|
79
|
-
const cname = node.name.getText(source);
|
|
80
|
-
const modifiers = node.modifiers ? node.modifiers.map(mod => mod.getText(source)).join(' ') : '';
|
|
81
|
-
|
|
82
|
-
const heritage = node.heritageClauses ? node.heritageClauses.map(clause => {
|
|
83
|
-
const typeText = clause.types.map(type => type.getText(source)).join(', ');
|
|
84
|
-
return clause.token === ts.SyntaxKind.ExtendsKeyword ? `extends ${typeText}` : `implements ${typeText}`;
|
|
85
|
-
}).join(' ') : '';
|
|
86
|
-
|
|
87
|
-
const typeParameters = node.typeParameters ? `<${node.typeParameters.map(param => param.getText(source)).join(', ')}>` : '';
|
|
88
|
-
|
|
89
|
-
this.emit( 1, `${modifiers} class ${cname}${typeParameters} ${heritage} {\n` );
|
|
90
|
-
|
|
91
|
-
ts.forEachChild(node, (x) => {
|
|
92
|
-
|
|
93
|
-
if (ts.isPropertyDeclaration(x)) {
|
|
94
|
-
const name = x.name ? x.name.getText(source) : 'unknown';
|
|
95
|
-
const type = x.type ? x.type.getText(source) : 'any';
|
|
96
|
-
const isOptional = x.questionToken ? '?' : '';
|
|
97
|
-
this.emit( 2, `${name}${isOptional}: ${type};\n` );
|
|
98
|
-
}
|
|
99
|
-
else if (ts.isMethodDeclaration(x)) {
|
|
100
|
-
this.genMethodSig(x, source, false);
|
|
101
|
-
}
|
|
102
|
-
else if (ts.isConstructorDeclaration(x)) {
|
|
103
|
-
this.genMethodSig(x, source, true);
|
|
104
|
-
}
|
|
105
|
-
else if (ts.isPropertySignature(x)) {
|
|
106
|
-
this.genPropSig( x, source );
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
//debugger;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
this.emit( 1, "}\n\n" );
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
genInterfaceSig(node, source) {
|
|
121
|
-
const name = node.name.getText(source);
|
|
122
|
-
const modifiers = node.modifiers ? node.modifiers.map(mod => mod.getText(source)).join(' ') + ' ' : '';
|
|
123
|
-
const heritage = node.heritageClauses ? node.heritageClauses.map(clause => {
|
|
124
|
-
const typeText = clause.types.map(type => type.getText(source)).join(', ');
|
|
125
|
-
return clause.token === ts.SyntaxKind.ExtendsKeyword ? `extends ${typeText}` : `implements ${typeText}`;
|
|
126
|
-
}).join(' ') : '';
|
|
127
|
-
|
|
128
|
-
const typeParameters = this.genTypeParams( node.typeParameters, source );
|
|
129
|
-
|
|
130
|
-
this.emit( 1, `${modifiers}interface ${name}${typeParameters} ${heritage} {\n` );
|
|
131
|
-
|
|
132
|
-
ts.forEachChild(node, (x) => {
|
|
133
|
-
|
|
134
|
-
if (ts.isPropertySignature(x)) {
|
|
135
|
-
const name = x.name ? x.name.getText(source) : 'unknown';
|
|
136
|
-
const type = x.type ? x.type.getText(source) : 'any';
|
|
137
|
-
const isOptional = x.questionToken ? '?' : '';
|
|
138
|
-
this.emit( 2, `${name}${isOptional}: ${type};\n` );
|
|
139
|
-
}
|
|
140
|
-
else if (ts.isMethodSignature(x)) {
|
|
141
|
-
this.genMethodSig(x, source, false);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
this.emit( 1, "}\n\n" );
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
*
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
genTypeParams( node, source ) {
|
|
153
|
-
return node ? `<${node.map(param => param.getText(source)).join(', ')}>` : '';
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
genTypeDefinition(node, source) {
|
|
161
|
-
const typeName = node.name.getText(source);
|
|
162
|
-
const params = this.genTypeParams( node.typeParameters, source );
|
|
163
|
-
|
|
164
|
-
// pb if complex types
|
|
165
|
-
//const typeDefinition = node.type ? node.type.getText(source) : '';
|
|
166
|
-
|
|
167
|
-
this.emit( 1, `type ${typeName}${params} = ` );
|
|
168
|
-
|
|
169
|
-
if (ts.isTypeLiteralNode(node.type)) {
|
|
170
|
-
this.emit( 0, `{\n` );
|
|
171
|
-
|
|
172
|
-
node.type.members.forEach( member => {
|
|
173
|
-
if( ts.isMethodSignature(member) || ts.isConstructSignatureDeclaration(member) ) {
|
|
174
|
-
this.genMethodSig( member, source );
|
|
175
|
-
}
|
|
176
|
-
else if( ts.isPropertySignature(member) ) {
|
|
177
|
-
this.genPropSig( member, source );
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
this.emit( 1, `}\n\n` );
|
|
182
|
-
}
|
|
183
|
-
else if ( ts.isUnionTypeNode(node.type) || ts.isIntersectionTypeNode(node.type) ) {
|
|
184
|
-
const operator = ts.isUnionTypeNode(node.type) ? ' | ' : ' & ';
|
|
185
|
-
const typeDefinition = node.type.types.map(t => t.getText(source)).join(operator);
|
|
186
|
-
this.emit( 0, `${typeDefinition};\n\n` );
|
|
187
|
-
}
|
|
188
|
-
else if (ts.isArrayTypeNode(node.type)) {
|
|
189
|
-
// Gérer les tableaux
|
|
190
|
-
const typeDefinition = `${node.type.elementType.getText(source)}[]`;
|
|
191
|
-
debugger;
|
|
192
|
-
this.emit( 0, `${typeDefinition};\n\n` );
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
// Pour les autres types (primitifs, tuples, etc.)
|
|
196
|
-
const typeDefinition = node.type.getText(source);
|
|
197
|
-
this.emit( 0, `${typeDefinition};\n\n` );
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
*/
|
|
206
|
-
|
|
207
|
-
genEnumDefinition(node,source) {
|
|
208
|
-
|
|
209
|
-
const ename = node.name.getText(source);
|
|
210
|
-
|
|
211
|
-
this.emit( 1, `enum ${ename} {\n`);
|
|
212
|
-
|
|
213
|
-
node.members.forEach( member => {
|
|
214
|
-
const memberName = member.name.getText(source);
|
|
215
|
-
const memberValue = member.initializer ? ` = ${member.initializer.getText(source)}` : '';
|
|
216
|
-
this.emit( 2, `${memberName}${memberValue},\n` );
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// Assembler la définition complète
|
|
220
|
-
this.emit( 1, `}\n\n`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
*
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
visitNode(node, source) {
|
|
228
|
-
if (ts.isInterfaceDeclaration(node)) {
|
|
229
|
-
this.genInterfaceSig(node, source);
|
|
230
|
-
}
|
|
231
|
-
else if (ts.isClassDeclaration(node)) {
|
|
232
|
-
this.genClassSig(node, source);
|
|
233
|
-
}
|
|
234
|
-
else if (ts.isTypeAliasDeclaration(node)) {
|
|
235
|
-
this.genTypeDefinition(node, source );
|
|
236
|
-
}
|
|
237
|
-
else if (ts.isEnumDeclaration(node)) {
|
|
238
|
-
this.genEnumDefinition(node, source );
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
ts.forEachChild(node, (x) => this.visitNode(x, source));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* rz=eally quick and dirty dts generator
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
async build( output_path ) {
|
|
250
|
-
|
|
251
|
-
this.output = fs.createWriteStream(output_path, {});
|
|
252
|
-
|
|
253
|
-
this.emit( 0, `/** \n`);
|
|
254
|
-
this.emit( 0, ` * ___ ___ __\n`);
|
|
255
|
-
this.emit( 0, ` * \\ \\/ / / _\n`);
|
|
256
|
-
this.emit( 0, ` * \\ / /_| |_\n`);
|
|
257
|
-
this.emit( 0, ` * / \\____ _| \n`);
|
|
258
|
-
this.emit( 0, ` * /__/\\__\\ |_|\n`);
|
|
259
|
-
this.emit( 0, ` * \n`);
|
|
260
|
-
this.emit( 0, ` * @author Etienne Cochard \n`);
|
|
261
|
-
this.emit( 0, ` * @copyright (c) 2024 R-libre ingenierie\n`);
|
|
262
|
-
this.emit( 0, ` *\n`);
|
|
263
|
-
this.emit( 0, ` * Use of this source code is governed by an MIT-style license \n`);
|
|
264
|
-
this.emit( 0, ` * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.\n`);
|
|
265
|
-
this.emit( 0, ` *\n` );
|
|
266
|
-
this.emit( 0, ` * AUTOGENERATED CODE, DO NOT MODIFY\n` );
|
|
267
|
-
this.emit( 0, ` * generated on ${new Date().toDateString()}\n` );
|
|
268
|
-
this.emit( 0, ` */\n\n\n` );
|
|
269
|
-
|
|
270
|
-
this.emit( 0, "declare module 'x4js' {\n\n");
|
|
271
|
-
|
|
272
|
-
const inputFiles = ["src/x4.ts", "src/custom.d.ts"];
|
|
273
|
-
const compilerOptions = readJSON("tsconfig.json");
|
|
274
|
-
|
|
275
|
-
compilerOptions.declaration = true;
|
|
276
|
-
|
|
277
|
-
const host = ts.createCompilerHost(compilerOptions);
|
|
278
|
-
const program = ts.createProgram(inputFiles, compilerOptions, host);
|
|
279
|
-
|
|
280
|
-
const cwd = process.cwd().replaceAll("\\", "/");
|
|
281
|
-
const mod_path = cwd + "/node_modules";
|
|
282
|
-
|
|
283
|
-
program.getSourceFiles().forEach((sourceFile) => {
|
|
284
|
-
|
|
285
|
-
let pth = sourceFile.fileName;
|
|
286
|
-
if (pth.startsWith(mod_path)) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
else if( !pth.startsWith(cwd) ) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
pth = pth.substring(cwd.length);
|
|
294
|
-
|
|
295
|
-
this.emit(1,`// ---------------------------------------\n` );
|
|
296
|
-
this.emit(1,`// from ${pth}\n\n`);
|
|
297
|
-
|
|
298
|
-
this.visitNode(sourceFile, sourceFile);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
this.emit(0,"}\n\n");
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
async function main() {
|
|
307
|
-
|
|
308
|
-
const pkg = readPackage();
|
|
309
|
-
|
|
310
|
-
console.log(chalk.yellow("-- prepack ------------------------"))
|
|
311
|
-
|
|
312
|
-
fs.mkdirSync('lib/styles', { recursive: true });
|
|
313
|
-
fs.mkdirSync('lib/types', { recursive: true });
|
|
314
|
-
|
|
315
|
-
console.log(chalk.green("building esm..."));
|
|
316
|
-
execSync("npx x4build --release --outdir=lib/esm");
|
|
317
|
-
|
|
318
|
-
console.log(chalk.green("building cjs..."));
|
|
319
|
-
execSync("npx x4build --release --cjs --outdir=lib/cjs");
|
|
320
|
-
|
|
321
|
-
console.log(chalk.green("creating .d.ts..."));
|
|
322
|
-
|
|
323
|
-
const generator = new DTSGenerator( );
|
|
324
|
-
await generator.build( "lib/types/x4js.d.ts" );
|
|
325
|
-
|
|
326
|
-
console.log(chalk.green("copying dependencies..."));
|
|
327
|
-
|
|
328
|
-
fs.cpSync('lib/esm/x4.css', 'lib/styles/x4.css');
|
|
329
|
-
fs.renameSync('lib/esm/x4.js', 'lib/esm/x4.mjs');
|
|
330
|
-
|
|
331
|
-
console.log(chalk.yellow("-----------------------------------"))
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
main( );
|
|
335
|
-
|
|
336
|
-
//(async function tt( ) {
|
|
337
|
-
//const generator = new DTSGenerator( );
|
|
338
|
-
// await generator.build( "output.d.ts" );
|
|
339
|
-
//})( );
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|