@flapsdk/vault-runtime 0.1.40-next.1 → 0.1.40-next.3
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/README.md +19 -1
- package/{chunk-6HCCALXB.js → chunk-2EAXTZQO.js} +204 -3
- package/chunk-2EAXTZQO.js.map +1 -0
- package/{chunk-WINK5MYF.js → chunk-AJVSTKLX.js} +3 -3
- package/{chunk-WINK5MYF.js.map → chunk-AJVSTKLX.js.map} +1 -1
- package/{chunk-FWYBGHBX.js → chunk-WQ7WM2BC.js} +6 -3
- package/chunk-WQ7WM2BC.js.map +1 -0
- package/host-client.d.mts +1 -1
- package/host-client.js +2 -2
- package/host.d.mts +22 -5
- package/host.js +145 -3
- package/host.js.map +1 -1
- package/{hostRuntimeConfig-CukX-pP3.d.mts → hostRuntimeConfig-BnuejUgF.d.mts} +1 -1
- package/maplibre-gl-KTPWJHIW.js +26453 -0
- package/maplibre-gl-KTPWJHIW.js.map +1 -0
- package/package.json +5 -3
- package/runtime-contract.json +13 -4
- package/runtime-map/LICENSE.maplibre.txt +116 -0
- package/runtime-map/maplibre-6.15.0-worker.mjs +10 -0
- package/sdk.d.mts +10 -5
- package/sdk.js +16 -10
- package/sdk.js.map +1 -1
- package/server.d.mts +3 -3
- package/{txError-BjpNYS6Z.d.mts → txError-QcxxhHW8.d.mts} +24 -2
- package/{types-BwvSwC4U.d.mts → types-CymnHDsV.d.mts} +2 -0
- package/ui.d.mts +30 -2
- package/ui.js +1 -1
- package/chunk-6HCCALXB.js.map +0 -1
- package/chunk-FWYBGHBX.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Generated from `flap-vault-ui-template`.
|
|
|
6
6
|
|
|
7
7
|
This package is the shared runtime surface that local preview, Artifact Workbench, and `flap.sh` should agree on.
|
|
8
8
|
|
|
9
|
-
Package version: `0.1.40-next.
|
|
9
|
+
Package version: `0.1.40-next.3`. Source commit: `4bf5f3bb111993cdb9167ba18e9ec225b351c79f`.
|
|
10
10
|
|
|
11
11
|
## Exports
|
|
12
12
|
|
|
@@ -17,6 +17,24 @@ Package version: `0.1.40-next.1`. Source commit: `f9ac5edf021641f26d1c0bcce0e318
|
|
|
17
17
|
|
|
18
18
|
See `runtime-contract.json` for the machine-readable subpath contract.
|
|
19
19
|
|
|
20
|
+
## Mini App subroutes
|
|
21
|
+
|
|
22
|
+
Standalone Mini Apps use `useMiniAppRouter()` from `./sdk`. It returns
|
|
23
|
+
App-relative `pathname`, decoded `segments`, `search`, and
|
|
24
|
+
`push(path)`, `replace(path)`, `back()`. Paths start with `/`
|
|
25
|
+
inside the current App; external URLs, traversal, encoded separators and hashes
|
|
26
|
+
are rejected. Routing grants no wallet or contract access.
|
|
27
|
+
`MINI_APP_ROUTING_VERSION = 1` and `sdkFeatures.miniAppRouting = 1`
|
|
28
|
+
identify the feature. Hosts inject a `router` into `MiniAppRuntimeProvider`;
|
|
29
|
+
`./host` exports `parseMiniAppPath`, `createMiniAppMemoryRouter` and
|
|
30
|
+
`createMiniAppBrowserRouter`. Old Apps need no adapter. The new hook fails
|
|
31
|
+
explicitly if the host has not enabled routing. Deploy supporting hosts before
|
|
32
|
+
accepting new route-dependent artifacts; source-package provenance is unchanged.
|
|
33
|
+
|
|
34
|
+
## Street maps
|
|
35
|
+
|
|
36
|
+
The `./ui` export `FlapStreetMap` requires `mapCapabilities: ["street-map-v1"]` and `uiFeatures.streetMap = 1`. Hosts copy the packaged `runtime-map/maplibre-6.15.0-worker.mjs` to the exact same-origin path `/runtime-map/maplibre-6.15.0-worker.mjs`. The fixed MapLibre 6.15.0 engine is lazy bundled; there is no CDN loader, arbitrary style/URL/Worker/HTML API or automatic GPS request. Pass points, center and optional existing GPS coordinates, then handle state and supply a localized list fallback. Points are capped at 2000, zoom at 3..18. Fixed OpenFreeMap dark resources are requested without credentials; the provider sees the client IP and viewport. This direct-resource policy does not isolate redirects or guarantee upstream availability. WebGL2/Worker failure and a 15-second startup timeout show the fallback. Map-owned canvas/listeners/observers are released on unmount; MapLibre retains its page-wide shared pool, capped at two Workers, for reuse. Preserve the package Worker license and fixed attribution links. Old UI remains compatible; deployed 0.1.39 hosts do not gain this testing feature. See template docs/street-map.md and docs/street-map.zh-CN.md.
|
|
37
|
+
|
|
20
38
|
## Location and motion sensors
|
|
21
39
|
|
|
22
40
|
This release adds `useGeolocation()`, `useDeviceMotion()` and
|
|
@@ -12,6 +12,7 @@ import { createPortal } from 'react-dom';
|
|
|
12
12
|
|
|
13
13
|
var RuntimeContext = createContext(null);
|
|
14
14
|
var MiniAppContext = createContext(null);
|
|
15
|
+
var MiniAppRoutingContext = createContext(null);
|
|
15
16
|
function useFlapSdk(options) {
|
|
16
17
|
const vault = useContext(RuntimeContext);
|
|
17
18
|
const app = useContext(MiniAppContext);
|
|
@@ -1953,6 +1954,206 @@ function VideoClipSessionPlayer({ clips, label, fallback = null, className, auto
|
|
|
1953
1954
|
] });
|
|
1954
1955
|
}
|
|
1955
1956
|
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1957
|
+
// src/ui/streetMapPolicy.ts
|
|
1958
|
+
var STREET_MAP_WORKER_PATH = "/runtime-map/maplibre-6.15.0-worker.mjs";
|
|
1959
|
+
var STREET_MAP_STYLE = "https://tiles.openfreemap.org/styles/dark";
|
|
1960
|
+
var STREET_MAP_MAX_POINTS = 2e3;
|
|
1961
|
+
function validStreetMapCoordinate(value) {
|
|
1962
|
+
if (!value || typeof value !== "object") return false;
|
|
1963
|
+
const coordinate = value;
|
|
1964
|
+
return Number.isFinite(coordinate.lat) && Math.abs(coordinate.lat) <= 85.051129 && Number.isFinite(coordinate.lng) && Math.abs(coordinate.lng) <= 180;
|
|
1965
|
+
}
|
|
1966
|
+
function validStreetMapPoints(value) {
|
|
1967
|
+
if (!Array.isArray(value) || value.length > STREET_MAP_MAX_POINTS) return false;
|
|
1968
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1969
|
+
for (const point of value) {
|
|
1970
|
+
if (!validStreetMapCoordinate(point)) return false;
|
|
1971
|
+
const item = point;
|
|
1972
|
+
if (typeof item.id !== "string" || !item.id.length || item.id.length > 128 || ids.has(item.id) || typeof item.title !== "string" || item.title.length > 256 || item.rarity !== void 0 && !["common", "rare", "epic", "legendary"].includes(item.rarity)) return false;
|
|
1973
|
+
ids.add(item.id);
|
|
1974
|
+
}
|
|
1975
|
+
return true;
|
|
1976
|
+
}
|
|
1977
|
+
function streetMapZoom(value) {
|
|
1978
|
+
return value === void 0 ? 12 : Math.min(18, Math.max(3, value));
|
|
1979
|
+
}
|
|
1980
|
+
function streetMapRequest(url) {
|
|
1981
|
+
if (typeof url !== "string" || url.length > 1024) throw new Error("street-map/resource-blocked");
|
|
1982
|
+
const parsed = new URL(url);
|
|
1983
|
+
if (parsed.origin !== "https://tiles.openfreemap.org" || parsed.username || parsed.password || parsed.search || parsed.hash || /[\\\u0000-\u0020]/.test(url) || /%(?:2f|5c|2e|00)/i.test(parsed.pathname)) throw new Error("street-map/resource-blocked");
|
|
1984
|
+
const pathname = parsed.pathname;
|
|
1985
|
+
const allowed = pathname === "/styles/dark" || pathname === "/planet" || /^\/planet\/\d{8}_\d{6}_pt\/\d{1,2}\/\d{1,6}\/\d{1,6}\.pbf$/.test(pathname) || /^\/natural_earth\/ne2sr\/[0-6]\/\d{1,2}\/\d{1,2}\.png$/.test(pathname) || /^\/sprites\/ofm_[a-zA-Z0-9]{1,32}\/ofm(?:@2x)?\.(?:json|png)$/.test(pathname) || /^\/fonts\/[a-zA-Z0-9_,%+.-]{1,256}\/\d{1,7}-\d{1,7}\.pbf$/.test(pathname);
|
|
1986
|
+
if (!allowed) throw new Error("street-map/resource-blocked");
|
|
1987
|
+
return { url: parsed.href, credentials: "omit", referrerPolicy: "no-referrer" };
|
|
1988
|
+
}
|
|
1989
|
+
function streetMapPointData(points) {
|
|
1990
|
+
return { type: "FeatureCollection", features: points.map((point) => ({
|
|
1991
|
+
type: "Feature",
|
|
1992
|
+
geometry: { type: "Point", coordinates: [point.lng, point.lat] },
|
|
1993
|
+
// Titles stay React text in fallbacks. Never expose HTML or remote attribution.
|
|
1994
|
+
properties: { id: point.id, rarity: point.rarity ?? "common" }
|
|
1995
|
+
})) };
|
|
1996
|
+
}
|
|
1997
|
+
function streetMapLocationData(location) {
|
|
1998
|
+
return { type: "FeatureCollection", features: location ? [{ type: "Feature", geometry: { type: "Point", coordinates: [location.lng, location.lat] }, properties: {} }] : [] };
|
|
1999
|
+
}
|
|
2000
|
+
var EMPTY_POINTS = [];
|
|
2001
|
+
var DEFAULT_CENTER = { lat: 31.2304, lng: 121.4737 };
|
|
2002
|
+
var MAP_CSS = `.flap-street-map{position:relative;width:100%;min-height:400px;background:var(--background,#070808);overflow:hidden}.flap-street-map__canvas{position:absolute;inset:0}.flap-street-map .maplibregl-canvas{position:absolute;left:0;top:0}.flap-street-map .maplibregl-canvas-container{position:absolute;inset:0}.flap-street-map .maplibregl-interactive{cursor:grab;user-select:none;-webkit-user-select:none;touch-action:none}.flap-street-map .maplibregl-interactive:active{cursor:grabbing}.flap-street-map__fallback{position:relative;padding:16px}.flap-street-map__fallback button{display:block;text-align:left;color:inherit}.flap-street-map__attribution{position:absolute;bottom:0;right:0;z-index:1;padding:2px 5px;background:var(--background,#070808);color:var(--muted-foreground,#a3a3a3);font:10px/1.5 sans-serif}.flap-street-map__attribution a{color:inherit;text-decoration:underline}`;
|
|
2003
|
+
function FlapStreetMap({ points = EMPTY_POINTS, center, userLocation, zoom, onSelectPoint, onStateChange, fallback, className }) {
|
|
2004
|
+
const vault = React10.useContext(RuntimeContext), app = React10.useContext(MiniAppContext);
|
|
2005
|
+
const declared = (app ?? vault)?.context.manifest.mapCapabilities?.includes("street-map-v1") === true;
|
|
2006
|
+
const valid = validStreetMapPoints(points) && (center === void 0 || validStreetMapCoordinate(center)) && (userLocation == null || validStreetMapCoordinate(userLocation)) && (zoom === void 0 || Number.isFinite(zoom));
|
|
2007
|
+
const containerRef = React10.useRef(null);
|
|
2008
|
+
const mapRef = React10.useRef(null);
|
|
2009
|
+
const failRef = React10.useRef(null);
|
|
2010
|
+
const latest = React10.useRef({ points, center, userLocation, zoom, onSelectPoint, onStateChange });
|
|
2011
|
+
latest.current = { points, center, userLocation, zoom, onSelectPoint, onStateChange };
|
|
2012
|
+
const [state, setState] = React10.useState({ status: "loading" });
|
|
2013
|
+
React10.useEffect(() => {
|
|
2014
|
+
let disposed = false;
|
|
2015
|
+
let failed = false;
|
|
2016
|
+
let map = null;
|
|
2017
|
+
let resize;
|
|
2018
|
+
let timeout;
|
|
2019
|
+
let canvas;
|
|
2020
|
+
const emit = (next) => {
|
|
2021
|
+
if (disposed) return;
|
|
2022
|
+
setState(next);
|
|
2023
|
+
try {
|
|
2024
|
+
latest.current.onStateChange?.(next);
|
|
2025
|
+
} catch {
|
|
2026
|
+
console.error("FlapStreetMap onStateChange failed.");
|
|
2027
|
+
}
|
|
2028
|
+
};
|
|
2029
|
+
const cleanMap = () => {
|
|
2030
|
+
if (timeout) clearTimeout(timeout);
|
|
2031
|
+
resize?.disconnect();
|
|
2032
|
+
canvas?.removeEventListener("webglcontextlost", contextLost);
|
|
2033
|
+
if (map) {
|
|
2034
|
+
const previous = map;
|
|
2035
|
+
map = null;
|
|
2036
|
+
if (mapRef.current === previous) mapRef.current = null;
|
|
2037
|
+
previous.remove();
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
2040
|
+
const fail = (reason) => {
|
|
2041
|
+
if (disposed || failed) return;
|
|
2042
|
+
failed = true;
|
|
2043
|
+
cleanMap();
|
|
2044
|
+
emit({ status: "unavailable", reason });
|
|
2045
|
+
};
|
|
2046
|
+
const contextLost = () => fail("context-lost");
|
|
2047
|
+
failRef.current = fail;
|
|
2048
|
+
if (!declared || !valid) {
|
|
2049
|
+
emit({ status: "unavailable", reason: declared ? "invalid-input" : "not-declared" });
|
|
2050
|
+
return () => {
|
|
2051
|
+
disposed = true;
|
|
2052
|
+
if (failRef.current === fail) failRef.current = null;
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
emit({ status: "loading" });
|
|
2056
|
+
const mount = containerRef.current;
|
|
2057
|
+
let supported = typeof Worker === "function";
|
|
2058
|
+
try {
|
|
2059
|
+
const probe = document.createElement("canvas");
|
|
2060
|
+
const context = supported ? probe.getContext("webgl2") : null;
|
|
2061
|
+
supported = !!context;
|
|
2062
|
+
context?.getExtension("WEBGL_lose_context")?.loseContext();
|
|
2063
|
+
} catch {
|
|
2064
|
+
supported = false;
|
|
2065
|
+
}
|
|
2066
|
+
if (!supported || !mount) fail("unsupported");
|
|
2067
|
+
else {
|
|
2068
|
+
timeout = setTimeout(() => fail("timeout"), 15e3);
|
|
2069
|
+
void import('./maplibre-gl-KTPWJHIW.js').then((engine) => {
|
|
2070
|
+
if (disposed || failed || !containerRef.current || containerRef.current !== mount) return;
|
|
2071
|
+
engine.setWorkerUrl(STREET_MAP_WORKER_PATH);
|
|
2072
|
+
engine.setWorkerCount(2);
|
|
2073
|
+
const current = latest.current;
|
|
2074
|
+
const initial = current.center ?? current.userLocation ?? DEFAULT_CENTER;
|
|
2075
|
+
map = new engine.Map({
|
|
2076
|
+
container: mount,
|
|
2077
|
+
style: STREET_MAP_STYLE,
|
|
2078
|
+
center: [initial.lng, initial.lat],
|
|
2079
|
+
zoom: streetMapZoom(current.zoom),
|
|
2080
|
+
minZoom: 3,
|
|
2081
|
+
maxZoom: 18,
|
|
2082
|
+
attributionControl: false,
|
|
2083
|
+
maxTileCacheSize: 128,
|
|
2084
|
+
// MapLibre forwards this to fetch. Its public type currently omits the
|
|
2085
|
+
// valid Fetch credentials="omit" value; no cookie/header is provided.
|
|
2086
|
+
transformRequest: (url) => streetMapRequest(url)
|
|
2087
|
+
});
|
|
2088
|
+
mapRef.current = map;
|
|
2089
|
+
canvas = map.getCanvas();
|
|
2090
|
+
canvas.addEventListener("webglcontextlost", contextLost);
|
|
2091
|
+
map.on("error", () => fail("load-failed"));
|
|
2092
|
+
map.on("load", () => {
|
|
2093
|
+
if (disposed || failed || !map) return;
|
|
2094
|
+
try {
|
|
2095
|
+
map.addSource("flap-points", { type: "geojson", data: streetMapPointData(latest.current.points) });
|
|
2096
|
+
map.addLayer({ id: "flap-points-glow", type: "circle", source: "flap-points", paint: { "circle-radius": 14, "circle-color": "#f59e0b", "circle-opacity": 0.25, "circle-blur": 0.6 } });
|
|
2097
|
+
map.addLayer({ id: "flap-points-core", type: "circle", source: "flap-points", paint: { "circle-radius": 6, "circle-color": "#fbbf24", "circle-stroke-width": 1.5, "circle-stroke-color": "#000000" } });
|
|
2098
|
+
map.addSource("flap-location", { type: "geojson", data: streetMapLocationData(latest.current.userLocation) });
|
|
2099
|
+
map.addLayer({ id: "flap-location-dot", type: "circle", source: "flap-location", paint: { "circle-radius": 7, "circle-color": "#38bdf8", "circle-stroke-width": 2, "circle-stroke-color": "#ffffff" } });
|
|
2100
|
+
map.on("click", "flap-points-core", (event) => {
|
|
2101
|
+
const id = event.features?.[0]?.properties?.id;
|
|
2102
|
+
if (typeof id === "string" && latest.current.points.some((point) => point.id === id)) {
|
|
2103
|
+
try {
|
|
2104
|
+
latest.current.onSelectPoint?.(id);
|
|
2105
|
+
} catch {
|
|
2106
|
+
console.error("FlapStreetMap onSelectPoint failed.");
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
});
|
|
2110
|
+
if (timeout) clearTimeout(timeout);
|
|
2111
|
+
if (latest.current.center) map.jumpTo({ center: [latest.current.center.lng, latest.current.center.lat], zoom: streetMapZoom(latest.current.zoom) });
|
|
2112
|
+
else if (latest.current.zoom !== void 0) map.setZoom(streetMapZoom(latest.current.zoom));
|
|
2113
|
+
emit({ status: "ready" });
|
|
2114
|
+
} catch {
|
|
2115
|
+
fail("load-failed");
|
|
2116
|
+
}
|
|
2117
|
+
});
|
|
2118
|
+
if (typeof ResizeObserver === "function") {
|
|
2119
|
+
resize = new ResizeObserver(() => map?.resize());
|
|
2120
|
+
resize.observe(mount);
|
|
2121
|
+
}
|
|
2122
|
+
}).catch(() => fail("load-failed"));
|
|
2123
|
+
}
|
|
2124
|
+
return () => {
|
|
2125
|
+
disposed = true;
|
|
2126
|
+
if (failRef.current === fail) failRef.current = null;
|
|
2127
|
+
cleanMap();
|
|
2128
|
+
};
|
|
2129
|
+
}, [declared, valid]);
|
|
2130
|
+
React10.useEffect(() => {
|
|
2131
|
+
const map = mapRef.current;
|
|
2132
|
+
if (!valid || !map || !map.getSource("flap-points")) return;
|
|
2133
|
+
try {
|
|
2134
|
+
map.getSource("flap-points")?.setData(streetMapPointData(points));
|
|
2135
|
+
map.getSource("flap-location")?.setData(streetMapLocationData(userLocation));
|
|
2136
|
+
if (center) map.jumpTo({ center: [center.lng, center.lat], ...zoom === void 0 ? {} : { zoom: streetMapZoom(zoom) } });
|
|
2137
|
+
else if (zoom !== void 0) map.setZoom(streetMapZoom(zoom));
|
|
2138
|
+
} catch {
|
|
2139
|
+
failRef.current?.("load-failed");
|
|
2140
|
+
}
|
|
2141
|
+
}, [points, center, userLocation, zoom, valid]);
|
|
2142
|
+
const visibleState = !declared ? { status: "unavailable", reason: "not-declared" } : !valid ? { status: "unavailable", reason: "invalid-input" } : state;
|
|
2143
|
+
return /* @__PURE__ */ jsxs("div", { className: ["flap-street-map", className].filter(Boolean).join(" "), "data-flap-ui": "street-map", "data-map-state": visibleState.status, "data-map-reason": visibleState.reason, children: [
|
|
2144
|
+
/* @__PURE__ */ jsx("style", { children: MAP_CSS }),
|
|
2145
|
+
/* @__PURE__ */ jsx("div", { ref: containerRef, className: "flap-street-map__canvas", "aria-hidden": visibleState.status !== "ready", style: { visibility: visibleState.status === "ready" ? "visible" : "hidden" } }),
|
|
2146
|
+
visibleState.status !== "ready" && /* @__PURE__ */ jsx("div", { className: "flap-street-map__fallback", children: fallback ?? (validStreetMapPoints(points) ? points.map((point) => /* @__PURE__ */ jsx("button", { type: "button", onClick: () => onSelectPoint?.(point.id), children: point.title }, point.id)) : null) }),
|
|
2147
|
+
/* @__PURE__ */ jsxs("div", { className: "flap-street-map__attribution", children: [
|
|
2148
|
+
/* @__PURE__ */ jsx("a", { href: "https://openfreemap.org/", target: "_blank", rel: "noopener noreferrer", children: "OpenFreeMap" }),
|
|
2149
|
+
" \xB7 ",
|
|
2150
|
+
/* @__PURE__ */ jsx("a", { href: "https://openmaptiles.org/", target: "_blank", rel: "noopener noreferrer", children: "OpenMapTiles" }),
|
|
2151
|
+
" \xB7 ",
|
|
2152
|
+
/* @__PURE__ */ jsx("a", { href: "https://www.openstreetmap.org/copyright", target: "_blank", rel: "noopener noreferrer", children: "\xA9 OpenStreetMap" })
|
|
2153
|
+
] })
|
|
2154
|
+
] });
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
export { AddressLink, Alert, BinanceImage, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, CopyButton, Countdown, DataRow, DetailTile, ExternalLink2 as ExternalLink, FlapStreetMap, Input, IpfsBackground, IpfsImage, IpfsText, Metric, MiniAppContext, MiniAppRoutingContext, NftMetadataImage, ReviewedFrame, RuntimeContext, StatusBadge, TxButton, VaultBanner, VideoSessionPlayer, VideoSessionReadError, buttonVariants, createConsumerVideoSessionReader, readVideoSessionLength, readVideoSessionSlice, useFlapI18n, useFlapNotify, useFlapSdk, useVaultContext };
|
|
2158
|
+
//# sourceMappingURL=chunk-2EAXTZQO.js.map
|
|
2159
|
+
//# sourceMappingURL=chunk-2EAXTZQO.js.map
|