@nldd/design-system 0.27.0 → 0.27.1

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 (205) hide show
  1. package/custom-elements.json +32 -0
  2. package/dist/cdn/autoloader.js +141 -141
  3. package/dist/cdn/chunks/{accordion-item-D90CmJyl.js → accordion-item-Db9LW8AG.js} +4 -4
  4. package/dist/cdn/chunks/{accordion-DBM4AcGb.js → accordion-tLICRUFs.js} +4 -4
  5. package/dist/cdn/chunks/{activity-indicator-B6m9h0oa.js → activity-indicator-CMNIikEV.js} +5 -5
  6. package/dist/cdn/chunks/{admonition-B-YTkCjn.js → admonition-DEXVkTJm.js} +4 -4
  7. package/dist/cdn/chunks/{avatar-group-DW_xMwb_.js → avatar-group-DMU0HLBL.js} +15 -15
  8. package/dist/cdn/chunks/{avatar-CfBP9UZZ.js → avatar-nLrlfh4s.js} +6 -6
  9. package/dist/cdn/chunks/{badge-DnAuIhp1.js → badge-D1XadmOE.js} +5 -5
  10. package/dist/cdn/chunks/{banner-CRk2ARtC.js → banner-B4kFQlHx.js} +7 -7
  11. package/dist/cdn/chunks/{bar-split-view-DDgOYs7Z.js → bar-split-view-DtD4zmoP.js} +5 -5
  12. package/dist/cdn/chunks/{blockquote-DlfhBScg.js → blockquote-DbFjwox8.js} +3 -3
  13. package/dist/cdn/chunks/{box-DdU13yI4.js → box-BlwaDicI.js} +3 -3
  14. package/dist/cdn/chunks/{breadcrumbs-CqkR_6XN.js → breadcrumbs-DJS9-8wX.js} +5 -5
  15. package/dist/cdn/chunks/{button-muXGJHlo.js → button-BK8CmshL.js} +8 -8
  16. package/dist/cdn/chunks/{button-bar-BKkap9nk.js → button-bar-5RtXjgGl.js} +3 -3
  17. package/dist/cdn/chunks/{button-group-D-YTmErV.js → button-group-BYMkQNhT.js} +2 -2
  18. package/dist/cdn/chunks/{card-Dvqz83fC.js → card-NNl0PxBY.js} +4 -4
  19. package/dist/cdn/chunks/{cell-C0O8tZbX.js → cell-D2NzCBVZ.js} +6 -6
  20. package/dist/cdn/chunks/{checkbox-CNWROiHV.js → checkbox-CXFA_up4.js} +5 -5
  21. package/dist/cdn/chunks/{checkbox-field-DCYpRJfz.js → checkbox-field-sFs7GvAq.js} +7 -7
  22. package/dist/cdn/chunks/{checkbox-group-DxWAYp_b.js → checkbox-group-BPN4eRCX.js} +3 -3
  23. package/dist/cdn/chunks/{class-map-D720ceWJ.js → class-map-1XjgYGeg.js} +1 -1
  24. package/dist/cdn/chunks/{code-editor-DlnTXkHx.js → code-editor-KZEaMAN7.js} +5 -5
  25. package/dist/cdn/chunks/{code-viewer-DyJzo36-.js → code-viewer-CJwpLKb1.js} +7 -7
  26. package/dist/cdn/chunks/{codemirror-input-DPSOMYZ4.js → codemirror-input-CYBNNf0-.js} +5 -5
  27. package/dist/cdn/chunks/{collection-i7H8zkQ8.js → collection-BdUB8qeL.js} +8 -8
  28. package/dist/cdn/chunks/{combo-box-CpNl_us0.js → combo-box-DxWW-zeE.js} +9 -9
  29. package/dist/cdn/chunks/{container-YWW7mHNa.js → container-Dhf1Ahi8.js} +2 -2
  30. package/dist/cdn/chunks/{custom-element-D8yf5dqU.js → custom-element-DtLjpays.js} +1 -1
  31. package/dist/cdn/chunks/{date-field-DzhUp4Rk.js → date-field-D83r9gjY.js} +12 -12
  32. package/dist/cdn/chunks/{date-picker-CGvsvK3g.js → date-picker-D8qv2iuG.js} +10 -10
  33. package/dist/cdn/chunks/{decorate-1aEyfetK.js → decorate-BhnGmemK.js} +1 -1
  34. package/dist/cdn/chunks/{described-by-mixin-DffYoaxu.js → described-by-mixin-Jh_PTTde.js} +2 -2
  35. package/dist/cdn/chunks/{description-cell-DEw6xc2o.js → description-cell-nQKMluy8.js} +6 -6
  36. package/dist/cdn/chunks/{dev-checks-CTopJcdE.js → dev-checks-Bet7bhMS.js} +87 -49
  37. package/dist/cdn/chunks/{directive-helpers-BQml5ahH.js → directive-helpers-dLE2M1R1.js} +1 -1
  38. package/dist/cdn/chunks/{dist-DAf6EMuK.js → dist-BTuJ-NyU.js} +2 -2
  39. package/dist/cdn/chunks/{dist-B5t9fS8q.js → dist-BbwC3zHR.js} +2 -2
  40. package/dist/cdn/chunks/{dist-BYbLHkMP.js → dist-BpqJqkl_.js} +1 -1
  41. package/dist/cdn/chunks/{dist-D59Ae7dj.js → dist-C9xmfEc_.js} +1 -1
  42. package/dist/cdn/chunks/{dist-CIX4JLW1.js → dist-CYKK2xXE.js} +3 -3
  43. package/dist/cdn/chunks/{dist-DevfJ4Mu.js → dist-Cdmhq-4P.js} +2 -2
  44. package/dist/cdn/chunks/{dist-BKnqQxdv.js → dist-DJSiRJRL.js} +1 -1
  45. package/dist/cdn/chunks/{dist-C8ZY_QIK.js → dist-DwevYbXo.js} +1 -1
  46. package/dist/cdn/chunks/{dist-B87Ag4L-.js → dist-Dzlvec4O.js} +1 -1
  47. package/dist/cdn/chunks/{dist-qHSPGfTO.js → dist-EP5KATv0.js} +1 -1
  48. package/dist/cdn/chunks/{dist-Cr8NctvS.js → dist-u6MS5-M8.js} +3 -3
  49. package/dist/cdn/chunks/{divider-44rkHLYj.js → divider-DjT76fuO.js} +2 -2
  50. package/dist/cdn/chunks/{document-tab-bar-CcSKzhEy.js → document-tab-bar-CO2M1bFc.js} +9 -9
  51. package/dist/cdn/chunks/{dropdown-CJPjI-p1.js → dropdown-CdQ1beF2.js} +5 -5
  52. package/dist/cdn/chunks/{file-field-B4HQKpkI.js → file-field-D0UlnM9R.js} +13 -13
  53. package/dist/cdn/chunks/{form-obggZEpt.js → form-BV9wifov.js} +1 -1
  54. package/dist/cdn/chunks/{form-actions-HaBfh6vm.js → form-actions-DDeF8urg.js} +2 -2
  55. package/dist/cdn/chunks/{form-associated-mixin-BByNH679.js → form-associated-mixin-Cm1N24gR.js} +2 -2
  56. package/dist/cdn/chunks/{form-field-CwYXsuvv.js → form-field-IeKadcwe.js} +5 -5
  57. package/dist/cdn/chunks/{form-section-B2UZx_-z.js → form-section-C350G5wg.js} +1 -1
  58. package/dist/cdn/chunks/{full-bleed-section-BSnWghWY.js → full-bleed-section-CR3zsX7K.js} +3 -3
  59. package/dist/cdn/chunks/{hero-CzbuEAUM.js → hero-Ch5el5J5.js} +4 -4
  60. package/dist/cdn/chunks/{icon-CkCT7sPE.js → icon-Dj98ov4G.js} +2 -2
  61. package/dist/cdn/chunks/{icon-button-BBGwCfYp.js → icon-button-HKoCqWG3.js} +9 -9
  62. package/dist/cdn/chunks/{icon-cell-DcHnXV-8.js → icon-cell-C1I-oIWn.js} +5 -5
  63. package/dist/cdn/chunks/{identity-C0fujsxK.js → identity-DNkEDJ8m.js} +6 -6
  64. package/dist/cdn/chunks/{if-defined-CL4nn-Q-.js → if-defined-CZ1Fmb74.js} +1 -1
  65. package/dist/cdn/chunks/{image-BgtqLXfM.js → image-KXTd-hL-.js} +8 -8
  66. package/dist/cdn/chunks/{inline-dialog-BYRIWhkm.js → inline-dialog-BTI0xmIT.js} +6 -6
  67. package/dist/cdn/chunks/{just-in-time-education-DwH3ubhZ.js → just-in-time-education-BtjbYffu.js} +5 -5
  68. package/dist/cdn/chunks/{kanban-BIZUoBj-.js → kanban-DNXtL34O.js} +5 -5
  69. package/dist/cdn/chunks/{kanban-column-CtjCIgaR.js → kanban-column-D0ujQ2_W.js} +4 -4
  70. package/dist/cdn/chunks/{keyboard-shortcut-BHylGMNu.js → keyboard-shortcut-BikzmCBH.js} +3 -3
  71. package/dist/cdn/chunks/{languages-DghCYmiz.js → languages-CPd7_I8H.js} +12 -12
  72. package/dist/cdn/chunks/{link-S53veJpD.js → link-DqMeRYFm.js} +6 -6
  73. package/dist/cdn/chunks/{link-group-B2_vdANe.js → link-group-BKn4MHA-.js} +2 -2
  74. package/dist/cdn/chunks/{list-C8hY4uGW.js → list-C8Dnks-q.js} +8 -8
  75. package/dist/cdn/chunks/{list-item-CK1Rli4F.js → list-item-CSP1a_cN.js} +5 -5
  76. package/dist/cdn/chunks/{list-item-segment-KyrcOFDA.js → list-item-segment-BvFqXXnA.js} +3 -3
  77. package/dist/cdn/chunks/{menu-m67vk1Z4.js → menu-LZ0DmVCe.js} +13 -13
  78. package/dist/cdn/chunks/{menu-bar-item-DKW198ZW.js → menu-bar-item-DENdrp0m.js} +6 -6
  79. package/dist/cdn/chunks/{menu-bar-BRoqy5zp.js → menu-bar-rsGd3kKq.js} +6 -6
  80. package/dist/cdn/chunks/{menu-divider-DDPBPK-o.js → menu-divider-BptK2nug.js} +3 -3
  81. package/dist/cdn/chunks/{menu-group-uZXsE-uu.js → menu-group-0B34NyN5.js} +4 -4
  82. package/dist/cdn/chunks/{menu-item-BOvb4QLd.js → menu-item-55vjckz2.js} +4 -4
  83. package/dist/cdn/chunks/{menu.template-v6VnRUNJ.js → menu.template-B_HMnBsa.js} +5 -5
  84. package/dist/cdn/chunks/{modal-dialog-BNq0r-1L.js → modal-dialog-DQY_0Qlk.js} +4 -4
  85. package/dist/cdn/chunks/{multi-line-text-field-Bfq47I3P.js → multi-line-text-field-DB4Vflno.js} +6 -6
  86. package/dist/cdn/chunks/{navigation-split-view-BiPoxCLL.js → navigation-split-view-Dbhrxni9.js} +4 -4
  87. package/dist/cdn/chunks/{notification-DjZXBv4J.js → notification-dtrMLORo.js} +6 -6
  88. package/dist/cdn/chunks/{number-field-tqoQLrgZ.js → number-field-Ctxk40as.js} +8 -8
  89. package/dist/cdn/chunks/{one-half-one-half-section-CyIm21PD.js → one-half-one-half-section-Bx6KLSY5.js} +3 -3
  90. package/dist/cdn/chunks/{one-third-two-thirds-section-CpnK0vzB.js → one-third-two-thirds-section-Bql0Xrsc.js} +3 -3
  91. package/dist/cdn/chunks/{one-time-code-field-6sMEfzoY.js → one-time-code-field-B-y5gRLi.js} +7 -7
  92. package/dist/cdn/chunks/{overflow-menu-IfYEX8tm.js → overflow-menu-Cs1VLcX7.js} +1 -1
  93. package/dist/cdn/chunks/{page-w4XAfBWD.js → page-Bdkit86l.js} +6 -6
  94. package/dist/cdn/chunks/{page-footer-ET6j1N2Z.js → page-footer-D68JiIFE.js} +4 -4
  95. package/dist/cdn/chunks/{page-section-mixin-D9JL2q9A.js → page-section-mixin-Bmlpcmrw.js} +3 -3
  96. package/dist/cdn/chunks/{pagination-D7QFUu8x.js → pagination-BH6UQbby.js} +6 -6
  97. package/dist/cdn/chunks/{password-field-Ck5wx6pg.js → password-field-Dz0znv2L.js} +8 -8
  98. package/dist/cdn/chunks/{popover-DOmi5m85.js → popover-C6j3sO70.js} +5 -5
  99. package/dist/cdn/chunks/{progress-bar-BDNcB06i.js → progress-bar-BA_5dDXK.js} +7 -7
  100. package/dist/cdn/chunks/{progress-circle-BAMztpb3.js → progress-circle-DsCyTyw-.js} +7 -7
  101. package/dist/cdn/chunks/{radio-button-field-BbPk0nM_.js → radio-button-field-JsQalrMs.js} +6 -6
  102. package/dist/cdn/chunks/{radio-button-group-lxzwku00.js → radio-button-group-Bqn43LYh.js} +3 -3
  103. package/dist/cdn/chunks/{radio-button-DAps6n0Q.js → radio-button-pcE5Vo5k.js} +4 -4
  104. package/dist/cdn/chunks/{render-marked-ClMFyNu0.js → render-marked-DAVGoeYa.js} +1 -1
  105. package/dist/cdn/chunks/{reorder-handle-cell-Cap2u2zx.js → reorder-handle-cell-r4OuA45S.js} +4 -4
  106. package/dist/cdn/chunks/{reorder-handle-mixin-CnRKPVqU.js → reorder-handle-mixin-Co5E_Y7l.js} +2 -2
  107. package/dist/cdn/chunks/{repeat-CIyCvHHQ.js → repeat-DoLR8W_a.js} +2 -2
  108. package/dist/cdn/chunks/{rich-text-CblFmHY-.js → rich-text-CEmzxZRC.js} +3 -3
  109. package/dist/cdn/chunks/{row-header-mixin-C8z9StDU.js → row-header-mixin-BCYXiXva.js} +2 -2
  110. package/dist/cdn/chunks/{scroll-fade-C_L9CJrR.js → scroll-fade-OSFrYTum.js} +2 -2
  111. package/dist/cdn/chunks/{search-field-JeUPcBjZ.js → search-field-CT483s7J.js} +10 -10
  112. package/dist/cdn/chunks/{segmented-control-DtycvVyp.js → segmented-control-5zMasjz7.js} +7 -7
  113. package/dist/cdn/chunks/{shadow-resets-DgR56wQK.js → shadow-resets-DR73IFIL.js} +2 -2
  114. package/dist/cdn/chunks/{sheet-XtRs26hN.js → sheet-CDXX61d_.js} +3 -3
  115. package/dist/cdn/chunks/{shell-CCaEEGna.js → shell-C4vAeA49.js} +3 -3
  116. package/dist/cdn/chunks/{side-by-side-split-view-mhXD4Lde.js → side-by-side-split-view-D9_u1TIS.js} +4 -4
  117. package/dist/cdn/chunks/{sidebar-section-Cwd4LSE6.js → sidebar-section-vWX-ymIa.js} +7 -7
  118. package/dist/cdn/chunks/{simple-section-BuiaCGks.js → simple-section-CEw2oC7K.js} +3 -3
  119. package/dist/cdn/chunks/{skip-link-nTlmioFt.js → skip-link-DcOGlfM9.js} +4 -4
  120. package/dist/cdn/chunks/{slider-C0rNQEIY.js → slider-B108QDlz.js} +9 -9
  121. package/dist/cdn/chunks/{spacer-CeSO9CP1.js → spacer-CpfTNtbZ.js} +2 -2
  122. package/dist/cdn/chunks/{spacer-cell-NhlxEdhA.js → spacer-cell-DBm7_AUi.js} +4 -4
  123. package/dist/cdn/chunks/{split-button-BR-ccA6_.js → split-button-DxgDxdan.js} +7 -7
  124. package/dist/cdn/chunks/{split-view-divider-HcIV0yli.js → split-view-divider-6_RDvANN.js} +2 -2
  125. package/dist/cdn/chunks/{split-view-pane-BgFUL3BV.js → split-view-pane-9tEGLRZC.js} +3 -3
  126. package/dist/cdn/chunks/{stacked-split-view-j77p3uE2.js → stacked-split-view-CRMEMwtv.js} +4 -4
  127. package/dist/cdn/chunks/{static-html-CGoLwgpW.js → static-html-CmXnRyP6.js} +1 -1
  128. package/dist/cdn/chunks/{status-bar-ByJ21hV2.js → status-bar-Blk_iYSD.js} +4 -4
  129. package/dist/cdn/chunks/{step-bar-CRxF0S42.js → step-bar-DM4a_0PG.js} +5 -5
  130. package/dist/cdn/chunks/{step-cell-C-gOxNA6.js → step-cell-CUs8AKJq.js} +5 -5
  131. package/dist/cdn/chunks/{stepper-Dmljb7Qc.js → stepper-JwxPNJRc.js} +7 -7
  132. package/dist/cdn/chunks/{style-map-CK811FGv.js → style-map-DUDIMhuW.js} +1 -1
  133. package/dist/cdn/chunks/{swatch-picker-DtAgTXLo.js → swatch-picker-BXs7Ob4o.js} +6 -6
  134. package/dist/cdn/chunks/{switch-Bqion92b.js → switch-CWKoOyz7.js} +5 -5
  135. package/dist/cdn/chunks/{switch-field-CWobTcEn.js → switch-field-BgX9mNOA.js} +6 -6
  136. package/dist/cdn/chunks/{tab-bar-DPtRjP8Z.js → tab-bar-BNaJSB38.js} +8 -8
  137. package/dist/cdn/chunks/{table-C4CFiDgr.js → table-dgJdHR92.js} +5 -5
  138. package/dist/cdn/chunks/{tag-Bo23A60g.js → tag-DHHf_gxq.js} +4 -4
  139. package/dist/cdn/chunks/{term-DPMEWR-t.js → term-DNLqQErM.js} +12 -12
  140. package/dist/cdn/chunks/{text-CuiMvMZQ.js → text-CK1-qJ6d.js} +3 -3
  141. package/dist/cdn/chunks/{text-cell-E3yc99xw.js → text-cell-CrKBqL5A.js} +8 -8
  142. package/dist/cdn/chunks/{text-editor-BVmHiq_b.js → text-editor-B0A2vNpD.js} +10 -10
  143. package/dist/cdn/chunks/{text-field-DOv1aI_F.js → text-field-CqYxSiKy.js} +6 -6
  144. package/dist/cdn/chunks/{time-field-BhlLk6tt.js → time-field-DHm6KQsG.js} +14 -14
  145. package/dist/cdn/chunks/{time-picker-A4-HeVas.js → time-picker-C_BE5oNq.js} +5 -5
  146. package/dist/cdn/chunks/{title-EMt-SYKV.js → title-BpREzeX9.js} +4 -4
  147. package/dist/cdn/chunks/{title-cell--EE-L_8a.js → title-cell-C4ZL3mJo.js} +8 -8
  148. package/dist/cdn/chunks/{toggle-button-BLwpxmQs.js → toggle-button-COQdr-hZ.js} +8 -8
  149. package/dist/cdn/chunks/{toggle-button-group-scdxolJt.js → toggle-button-group-D4vTcGce.js} +2 -2
  150. package/dist/cdn/chunks/{token-DVgXuCRO.js → token-1DfHVSVj.js} +5 -5
  151. package/dist/cdn/chunks/{token-field-CICQXLlO.js → token-field-s_mCjtcZ.js} +11 -11
  152. package/dist/cdn/chunks/{toolbar-Des2gaH2.js → toolbar-Bz_8d1v-.js} +8 -8
  153. package/dist/cdn/chunks/{toolbar-item-CkwQ2UyY.js → toolbar-item-B-EDYaPf.js} +3 -3
  154. package/dist/cdn/chunks/{toolbar-title-PoOf794l.js → toolbar-title-Cl8VPHYK.js} +4 -4
  155. package/dist/cdn/chunks/{toolbar.styles-DzreUGTp.js → toolbar.styles-BiT7JPsr.js} +3 -3
  156. package/dist/cdn/chunks/{tooltip-CMCT2iiD.js → tooltip-DhPeqDvL.js} +4 -4
  157. package/dist/cdn/chunks/{top-navigation-bar-BfMGgTIy.js → top-navigation-bar-CHWqoNms.js} +17 -17
  158. package/dist/cdn/chunks/{top-title-bar-CvvldlNt.js → top-title-bar-DUp0bSIU.js} +6 -6
  159. package/dist/cdn/chunks/{translations-C5JpcNNC.js → translations-C6WKR-hE.js} +1 -1
  160. package/dist/cdn/chunks/{two-thirds-one-third-section-BTkeIiHm.js → two-thirds-one-third-section-CftZqodu.js} +3 -3
  161. package/dist/cdn/chunks/{validation-list-BasB3ZaT.js → validation-list-BdTSfsD6.js} +3 -3
  162. package/dist/cdn/chunks/{visibility-mixin-BxhcJG-x.js → visibility-mixin-DL737l0g.js} +2 -2
  163. package/dist/cdn/chunks/{visually-hidden-ByHY8pKl.js → visually-hidden-DvU3wAD4.js} +2 -2
  164. package/dist/cdn/chunks/{window-B5blEfMR.js → window-7XYqha2V.js} +4 -4
  165. package/dist/cdn/chunks/{with-translations-QDhHJYMT.js → with-translations-nT8q6ELU.js} +3 -3
  166. package/dist/components/content/image/image.d.ts +1 -4
  167. package/dist/components/content/image/image.d.ts.map +1 -1
  168. package/dist/components/content/image/image.js +1 -4
  169. package/dist/components/content/image/image.js.map +1 -1
  170. package/dist/components/content/tooltip/tooltip.d.ts +1 -4
  171. package/dist/components/content/tooltip/tooltip.d.ts.map +1 -1
  172. package/dist/components/content/tooltip/tooltip.js +1 -4
  173. package/dist/components/content/tooltip/tooltip.js.map +1 -1
  174. package/dist/components/layout/page/page.d.ts +4 -0
  175. package/dist/components/layout/page/page.d.ts.map +1 -1
  176. package/dist/components/layout/page/page.js +4 -0
  177. package/dist/components/layout/page/page.js.map +1 -1
  178. package/dist/components/layout/page/page.styles.js +2 -2
  179. package/dist/components/layout/shell/shell.d.ts +2 -0
  180. package/dist/components/layout/shell/shell.d.ts.map +1 -1
  181. package/dist/components/layout/shell/shell.js +2 -0
  182. package/dist/components/layout/shell/shell.js.map +1 -1
  183. package/dist/nldd.min.js +2 -2
  184. package/dist/utilities/dev-checks.d.ts +6 -0
  185. package/dist/utilities/dev-checks.d.ts.map +1 -1
  186. package/dist/utilities/dev-checks.js +42 -16
  187. package/dist/utilities/dev-checks.js.map +1 -1
  188. package/dist/utilities/dev-rules.generated.d.ts.map +1 -1
  189. package/dist/utilities/dev-rules.generated.js +27 -2
  190. package/dist/utilities/dev-rules.generated.js.map +1 -1
  191. package/lint/css.js +58 -26
  192. package/lint/data.generated.json +1 -1
  193. package/lint/engine.js +29 -12
  194. package/lint/fix.js +103 -12
  195. package/lint/format.js +4 -3
  196. package/lint/frontends.js +153 -35
  197. package/lint/linter.js +174 -25
  198. package/lint/main.js +7 -2
  199. package/lint/project.js +50 -12
  200. package/lint/rule-compiler.js +20 -11
  201. package/lint/rule-data.js +8 -0
  202. package/lint/rule.schema.json +2 -1
  203. package/lint/session.js +42 -18
  204. package/lint/tree.js +5 -2
  205. package/package.json +1 -1
