numori-ui 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.
Files changed (130) hide show
  1. package/LICENSE +651 -0
  2. package/README.md +466 -0
  3. package/dist/components/Alert.js +137 -0
  4. package/dist/components/Alert.js.map +1 -0
  5. package/dist/components/Avatar.js +133 -0
  6. package/dist/components/Avatar.js.map +1 -0
  7. package/dist/components/Badge.js +93 -0
  8. package/dist/components/Badge.js.map +1 -0
  9. package/dist/components/Button.js +428 -0
  10. package/dist/components/Button.js.map +1 -0
  11. package/dist/components/ButtonsGroup.js +153 -0
  12. package/dist/components/ButtonsGroup.js.map +1 -0
  13. package/dist/components/Checkbox.js +93 -0
  14. package/dist/components/Checkbox.js.map +1 -0
  15. package/dist/components/Divider.js +79 -0
  16. package/dist/components/Divider.js.map +1 -0
  17. package/dist/components/Dropdown.js +166 -0
  18. package/dist/components/Dropdown.js.map +1 -0
  19. package/dist/components/DropdownItem.js +106 -0
  20. package/dist/components/DropdownItem.js.map +1 -0
  21. package/dist/components/DropdownRow.js +41 -0
  22. package/dist/components/DropdownRow.js.map +1 -0
  23. package/dist/components/DropdownSubmenu.js +142 -0
  24. package/dist/components/DropdownSubmenu.js.map +1 -0
  25. package/dist/components/FileInput.js +122 -0
  26. package/dist/components/FileInput.js.map +1 -0
  27. package/dist/components/FormField.js +112 -0
  28. package/dist/components/FormField.js.map +1 -0
  29. package/dist/components/Input.js +603 -0
  30. package/dist/components/Input.js.map +1 -0
  31. package/dist/components/Kbd.js +35 -0
  32. package/dist/components/Kbd.js.map +1 -0
  33. package/dist/components/ListMenu.js +143 -0
  34. package/dist/components/ListMenu.js.map +1 -0
  35. package/dist/components/ListMenuItem.js +189 -0
  36. package/dist/components/ListMenuItem.js.map +1 -0
  37. package/dist/components/Modal.js +206 -0
  38. package/dist/components/Modal.js.map +1 -0
  39. package/dist/components/Numpad.js +123 -0
  40. package/dist/components/Numpad.js.map +1 -0
  41. package/dist/components/Popup.js +170 -0
  42. package/dist/components/Popup.js.map +1 -0
  43. package/dist/components/ProgressBar.js +118 -0
  44. package/dist/components/ProgressBar.js.map +1 -0
  45. package/dist/components/Prompt.js +201 -0
  46. package/dist/components/Prompt.js.map +1 -0
  47. package/dist/components/Radio.js +81 -0
  48. package/dist/components/Radio.js.map +1 -0
  49. package/dist/components/Select.js +441 -0
  50. package/dist/components/Select.js.map +1 -0
  51. package/dist/components/Slider.js +116 -0
  52. package/dist/components/Slider.js.map +1 -0
  53. package/dist/components/Stepper.js +65 -0
  54. package/dist/components/Stepper.js.map +1 -0
  55. package/dist/components/Toggle.js +133 -0
  56. package/dist/components/Toggle.js.map +1 -0
  57. package/dist/components/Tooltip.js +120 -0
  58. package/dist/components/Tooltip.js.map +1 -0
  59. package/dist/components/index.js +81 -0
  60. package/dist/components/index.js.map +1 -0
  61. package/dist/composables/onClickOutside.js +51 -0
  62. package/dist/composables/onClickOutside.js.map +1 -0
  63. package/dist/composables/useBackButton.js +98 -0
  64. package/dist/composables/useBackButton.js.map +1 -0
  65. package/dist/composables/useEventListener.js +63 -0
  66. package/dist/composables/useEventListener.js.map +1 -0
  67. package/dist/icons/Icon.js +120 -0
  68. package/dist/icons/Icon.js.map +1 -0
  69. package/dist/icons/mdi.js +69 -0
  70. package/dist/icons/mdi.js.map +1 -0
  71. package/dist/icons/registry.js +63 -0
  72. package/dist/icons/registry.js.map +1 -0
  73. package/dist/icons/resolver.js +49 -0
  74. package/dist/icons/resolver.js.map +1 -0
  75. package/dist/index.d.ts +108 -0
  76. package/dist/index.js +157 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/manifest.js +89 -0
  79. package/dist/manifest.js.map +1 -0
  80. package/dist/numori-ui.css +184 -0
  81. package/dist/nuxt.d.ts +35 -0
  82. package/dist/nuxt.mjs +243 -0
  83. package/dist/nuxt.mjs.map +1 -0
  84. package/dist/vite.d.ts +29 -0
  85. package/dist/vite.mjs +187 -0
  86. package/dist/vite.mjs.map +1 -0
  87. package/package.json +138 -0
  88. package/src/components/Alert.vue +127 -0
  89. package/src/components/Avatar.vue +100 -0
  90. package/src/components/Badge.vue +77 -0
  91. package/src/components/Button.vue +419 -0
  92. package/src/components/ButtonsGroup.vue +140 -0
  93. package/src/components/Checkbox.vue +81 -0
  94. package/src/components/Divider.vue +64 -0
  95. package/src/components/Dropdown.vue +150 -0
  96. package/src/components/DropdownItem.vue +78 -0
  97. package/src/components/DropdownRow.vue +37 -0
  98. package/src/components/DropdownSubmenu.vue +127 -0
  99. package/src/components/FileInput.vue +107 -0
  100. package/src/components/FormField.vue +86 -0
  101. package/src/components/Input.vue +619 -0
  102. package/src/components/Kbd.vue +30 -0
  103. package/src/components/ListMenu.vue +127 -0
  104. package/src/components/ListMenuItem.vue +171 -0
  105. package/src/components/Modal.vue +209 -0
  106. package/src/components/Numpad.vue +118 -0
  107. package/src/components/Popup.vue +156 -0
  108. package/src/components/ProgressBar.vue +107 -0
  109. package/src/components/Prompt.vue +161 -0
  110. package/src/components/Radio.vue +50 -0
  111. package/src/components/Select.vue +470 -0
  112. package/src/components/Slider.vue +93 -0
  113. package/src/components/Stepper.vue +53 -0
  114. package/src/components/Toggle.vue +125 -0
  115. package/src/components/Tooltip.vue +113 -0
  116. package/src/components/index.js +109 -0
  117. package/src/composables/onClickOutside.js +61 -0
  118. package/src/composables/useBackButton.js +98 -0
  119. package/src/composables/useEventListener.js +65 -0
  120. package/src/icons/Icon.vue +139 -0
  121. package/src/icons/mdi.js +67 -0
  122. package/src/icons/registry.js +64 -0
  123. package/src/icons/resolver.js +48 -0
  124. package/src/index.js +167 -0
  125. package/src/manifest.js +86 -0
  126. package/src/nuxt.js +315 -0
  127. package/src/style.css +20 -0
  128. package/src/tailwind.css +18 -0
  129. package/src/theme.css +172 -0
  130. package/src/vite.js +235 -0
