@bysages/nuxt 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.d.mts CHANGED
@@ -2,11 +2,11 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { ApplyThemeOptions } from '@bysages/core';
3
3
 
4
4
  interface BsElementsOptions {
5
- /** Prefix for the auto-imported components — "Bs" renders `<BsButton>`.
6
- * Empty by default. */
5
+ /** Prefix for auto-imported components — `Bs` renders `<BsButton>`.
6
+ * `"Bs"` by default; use `""` only when the app owns the name space. */
7
7
  prefix?: string;
8
- /** Theme applied on the client before the app mounts: mode, accent,
9
- * scene, density, contrast — anything `applyTheme` accepts. */
8
+ /** Default theme applied before mount: mode, accent, scene, density,
9
+ * contrast — anything `applyTheme` accepts. A persisted user choice wins. */
10
10
  theme?: ApplyThemeOptions;
11
11
  }
12
12
  declare const _default: _nuxt_schema.NuxtModule<BsElementsOptions, BsElementsOptions, false>;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bysages/nuxt",
3
3
  "configKey": "bsElements",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { tokensCss, componentStyles } from '@bysages/core';
1
+ import { tokensCss, componentStyles, themeStorageKey } from '@bysages/core';
2
2
  import { defineNuxtModule, createResolver, addComponent, addTemplate, addPlugin } from '@nuxt/kit';
3
3
 
4
4
  function isComponentExport(value) {
@@ -9,23 +9,23 @@ function isComponentExport(value) {
9
9
  (member) => typeof member === "function" || typeof member === "object" && member !== null && ("render" in member || "setup" in member)
10
10
  );
11
11
  }
12
- const RESERVED = /* @__PURE__ */ new Set(["Icon"]);
13
12
  const module$1 = defineNuxtModule({
14
13
  meta: {
15
14
  name: "@bysages/nuxt",
16
15
  configKey: "bsElements"
17
16
  },
18
17
  defaults: {
19
- prefix: ""
18
+ prefix: "Bs"
20
19
  },
21
20
  async setup(options, nuxt) {
22
21
  const resolver = createResolver(import.meta.url);
23
22
  const families = await import('@bysages/vue');
24
23
  for (const name of Object.keys(families)) {
25
24
  if (!/^[A-Z]/.test(name) || !isComponentExport(families[name])) continue;
26
- if (RESERVED.has(name)) continue;
25
+ const componentName = `${options.prefix}${name}`;
26
+ if (componentName === "Icon") continue;
27
27
  addComponent({
28
- name: options.prefix + name,
28
+ name: componentName,
29
29
  export: name,
30
30
  filePath: "@bysages/vue"
31
31
  });
@@ -42,6 +42,28 @@ const module$1 = defineNuxtModule({
42
42
  nuxt.options.css.push(styles.dst);
43
43
  nuxt.options.app.head.meta ||= [];
44
44
  nuxt.options.app.head.meta.push({ name: "bs-styles-shipped", content: "build" });
45
+ const configuredTheme = JSON.stringify(options.theme ?? null).replaceAll("<", "\\u003c");
46
+ nuxt.options.app.head.script ||= [];
47
+ nuxt.options.app.head.script.push({
48
+ tagPosition: "head",
49
+ innerHTML: `(() => {
50
+ try {
51
+ const stored = JSON.parse(localStorage.getItem(${JSON.stringify(themeStorageKey)}) || "null");
52
+ const theme = stored || ${configuredTheme};
53
+ if (!theme) return;
54
+ const mode = theme.mode === "system"
55
+ ? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light")
56
+ : theme.mode;
57
+ const root = document.documentElement;
58
+ if (mode === "dark" || mode === "light") root.dataset.theme = mode;
59
+ if (theme.contrast === "high") root.dataset.contrast = "high";
60
+ else delete root.dataset.contrast;
61
+ root.dataset.density = theme.density || "default";
62
+ if (theme.scene && theme.scene !== "auto") root.dataset.scene = theme.scene;
63
+ else delete root.dataset.scene;
64
+ } catch {}
65
+ })();`
66
+ });
45
67
  addPlugin(resolver.resolve("./runtime/plugin"));
46
68
  }
47
69
  });
@@ -1,7 +1,5 @@
1
- /** Applies the theme configured through module options on the client.
2
- * The wrappers' own injection already stands down against the build-time
3
- * stylesheet via the head marker the module plants. Published modules
4
- * cannot lean on the application's auto-imports — the Nuxt APIs come
5
- * in explicitly from `#imports`, which the consuming build resolves. */
1
+ /** Applies the configured default theme, but never outranks an explicit
2
+ * persisted choice. A stored theme is restored before mount instead; the
3
+ * module's early head script already prevents the first-paint flash. */
6
4
  declare const _default: any;
7
5
  export default _default;
@@ -1,7 +1,11 @@
1
- import { applyTheme } from "@bysages/core";
1
+ import { applyTheme, hasStoredTheme, initTheme } from "@bysages/core";
2
2
  import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
3
3
  export default defineNuxtPlugin(() => {
4
4
  if (import.meta.server) return;
5
5
  const { theme } = useRuntimeConfig().public.bsElements;
6
- if (theme) applyTheme(theme);
6
+ if (hasStoredTheme()) {
7
+ initTheme();
8
+ } else if (theme) {
9
+ applyTheme(theme);
10
+ }
7
11
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bysages/nuxt",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Nuxt module for By Sages Elements — auto-imports the paper-and-ink Vue components and applies the theme",
5
5
  "keywords": [
6
6
  "components",
@@ -46,8 +46,8 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@nuxt/kit": "4.5.2",
49
- "@bysages/vue": "0.4.0",
50
- "@bysages/core": "0.4.0"
49
+ "@bysages/core": "0.4.1",
50
+ "@bysages/vue": "0.4.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@nuxt/module-builder": "1.0.3",