package/lint/engine.js CHANGED
@@ -36,10 +36,11 @@ function forWorld(tokens, classes, widen) {
36
36
  return { ...token, data: token.data.map((each) => forWorld(each, classes, inner)) };
37
37
  }
38
38
  if (!widen) return token;
39
- if (token.type === 'pseudo' && favorableName(token.name) !== token.name) return { ...token, name: favorableName(token.name) };
39
+ const named = token.type === 'pseudo' ? { ...token, name: favorableName(token.name) } : token;
40
40
  if (token.type === 'tag' || (token.type === 'pseudo' && token.name in classes)) {
41
- return { type: 'pseudo', name: 'is', data: [[token], [unknown]] };
41
+ return { type: 'pseudo', name: 'is', data: [[named], [unknown]] };
42
42
  }
43
+ if (named.name !== token.name) return named;
43
44
  // "Not empty" is about a value we have, and a bound value is not empty.
44
45
  if (token.type === 'attribute' && token.action === 'equals' && token.value === '') return token;
45
46
  if (token.type === 'attribute') {
@@ -50,9 +51,9 @@ function forWorld(tokens, classes, widen) {
50
51
  });
51
52
  }
52
53
 
53
- export function createEngine({ classes = {}, tags = {}, designSystemCss = {} } = {}) {
54
+ export function createEngine({ classes = {}, tags = {}, designSystemCss = {}, isDesignSystemCss } = {}) {
54
55
  const pseudos = {
55
- ...sourcePseudos({ classes, tags, designSystemCss }),
56
+ ...sourcePseudos({ classes, tags, designSystemCss, isDesignSystemCss }),
56
57
  // Engine-only: how forWorld lets what is unknown match in W+.
57
58
  unknown: (node) => node.opaque,
58
59
  bound: (node, name) => node.opaque || node.spread || node.attrs.get(name) === BOUND,
@@ -92,19 +93,35 @@ export function createEngine({ classes = {}, tags = {}, designSystemCss = {} } =
92
93
  return true;
93
94
  }
94
95
 
96
+ /** The elements of a tree by id, and those whose id this file cannot know. Built once per tree. */
97
+ const idIndexes = new WeakMap();
98
+ function idIndex(root) {
99
+ if (!idIndexes.has(root)) {
100
+ const byId = new Map();
101
+ const unknown = [];
102
+ walk(root, (node) => {
103
+ const id = node.attrs.get('id');
104
+ if (typeof id === 'string') byId.set(id, [...(byId.get(id) ?? []), node]);
105
+ if (node !== root && (node.opaque || node.spread || node.templated || id === BOUND)) unknown.push(node);
106
+ });
107
+ idIndexes.set(root, { byId, unknown });
108
+ }
109
+ return idIndexes.get(root);
110
+ }
111
+
95
112
  function refOutcome(rule, node, root) {
96
113
  const { attr, target, equal } = rule.ref;
97
114
  const value = node.attrs.get(attr);
98
115
  if (value === undefined) return 'passed';
99
116
  if (value === BOUND || node.spread) return 'cantTell';
100
- const found = [];
101
- walk(root, (candidate) => {
102
- if (candidate.attrs.get('id') === value && matches(candidate, target, '-')) {
103
- found.push(candidate);
104
- }
105
- });
106
- // The target may be rendered by another file, unless this is a whole document.
107
- if (found.length === 0) return root.opaque ? 'cantTell' : 'failed';
117
+ const { byId, unknown } = idIndex(root);
118
+ const candidates = byId.get(value) ?? [];
119
+ const found = candidates.filter((candidate) => matches(candidate, target, '-'));
120
+ if (found.length === 0) {
121
+ // The target may be rendered by another file, unless this is a whole document, or have an id we cannot read.
122
+ const maybe = root.opaque || [...candidates, ...unknown].some((candidate) => matches(candidate, target, '+'));
123
+ return maybe ? 'cantTell' : 'failed';
124
+ }
108
125
  if (!equal) return 'passed';
109
126
  const expected = node.attrs.get(equal);
110
127
  const actual = found[0].attrs.get(equal);
package/lint/fix.js CHANGED
@@ -22,11 +22,24 @@ function renameEdits(source, startTag, from, to) {
22
22
  return [{ from: nameStart, to: nameEnd, text: isProperty || name !== from ? toCamelCase(to) : to }];
23
23
  }
24
24
 
25
+ /**
26
+ * `{5}`, `{"5"}` and `` {`5`} ``: braces around one number or one string without an escape or a hole.
27
+ * A number is matched as written, so `{05}` or `{5.0}` finds no value and stays a finding.
28
+ * Only a value the rule names for this attribute is rewritten, so `{"5"}` elsewhere stays as it is.
29
+ */
30
+ const BRACED_LITERAL = /^\{\s*(?:(\d+(?:\.\d+)?)|"([^"\\\n]*)"|'([^'\\\n]*)'|`([^`\\$\n]*)`)\s*\}$/;
31
+
25
32
  /** Only a value written out in the markup: a bound one can hold anything. */
26
33
  function valueEdits(source, startTag, name, values) {
27
34
  const found = findAttribute(startTag, name);
28
35
  const value = found?.value;
29
- if (!value || found.prefix || value.quote === '{') return [];
36
+ if (!value || found.prefix) return [];
37
+ if (value.quote === '{') {
38
+ // A literal in braces is as certain as a quoted value, and becomes one: the new value is a string.
39
+ const literal = BRACED_LITERAL.exec(source.slice(value.start, value.end));
40
+ const written = literal?.slice(1).find((group) => group !== undefined);
41
+ return written !== undefined && Object.hasOwn(values, written) ? [{ from: value.start, to: value.end, text: `"${values[written]}"` }] : [];
42
+ }
30
43
  const at = value.quote ? value.start + 1 : value.start;
31
44
  const end = value.quote ? value.end - 1 : value.end;
32
45
  return Object.entries(values).flatMap(([from, to]) =>
@@ -34,6 +47,61 @@ function valueEdits(source, startTag, name, values) {
34
47
  );
35
48
  }
36
49
 
50
+ /** The text of a value written out in the markup, quoted or bare. A value in braces is an expression, and has none. */
51
+ function writtenText(source, found) {
52
+ const value = found?.value;
53
+ if (!value || found.prefix || found.templated || value.quote === '{') return undefined;
54
+ return value.quote ? source.slice(value.start + 1, value.end - 1) : source.slice(value.start, value.end);
55
+ }
56
+
57
+ const UNCERTAIN_TEXT = /[&\\\n]|\{\{|\{%|\$\{/;
58
+
59
+ /** `translations` as JSON in single quotes. */
60
+ function translationsAttribute(entries) {
61
+ return `translations='{${entries.map(([key, text]) => `${JSON.stringify(key)}: ${JSON.stringify(text)}`).join(', ')}}'`;
62
+ }
63
+
64
+ /** The keys a `translations` holds, when it is written out as JSON in single quotes. */
65
+ function writtenTranslations(source, found) {
66
+ const value = found.value;
67
+ if (!value || found.prefix || found.templated || value.quote !== "'") return undefined;
68
+ const json = source.slice(value.start + 1, value.end - 1);
69
+ if (UNCERTAIN_TEXT.test(json)) return undefined;
70
+ try {
71
+ const parsed = JSON.parse(json);
72
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed) || Object.values(parsed).some((text) => typeof text !== 'string')) return undefined;
73
+ return Object.entries(parsed);
74
+ } catch {
75
+ return undefined;
76
+ }
77
+ }
78
+
79
+ /**
80
+ * A text attribute that became a translation key: the attribute goes, and its text
81
+ * goes in `translations` under that key, as JSON in single quotes. Not in JSX: React 18
82
+ * writes an object as `[object Object]`, and React 19 sets a string as the property,
83
+ * which the component does not parse. An entity, a backslash, a template hole or a quote
84
+ * that the JSON cannot hold makes it uncertain, and so does a `translations` that is
85
+ * bound or already has the key. One per element per pass: the next pass adds the next key.
86
+ */
87
+ function translationEdits(source, finding, translation) {
88
+ const { startTag, jsx } = finding;
89
+ if (jsx) return [];
90
+ return Object.entries(translation).flatMap(([name, key]) => {
91
+ const found = findAttribute(startTag, name);
92
+ const text = writtenText(source, found);
93
+ // An empty text would win over the default in translate() and leave the button blank.
94
+ if (text === undefined || text.trim() === '' || UNCERTAIN_TEXT.test(text) || text.includes("'")) return [];
95
+ const existing = findAttribute(startTag, 'translations');
96
+ if (!existing) return [{ from: found.start, to: found.end, text: translationsAttribute([[key, text]]) }];
97
+ const entries = writtenTranslations(source, existing);
98
+ if (!entries || entries.some(([existingKey]) => existingKey === key)) return [];
99
+ const removal = removeEdits(source, finding, name);
100
+ if (removal.length === 0) return [];
101
+ return [{ from: existing.start, to: existing.end, text: translationsAttribute([...entries, [key, text]]) }, ...removal];
102
+ });
103
+ }
104
+
37
105
  /** What stands before an attribute, back to the one before it or the tag name. */
38
106
  function gapBefore(source, { offset, tag, startTag }, found) {
39
107
  const previous = startTag.attributes.filter((attribute) => attribute.end <= found.start).at(-1);
@@ -95,7 +163,7 @@ function wrapEdits(source, finding, wrapper) {
95
163
  const content = contentOf(source, finding);
96
164
  const inner = content?.text.trim();
97
165
  // A blank line ends raw HTML in Markdown, and indenting it leaves trailing space.
98
- if (!inner || /\n[ \t]*\n/.test(inner)) return [];
166
+ if (!inner || /\r?\n[ \t]*\r?\n/.test(inner)) return [];
99
167
  const tags = [...inner.matchAll(/<\/?([a-zA-Z][\w-]*)/g)].map((match) => match[1].toLowerCase());
100
168
  if (tags.some((name) => !INLINE.has(name))) return [];
101
169
  const leading = /^\s*/.exec(content.text)[0];
@@ -104,7 +172,8 @@ function wrapEdits(source, finding, wrapper) {
104
172
  let wrapped = `<${wrapper}>${inner}</${wrapper}>`;
105
173
  if (base !== undefined && inner.includes('\n')) {
106
174
  const unit = base.includes('\t') || !base ? '\t' : ' ';
107
- wrapped = `<${wrapper}>\n${base}${unit}${inner.replace(/\n/g, `\n${unit}`)}\n${base}</${wrapper}>`;
175
+ const eol = leading.includes('\r\n') ? '\r\n' : '\n';
176
+ wrapped = `<${wrapper}>${eol}${base}${unit}${inner.replace(/\n/g, `\n${unit}`)}${eol}${base}</${wrapper}>`;
108
177
  }
109
178
  return [{ from: content.start, to: content.end, text: leading + wrapped + trailing }];
110
179
  }
@@ -120,6 +189,12 @@ function editsOf(source, finding) {
120
189
  ...(fix.tag && mention ? [{ from: offset + 1, to: offset + 1 + tag.length, text: fix.tag }] : []),
121
190
  ...(fix.tag && !mention ? tagEdits(source, finding, fix.tag) : []),
122
191
  ...(fix.wrap ? wrapEdits(source, finding, fix.wrap) : []),
192
+ ...(fix.translation ? translationEdits(source, finding, fix.translation) : []),
193
+ // A token that got another name: the finding spans the old name in a `var()`, and
194
+ // startsWith checks that the span still holds it.
195
+ ...(fix.token && source.startsWith(tag, offset) ? [{ from: offset, to: finding.endOffset, text: fix.token }] : []),
196
+ // An event that got another name: the finding spans the old name in a listener.
197
+ ...(fix.event && source.startsWith(tag, offset) ? [{ from: offset, to: finding.endOffset, text: fix.event }] : []),
123
198
  ];
124
199
  }
125
200
 
@@ -240,20 +315,36 @@ export function linesNaming(source, renamedTags) {
240
315
  return source.split('\n').flatMap((line, index) => (names.some((name) => line.search(name) !== -1) ? [index + 1] : []));
241
316
  }
242
317
 
318
+ const isSameEdit = (a, b) => a.from === b.from && a.to === b.to && a.text === b.text;
319
+
320
+ /**
321
+ * Two edits at one place, or ranges that share a character, cannot both apply to the original offsets.
322
+ * Two insertions at the same offset count too: the second waits for the next pass.
323
+ */
324
+ const overlaps = (a, b) => a.from === b.from || (a.from < b.to && b.from < a.to);
325
+
243
326
  /**
327
+ * One pass of fixes. An edit that overlaps one already taken is left for the next pass, so a
328
+ * caller applies this until `fixed` is 0, as fixUntilStable does.
244
329
  * @returns {{ source: string, fixed: number, renamedTags: Map<string, string> }}
245
330
  */
246
331
  export function applyFixes(source, findings) {
247
332
  const renamedTags = new Map();
248
- const edits = findings
249
- .filter(({ fix }) => fix)
250
- .flatMap((finding) => {
251
- const found = editsOf(source, finding);
252
- if (found.length > 0 && finding.fix.tag) renamedTags.set(finding.tag, finding.fix.tag);
253
- return found;
254
- });
255
- const seen = new Set();
256
- const unique = edits.filter(({ from }) => !seen.has(from) && seen.add(from));
333
+ const translated = new Set();
334
+ const unique = [];
335
+ for (const finding of findings.filter(({ fix }) => fix)) {
336
+ // Two keys for one element would each write `translations`: the next pass adds the second.
337
+ if (finding.fix.translation && translated.has(finding.offset)) continue;
338
+ const found = editsOf(source, finding).filter((edit) => !unique.some((other) => isSameEdit(edit, other)));
339
+ // The edits of one finding go together or not at all, such as both tags of a rename.
340
+ // One that overlaps an edit already taken, such as a wrap around this element, waits for the next pass.
341
+ // Edits of one finding that overlap each other would corrupt the file, so that fix is not made.
342
+ const clash = (edit, i) => unique.some((other) => overlaps(edit, other)) || found.slice(i + 1).some((other) => overlaps(edit, other));
343
+ if (found.length === 0 || found.some(clash)) continue;
344
+ unique.push(...found);
345
+ if (finding.fix.tag) renamedTags.set(finding.tag, finding.fix.tag);
346
+ if (finding.fix.translation) translated.add(finding.offset);
347
+ }
257
348
  let fixed = source;
258
349
  for (const { from, to, text } of unique.sort((a, b) => b.from - a.from)) {
259
350
  fixed = fixed.slice(0, from) + text + fixed.slice(to);
package/lint/format.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /** Renders findings. `text` is for people, `json` for agents and tools, `github` for CI. */
2
2
 
3
3
  import { relative } from 'node:path';
4
+ import { relativePath } from './project.js';
4
5
 
5
6
  const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
6
7
  const paint = (code) => (text) => (useColor ? `\u001b[${code}m${text}\u001b[0m` : text);
@@ -82,7 +83,7 @@ export function formatStatistics(results, { files, unread, ms, skipped }) {
82
83
  for (const { rule, severity, fix } of results.flatMap(({ findings }) => findings)) {
83
84
  const entry = counts.get(rule) ?? { rule, severity, count: 0 };
84
85
  entry.count += 1;
85
- entry.fixable = Boolean(fix);
86
+ entry.fixable ||= Boolean(fix);
86
87
  counts.set(rule, entry);
87
88
  }
88
89
  const rows = [...counts.values()].sort((a, b) => b.count - a.count || a.rule.localeCompare(b.rule));
@@ -101,7 +102,7 @@ export function formatJson(results, { root, explainRule, skipped = 0, loose = 0
101
102
  list.map((finding) => {
102
103
  const detail = explainRule(finding.rule);
103
104
  return {
104
- file: relative(root, filename),
105
+ file: relativePath(root, filename),
105
106
  line: finding.line,
106
107
  column: finding.column,
107
108
  severity: finding.severity,
@@ -129,7 +130,7 @@ export function formatGithub(results, { root, loose = 0 }) {
129
130
  for (const { filename, findings } of results) {
130
131
  for (const { severity, line, column, rule, message } of findings) {
131
132
  const level = { error: 'error', warn: 'warning', hint: 'notice' }[severity];
132
- const file = relative(root, filename);
133
+ const file = relativePath(root, filename);
133
134
  lines.push(`::${level} file=${escapeProperty(file)},line=${line},col=${column},title=${rule}::${escapeGithub(message)}`);
134
135
  }
135
136
  }
package/lint/frontends.js CHANGED
@@ -37,19 +37,29 @@ const TRANSPARENT = new Set([
37
37
  const CONDITIONAL = new Set(['v-if', 'v-else', 'v-else-if', '*ngIf']);
38
38
  const REPEATED = new Set(['v-for', '*ngFor']);
39
39
 
40
- /** A value a template language fills in: `{{ x }}`, `{% x %}`, `${x}`, `<%= x %>` or `{x}`. */
41
- const TEMPLATE_VALUE = /\{\{|\{%|\$\{|<%|^\{.*\}$/;
40
+ /** What a template language writes to fill something in: `{{ x }}`, `{% x %}`, `${x}` or `<%= x %>`. */
41
+ const TEMPLATE_SYNTAX = /\{\{|\{%|\$\{|<%/;
42
+
43
+ /** A value a template language fills in, also a whole `{x}`. */
44
+ const TEMPLATE_VALUE = new RegExp(`${TEMPLATE_SYNTAX.source}|^\\{.*\\}$`);
42
45
 
43
46
  /** A JSON object, such as a `translations` attribute, is written out and not filled in. */
44
47
  const isJsonObject = (value) => {
45
48
  if (!/^\{\s*("|\})/.test(value)) return false;
46
49
  try {
47
- return JSON.parse(value) !== null;
50
+ const parsed = JSON.parse(value);
51
+ // A key the template fills in is no key anyone can check.
52
+ return parsed !== null && !Object.keys(parsed).some((key) => TEMPLATE_SYNTAX.test(key));
48
53
  } catch {
49
54
  return false;
50
55
  }
51
56
  };
52
57
 
58
+ /** A filler of `length` characters without spaces that reads as a bound value: `${xxx}`. */
59
+ const boundFiller = (length) => `\${${'x'.repeat(length - 3)}}`;
60
+
61
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
62
+
53
63
  /** Jinja, Django, Handlebars and Angular control flow, written between the tags. */
54
64
  const TEMPLATE_TEXT = /\{%|\{\{|@(if|else|for|switch|defer)\b/;
55
65
 
@@ -67,7 +77,9 @@ function readAttribute(element, name, value) {
67
77
  else if (name === 'v-model') element.attrs.set('value', BOUND);
68
78
  else if (name.startsWith('v-model:')) element.attrs.set(name.slice(8), BOUND);
69
79
  else if (/^(:|v-bind:|x-bind:|\.|\?)/.test(name)) {
70
- const bare = name.replace(/^(v-bind|x-bind)?[:.?]/, '').replace(/\.(prop|attr|camel)$/, '');
80
+ // Vue and Alpine take any modifier after the name, `:value.sync`; Lit takes none.
81
+ const modifiers = /^(v-bind:|x-bind:|:)/.test(name) ? /(\.[a-zA-Z]+)+$/ : /\.(prop|attr|camel)$/;
82
+ const bare = name.replace(/^(v-bind|x-bind)?[:.?]/, '').replace(modifiers, '');
71
83
  element.attrs.set(bare, BOUND);
72
84
  } else if (/^\[(class\.|style\.)/.test(name) || /^\[(ngClass|ngStyle|className)\]$/.test(name)) {
73
85
  // Angular's way to set one class or style, or a set of them. Not an attribute of
@@ -101,8 +113,12 @@ function readHtmlChildren(children, parent, given) {
101
113
  // In Markdown, text in an element can be a paragraph the renderer writes around it.
102
114
  const paragraphs = given.markdown && parent.name !== '#root' ? given.markdown(children) : null;
103
115
  for (const node of children) {
104
- if (node.type === 'text' && node.data.trim()) {
105
- const paragraph = paragraphs?.(node.data);
116
+ // MDX marks an expression too short to stand as an element with a hole.
117
+ const holeAt = given.jsx && node.type === 'text' ? node.data.indexOf(HOLE) : -1;
118
+ if (holeAt !== -1) appendUnknown(parent, (node.startIndex ?? 0) + holeAt);
119
+ const data = holeAt === -1 ? node.data : node.data.replaceAll(HOLE, ' ');
120
+ if (node.type === 'text' && data.trim()) {
121
+ const paragraph = paragraphs?.(data);
106
122
  if (paragraph?.loose !== false) parent.text = true;
107
123
  if (paragraph?.at >= 0) {
108
124
  const p = createNode('p', (node.startIndex ?? 0) + paragraph.at);
@@ -158,20 +174,31 @@ function readHtmlChildren(children, parent, given) {
158
174
  }
159
175
  }
160
176
 
177
+ /**
178
+ * A browser lowers every name in HTML. Only a name that is certainly the same in
179
+ * lowercase is lowered here: a camelCase one may be an Angular directive, and a
180
+ * PascalCase tag stays a component nobody can see into.
181
+ */
182
+ const htmlName = (name, isTag) => {
183
+ const same = isTag ? /^nldd-/i.test(name) || !/[a-z]/.test(name) : /^[A-Z]/.test(name);
184
+ return same ? name.toLowerCase() : name;
185
+ };
186
+
161
187
  /**
162
188
  * The document handler, plus where each attribute stands: the parser knows it
163
189
  * while it reads the tag, and the tree keeps it for `--fix`.
164
190
  */
165
191
  class SpanHandler extends DomHandler {
166
- constructor(source, original, options) {
192
+ constructor(source, original, options, lowerCase) {
167
193
  super(undefined, options);
168
194
  this.source = source;
169
195
  this.original = original;
196
+ this.lowerCase = lowerCase;
170
197
  this.pending = [];
171
198
  }
172
199
 
173
200
  onattribute(name) {
174
- const span = attributeSpan(this.source, name, this.parser.startIndex, this.parser.endIndex);
201
+ const span = attributeSpan(this.source, this.lowerCase ? htmlName(name, false) : name, this.parser.startIndex, this.parser.endIndex);
175
202
  if (this.original !== this.source) span.templated = this.rewritten(span);
176
203
  this.pending.push(span);
177
204
  }
@@ -186,6 +213,10 @@ class SpanHandler extends DomHandler {
186
213
  }
187
214
 
188
215
  onopentag(name, attribs) {
216
+ if (this.lowerCase) {
217
+ name = htmlName(name, true);
218
+ attribs = Object.fromEntries(Object.entries(attribs).map(([key, value]) => [htmlName(key, false), value]));
219
+ }
189
220
  super.onopentag(name, attribs);
190
221
  const end = this.parser.endIndex;
191
222
  this.tagStack.at(-1).startTag = { end, selfClosing: this.source[end - 1] === '/', attributes: this.pending };
@@ -194,7 +225,7 @@ class SpanHandler extends DomHandler {
194
225
  }
195
226
 
196
227
  /** `original` is the source before quieting a template, of the same length. */
197
- function parseMarkup(source, { selfClosing, original = source }) {
228
+ function parseMarkup(source, { selfClosing, original = source, lowerCase = false }) {
198
229
  const options = {
199
230
  lowerCaseTags: false,
200
231
  lowerCaseAttributeNames: false,
@@ -202,17 +233,67 @@ function parseMarkup(source, { selfClosing, original = source }) {
202
233
  withStartIndices: true,
203
234
  withEndIndices: true,
204
235
  };
205
- const handler = new SpanHandler(source, original, options);
236
+ const handler = new SpanHandler(source, original, options, lowerCase);
206
237
  new Parser(handler, options).end(source);
207
238
  return handler.root;
208
239
  }
209
240
 
210
- const OPENS_BLOCK = /^\{%-?\s*(if|for|with|block|macro|call|filter|autoescape|trans|blocktrans)\b/;
241
+ // Every tag that has a `{% end… %}`: one missing here would end the `{% if %}` around it too early.
242
+ // `set` only in its block form, without `=`.
243
+ const OPENS_BLOCK = /^\{%-?\s*(?:(if|for|with|block|macro|call|filter|autoescape|trans|blocktrans|blocktranslate|raw|spaceless|verbatim|cache|language|localize|ifchanged)\b|set\b(?![^%]*=))/;
211
244
  const CLOSES_BLOCK = /^\{%-?\s*end/;
212
245
 
246
+ /** The same for Go templates and Handlebars: `{{if}}…{{end}}`, `{{#if}}…{{/if}}`. */
247
+ // A Go action takes an argument, so `{{ block }}` alone is a value, not a block.
248
+ const OPENS_MUSTACHE = /^\{\{[-~]?\s*(#|\^\s*[^\s}~-]|(if|range|with|block|define)\s+[^\s}])/;
249
+ const CLOSES_MUSTACHE = /^\{\{[-~]?\s*(\/|end\b)/;
250
+
251
+ /** Another branch of a block: `{% elif %}`, `{% else %}`, `{% empty %}`, `{{else}}`, `{{^}}`. */
252
+ const ALTERNATIVE = /^\{%-?\s*(elif|else|empty)\b|^\{\{[-~]?\s*(else(?![\w.-])|\^\s*[-~]?\}\})/;
253
+
254
+ /** Where the branch ends that starts at `from`: the next `{% else %}` of its block, or the end of the block. */
255
+ function endOfBranch(text, from) {
256
+ const tags = /\{%[\s\S]*?%\}|\{\{[\s\S]*?\}\}/g;
257
+ tags.lastIndex = from;
258
+ let depth = 0;
259
+ for (let match = tags.exec(text); match; match = tags.exec(text)) {
260
+ if (OPENS_BLOCK.test(match[0]) || OPENS_MUSTACHE.test(match[0])) depth += 1;
261
+ else if (CLOSES_BLOCK.test(match[0]) || CLOSES_MUSTACHE.test(match[0])) {
262
+ if (depth === 0) return match.index;
263
+ depth -= 1;
264
+ } else if (depth === 0 && ALTERNATIVE.test(match[0])) return match.index;
265
+ }
266
+ return text.length;
267
+ }
268
+
269
+ /** Elements whose end tag HTML may leave out: the next one of the kind closes them. */
270
+ const OPTIONAL_END = new Set(['li', 'p', 'dt', 'dd', 'option', 'optgroup', 'tr', 'td', 'th', 'thead', 'tbody', 'tfoot', 'rt', 'rp', 'colgroup', 'caption']);
271
+
272
+ /**
273
+ * True when every element the markup opens, it also closes, and it closes none it did not open.
274
+ * An element whose end tag HTML may leave out (`<li>`) needs none (not `body`, `head` or `html`, rare in a branch), and `<x />` closes only where the
275
+ * parser reads it so (`selfClosing`); in HTML it stays open. In doubt it says false: that
276
+ * blanks a branch, which can miss a finding but never make one up.
277
+ */
278
+ function isBalanced(markup, selfClosing = false) {
279
+ const open = [];
280
+ const tags = markup.replace(/<!--[\s\S]*?-->|<(script|style)\b[\s\S]*?<\/\1\s*>/gi, '');
281
+ for (const [tag, slash, name] of tags.matchAll(/<(\/?)([a-zA-Z][\w-]*)(?:"[^"]*"|'[^']*'|[^'">])*>/g)) {
282
+ const lower = name.toLowerCase();
283
+ if (slash) {
284
+ while (open.length > 0 && open.at(-1) !== lower && OPTIONAL_END.has(open.at(-1))) open.pop();
285
+ if (open.pop() !== lower) return false;
286
+ } else if (!VOID.has(lower) && !(selfClosing && tag.endsWith('/>'))) open.push(lower);
287
+ }
288
+ return open.every((name) => OPTIONAL_END.has(name));
289
+ }
290
+
213
291
  /** Same length, so positions stay right. */
214
292
  const blank = (text) => text.replace(/[^\n]/g, ' ');
215
293
 
294
+ /** Markup without its template tags, so `{% if a %}>{% endif %}` in a tag does not end it. */
295
+ const withoutTemplateTags = (text) => text.replace(/\{%[\s\S]*?%\}|\{\{[\s\S]*?\}\}|\{#[\s\S]*?#\}/g, '');
296
+
216
297
  /**
217
298
  * Jinja and Django write into a tag, where an HTML parser reads them as markup:
218
299
  * `<nldd-field{% if x %} hidden{% endif %}>` would be a tag called `nldd-field{%`.
@@ -220,7 +301,7 @@ const blank = (text) => text.replace(/[^\n]/g, ' ');
220
301
  * in a tag it leaves a name that cannot be an attribute, so the element counts as
221
302
  * spread, and a whole `{% if %}` block goes: what is in it may not be there.
222
303
  */
223
- function quietTemplateTags(source) {
304
+ function quietTemplateTags(source, blanked = new Set(), selfClosing = false) {
224
305
  const text = source
225
306
  .replace(/\{#[\s\S]*?#\}|\{%-?\s*comment\b[\s\S]*?\{%-?\s*endcomment\s*-?%\}/g, blank)
226
307
  // A name the template fills in is a tag nobody can check.
@@ -235,6 +316,19 @@ function quietTemplateTags(source) {
235
316
  const end = close ? text.indexOf(close, at) : -1;
236
317
  if (end !== -1) {
237
318
  const piece = text.slice(at, end + 2);
319
+ if (!inTag && ALTERNATIVE.test(piece)) {
320
+ // One branch renders. A branch that leaves an element open, as the first one may too,
321
+ // goes, so the element in each does not nest in the other. A balanced branch stays.
322
+ const stop = endOfBranch(text, end + 2);
323
+ const branch = text.slice(end + 2, stop);
324
+ out += piece.replace(/[<>]/g, ' ');
325
+ at = end + 2;
326
+ if (isBalanced(withoutTemplateTags(branch), selfClosing)) continue;
327
+ for (const [, name] of branch.matchAll(/<([a-zA-Z][\w-]*)/g)) blanked.add(name.toLowerCase());
328
+ out += blank(branch);
329
+ at = stop;
330
+ continue;
331
+ }
238
332
  if (!inTag) out += piece.replace(/[<>]/g, ' ');
239
333
  else if (quote) out += `{{${'x'.repeat(piece.length - 4)}}}`;
240
334
  else {
@@ -248,7 +342,12 @@ function quietTemplateTags(source) {
248
342
  const char = text[at];
249
343
  if (!inTag) {
250
344
  const raw = char === '<' && /^<(script|style)[\s>]/i.exec(text.slice(at, at + 8));
251
- const skip = raw ? text.toLowerCase().indexOf(`</${raw[1].toLowerCase()}`, at) : text.startsWith('<!--', at) ? text.indexOf('-->', at) : -1;
345
+ let skip = text.startsWith('<!--', at) ? text.indexOf('-->', at) : -1;
346
+ if (raw) {
347
+ const closer = new RegExp(`</${raw[1]}`, 'gi');
348
+ closer.lastIndex = at;
349
+ skip = closer.exec(text)?.index ?? -1;
350
+ }
252
351
  if (skip !== -1) {
253
352
  out += text.slice(at, skip);
254
353
  at = skip;
@@ -269,16 +368,32 @@ function quietTemplateTags(source) {
269
368
  return out;
270
369
  }
271
370
 
272
- const quietIfTemplated = (source) => (/\{[%{#]/.test(source) ? quietTemplateTags(source) : source);
371
+ const quietIfTemplated = (source, blanked, selfClosing) => (/\{[%{#]/.test(source) ? quietTemplateTags(source, blanked, selfClosing) : source);
273
372
 
274
- export function parseHtml(source) {
373
+ /**
374
+ * A tag that also opens in a branch that went: which start tag its closing tag
375
+ * belongs to is unknown, so its end is too, and `--fix` leaves it as it is.
376
+ */
377
+ function forgetEnds(root, blanked) {
378
+ if (blanked.size > 0) walk(root, (node) => blanked.has(node.name.toLowerCase()) && (node.endOffset = undefined));
379
+ }
380
+
381
+ export function parseHtml(source, filename = '') {
275
382
  const root = createRoot({ closed: /<html[\s>]/i.test(source) });
276
- readHtmlChildren(parseMarkup(quietIfTemplated(source), { selfClosing: ANGULAR.test(source), original: source }).children, root, { inert: true });
383
+ const angular = ANGULAR.test(source) || filename.endsWith('.component.html');
384
+ // A browser lowers the names in HTML; Angular's compiler keeps their case.
385
+ const options = { selfClosing: angular, original: source, lowerCase: !angular };
386
+ const blanked = new Set();
387
+ readHtmlChildren(parseMarkup(quietIfTemplated(source, blanked, options.selfClosing), options).children, root, { inert: true });
388
+ forgetEnds(root, blanked);
277
389
  return [root];
278
390
  }
279
391
 
392
+ /** A `<` or `>` in an interpolation between the tags compares, and opens no element. */
393
+ const quietInterpolations = (source) => source.replace(/\{\{[\s\S]*?\}\}/g, (piece) => piece.replace(/[<>]/g, ' '));
394
+
280
395
  export function parseVue(source) {
281
- const documentNode = parseMarkup(source, { selfClosing: true });
396
+ const documentNode = parseMarkup(quietInterpolations(source), { selfClosing: true, original: source });
282
397
  const template = documentNode.children.find(
283
398
  (node) => node.type === 'tag' && node.name === 'template',
284
399
  );
@@ -368,7 +483,7 @@ function endOfExpression(source, start) {
368
483
  * comment as nothing. ESM goes, so `import` and `export` are not prose.
369
484
  */
370
485
  function mdxAsHtml(mdx) {
371
- const source = mdx.replace(/^(?:import|export)\s.*(?:\n.*\S.*)*/gm, blank);
486
+ const source = mdx.replace(/^(?:import|export)\s.*(?:\n.*\S.*)*/gm, blank).replaceAll(HOLE, ' ');
372
487
  const out = source.split('');
373
488
  let inTag = false;
374
489
  for (let at = 0; at < out.length; at += 1) {
@@ -380,10 +495,15 @@ function mdxAsHtml(mdx) {
380
495
  const end = endOfExpression(source, at);
381
496
  const length = end - at + 1;
382
497
  let fill;
498
+ let before = at - 1;
499
+ while (/[ \t\n]/.test(source[before] ?? '')) before -= 1;
500
+ const isComment = /^\{\s*\/\*/.test(source.slice(at, end));
383
501
  // An empty `{}` is no expression MDX accepts; it reads as an empty value.
384
- if (inTag && out[at - 1] === '=') fill = length >= 3 ? `\${${'x'.repeat(length - 3)}}` : '""';
502
+ if (inTag && source[before] === '=') fill = length >= 3 ? boundFiller(length) : '""';
385
503
  else if (inTag) fill = length >= 6 ? 'v-bind'.padEnd(length) : `{${'x'.repeat(Math.max(length - 2, 0))}}`.slice(0, length);
386
- else if (length >= 4 && !/^\{\s*\/\*/.test(source.slice(at, end))) fill = `<X${' '.repeat(length - 4)}/>`;
504
+ else if (length >= 4 && !isComment) fill = `<X${' '.repeat(length - 4)}/>`;
505
+ // Too short for an element, `{t}`: a mark the tree reads as content nobody can see here.
506
+ else if (!isComment && /\S/.test(source.slice(at + 1, end))) fill = HOLE.padEnd(length);
387
507
  else fill = blank(source.slice(at, end + 1));
388
508
  out.splice(at, length, ...fill);
389
509
  at = end;
@@ -546,7 +666,7 @@ function astroAsHtml(source) {
546
666
  // A comment between the attributes sets nothing.
547
667
  if (!isValue && ONLY_COMMENTS.test(source.slice(start + 1, end).trim())) return;
548
668
  if (!isValue) put(start, size >= 3 ? `:[${'x'.repeat(size - 3)}]` : '');
549
- else if (room >= 3) put(start, `\${${'x'.repeat(room - 3)}}`);
669
+ else if (room >= 3) put(start, boundFiller(room));
550
670
  else put(start, room === 2 && size === 3 ? '{{' : '""');
551
671
  }
552
672
 
@@ -645,7 +765,7 @@ function astroAsHtml(source) {
645
765
  if (!closes) depth += 1;
646
766
  if (tag.raw && !closes) {
647
767
  // Case-insensitive without lowering the source, which can change its length.
648
- const closer = new RegExp(`</${tag.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'gi');
768
+ const closer = new RegExp(`</${escapeRegExp(tag.name)}`, 'gi');
649
769
  closer.lastIndex = at;
650
770
  const end = closer.exec(source)?.index ?? length;
651
771
  // What `is:raw` holds is text as it stands, not elements and not expressions.
@@ -757,7 +877,7 @@ const markdownParagraphs = (mdx) => (children) => {
757
877
  function markMentions(node, source) {
758
878
  for (const child of node.children) {
759
879
  const written = source.slice(child.offset, (child.endOffset ?? 0) + 1);
760
- if (child.name.startsWith('nldd-') && !new RegExp(`</${child.name}\\s*>$`).test(written)) {
880
+ if (child.name.startsWith('nldd-') && !new RegExp(`</${escapeRegExp(child.name)}\\s*>$`).test(written)) {
761
881
  child.mention = true;
762
882
  child.endOffset = undefined;
763
883
  }
@@ -774,15 +894,17 @@ export function parseMarkdown(source, filename = '') {
774
894
  const roots = [];
775
895
  const read = (text, offset, given = {}) => {
776
896
  const root = createRoot();
777
- const padded = ' '.repeat(offset) + quietIfTemplated(text);
897
+ const blanked = new Set();
898
+ const padded = ' '.repeat(offset) + quietIfTemplated(text, blanked, true);
778
899
  readHtmlChildren(parseMarkup(padded, { selfClosing: true, original: ' '.repeat(offset) + text }).children, root, given);
900
+ forgetEnds(root, blanked);
779
901
  roots.push(root);
780
902
  };
781
903
  const fences = /^( *)(```|~~~)[^\n]*\n([\s\S]*?)^ *\2/gm;
782
904
  for (const match of source.matchAll(fences)) {
783
905
  if (match[3].includes('<nldd-')) read(match[3], match.index + match[0].indexOf('\n') + 1);
784
906
  }
785
- let prose = source.replace(fences, blank).replace(/^---\n[\s\S]*?\n---(?=\n)/, blank);
907
+ let prose = source.replace(fences, blank).replace(/^---\r?\n[\s\S]*?\r?\n---(?=\r?\n|$)/, blank);
786
908
  // A bare `<nldd-button>` in a sentence names the tag and says nothing about its attributes.
787
909
  for (const match of prose.matchAll(/`(<nldd-[^`\n]*)`/g)) {
788
910
  read(match[1].replace(/^<([a-z-]+)\s*\/?>$/, '<$1 v-bind="x"><Mention /></$1>'), match.index + 1);
@@ -801,13 +923,6 @@ export function parseMarkdown(source, filename = '') {
801
923
  */
802
924
  function litTemplates(source) {
803
925
  const templates = [];
804
- const skipString = (start) => {
805
- let at = start + 1;
806
- while (at < source.length && source[at] !== source[start] && source[at] !== '\n') {
807
- at += source[at] === '\\' ? 2 : 1;
808
- }
809
- return at;
810
- };
811
926
  const readTemplate = (start, isHtml) => {
812
927
  const holes = [];
813
928
  let at = start;
@@ -827,7 +942,7 @@ function litTemplates(source) {
827
942
  let at = start;
828
943
  while (at < source.length) {
829
944
  const char = source[at];
830
- if (char === "'" || char === '"') at = skipString(at);
945
+ if (char === "'" || char === '"') at = endOfString(source, at);
831
946
  else if (source.startsWith('//', at)) at = source.indexOf('\n', at) >>> 0;
832
947
  else if (source.startsWith('/*', at)) at = source.indexOf('*/', at) >>> 0;
833
948
  else if (char === '`') at = readTemplate(at + 1, source.slice(at - 4, at) === 'html');
@@ -853,7 +968,7 @@ export function parseLit(source) {
853
968
  let text = source.slice(start, end);
854
969
  if (!text.includes('<nldd-')) return [];
855
970
  for (const [from, to] of holes) {
856
- const filler = `\${${'x'.repeat(to - from - 3)}}`;
971
+ const filler = boundFiller(to - from);
857
972
  text = text.slice(0, from - start) + filler + text.slice(to - start);
858
973
  }
859
974
  const root = createRoot();
@@ -1049,8 +1164,11 @@ function readJsxExpression(expression, parent, flags, roots) {
1049
1164
  case 'JSXEmptyExpression':
1050
1165
  break;
1051
1166
  case 'Literal':
1167
+ // `{true}`, `{false}` and `{null}` render nothing; a string or a number is text.
1168
+ if ((typeof expression.value === 'string' && expression.value.trim()) || typeof expression.value === 'number') parent.text = true;
1169
+ break;
1052
1170
  case 'TemplateLiteral':
1053
- if (expression.value !== '' && expression.value !== null) parent.text = true;
1171
+ if (expression.expressions.length > 0 || expression.quasis.some((quasi) => (quasi.value.cooked ?? quasi.value.raw).trim())) parent.text = true;
1054
1172
  break;
1055
1173
  case 'LogicalExpression':
1056
1174
  // The left of `a && <x />` renders nothing worth counting.