ether-code 0.1.5 → 0.1.7

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 (44) hide show
  1. package/cli/ether.js +1 -1
  2. package/generators/css-generator.js +42 -55
  3. package/generators/graphql-generator.js +19 -22
  4. package/generators/html-generator.js +51 -182
  5. package/generators/js-generator.js +76 -157
  6. package/generators/node-generator.js +49 -93
  7. package/generators/php-generator.js +46 -68
  8. package/generators/python-generator.js +35 -54
  9. package/generators/react-generator.js +37 -47
  10. package/generators/ruby-generator.js +59 -119
  11. package/generators/sql-generator.js +42 -63
  12. package/generators/ts-generator.js +59 -133
  13. package/i18n/i18n-css.json +147 -147
  14. package/i18n/i18n-graphql.json +6 -6
  15. package/i18n/i18n-html.json +135 -135
  16. package/i18n/i18n-js.json +107 -107
  17. package/i18n/i18n-node.json +14 -14
  18. package/i18n/i18n-php.json +177 -177
  19. package/i18n/i18n-python.json +16 -16
  20. package/i18n/i18n-react.json +97 -97
  21. package/i18n/i18n-ruby.json +22 -22
  22. package/i18n/i18n-sql.json +153 -153
  23. package/i18n/i18n-ts.json +10 -10
  24. package/lexer/ether-lexer.js +175 -34
  25. package/lexer/tokens.js +6 -6
  26. package/package.json +1 -1
  27. package/parsers/ast-css.js +0 -545
  28. package/parsers/ast-graphql.js +0 -424
  29. package/parsers/ast-html.js +0 -886
  30. package/parsers/ast-js.js +0 -750
  31. package/parsers/ast-node.js +0 -2440
  32. package/parsers/ast-php.js +0 -957
  33. package/parsers/ast-react.js +0 -580
  34. package/parsers/ast-ruby.js +0 -895
  35. package/parsers/ast-ts.js +0 -1352
  36. package/parsers/css-parser.js +0 -1981
  37. package/parsers/graphql-parser.js +0 -2011
  38. package/parsers/html-parser.js +0 -1182
  39. package/parsers/js-parser.js +0 -2564
  40. package/parsers/node-parser.js +0 -2644
  41. package/parsers/php-parser.js +0 -3037
  42. package/parsers/react-parser.js +0 -1035
  43. package/parsers/ruby-parser.js +0 -2680
  44. package/parsers/ts-parser.js +0 -3881
@@ -5,96 +5,16 @@ class HTMLGenerator {
5
5
  this.i18n = null
6
6
  this.indent = 0
7
7
  this.output = ''
8
- this.tagMap = {}
9
- this.attrMap = {}
10
- this.eventMap = {}
11
- this.inputTypeMap = {}
12
8
  this.voidElements = [
13
9
  'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
14
10
  'link', 'meta', 'param', 'source', 'track', 'wbr'
15
11
  ]
16
12
 
17
- this.buildGenericMaps()
18
-
19
13
  if (i18nPath) {
20
14
  this.loadI18n(i18nPath)
21
15
  }
22
16
  }
23
17
 
