truecanvas 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 (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +265 -0
  3. package/dist/catalog-worker.js +7 -0
  4. package/dist/chunk-753N4QRO.js +317 -0
  5. package/dist/chunk-J6CJBZO6.js +23 -0
  6. package/dist/chunk-WB35FXGP.js +3366 -0
  7. package/dist/cli.js +2931 -0
  8. package/dist/core/index.d.ts +820 -0
  9. package/dist/core/index.js +71 -0
  10. package/dist/editor/assets/controls-BQYSgX53.css +1 -0
  11. package/dist/editor/assets/controls-BYFjuGCq.js +9 -0
  12. package/dist/editor/assets/hub-C4_700Hv.js +2 -0
  13. package/dist/editor/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  14. package/dist/editor/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  15. package/dist/editor/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  16. package/dist/editor/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  17. package/dist/editor/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  18. package/dist/editor/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  19. package/dist/editor/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  20. package/dist/editor/assets/main-CfAJbDf1.js +25 -0
  21. package/dist/editor/assets/react-DB-4Zxce.js +1 -0
  22. package/dist/editor/favicon.svg +3 -0
  23. package/dist/editor/hub.html +16 -0
  24. package/dist/editor/index.html +16 -0
  25. package/dist/next/index.d.ts +11 -0
  26. package/dist/next/index.js +83 -0
  27. package/dist/next/loader.cjs +16210 -0
  28. package/dist/runtime/host.d.ts +23 -0
  29. package/dist/runtime/host.js +412 -0
  30. package/dist/runtime/index.d.ts +42 -0
  31. package/dist/runtime/index.js +11 -0
  32. package/package.json +108 -0
@@ -0,0 +1,16 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Truecanvas</title>
7
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
8
+ <script type="module" crossorigin src="/assets/main-CfAJbDf1.js"></script>
9
+ <link rel="modulepreload" crossorigin href="/assets/react-DB-4Zxce.js">
10
+ <link rel="modulepreload" crossorigin href="/assets/controls-BYFjuGCq.js">
11
+ <link rel="stylesheet" crossorigin href="/assets/controls-BQYSgX53.css">
12
+ </head>
13
+ <body>
14
+ <div id="root"></div>
15
+ </body>
16
+ </html>
@@ -0,0 +1,11 @@
1
+ import { NextConfig } from 'next';
2
+
3
+ /**
4
+ * Enables Truecanvas in development: canvas files (`*.canvas.tsx`), pages and
5
+ * layouts get their JSX stamped with source ids so the editor can map pixels
6
+ * back to code.
7
+ * In production builds the config is returned untouched.
8
+ */
9
+ declare function withTruecanvas(config?: NextConfig): NextConfig;
10
+
11
+ export { withTruecanvas as default, withTruecanvas };
@@ -0,0 +1,83 @@
1
+ // src/next/index.ts
2
+ import { fileURLToPath } from "url";
3
+ import { existsSync, readFileSync, realpathSync } from "fs";
4
+ import { createRequire } from "module";
5
+ import { dirname, join, relative } from "path";
6
+ function withTruecanvas(config = {}) {
7
+ if (process.env.NODE_ENV === "production") return config;
8
+ const loader = fileURLToPath(new URL("./loader.cjs", import.meta.url));
9
+ warnIfLinkedOutside(loader);
10
+ const userWebpack = config.webpack;
11
+ const root = process.cwd();
12
+ const appDir = existsSync(join(root, "src/app")) ? "src/app" : "app";
13
+ const components = componentRoots(root, appDir);
14
+ const options = { root, appDir, components };
15
+ const rule = {
16
+ "*.canvas.tsx": { loaders: [loader], as: "*.tsx" },
17
+ // pages and layouts, for linked frames (the loader skips anything outside this project's app dir)
18
+ [`**/${appDir}/**/{page,layout}.{tsx,jsx}`]: { loaders: [{ loader, options }] }
19
+ };
20
+ for (const dir of components) rule[`**/${dir}/**/*.{tsx,jsx}`] = { loaders: [{ loader, options }] };
21
+ const legacy = nextVersion() < 15.3;
22
+ const turbo = legacy ? { experimental: { ...config.experimental, turbo: { ...config.experimental?.turbo, rules: { ...config.experimental?.turbo?.rules, ...rule } } } } : { turbopack: { ...config.turbopack, rules: { ...config.turbopack?.rules, ...rule } } };
23
+ return {
24
+ ...config,
25
+ ...turbo,
26
+ webpack(webpackConfig, ctx) {
27
+ webpackConfig.module.rules.push({ test: /\.canvas\.tsx$/, enforce: "pre", use: [loader] });
28
+ webpackConfig.module.rules.push({ test: /[\\/](page|layout)\.[jt]sx$/, enforce: "pre", use: [{ loader, options }] });
29
+ webpackConfig.module.rules.push({ test: /\.[jt]sx$/, include: components.map((d) => join(root, d)), enforce: "pre", use: [{ loader, options }] });
30
+ return userWebpack ? userWebpack(webpackConfig, ctx) : webpackConfig;
31
+ }
32
+ };
33
+ }
34
+ var next_default = withTruecanvas;
35
+ function warnIfLinkedOutside(file) {
36
+ try {
37
+ const real = realpathSync(file);
38
+ const root = realpathSync(workspaceRoot(process.cwd()));
39
+ const rel = relative(root, real);
40
+ const insideWorkspace = !rel.startsWith("..") || /node_modules/.test(real);
41
+ if (!insideWorkspace) {
42
+ console.warn(
43
+ "\n[truecanvas] This project uses a linked copy of truecanvas from outside the project folder.\nTurbopack can't load it. Install a packed build instead: run `pnpm pack:local` in the truecanvas repo,\nthen `pnpm add -D /path/to/truecanvas-<version>.tgz` here.\n"
44
+ );
45
+ }
46
+ } catch {
47
+ }
48
+ }
49
+ function componentRoots(root, appDir) {
50
+ let globs = [`${appDir.startsWith("src/") ? "src/" : ""}components/**/*.tsx`];
51
+ try {
52
+ const file = JSON.parse(readFileSync(join(root, "truecanvas.config.json"), "utf8"));
53
+ if (Array.isArray(file.components)) globs = file.components;
54
+ } catch {
55
+ }
56
+ return [...new Set(globs.map((g) => g.split("/").filter((p) => !p.includes("*")).join("/")).filter(Boolean))];
57
+ }
58
+ function workspaceRoot(dir) {
59
+ for (let d = dir; ; ) {
60
+ if (existsSync(join(d, "pnpm-workspace.yaml"))) return d;
61
+ try {
62
+ if (JSON.parse(readFileSync(join(d, "package.json"), "utf8")).workspaces) return d;
63
+ } catch {
64
+ }
65
+ const up = dirname(d);
66
+ if (up === d) return dir;
67
+ d = up;
68
+ }
69
+ }
70
+ function nextVersion() {
71
+ try {
72
+ const require2 = createRequire(join(process.cwd(), "package.json"));
73
+ const v = require2("next/package.json").version;
74
+ const [major, minor] = v.split(".").map(Number);
75
+ return major + minor / 10;
76
+ } catch {
77
+ return 99;
78
+ }
79
+ }
80
+ export {
81
+ next_default as default,
82
+ withTruecanvas
83
+ };