@jxsuite/compiler 1.4.0 → 2.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": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "description": "Jx static HTML compiler, island detector, and site builder",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -45,17 +45,19 @@
45
45
  "upgrade": "bunx npm-check-updates -u && bun install"
46
46
  },
47
47
  "dependencies": {
48
- "@apidevtools/json-schema-ref-parser": "^15.5.0",
49
- "@jxsuite/create": "^1.2.1",
50
- "@jxsuite/runtime": "^1.3.1",
51
- "@jxsuite/schema": "^1.4.0",
52
- "esbuild": "^0.28.1",
48
+ "@apidevtools/json-schema-ref-parser": "^16.0.0",
49
+ "@jxsuite/create": "^1.3.0",
50
+ "@jxsuite/runtime": "^2.0.0",
51
+ "@jxsuite/schema": "^1.6.0",
52
+ "@vue/reactivity": "3.5.41",
53
+ "esbuild": "^0.28.2",
54
+ "lit-html": "^3.3.3",
53
55
  "sharp": "^0.35.3"
54
56
  },
55
57
  "devDependencies": {
56
- "@happy-dom/global-registrator": "^20.11.1",
57
- "@jxsuite/connector": "^0.4.1",
58
- "@jxsuite/parser": "^1.4.0",
58
+ "@happy-dom/global-registrator": "^20.11.2",
59
+ "@jxsuite/connector": "^0.5.0",
60
+ "@jxsuite/parser": "^1.5.0",
59
61
  "@types/mdast": "^4.0.4"
60
62
  }
61
63
  }
package/src/compiler.ts CHANGED
@@ -130,7 +130,7 @@ export async function compile(sourcePath: string | JxDocument, opts: CompileOpti
130
130
  path: `${tagName}.js`,
131
131
  tagName,
132
132
  };
133
- const styleBlock = compileStyles(raw, raw.$media ?? {});
133
+ const styleBlock = compileStyles(raw, raw.$media ?? {}, projectStyle);
134
134
 
135
135
  const html = `<!DOCTYPE html>
136
136
  <html lang="en">
package/src/shadow.ts ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Shadow DOM, opt-in.
3
+ *
4
+ * Light DOM is the default and stays the default. It is not a placeholder for shadow DOM: a Jx
5
+ * component's styles are reachable from the page, which is how a project restyles a component it
6
+ * did not write, and the `<slot>` emulation that makes light-DOM composition work has different
7
+ * distribution semantics from real slotting. Switching a component to a shadow root changes both,
8
+ * so it is a per-component decision an author makes deliberately.
9
+ *
10
+ * `$shadow` on a component document, `defaults.shadow` on the project, `false` if neither says
11
+ * otherwise. `"open"` and `"closed"` are the standard's two modes; the difference matters more here
12
+ * than usual, because a **closed** declarative shadow root is not reachable through
13
+ * `element.shadowRoot` and hydration has to find it another way (§16.6).
14
+ *
15
+ * @docs framework/concepts/components
16
+ */
17
+
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
+ function asSetting(value: unknown): ShadowSetting | undefined {
27
+ if (value === false || value === "open" || value === "closed") {
28
+ return value;
29
+ }
30
+ return undefined;
31
+ }
32
+
33
+ /**
34
+ * The shadow mode a component renders in, or null for light DOM.
35
+ *
36
+ * A component's own `$shadow` wins over the project default in both directions — including
37
+ * `$shadow: false`, which is how one component opts _out_ of a project that opted in.
38
+ *
39
+ * @param {JxDocument | JxElement | null | undefined} doc - The component definition
40
+ * @param {ProjectConfig["defaults"] | undefined} defaults
41
+ * @returns {ShadowMode | null}
42
+ */
43
+ export function resolveShadowMode(
44
+ doc: JxDocument | JxElement | null | undefined,
45
+ defaults?: ProjectConfig["defaults"],
46
+ ): ShadowMode | null {
47
+ const own = asSetting((doc as { $shadow?: unknown } | null | undefined)?.$shadow);
48
+ const setting = own ?? asSetting(defaults?.shadow) ?? false;
49
+ return setting === false ? null : setting;
50
+ }
51
+
52
+ /**
53
+ * The CSS scope prefix for a component's own rules.
54
+ *
55
+ * In light DOM the prefix is the tag name, which is what makes `sty-card .inner` reach only that
56
+ * component's descendants. Inside a shadow root the selector cannot see the host's tag name, and
57
+ * `:host` is the standard's way to address it.
58
+ *
59
+ * @param {string} tagName
60
+ * @param {ShadowMode | null} shadow
61
+ * @returns {string}
62
+ */
63
+ export function styleScopePrefix(tagName: string, shadow: ShadowMode | null): string {
64
+ return shadow === null ? tagName : ":host";
65
+ }