ether-code 0.1.6 → 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 -220
  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,72 +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.generateNodeWithCharset(node.html)
493
- }
494
- }
495
-
496
- generateNodeWithCharset(node) {
497
- if (node.type === 'Element' && node.htmlTag === 'html') {
498
- const tag = 'html'
499
- const attributes = this.generateAttributes(node.attributes || [])
500
- this.writeLine(`<${tag}${attributes}>`)
501
- this.indent++
502
-
503
- for (const child of (node.children || [])) {
504
- if (child.htmlTag === 'head') {
505
- this.generateHeadWithCharset(child)
506
- } else {
507
- this.generateNode(child)
508
- }
509
- }
510
-
511
- this.indent--
512
- this.writeLine(`</${tag}>`)
513
- } else {
514
- this.generateNode(node)
515
- }
516
- }
517
-
518
- generateHeadWithCharset(node) {
519
- const tag = 'head'
520
- const attributes = this.generateAttributes(node.attributes || [])
521
- this.writeLine(`<${tag}${attributes}>`)
522
- this.indent++
523
-
524
- this.writeLine('<meta charset="UTF-8">')
525
-
526
- for (const child of (node.children || [])) {
527
- this.generateNode(child)
528
- }
529
-
530
- this.indent--
531
- this.writeLine(`</${tag}>`)
532
- }
533
-
534
- generateTextNode(node) {
535
- if (node.value || node.content) {
536
- this.writeLine(this.escapeHtml(node.value || node.content))
537
- }
538
- }
539
-
540
408
  generateElement(node) {
541
- let tag
542
- if (node.htmlTag && !node.htmlTag.startsWith('<')) {
543
- tag = node.htmlTag
544
- } else {
545
- const rawTag = node.tag || node.tagName || node.name
546
- tag = this.translateTag(rawTag)
547
- }
548
-
409
+ const tag = this.translateTag(node.tag || node.tagName || node.name)
549
410
  const attributes = this.generateAttributes(node.attributes || node.attrs || {})
550
411
  const isVoid = this.voidElements.includes(tag.toLowerCase())
551
412
 
@@ -585,73 +446,43 @@ class HTMLGenerator {
585
446
  }
586
447
 
587
448
  generateAttributes(attrs) {
588
- if (!attrs || (Array.isArray(attrs) && attrs.length === 0) || Object.keys(attrs).length === 0) {
449
+ if (!attrs || Object.keys(attrs).length === 0) {
589
450
  return ''
590
451
  }
591
452
 
592
453
  const parts = []
593
-
594
- if (Array.isArray(attrs)) {
595
- for (const attr of attrs) {
596
- const attrName = attr.htmlName || this.translateAttribute(attr.name)
597
- const value = attr.value
598
-
599
- if (value === true || value === '') {
600
- parts.push(attrName)
601
- } else if (value === false || value === null || value === undefined) {
602
- continue
603
- } else {
604
- parts.push(`${attrName}="${this.escapeAttr(value)}"`)
605
- }
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)
606
459
  }
607
- } else {
608
- for (const [key, value] of Object.entries(attrs)) {
609
- let attrName = this.translateAttribute(key)
610
-
611
- if (attrName.startsWith('au ') || attrName.startsWith('a la ')) {
612
- attrName = this.translateEvent(key)
613
- }
614
460
 
615
- if (value === true || value === '') {
616
- parts.push(attrName)
617
- } else if (value === false || value === null || value === undefined) {
618
- continue
619
- } else {
620
- let attrValue = this.translateAttrValue(value)
621
-
622
- if (attrName === 'type' && this.isInputType(value)) {
623
- attrValue = this.translateInputType(value)
624
- }
625
-
626
- 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)
627
470
  }
471
+
472
+ parts.push(`${attrName}="${this.escapeAttr(attrValue)}"`)
628
473
  }
629
474
  }
630
475
 
631
476
  return parts.length > 0 ? ' ' + parts.join(' ') : ''
632
477
  }
633
478
 
634
- translateAttrValue(value) {
635
- if (typeof value !== 'string') return value
636
- const lower = value.toLowerCase()
637
-
638
- const valueMap = {
639
- 'nouvelle fenetre': '_blank', 'nouvel onglet': '_blank',
640
- 'meme fenetre': '_self', 'parent': '_parent', 'haut': '_top',
641
- 'paresseux': 'lazy', 'immediat': 'eager',
642
- 'post': 'post', 'get': 'get'
643
- }
644
-
645
- return valueMap[lower] || value
646
- }
647
-
648
479
  translateEvent(event) {
649
480
  const events = {
650
481
  'au clic': 'onclick',
651
482
  'au double clic': 'ondblclick',
652
483
  'au survol': 'onmouseover',
653
484
  'au survol fin': 'onmouseout',
654
- 'souris entrée': 'onmouseenter',
485
+ 'souris entree': 'onmouseenter',
655
486
  'souris sortie': 'onmouseleave',
656
487
  'souris bas': 'onmousedown',
657
488
  'souris haut': 'onmouseup',
@@ -669,33 +500,33 @@ class HTMLGenerator {
669
500
  'au chargement': 'onload',
670
501
  'a la fermeture': 'onunload',
671
502
  'au redimensionnement': 'onresize',
672
- 'au défilement': 'onscroll',
503
+ 'au defilement': 'onscroll',
673
504
  'erreur': 'onerror',
674
505
  'lecture': 'onplay',
675
506
  'pause': 'onpause',
676
507
  'fin': 'onended',
677
- 'glisser début': 'ondragstart',
508
+ 'glisser debut': 'ondragstart',
678
509
  'glisser': 'ondrag',
679
510
  'glisser fin': 'ondragend',
680
- 'glisser entrée': 'ondragenter',
511
+ 'glisser entree': 'ondragenter',
681
512
  'glisser sortie': 'ondragleave',
682
513
  'glisser survol': 'ondragover',
683
514
  'deposer': 'ondrop',
684
515
  'copier': 'oncopy',
685
516
  'couper': 'oncut',
686
517
  'coller': 'onpaste',
687
- 'toucher début': 'ontouchstart',
518
+ 'toucher debut': 'ontouchstart',
688
519
  'toucher mouvement': 'ontouchmove',
689
520
  'toucher fin': 'ontouchend',
690
521
  'toucher annuler': 'ontouchcancel',
691
522
  'pointeur bas': 'onpointerdown',
692
523
  'pointeur haut': 'onpointerup',
693
524
  'pointeur mouvement': 'onpointermove',
694
- 'pointeur entrée': 'onpointerenter',
525
+ 'pointeur entree': 'onpointerenter',
695
526
  'pointeur sortie': 'onpointerleave',
696
527
  'roue': 'onwheel',
697
528
  'menu contextuel': 'oncontextmenu',
698
- 'animation début': 'onanimationstart',
529
+ 'animation debut': 'onanimationstart',
699
530
  'animation fin': 'onanimationend',
700
531
  'transition fin': 'ontransitionend'
701
532
  }