@jxsuite/compiler 9.0.1 → 10.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jxsuite/compiler",
3
- "version": "9.0.1",
3
+ "version": "10.0.0",
4
4
  "description": "Jx static HTML compiler, island detector, and site builder",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,6 +38,7 @@
38
38
  "./types": "./src/types.ts",
39
39
  "./db-push": "./src/site/db-push.ts",
40
40
  "./document-scripts": "./src/site/document-scripts.ts",
41
+ "./pack": "./src/targets/compile-pack.ts",
41
42
  "./bundler": "./src/site/bundler.ts",
42
43
  "./bun-plugin": "./src/site/bun-plugin.ts"
43
44
  },
@@ -54,31 +55,31 @@
54
55
  "upgrade": "bun update --latest && bun install"
55
56
  },
56
57
  "dependencies": {
57
- "@jxsuite/compiler-binding": "^0.2.1",
58
- "@jxsuite/create": "^1.8.2",
59
- "@jxsuite/erase": "^0.3.1",
60
- "@jxsuite/runtime": "^7.0.1",
61
- "@jxsuite/schema": "^6.0.1",
62
- "@jxsuite/site": "^2.7.1",
63
- "@vue/reactivity": "3.5.44",
58
+ "@jxsuite/compiler-binding": "^0.3.0",
59
+ "@jxsuite/create": "^1.8.4",
60
+ "@jxsuite/erase": "^0.3.3",
61
+ "@jxsuite/runtime": "^8.0.0",
62
+ "@jxsuite/schema": "^7.0.0",
63
+ "@jxsuite/site": "^3.0.0",
64
+ "@vue/reactivity": "3.5.45",
64
65
  "esbuild": "^0.28.2",
65
66
  "lit-html": "^3.3.3"
66
67
  },
67
68
  "devDependencies": {
68
69
  "@happy-dom/global-registrator": "^21.0.4",
69
- "@jxsuite/connector": "^0.8.10",
70
- "@jxsuite/parser": "^5.0.1",
70
+ "@jxsuite/connector": "^0.8.12",
71
+ "@jxsuite/parser": "^5.1.0",
71
72
  "@jxsuite/test-support": "^0.0.0",
72
73
  "@types/mdast": "^4.0.4"
73
74
  },
74
75
  "optionalDependencies": {
75
- "@jxsuite/compiler-binding-linux-x64-gnu": "0.2.1",
76
- "@jxsuite/compiler-binding-linux-x64-musl": "0.2.1",
77
- "@jxsuite/compiler-binding-linux-arm64-gnu": "0.2.1",
78
- "@jxsuite/compiler-binding-linux-arm64-musl": "0.2.1",
79
- "@jxsuite/compiler-binding-darwin-x64": "0.2.1",
80
- "@jxsuite/compiler-binding-darwin-arm64": "0.2.1",
81
- "@jxsuite/compiler-binding-win32-x64-msvc": "0.2.1",
82
- "@jxsuite/compiler-binding-win32-arm64-msvc": "0.2.1"
76
+ "@jxsuite/compiler-binding-linux-x64-gnu": "0.3.0",
77
+ "@jxsuite/compiler-binding-linux-x64-musl": "0.3.0",
78
+ "@jxsuite/compiler-binding-linux-arm64-gnu": "0.3.0",
79
+ "@jxsuite/compiler-binding-linux-arm64-musl": "0.3.0",
80
+ "@jxsuite/compiler-binding-darwin-x64": "0.3.0",
81
+ "@jxsuite/compiler-binding-darwin-arm64": "0.3.0",
82
+ "@jxsuite/compiler-binding-win32-x64-msvc": "0.3.0",
83
+ "@jxsuite/compiler-binding-win32-arm64-msvc": "0.3.0"
83
84
  }
84
85
  }
package/src/cli.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * Jx — Unified CLI for the Jx platform
4
4
  *