package/src/vite.js ADDED
@@ -0,0 +1,235 @@
1
+ import { createRequire } from 'node:module'
2
+ import { join } from 'node:path'
3
+ import { pathToFileURL } from 'node:url'
4
+ import { COMPONENT_NAMES, DEFAULT_PREFIX, componentEntries, prefixed } from './manifest.js'
5
+
6
+ /**
7
+ * Numori UI — Vite plugin.
8
+ *
9
+ * Gives a plain Vite + Vue app the same ergonomics the Nuxt module gives a Nuxt
10
+ * app: write `<UiButton>` in a template and the import is added for you, with
11
+ * only the components you actually reference ending up in the bundle.
12
+ *
13
+ * Auto-import is delegated to `unplugin-vue-components`, the de facto standard
14
+ * for this in the Vite ecosystem, rather than reimplemented here. It is an
15
+ * optional peer dependency — install it only if you want auto-import:
16
+ *
17
+ * npm i -D unplugin-vue-components
18
+ *
19
+ * Without it (or with `autoImport: false`) the plugin still handles the Tailwind
20
+ * wiring, and you register components the ordinary way with `app.use(NumoriUI)`.
21
+ *
22
+ * @example vite.config.js
23
+ * import vue from '@vitejs/plugin-vue'
24
+ * import numoriUI from 'numori-ui/vite'
25
+ *
26
+ * export default {
27
+ * plugins: [vue(), numoriUI()],
28
+ * }
29
+ *
30
+ * @example Let the plugin own the Tailwind setup too
31
+ * plugins: [vue(), numoriUI({ tailwind: true })]
32
+ */
33
+
34
+ /** Package specifier used for the generated imports. */
35
+ const PKG = 'numori-ui'
36
+
37
+ /**
38
+ * Map of base component name -> import specifier resolvable by the consumer.
39
+ * Uses the package's `./src/*` export so the raw SFCs are compiled by the
40
+ * host's own `@vitejs/plugin-vue`, which is what keeps tree-shaking intact.
41
+ * @returns {Record<string, string>}
42
+ */
43
+ function componentSpecifiers() {
44
+ return Object.fromEntries(
45
+ componentEntries().map(({ name, file }) => [name, `${PKG}/src/${file}`]),
46
+ )
47
+ }
48
+
49
+ /**
50
+ * Resolver for `unplugin-vue-components`.
51
+ *
52
+ * Export it directly when you already run `unplugin-vue-components` yourself
53
+ * and just want Numori UI added to your existing resolver list.
54
+ *
55
+ * @param {object} [options]
56
+ * @param {string} [options.prefix='Ui'] Prefix the components are written with.
57
+ * @returns {{ type: 'component', resolve: (name: string) => { name: string, from: string } | undefined }}
58
+ *
59
+ * @example vite.config.js with your own unplugin setup
60
+ * import Components from 'unplugin-vue-components/vite'
61
+ * import { NumoriUIResolver } from 'numori-ui/vite'
62
+ *
63
+ * export default {
64
+ * plugins: [vue(), Components({ resolvers: [NumoriUIResolver()] })],
65
+ * }
66
+ */
67
+ export function NumoriUIResolver(options = {}) {
68
+ const { prefix = DEFAULT_PREFIX } = options
69
+
70
+ // See src/index.js: an empty prefix would have this resolver claim every
71
+ // bare tag it knows a base name for, including `Button`, whose own root
72
+ // element is a dynamic `button` — which recurses until the stack overflows.
73
+ if (typeof prefix !== 'string' || prefix.length === 0) {
74
+ throw new Error(
75
+ '[numori-ui] `prefix` must be a non-empty string. Registering components under their ' +
76
+ 'bare names would make <Button> resolve its own native `button` root element, ' +
77
+ 'recursing infinitely. Use a prefix such as "Ui" or "N".',
78
+ )
79
+ }
80
+
81
+ const specifiers = componentSpecifiers()
82
+
83
+ return {
84
+ type: 'component',
85
+ resolve(name) {
86
+ if (!name.startsWith(prefix)) return
87
+ const base = name.slice(prefix.length)
88
+ const from = specifiers[base]
89
+ if (!from) return
90
+ // SFCs are default exports.
91
+ return { name: 'default', from }
92
+ },
93
+ }
94
+ }
95
+
96
+ /**
97
+ * The Vite plugin.
98
+ *
99
+ * Returns an array of plugins (Vite flattens these), and resolves
100
+ * asynchronously because the optional integrations are imported on demand —
101
+ * Vite accepts promises in its `plugins` array.
102
+ *
103
+ * @param {object} [options]
104
+ * @param {string} [options.prefix='Ui']
105
+ * Prefix the components are written with in templates.
106
+ * @param {boolean} [options.autoImport=true]
107
+ * Auto-import referenced components via `unplugin-vue-components`.
108
+ * Silently inert (with a hint) if that package isn't installed.
109
+ * @param {boolean} [options.tailwind=false]
110
+ * Also register `@tailwindcss/vite`. Use when you'd rather not add it
111
+ * yourself; requires `@tailwindcss/vite` to be installed.
112
+ * @param {boolean} [options.dts=false]
113
+ * Ask `unplugin-vue-components` to emit a component type declaration file.
114
+ * Off by default — this library is JavaScript-first and most consumers have
115
+ * no use for it.
116
+ * @returns {Promise<Array<import('vite').PluginOption>>}
117
+ */
118
+ export default async function numoriUI(options = {}) {
119
+ const { prefix = DEFAULT_PREFIX, autoImport = true, tailwind = false, dts = false } = options
120
+
121
+ const plugins = [baseConfigPlugin()]
122
+
123
+ if (autoImport) {
124
+ const components = await loadUnpluginComponents()
125
+ if (components) {
126
+ plugins.push(
127
+ components({
128
+ dts,
129
+ // Only touch what our resolver claims; the host's own components
130
+ // directory scanning is left entirely alone.
131
+ dirs: [],
132
+ resolvers: [NumoriUIResolver({ prefix })],
133
+ }),
134
+ )
135
+ }
136
+ }
137
+
138
+ if (tailwind) {
139
+ const tailwindVite = await loadTailwindVite()
140
+ if (tailwindVite) plugins.push(tailwindVite())
141
+ }
142
+
143
+ return plugins
144
+ }
145
+
146
+ /**
147
+ * Small always-on plugin handling the config details that make importing raw
148
+ * SFCs out of `node_modules` behave.
149
+ *
150
+ * @returns {import('vite').Plugin}
151
+ */
152
+ function baseConfigPlugin() {
153
+ return {
154
+ name: 'numori-ui:config',
155
+ enforce: 'pre',
156
+ config() {
157
+ return {
158
+ optimizeDeps: {
159
+ // The dep optimiser only understands JavaScript. Numori UI's
160
+ // components are consumed as `.vue` source so the host compiles
161
+ // them, so the package must stay out of the prebundle.
162
+ exclude: [PKG],
163
+ },
164
+ ssr: {
165
+ // Same reason on the server: the SFCs need the host's vue plugin,
166
+ // which means they must not be externalised.
167
+ noExternal: [PKG],
168
+ },
169
+ }
170
+ },
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Import an optional peer dependency, resolved from the **consuming project**
176
+ * rather than from this package.
177
+ *
178
+ * A bare `import('unplugin-vue-components/vite')` resolves relative to this
179
+ * file, which is wrong for an optional peer: the package is installed in the
180
+ * app's `node_modules`, not ours. That lookup fails outright under pnpm's
181
+ * strict layout and when the package is linked (`file:`/`npm link`), because
182
+ * neither arrangement puts the app's dependencies on our resolution path.
183
+ *
184
+ * Resolving from `process.cwd()` is correct here — a Vite plugin is
185
+ * instantiated while loading `vite.config.js`, with the working directory at
186
+ * the project root.
187
+ *
188
+ * @param {string} specifier Module to load.
189
+ * @returns {Promise<any | null>} The module, or null if it isn't installed.
190
+ */
191
+ async function importFromProject(specifier) {
192
+ const require = createRequire(join(process.cwd(), 'package.json'))
193
+ try {
194
+ return await import(pathToFileURL(require.resolve(specifier)).href)
195
+ } catch {
196
+ // Fall back to our own resolution path, which covers the case where the
197
+ // dependency is hoisted somewhere cwd cannot see it.
198
+ try {
199
+ return await import(specifier)
200
+ } catch {
201
+ return null
202
+ }
203
+ }
204
+ }
205
+
206
+ /**
207
+ * @returns {Promise<Function | null>} unplugin-vue-components' Vite plugin.
208
+ */
209
+ async function loadUnpluginComponents() {
210
+ const mod = await importFromProject('unplugin-vue-components/vite')
211
+ if (mod) return mod.default
212
+
213
+ console.warn(
214
+ '[numori-ui] Auto-import is on but `unplugin-vue-components` could not be resolved.\n' +
215
+ ' Install it: npm i -D unplugin-vue-components\n' +
216
+ ' Or set `autoImport: false` and register components with `app.use(NumoriUI)`.',
217
+ )
218
+ return null
219
+ }
220
+
221
+ /**
222
+ * @returns {Promise<Function | null>} @tailwindcss/vite's plugin.
223
+ */
224
+ async function loadTailwindVite() {
225
+ const mod = await importFromProject('@tailwindcss/vite')
226
+ if (mod) return mod.default
227
+
228
+ console.warn(
229
+ '[numori-ui] `tailwind: true` is set but `@tailwindcss/vite` could not be resolved.\n' +
230
+ ' Install it: npm i -D @tailwindcss/vite',
231
+ )
232
+ return null
233
+ }
234
+
235
+ export { COMPONENT_NAMES, DEFAULT_PREFIX, prefixed }