x4js 2.0.30 → 2.0.32

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x4js",
3
- "version": "2.0.30",
3
+ "version": "2.0.32",
4
4
  "type": "module",
5
5
  "main": "src/x4.ts",
6
6
  "module": "src/x4.ts",
@@ -12,7 +12,6 @@
12
12
  "build": "x4build --watch --hmr --serve",
13
13
  "build-release": "x4build --release"
14
14
  },
15
-
16
15
  "repository": {
17
16
  "type": "git",
18
17
  "url": "git+https://github.com/rlibre/x4.git"
@@ -17,9 +17,69 @@
17
17
  @use "./shared.scss";
18
18
 
19
19
  .x4box {
20
- @extend .box;
20
+ @extend %box;
21
21
  }
22
22
 
23
23
  .x4flex {
24
- @extend .flex;
24
+ @extend %flex;
25
25
  }
26
+
27
+ @keyframes rotating {
28
+ from {
29
+ transform: rotate(0deg);
30
+ }
31
+ to {
32
+ transform: rotate(360deg);
33
+ }
34
+ }
35
+
36
+ @keyframes shaking {
37
+ 0% {
38
+ transform: rotate(-15deg)
39
+ }
40
+
41
+ 4% {
42
+ transform: rotate(15deg)
43
+ }
44
+
45
+ 8%,24% {
46
+ transform: rotate(-18deg)
47
+ }
48
+
49
+ 12%,28% {
50
+ transform: rotate(18deg)
51
+ }
52
+
53
+ 16% {
54
+ transform: rotate(-22deg)
55
+ }
56
+
57
+ 20% {
58
+ transform: rotate(22deg)
59
+ }
60
+
61
+ 32% {
62
+ transform: rotate(-12deg)
63
+ }
64
+
65
+ 36% {
66
+ transform: rotate(12deg)
67
+ }
68
+
69
+ 40% {
70
+ transform: rotate(0deg)
71
+ }
72
+ }
73
+
74
+
75
+ .x4rotate {
76
+ animation: rotating 2s linear infinite;
77
+ }
78
+
79
+ .x4shake {
80
+ animation-name: shaking;
81
+ animation-duration: 5s;
82
+ animation-iteration-count: infinite;
83
+ animation-timing-function: linear;
84
+ animation-direction: reverse;
85
+ }
@@ -17,21 +17,21 @@
17
17
  @use "../shared.scss";
18
18
 
19
19
  .x4hbox {
20
- @extend .hbox;
20
+ @extend %hbox;
21
21
  &.align-start {
22
22
  align-items: start;
23
23
  }
24
24
  }
25
25
 
26
26
  .x4vbox {
27
- @extend .vbox;
27
+ @extend %vbox;
28
28
  }
29
29
 
30
30
  .x4stackbox {
31
31
  display: flex;
32
32
 
33
33
  &>* {
34
- @extend .fit;
34
+ @extend %fit;
35
35
  position: relative !important;
36
36
  }
37
37
 
@@ -51,7 +51,7 @@
51
51
  }
52
52
 
53
53
  .x4button {
54
- @extend .hbox;
54
+ @extend %hbox;
55
55
 
56
56
  margin: 5px;
57
57
  gap: 4px;
@@ -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.ts"
18
- import { EventCallback } from '../../core/core_events.ts';
19
- import { class_ns, UnsafeHtml } from '../../core/core_tools.ts';
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.ts"
21
+ import { Icon } from "../icon/icon"
22
22
 
23
23
  import "./button.module.scss";
24
24
 
@@ -81,12 +81,12 @@
81
81
  }
82
82
 
83
83
  .week {
84
- @extend .flex;
84
+ @extend %flex;
85
85
  align-items: center;
86
86
  padding: 2px;
87
87
 
88
88
  .cell {
89
- @extend .flex;
89
+ @extend %flex;
90
90
  min-width: 28px;
91
91
  min-height: 28px;
92
92
 
@@ -94,7 +94,7 @@
94
94
  text-align: center;
95
95
 
96
96
  .text {
97
- @extend .hbox;
97
+ @extend %hbox;
98
98
 
99
99
  transition: background-color 0.3s, color 0.3s;
100
100
  justify-content: center;
@@ -27,7 +27,7 @@
27
27
  }
28
28
 
29
29
  .x4checkbox {
30
- @extend .hbox;
30
+ @extend %hbox;
31
31
 
32
32
  display: flex;
33
33
  flex-direction: row;
@@ -31,8 +31,8 @@
31
31
  }
32
32
 
33
33
  .x4dropdownlist {
34
- @extend .shadow-xl;
35
- @extend .hbox;
34
+ @extend %shadow-xl;
35
+ @extend %hbox;
36
36
 
37
37
  max-height: 250px;
38
38
  max-width: 50vw;
@@ -42,7 +42,7 @@
42
42
  border: 1px solid var( --dropdown-border );
43
43
 
44
44
  .x4listbox {
45
- @extend .flex;
45
+ @extend %flex;
46
46
 
47
47
  border: none;
48
48
  margin: 0;
@@ -65,7 +65,7 @@
65
65
  }
66
66
 
67
67
  .x4combobox {
68
- @extend .hbox;
68
+ @extend %hbox;
69
69
  margin: 5px;
70
70
  gap: 6px;
71
71
 
@@ -88,14 +88,14 @@
88
88
  }
89
89
 
90
90
  &>#edit {
91
- @extend .flex;
91
+ @extend %flex;
92
92
  border-bottom: 1px solid var( --combobox-border );
93
93
  &:focus-within {
94
94
  border-bottom-color: var( --combobox-border-focus );
95
95
  }
96
96
 
97
97
  .x4input {
98
- @extend .flex;
98
+ @extend %flex;
99
99
 
100
100
  &[readonly] {
101
101
  cursor: pointer;
@@ -22,7 +22,7 @@
22
22
  }
23
23
 
24
24
  .x4dialog {
25
- @extend .shadow-xl, .vbox;
25
+ @extend %shadow-xl, .vbox;
26
26
 
27
27
  position: absolute !important;
28
28
  background-color: white;
@@ -33,7 +33,7 @@
33
33
  background-color: var(--color-dialog-caption);
34
34
 
35
35
  & > #title {
36
- @extend .flex;
36
+ @extend %flex;
37
37
  color: var(--color-dialog-caption-text);
38
38
  font-weight: bold;
39
39
  font-size: 120%;
@@ -21,8 +21,8 @@
21
21
  }
22
22
 
23
23
  .x4form {
24
- @extend .vbox;
25
- @extend .flex;
24
+ @extend %vbox;
25
+ @extend %flex;
26
26
 
27
27
  padding: 16px;
28
28
  background-color: var( --color-form );
@@ -17,7 +17,7 @@
17
17
  @use "../shared.scss";
18
18
 
19
19
  .x4icon {
20
- @extend .hbox;
20
+ @extend %hbox;
21
21
 
22
22
  flex-shrink: 0;
23
23
  min-width: 10px;
@@ -24,7 +24,7 @@
24
24
  }
25
25
 
26
26
  .x4label {
27
- @extend .hbox;
27
+ @extend %hbox;
28
28
 
29
29
  color: var( --label-color );
30
30
  background-color: var( --label-background );
@@ -72,7 +72,7 @@
72
72
  }
73
73
 
74
74
  &.vertical {
75
- @extend .vbox;
75
+ @extend %vbox;
76
76
  }
77
77
  }
78
78
 
@@ -33,7 +33,7 @@
33
33
  }
34
34
 
35
35
  .x4listbox {
36
- @extend .vbox;
36
+ @extend %vbox;
37
37
 
38
38
  margin: 5px;
39
39
  border: 1px solid var( --listbox-border );
@@ -66,7 +66,7 @@
66
66
  }
67
67
 
68
68
  .x4item {
69
- @extend .flex;
69
+ @extend %flex;
70
70
 
71
71
  padding: 4px;
72
72
  background-color: transparent;
@@ -28,7 +28,7 @@
28
28
  }
29
29
 
30
30
  .x4menu {
31
- @extend .shadow-xxl;
31
+ @extend %shadow-xxl;
32
32
 
33
33
  position: absolute;
34
34
  overflow-y: auto;
@@ -44,7 +44,7 @@
44
44
  max-height: calc( 100vh - 32px );
45
45
 
46
46
  .x4cmenuitem {
47
- @extend .hbox;
47
+ @extend %hbox;
48
48
 
49
49
  transition: background-color 0.3s, color 0.3s;
50
50
 
@@ -82,7 +82,7 @@
82
82
  }
83
83
 
84
84
  #text {
85
- @extend .flex;
85
+ @extend %flex;
86
86
  }
87
87
 
88
88
  &.title {
@@ -26,7 +26,7 @@
26
26
  }
27
27
 
28
28
  .x4notification {
29
- @extend .shadow-xl;
29
+ @extend %shadow-xl;
30
30
 
31
31
  padding: 8px;
32
32
  border: 1px solid var(--notification-border);
@@ -40,7 +40,12 @@
40
40
  }
41
41
 
42
42
  & > .body {
43
- @extend .rel-fit;
43
+ position: relative;
44
+ left: 0;
45
+ top: 0;
46
+ right: 0;
47
+ bottom: 0;
48
+
44
49
  overflow: hidden;
45
50
  justify-content: start;
46
51
  padding: 8px;
@@ -14,25 +14,25 @@
14
14
  * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
15
  **/
16
16
 
17
- .box {
17
+ %box {
18
18
  position: relative;
19
19
  }
20
20
 
21
- .hbox {
22
- @extend .box;
21
+ %hbox {
22
+ @extend %box;
23
23
  display: flex;
24
24
  flex-direction: row;
25
25
  align-items: center;
26
26
  }
27
27
 
28
- .vbox {
29
- @extend .box;
28
+ %vbox {
29
+ @extend %box;
30
30
  display: flex;
31
31
  flex-direction: column;
32
32
  }
33
33
 
34
34
 
35
- .fit {
35
+ %fit {
36
36
  position: absolute;
37
37
  left: 0;
38
38
  top: 0;
@@ -40,16 +40,7 @@
40
40
  bottom: 0;
41
41
  }
42
42
 
43
-
44
- .rel-fit {
45
- position: relative;
46
- left: 0;
47
- top: 0;
48
- right: 0;
49
- bottom: 0;
50
- }
51
-
52
- .flex {
43
+ %flex {
53
44
  flex-grow: 1;
54
45
  flex-shrink: 0;
55
46
  flex-basis: 0;
@@ -59,83 +50,22 @@
59
50
 
60
51
  // from tailwind
61
52
 
62
- .shadow-sm {
53
+ %shadow-sm {
63
54
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
64
55
  }
65
56
 
66
- .shadow-md {
57
+ %shadow-md {
67
58
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
68
59
  }
69
60
 
70
- .shadow-lg {
61
+ %shadow-lg {
71
62
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
72
63
  }
73
64
 
74
- .shadow-xl {
65
+ %shadow-xl {
75
66
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
76
67
  }
77
68
 
78
- .shadow-xxl {
69
+ %shadow-xxl {
79
70
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 8px 10px -6px rgb(0 0 0 / 0.3);
80
71
  }
81
-
82
-
83
- @keyframes rotating {
84
- from {
85
- transform: rotate(0deg);
86
- }
87
- to {
88
- transform: rotate(360deg);
89
- }
90
- }
91
-
92
- @keyframes shaking {
93
- 0% {
94
- transform: rotate(-15deg)
95
- }
96
-
97
- 4% {
98
- transform: rotate(15deg)
99
- }
100
-
101
- 8%,24% {
102
- transform: rotate(-18deg)
103
- }
104
-
105
- 12%,28% {
106
- transform: rotate(18deg)
107
- }
108
-
109
- 16% {
110
- transform: rotate(-22deg)
111
- }
112
-
113
- 20% {
114
- transform: rotate(22deg)
115
- }
116
-
117
- 32% {
118
- transform: rotate(-12deg)
119
- }
120
-
121
- 36% {
122
- transform: rotate(12deg)
123
- }
124
-
125
- 40% {
126
- transform: rotate(0deg)
127
- }
128
- }
129
-
130
-
131
- .x4rotate {
132
- animation: rotating 2s linear infinite;
133
- }
134
-
135
- .x4shake {
136
- animation-name: shaking;
137
- animation-duration: 5s;
138
- animation-iteration-count: infinite;
139
- animation-timing-function: linear;
140
- animation-direction: reverse;
141
- }
@@ -39,7 +39,7 @@
39
39
  }
40
40
 
41
41
  textarea {
42
- @extend .flex;
42
+ @extend %flex;
43
43
 
44
44
  padding: 4px;
45
45
  outline: none;
@@ -29,7 +29,7 @@
29
29
  }
30
30
 
31
31
  .x4textedit {
32
- @extend .hbox;
32
+ @extend %hbox;
33
33
  margin: 5px;
34
34
  gap: 6px;
35
35
 
@@ -38,7 +38,7 @@
38
38
  justify-content: end;
39
39
 
40
40
  &> .x4label {
41
- @extend .hbox;
41
+ @extend %hbox;
42
42
  height: 100%;
43
43
  padding: 0;
44
44
  font-weight: 500;
@@ -51,12 +51,12 @@
51
51
  }
52
52
 
53
53
  &> #edit {
54
- @extend .hbox;
55
- @extend .flex;
54
+ @extend %hbox;
55
+ @extend %flex;
56
56
  border-bottom: 1px solid var( --textedit-border );
57
57
 
58
58
  .x4input {
59
- @extend .flex;
59
+ @extend %flex;
60
60
  outline: none;
61
61
  margin: 0;
62
62
  }
@@ -29,7 +29,7 @@
29
29
  }
30
30
 
31
31
  .x4tooltip {
32
- @extend .shadow-xl;
32
+ @extend %shadow-xl;
33
33
 
34
34
  display: flex;
35
35
  flex-direction: row;
@@ -34,7 +34,7 @@
34
34
  }
35
35
 
36
36
  .x4treeview {
37
- @extend .vbox;
37
+ @extend %vbox;
38
38
 
39
39
  overflow-y: auto;
40
40
  height: 100%;
@@ -17,7 +17,7 @@
17
17
  @use "../shared.scss";
18
18
 
19
19
  .x4scrollview {
20
- @extend .flex;
20
+ @extend %flex;
21
21
 
22
22
  position: absolute;
23
23
  height: 100%;
package/src/x4.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file x4.d.ts
3
+ * @author Etienne Cochard
4
+ * @copyright (c) 2026 R-libre ingenierie, all rights reserved.
5
+ **/
6
+
7
+ declare module "*.svg" {
8
+ const content: string;
9
+ export default content;
10
+ }
package/src/x4.scss CHANGED
@@ -14,6 +14,6 @@
14
14
  * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
15
  **/
16
16
 
17
- @use "./components/normalize.scss";
18
- @use "./components/themes.scss";
19
- @use "./components/base.scss"
17
+ @import "./components/normalize.scss";
18
+ @import "./components/themes.scss";
19
+ @import "./components/base.scss";
package/ai-comments.txt DELETED
@@ -1,97 +0,0 @@
1
- x4 se distingue des approches réactives conventionnelles.
2
- Il offre une expérience de développement qui met l'accent sur la simplicité, la performance et un contrôle affiné sur la manière dont l'interface utilisateur est construite et mise à jour.
3
-
4
- Voici les avantages qui découlent de cette philosophie :
5
-
6
- - Abstraction du DOM, mais avec une philosophie distincte :
7
- Contrairement aux frameworks réactifs qui utilisent un Virtual DOM et des mécanismes de réconciliation
8
- pour abstraire les manipulations du DOM, x4 propose une abstraction différente.
9
- L'objectif n'est pas d'imiter le fonctionnement des frameworks populaires, mais de fournir une manière plus directe, plus légère et plus performante
10
- d'interagir avec les concepts de l'interface utilisateur. Cette abstraction est conçue pour être moins "magique" et plus prévisible.
11
-
12
- - Performance optimisée :
13
- En concevant son propre modèle d'abstraction et de mise à jour du DOM, x4 vise à atteindre une performance brute supérieure.
14
- Il peut s'affranchir de certaines complexités inhérentes aux approches réactives pour se concentrer sur l'essentiel,
15
- offrant ainsi une expérience utilisateur fluide même dans des applications exigeantes.
16
-
17
- - Un écosystème TypeScript pur :
18
- Pour garantir une robustesse et une maintenabilité maximales, ce framework élimine tout mélange de syntaxe déclarative comme JSX/TSX avec du code JavaScript.
19
- L'intégralité de la création d'interfaces et de la logique applicative est réalisée en TypeScript natif.
20
- Cela permet de bénéficier pleinement des avantages du typage fort, de la vérification à la compilation, et d'une expérience de développement cohérente et sécurisée.
21
-
22
- - Gestion de l'état et des références simplifiée :
23
- Ce framework s'affranchit des concepts comme useRef ou des "hooks" tels qu'on les trouve dans d'autres écosystèmes.
24
- La gestion des états et des références est intégrée de manière plus directe et idiomatique à sa propre architecture, favorisant une logique plus linéaire et plus facile à suivre.
25
-
26
- - Conçu pour les applications complètes :
27
- Plutôt que de se concentrer uniquement sur des composants UI isolés, ce framework est orienté vers la construction d'applications complètes.
28
- Il offre les outils et la structure nécessaires pour gérer des architectures plus vastes, de la gestion des routes à l'état global.
29
-
30
- - Compatibilité avec les Web Workers :
31
- Afin d'optimiser les performances et de permettre des traitements asynchrones intensifs sans bloquer le thread principal,
32
- ce framework est conçu pour être compatible avec les Web Workers. Cela ouvre la voie à des applications plus réactives et performantes, en déportant les tâches lourdes.
33
-
34
- - Environnement de compilation et outils spécifiques :
35
- Le développement avec ce framework est accéléré par un environnement de compilation ultra-rapide, basé sur esbuild.
36
- De plus, il est livré avec un outils spécifiques X4Build qui améliore l'expérience développeur.
37
- ainsi qu'une expérience de Hot Module Replacement (HMR) fluide et efficace pour des itérations rapides.
38
-
39
- - Modèle de développement éprouvé :
40
- L'architecture et les pratiques recommandées par ce framework constituent un modèle de développement éprouvé.
41
- Il facilite notamment des scénarios avancés comme les evenements distribués via WebSocket directement intégré (si besoin) dans l'application,
42
-
43
- - Création de composants intuitive :
44
- La manière dont x4 abstrait le DOM et gère la réactivité rend la création de composants d'une simplicité déconcertante.
45
- Vous pouvez construire des interfaces modulaires et réutilisables avec une facilité remarquable, en vous concentrant sur la logique métier plutôt
46
- que sur la gestion complexe des interactions DOM.
47
-
48
- - Accélération Drastique du Développement :
49
- Avec plus de 50 composants prêts à l'emploi, les développeurs peuvent assembler des interfaces utilisateur complexes et fonctionnelles
50
- à une vitesse remarquable. Plutôt que de passer du temps à concevoir et implémenter des éléments de base comme des buttons, des inputs, des checkboxes ou des sliders,
51
- ils peuvent les utiliser directement. Ceci libère un temps précieux pour se concentrer sur la logique métier spécifique de l'application.
52
-
53
- Le développement "from scratch" de tels composants est coûteux en temps et en ressources. La richesse de cette bibliothèque élimine ce fardeau,
54
- réduisant ainsi les efforts de conception, de codage, de test et de maintenance de ces éléments d'interface fondamentaux.
55
- Cela signifie moins de code à écrire, moins de bugs potentiels et une meilleure productivité globale.
56
-
57
- - Richesse et Diversité des Interfaces Utilisateur :
58
- La large gamme de composants permet de créer des expériences utilisateur très riches et interactives sans avoir à intégrer de bibliothèques
59
- tierces supplémentaires pour des fonctionnalités de base. Des composants sophistiqués comme gridview (pour l'affichage de données tabulaires), spreadsheet (pour des fonctionnalités de tableur complètes),
60
- calendar, colorpicker, dialog, treeview ou progress sont inclus, offrant une boîte à outils complète pour des applications métier complexes ou des tableaux de bord interactifs.
61
-
62
- - Cohérence et Qualité :
63
- L'utilisation de composants d'un même framework assure une cohérence visuelle et comportementale à travers toute l'application.
64
- Ces composants sont testés et optimisés, garantissant une meilleure qualité et une expérience utilisateur plus fiable dès le départ.
65
- En somme, cette collection de composants est un avantage concurrentiel énorme.
66
-
67
-
68
-
69
-
70
-
71
-
72
- You are a TypeScript/JavaScript documentation assistant.
73
- Your task is to generate **JSDoc comments** for public APIs in the provided code.
74
- Follow these rules strictly:
75
-
76
- ### Rules:
77
- 1. **Only document public APIs**:
78
- - Public classes, methods, properties, and events.
79
- - Ignore private/protected/internal members (e.g., `_privateField`, `#privateMethod`).
80
-
81
- 2. **Output format**:
82
- - Generate **only JSDoc blocks** (no code repetition).
83
- - Use **inline comments** (`/** ... */`) for brevity.
84
- - Do not include `@class` or `@extends` (JSDoc infers these).
85
- - Document in english
86
-
87
- 3. **Content guidelines**:
88
- - Describe **purpose, behavior, and usage** (not implementation).
89
- - Mention auto-generated CSS classes (e.g., `Button → x4button`).
90
- - Include `@example` where helpful.
91
- - Be concise, clear, and professional.
92
-
93
- Avoid:
94
-
95
- Implementation details.
96
- Private/protected members.
97
- Redundant or repetitive descriptions.
File without changes
package/prepack.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { rm } from 'node:fs/promises';
2
- await rm('lib', { recursive: true, force: true });
3
- console.log('lib/ supprimé → package source-only ✓');
@@ -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
-