@lalalic/markcut 2.8.0 → 2.9.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/src/types/Map.tsx CHANGED
@@ -39,6 +39,15 @@ function resolveApiKey(stream: MapStream): string {
39
39
  return "";
40
40
  }
41
41
 
42
+ function resolveMapLocale(language?: string, region?: string): { language?: string; region?: string } {
43
+ if (!language) return { language: undefined, region };
44
+ const lang = language.trim().toLowerCase();
45
+ if (lang === "zh") return { language: "zh-CN", region: region ?? "CN" };
46
+ if (lang === "en") return { language: "en", region: region ?? "US" };
47
+ if (lang.startsWith("zh-")) return { language, region: region ?? "CN" };
48
+ return { language, region };
49
+ }
50
+
42
51
  // ============================================================
43
52
  // MapLeaf — entry point, renders each action as a Sequence
44
53
  // ============================================================
@@ -58,13 +67,53 @@ export function MapLeaf({ stream }: { stream: MapStream }) {
58
67
  const mapType = stream.mapType ?? "roadmap";
59
68
  const travelMode = stream.travelMode ?? "DRIVING";
60
69
  const markerEmoji = stream.routeMarker ?? "🚗";
70
+ const mapLocale = React.useMemo(
71
+ () => resolveMapLocale(stream.language, stream.region),
72
+ [stream.language, stream.region],
73
+ );
74
+ const mapLoadHandleRef = React.useRef<number | null>(null);
75
+ const mapLoadContinuedRef = React.useRef(false);
76
+
77
+ React.useEffect(() => {
78
+ mapLoadHandleRef.current = delayRender("Waiting for map tiles to load...");
79
+ mapLoadContinuedRef.current = false;
80
+
81
+ // Avoid hanging indefinitely when map tiles fail to load.
82
+ const fallbackTimer = window.setTimeout(() => {
83
+ if (!mapLoadContinuedRef.current && mapLoadHandleRef.current !== null) {
84
+ continueRender(mapLoadHandleRef.current);
85
+ mapLoadContinuedRef.current = true;
86
+ }
87
+ }, 8000);
88
+
89
+ return () => {
90
+ window.clearTimeout(fallbackTimer);
91
+ if (!mapLoadContinuedRef.current && mapLoadHandleRef.current !== null) {
92
+ continueRender(mapLoadHandleRef.current);
93
+ mapLoadContinuedRef.current = true;
94
+ }
95
+ mapLoadHandleRef.current = null;
96
+ };
97
+ }, [stream.id, start, end]);
98
+
99
+ const handleTilesLoaded = React.useCallback(() => {
100
+ if (!mapLoadContinuedRef.current && mapLoadHandleRef.current !== null) {
101
+ continueRender(mapLoadHandleRef.current);
102
+ mapLoadContinuedRef.current = true;
103
+ }
104
+ }, []);
105
+
61
106
  return (
62
107
  <Sequence
63
108
  durationInFrames={durFrames}
64
109
  from={Math.floor(fps * start)}
65
110
  layout="none"
66
111
  >
67
- <APIProvider apiKey={apiKey}>
112
+ <APIProvider
113
+ apiKey={apiKey}
114
+ language={mapLocale.language}
115
+ region={mapLocale.region}
116
+ >
68
117
  <GoogleMap
69
118
  mapId={String(stream.id ?? "map")}
70
119
  defaultCenter={center}
@@ -74,6 +123,7 @@ export function MapLeaf({ stream }: { stream: MapStream }) {
74
123
  disableDefaultUI: true,
75
124
  zoomControl: false,
76
125
  }}
126
+ onTilesLoaded={handleTilesLoaded}
77
127
  style={{ width: "100%", height: "100%", position: "absolute" }}
78
128
  >
79
129
  <RouteWithMarker
@@ -1,8 +0,0 @@
1
- {
2
- "test-photo": {
3
- "width": 64,
4
- "height": 64,
5
- "created": null,
6
- "location": null
7
- }
8
- }
@@ -1,21 +0,0 @@
1
- import { parseMarkdownDescriptive } from '../src/descriptive/markdown';
2
- import { applyStoryboardOverrides } from '../src/descriptive/resolve';
3
- import { compileDescriptiveRoot } from '../src/descriptive/compiler';
4
-
5
- const md = [
6
- '---',
7
- 'title: "My Book"',
8
- 'author: John Doe',
9
- 'keywords: dog, confidence, training',
10
- '---',
11
- '# video',
12
- 'width:1080 height:1920 fps:30',
13
- '## Test',
14
- '- image prompt:"a cat" duration:3',
15
- ].join('\n');
16
-
17
- const root = parseMarkdownDescriptive(md);
18
- console.log('rawFrontmatter:', (root as any).rawFrontmatter);
19
- const r = applyStoryboardOverrides(root, { variants: ['default'] });
20
- const c = compileDescriptiveRoot(r);
21
- console.log('data:', JSON.stringify(c.children[0].data, null, 2));