5
- * Commands: jx build [project-root] [--verbose] [--no-clean] [--include-held] jx schema
6
- * [project-root] jx validate [project-root]
5
+ * Commands: jx build [project-root] [--verbose] [--no-clean] [--include-held]
6
+ * [--no-optimize-images] jx schema [project-root] jx validate [project-root]
7
7
  *
8
8
  * @module jx-cli
9
9
  */
@@ -37,6 +37,8 @@ Options:
37
37
  --verbose Print detailed build progress
38
38
  --no-clean Don't clean outDir before building
39
39
  --include-held Keep entries a content type's hold rules match, for a preview
40
+ --no-optimize-images Publish images as they are, whatever images.optimize says (also
41
+ JX_IMAGES_OPTIMIZE=false in the environment)
40
42
  --port <n> dev/preview: port to listen on (default 3000 / 4173)
41
43
  --dry-run db push: print the statements without executing them
42
44
  --connection db push: restrict to one connection name
@@ -139,7 +141,15 @@ Options:
139
141
 
140
142
  try {
141
143
  const { buildSite } = await import("./site/site-build.ts");
142
- const result = await buildSite(projectRoot, { clean, includeHeld, verbose });
144
+ const { imagesOptimizeOff } = await import("./site/site-loader.ts");
145
+ const optimizeImages =
146
+ !flags.has("--no-optimize-images") && !imagesOptimizeOff(process.env.JX_IMAGES_OPTIMIZE);
147
+ const result = await buildSite(projectRoot, {
148
+ clean,
149
+ includeHeld,
150
+ optimizeImages,
151
+ verbose,
152
+ });
143
153
 
144
154
  if (result.errors.length > 0) {
145
155
  console.error(`\nBuild completed with ${result.errors.length} error(s):`);
package/src/compiler.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Routes Jx documents to the appropriate compilation target:
5
5
  *
6
+ * - `$prototype: "Class"` → compile-class.js (ES class module, compiler.md §5.6)
6
7
  * - Fully static → compile-static.js (plain HTML/CSS, zero JS)
7
8
  * - Custom element (-) → compile-element.js (lit-html web component)
8
9
  * - Dynamic (standard) → compile-client.js (pre-rendered HTML + reactive bindings)
@@ -21,6 +22,7 @@ import {
21
22
  compileStyles,
22
23
  escapeHtml,
23
24
  isDynamic,
25
+ pageImportMap,
24
26
  tagNameToClassName,
25
27
  } from "./shared.ts";
26
28
 
@@ -29,13 +31,15 @@ import { compileStaticPage } from "./targets/compile-static.ts";
29
31
  import { compileClient } from "./targets/compile-client.ts";
30
32
  import { isClassDef, isString } from "@jxsuite/schema/guards";
31
33
  import { isNativeDocumentPath, parseNativeDocument } from "@jxsuite/schema/jxn";
32
- import type { JxDocument, JxStyle } from "@jxsuite/schema/types";
34
+ import type { JxDocument, JxPrototypeDef, JxStyle } from "@jxsuite/schema/types";
33
35
  import type { FormatRegistry } from "@jxsuite/schema/format-registry";
34
36
 
35
37
  // Re-exports for consumers
36
38
  export { isDynamic } from "./shared.ts";
37
39
  export { compileSiteServer } from "./targets/compile-server.ts";
38
40
  export { compileElement, compileElementPage } from "./targets/compile-element.ts";
41
+ export { compileElementPack, writeElementPack } from "./targets/compile-pack.ts";
42
+ export type { ElementPack, ElementPackOptions } from "./targets/compile-pack.ts";
39
43
  export { compileClient } from "./targets/compile-client.ts";
40
44
 
41
45
  // ─── Entry ────────────────────────────────────────────────────────────────────
@@ -44,10 +48,21 @@ export interface CompileOptions {
44
48
  title?: string;
45
49
  reactivitySrc?: string;
46
50
  litHtmlSrc?: string;
51
+ /**
52
+ * The build's whole import map, prefix keys included. A page that writes its own map writes this
53
+ * one, so a compiled module's package subpath (`lit-html/directives/repeat.js`) resolves there
54
+ * (compiler.md §12). Without it the page maps the two sources above.
55
+ */
56
+ runtimeImports?: Record<string, string>;
47
57
  projectStyle?: JxStyle | null;
48
58
  formats?: FormatRegistry;
49
59
  /** Rewrite Function-def `$src` specifiers to served URLs (see CompileElementOptions). */
50
60
  rewriteSrc?: (specifier: string) => string;
61
+ /**
62
+ * The URL a `timing: "client"` external class's module is served at (compiler.md §3, §12). A site
63
+ * build supplies it; without it such an entry is a compile error.
64
+ */
65
+ resolveClass?: (def: JxPrototypeDef) => string;
51
66
  /**
52
67
  * The route prefix a `timing: "server"` entry posts to, deployment base included
53
68
  * (`serverRoutePrefix`). Default `"/_jx/server"`, for a site served from its origin root.
@@ -74,8 +89,10 @@ interface PageTargetOverrides {
74
89
  /**
75
90
  * Compile a Jx document to HTML (+ optional JS module files).
76
91
  *
77
- * Routing: 1. Not dynamic → static HTML/CSS, zero JS 2. tagName contains hyphen → custom element
78
- * (lit-html) 3. Otherwise → pre-rendered HTML with reactive bindings
92
+ * Routing, first match wins: 0. Root `$prototype` is `"Class"` → ES class module (compiler.md §5.6)
93
+ *
94
+ * 1. Not dynamic → static HTML/CSS, zero JS 2. tagName contains hyphen → custom element (lit-html) 3.
95
+ * Otherwise → pre-rendered HTML with reactive bindings
79
96
  *
80
97
  * @param {string | JxDocument} sourcePath - Path to .json file, URL, or raw document object
81
98
  * @param {CompileOptions} [opts]
@@ -113,25 +130,25 @@ export async function compile(sourcePath: string | JxDocument, opts: CompileOpti
113
130
  // Function bodies as JavaScript before anything analyses them (spec.md §23.1).
114
131
  raw = erasedDocument(raw, isString(sourcePath) ? sourcePath : "the document");
115
132
 
116
- // Route 0: .class.json schema-defined class → JS class module
133
+ // Route 0: a class document (`$prototype: "Class"`, whatever the file is called) → JS class module
117
134
  if (isClassDef(raw)) {
118
135
  const { compileClassJson } = await import("./targets/compile-class.js");
119
136
  const jsContent = compileClassJson(raw);
137
+ // Beside the source and never over it: the extension, and a `.class` before it, become `.js`.
120
138
  const outputPath = isString(sourcePath)
121
- ? sourcePath.replace(/\.class\.json$/, ".js")
139
+ ? sourcePath.replace(/(\.class)?\.[^./\\]+$/, ".js")
122
140
  : `${raw.title}.js`;
123
141
  return { files: [{ content: jsContent, path: outputPath }], html: "" };
124
142
  }
125
143
 
126
144
  // Route 1: Fully static → plain HTML/CSS
127
145
  if (!isDynamic(raw)) {
128
- return compileStaticPage(raw, {
129
- litHtmlSrc,
130
- projectStyle,
131
- reactivitySrc,
132
- ...pageTargetOverrides(opts),
133
- title,
134
- });
146
+ // The static target emits no module, so it takes no runtime source and no `$src` rewriter.
147
+ const staticOptions: Parameters<typeof compileStaticPage>[1] = { projectStyle, title };
148
+ if (opts.prePaintScheme === false) {
149
+ staticOptions.prePaintScheme = false;
150
+ }
151
+ return compileStaticPage(raw, staticOptions);
135
152
  }
136
153
 
137
154
  // Route 2: Custom element tagName (contains hyphen) → lit-html web component
@@ -145,6 +162,8 @@ export async function compile(sourcePath: string | JxDocument, opts: CompileOpti
145
162
  opts.rewriteSrc,
146
163
  null,
147
164
  opts.serverBaseUrl,
165
+ [],
166
+ opts.resolveClass,
148
167
  );
149
168
  const moduleFile = {
150
169
  content: moduleContent,
@@ -159,14 +178,7 @@ export async function compile(sourcePath: string | JxDocument, opts: CompileOpti
159
178
  <meta charset="utf-8">
160
179
  <meta name="viewport" content="width=device-width, initial-scale=1">
161
180
  <title>${escapeHtml(title)}</title>
162
- <script type="importmap">
163
- {
164
- "imports": {
165
- "@vue/reactivity": "${reactivitySrc}",
166
- "lit-html": "${litHtmlSrc}"
167
- }
168
- }
169
- </script>
181
+ ${pageImportMap({ litHtmlSrc, reactivitySrc, runtimeImports: opts.runtimeImports })}
170
182
  ${styleBlock}
171
183
  </head>
172
184
  <body>
@@ -189,6 +201,12 @@ export async function compile(sourcePath: string | JxDocument, opts: CompileOpti
189
201
  if (opts.serverBaseUrl !== undefined) {
190
202
  clientOptions.serverBaseUrl = opts.serverBaseUrl;
191
203
  }
204
+ if (opts.resolveClass !== undefined) {
205
+ clientOptions.resolveClass = opts.resolveClass;
206
+ }
207
+ if (opts.runtimeImports !== undefined) {
208
+ clientOptions.runtimeImports = opts.runtimeImports;
209
+ }
192
210
  return compileClient(raw, clientOptions);
193
211
  }
194
212
 
package/src/shadow.ts CHANGED
@@ -12,43 +12,16 @@
12
12
  * than usual, because a **closed** declarative shadow root is not reachable through
13
13
  * `element.shadowRoot` and hydration has to find it another way (§16.6).
14
14
  *
15
+ * The verdict itself is the runtime's (`resolveShadowMode` in `@jxsuite/runtime/css`), re-exported
16
+ * here for the compiler's callers; the CSS scope a component sheet is written under is the
17
+ * compiler's own.
18
+ *
15
19
  * @docs framework/concepts/components
16
20
  */
17
21
 
18
- import type { JxDocument, JxElement, ProjectConfig } from "@jxsuite/schema/types";
19
-
20
- /** The two modes the standard defines, or null for light DOM. */
21
- export type ShadowMode = "open" | "closed";
22
-
23
- /** A value `$shadow` or `defaults.shadow` may carry. */
24
- export type ShadowSetting = ShadowMode | false;
25
-
26
- /** Whether a document value is one of the settings `$shadow` / `defaults.shadow` may carry. */
27
- function isShadowSetting(value: unknown): value is ShadowSetting {
28
- return value === false || value === "open" || value === "closed";
29
- }
22
+ import type { ShadowMode } from "@jxsuite/runtime/css";
30
23
 
31
- /**
32
- * The shadow mode a component renders in, or null for light DOM.
33
- *
34
- * A component's own `$shadow` wins over the project default in both directions — including
35
- * `$shadow: false`, which is how one component opts _out_ of a project that opted in.
36
- *
37
- * @param {JxDocument | JxElement | null | undefined} doc - The component definition
38
- * @param {ProjectConfig["defaults"] | undefined} defaults
39
- * @returns {ShadowMode | null}
40
- */
41
- export function resolveShadowMode(
42
- doc: JxDocument | JxElement | null | undefined,
43
- defaults?: ProjectConfig["defaults"],
44
- ): ShadowMode | null {
45
- const own = doc?.$shadow;
46
- if (isShadowSetting(own)) {
47
- return own === false ? null : own;
48
- }
49
- const projectDefault = defaults?.shadow;
50
- return isShadowSetting(projectDefault) && projectDefault !== false ? projectDefault : null;
51
- }
24
+ export { resolveShadowMode, type ShadowMode, type ShadowSetting } from "@jxsuite/runtime/css";
52
25
 
53
26
  /**
54
27
  * The CSS scope prefix for a component's own rules.