tempo-sdk 0.0.4 → 0.0.6

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
@@ -42,6 +42,15 @@ interface StoryboardLayout {
42
42
  width: number;
43
43
  height: number;
44
44
  zIndex?: number;
45
+ /** Opt the storyboard wrapper's runtime size out of the legacy
46
+ * page-metadata path: when set, the wrapper sizes to whatever rect
47
+ * the storyboard's root element renders at (tracked via
48
+ * `useStoryboardRootSizeSync`) rather than to the cached `width`/
49
+ * `height` above. The cached values still drive the cold-boot
50
+ * render before the iframe captures and the layers panel size
51
+ * fields. New frames drawn via the canvas-edit-pipeline land in
52
+ * this mode by default. */
53
+ intrinsicSizing?: "root-element";
45
54
  }
46
55
  interface TempoStoryboard {
47
56
  render: () => ReactElement;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // index.ts
2
- import { realpathSync as realpathSync3, statSync as statSync2 } from "fs";
3
- import { relative } from "path";
2
+ import { existsSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
3
+ import { dirname, relative, resolve } from "path";
4
4
 
5
5
  // ../../modules/annotation/annotate-file.ts
6
6
  import { parseSync as parseSync2 } from "oxc-parser";
@@ -111,6 +111,17 @@ function annotateFile(source, filename, computeAnnotatedProps) {
111
111
  return { annotatedSource: chunks.join(""), elementsAnnotated: insertions.length, parseResult };
112
112
  }
113
113
 
114
+ // ../../modules/annotation/has-expression-children.ts
115
+ function hasJsxExpressionChild(element) {
116
+ for (const child of element.children) {
117
+ if (child.type !== "JSXExpressionContainer") continue;
118
+ const expression = child.expression;
119
+ if (!expression || expression.type === "JSXEmptyExpression") continue;
120
+ return true;
121
+ }
122
+ return false;
123
+ }
124
+
114
125
  // index.ts
115
126
  import { createFilter } from "@rollup/pluginutils";
116
127
 
@@ -681,6 +692,47 @@ function hasRootMetaTag(html) {
681
692
  function isIntrinsicElement(tagName) {
682
693
  return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
683
694
  }
695
+ var IMPORT_RESOLUTION_EXTENSIONS = [
696
+ "",
697
+ ".tsx",
698
+ ".ts",
699
+ ".jsx",
700
+ ".js",
701
+ ".mjs",
702
+ ".cjs",
703
+ ".json"
704
+ ];
705
+ function hasJsxAttribute(info, attrName) {
706
+ for (const attr of info.element.openingElement.attributes) {
707
+ const name = attr.name;
708
+ if (name?.name === attrName) return true;
709
+ }
710
+ return false;
711
+ }
712
+ function pathExistsWithCommonExtensions(basePath) {
713
+ for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
714
+ const candidate = `${basePath}${ext}`;
715
+ if (existsSync(candidate)) return true;
716
+ }
717
+ for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
718
+ const candidate = resolve(basePath, `index${ext}`);
719
+ if (existsSync(candidate)) return true;
720
+ }
721
+ return false;
722
+ }
723
+ function findMissingRelativeImport(source, importerPath) {
724
+ const importPattern = /(?:import|export)\s+(?:[\s\S]*?\s+from\s+)?["'](\.{1,2}\/[^"']+)["']/g;
725
+ let match;
726
+ while (match = importPattern.exec(source)) {
727
+ const specifier = match[1];
728
+ if (!specifier) continue;
729
+ const resolved = resolve(dirname(importerPath), specifier);
730
+ if (!pathExistsWithCommonExtensions(resolved)) {
731
+ return specifier;
732
+ }
733
+ }
734
+ return null;
735
+ }
684
736
  var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
685
737
  "area",
686
738
  "base",
@@ -752,10 +804,10 @@ function createErrorServer() {
752
804
  return server;
753
805
  }
754
806
  function readBody(req) {
755
- return new Promise((resolve, reject) => {
807
+ return new Promise((resolve2, reject) => {
756
808
  const chunks = [];
757
809
  req.on("data", (chunk) => chunks.push(chunk));
758
- req.on("end", () => resolve(Buffer.concat(chunks).toString()));
810
+ req.on("end", () => resolve2(Buffer.concat(chunks).toString()));
759
811
  req.on("error", reject);
760
812
  });
761
813
  }
@@ -806,6 +858,29 @@ function handleErrorMiddleware(errorServer, req, res, next) {
806
858
  }
807
859
  next();
808
860
  }
861
+ function parseViteInternalServerError(message) {
862
+ if (!message.includes("Internal server error:")) return null;
863
+ const lines = message.split(/\r?\n/);
864
+ const firstLine = lines.find(
865
+ (line) => line.includes("Internal server error:")
866
+ );
867
+ if (!firstLine) return null;
868
+ const fileLine = lines.find((line) => line.trim().startsWith("File:"));
869
+ const pluginLine = lines.find((line) => line.trim().startsWith("Plugin:"));
870
+ const locMatch = fileLine?.match(/File:\s*(.+?)(?::(\d+):(\d+))?\s*$/);
871
+ return {
872
+ type: "compile",
873
+ message: firstLine.replace(/^.*Internal server error:\s*/, "").trim(),
874
+ stack: message,
875
+ file: locMatch?.[1]?.trim(),
876
+ plugin: pluginLine?.replace(/^.*Plugin:\s*/, "").trim(),
877
+ loc: locMatch?.[2] && locMatch?.[3] ? {
878
+ file: locMatch[1]?.trim(),
879
+ line: Number(locMatch[2]),
880
+ column: Number(locMatch[3])
881
+ } : void 0
882
+ };
883
+ }
809
884
  function tempoVitePlugin(options = {}) {
810
885
  const enabled = !!process.env.TEMPO;
811
886
  const include = options.include === void 0 ? DEFAULT_INCLUDE : options.include;
@@ -865,6 +940,18 @@ function tempoVitePlugin(options = {}) {
865
940
  if (clientHot && clientHot !== server.ws) {
866
941
  interceptHmrSend(clientHot);
867
942
  }
943
+ if (server.config?.logger?.error) {
944
+ const originalLoggerError = server.config.logger.error.bind(
945
+ server.config.logger
946
+ );
947
+ server.config.logger.error = ((message, options2) => {
948
+ const error = parseViteInternalServerError(String(message));
949
+ if (error) {
950
+ errorServer.setError(error);
951
+ }
952
+ return originalLoggerError(message, options2);
953
+ });
954
+ }
868
955
  },
869
956
  transformIndexHtml(html) {
870
957
  if (!enabled || command !== "serve") {
@@ -897,22 +984,43 @@ function tempoVitePlugin(options = {}) {
897
984
  }
898
985
  try {
899
986
  const filepath = relative(canonicalRoot, cleanId);
987
+ const missingImport = findMissingRelativeImport(source, cleanId);
988
+ if (missingImport) {
989
+ const message = `Failed to resolve import "${missingImport}" from "${filepath}". Does the file exist?`;
990
+ errorServer.setError({
991
+ type: "compile",
992
+ message,
993
+ file: cleanId,
994
+ plugin: "vite:import-analysis"
995
+ });
996
+ } else {
997
+ errorServer.clearErrorForModules([cleanId, filepath]);
998
+ }
900
999
  const modifiedtsMs = Math.trunc(statSync2(cleanId).mtimeMs);
901
1000
  const typeInfo = typeAnalyzer?.analyzeFileTypes(cleanId, source);
902
1001
  const result = annotateFile(source, cleanId, (info) => {
903
1002
  const userProps = computeAnnotatedProps(info, filepath, modifiedtsMs);
1003
+ const dynamicChildrenProp = hasJsxExpressionChild(info.element) ? { "data-tempo-dynamic-children": true } : {};
904
1004
  if (isIntrinsicElement(info.tagName)) {
905
1005
  return {
906
1006
  ...userProps,
907
- "data-tempo-supports-children": !HTML_VOID_ELEMENTS.has(info.tagName)
1007
+ ...dynamicChildrenProp,
1008
+ "data-tempo-supports-children": hasJsxAttribute(
1009
+ info,
1010
+ "data-tempo-supports-children"
1011
+ ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
908
1012
  };
909
1013
  }
910
1014
  const support = typeInfo?.get(info.element.openingElement.start);
911
1015
  return {
912
1016
  ...userProps,
1017
+ ...dynamicChildrenProp,
913
1018
  "data-tempo-supports-style": support?.supportsStyle ?? false,
914
1019
  "data-tempo-supports-classname": support?.supportsClassName ?? false,
915
- "data-tempo-supports-children": support?.supportsChildren ?? false
1020
+ "data-tempo-supports-children": hasJsxAttribute(
1021
+ info,
1022
+ "data-tempo-supports-children"
1023
+ ) ? void 0 : support?.supportsChildren ?? false
916
1024
  };
917
1025
  });
918
1026
  if (result.elementsAnnotated === 0) {