@craft-native/ts-maps

中文文档
0.0.413发布于 2026/11/01MITTypeScriptES Module零依赖构建来源已验证

Craft SDK bindings for the ts-maps interactive map runtime. Provides a cross-platform MapView component backed by the MapProvider.ts_maps variant in the Zig core.

原始使用文档
文档目录5 节
  1. Install
  2. Quick start
  3. API overview
  4. Bridge protocol
  5. Development

@craft-native/ts-maps

Craft SDK bindings for the ts-maps interactive map runtime.

This package is the TypeScript side of MapProvider.ts_maps in Craft's Zig core. Its MapView owns a DOM container and renders ts-maps inside a browser or WebView, with zero API keys. It is not the STX native Map component.

For a fully native STX screen, use Map, MapMarker, and MapPolyline. Craft renders them with MapKit on iOS and the configured native Android map provider. Android's mapProvider: 'maplibre' selects a key-free native GL view; it does not mount this package's DOM adapter.

Install

bun add @craft-native/ts-maps

Quick start

import { createMapView, defaultMapConfiguration, tsMapsProvider } from '@craft-native/ts-maps'

const view = createMapView({
  configuration: { ...defaultMapConfiguration, provider: tsMapsProvider },
  initialCamera: {
    center: { latitude: 37.7749, longitude: -122.4194 },
    zoom: 12,
    pitch: 0,
    heading: 0,
  },
  markers: [
    {
      id: 1,
      coordinate: { latitude: 37.7749, longitude: -122.4194 },
      title: 'San Francisco',
      subtitle: null,
      color: 'red',
      is_draggable: false,
      is_selected: false,
      custom_icon: null,
      anchor_x: 0.5,
      anchor_y: 1,
    },
  ],
  onTap: (coord) => console.log('tapped', coord),
  onMarkerTap: (id, coord) => console.log('marker', id, coord),
})

document.body.appendChild(view.container)

API overview

ExportWhat it is
createMapView(props)Factory returning a MapViewInstance with id, container, map, and imperative methods (setCamera, addMarker, fitToMarkers, …).
MapViewProps / MapViewInstanceTypes for the component.
Coordinate, MapRegion, MapCamera, MapMarker, …TypeScript mirrors of the structs in packages/zig/src/maps.zig. Field names match exactly so JSON round-trips are free.
craftCoordToLatLng, latLngToCraftCoord, craftRegionToBounds, craftCameraToOptions, craftMarkerToMarker, …Pure adapter functions between Craft and ts-maps types.
tsMapsProviderConstant 'ts_maps' that matches the Zig enum tag.
Everything from ts-mapsTsMap, LatLng, Marker, Polyline, marker(), tileLayer(), etc. are re-exported so you only need one import.

Bridge protocol

When running inside a Craft WebView, createMapView registers itself with getBridge() and listens for the methods declared in ./bridge-protocol:

  • setCamera, setRegion, addMarker, removeMarker, addPolyline, addPolygon, addCircle, fitToMarkers, selectMarker, deselectAll, setConfiguration.

It emits these events back:

  • map:tap, map:markerTap, map:regionChanged, map:cameraChanged.

If no bridge is available (browser-only, tests, etc.) the component silently falls back to local-only behavior — event callbacks passed via props still fire.

Development

bun run typecheck
bun test
bunx --bun pickier .

版本与发布记录

@craft-native/ts-maps 共发布 213 个版本,首次发布于 2026/05/13;过去 12 个月发布了 213 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.413latest2026/11/012 天前
0.0.4112026/10/313 天前
0.0.4102026/10/313 天前
0.0.4092026/10/313 天前
0.0.4082026/10/313 天前
0.0.3962026/10/313 天前

关于 @craft-native/ts-maps 的常见问题

@craft-native/ts-maps 是什么?

为ts-maps交互式地图运行时制作SDK绑定。提供一个由MapProvider支持的跨平台MapView组件。Zig核心中的ts_maps变量。

如何安装 @craft-native/ts-maps?

在项目目录运行 npm install @craft-native/ts-maps,或使用 pnpm add / yarn add / bun add。

@craft-native/ts-maps 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@craft-native/ts-maps 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@craft-native/ts-maps 可以商用吗?

@craft-native/ts-maps 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@craft-native/ts-maps 还在维护吗?

最新版本 0.0.413 发布于 2026/11/01(2 天前);至今共发布 213 个版本,其中过去 12 个月发布了 213 个;首次发布于 2026/05/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。