tempo-sdk 0.0.22 → 0.0.23

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/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ServerResponse, IncomingMessage } from 'node:http';
2
2
  import { FilterPattern } from '@rollup/pluginutils';
3
3
  import { Plugin } from 'vite';
4
4
  import { JSXElement } from 'oxc-parser';
5
- export { S as StoryboardLayout, T as TempoCanvasConfig, a as TempoHtmlStoryboard, b as TempoPage, c as TempoRouteStoryboard, d as TempoStoryboard } from './page-BUbHO0BI.js';
5
+ export { S as StoryboardLayout, T as TempoCanvasConfig, a as TempoHtmlStoryboard, b as TempoPage, c as TempoRouteStoryboard, d as TempoStoryboard } from './page-xi1aI5a7.js';
6
6
  import 'react';
7
7
 
8
8
  interface ElementInfo {
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
 
5
5
  // index.ts
6
6
  import {
7
+ existsSync,
7
8
  readFileSync,
8
9
  realpathSync as realpathSync2,
9
10
  statSync as statSync2,
@@ -11,6 +12,7 @@ import {
11
12
  } from "fs";
12
13
  import { createRequire } from "module";
13
14
  import { dirname, isAbsolute, join, relative as relative2, resolve } from "path";
15
+ import { fileURLToPath } from "url";
14
16
  import { createFilter } from "@rollup/pluginutils";
15
17
 
16
18
  // ../../modules/annotation/annotate-file.ts
@@ -369,6 +371,20 @@ function createRapidHotUpdateReplay(options) {
369
371
  const schedule = options?.schedule ?? setTimeout;
370
372
  const cancel = options?.cancel ?? clearTimeout;
371
373
  const bursts = /* @__PURE__ */ new Map();
374
+ const armGate = (burst, previous) => {
375
+ if (burst.eventCount < 2) return;
376
+ if (previous?.gate && previous.release) {
377
+ burst.gate = previous.gate;
378
+ burst.release = previous.release;
379
+ previous.release = void 0;
380
+ if (previous.expiry) cancel(previous.expiry);
381
+ } else {
382
+ burst.gate = new Promise((resolve2) => {
383
+ burst.release = resolve2;
384
+ });
385
+ }
386
+ burst.expiry = schedule(() => burst.release?.(), quietMs * 2);
387
+ };
372
388
  return {
373
389
  observe(file, replay) {
374
390
  const previous = bursts.get(file);
@@ -377,11 +393,17 @@ function createRapidHotUpdateReplay(options) {
377
393
  eventCount: (previous?.eventCount ?? 0) + 1,
378
394
  replay
379
395
  };
396
+ armGate(burst, previous);
380
397
  burst.timer = schedule(() => {
381
398
  if (bursts.get(file) !== burst) return;
382
399
  bursts.delete(file);
400
+ if (burst.expiry) cancel(burst.expiry);
401
+ burst.release?.();
383
402
  if (burst.eventCount < 2) return;
384
- const replayAllowance = { eventCount: -1, replay: burst.replay };
403
+ const replayAllowance = {
404
+ eventCount: -1,
405
+ replay: burst.replay
406
+ };
385
407
  replayAllowance.timer = schedule(() => {
386
408
  if (bursts.get(file) === replayAllowance) bursts.delete(file);
387
409
  }, quietMs);
@@ -390,15 +412,133 @@ function createRapidHotUpdateReplay(options) {
390
412
  }, quietMs);
391
413
  bursts.set(file, burst);
392
414
  },
415
+ settled(file) {
416
+ return bursts.get(file)?.gate ?? Promise.resolve();
417
+ },
393
418
  clear() {
394
419
  for (const burst of bursts.values()) {
395
420
  if (burst.timer) cancel(burst.timer);
421
+ if (burst.expiry) cancel(burst.expiry);
422
+ burst.release?.();
396
423
  }
397
424
  bursts.clear();
398
425
  }
399
426
  };
400
427
  }
401
428
 
429
+ // tailwind-scan-net.ts
430
+ var SCANNABLE_EXTENSIONS = /* @__PURE__ */ new Set([
431
+ "ts",
432
+ "tsx",
433
+ "js",
434
+ "jsx",
435
+ "mjs",
436
+ "cjs",
437
+ "html",
438
+ "mdx",
439
+ "md",
440
+ "svelte",
441
+ "vue",
442
+ "astro"
443
+ ]);
444
+ var IGNORED_PATH_SEGMENTS = [
445
+ "/node_modules/",
446
+ "/.git/",
447
+ "/.vite/",
448
+ "/.tempo/"
449
+ ];
450
+ var TAILWIND_SCAN_NET_DEBOUNCE_MS = 100;
451
+ var TAILWIND_SCAN_NET_MAX_POKES_PER_PAIR = 2;
452
+ var POKE_LEDGER_MAX_ENTRIES = 2e4;
453
+ function normalizeSlashes(path) {
454
+ return path.replace(/\\/g, "/");
455
+ }
456
+ function fileExtension(path) {
457
+ const base = path.slice(path.lastIndexOf("/") + 1);
458
+ const dot = base.lastIndexOf(".");
459
+ return dot <= 0 ? "" : base.slice(dot + 1).toLowerCase();
460
+ }
461
+ function isScannableSourceFile(file) {
462
+ const normalized = normalizeSlashes(file);
463
+ if (!SCANNABLE_EXTENSIONS.has(fileExtension(normalized))) return false;
464
+ return !IGNORED_PATH_SEGMENTS.some(
465
+ (segment) => normalized.includes(segment)
466
+ );
467
+ }
468
+ function isScanDep(dep) {
469
+ if (dep.includes("*")) return true;
470
+ const ext = fileExtension(normalizeSlashes(dep));
471
+ return ext !== "" && ext !== "css" && SCANNABLE_EXTENSIONS.has(ext);
472
+ }
473
+ function cssEntryNeedsRescanFor(entry, file) {
474
+ if (entry.deps === null) return false;
475
+ const normalizedFile = normalizeSlashes(file);
476
+ let scansClasses = false;
477
+ for (const dep of entry.deps) {
478
+ const normalizedDep = normalizeSlashes(dep);
479
+ if (normalizedDep === normalizedFile) return false;
480
+ if (!scansClasses && isScanDep(normalizedDep)) scansClasses = true;
481
+ }
482
+ return scansClasses;
483
+ }
484
+ function createTailwindScanNet(args) {
485
+ const debounceMs = args.debounceMs ?? TAILWIND_SCAN_NET_DEBOUNCE_MS;
486
+ const maxPokesPerPair = args.maxPokesPerPair ?? TAILWIND_SCAN_NET_MAX_POKES_PER_PAIR;
487
+ const pendingCssFiles = /* @__PURE__ */ new Set();
488
+ const pokeLedger = /* @__PURE__ */ new Map();
489
+ const countedThisWindow = /* @__PURE__ */ new Set();
490
+ let flushTimer = null;
491
+ let lastFlushAt = Number.NEGATIVE_INFINITY;
492
+ let disposed = false;
493
+ const flush = () => {
494
+ flushTimer = null;
495
+ lastFlushAt = Date.now();
496
+ countedThisWindow.clear();
497
+ const cssFiles = [...pendingCssFiles];
498
+ pendingCssFiles.clear();
499
+ for (const cssFile of cssFiles) {
500
+ args.emitChange(cssFile);
501
+ }
502
+ };
503
+ return {
504
+ handleWatcherFile(file) {
505
+ if (disposed) return false;
506
+ if (!isScannableSourceFile(file)) return false;
507
+ let scheduled = false;
508
+ for (const entry of args.listCssEntries()) {
509
+ if (!cssEntryNeedsRescanFor(entry, file)) continue;
510
+ const pairKey = `${entry.cssFile}\0${normalizeSlashes(file)}`;
511
+ if (!countedThisWindow.has(pairKey)) {
512
+ const pokes = pokeLedger.get(pairKey) ?? 0;
513
+ if (pokes >= maxPokesPerPair) continue;
514
+ if (pokeLedger.size >= POKE_LEDGER_MAX_ENTRIES) pokeLedger.clear();
515
+ pokeLedger.set(pairKey, pokes + 1);
516
+ countedThisWindow.add(pairKey);
517
+ }
518
+ pendingCssFiles.add(entry.cssFile);
519
+ scheduled = true;
520
+ }
521
+ if (scheduled && flushTimer === null) {
522
+ const sinceLastFlush = Date.now() - lastFlushAt;
523
+ const delay = sinceLastFlush >= debounceMs ? 0 : debounceMs;
524
+ flushTimer = setTimeout(flush, delay);
525
+ flushTimer.unref?.();
526
+ }
527
+ return scheduled;
528
+ },
529
+ dispose() {
530
+ disposed = true;
531
+ pendingCssFiles.clear();
532
+ pokeLedger.clear();
533
+ countedThisWindow.clear();
534
+ if (flushTimer !== null) {
535
+ clearTimeout(flushTimer);
536
+ flushTimer = null;
537
+ }
538
+ }
539
+ };
540
+ }
541
+
402
542
  // index.ts
403
543
  var DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx"];
404
544
  var DEFAULT_EXCLUDE = ["**/node_modules/**"];
@@ -406,6 +546,17 @@ var ROOT_META_NAME = "tempo-project-root";
406
546
  var SOURCE_IDENTITY_ROOT_META_NAME = "tempo-source-identity-root";
407
547
  var INTERACT_PROJECTION_CLIENT_PATH = "/@tempo/interact-projection";
408
548
  var INTERACT_PROJECTION_CLIENT_ID = "\0tempo:interact-projection";
549
+ var INTERACT_PROJECTION_SDK_SPECIFIER = "tempo-sdk/canvas/interact-projection";
550
+ function resolveOwnInteractProjectionModule() {
551
+ const selfDir = dirname(fileURLToPath(import.meta.url));
552
+ for (const candidate of [
553
+ join(selfDir, "canvas", "interact-projection.ts"),
554
+ join(selfDir, "canvas", "interact-projection.js")
555
+ ]) {
556
+ if (existsSync(candidate)) return candidate.replace(/\\/g, "/");
557
+ }
558
+ return null;
559
+ }
409
560
  var INTERACT_PROJECTION_BOOTSTRAP = `
410
561
  (function() {
411
562
  if (window.parent === window || (window.name !== ${JSON.stringify(TEMPO_INTERACT_FRAME_NAME)} && !window.name.startsWith(${JSON.stringify(`${TEMPO_INTERACT_FRAME_NAME}:`)}))) return;
@@ -749,6 +900,41 @@ function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs,
749
900
  timer.unref?.();
750
901
  server.httpServer?.once("close", () => clearInterval(timer));
751
902
  }
903
+ function installTailwindScanNet(server) {
904
+ const net = createTailwindScanNet({
905
+ listCssEntries: function* () {
906
+ const fileToModules = server.moduleGraph?.fileToModulesMap ?? /* @__PURE__ */ new Map();
907
+ for (const [file, modules] of fileToModules) {
908
+ if (!file.endsWith(".css")) continue;
909
+ for (const module of modules) {
910
+ const deps = [];
911
+ for (const imported of module.importedModules ?? []) {
912
+ const dep = imported.file ?? imported.url ?? imported.id;
913
+ if (dep) deps.push(dep);
914
+ }
915
+ yield { cssFile: file, deps };
916
+ }
917
+ }
918
+ },
919
+ emitChange: (cssFile) => {
920
+ server.config?.logger?.info?.(
921
+ `[tempo] new source file outside the Tailwind scan \u2014 re-emitting change: ${cssFile}`,
922
+ { timestamp: true }
923
+ );
924
+ server.watcher?.emit?.("change", cssFile);
925
+ }
926
+ });
927
+ const onWatcherFile = (file) => {
928
+ net.handleWatcherFile(file);
929
+ };
930
+ server.watcher?.on?.("add", onWatcherFile);
931
+ server.watcher?.on?.("change", onWatcherFile);
932
+ server.httpServer?.once("close", () => {
933
+ server.watcher?.off?.("add", onWatcherFile);
934
+ server.watcher?.off?.("change", onWatcherFile);
935
+ net.dispose();
936
+ });
937
+ }
752
938
  function tempoVitePlugin(options = {}) {
753
939
  const enabled = !!process.env.TEMPO;
754
940
  const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
@@ -772,6 +958,7 @@ function tempoVitePlugin(options = {}) {
772
958
  const rapidHotUpdateReplay = createRapidHotUpdateReplay();
773
959
  const hotUpdateMtimesMs = /* @__PURE__ */ new Map();
774
960
  const normalizedFileKey = (file) => file.replace(/\\/g, "/");
961
+ const burstKey = (file) => normalizedFileKey(fsPathFromModuleId(file));
775
962
  const recordHotUpdateCoverage = (file) => {
776
963
  const cleanFile = fsPathFromModuleId(file);
777
964
  const key = normalizedFileKey(cleanFile);
@@ -1087,6 +1274,14 @@ function tempoVitePlugin(options = {}) {
1087
1274
  if (id === INTERACT_PROJECTION_CLIENT_PATH) {
1088
1275
  return INTERACT_PROJECTION_CLIENT_ID;
1089
1276
  }
1277
+ if (id === INTERACT_PROJECTION_SDK_SPECIFIER && importer === INTERACT_PROJECTION_CLIENT_ID) {
1278
+ const resolved = await this.resolve(id, importer, {
1279
+ ...resolveOptions,
1280
+ skipSelf: true
1281
+ });
1282
+ if (resolved) return resolved;
1283
+ return resolveOwnInteractProjectionModule();
1284
+ }
1090
1285
  if (enabled && importer && !importer.startsWith("\0")) {
1091
1286
  const packageName = barePackageName(id);
1092
1287
  if (!isRelativeImportSpecifier(id) && !packageName) return null;
@@ -1105,13 +1300,21 @@ function tempoVitePlugin(options = {}) {
1105
1300
  return null;
1106
1301
  }
1107
1302
  },
1108
- load(id) {
1109
- if (id === INTERACT_PROJECTION_CLIENT_ID) {
1110
- return `let stop;
1303
+ // `order: "pre"` + a null return: this hook never loads anything of its
1304
+ // own for a project file, it only decides WHEN Vite core is allowed to
1305
+ // read it. Awaiting the burst gate here (rather than in `transform`) is
1306
+ // what makes the content terminal — by `transform` the bytes have already
1307
+ // been read, so delaying there would ship a stale revision late instead of
1308
+ // not shipping it at all.
1309
+ load: {
1310
+ order: "pre",
1311
+ async handler(id) {
1312
+ if (id === INTERACT_PROJECTION_CLIENT_ID) {
1313
+ return `let stop;
1111
1314
  let disposed = false;
1112
1315
  if (window.parent !== window && (window.name === ${JSON.stringify(TEMPO_INTERACT_FRAME_NAME)} || window.name.startsWith(${JSON.stringify(`${TEMPO_INTERACT_FRAME_NAME}:`)}))) {
1113
1316
  window.__tempoInteractProjectionOwner = "vite";
1114
- void import("tempo-sdk/canvas/interact-projection").then(({ installTempoInteractProjectionSource }) => {
1317
+ void import(${JSON.stringify(INTERACT_PROJECTION_SDK_SPECIFIER)}).then(({ installTempoInteractProjectionSource }) => {
1115
1318
  if (disposed) return;
1116
1319
  stop = installTempoInteractProjectionSource();
1117
1320
  });
@@ -1120,8 +1323,11 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1120
1323
  disposed = true;
1121
1324
  stop?.();
1122
1325
  });`;
1326
+ }
1327
+ if (!enabled || command === "build" || id.startsWith("\0")) return null;
1328
+ await rapidHotUpdateReplay.settled(burstKey(id));
1329
+ return null;
1123
1330
  }
1124
- return null;
1125
1331
  },
1126
1332
  // Expose error server for testing
1127
1333
  _tempoErrorServer: errorServer,
@@ -1177,6 +1383,12 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1177
1383
  },
1178
1384
  configureServer(server) {
1179
1385
  if (!enabled) return;
1386
+ const ownInteractModule = resolveOwnInteractProjectionModule();
1387
+ const allow = server.config?.server?.fs?.allow;
1388
+ if (ownInteractModule && Array.isArray(allow)) {
1389
+ const ownDir = dirname(ownInteractModule);
1390
+ if (!allow.includes(ownDir)) allow.push(ownDir);
1391
+ }
1180
1392
  devServer = server;
1181
1393
  syncUnresolvedImportWatcher();
1182
1394
  server.watcher?.once?.("close", closeUnresolvedImportWatchers);
@@ -1190,6 +1402,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1190
1402
  (file) => hotUpdateMtimesMs.get(normalizedFileKey(file)),
1191
1403
  () => pollCompileErrorRecovery(server)
1192
1404
  );
1405
+ installTailwindScanNet(server);
1193
1406
  const interceptHmrSend = (target) => {
1194
1407
  const orig = target.send.bind(target);
1195
1408
  target.send = ((...args) => {
@@ -1247,7 +1460,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1247
1460
  if (!enabled || this.environment.config.consumer !== "client") return;
1248
1461
  recordHotUpdateCoverage(context.file);
1249
1462
  if (context.type === "update" && context.modules.length > 0) {
1250
- rapidHotUpdateReplay.observe(context.file, () => {
1463
+ rapidHotUpdateReplay.observe(burstKey(context.file), () => {
1251
1464
  context.server.config.logger.info(
1252
1465
  `[tempo] replaying settled rapid watcher change: ${context.file}`,
1253
1466
  { timestamp: true }
@@ -1279,7 +1492,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1279
1492
  if (!enabled) return;
1280
1493
  recordHotUpdateCoverage(context.file);
1281
1494
  if (context.modules.length > 0) {
1282
- rapidHotUpdateReplay.observe(context.file, () => {
1495
+ rapidHotUpdateReplay.observe(burstKey(context.file), () => {
1283
1496
  context.server.config.logger.info(
1284
1497
  `[tempo] replaying settled rapid watcher change: ${context.file}`,
1285
1498
  { timestamp: true }