@jxsuite/compiler 1.0.0 → 1.2.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.
@@ -7,10 +7,12 @@
7
7
 
8
8
  import {
9
9
  buildAttrs,
10
+ colorSchemePrePaintScript,
10
11
  compileStyles,
11
12
  createCompileContext,
12
13
  escapeHtml,
13
14
  isNodeDynamic,
15
+ pureSchemeOf,
14
16
  resolveStaticValue,
15
17
  SELF_CLOSING,
16
18
  } from "../shared.ts";
@@ -31,6 +33,7 @@ export function compileStaticPage(
31
33
  reactivitySrc?: string;
32
34
  litHtmlSrc?: string;
33
35
  projectStyle?: JxStyle | null;
36
+ prePaintScheme?: boolean;
34
37
  [key: string]: unknown;
35
38
  },
36
39
  ) {
@@ -51,7 +54,12 @@ export function compileStaticPage(
51
54
  let moduleScripts = "";
52
55
  if (islands.length > 0) {
53
56
  for (const island of islands) {
54
- const moduleContent = emitElementModule(island.def as JxDocument, island.className, []);
57
+ const moduleContent = emitElementModule(
58
+ island.def as JxDocument,
59
+ island.className,
60
+ [],
61
+ opts.rewriteSrc as ((specifier: string) => string) | undefined,
62
+ );
55
63
  files.push({
56
64
  content: moduleContent,
57
65
  path: `_islands/${island.tagName}.js`,
@@ -73,13 +81,20 @@ export function compileStaticPage(
73
81
  .join("\n ");
74
82
  }
75
83
 
84
+ // Forced-scheme contract (spec §9.5): restore the persisted scheme before any styles apply
85
+ const prePaint =
86
+ opts.prePaintScheme !== false &&
87
+ Object.values(raw.$media ?? {}).some((q) => pureSchemeOf(String(q)) !== null)
88
+ ? `<script>${colorSchemePrePaintScript()}</script>\n `
89
+ : "";
90
+
76
91
  const html = `<!DOCTYPE html>
77
92
  <html lang="en">
78
93
  <head>
79
94
  <meta charset="utf-8">
80
95
  <meta name="viewport" content="width=device-width, initial-scale=1">
81
96
  <title>${escapeHtml(title)}</title>
82
- ${importMap}
97
+ ${prePaint}${importMap}
83
98
  ${styleBlock}
84
99
  </head>
85
100
  <body>