24
- buildGenericMaps() {
25
- this.tagMap = {
26
- 'division': 'div', 'paragraphe': 'p', 'portee': 'span',
27
- 'titre1': 'h1', 'titre2': 'h2', 'titre3': 'h3', 'titre4': 'h4', 'titre5': 'h5', 'titre6': 'h6',
28
- 'lien': 'a', 'image': 'img', 'bouton': 'button',
29
- 'formulaire': 'form', 'champ': 'input', 'zone texte': 'textarea',
30
- 'sélection': 'select', 'selection': 'select', 'option': 'option', 'étiquette': 'label', 'étiquette': 'label',
31
- 'liste': 'ul', 'liste ordonnée': 'ol', 'élément': 'li', 'élément liste': 'li',
32
- 'tableau': 'table', 'ligne': 'tr', 'cellule': 'td', 'entête cellule': 'th', 'entete cellule': 'th',
33
- 'corps tableau': 'tbody', 'entête tableau': 'thead', 'pied tableau': 'tfoot',
34
- 'entête': 'header', 'piedpage': 'footer', 'navigation': 'nav',
35
- 'section': 'section', 'article': 'article', 'côté': 'aside', 'principal': 'main',
36
- 'figure': 'figure', 'legende': 'figcaption',
37
- 'gras': 'strong', 'italique': 'em', 'souligne': 'u', 'barre': 's',
38
- 'code': 'code', 'preformate': 'pre', 'citation': 'blockquote',
39
- 'abreviation': 'abbr', 'temps': 'time', 'marque': 'mark',
40
- 'indice': 'sub', 'exposant': 'sup',
41
- 'video': 'video', 'audio': 'audio', 'cadre': 'iframe', 'toile': 'canvas',
42
- 'details': 'details', 'résumé': 'summary', 'resume': 'summary', 'dialogue': 'dialog',
43
- 'progression': 'progress', 'metre': 'meter',
44
- 'groupe champs': 'fieldset', 'legende groupe': 'legend',
45
- 'liste données': 'datalist', 'liste donnees': 'datalist', 'sortie': 'output',
46
- 'modele': 'template', 'emplacement': 'slot',
47
- 'saut ligne': 'br', 'ligne horizontale': 'hr', 'cesure': 'wbr', 'meta': 'meta',
48
- 'lien externe': 'link'
49
- }
50
-
51
- this.attrMap = {
52
- 'classe': 'class', 'identifiant': 'id', 'nom': 'name', 'valeur': 'value',
53
- 'type': 'type', 'adresse': 'href', 'source': 'src', 'alternatif': 'alt',
54
- 'titre': 'title', 'cible': 'target', 'relation': 'rel',
55
- 'largeur': 'width', 'hauteur': 'height',
56
- 'placeholder': 'placeholder', 'indicateur': 'placeholder',
57
- 'requis': 'required', 'desactive': 'disabled', 'lecture seule': 'readonly',
58
- 'coche': 'checked', 'selectionne': 'selected',
59
- 'minimum': 'min', 'maximum': 'max', 'pas': 'step',
60
- 'lignes': 'rows', 'colonnes': 'cols',
61
- 'fusion colonnes': 'colspan', 'fusion lignes': 'rowspan',
62
- 'pour': 'for', 'méthode': 'method', 'action': 'action',
63
- 'accepter': 'accept', 'autocomplete': 'autocomplete',
64
- 'focus auto': 'autofocus', 'motif': 'pattern',
65
- 'longueur min': 'minlength', 'longueur max': 'maxlength',
66
- 'controles': 'controls', 'boucle': 'loop', 'muet': 'muted', 'lecture auto': 'autoplay',
67
- 'editable': 'contenteditable', 'deplacable': 'draggable', 'cache': 'hidden',
68
- 'index tabulation': 'tabindex', 'langue': 'lang', 'direction': 'dir',
69
- 'chargement': 'loading', 'datetime': 'datetime',
70
- 'aria étiquette': 'aria-label', 'aria decrit par': 'aria-describedby',
71
- 'aria cache': 'aria-hidden', 'aria étendu': 'aria-expanded',
72
- 'role': 'role', 'valeur défaut': 'defaultValue', 'coché défaut': 'defaultChecked'
73
- }
74
-
75
- this.attrValueMap = {
76
- 'nouvelle fenetre': '_blank', 'nouvel onglet': '_blank',
77
- 'meme fenetre': '_self', 'parent': '_parent', 'haut': '_top',
78
- 'paresseux': 'lazy', 'immediat': 'eager'
79
- }
80
-
81
- this.eventMap = {
82
- 'au clic': 'onclick', 'au double clic': 'ondblclick',
83
- 'au changement': 'onchange', 'a la soumission': 'onsubmit',
84
- 'au survol': 'onmouseover', 'au survol fin': 'onmouseout',
85
- 'au focus': 'onfocus', 'au focus perdu': 'onblur',
86
- 'touche bas': 'onkeydown', 'touche haut': 'onkeyup',
87
- 'au chargement': 'onload', 'erreur': 'onerror'
88
- }
89
-
90
- this.inputTypeMap = {
91
- 'texte': 'text', 'mot de passe': 'password', 'courriel': 'email',
92
- 'nombre': 'number', 'case a cocher': 'checkbox', 'bouton radio': 'radio',
93
- 'fichier': 'file', 'date': 'date', 'intervalle': 'range',
94
- 'soumettre': 'submit', 'reinitialiser': 'reset', 'cache': 'hidden'
95
- }
96
- }
97
-
98
18
  loadI18n(filePath) {
99
19
  const content = fs.readFileSync(filePath, 'utf-8')
100
20
  this.i18n = JSON.parse(content)
@@ -161,7 +81,9 @@ class HTMLGenerator {
161
81
 
162
82
  translateTag(tag) {
163
83
  const lower = tag.toLowerCase()
164
- return this.tagMap[lower] || this.translateGenericTag(tag)
84
+ let result = this.tagMap[lower] || this.translateGenericTag(tag)
85
+ result = result.replace(/^<|>$/g, '').trim()
86
+ return result
165
87
  }
166
88
 
167
89
  translateAttribute(attr) {
@@ -179,14 +101,14 @@ class HTMLGenerator {
179
101
  'lien': 'link',
180
102
  'style': 'style',
181
103
  'script': 'script',
182
- 'entête': 'header',
104
+ 'entete': 'header',
183
105
  'piedpage': 'footer',
184
106
  'navigation': 'nav',
185
107
  'principal': 'main',
186
108
  'section': 'section',
187
109
  'article': 'article',
188
110
  'aside': 'aside',
189
- 'côté': 'aside',
111
+ 'cote': 'aside',
190
112
  'recherche': 'search',
191
113
  'adresse': 'address',
192
114
  'titre1': 'h1',
@@ -204,25 +126,23 @@ class HTMLGenerator {
204
126
  'figure': 'figure',
205
127
  'legende': 'figcaption',
206
128
  'liste': 'ul',
207
- 'liste ordonnée': 'ol',
208
- 'élément': 'li',
129
+ 'liste ordonnee': 'ol',
130
+ 'element': 'li',
209
131
  'definition': 'dl',
210
132
  'terme': 'dt',
211
133
  'description': 'dd',
212
134
  'tableau': 'table',
213
135
  'ligne': 'tr',
214
136
  'cellule': 'td',
215
- 'entête cellule': 'th',
216
137
  'entete cellule': 'th',
217
- 'entête tableau': 'thead',
138
+ 'entete tableau': 'thead',
218
139
  'corps tableau': 'tbody',
219
140
  'pied tableau': 'tfoot',
220
141
  'formulaire': 'form',
221
- 'étiquette': 'label',
222
- 'étiquette': 'label',
142
+ 'etiquette': 'label',
223
143
  'champ': 'input',
224
144
  'zone texte': 'textarea',
225
- 'sélection': 'select',
145
+ 'selection': 'select',
226
146
  'option': 'option',
227
147
  'groupe options': 'optgroup',
228
148
  'bouton': 'button',
@@ -264,14 +184,13 @@ class HTMLGenerator {
264
184
  'saut ligne': 'br',
265
185
  'retour ligne': 'br',
266
186
  'details': 'details',
267
- 'résumé': 'summary',
268
187
  'resume': 'summary',
269
188
  'dialogue': 'dialog',
270
189
  'menu': 'menu',
271
190
  'modele': 'template',
272
191
  'slot': 'slot',
273
192
  'emplacement': 'slot',
274
- 'données': 'data',
193
+ 'donnees': 'data',
275
194
  'metre': 'meter',
276
195
  'progression': 'progress',
277
196
  'sortie': 'output',
@@ -283,9 +202,7 @@ class HTMLGenerator {
283
202
  'wbr': 'wbr',
284
203
  'cesure': 'wbr',
285
204
  'noscript': 'noscript',
286
- 'sans script': 'noscript',
287
- 'liste données': 'datalist',
288
- 'liste donnees': 'datalist'
205
+ 'sans script': 'noscript'
289
206
  }
290
207
 
291
208
  const lower = tag.toLowerCase()
@@ -318,7 +235,7 @@ class HTMLGenerator {
318
235
  'chargement': 'loading',
319
236
  'paresseux': 'lazy',
320
237
  'action': 'action',
321
- 'méthode': 'method',
238
+ 'methode': 'method',
322
239
  'type': 'type',
323
240
  'nom': 'name',
324
241
  'valeur': 'value',
@@ -361,9 +278,9 @@ class HTMLGenerator {
361
278
  'media': 'media',
362
279
  'type media': 'media',
363
280
  'charset': 'charset',
364
- 'encodage caractères': 'charset',
365
- 'asynchrone': 'asynchrone',
366
- 'asynchrone': 'asynchrone',
281
+ 'encodage caracteres': 'charset',
282
+ 'async': 'async',
283
+ 'asynchrone': 'async',
367
284
  'defer': 'defer',
368
285
  'differer': 'defer',
369
286
  'crossorigin': 'crossorigin',
@@ -375,7 +292,7 @@ class HTMLGenerator {
375
292
  'bac a sable': 'sandbox',
376
293
  'allow': 'allow',
377
294
  'autoriser': 'allow',
378
- 'données': 'data',
295
+ 'donnees': 'data',
379
296
  'accesskey': 'accesskey',
380
297
  'touche acces': 'accesskey',
381
298
  'translate': 'translate',
@@ -383,7 +300,7 @@ class HTMLGenerator {
383
300
  'spellcheck': 'spellcheck',
384
301
  'orthographe': 'spellcheck',
385
302
  'enterkeyhint': 'enterkeyhint',
386
- 'indice entrée': 'enterkeyhint',
303
+ 'indice entree': 'enterkeyhint',
387
304
  'inputmode': 'inputmode',
388
305
  'mode saisie': 'inputmode',
389
306
  'is': 'is',
@@ -456,15 +373,17 @@ class HTMLGenerator {
456
373
 
457
374
  switch (node.type) {
458
375
  case 'Document':
459
- this.generateDocument(node)
376
+ case 'document':
377
+ if (node.children) {
378
+ for (const child of node.children) {
379
+ this.generateNode(child)
380
+ }
381
+ }
460
382
  break
461
383
  case 'Element':
462
- case 'élément':
384
+ case 'element':
463
385
  this.generateElement(node)
464
386
  break
465
- case 'TextNode':
466
- this.generateTextNode(node)
467
- break
468
387
  case 'Text':
469
388
  case 'text':
470
389
  this.generateText(node)
@@ -480,34 +399,14 @@ class HTMLGenerator {
480
399
  default:
481
400
  if (node.tag || node.tagName) {
482
401
  this.generateElement(node)
483
- } else if (node.text || node.content || node.value) {
402
+ } else if (node.text || node.content) {
484
403
  this.generateText(node)
485
404
  }
486
405
  }
487
406
  }
488
407
 
489
- generateDocument(node) {
490
- this.writeLine('<!DOCTYPE html>')
491
- if (node.html) {
492
- this.generateNode(node.html)
493
- }
494
- }
495
-
496
- generateTextNode(node) {
497
- if (node.value || node.content) {
498
- this.writeLine(this.escapeHtml(node.value || node.content))
499
- }
500
- }
501
-
502
408
  generateElement(node) {
503
- let tag
504
- if (node.htmlTag && !node.htmlTag.startsWith('<')) {
505
- tag = node.htmlTag
506
- } else {
507
- const rawTag = node.tag || node.tagName || node.name
508
- tag = this.translateTag(rawTag)
509
- }
510
-
409
+ const tag = this.translateTag(node.tag || node.tagName || node.name)
511
410
  const attributes = this.generateAttributes(node.attributes || node.attrs || {})
512
411
  const isVoid = this.voidElements.includes(tag.toLowerCase())
513
412
 
@@ -547,73 +446,43 @@ class HTMLGenerator {
547
446
  }
548
447
 
549
448
  generateAttributes(attrs) {
550
- if (!attrs || (Array.isArray(attrs) && attrs.length === 0) || Object.keys(attrs).length === 0) {
449
+ if (!attrs || Object.keys(attrs).length === 0) {
551
450
  return ''
552
451
  }
553
452
 
554
453
  const parts = []
555
-
556
- if (Array.isArray(attrs)) {
557
- for (const attr of attrs) {
558
- const attrName = attr.htmlName || this.translateAttribute(attr.name)
559
- const value = attr.value
560
-
561
- if (value === true || value === '') {
562
- parts.push(attrName)
563
- } else if (value === false || value === null || value === undefined) {
564
- continue
565
- } else {
566
- parts.push(`${attrName}="${this.escapeAttr(value)}"`)
567
- }
454
+ for (const [key, value] of Object.entries(attrs)) {
455
+ let attrName = this.translateAttribute(key)
456
+
457
+ if (attrName.startsWith('au ') || attrName.startsWith('a la ')) {
458
+ attrName = this.translateEvent(key)
568
459
  }
569
- } else {
570
- for (const [key, value] of Object.entries(attrs)) {
571
- let attrName = this.translateAttribute(key)
572
-
573
- if (attrName.startsWith('au ') || attrName.startsWith('a la ')) {
574
- attrName = this.translateEvent(key)
575
- }
576
460
 
577
- if (value === true || value === '') {
578
- parts.push(attrName)
579
- } else if (value === false || value === null || value === undefined) {
580
- continue
581
- } else {
582
- let attrValue = this.translateAttrValue(value)
583
-
584
- if (attrName === 'type' && this.isInputType(value)) {
585
- attrValue = this.translateInputType(value)
586
- }
587
-
588
- parts.push(`${attrName}="${this.escapeAttr(attrValue)}"`)
461
+ if (value === true || value === '') {
462
+ parts.push(attrName)
463
+ } else if (value === false || value === null || value === undefined) {
464
+ continue
465
+ } else {
466
+ let attrValue = value
467
+
468
+ if (attrName === 'type' && this.isInputType(value)) {
469
+ attrValue = this.translateInputType(value)
589
470
  }
471
+
472
+ parts.push(`${attrName}="${this.escapeAttr(attrValue)}"`)
590
473
  }
591
474
  }
592
475
 
593
476
  return parts.length > 0 ? ' ' + parts.join(' ') : ''
594
477
  }
595
478
 
596
- translateAttrValue(value) {
597
- if (typeof value !== 'string') return value
598
- const lower = value.toLowerCase()
599
-
600
- const valueMap = {
601
- 'nouvelle fenetre': '_blank', 'nouvel onglet': '_blank',
602
- 'meme fenetre': '_self', 'parent': '_parent', 'haut': '_top',
603
- 'paresseux': 'lazy', 'immediat': 'eager',
604
- 'post': 'post', 'get': 'get'
605
- }
606
-
607
- return valueMap[lower] || value
608
- }
609
-
610
479
  translateEvent(event) {
611
480
  const events = {
612
481
  'au clic': 'onclick',
613
482
  'au double clic': 'ondblclick',
614
483
  'au survol': 'onmouseover',
615
484
  'au survol fin': 'onmouseout',
616
- 'souris entrée': 'onmouseenter',
485
+ 'souris entree': 'onmouseenter',
617
486
  'souris sortie': 'onmouseleave',
618
487
  'souris bas': 'onmousedown',
619
488
  'souris haut': 'onmouseup',
@@ -631,33 +500,33 @@ class HTMLGenerator {
631
500
  'au chargement': 'onload',
632
501
  'a la fermeture': 'onunload',
633
502
  'au redimensionnement': 'onresize',
634
- 'au défilement': 'onscroll',
503
+ 'au defilement': 'onscroll',
635
504
  'erreur': 'onerror',
636
505
  'lecture': 'onplay',
637
506
  'pause': 'onpause',
638
507
  'fin': 'onended',
639
- 'glisser début': 'ondragstart',
508
+ 'glisser debut': 'ondragstart',
640
509
  'glisser': 'ondrag',
641
510
  'glisser fin': 'ondragend',
642
- 'glisser entrée': 'ondragenter',
511
+ 'glisser entree': 'ondragenter',
643
512
  'glisser sortie': 'ondragleave',
644
513
  'glisser survol': 'ondragover',
645
514
  'deposer': 'ondrop',
646
515
  'copier': 'oncopy',
647
516
  'couper': 'oncut',
648
517
  'coller': 'onpaste',
649
- 'toucher début': 'ontouchstart',
518
+ 'toucher debut': 'ontouchstart',
650
519
  'toucher mouvement': 'ontouchmove',
651
520
  'toucher fin': 'ontouchend',
652
521
  'toucher annuler': 'ontouchcancel',
653
522
  'pointeur bas': 'onpointerdown',
654
523
  'pointeur haut': 'onpointerup',
655
524
  'pointeur mouvement': 'onpointermove',
656
- 'pointeur entrée': 'onpointerenter',
525
+ 'pointeur entree': 'onpointerenter',
657
526
  'pointeur sortie': 'onpointerleave',
658
527
  'roue': 'onwheel',
659
528
  'menu contextuel': 'oncontextmenu',
660
- 'animation début': 'onanimationstart',
529
+ 'animation debut': 'onanimationstart',
661
530
  'animation fin': 'onanimationend',
662
531
  'transition fin': 'ontransitionend'
663
532
  }