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.
- package/LICENSE +651 -0
- package/README.md +466 -0
- package/dist/components/Alert.js +137 -0
- package/dist/components/Alert.js.map +1 -0
- package/dist/components/Avatar.js +133 -0
- package/dist/components/Avatar.js.map +1 -0
- package/dist/components/Badge.js +93 -0
- package/dist/components/Badge.js.map +1 -0
- package/dist/components/Button.js +428 -0
- package/dist/components/Button.js.map +1 -0
- package/dist/components/ButtonsGroup.js +153 -0
- package/dist/components/ButtonsGroup.js.map +1 -0
- package/dist/components/Checkbox.js +93 -0
- package/dist/components/Checkbox.js.map +1 -0
- package/dist/components/Divider.js +79 -0
- package/dist/components/Divider.js.map +1 -0
- package/dist/components/Dropdown.js +166 -0
- package/dist/components/Dropdown.js.map +1 -0
- package/dist/components/DropdownItem.js +106 -0
- package/dist/components/DropdownItem.js.map +1 -0
- package/dist/components/DropdownRow.js +41 -0
- package/dist/components/DropdownRow.js.map +1 -0
- package/dist/components/DropdownSubmenu.js +142 -0
- package/dist/components/DropdownSubmenu.js.map +1 -0
- package/dist/components/FileInput.js +122 -0
- package/dist/components/FileInput.js.map +1 -0
- package/dist/components/FormField.js +112 -0
- package/dist/components/FormField.js.map +1 -0
- package/dist/components/Input.js +603 -0
- package/dist/components/Input.js.map +1 -0
- package/dist/components/Kbd.js +35 -0
- package/dist/components/Kbd.js.map +1 -0
- package/dist/components/ListMenu.js +143 -0
- package/dist/components/ListMenu.js.map +1 -0
- package/dist/components/ListMenuItem.js +189 -0
- package/dist/components/ListMenuItem.js.map +1 -0
- package/dist/components/Modal.js +206 -0
- package/dist/components/Modal.js.map +1 -0
- package/dist/components/Numpad.js +123 -0
- package/dist/components/Numpad.js.map +1 -0
- package/dist/components/Popup.js +170 -0
- package/dist/components/Popup.js.map +1 -0
- package/dist/components/ProgressBar.js +118 -0
- package/dist/components/ProgressBar.js.map +1 -0
- package/dist/components/Prompt.js +201 -0
- package/dist/components/Prompt.js.map +1 -0
- package/dist/components/Radio.js +81 -0
- package/dist/components/Radio.js.map +1 -0
- package/dist/components/Select.js +441 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Slider.js +116 -0
- package/dist/components/Slider.js.map +1 -0
- package/dist/components/Stepper.js +65 -0
- package/dist/components/Stepper.js.map +1 -0
- package/dist/components/Toggle.js +133 -0
- package/dist/components/Toggle.js.map +1 -0
- package/dist/components/Tooltip.js +120 -0
- package/dist/components/Tooltip.js.map +1 -0
- package/dist/components/index.js +81 -0
- package/dist/components/index.js.map +1 -0
- package/dist/composables/onClickOutside.js +51 -0
- package/dist/composables/onClickOutside.js.map +1 -0
- package/dist/composables/useBackButton.js +98 -0
- package/dist/composables/useBackButton.js.map +1 -0
- package/dist/composables/useEventListener.js +63 -0
- package/dist/composables/useEventListener.js.map +1 -0
- package/dist/icons/Icon.js +120 -0
- package/dist/icons/Icon.js.map +1 -0
- package/dist/icons/mdi.js +69 -0
- package/dist/icons/mdi.js.map +1 -0
- package/dist/icons/registry.js +63 -0
- package/dist/icons/registry.js.map +1 -0
- package/dist/icons/resolver.js +49 -0
- package/dist/icons/resolver.js.map +1 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +157 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.js +89 -0
- package/dist/manifest.js.map +1 -0
- package/dist/numori-ui.css +184 -0
- package/dist/nuxt.d.ts +35 -0
- package/dist/nuxt.mjs +243 -0
- package/dist/nuxt.mjs.map +1 -0
- package/dist/vite.d.ts +29 -0
- package/dist/vite.mjs +187 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +138 -0
- package/src/components/Alert.vue +127 -0
- package/src/components/Avatar.vue +100 -0
- package/src/components/Badge.vue +77 -0
- package/src/components/Button.vue +419 -0
- package/src/components/ButtonsGroup.vue +140 -0
- package/src/components/Checkbox.vue +81 -0
- package/src/components/Divider.vue +64 -0
- package/src/components/Dropdown.vue +150 -0
- package/src/components/DropdownItem.vue +78 -0
- package/src/components/DropdownRow.vue +37 -0
- package/src/components/DropdownSubmenu.vue +127 -0
- package/src/components/FileInput.vue +107 -0
- package/src/components/FormField.vue +86 -0
- package/src/components/Input.vue +619 -0
- package/src/components/Kbd.vue +30 -0
- package/src/components/ListMenu.vue +127 -0
- package/src/components/ListMenuItem.vue +171 -0
- package/src/components/Modal.vue +209 -0
- package/src/components/Numpad.vue +118 -0
- package/src/components/Popup.vue +156 -0
- package/src/components/ProgressBar.vue +107 -0
- package/src/components/Prompt.vue +161 -0
- package/src/components/Radio.vue +50 -0
- package/src/components/Select.vue +470 -0
- package/src/components/Slider.vue +93 -0
- package/src/components/Stepper.vue +53 -0
- package/src/components/Toggle.vue +125 -0
- package/src/components/Tooltip.vue +113 -0
- package/src/components/index.js +109 -0
- package/src/composables/onClickOutside.js +61 -0
- package/src/composables/useBackButton.js +98 -0
- package/src/composables/useEventListener.js +65 -0
- package/src/icons/Icon.vue +139 -0
- package/src/icons/mdi.js +67 -0
- package/src/icons/registry.js +64 -0
- package/src/icons/resolver.js +48 -0
- package/src/index.js +167 -0
- package/src/manifest.js +86 -0
- package/src/nuxt.js +315 -0
- package/src/style.css +20 -0
- package/src/tailwind.css +18 -0
- package/src/theme.css +172 -0
- package/src/vite.js +235 -0
package/dist/nuxt.mjs
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { COMPONENT_NAMES, DEFAULT_PREFIX, componentEntries, prefixed } from "./manifest.js";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { addComponent, addImports, addPluginTemplate, addTemplate, defineNuxtModule, useLogger } from "@nuxt/kit";
|
|
7
|
+
//#region src/nuxt.js
|
|
8
|
+
/**
|
|
9
|
+
* Absolute path to the package's `src/` directory.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately not derived with `createResolver(import.meta.url)`: that resolves
|
|
12
|
+
* relative to *this file*, which is `dist/nuxt.mjs` once built — so component
|
|
13
|
+
* paths would come out as `dist/components/Button.vue`, which does not exist.
|
|
14
|
+
* The module has to point at the shipped `src/` either way, because handing
|
|
15
|
+
* Nuxt the raw SFCs is what lets it compile and tree-shake them.
|
|
16
|
+
*
|
|
17
|
+
* `dist/` and `src/` are both direct children of the package root, so going up
|
|
18
|
+
* one level works whether this module is running from source (in-repo) or from
|
|
19
|
+
* the published build.
|
|
20
|
+
*/
|
|
21
|
+
var SRC_DIR = join(dirname(dirname(fileURLToPath(import.meta.url))), "src");
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a path inside the package's `src/`.
|
|
24
|
+
* @param {string} relativePath e.g. 'components/Button.vue'
|
|
25
|
+
* @returns {string} Absolute path.
|
|
26
|
+
*/
|
|
27
|
+
var fromSrc = (relativePath) => join(SRC_DIR, relativePath);
|
|
28
|
+
/**
|
|
29
|
+
* Import an optional peer dependency, resolved from the **Nuxt project** rather
|
|
30
|
+
* than from this package.
|
|
31
|
+
*
|
|
32
|
+
* A bare `import('@tailwindcss/vite')` resolves relative to this file, which is
|
|
33
|
+
* wrong for an optional peer: it lives in the app's `node_modules`, not ours.
|
|
34
|
+
* That lookup fails outright under pnpm's strict layout and whenever the package
|
|
35
|
+
* is linked (`file:`/`npm link`), because neither arrangement puts the app's
|
|
36
|
+
* dependencies on our resolution path.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} specifier Module to load.
|
|
39
|
+
* @param {string} projectRoot Directory to resolve from (nuxt.options.rootDir).
|
|
40
|
+
* @returns {Promise<any | null>} The module, or null if it isn't installed.
|
|
41
|
+
*/
|
|
42
|
+
async function importFromProject(specifier, projectRoot) {
|
|
43
|
+
try {
|
|
44
|
+
const require = createRequire(join(projectRoot, "package.json"));
|
|
45
|
+
return await import(pathToFileURL(require.resolve(specifier)).href);
|
|
46
|
+
} catch {
|
|
47
|
+
try {
|
|
48
|
+
return await import(specifier);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Numori UI — Nuxt module.
|
|
56
|
+
*
|
|
57
|
+
* Registers every component so templates can use `<UiButton>` with no import,
|
|
58
|
+
* exposes the library's composables to Nuxt's auto-import system, and can
|
|
59
|
+
* optionally stand up the whole Tailwind v4 pipeline.
|
|
60
|
+
*
|
|
61
|
+
* Components are registered from source (`.vue`), not from the bundled build,
|
|
62
|
+
* so Nuxt compiles them in the app's own Vite pass. That is what makes
|
|
63
|
+
* per-component tree-shaking work: Nuxt only emits the components a template
|
|
64
|
+
* actually references, so an app using three of them ships three.
|
|
65
|
+
*
|
|
66
|
+
* @example nuxt.config.ts
|
|
67
|
+
* export default defineNuxtConfig({
|
|
68
|
+
* modules: ['numori-ui/nuxt'],
|
|
69
|
+
* numoriUi: { prefix: 'Ui' },
|
|
70
|
+
* })
|
|
71
|
+
*/
|
|
72
|
+
var nuxt_default = defineNuxtModule({
|
|
73
|
+
meta: {
|
|
74
|
+
name: "numori-ui",
|
|
75
|
+
configKey: "numoriUi",
|
|
76
|
+
compatibility: { nuxt: ">=3.0.0" }
|
|
77
|
+
},
|
|
78
|
+
defaults: {
|
|
79
|
+
/**
|
|
80
|
+
* Prefix for auto-registered component names.
|
|
81
|
+
* `'Ui'` gives `<UiButton>`, matching Numori Notes' existing templates.
|
|
82
|
+
*/
|
|
83
|
+
prefix: "Ui",
|
|
84
|
+
/** Register only these base names. `null` registers all of them. */
|
|
85
|
+
include: null,
|
|
86
|
+
/** Skip these base names — use when the app has its own `<UiButton>`. */
|
|
87
|
+
exclude: [],
|
|
88
|
+
/** Auto-import the library's composables (`useBackButton`, ...). */
|
|
89
|
+
composables: true,
|
|
90
|
+
/**
|
|
91
|
+
* Set up Tailwind v4 for the whole app: registers `@tailwindcss/vite` and
|
|
92
|
+
* injects a stylesheet importing Tailwind plus the Numori tokens.
|
|
93
|
+
*
|
|
94
|
+
* Leave this off if the app already configures Tailwind; in that case add
|
|
95
|
+
* `@import "numori-ui/css";` to your own stylesheet instead.
|
|
96
|
+
*/
|
|
97
|
+
tailwind: false,
|
|
98
|
+
/**
|
|
99
|
+
* Icon rendering. By default icons are inline SVGs from the subset bundled
|
|
100
|
+
* with the package.
|
|
101
|
+
*
|
|
102
|
+
* `component` takes the *name* of a globally registered component — e.g.
|
|
103
|
+
* `'Icon'` to render through `@nuxt/icon` — since nuxt.config cannot carry
|
|
104
|
+
* a component reference. `extra` adds raw path data to the bundled set.
|
|
105
|
+
*/
|
|
106
|
+
icons: {
|
|
107
|
+
component: null,
|
|
108
|
+
extra: null
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
async setup(options, nuxt) {
|
|
112
|
+
const logger = useLogger("numori-ui");
|
|
113
|
+
if (typeof options.prefix !== "string" || options.prefix.length === 0) throw new Error("[numori-ui] `numoriUi.prefix` must be a non-empty string. Registering components under their bare names would make <Button> resolve its own native `button` root element, recursing infinitely. Use a prefix such as \"Ui\" or \"N\".");
|
|
114
|
+
const skipped = [];
|
|
115
|
+
for (const { name, file } of componentEntries()) {
|
|
116
|
+
if (!((!options.include || options.include.includes(name)) && !options.exclude.includes(name))) {
|
|
117
|
+
skipped.push(name);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
addComponent({
|
|
121
|
+
name: prefixed(name, options.prefix),
|
|
122
|
+
filePath: fromSrc(file),
|
|
123
|
+
mode: "all"
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (skipped.length) logger.info(`Not registering: ${skipped.join(", ")}`);
|
|
127
|
+
if (options.composables) addImports([
|
|
128
|
+
{
|
|
129
|
+
name: "useBackButton",
|
|
130
|
+
from: fromSrc("composables/useBackButton.js")
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "onClickOutside",
|
|
134
|
+
from: fromSrc("composables/onClickOutside.js")
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "useEventListener",
|
|
138
|
+
from: fromSrc("composables/useEventListener.js")
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "registerIcons",
|
|
142
|
+
from: fromSrc("icons/registry.js")
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "provideIconComponent",
|
|
146
|
+
from: fromSrc("icons/resolver.js")
|
|
147
|
+
}
|
|
148
|
+
]);
|
|
149
|
+
if (options.icons?.component || options.icons?.extra) {
|
|
150
|
+
const { component, extra } = options.icons;
|
|
151
|
+
addPluginTemplate({
|
|
152
|
+
filename: "numori-ui-icons.mjs",
|
|
153
|
+
getContents: () => [
|
|
154
|
+
`import { defineNuxtPlugin } from '#app'`,
|
|
155
|
+
`import { ICON_COMPONENT_KEY } from ${JSON.stringify(fromSrc("icons/resolver.js"))}`,
|
|
156
|
+
extra ? `import { registerIcons } from ${JSON.stringify(fromSrc("icons/registry.js"))}` : null,
|
|
157
|
+
``,
|
|
158
|
+
`export default defineNuxtPlugin({`,
|
|
159
|
+
` name: 'numori-ui:icons',`,
|
|
160
|
+
` enforce: 'pre',`,
|
|
161
|
+
` setup(nuxtApp) {`,
|
|
162
|
+
extra ? ` registerIcons(${JSON.stringify(extra)})` : null,
|
|
163
|
+
component ? ` nuxtApp.vueApp.provide(ICON_COMPONENT_KEY, ${JSON.stringify(component)})` : null,
|
|
164
|
+
` },`,
|
|
165
|
+
`})`,
|
|
166
|
+
``
|
|
167
|
+
].filter((line) => line !== null).join("\n")
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (options.tailwind) await setupTailwind(nuxt, logger);
|
|
171
|
+
else nuxt.hook("build:before", () => {
|
|
172
|
+
if (!appImportsNumoriCss(nuxt)) logger.warn("No stylesheet appears to import \"numori-ui/css\" — components may render unstyled.\n Add to your Tailwind entry stylesheet:\n @import \"tailwindcss\";\n @import \"numori-ui/css\";\n Or set `numoriUi: { tailwind: true }` to have this module configure Tailwind.");
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* Best-effort check that the app pulls the design tokens in somewhere.
|
|
178
|
+
* A missed detection only produces a warning, so it can never break a build.
|
|
179
|
+
*
|
|
180
|
+
* @param {object} nuxt
|
|
181
|
+
* @returns {boolean}
|
|
182
|
+
*/
|
|
183
|
+
function appImportsNumoriCss(nuxt) {
|
|
184
|
+
for (const entry of nuxt.options.css || []) {
|
|
185
|
+
if (typeof entry !== "string") continue;
|
|
186
|
+
if (entry.includes("numori-ui")) return true;
|
|
187
|
+
try {
|
|
188
|
+
const path = entry.startsWith("~") ? entry.replace(/^~~?\/?/, `${nuxt.options.srcDir}/`) : entry;
|
|
189
|
+
if (existsSync(path) && readFileSync(path, "utf8").includes("numori-ui")) return true;
|
|
190
|
+
} catch {}
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Register `@tailwindcss/vite` and generate a base stylesheet wiring Tailwind
|
|
196
|
+
* to the Numori tokens. Opt-in, because taking over an app's CSS pipeline
|
|
197
|
+
* should be a deliberate choice.
|
|
198
|
+
*
|
|
199
|
+
* The stylesheet is generated into Nuxt's buildDir with **absolute** `@source`
|
|
200
|
+
* paths. That matters: Tailwind v4 bases automatic source detection on the
|
|
201
|
+
* stylesheet's own location and skips `node_modules`, so a stylesheet shipped
|
|
202
|
+
* inside the package would scan the wrong tree and find none of the app's
|
|
203
|
+
* templates. Naming both roots explicitly removes the guesswork.
|
|
204
|
+
*
|
|
205
|
+
* `@tailwindcss/vite` is an optional peer — only this path needs it.
|
|
206
|
+
*
|
|
207
|
+
* @param {object} nuxt
|
|
208
|
+
* @param {ReturnType<typeof useLogger>} logger
|
|
209
|
+
*/
|
|
210
|
+
async function setupTailwind(nuxt, logger) {
|
|
211
|
+
const tailwindMod = await importFromProject("@tailwindcss/vite", nuxt.options.rootDir);
|
|
212
|
+
if (!tailwindMod) {
|
|
213
|
+
logger.error("`numoriUi.tailwind` is enabled but @tailwindcss/vite could not be resolved.\n Install it: npm i -D @tailwindcss/vite\n Or set `numoriUi: { tailwind: false }` and configure Tailwind yourself.");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const tailwindVite = tailwindMod.default;
|
|
217
|
+
nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
|
|
218
|
+
nuxt.options.vite.plugins.push(tailwindVite());
|
|
219
|
+
const template = addTemplate({
|
|
220
|
+
filename: "numori-ui-tailwind.css",
|
|
221
|
+
write: true,
|
|
222
|
+
getContents: () => [
|
|
223
|
+
"/* Generated by numori-ui/nuxt (numoriUi.tailwind = true). */",
|
|
224
|
+
"@import \"tailwindcss\";",
|
|
225
|
+
`@import ${JSON.stringify(fromSrc("theme.css"))};`,
|
|
226
|
+
"",
|
|
227
|
+
"/* The library, then the app. Absolute so neither depends on where",
|
|
228
|
+
" * this generated file happens to sit. */",
|
|
229
|
+
`@source ${JSON.stringify(fromSrc("components"))};`,
|
|
230
|
+
`@source ${JSON.stringify(fromSrc("icons"))};`,
|
|
231
|
+
`@source ${JSON.stringify(nuxt.options.srcDir)};`,
|
|
232
|
+
...nuxt.options.rootDir !== nuxt.options.srcDir ? [`@source ${JSON.stringify(nuxt.options.rootDir)};`] : [],
|
|
233
|
+
""
|
|
234
|
+
].join("\n")
|
|
235
|
+
});
|
|
236
|
+
nuxt.options.css = nuxt.options.css || [];
|
|
237
|
+
if (!nuxt.options.css.includes(template.dst)) nuxt.options.css.unshift(template.dst);
|
|
238
|
+
logger.success("Tailwind v4 configured with the Numori UI theme.");
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
export { COMPONENT_NAMES, DEFAULT_PREFIX, nuxt_default as default };
|
|
242
|
+
|
|
243
|
+
//# sourceMappingURL=nuxt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nuxt.mjs","names":[],"sources":["../src/nuxt.js"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport {\n addComponent,\n addImports,\n addPluginTemplate,\n addTemplate,\n defineNuxtModule,\n useLogger,\n} from '@nuxt/kit'\nimport { COMPONENT_NAMES, DEFAULT_PREFIX, componentEntries, prefixed } from './manifest.js'\n\n/**\n * Absolute path to the package's `src/` directory.\n *\n * Deliberately not derived with `createResolver(import.meta.url)`: that resolves\n * relative to *this file*, which is `dist/nuxt.mjs` once built — so component\n * paths would come out as `dist/components/Button.vue`, which does not exist.\n * The module has to point at the shipped `src/` either way, because handing\n * Nuxt the raw SFCs is what lets it compile and tree-shake them.\n *\n * `dist/` and `src/` are both direct children of the package root, so going up\n * one level works whether this module is running from source (in-repo) or from\n * the published build.\n */\nconst SRC_DIR = join(dirname(dirname(fileURLToPath(import.meta.url))), 'src')\n\n/**\n * Resolve a path inside the package's `src/`.\n * @param {string} relativePath e.g. 'components/Button.vue'\n * @returns {string} Absolute path.\n */\nconst fromSrc = (relativePath) => join(SRC_DIR, relativePath)\n\n/**\n * Import an optional peer dependency, resolved from the **Nuxt project** rather\n * than from this package.\n *\n * A bare `import('@tailwindcss/vite')` resolves relative to this file, which is\n * wrong for an optional peer: it lives in the app's `node_modules`, not ours.\n * That lookup fails outright under pnpm's strict layout and whenever the package\n * is linked (`file:`/`npm link`), because neither arrangement puts the app's\n * dependencies on our resolution path.\n *\n * @param {string} specifier Module to load.\n * @param {string} projectRoot Directory to resolve from (nuxt.options.rootDir).\n * @returns {Promise<any | null>} The module, or null if it isn't installed.\n */\nasync function importFromProject(specifier, projectRoot) {\n try {\n const require = createRequire(join(projectRoot, 'package.json'))\n return await import(pathToFileURL(require.resolve(specifier)).href)\n } catch {\n // Fall back to our own resolution path, for layouts where the dependency is\n // hoisted somewhere the project root cannot see.\n try {\n return await import(specifier)\n } catch {\n return null\n }\n }\n}\n\n/**\n * Numori UI — Nuxt module.\n *\n * Registers every component so templates can use `<UiButton>` with no import,\n * exposes the library's composables to Nuxt's auto-import system, and can\n * optionally stand up the whole Tailwind v4 pipeline.\n *\n * Components are registered from source (`.vue`), not from the bundled build,\n * so Nuxt compiles them in the app's own Vite pass. That is what makes\n * per-component tree-shaking work: Nuxt only emits the components a template\n * actually references, so an app using three of them ships three.\n *\n * @example nuxt.config.ts\n * export default defineNuxtConfig({\n * modules: ['numori-ui/nuxt'],\n * numoriUi: { prefix: 'Ui' },\n * })\n */\nexport default defineNuxtModule({\n meta: {\n name: 'numori-ui',\n configKey: 'numoriUi',\n compatibility: { nuxt: '>=3.0.0' },\n },\n\n defaults: {\n /**\n * Prefix for auto-registered component names.\n * `'Ui'` gives `<UiButton>`, matching Numori Notes' existing templates.\n */\n prefix: DEFAULT_PREFIX,\n\n /** Register only these base names. `null` registers all of them. */\n include: null,\n\n /** Skip these base names — use when the app has its own `<UiButton>`. */\n exclude: [],\n\n /** Auto-import the library's composables (`useBackButton`, ...). */\n composables: true,\n\n /**\n * Set up Tailwind v4 for the whole app: registers `@tailwindcss/vite` and\n * injects a stylesheet importing Tailwind plus the Numori tokens.\n *\n * Leave this off if the app already configures Tailwind; in that case add\n * `@import \"numori-ui/css\";` to your own stylesheet instead.\n */\n tailwind: false,\n\n /**\n * Icon rendering. By default icons are inline SVGs from the subset bundled\n * with the package.\n *\n * `component` takes the *name* of a globally registered component — e.g.\n * `'Icon'` to render through `@nuxt/icon` — since nuxt.config cannot carry\n * a component reference. `extra` adds raw path data to the bundled set.\n */\n icons: {\n component: null,\n extra: null,\n },\n },\n\n async setup(options, nuxt) {\n const logger = useLogger('numori-ui')\n\n // See src/index.js: bare names make `Button` resolve its own `button` root\n // element and recurse until the stack overflows, with an error message that\n // gives no clue why. Fail the build instead.\n if (typeof options.prefix !== 'string' || options.prefix.length === 0) {\n throw new Error(\n '[numori-ui] `numoriUi.prefix` must be a non-empty string. Registering components under ' +\n 'their bare names would make <Button> resolve its own native `button` root element, ' +\n 'recursing infinitely. Use a prefix such as \"Ui\" or \"N\".',\n )\n }\n\n /* ── Components ─────────────────────────────────────────────────── *\n * `mode: 'all'` keeps them usable in SSR and client-only trees alike.\n * Registering by file path lets Nuxt handle transpiling and chunking. */\n const skipped = []\n for (const { name, file } of componentEntries()) {\n const wanted =\n (!options.include || options.include.includes(name)) && !options.exclude.includes(name)\n if (!wanted) {\n skipped.push(name)\n continue\n }\n addComponent({\n name: prefixed(name, options.prefix),\n filePath: fromSrc(file),\n mode: 'all',\n })\n }\n\n if (skipped.length) logger.info(`Not registering: ${skipped.join(', ')}`)\n\n /* ── Composables ────────────────────────────────────────────────── */\n if (options.composables) {\n addImports([\n { name: 'useBackButton', from: fromSrc('composables/useBackButton.js') },\n { name: 'onClickOutside', from: fromSrc('composables/onClickOutside.js') },\n { name: 'useEventListener', from: fromSrc('composables/useEventListener.js') },\n { name: 'registerIcons', from: fromSrc('icons/registry.js') },\n { name: 'provideIconComponent', from: fromSrc('icons/resolver.js') },\n ])\n }\n\n /* ── Icon delegation / extra icons ──────────────────────────────── *\n * Needs a live Vue app: `provide` for the renderer and the runtime\n * registry for extra paths, so it happens in a plugin.\n *\n * The renderer is provided as a bare string. `<component :is=\"'Icon'\">`\n * resolves a globally registered component by name, which means no proxy\n * component is needed and registration order doesn't matter — the lookup\n * happens at render time, long after every module has run. */\n if (options.icons?.component || options.icons?.extra) {\n const { component, extra } = options.icons\n addPluginTemplate({\n filename: 'numori-ui-icons.mjs',\n getContents: () =>\n [\n `import { defineNuxtPlugin } from '#app'`,\n `import { ICON_COMPONENT_KEY } from ${JSON.stringify(fromSrc('icons/resolver.js'))}`,\n extra\n ? `import { registerIcons } from ${JSON.stringify(fromSrc('icons/registry.js'))}`\n : null,\n ``,\n `export default defineNuxtPlugin({`,\n ` name: 'numori-ui:icons',`,\n ` enforce: 'pre',`,\n ` setup(nuxtApp) {`,\n extra ? ` registerIcons(${JSON.stringify(extra)})` : null,\n component\n ? ` nuxtApp.vueApp.provide(ICON_COMPONENT_KEY, ${JSON.stringify(component)})`\n : null,\n ` },`,\n `})`,\n ``,\n ]\n .filter((line) => line !== null)\n .join('\\n'),\n })\n }\n\n /* ── Tailwind v4 ────────────────────────────────────────────────── */\n if (options.tailwind) {\n await setupTailwind(nuxt, logger)\n } else {\n // The tokens live in CSS, so unlike a v3 preset there is nothing to\n // inject on the app's behalf — `@theme` only has meaning inside a\n // stylesheet that imports Tailwind. Nudge rather than fail silently.\n nuxt.hook('build:before', () => {\n if (!appImportsNumoriCss(nuxt)) {\n logger.warn(\n 'No stylesheet appears to import \"numori-ui/css\" — components may render unstyled.\\n' +\n ' Add to your Tailwind entry stylesheet:\\n' +\n ' @import \"tailwindcss\";\\n' +\n ' @import \"numori-ui/css\";\\n' +\n ' Or set `numoriUi: { tailwind: true }` to have this module configure Tailwind.',\n )\n }\n })\n }\n },\n})\n\n/**\n * Best-effort check that the app pulls the design tokens in somewhere.\n * A missed detection only produces a warning, so it can never break a build.\n *\n * @param {object} nuxt\n * @returns {boolean}\n */\nfunction appImportsNumoriCss(nuxt) {\n for (const entry of nuxt.options.css || []) {\n if (typeof entry !== 'string') continue\n if (entry.includes('numori-ui')) return true\n try {\n const path = entry.startsWith('~')\n ? entry.replace(/^~~?\\/?/, `${nuxt.options.srcDir}/`)\n : entry\n if (existsSync(path) && readFileSync(path, 'utf8').includes('numori-ui')) return true\n } catch {\n // Unreadable or virtual entry — fall through to the warning.\n }\n }\n return false\n}\n\n/**\n * Register `@tailwindcss/vite` and generate a base stylesheet wiring Tailwind\n * to the Numori tokens. Opt-in, because taking over an app's CSS pipeline\n * should be a deliberate choice.\n *\n * The stylesheet is generated into Nuxt's buildDir with **absolute** `@source`\n * paths. That matters: Tailwind v4 bases automatic source detection on the\n * stylesheet's own location and skips `node_modules`, so a stylesheet shipped\n * inside the package would scan the wrong tree and find none of the app's\n * templates. Naming both roots explicitly removes the guesswork.\n *\n * `@tailwindcss/vite` is an optional peer — only this path needs it.\n *\n * @param {object} nuxt\n * @param {ReturnType<typeof useLogger>} logger\n */\nasync function setupTailwind(nuxt, logger) {\n const tailwindMod = await importFromProject('@tailwindcss/vite', nuxt.options.rootDir)\n if (!tailwindMod) {\n logger.error(\n '`numoriUi.tailwind` is enabled but @tailwindcss/vite could not be resolved.\\n' +\n ' Install it: npm i -D @tailwindcss/vite\\n' +\n ' Or set `numoriUi: { tailwind: false }` and configure Tailwind yourself.',\n )\n return\n }\n const tailwindVite = tailwindMod.default\n\n nuxt.options.vite.plugins = nuxt.options.vite.plugins || []\n nuxt.options.vite.plugins.push(tailwindVite())\n\n const template = addTemplate({\n filename: 'numori-ui-tailwind.css',\n write: true,\n getContents: () =>\n [\n '/* Generated by numori-ui/nuxt (numoriUi.tailwind = true). */',\n '@import \"tailwindcss\";',\n `@import ${JSON.stringify(fromSrc('theme.css'))};`,\n '',\n '/* The library, then the app. Absolute so neither depends on where',\n ' * this generated file happens to sit. */',\n `@source ${JSON.stringify(fromSrc('components'))};`,\n `@source ${JSON.stringify(fromSrc('icons'))};`,\n `@source ${JSON.stringify(nuxt.options.srcDir)};`,\n ...(nuxt.options.rootDir !== nuxt.options.srcDir\n ? [`@source ${JSON.stringify(nuxt.options.rootDir)};`]\n : []),\n '',\n ].join('\\n'),\n })\n\n nuxt.options.css = nuxt.options.css || []\n if (!nuxt.options.css.includes(template.dst)) nuxt.options.css.unshift(template.dst)\n\n logger.success('Tailwind v4 configured with the Numori UI theme.')\n}\n\nexport { COMPONENT_NAMES, DEFAULT_PREFIX }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,IAAM,UAAU,KAAK,QAAQ,QAAQ,cAAc,YAAY,GAAG,CAAC,CAAC,GAAG,KAAK;;;;;;AAO5E,IAAM,WAAW,iBAAiB,KAAK,SAAS,YAAY;;;;;;;;;;;;;;;AAgB5D,eAAe,kBAAkB,WAAW,aAAa;CACvD,IAAI;EACF,MAAM,UAAU,cAAc,KAAK,aAAa,cAAc,CAAC;EAC/D,OAAO,MAAM,OAAO,cAAc,QAA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K,QAAQ,KAAK,UAAU,KAAK,QAAQ,KAAK,WAAW,CAAC;CAC1D,KAAK,QAAQ,KAAK,QAAQ,KAAK,aAAa,CAAC;CAE7C,MAAM,WAAW,YAAY;EAC3B,UAAU;EACV,OAAO;EACP,mBACE;GACE;GACA;GACA,WAAW,KAAK,UAAU,QAAQ,WAAW,CAAC,EAAE;GAChD;GACA;GACA;GACA,WAAW,KAAK,UAAU,QAAQ,YAAY,CAAC,EAAE;GACjD,WAAW,KAAK,UAAU,QAAQ,OAAO,CAAC,EAAE;GAC5C,WAAW,KAAK,UAAU,KAAK,QAAQ,MAAM,EAAE;GAC/C,GAAI,KAAK,QAAQ,YAAY,KAAK,QAAQ,SACtC,CAAC,WAAW,KAAK,UAAU,KAAK,QAAQ,OAAO,EAAE,EAAE,IACnD,CAAC;GACL;EACF,CAAC,CAAC,KAAK,IAAI;CACf,CAAC;CAED,KAAK,QAAQ,MAAM,KAAK,QAAQ,OAAO,CAAC;CACxC,IAAI,CAAC,KAAK,QAAQ,IAAI,SAAS,SAAS,GAAG,GAAG,KAAK,QAAQ,IAAI,QAAQ,SAAS,GAAG;CAEnF,OAAO,QAAQ,kDAAkD;AACnE"}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite'
|
|
2
|
+
|
|
3
|
+
export interface NumoriUIViteOptions {
|
|
4
|
+
/** Prefix the components are written with in templates. Default `'Ui'`. */
|
|
5
|
+
prefix?: string
|
|
6
|
+
/** Auto-import components via unplugin-vue-components. Default `true`. */
|
|
7
|
+
autoImport?: boolean
|
|
8
|
+
/** Also register @tailwindcss/vite. Default `false`. */
|
|
9
|
+
tailwind?: boolean
|
|
10
|
+
/** Emit a component .d.ts from unplugin-vue-components. Default `false`. */
|
|
11
|
+
dts?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface NumoriUIComponentResolver {
|
|
15
|
+
type: 'component'
|
|
16
|
+
resolve(name: string): { name: string; from: string } | undefined
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Resolver for an existing unplugin-vue-components setup. */
|
|
20
|
+
export declare function NumoriUIResolver(options?: {
|
|
21
|
+
prefix?: string
|
|
22
|
+
}): NumoriUIComponentResolver
|
|
23
|
+
|
|
24
|
+
declare function numoriUI(options?: NumoriUIViteOptions): Promise<PluginOption[]>
|
|
25
|
+
export default numoriUI
|
|
26
|
+
|
|
27
|
+
export declare const COMPONENT_NAMES: string[]
|
|
28
|
+
export declare const DEFAULT_PREFIX: string
|
|
29
|
+
export declare function prefixed(name: string, prefix?: string): string
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { COMPONENT_NAMES, DEFAULT_PREFIX, componentEntries, prefixed } from "./manifest.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
//#region src/vite.js
|
|
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
|
+
/** Package specifier used for the generated imports. */
|
|
34
|
+
var PKG = "numori-ui";
|
|
35
|
+
/**
|
|
36
|
+
* Map of base component name -> import specifier resolvable by the consumer.
|
|
37
|
+
* Uses the package's `./src/*` export so the raw SFCs are compiled by the
|
|
38
|
+
* host's own `@vitejs/plugin-vue`, which is what keeps tree-shaking intact.
|
|
39
|
+
* @returns {Record<string, string>}
|
|
40
|
+
*/
|
|
41
|
+
function componentSpecifiers() {
|
|
42
|
+
return Object.fromEntries(componentEntries().map(({ name, file }) => [name, `${PKG}/src/${file}`]));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolver for `unplugin-vue-components`.
|
|
46
|
+
*
|
|
47
|
+
* Export it directly when you already run `unplugin-vue-components` yourself
|
|
48
|
+
* and just want Numori UI added to your existing resolver list.
|
|
49
|
+
*
|
|
50
|
+
* @param {object} [options]
|
|
51
|
+
* @param {string} [options.prefix='Ui'] Prefix the components are written with.
|
|
52
|
+
* @returns {{ type: 'component', resolve: (name: string) => { name: string, from: string } | undefined }}
|
|
53
|
+
*
|
|
54
|
+
* @example vite.config.js with your own unplugin setup
|
|
55
|
+
* import Components from 'unplugin-vue-components/vite'
|
|
56
|
+
* import { NumoriUIResolver } from 'numori-ui/vite'
|
|
57
|
+
*
|
|
58
|
+
* export default {
|
|
59
|
+
* plugins: [vue(), Components({ resolvers: [NumoriUIResolver()] })],
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
62
|
+
function NumoriUIResolver(options = {}) {
|
|
63
|
+
const { prefix = "Ui" } = options;
|
|
64
|
+
if (typeof prefix !== "string" || prefix.length === 0) throw new Error("[numori-ui] `prefix` must be a non-empty string. Registering components under their bare names would make <Button> resolve its own native `button` root element, recursing infinitely. Use a prefix such as \"Ui\" or \"N\".");
|
|
65
|
+
const specifiers = componentSpecifiers();
|
|
66
|
+
return {
|
|
67
|
+
type: "component",
|
|
68
|
+
resolve(name) {
|
|
69
|
+
if (!name.startsWith(prefix)) return;
|
|
70
|
+
const base = name.slice(prefix.length);
|
|
71
|
+
const from = specifiers[base];
|
|
72
|
+
if (!from) return;
|
|
73
|
+
return {
|
|
74
|
+
name: "default",
|
|
75
|
+
from
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The Vite plugin.
|
|
82
|
+
*
|
|
83
|
+
* Returns an array of plugins (Vite flattens these), and resolves
|
|
84
|
+
* asynchronously because the optional integrations are imported on demand —
|
|
85
|
+
* Vite accepts promises in its `plugins` array.
|
|
86
|
+
*
|
|
87
|
+
* @param {object} [options]
|
|
88
|
+
* @param {string} [options.prefix='Ui']
|
|
89
|
+
* Prefix the components are written with in templates.
|
|
90
|
+
* @param {boolean} [options.autoImport=true]
|
|
91
|
+
* Auto-import referenced components via `unplugin-vue-components`.
|
|
92
|
+
* Silently inert (with a hint) if that package isn't installed.
|
|
93
|
+
* @param {boolean} [options.tailwind=false]
|
|
94
|
+
* Also register `@tailwindcss/vite`. Use when you'd rather not add it
|
|
95
|
+
* yourself; requires `@tailwindcss/vite` to be installed.
|
|
96
|
+
* @param {boolean} [options.dts=false]
|
|
97
|
+
* Ask `unplugin-vue-components` to emit a component type declaration file.
|
|
98
|
+
* Off by default — this library is JavaScript-first and most consumers have
|
|
99
|
+
* no use for it.
|
|
100
|
+
* @returns {Promise<Array<import('vite').PluginOption>>}
|
|
101
|
+
*/
|
|
102
|
+
async function numoriUI(options = {}) {
|
|
103
|
+
const { prefix = "Ui", autoImport = true, tailwind = false, dts = false } = options;
|
|
104
|
+
const plugins = [baseConfigPlugin()];
|
|
105
|
+
if (autoImport) {
|
|
106
|
+
const components = await loadUnpluginComponents();
|
|
107
|
+
if (components) plugins.push(components({
|
|
108
|
+
dts,
|
|
109
|
+
dirs: [],
|
|
110
|
+
resolvers: [NumoriUIResolver({ prefix })]
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
if (tailwind) {
|
|
114
|
+
const tailwindVite = await loadTailwindVite();
|
|
115
|
+
if (tailwindVite) plugins.push(tailwindVite());
|
|
116
|
+
}
|
|
117
|
+
return plugins;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Small always-on plugin handling the config details that make importing raw
|
|
121
|
+
* SFCs out of `node_modules` behave.
|
|
122
|
+
*
|
|
123
|
+
* @returns {import('vite').Plugin}
|
|
124
|
+
*/
|
|
125
|
+
function baseConfigPlugin() {
|
|
126
|
+
return {
|
|
127
|
+
name: "numori-ui:config",
|
|
128
|
+
enforce: "pre",
|
|
129
|
+
config() {
|
|
130
|
+
return {
|
|
131
|
+
optimizeDeps: { exclude: [PKG] },
|
|
132
|
+
ssr: { noExternal: [PKG] }
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Import an optional peer dependency, resolved from the **consuming project**
|
|
139
|
+
* rather than from this package.
|
|
140
|
+
*
|
|
141
|
+
* A bare `import('unplugin-vue-components/vite')` resolves relative to this
|
|
142
|
+
* file, which is wrong for an optional peer: the package is installed in the
|
|
143
|
+
* app's `node_modules`, not ours. That lookup fails outright under pnpm's
|
|
144
|
+
* strict layout and when the package is linked (`file:`/`npm link`), because
|
|
145
|
+
* neither arrangement puts the app's dependencies on our resolution path.
|
|
146
|
+
*
|
|
147
|
+
* Resolving from `process.cwd()` is correct here — a Vite plugin is
|
|
148
|
+
* instantiated while loading `vite.config.js`, with the working directory at
|
|
149
|
+
* the project root.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} specifier Module to load.
|
|
152
|
+
* @returns {Promise<any | null>} The module, or null if it isn't installed.
|
|
153
|
+
*/
|
|
154
|
+
async function importFromProject(specifier) {
|
|
155
|
+
const require = createRequire(join(process.cwd(), "package.json"));
|
|
156
|
+
try {
|
|
157
|
+
return await import(pathToFileURL(require.resolve(specifier)).href);
|
|
158
|
+
} catch {
|
|
159
|
+
try {
|
|
160
|
+
return await import(specifier);
|
|
161
|
+
} catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @returns {Promise<Function | null>} unplugin-vue-components' Vite plugin.
|
|
168
|
+
*/
|
|
169
|
+
async function loadUnpluginComponents() {
|
|
170
|
+
const mod = await importFromProject("unplugin-vue-components/vite");
|
|
171
|
+
if (mod) return mod.default;
|
|
172
|
+
console.warn("[numori-ui] Auto-import is on but `unplugin-vue-components` could not be resolved.\n Install it: npm i -D unplugin-vue-components\n Or set `autoImport: false` and register components with `app.use(NumoriUI)`.");
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* @returns {Promise<Function | null>} @tailwindcss/vite's plugin.
|
|
177
|
+
*/
|
|
178
|
+
async function loadTailwindVite() {
|
|
179
|
+
const mod = await importFromProject("@tailwindcss/vite");
|
|
180
|
+
if (mod) return mod.default;
|
|
181
|
+
console.warn("[numori-ui] `tailwind: true` is set but `@tailwindcss/vite` could not be resolved.\n Install it: npm i -D @tailwindcss/vite");
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
export { COMPONENT_NAMES, DEFAULT_PREFIX, NumoriUIResolver, numoriUI as default, prefixed };
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=vite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite.js"],"sourcesContent":["import { createRequire } from 'node:module'\nimport { join } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { COMPONENT_NAMES, DEFAULT_PREFIX, componentEntries, prefixed } from './manifest.js'\n\n/**\n * Numori UI — Vite plugin.\n *\n * Gives a plain Vite + Vue app the same ergonomics the Nuxt module gives a Nuxt\n * app: write `<UiButton>` in a template and the import is added for you, with\n * only the components you actually reference ending up in the bundle.\n *\n * Auto-import is delegated to `unplugin-vue-components`, the de facto standard\n * for this in the Vite ecosystem, rather than reimplemented here. It is an\n * optional peer dependency — install it only if you want auto-import:\n *\n * npm i -D unplugin-vue-components\n *\n * Without it (or with `autoImport: false`) the plugin still handles the Tailwind\n * wiring, and you register components the ordinary way with `app.use(NumoriUI)`.\n *\n * @example vite.config.js\n * import vue from '@vitejs/plugin-vue'\n * import numoriUI from 'numori-ui/vite'\n *\n * export default {\n * plugins: [vue(), numoriUI()],\n * }\n *\n * @example Let the plugin own the Tailwind setup too\n * plugins: [vue(), numoriUI({ tailwind: true })]\n */\n\n/** Package specifier used for the generated imports. */\nconst PKG = 'numori-ui'\n\n/**\n * Map of base component name -> import specifier resolvable by the consumer.\n * Uses the package's `./src/*` export so the raw SFCs are compiled by the\n * host's own `@vitejs/plugin-vue`, which is what keeps tree-shaking intact.\n * @returns {Record<string, string>}\n */\nfunction componentSpecifiers() {\n return Object.fromEntries(\n componentEntries().map(({ name, file }) => [name, `${PKG}/src/${file}`]),\n )\n}\n\n/**\n * Resolver for `unplugin-vue-components`.\n *\n * Export it directly when you already run `unplugin-vue-components` yourself\n * and just want Numori UI added to your existing resolver list.\n *\n * @param {object} [options]\n * @param {string} [options.prefix='Ui'] Prefix the components are written with.\n * @returns {{ type: 'component', resolve: (name: string) => { name: string, from: string } | undefined }}\n *\n * @example vite.config.js with your own unplugin setup\n * import Components from 'unplugin-vue-components/vite'\n * import { NumoriUIResolver } from 'numori-ui/vite'\n *\n * export default {\n * plugins: [vue(), Components({ resolvers: [NumoriUIResolver()] })],\n * }\n */\nexport function NumoriUIResolver(options = {}) {\n const { prefix = DEFAULT_PREFIX } = options\n\n // See src/index.js: an empty prefix would have this resolver claim every\n // bare tag it knows a base name for, including `Button`, whose own root\n // element is a dynamic `button` — which recurses until the stack overflows.\n if (typeof prefix !== 'string' || prefix.length === 0) {\n throw new Error(\n '[numori-ui] `prefix` must be a non-empty string. Registering components under their ' +\n 'bare names would make <Button> resolve its own native `button` root element, ' +\n 'recursing infinitely. Use a prefix such as \"Ui\" or \"N\".',\n )\n }\n\n const specifiers = componentSpecifiers()\n\n return {\n type: 'component',\n resolve(name) {\n if (!name.startsWith(prefix)) return\n const base = name.slice(prefix.length)\n const from = specifiers[base]\n if (!from) return\n // SFCs are default exports.\n return { name: 'default', from }\n },\n }\n}\n\n/**\n * The Vite plugin.\n *\n * Returns an array of plugins (Vite flattens these), and resolves\n * asynchronously because the optional integrations are imported on demand —\n * Vite accepts promises in its `plugins` array.\n *\n * @param {object} [options]\n * @param {string} [options.prefix='Ui']\n * Prefix the components are written with in templates.\n * @param {boolean} [options.autoImport=true]\n * Auto-import referenced components via `unplugin-vue-components`.\n * Silently inert (with a hint) if that package isn't installed.\n * @param {boolean} [options.tailwind=false]\n * Also register `@tailwindcss/vite`. Use when you'd rather not add it\n * yourself; requires `@tailwindcss/vite` to be installed.\n * @param {boolean} [options.dts=false]\n * Ask `unplugin-vue-components` to emit a component type declaration file.\n * Off by default — this library is JavaScript-first and most consumers have\n * no use for it.\n * @returns {Promise<Array<import('vite').PluginOption>>}\n */\nexport default async function numoriUI(options = {}) {\n const { prefix = DEFAULT_PREFIX, autoImport = true, tailwind = false, dts = false } = options\n\n const plugins = [baseConfigPlugin()]\n\n if (autoImport) {\n const components = await loadUnpluginComponents()\n if (components) {\n plugins.push(\n components({\n dts,\n // Only touch what our resolver claims; the host's own components\n // directory scanning is left entirely alone.\n dirs: [],\n resolvers: [NumoriUIResolver({ prefix })],\n }),\n )\n }\n }\n\n if (tailwind) {\n const tailwindVite = await loadTailwindVite()\n if (tailwindVite) plugins.push(tailwindVite())\n }\n\n return plugins\n}\n\n/**\n * Small always-on plugin handling the config details that make importing raw\n * SFCs out of `node_modules` behave.\n *\n * @returns {import('vite').Plugin}\n */\nfunction baseConfigPlugin() {\n return {\n name: 'numori-ui:config',\n enforce: 'pre',\n config() {\n return {\n optimizeDeps: {\n // The dep optimiser only understands JavaScript. Numori UI's\n // components are consumed as `.vue` source so the host compiles\n // them, so the package must stay out of the prebundle.\n exclude: [PKG],\n },\n ssr: {\n // Same reason on the server: the SFCs need the host's vue plugin,\n // which means they must not be externalised.\n noExternal: [PKG],\n },\n }\n },\n }\n}\n\n/**\n * Import an optional peer dependency, resolved from the **consuming project**\n * rather than from this package.\n *\n * A bare `import('unplugin-vue-components/vite')` resolves relative to this\n * file, which is wrong for an optional peer: the package is installed in the\n * app's `node_modules`, not ours. That lookup fails outright under pnpm's\n * strict layout and when the package is linked (`file:`/`npm link`), because\n * neither arrangement puts the app's dependencies on our resolution path.\n *\n * Resolving from `process.cwd()` is correct here — a Vite plugin is\n * instantiated while loading `vite.config.js`, with the working directory at\n * the project root.\n *\n * @param {string} specifier Module to load.\n * @returns {Promise<any | null>} The module, or null if it isn't installed.\n */\nasync function importFromProject(specifier) {\n const require = createRequire(join(process.cwd(), 'package.json'))\n try {\n return await import(pathToFileURL(require.resolve(specifier)).href)\n } catch {\n // Fall back to our own resolution path, which covers the case where the\n // dependency is hoisted somewhere cwd cannot see it.\n try {\n return await import(specifier)\n } catch {\n return null\n }\n }\n}\n\n/**\n * @returns {Promise<Function | null>} unplugin-vue-components' Vite plugin.\n */\nasync function loadUnpluginComponents() {\n const mod = await importFromProject('unplugin-vue-components/vite')\n if (mod) return mod.default\n\n console.warn(\n '[numori-ui] Auto-import is on but `unplugin-vue-components` could not be resolved.\\n' +\n ' Install it: npm i -D unplugin-vue-components\\n' +\n ' Or set `autoImport: false` and register components with `app.use(NumoriUI)`.',\n )\n return null\n}\n\n/**\n * @returns {Promise<Function | null>} @tailwindcss/vite's plugin.\n */\nasync function loadTailwindVite() {\n const mod = await importFromProject('@tailwindcss/vite')\n if (mod) return mod.default\n\n console.warn(\n '[numori-ui] `tailwind: true` is set but `@tailwindcss/v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,SAAS,mBAAmB;CAC1B,OAAO;EACL,MAAM;EACN,SAAS;EACT,SAAS;GACP,OAAO;IACL,cAAc,EAIZ,SAAS,CAAC,GAAG,EACf;IACA,KAAK,EAGH,YAAY,CAAC,GAAG,EAClB;GACF;EACF;CACF;AACF;;;;;;;;;;;;;;;;;;AAmBA,eAAe,kBAAkB,WAAW;CAC1C,MAAM,UAAU,cAAc,KAAK,QAAQ,IAAI,GAAG,cAAc,CAAC;CACjE,IAAI;EACF,OAAO,MAAM,OAAO,cAAc,QAAQ,QAAQ,SAAS,CAAC,CAAC,CAAC;CAChE,QAAQ;EAGN,IAAI;GACF,OAAO,MAAM,OAAO;EACtB,QAAQ;GACN,OAAO;EACT;CACF;AACF;;;;AAKA,eAAe,yBAAyB;CACtC,MAAM,MAAM,MAAM,kBAAkB,8BAA8B;CAClE,IAAI,KAAK,OAAO,IAAI;CAEpB,QAAQ,KACN,qNAGF;CACA,OAAO;AACT;;;;AAKA,eAAe,mBAAmB;CAChC,MAAM,MAAM,MAAM,kBAAkB,mBAAmB;CACvD,IAAI,KAAK,OAAO,IAAI;CAEpB,QAAQ,KACN,+HAEF;CACA,OAAO;AACT"}
|
package/package.json
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "numori-ui",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "The Numori design system — a Tailwind 4 Vue 3 component library, consumable as a Nuxt module or a Vite plugin.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Erik Bjerke",
|
|
8
|
+
"email": "contact@erikbjerke.com",
|
|
9
|
+
"url": "https://erikbjerke.com"
|
|
10
|
+
},
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Yaiza Wadhwani Valderas",
|
|
14
|
+
"email": "yaizawv@proton.me"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "TheProcedural Software Ltd",
|
|
18
|
+
"email": "contact@theprocedural.com",
|
|
19
|
+
"url": "https://theprocedural.com"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"license": "AGPL-3.0",
|
|
23
|
+
"homepage": "https://github.com/Numori-Ecosystem/Numori-UI",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/Numori-Ecosystem/Numori-UI.git"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Numori-Ecosystem/Numori-UI/issues"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"vue",
|
|
36
|
+
"vue3",
|
|
37
|
+
"nuxt",
|
|
38
|
+
"nuxt-module",
|
|
39
|
+
"vite-plugin",
|
|
40
|
+
"tailwind",
|
|
41
|
+
"tailwindcss",
|
|
42
|
+
"tailwind-v4",
|
|
43
|
+
"component-library",
|
|
44
|
+
"design-system",
|
|
45
|
+
"ui",
|
|
46
|
+
"numori"
|
|
47
|
+
],
|
|
48
|
+
"sideEffects": [
|
|
49
|
+
"**/*.css"
|
|
50
|
+
],
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
54
|
+
"import": "./dist/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./nuxt": {
|
|
57
|
+
"types": "./dist/nuxt.d.ts",
|
|
58
|
+
"import": "./dist/nuxt.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./vite": {
|
|
61
|
+
"types": "./dist/vite.d.ts",
|
|
62
|
+
"import": "./dist/vite.mjs"
|
|
63
|
+
},
|
|
64
|
+
"./css": "./dist/numori-ui.css",
|
|
65
|
+
"./theme.css": "./dist/numori-ui.css",
|
|
66
|
+
"./components/*": "./src/components/*",
|
|
67
|
+
"./src/*": "./src/*",
|
|
68
|
+
"./package.json": "./package.json"
|
|
69
|
+
},
|
|
70
|
+
"main": "./dist/index.js",
|
|
71
|
+
"module": "./dist/index.js",
|
|
72
|
+
"types": "./dist/index.d.ts",
|
|
73
|
+
"style": "./dist/numori-ui.css",
|
|
74
|
+
"files": [
|
|
75
|
+
"dist",
|
|
76
|
+
"src",
|
|
77
|
+
"README.md",
|
|
78
|
+
"LICENSE"
|
|
79
|
+
],
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=20.19.0"
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "node scripts/build.mjs",
|
|
85
|
+
"build:lib": "vite build",
|
|
86
|
+
"icons": "node scripts/extract-icons.mjs",
|
|
87
|
+
"sync": "node scripts/sync-from-notes.mjs",
|
|
88
|
+
"dev:nuxt": "npm --prefix playground/nuxt run dev",
|
|
89
|
+
"dev:vite": "npm --prefix playground/vite run dev",
|
|
90
|
+
"test": "npm run verify && npm run smoke && npm run treeshake",
|
|
91
|
+
"verify": "node scripts/verify.mjs",
|
|
92
|
+
"smoke": "node scripts/smoke.mjs",
|
|
93
|
+
"treeshake": "node scripts/treeshake.mjs",
|
|
94
|
+
"lint": "eslint . --max-warnings 0",
|
|
95
|
+
"lint:fix": "eslint . --fix",
|
|
96
|
+
"format": "prettier --write .",
|
|
97
|
+
"format:check": "prettier --check .",
|
|
98
|
+
"prepack": "npm run build"
|
|
99
|
+
},
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"tailwind-merge": "^3.6.0"
|
|
102
|
+
},
|
|
103
|
+
"peerDependencies": {
|
|
104
|
+
"@nuxt/kit": "^3.0.0 || ^4.0.0",
|
|
105
|
+
"@tailwindcss/vite": "^4.0.0",
|
|
106
|
+
"tailwindcss": "^4.0.0",
|
|
107
|
+
"unplugin-vue-components": "^28.0.0 || ^29.0.0 || ^30.0.0 || ^31.0.0 || ^32.0.0",
|
|
108
|
+
"vue": "^3.5.0"
|
|
109
|
+
},
|
|
110
|
+
"peerDependenciesMeta": {
|
|
111
|
+
"@nuxt/kit": {
|
|
112
|
+
"optional": true
|
|
113
|
+
},
|
|
114
|
+
"@tailwindcss/vite": {
|
|
115
|
+
"optional": true
|
|
116
|
+
},
|
|
117
|
+
"tailwindcss": {
|
|
118
|
+
"optional": true
|
|
119
|
+
},
|
|
120
|
+
"unplugin-vue-components": {
|
|
121
|
+
"optional": true
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"devDependencies": {
|
|
125
|
+
"@eslint/js": "^10.0.1",
|
|
126
|
+
"@nuxt/kit": "^4.5.2",
|
|
127
|
+
"@iconify-json/mdi": "^1.2.3",
|
|
128
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
129
|
+
"eslint": "^10.8.0",
|
|
130
|
+
"eslint-plugin-vue": "^10.10.0",
|
|
131
|
+
"globals": "^17.11.0",
|
|
132
|
+
"prettier": "^3.9.6",
|
|
133
|
+
"tailwindcss": "^4.3.3",
|
|
134
|
+
"vite": "^8.2.2",
|
|
135
|
+
"vue": "^3.5.42",
|
|
136
|
+
"vue-eslint-parser": "^10.4.1"
|
|
137
|
+
}
|
|
138
|
+
}
|