tresjs-nuxt 4.4.0 → 4.6.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![NPM downloads][badge-npm-downloads]][url-npm]
6
6
  [![NPM Unpacked Size (with version)][badge-npm-unpacked-size]][url-npm]
7
7
 
8
- A Nuxt module for TresJS that auto-imports the TresJS core API, registers TresCanvas for client and server, and registers every installed @tresjs package's components and composables, with no devtools UI of its own.
8
+ A Nuxt module for TresJS that auto-imports the TresJS core API and registers TresCanvas for client and server. It registers the components and composables of every installed @tresjs package, and has no devtools UI of its own.
9
9
 
10
10
  Design notes live in [the specs](https://github.com/Esposter/Esposter/tree/main/openspec/specs/tresjs-nuxt).
11
11
 
@@ -19,10 +19,16 @@ Design notes live in [the specs](https://github.com/Esposter/Esposter/tree/main/
19
19
 
20
20
  ## <a name="getting-started">🚀 Getting Started</a>
21
21
 
22
+ 1. Install the package.
23
+
22
24
  ```bash
23
25
  pnpm i tresjs-nuxt
24
26
  ```
25
27
 
28
+ Check: `package.json` lists `tresjs-nuxt` in its dependencies.
29
+
30
+ 2. Add this to `nuxt.config.ts`.
31
+
26
32
  ```ts
27
33
  // nuxt.config.ts
28
34
  export default defineNuxtConfig({
@@ -32,12 +38,14 @@ export default defineNuxtConfig({
32
38
  });
33
39
  ```
34
40
 
41
+ Check: `pnpm dev` starts with no module error.
42
+
35
43
  ## <a name="key-exports">🧩 Key Exports</a>
36
44
 
37
- | Export | Kind | Purpose |
38
- | :-------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------- |
39
- | `default` | const | The Nuxt module: auto-imports the TresJS core API, registers `TresCanvas` and each installed `@tresjs/*` package's exports |
40
- | `ModuleOptions` | interface | The `tres` config key: `glsl` loads the `vite-plugin-glsl` peer, and `modules` names extra packages whose exports register |
45
+ | Export | Kind | Purpose |
46
+ | :-------------- | :-------- | :-------------------------------------------------------------------------------------------------------------------------------------- |
47
+ | `default` | const | The Nuxt module. It auto-imports the TresJS core API, and registers `TresCanvas` and the exports of each installed `@tresjs/*` package. |
48
+ | `ModuleOptions` | interface | The `tres` config key. `glsl` loads the `vite-plugin-glsl` peer. `modules` names extra packages whose exports register. |
41
49
 
42
50
  ## <a name="license">⚖️ License</a>
43
51
 
@@ -0,0 +1,4 @@
1
+ import { ModuleOptions } from "./models/ModuleOptions.js";
2
+ import { NuxtModule } from "@nuxt/schema";
3
+ declare const tresjsModule: NuxtModule<ModuleOptions>;
4
+ export { type ModuleOptions, tresjsModule as default };
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
1
+ import { MODULE_NAME } from "./runtime/constants.js";
2
+ import { checkIsTresCustomElement } from "./services/checkIsTresCustomElement.js";
3
+ import { CORE_PACKAGE_NAME, GLSL_PACKAGE_NAME, THREE_PACKAGE_NAME, TRES_CANVAS_NAME } from "./services/constants.js";
4
+ import { getExportNames } from "./services/getExportNames.js";
5
+ import { getTresPackageNames } from "./services/getTresPackageNames.js";
6
+ import { addComponent, addImports, addVitePlugin, createResolver, defineNuxtModule, resolvePath } from "@nuxt/kit";
7
+ import { defu } from "defu";
8
+ // src/module.ts
9
+ const LOWERCASE_NAME_REGEX = /^[a-z]/u;
10
+ const tresjsModule = defineNuxtModule({
11
+ defaults: {
12
+ glsl: false,
13
+ modules: []
14
+ },
15
+ meta: {
16
+ compatibility: { nuxt: ">=5.0.0-0" },
17
+ configKey: "tres",
18
+ name: MODULE_NAME
19
+ },
20
+ async setup(options, nuxt) {
21
+ const { resolve } = createResolver(import.meta.url);
22
+ nuxt.options.build.transpile.push(/@tresjs\//u);
23
+ nuxt.options.vue.compilerOptions.isCustomElement = checkIsTresCustomElement;
24
+ const coreExportNames = await getExportNames(await resolvePath(CORE_PACKAGE_NAME));
25
+ addImports([
26
+ ...coreExportNames.filter((name) => name.startsWith("use")).map((name) => ({
27
+ from: CORE_PACKAGE_NAME,
28
+ name
29
+ })),
30
+ {
31
+ as: "extendTres",
32
+ from: CORE_PACKAGE_NAME,
33
+ name: "extend"
34
+ },
35
+ {
36
+ from: CORE_PACKAGE_NAME,
37
+ name: "TresObject",
38
+ type: true
39
+ }
40
+ ]);
41
+ nuxt.hook("prepare:types", ({ references }) => {
42
+ references.push({ types: CORE_PACKAGE_NAME });
43
+ });
44
+ const packageNames = /* @__PURE__ */ new Set([...options.modules ?? [], ...await getTresPackageNames(nuxt.options.rootDir)]);
45
+ const packageExports = await Promise.all(Array.from(packageNames, async (packageName) => {
46
+ const entryPath = await resolvePath(packageName);
47
+ if (entryPath === packageName) return [];
48
+ return (await getExportNames(entryPath)).map((name) => ({
49
+ name,
50
+ packageName
51
+ }));
52
+ }));
53
+ for (const { name, packageName } of packageExports.flat()) if (LOWERCASE_NAME_REGEX.test(name)) addImports({
54
+ from: packageName,
55
+ name
56
+ });
57
+ else addComponent({
58
+ export: name,
59
+ filePath: packageName,
60
+ name
61
+ });
62
+ nuxt.options.vite.resolve = defu(nuxt.options.vite.resolve, { dedupe: [THREE_PACKAGE_NAME] });
63
+ nuxt.options.vite.optimizeDeps = defu(nuxt.options.vite.optimizeDeps, { include: [THREE_PACKAGE_NAME] });
64
+ addComponent({
65
+ filePath: await resolvePath(resolve("./runtime/TresCanvas.client")),
66
+ name: TRES_CANVAS_NAME
67
+ });
68
+ addComponent({
69
+ filePath: await resolvePath(resolve("./runtime/TresCanvas.server")),
70
+ name: TRES_CANVAS_NAME
71
+ });
72
+ if (options.glsl) {
73
+ const { default: glsl } = await import(GLSL_PACKAGE_NAME);
74
+ addVitePlugin(glsl());
75
+ }
76
+ }
77
+ });
78
+ export { tresjsModule as default };
@@ -0,0 +1,4 @@
1
+ export interface ModuleOptions {
2
+ glsl?: boolean;
3
+ modules?: string[];
4
+ }
@@ -0,0 +1,3 @@
1
+ import { Component } from "vue";
2
+ declare const tresCanvasClient: Component;
3
+ export { tresCanvasClient as default };
@@ -0,0 +1,12 @@
1
+ import { TRES_CANVAS_NAME } from "../services/constants.js";
2
+ import { TresCanvas } from "@tresjs/core";
3
+ import { defineComponent, h } from "vue";
4
+ // src/runtime/TresCanvas.client.ts
5
+ const tresCanvasClient = defineComponent({
6
+ inheritAttrs: false,
7
+ name: TRES_CANVAS_NAME,
8
+ setup(_props, { attrs, slots }) {
9
+ return () => h(TresCanvas, attrs, slots);
10
+ }
11
+ });
12
+ export { tresCanvasClient as default };
@@ -0,0 +1,3 @@
1
+ import { Component } from "vue";
2
+ declare const tresCanvasServer: Component;
3
+ export { tresCanvasServer as default };
@@ -0,0 +1,8 @@
1
+ import { TRES_CANVAS_NAME } from "../services/constants.js";
2
+ import { defineComponent, h } from "vue";
3
+ // src/runtime/TresCanvas.server.ts
4
+ const tresCanvasServer = defineComponent({
5
+ name: TRES_CANVAS_NAME,
6
+ setup: () => () => h("span")
7
+ });
8
+ export { tresCanvasServer as default };
@@ -0,0 +1 @@
1
+ export declare const MODULE_NAME = "tresjs-nuxt";
@@ -0,0 +1,3 @@
1
+ // src/runtime/constants.ts
2
+ const MODULE_NAME = "tresjs-nuxt";
3
+ export { MODULE_NAME };
@@ -0,0 +1,7 @@
1
+ import { TRES_CORE_COMPONENT_NAMES } from "./constants.js";
2
+ // src/services/checkIsTresCustomElement.ts
3
+ const PRIMITIVE_TAG_NAME = "primitive";
4
+ const TRES_COMPONENT_NAME_REGEX = /^Tres[A-Z]/u;
5
+ const TRES_ELEMENT_NAME_PREFIX = "tres-";
6
+ const checkIsTresCustomElement = (tagName) => (TRES_COMPONENT_NAME_REGEX.test(tagName) || tagName.startsWith(TRES_ELEMENT_NAME_PREFIX)) && !TRES_CORE_COMPONENT_NAMES.includes(tagName) || tagName === PRIMITIVE_TAG_NAME;
7
+ export { checkIsTresCustomElement };
@@ -0,0 +1,14 @@
1
+ // src/services/constants.ts
2
+ const CORE_PACKAGE_NAME = "@tresjs/core";
3
+ const GLSL_PACKAGE_NAME = "vite-plugin-glsl";
4
+ const THREE_PACKAGE_NAME = "three";
5
+ const TRES_CANVAS_NAME = "TresCanvas";
6
+ const TRES_PACKAGE_SCOPE = "@tresjs/";
7
+ const TRES_CORE_COMPONENT_NAMES = [
8
+ TRES_CANVAS_NAME,
9
+ "TresCanvasContext",
10
+ "TresLeches",
11
+ "TresPortal",
12
+ "TresScene"
13
+ ];
14
+ export { CORE_PACKAGE_NAME, GLSL_PACKAGE_NAME, THREE_PACKAGE_NAME, TRES_CANVAS_NAME, TRES_CORE_COMPONENT_NAMES, TRES_PACKAGE_SCOPE };
@@ -0,0 +1,8 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ // src/services/getDependencyNames.ts
4
+ const getDependencyNames = async (directory) => {
5
+ const manifest = JSON.parse(await readFile(join(directory, "package.json"), "utf8"));
6
+ return [...Object.keys(manifest.dependencies ?? {}), ...Object.keys(manifest.devDependencies ?? {})];
7
+ };
8
+ export { getDependencyNames };
@@ -0,0 +1,5 @@
1
+ import { findExportNames } from "mlly";
2
+ import { readFile } from "node:fs/promises";
3
+ // src/services/getExportNames.ts
4
+ const getExportNames = async (entryPath) => findExportNames(await readFile(entryPath, "utf8"));
5
+ export { getExportNames };
@@ -0,0 +1,12 @@
1
+ import "./constants.js";
2
+ import { getDependencyNames } from "./getDependencyNames.js";
3
+ import { dirname, join } from "node:path";
4
+ import { existsSync } from "node:fs";
5
+ // src/services/getTresPackageNames.ts
6
+ const getTresPackageNames = async (rootDirectory) => {
7
+ const parentDirectory = dirname(rootDirectory);
8
+ const directories = existsSync(join(parentDirectory, "package.json")) ? [rootDirectory, parentDirectory] : [rootDirectory];
9
+ const dependencyNames = (await Promise.all(directories.map((directory) => getDependencyNames(directory)))).flat();
10
+ return [...new Set(dependencyNames)].filter((dependencyName) => dependencyName.startsWith("@tresjs/") && dependencyName !== "@tresjs/core");
11
+ };
12
+ export { getTresPackageNames };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tresjs-nuxt",
3
- "version": "4.4.0",
3
+ "version": "4.6.0",
4
4
  "description": "TresJS for Nuxt — a Nuxt module that auto-imports the TresJS core API, registers TresCanvas for client and server, and registers every installed @tresjs package's components and composables, with no devtools UI of its own.",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -50,21 +50,22 @@
50
50
  "mlly": "^1.8.2"
51
51
  },
52
52
  "devDependencies": {
53
- "@esposter/configuration": "4.4.0",
54
- "tsdown": "0.23.2",
53
+ "@esposter/configuration": "4.6.0",
54
+ "@types/node": "^26.6.6",
55
+ "tsdown": "^0.23.7",
55
56
  "vite-plugin-glsl": "^1.6.2"
56
57
  },
57
58
  "peerDependencies": {
58
59
  "@tresjs/core": "^5.10.1",
59
60
  "nuxt": "npm:nuxt-nightly@5x",
60
- "three": "^0.186.1",
61
+ "three": "^0.187.0",
61
62
  "vite-plugin-glsl": "^1.6.2",
62
- "vue": "^3.5.44"
63
+ "vue": "^3.5.45"
63
64
  },
64
65
  "peerDependenciesMeta": {
65
66
  "vite-plugin-glsl": {
66
67
  "optional": true
67
68
  }
68
69
  },
69
- "gitHead": "e1a416c4b91da69cc2aa259b50a4d656f204d272"
70
+ "gitHead": "0ceea3ffbe12ca69413ea5db2d3cfad197a63cba"
70
71
  }