@luxalgo/vela-ui 0.0.0-stage → 0.1.0
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/CHANGELOG.md +43 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +83 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +41 -0
- package/dist/button.js +10 -0
- package/dist/calendar.d.ts +22 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +98 -0
- package/dist/callout-bubble.js +173 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-2Q4JRINP.js +403 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-5QHXOAZA.js +351 -0
- package/dist/chunk-6NXY62JS.js +25 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-AJ2IYSOI.js +553 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-CH3DV6FD.js +280 -0
- package/dist/chunk-EZQXTO6K.js +89 -0
- package/dist/chunk-FCO3YZLT.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-IDA2BT7D.js +29 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-OBLIX3VN.js +227 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-SAPURP46.js +133 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-V6TTTMTE.js +79 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-X4YPSIW6.js +72 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XJAPCCOJ.js +101 -0
- package/dist/chunk-ZB3BZHSN.js +219 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +15 -0
- package/dist/css.js +4 -0
- package/dist/data-table-DtU3FX9j.d.ts +61 -0
- package/dist/data-table.d.ts +3 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +86 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +3854 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.js +150 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +188 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1745 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +211 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +247 -0
- package/llms.txt +66 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +303 -0
- package/registry/callout-bubble.ts +336 -0
- package/registry/checkbox.ts +234 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +392 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +134 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +303 -0
- package/src/components/callout-bubble.ts +336 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +392 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +112 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +131 -0
- package/src/lib/css.ts +44 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +654 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@luxalgo/vela-ui`, newest first. Vela's own changes, including how it
|
|
4
|
+
uses the kit, are in [Vela's changelog](../../CHANGELOG.md).
|
|
5
|
+
|
|
6
|
+
## [0.1.0]
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **The first release of Vela's component kit as a package of its own.** Buttons, badges,
|
|
11
|
+
tabs, toggle groups, dialogs, drawers, dropdown and context menus, tooltips, hover cards,
|
|
12
|
+
popovers, form controls (checkbox, switch, input and input group, text area, number field,
|
|
13
|
+
select, color picker, date picker, the settings field layer) and data components (data
|
|
14
|
+
table, stat, sparkline, donut, bar, line and scatter charts, key caps, empty states), one
|
|
15
|
+
import path each (`@luxalgo/vela-ui/<name>`), so a bundle holds only what it imports. Every
|
|
16
|
+
component is `create<Name>(props)`, returning a handle with its element and `destroy()`;
|
|
17
|
+
overlays and composite controls run Zag state machines for their keyboard behavior and
|
|
18
|
+
accessibility. `disposeWithin(root)` releases every control in a subtree you discard.
|
|
19
|
+
- **One typed theme config.** `createTheme` builds a theme from a brand color, a radius
|
|
20
|
+
scale, a font, any token by name, each component's settings and, when settings are not
|
|
21
|
+
enough, a component's CSS by part; `applyTheme` writes it once per document as a rule in
|
|
22
|
+
the `vela.theme` cascade layer. `checkTheme` lists what a theme gets wrong, a theme of
|
|
23
|
+
colors alone is plain JSON checked by the shipped JSON Schema, and the dark and light
|
|
24
|
+
themes also ship as plain CSS files.
|
|
25
|
+
- **Styles that give way to yours.** Component CSS sits in the `vela.ui` cascade layer and
|
|
26
|
+
styles parts by their `data-slot`, variants by `data-variant` and `data-size`, so a page's
|
|
27
|
+
own CSS overrides it without `!important`. Every scroller inside a kit host shows one
|
|
28
|
+
themeable scrollbar (`scroll`, `scroll-size`).
|
|
29
|
+
- **A reference inside the package.** `manifest.json` (every component's import, props,
|
|
30
|
+
variants, parts, settings, the tokens it reads and an example), `theme.schema.json`, the
|
|
31
|
+
guides (theming, what to change and where, writing a component) and `llms.txt` for coding
|
|
32
|
+
agents, all generated from the source.
|
|
33
|
+
- **Agent skills.** Three skills in `skills/` teach a coding agent to use the components,
|
|
34
|
+
theme them and write new ones, in the Agent Skills format: `npx skills experimental_sync`
|
|
35
|
+
links them into a project once the package is installed, and `npx skills add LuxAlgo/Vela`
|
|
36
|
+
installs them from the repository. `llms.txt` and the `AGENTS.md` block `add` writes point
|
|
37
|
+
at them.
|
|
38
|
+
- **A command line and a lint config.** `npx @luxalgo/vela-ui add`, `diff`, `check` and
|
|
39
|
+
`list`; `@luxalgo/vela-ui/stylelint` checks CSS written with the kit's `css` tag against the
|
|
40
|
+
kit's rules.
|
|
41
|
+
|
|
42
|
+
ES modules only, for the browsers with `color-mix()`: Chrome and Edge 111, Firefox 113,
|
|
43
|
+
Safari 16.2.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Vela
|
|
2
|
+
Copyright (c) 2026 LuxAlgo
|
|
3
|
+
https://velacharts.dev
|
|
4
|
+
|
|
5
|
+
This product includes the Vela charting library, developed by LuxAlgo.
|
|
6
|
+
|
|
7
|
+
ATTRIBUTION REQUIREMENT
|
|
8
|
+
|
|
9
|
+
Any product, website, or application that displays charts rendered by this
|
|
10
|
+
software must show a visible attribution to the Vela project on every page or
|
|
11
|
+
screen where such a chart is displayed.
|
|
12
|
+
|
|
13
|
+
The library satisfies this requirement automatically: it renders an attribution
|
|
14
|
+
mark (the project logomark linking to the Vela project page) on the chart
|
|
15
|
+
itself, enabled by default. You may restyle or reposition this mark to fit your
|
|
16
|
+
design.
|
|
17
|
+
|
|
18
|
+
You may disable the built-in mark (renderer feature `attribution`) ONLY if you
|
|
19
|
+
display an equivalent visible attribution — the name "Vela" together with a
|
|
20
|
+
link to the project page above — elsewhere on the same page or screen, in a
|
|
21
|
+
place available to your users.
|
|
22
|
+
|
|
23
|
+
Removing, hiding, or obscuring the attribution without providing the
|
|
24
|
+
equivalent notice described above is not permitted.
|
|
25
|
+
|
|
26
|
+
This file constitutes the NOTICE file described in Section 4(d) of the Apache
|
|
27
|
+
License, Version 2.0: redistributions of this software, in source or binary
|
|
28
|
+
form, must include a readable copy of these attribution notices.
|
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @luxalgo/vela-ui
|
|
2
|
+
|
|
3
|
+
The component kit of Vela: buttons, tabs, toggle groups, badges, dialogs, drawers, menus,
|
|
4
|
+
tooltips, popovers and form controls. One file per component, Zag state machines for
|
|
5
|
+
behavior, CSS in cascade layers over design tokens, and one typed theme config. It works
|
|
6
|
+
without the chart.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { createButton } from '@luxalgo/vela-ui/button';
|
|
10
|
+
import { createTheme, ensureUIHost } from '@luxalgo/vela-ui/theme';
|
|
11
|
+
|
|
12
|
+
const app = document.getElementById('app')!;
|
|
13
|
+
ensureUIHost(app, createTheme({ accent: '#7c3aed' }));
|
|
14
|
+
|
|
15
|
+
const save = createButton({ text: 'Save', variant: 'default' });
|
|
16
|
+
app.append(save.el);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`ensureUIHost` makes the element a kit host: it carries the theme and the kit's base styles,
|
|
20
|
+
and menus, dialogs and tooltips opened from inside it mount there, themed. `applyTheme(app,
|
|
21
|
+
theme)` switches a host to another theme later.
|
|
22
|
+
|
|
23
|
+
- **One import path per component** (`@luxalgo/vela-ui/<name>`), so a bundle holds only the
|
|
24
|
+
components it imports. Every component is `create<Name>(props)`, returning a handle with
|
|
25
|
+
`el` and `destroy()`. When you discard a whole subtree, `disposeWithin(root)`
|
|
26
|
+
(`@luxalgo/vela-ui/dispose`) releases every control in it, handles kept or not: controls
|
|
27
|
+
that run a state machine must be released, not only removed, or their page-wide listeners
|
|
28
|
+
stay behind. A destroyed dialog, drawer or popover releases its content itself.
|
|
29
|
+
- **Styles give way to yours.** Component CSS sits in the `vela.ui` cascade layer, so a
|
|
30
|
+
page's own CSS overrides it without `!important`. Every part carries a `data-slot`;
|
|
31
|
+
variants and sizes are `data-variant` and `data-size`.
|
|
32
|
+
- **One theme config.** `createTheme` sets the brand color, radius and font, any token by
|
|
33
|
+
name, each component's settings, or a component's whole look; a wrong name fails the
|
|
34
|
+
typecheck. See [Theming](docs/theming.md) and [What to change, and where](docs/what-to-change.md).
|
|
35
|
+
|
|
36
|
+
## Command line
|
|
37
|
+
|
|
38
|
+
| Command | Result |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `npx @luxalgo/vela-ui add button` | makes `@luxalgo/vela-ui` a direct dependency and prints the button's import and an example |
|
|
41
|
+
| `npx @luxalgo/vela-ui add button --source` | copies the button's source into the project (`src/ui` by default) as a component of your own, `app-button` (`--as` names it), which never styles the package's button |
|
|
42
|
+
| `npx @luxalgo/vela-ui diff app-button` | what changed upstream since the copy was made; `--accept` records the copy as up to date |
|
|
43
|
+
| `npx @luxalgo/vela-ui check` | one copy of the package installed, no copy behind it, the theme file valid |
|
|
44
|
+
| `npx @luxalgo/vela-ui list` | the components |
|
|
45
|
+
|
|
46
|
+
A `vela-ui.json` at the project's root says where copies go and which theme file to check:
|
|
47
|
+
`{ "aliases": { "ui": "#ui" }, "theme": "brand.theme.json" }` (`#ui` is a package.json
|
|
48
|
+
`imports` alias, or write a folder). Copies are recorded in `vela-ui.lock.json`, with their
|
|
49
|
+
upstream version kept under `.vela-ui/`: commit both. The first `add` offers to add a note to
|
|
50
|
+
the project's `AGENTS.md` pointing coding agents at this package's reference.
|
|
51
|
+
|
|
52
|
+
## For coding agents
|
|
53
|
+
|
|
54
|
+
Three agent skills ship in `skills/`: [using the components](skills/using-vela-ui-components/SKILL.md),
|
|
55
|
+
[theming](skills/theming-vela-ui/SKILL.md) and [writing components](skills/writing-vela-ui-components/SKILL.md).
|
|
56
|
+
`npx skills experimental_sync` links them into a project's agent once the package is installed
|
|
57
|
+
(Vela's own package pulls them in too), and `npx skills add LuxAlgo/Vela` installs them from
|
|
58
|
+
the repository. [`llms.txt`](llms.txt) indexes them with the rest of the reference.
|
|
59
|
+
|
|
60
|
+
## Reference
|
|
61
|
+
|
|
62
|
+
- `dist/manifest.json` (`@luxalgo/vela-ui/manifest.json`): every component's import, props,
|
|
63
|
+
variants, parts and slots, settings, the tokens it reads and an example, generated from
|
|
64
|
+
the source.
|
|
65
|
+
- `dist/theme.schema.json` (`@luxalgo/vela-ui/theme.schema.json`): the JSON Schema of a theme
|
|
66
|
+
written to a file.
|
|
67
|
+
- `llms.txt`: a short index of the above, for coding agents.
|
|
68
|
+
- [Writing a component](docs/writing-a-component.md): the one-file shape and its rules.
|
|
69
|
+
- `@luxalgo/vela-ui/stylelint`: the shared stylelint config for CSS written with the `css`
|
|
70
|
+
tag (tokens through `t`, no raw colors, logical directions, parts not classes). Extend it
|
|
71
|
+
and name your layer: `vela.ui` for components of your own, so themes restyle them like the
|
|
72
|
+
kit's, and `vela.custom` for CSS that restyles components
|
|
73
|
+
(`{ extends: ['@luxalgo/vela-ui/stylelint'], rules: { 'vela/layer': 'vela.ui' } }`). It
|
|
74
|
+
needs `stylelint`, `postcss-lit` and `stylelint-config-recommended`.
|
|
75
|
+
CSS outside the kit takes the tag and the tokens from `@luxalgo/vela-ui/css` and
|
|
76
|
+
`@luxalgo/vela-ui/t`.
|
|
77
|
+
- `@luxalgo/vela-ui/stylelint/lint`: `lintCss({ files, baseline?, update? })` runs that config
|
|
78
|
+
and fails when postcss-lit skips a template (it would pass while checking nothing). With a
|
|
79
|
+
`baseline` file, CSS written before the rules keeps its known violations, counted per file
|
|
80
|
+
and rule: the run fails when a count grows, and when one shrinks until `update: true`
|
|
81
|
+
rewrites the file, so the baseline only tightens.
|
|
82
|
+
|
|
83
|
+
ES modules only. Licensed under Apache-2.0.
|
package/cli/engine.mjs
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// The vela-ui CLI's engine, exported (`@luxalgo/vela-ui/cli`) so another CLI can reuse it: the
|
|
2
|
+
// catalog (the manifest and registry this package ships), dependency checks, source copies
|
|
3
|
+
// with their lock and base files, upstream diffs, and the project check.
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
6
|
+
|
|
7
|
+
export const PACKAGE = '@luxalgo/vela-ui';
|
|
8
|
+
export const CONFIG_FILE = 'vela-ui.json';
|
|
9
|
+
export const LOCK_FILE = 'vela-ui.lock.json';
|
|
10
|
+
/** Where each copy's upstream version is kept, the base `diff` compares against. */
|
|
11
|
+
export const BASE_DIR = '.vela-ui';
|
|
12
|
+
|
|
13
|
+
const readJson = (path, fallback) => (existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : fallback);
|
|
14
|
+
const writeJson = (path, value) => writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
15
|
+
|
|
16
|
+
/** The catalog a command reads: this package, or a checkout's (`--from`). */
|
|
17
|
+
export function readCatalog(from) {
|
|
18
|
+
const own = resolve(import.meta.dirname, '..');
|
|
19
|
+
const root = from ? (existsSync(join(from, 'packages/vela-ui/package.json')) ? join(from, 'packages/vela-ui') : resolve(from)) : own;
|
|
20
|
+
const manifestPath = join(root, 'dist/manifest.json');
|
|
21
|
+
if (!existsSync(manifestPath)) throw new Error(`No manifest at ${manifestPath}: build the package first (npm run build -w ${PACKAGE}).`);
|
|
22
|
+
const { version } = readJson(join(root, 'package.json'));
|
|
23
|
+
return { root, version, manifest: readJson(manifestPath) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A catalog item by its file name or its component name. */
|
|
27
|
+
export function findItem(catalog, name) {
|
|
28
|
+
return catalog.manifest.components.find((c) => c.name === name || c.component === name) ?? null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function detectPackageManager(cwd) {
|
|
32
|
+
if (existsSync(join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
33
|
+
if (existsSync(join(cwd, 'yarn.lock'))) return 'yarn';
|
|
34
|
+
if (existsSync(join(cwd, 'bun.lockb')) || existsSync(join(cwd, 'bun.lock'))) return 'bun';
|
|
35
|
+
return 'npm';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function installCommand(pm, spec) {
|
|
39
|
+
return pm === 'npm' ? `npm install ${spec}` : `${pm} add ${spec}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Whether the project lists the package itself (pnpm only lets a project import those). */
|
|
43
|
+
export function isDirectDependency(cwd) {
|
|
44
|
+
const pkg = readJson(join(cwd, 'package.json'), {});
|
|
45
|
+
return Boolean(pkg.dependencies?.[PACKAGE] ?? pkg.devDependencies?.[PACKAGE] ?? pkg.peerDependencies?.[PACKAGE]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function readConfig(cwd) {
|
|
49
|
+
return readJson(join(cwd, CONFIG_FILE), {});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The folder copies go to: `aliases.ui`, a path or a package.json `imports` alias (`#ui`). */
|
|
53
|
+
export function copyFolder(cwd, config = readConfig(cwd)) {
|
|
54
|
+
const alias = config.aliases?.ui ?? 'src/ui';
|
|
55
|
+
if (!alias.startsWith('#')) return resolve(cwd, alias);
|
|
56
|
+
const imports = readJson(join(cwd, 'package.json'), {}).imports ?? {};
|
|
57
|
+
const target = imports[`${alias}/*`];
|
|
58
|
+
const path = typeof target === 'string' ? target : target?.default;
|
|
59
|
+
if (!path) throw new Error(`${CONFIG_FILE} sends copies to ${alias}, but package.json has no "imports" entry for "${alias}/*".`);
|
|
60
|
+
return resolve(cwd, path.slice(0, path.indexOf('*')).replace(/\/$/, ''));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A component's source under a new name: its parts, its settings' variables and its sheet
|
|
64
|
+
* follow the name, so the copy and the package's component never style each other. */
|
|
65
|
+
export function renameComponent(source, from, to) {
|
|
66
|
+
if (from === to) return source;
|
|
67
|
+
// Component names are lowercase words joined by dashes: nothing in them needs escaping.
|
|
68
|
+
for (const name of [from, to]) if (!COMPONENT_NAME.test(name)) throw new Error(`"${name}" is not a component name (lowercase words joined by dashes).`);
|
|
69
|
+
return source
|
|
70
|
+
.replace(new RegExp(`(name:\\s*)(['"])${from}\\2`), `$1$2${to}$2`)
|
|
71
|
+
.replace(new RegExp(`(\\[data-slot~?=)(['"])${from}(?=['"-])`, 'g'), `$1$2${to}`)
|
|
72
|
+
.replace(new RegExp(`(['"])vela-ui-${from}\\1`, 'g'), `$1vela-ui-${to}$1`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const COMPONENT_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
76
|
+
|
|
77
|
+
/** The registry file of an item, renamed. */
|
|
78
|
+
export function itemSource(catalog, item, as) {
|
|
79
|
+
const path = join(catalog.root, 'registry', `${item.name}.ts`);
|
|
80
|
+
if (!existsSync(path)) throw new Error(`No registry file for ${item.name} in ${catalog.root}: build the package first.`);
|
|
81
|
+
return renameComponent(readFileSync(path, 'utf8'), item.component ?? item.name, as);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Copy an item's source into the project, recording it in the lock and keeping its base. */
|
|
85
|
+
export function copyItem({ cwd, catalog, item, as, force = false }) {
|
|
86
|
+
const folder = copyFolder(cwd);
|
|
87
|
+
const file = join(folder, `${as}.ts`);
|
|
88
|
+
if (existsSync(file) && !force) throw new Error(`${relative(cwd, file)} exists. Pass --force to overwrite it, or --as <name> for another copy.`);
|
|
89
|
+
const source = itemSource(catalog, item, as);
|
|
90
|
+
const header = `// Copied from ${PACKAGE} ${catalog.version} (${item.name}) by \`vela-ui add --source\`. Yours to change;\n// \`vela-ui diff ${as}\` shows what changed upstream since.\n`;
|
|
91
|
+
mkdirSync(folder, { recursive: true });
|
|
92
|
+
writeFileSync(file, header + source);
|
|
93
|
+
mkdirSync(join(cwd, BASE_DIR), { recursive: true });
|
|
94
|
+
writeFileSync(join(cwd, BASE_DIR, `${as}.ts`), source);
|
|
95
|
+
const lock = readJson(join(cwd, LOCK_FILE), { items: {} });
|
|
96
|
+
lock.items[as] = { item: item.name, version: catalog.version, file: relative(cwd, file).split('\\').join('/') };
|
|
97
|
+
writeJson(join(cwd, LOCK_FILE), lock);
|
|
98
|
+
return { file };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Line diff (longest common subsequence), as unified hunks with `context` lines around. */
|
|
102
|
+
export function diffLines(before, after, context = 3) {
|
|
103
|
+
const a = before.split(/\r?\n/);
|
|
104
|
+
const b = after.split(/\r?\n/);
|
|
105
|
+
const n = a.length;
|
|
106
|
+
const m = b.length;
|
|
107
|
+
const lcs = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
|
108
|
+
for (let i = n - 1; i >= 0; i -= 1) for (let j = m - 1; j >= 0; j -= 1) lcs[i][j] = a[i] === b[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
109
|
+
const ops = [];
|
|
110
|
+
let i = 0;
|
|
111
|
+
let j = 0;
|
|
112
|
+
while (i < n || j < m) {
|
|
113
|
+
if (i < n && j < m && a[i] === b[j]) {
|
|
114
|
+
ops.push(` ${a[i]}`);
|
|
115
|
+
i += 1;
|
|
116
|
+
j += 1;
|
|
117
|
+
} else if (i < n && (j === m || lcs[i + 1][j] >= lcs[i][j + 1])) ops.push(`-${a[i++]}`);
|
|
118
|
+
else ops.push(`+${b[j++]}`);
|
|
119
|
+
}
|
|
120
|
+
const shown = new Uint8Array(ops.length);
|
|
121
|
+
ops.forEach((op, k) => {
|
|
122
|
+
if (op[0] !== ' ') for (let c = Math.max(0, k - context); c <= Math.min(ops.length - 1, k + context); c += 1) shown[c] = 1;
|
|
123
|
+
});
|
|
124
|
+
const out = [];
|
|
125
|
+
ops.forEach((op, k) => {
|
|
126
|
+
if (!shown[k]) return;
|
|
127
|
+
if (k > 0 && !shown[k - 1] && out.length) out.push('@@');
|
|
128
|
+
out.push(op);
|
|
129
|
+
});
|
|
130
|
+
return out.join('\n');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** What changed upstream since a copy was made: its base against the catalog's version. */
|
|
134
|
+
export function upstreamDiff({ cwd, catalog, as }) {
|
|
135
|
+
const entry = readJson(join(cwd, LOCK_FILE), { items: {} }).items[as];
|
|
136
|
+
if (!entry) throw new Error(`${as} is not a copy recorded in ${LOCK_FILE}.`);
|
|
137
|
+
const item = findItem(catalog, entry.item);
|
|
138
|
+
if (!item) throw new Error(`${entry.item} is no longer in ${PACKAGE} ${catalog.version}.`);
|
|
139
|
+
const base = readFileSync(join(cwd, BASE_DIR, `${as}.ts`), 'utf8');
|
|
140
|
+
const next = itemSource(catalog, item, as);
|
|
141
|
+
return { entry, base, next, diff: base === next ? '' : diffLines(base, next) };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Record that a copy has taken the upstream changes in: its base and version move up. */
|
|
145
|
+
export function acceptUpstream({ cwd, catalog, as }) {
|
|
146
|
+
const { next } = upstreamDiff({ cwd, catalog, as });
|
|
147
|
+
writeFileSync(join(cwd, BASE_DIR, `${as}.ts`), next);
|
|
148
|
+
const lock = readJson(join(cwd, LOCK_FILE), { items: {} });
|
|
149
|
+
lock.items[as].version = catalog.version;
|
|
150
|
+
writeJson(join(cwd, LOCK_FILE), lock);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const MARK_BEGIN = '<!-- BEGIN:vela-ui-agent-rules -->';
|
|
154
|
+
const MARK_END = '<!-- END:vela-ui-agent-rules -->';
|
|
155
|
+
|
|
156
|
+
export function agentsBlock() {
|
|
157
|
+
return `${MARK_BEGIN}
|
|
158
|
+
## ${PACKAGE}
|
|
159
|
+
|
|
160
|
+
Before writing UI with \`${PACKAGE}\`, read \`node_modules/${PACKAGE}/llms.txt\`: it indexes the
|
|
161
|
+
component manifest, the theme schema, the guides and the agent skills
|
|
162
|
+
(\`node_modules/${PACKAGE}/skills/*/SKILL.md\`) of the installed version. Mount components in a
|
|
163
|
+
kit host (\`ensureUIHost\`); themes go through \`createTheme\`; restyle a component through its
|
|
164
|
+
parts, never its class names.
|
|
165
|
+
${MARK_END}
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function hasAgentsBlock(cwd) {
|
|
170
|
+
const path = join(cwd, 'AGENTS.md');
|
|
171
|
+
return existsSync(path) && readFileSync(path, 'utf8').includes(MARK_BEGIN);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function writeAgentsBlock(cwd) {
|
|
175
|
+
const path = join(cwd, 'AGENTS.md');
|
|
176
|
+
const text = existsSync(path) ? readFileSync(path, 'utf8') : '';
|
|
177
|
+
if (text.includes(MARK_BEGIN)) return false;
|
|
178
|
+
writeFileSync(path, `${text}${text && !text.endsWith('\n\n') ? (text.endsWith('\n') ? '\n' : '\n\n') : ''}${agentsBlock()}`);
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Every installed copy of the package under the project's node_modules. */
|
|
183
|
+
export function installedCopies(cwd) {
|
|
184
|
+
const found = [];
|
|
185
|
+
const visit = (dir, depth) => {
|
|
186
|
+
if (depth > 5 || !existsSync(dir)) return;
|
|
187
|
+
const own = join(dir, '@luxalgo', 'vela-ui', 'package.json');
|
|
188
|
+
if (existsSync(own)) found.push({ path: dirname(own), version: readJson(own).version });
|
|
189
|
+
for (const name of readdirSync(dir)) {
|
|
190
|
+
if (name === '.bin') continue;
|
|
191
|
+
const sub = join(dir, name);
|
|
192
|
+
if (name.startsWith('@')) {
|
|
193
|
+
for (const inner of existsSync(sub) ? readdirSync(sub) : []) visit(join(sub, inner, 'node_modules'), depth + 1);
|
|
194
|
+
} else if (name === '.pnpm') {
|
|
195
|
+
for (const inner of readdirSync(sub)) if (inner.startsWith('@luxalgo+vela-ui@')) visit(join(sub, inner, 'node_modules'), depth + 1);
|
|
196
|
+
} else visit(join(sub, 'node_modules'), depth + 1);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
visit(join(cwd, 'node_modules'), 0);
|
|
200
|
+
// A link and the folder it points to are one copy (pnpm links each package from its store).
|
|
201
|
+
const seen = new Set();
|
|
202
|
+
return found.filter((c) => {
|
|
203
|
+
const real = realpathSync(c.path);
|
|
204
|
+
return !seen.has(real) && seen.add(real);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const compareVersions = (x, y) => {
|
|
209
|
+
const p = (v) => v.split(/[.-]/).map((s) => (Number.isNaN(Number(s)) ? 0 : Number(s)));
|
|
210
|
+
const [a, b] = [p(x), p(y)];
|
|
211
|
+
for (let k = 0; k < Math.max(a.length, b.length); k += 1) if ((a[k] ?? 0) !== (b[k] ?? 0)) return (a[k] ?? 0) - (b[k] ?? 0);
|
|
212
|
+
return 0;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/** Validates a value against the subset of JSON Schema the theme schema uses. */
|
|
216
|
+
export function validate(schema, value, root = schema, at = '') {
|
|
217
|
+
if (schema.$ref) return validate(schema.$ref.slice(2).split('/').reduce((s, k) => s[k], root), value, root, at);
|
|
218
|
+
if (schema.oneOf) {
|
|
219
|
+
const ok = schema.oneOf.filter((s) => validate(s, value, root, at).length === 0);
|
|
220
|
+
return ok.length === 1 ? [] : [`${at || '/'}: matches ${ok.length} of the allowed shapes, not one`];
|
|
221
|
+
}
|
|
222
|
+
if (schema.enum && !schema.enum.includes(value)) return [`${at || '/'}: must be one of ${schema.enum.join(', ')}`];
|
|
223
|
+
if (schema.type === 'string') {
|
|
224
|
+
if (typeof value !== 'string') return [`${at}: must be a string`];
|
|
225
|
+
if (schema.pattern && !new RegExp(schema.pattern).test(value)) return [`${at}: "${value}" is not a color (#rrggbb, rgb() or var())`];
|
|
226
|
+
return [];
|
|
227
|
+
}
|
|
228
|
+
if (schema.type === 'object') {
|
|
229
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return [`${at || '/'}: must be an object`];
|
|
230
|
+
const errors = [];
|
|
231
|
+
for (const key of schema.required ?? []) if (!(key in value)) errors.push(`${at}/${key}: is required`);
|
|
232
|
+
for (const [key, v] of Object.entries(value)) {
|
|
233
|
+
const sub = schema.properties?.[key];
|
|
234
|
+
if (sub) errors.push(...validate(sub, v, root, `${at}/${key}`));
|
|
235
|
+
else if (schema.additionalProperties === false) errors.push(`${at}/${key}: is not a known field`);
|
|
236
|
+
}
|
|
237
|
+
return errors;
|
|
238
|
+
}
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The project's health: one copy of the package, copies of components not behind it, and
|
|
243
|
+
* the theme file valid (against the schema, then `checkTheme`, the package's own, when
|
|
244
|
+
* given). Each finding is `{ level: 'error' | 'warn', text }`. */
|
|
245
|
+
// The caller loads `checkTheme`: a computed `import()` in this file hangs Vite's SSR
|
|
246
|
+
// transform, which the tests load it through.
|
|
247
|
+
export function checkProject({ cwd, catalog, checkTheme }) {
|
|
248
|
+
const findings = [];
|
|
249
|
+
const copies = installedCopies(cwd);
|
|
250
|
+
const versions = [...new Set(copies.map((c) => c.version))];
|
|
251
|
+
if (copies.length === 0) findings.push({ level: 'error', text: `${PACKAGE} is not installed (${installCommand(detectPackageManager(cwd), PACKAGE)}).` });
|
|
252
|
+
else if (copies.length > 1)
|
|
253
|
+
findings.push({ level: 'error', text: `${copies.length} copies of ${PACKAGE} are installed (${versions.join(', ')}): a page would carry every component twice. Align the versions that depend on it.\n${copies.map((c) => ` ${relative(cwd, c.path)} ${c.version}`).join('\n')}` });
|
|
254
|
+
if (copies.length && !isDirectDependency(cwd)) findings.push({ level: 'warn', text: `${PACKAGE} is installed but not a direct dependency; pnpm will not let the project import it.` });
|
|
255
|
+
const installed = copies[0]?.version ?? catalog.version;
|
|
256
|
+
const lock = readJson(join(cwd, LOCK_FILE), { items: {} });
|
|
257
|
+
for (const [as, entry] of Object.entries(lock.items)) {
|
|
258
|
+
if (!existsSync(join(cwd, entry.file))) findings.push({ level: 'warn', text: `${as}: ${entry.file} is gone; remove it from ${LOCK_FILE}.` });
|
|
259
|
+
else if (compareVersions(entry.version, installed) < 0) findings.push({ level: 'warn', text: `${as} was copied from ${entry.version}; ${installed} is installed. \`vela-ui diff ${as}\` shows what changed.` });
|
|
260
|
+
}
|
|
261
|
+
const config = readConfig(cwd);
|
|
262
|
+
if (config.theme) {
|
|
263
|
+
const themeFile = resolve(cwd, config.theme);
|
|
264
|
+
if (!existsSync(themeFile)) findings.push({ level: 'error', text: `The theme file ${config.theme} does not exist.` });
|
|
265
|
+
else {
|
|
266
|
+
let input;
|
|
267
|
+
try {
|
|
268
|
+
input = JSON.parse(readFileSync(themeFile, 'utf8'));
|
|
269
|
+
} catch (e) {
|
|
270
|
+
findings.push({ level: 'error', text: `${config.theme} is not valid JSON: ${e.message}` });
|
|
271
|
+
}
|
|
272
|
+
if (input) {
|
|
273
|
+
const schema = readJson(join(catalog.root, 'dist/theme.schema.json'));
|
|
274
|
+
for (const text of validate(schema, input)) findings.push({ level: 'error', text: `${config.theme}${text}` });
|
|
275
|
+
const theme = { ...input };
|
|
276
|
+
delete theme.$schema;
|
|
277
|
+
for (const text of checkTheme?.(theme) ?? []) findings.push({ level: 'warn', text: `${config.theme}: ${text}` });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return findings;
|
|
282
|
+
}
|