tutuca 0.9.111 → 0.9.113

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.
@@ -4727,7 +4727,6 @@ function sizeOf(v) {
4727
4727
 
4728
4728
  class ValParser {
4729
4729
  constructor() {
4730
- this.bindValIt = new BindVal("it");
4731
4730
  this.nullConstVal = new ConstVal(null);
4732
4731
  }
4733
4732
  const(v) {
@@ -6108,7 +6107,7 @@ function parseXOp(attrs, childs, opIdx, px) {
6108
6107
  node = px.addNodeIf(RenderNode, parseXOpVal(name, value, px, vp.parseComponent), as);
6109
6108
  break;
6110
6109
  case "render-it":
6111
- node = px.addNodeIf(RenderItNode, vp.bindValIt, as);
6110
+ node = px.addNode(RenderItNode, as);
6112
6111
  break;
6113
6112
  case "render-each":
6114
6113
  node = parseRenderEach(px, value, as, attrs);
@@ -6201,7 +6200,7 @@ function parseRenderEach(px, value, as, attrs) {
6201
6200
  const seqVal = parseXOpVal("render-each", value, px, vp.parseSequence);
6202
6201
  if (seqVal === null)
6203
6202
  return null;
6204
- const renderIt = px.addNodeIf(RenderItNode, vp.bindValIt, as);
6203
+ const renderIt = px.addNode(RenderItNode, as);
6205
6204
  const attrParser = getAttrParser(px);
6206
6205
  const eachAttr = attrParser.eachAttr = attrParser.pushWrapper("each", value, seqVal);
6207
6206
  const when = attrs.getNamedItem("@when") ?? attrs.getNamedItem("when");
@@ -6288,6 +6287,12 @@ class ParseContext {
6288
6287
  }
6289
6288
  return null;
6290
6289
  }
6290
+ addNode(Class, extra) {
6291
+ const nodeId = this.nodes.length;
6292
+ const node = new Class(nodeId, null, extra);
6293
+ this.nodes.push(node);
6294
+ return node;
6295
+ }
6291
6296
  registerEvents() {
6292
6297
  const id = this.events.length;
6293
6298
  const events = new NodeEvents(id);
@@ -15219,7 +15224,7 @@ class Stack2 {
15219
15224
  return new Stack2(comps, it, binds, newDynBinds, views, viewsId, ctx);
15220
15225
  }
15221
15226
  static root(comps, it, ctx) {
15222
- const binds = [new BindFrame(it, { it }, true), null];
15227
+ const binds = [new BindFrame(it, {}, true), null];
15223
15228
  const dynBinds = [new ObjectFrame({}), null];
15224
15229
  const views = ["main", null];
15225
15230
  return new Stack2(comps, it, binds, dynBinds, views, "", ctx)._pushProvides();
@@ -17363,9 +17368,33 @@ function buildImports(base, { margauiEnabled, margauiJsUrl }) {
17363
17368
  imports.margaui = margauiJsUrl;
17364
17369
  return imports;
17365
17370
  }
17371
+ function themesBaseUrl(themeUrl) {
17372
+ return themeUrl.slice(0, themeUrl.lastIndexOf("/") + 1);
17373
+ }
17374
+ function renderNoFlashScript(themesUrl) {
17375
+ return `
17376
+ <script>
17377
+ (() => {
17378
+ const want = new URLSearchParams(location.search).get("theme");
17379
+ const name = /^[a-z]+$/.test(want ?? "")
17380
+ ? want
17381
+ : matchMedia("(prefers-color-scheme: dark)").matches
17382
+ ? "dark"
17383
+ : "light";
17384
+ document.documentElement.dataset.theme = name;
17385
+ if (name !== "light" && name !== "dark") {
17386
+ const link = document.createElement("link");
17387
+ link.rel = "stylesheet";
17388
+ link.id = "tutuca-theme-" + name;
17389
+ link.href = ${JSON.stringify(themesUrl)} + name + ".css";
17390
+ document.head.append(link);
17391
+ }
17392
+ })();
17393
+ </script>`;
17394
+ }
17366
17395
  function renderIndexHtml(imports, { margauiEnabled, margauiThemeUrl, bootstrapUrl }) {
17367
17396
  const theme = margauiEnabled ? `
17368
- <link rel="stylesheet" href="${margauiThemeUrl}" />` : "";
17397
+ <link rel="stylesheet" href="${margauiThemeUrl}" />${renderNoFlashScript(themesBaseUrl(margauiThemeUrl))}` : "";
17369
17398
  return `<!doctype html>
17370
17399
  <html lang="en">
17371
17400
  <head>
@@ -17383,7 +17412,7 @@ ${JSON.stringify({ imports }, null, 6)}
17383
17412
  </html>
17384
17413
  `;
17385
17414
  }
17386
- function renderBootstrap(devModuleUrls, { margauiEnabled, check, inspect: inspect3, noCache }) {
17415
+ function renderBootstrap(devModuleUrls, { margauiEnabled, margauiThemeUrl, check, inspect: inspect3, noCache }) {
17387
17416
  const lines = ['import { mountStorybook } from "tutuca/storybook";'];
17388
17417
  if (margauiEnabled) {
17389
17418
  lines.push('import { compileClassesToStyleText } from "tutuca/extra";');
@@ -17399,8 +17428,10 @@ function renderBootstrap(devModuleUrls, { margauiEnabled, check, inspect: inspec
17399
17428
  });
17400
17429
  const modules = devModuleUrls.map((_, i) => `m${i}`).join(", ");
17401
17430
  const optParts = [];
17402
- if (margauiEnabled)
17431
+ if (margauiEnabled) {
17403
17432
  optParts.push("compileCss: (app) => compileClassesToStyleText(app, compile)");
17433
+ optParts.push(`themes: { baseUrl: ${JSON.stringify(themesBaseUrl(margauiThemeUrl))} }`);
17434
+ }
17404
17435
  if (inspect3)
17405
17436
  optParts.push("dev: { shadowCheckComponent, runTests, expect }");
17406
17437
  if (noCache)
@@ -17612,7 +17643,13 @@ async function run5(argv, opts = {}) {
17612
17643
  margauiThemeUrl: mg2.themeUrl,
17613
17644
  bootstrapUrl: `./${bootstrapName}`
17614
17645
  }));
17615
- writeFileSync(resolve5(outDir, bootstrapName), renderBootstrap(devModuleUrls, { margauiEnabled, check, inspect: inspect3, noCache }));
17646
+ writeFileSync(resolve5(outDir, bootstrapName), renderBootstrap(devModuleUrls, {
17647
+ margauiEnabled,
17648
+ margauiThemeUrl: mg2.themeUrl,
17649
+ check,
17650
+ inspect: inspect3,
17651
+ noCache
17652
+ }));
17616
17653
  process.stdout.write(`wrote static storybook → ${relative2(process.cwd(), outDir) || "."}/
17617
17654
  index.html + ${bootstrapName} (${devModuleUrls.length} dev modules, CDN import map)
17618
17655
  Host it from the project root so /*.dev.js paths resolve.
@@ -17712,7 +17749,13 @@ async function run5(argv, opts = {}) {
17712
17749
  margauiThemeUrl: mg.themeUrl,
17713
17750
  bootstrapUrl: BOOTSTRAP_URL
17714
17751
  });
17715
- const bootstrapJs = renderBootstrap(devModuleUrls, { margauiEnabled, check, inspect: inspect3, noCache });
17752
+ const bootstrapJs = renderBootstrap(devModuleUrls, {
17753
+ margauiEnabled,
17754
+ margauiThemeUrl: mg.themeUrl,
17755
+ check,
17756
+ inspect: inspect3,
17757
+ noCache
17758
+ });
17716
17759
  const server = createServer((req, res) => {
17717
17760
  const path = req.url.split("?")[0];
17718
17761
  if (path === "/" || path === "/index.html") {
@@ -18084,6 +18127,7 @@ function extractGlobals(argv) {
18084
18127
  function dispatchKnownCommands() {
18085
18128
  return [...Object.keys(COMMANDS), ...Object.keys(NO_MODULE_COMMANDS)];
18086
18129
  }
18130
+ var DEV_BUILD_COMMANDS = new Set(["test", "storybook"]);
18087
18131
  async function main() {
18088
18132
  const { opts, rest } = extractGlobals(process.argv.slice(2));
18089
18133
  if (rest.length === 0) {
@@ -18091,6 +18135,8 @@ async function main() {
18091
18135
  return;
18092
18136
  }
18093
18137
  const command = rest[0];
18138
+ if (DEV_BUILD_COMMANDS.has(command))
18139
+ installDevBuildResolveHook();
18094
18140
  if (NO_MODULE_COMMANDS[command]) {
18095
18141
  const commandArgs2 = rest.slice(1);
18096
18142
  const args = opts.help ? [...commandArgs2, "--help"] : commandArgs2;
@@ -18124,8 +18170,6 @@ async function main() {
18124
18170
  opts.module = rest[1];
18125
18171
  commandArgs = rest.slice(2);
18126
18172
  }
18127
- if (command === "test")
18128
- installDevBuildResolveHook();
18129
18173
  try {
18130
18174
  await runCommand(cmd, commandArgs, opts);
18131
18175
  } catch (e) {
@@ -637,7 +637,6 @@ var PREDICATES = {
637
637
 
638
638
  class ValParser {
639
639
  constructor() {
640
- this.bindValIt = new BindVal("it");
641
640
  this.nullConstVal = new ConstVal(null);
642
641
  }
643
642
  const(v) {
@@ -2183,7 +2182,7 @@ function parseXOp(attrs, childs, opIdx, px) {
2183
2182
  node = px.addNodeIf(RenderNode, parseXOpVal(name, value, px, vp.parseComponent), as);
2184
2183
  break;
2185
2184
  case "render-it":
2186
- node = px.addNodeIf(RenderItNode, vp.bindValIt, as);
2185
+ node = px.addNode(RenderItNode, as);
2187
2186
  break;
2188
2187
  case "render-each":
2189
2188
  node = parseRenderEach(px, value, as, attrs);
@@ -2366,7 +2365,7 @@ function parseRenderEach(px, value, as, attrs) {
2366
2365
  const seqVal = parseXOpVal("render-each", value, px, vp.parseSequence);
2367
2366
  if (seqVal === null)
2368
2367
  return null;
2369
- const renderIt = px.addNodeIf(RenderItNode, vp.bindValIt, as);
2368
+ const renderIt = px.addNode(RenderItNode, as);
2370
2369
  const attrParser = getAttrParser(px);
2371
2370
  const eachAttr = attrParser.eachAttr = attrParser.pushWrapper("each", value, seqVal);
2372
2371
  const when = attrs.getNamedItem("@when") ?? attrs.getNamedItem("when");
@@ -2566,6 +2565,12 @@ class ParseContext {
2566
2565
  }
2567
2566
  return null;
2568
2567
  }
2568
+ addNode(Class, extra) {
2569
+ const nodeId = this.nodes.length;
2570
+ const node = new Class(nodeId, null, extra);
2571
+ this.nodes.push(node);
2572
+ return node;
2573
+ }
2569
2574
  registerEvents() {
2570
2575
  const id = this.events.length;
2571
2576
  const events = new NodeEvents(id);
@@ -6297,7 +6302,7 @@ class Stack {
6297
6302
  return new Stack(comps, it, binds, newDynBinds, views, viewsId, ctx);
6298
6303
  }
6299
6304
  static root(comps, it, ctx) {
6300
- const binds = [new BindFrame(it, { it }, true), null];
6305
+ const binds = [new BindFrame(it, {}, true), null];
6301
6306
  const dynBinds = [new ObjectFrame({}), null];
6302
6307
  const views = ["main", null];
6303
6308
  return new Stack(comps, it, binds, dynBinds, views, "", ctx)._pushProvides();
@@ -8289,7 +8289,6 @@ var PREDICATES = {
8289
8289
 
8290
8290
  class ValParser {
8291
8291
  constructor() {
8292
- this.bindValIt = new BindVal("it");
8293
8292
  this.nullConstVal = new ConstVal(null);
8294
8293
  }
8295
8294
  const(v) {
@@ -9832,7 +9831,7 @@ function parseXOp(attrs, childs, opIdx, px) {
9832
9831
  node = px.addNodeIf(RenderNode, parseXOpVal(name, value, px, vp.parseComponent), as);
9833
9832
  break;
9834
9833
  case "render-it":
9835
- node = px.addNodeIf(RenderItNode, vp.bindValIt, as);
9834
+ node = px.addNode(RenderItNode, as);
9836
9835
  break;
9837
9836
  case "render-each":
9838
9837
  node = parseRenderEach(px, value, as, attrs);
@@ -10015,7 +10014,7 @@ function parseRenderEach(px, value, as, attrs) {
10015
10014
  const seqVal = parseXOpVal("render-each", value, px, vp.parseSequence);
10016
10015
  if (seqVal === null)
10017
10016
  return null;
10018
- const renderIt = px.addNodeIf(RenderItNode, vp.bindValIt, as);
10017
+ const renderIt = px.addNode(RenderItNode, as);
10019
10018
  const attrParser = getAttrParser(px);
10020
10019
  const eachAttr = attrParser.eachAttr = attrParser.pushWrapper("each", value, seqVal);
10021
10020
  const when = attrs.getNamedItem("@when") ?? attrs.getNamedItem("when");
@@ -10215,6 +10214,12 @@ class ParseContext {
10215
10214
  }
10216
10215
  return null;
10217
10216
  }
10217
+ addNode(Class, extra) {
10218
+ const nodeId = this.nodes.length;
10219
+ const node = new Class(nodeId, null, extra);
10220
+ this.nodes.push(node);
10221
+ return node;
10222
+ }
10218
10223
  registerEvents() {
10219
10224
  const id = this.events.length;
10220
10225
  const events2 = new NodeEvents(id);
@@ -13946,7 +13951,7 @@ class Stack2 {
13946
13951
  return new Stack2(comps, it, binds, newDynBinds, views, viewsId, ctx);
13947
13952
  }
13948
13953
  static root(comps, it, ctx) {
13949
- const binds = [new BindFrame(it, { it }, true), null];
13954
+ const binds = [new BindFrame(it, {}, true), null];
13950
13955
  const dynBinds = [new ObjectFrame({}), null];
13951
13956
  const views = ["main", null];
13952
13957
  return new Stack2(comps, it, binds, dynBinds, views, "", ctx)._pushProvides();