@zwishing/emap 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -7,6 +7,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.3] - 2026-05-17
11
+
12
+ ### Fixed
13
+
14
+ - Made the browser mapshaper vendor loader prefer `window.modules` before any
15
+ bundler-injected `require` shim. This closes the remaining Vite dev
16
+ dep-optimizer failure where esbuild could make `require` truthy and trigger
17
+ `Dynamic require of "iconv-lite" is not supported` on file upload.
18
+ - Added an esbuild pre-bundle smoke test for the shipped ESM entry so this
19
+ Vite dev failure mode is covered in CI.
20
+
21
+ ## [0.1.2] - 2026-05-16
22
+
23
+ ### Fixed
24
+
25
+ - `import "@zwishing/emap"` is now self-contained in any browser bundler.
26
+ mapshaper is no longer routed through CommonJS in the ESM build (which could
27
+ emit a dead `require("adm-zip")` and a runtime-throwing `iconv-lite` helper);
28
+ it ships as a sibling ES module `dist/mapshaper-vendor.mjs` that `dist/emap.mjs`
29
+ imports by relative path. This **supersedes the 0.1.1 inlining approach** —
30
+ consumers can remove any `mapshaper`->browser alias, `Buffer` polyfill, or
31
+ band-aid tests.
32
+
33
+ ## [0.1.1] - 2026-05-16
34
+
35
+ ### Added
36
+
37
+ - Exported `MapOptions` from the package root for typed constructor options.
38
+ - Added `TopologySource.fromBytes(...)` for in-memory file and upload flows.
39
+ - Documented bundler, stylesheet, and worker asset integration for
40
+ `@zwishing/emap`.
41
+
42
+ ### Fixed
43
+
44
+ - Bundled mapshaper into the browser ESM entry so Vite/esbuild consumers no
45
+ longer need an app-level `Buffer` polyfill for local file parsing. _(Interim
46
+ approach — superseded in 0.1.2 by an externalized sibling ESM vendor.)_
47
+ - Changed `BasemapControl` to load MapLibre on demand instead of pulling it
48
+ into the root entry at import time.
49
+ - Corrected README package names and worker option examples.
50
+
10
51
  ## [0.1.0] - 2026-05-16
11
52
 
12
53
  Initial public release.
@@ -32,7 +73,10 @@ Initial public release.
32
73
  - Built-in UI controls: navigation, status, basemap, vertex edit, feature
33
74
  draw, history, box / lasso selection, simplify.
34
75
  - Distributed control stylesheet as `dist/emap.css` (importable via
35
- `emap/style.css`).
76
+ `@zwishing/emap/style.css`).
36
77
 
37
- [Unreleased]: https://github.com/zwishing/emap/compare/v0.1.0...HEAD
78
+ [Unreleased]: https://github.com/zwishing/emap/compare/v0.1.3...HEAD
79
+ [0.1.3]: https://github.com/zwishing/emap/compare/v0.1.2...v0.1.3
80
+ [0.1.2]: https://github.com/zwishing/emap/compare/v0.1.1...v0.1.2
81
+ [0.1.1]: https://github.com/zwishing/emap/compare/v0.1.0...v0.1.1
38
82
  [0.1.0]: https://github.com/zwishing/emap/releases/tag/v0.1.0
package/README.md CHANGED
@@ -18,9 +18,9 @@ A topology-oriented geographic map rendering and editing engine built around [Ma
18
18
  ## Install
19
19
 
20
20
  ```bash
21
- pnpm add emap
21
+ pnpm add @zwishing/emap
22
22
  # or
23
- npm install emap
23
+ npm install @zwishing/emap
24
24
  ```
25
25
 
26
26
  ## Hello map
@@ -29,13 +29,13 @@ npm install emap
29
29
  <!DOCTYPE html>
30
30
  <html>
31
31
  <head>
32
- <link rel="stylesheet" href="node_modules/emap/dist/emap.css" />
32
+ <link rel="stylesheet" href="node_modules/@zwishing/emap/dist/emap.css" />
33
33
  <style>#map { width: 100vw; height: 100vh; margin: 0; }</style>
34
34
  </head>
35
35
  <body>
36
36
  <div id="map"></div>
37
- <script src="node_modules/emap/dist/mapshaper-vendor.js"></script>
38
- <script src="node_modules/emap/dist/emap.js"></script>
37
+ <script src="node_modules/@zwishing/emap/dist/mapshaper-vendor.js"></script>
38
+ <script src="node_modules/@zwishing/emap/dist/emap.js"></script>
39
39
  <script>
40
40
  const { Emap, TopologySource, NavigationControl, EditToolbar } = emap;
41
41
 
@@ -56,8 +56,45 @@ npm install emap
56
56
  </html>
57
57
  ```
58
58
 
59
+ ### Bundlers
60
+
61
+ ```ts
62
+ import { Emap, TopologySource, type MapOptions } from '@zwishing/emap';
63
+ import '@zwishing/emap/style.css';
64
+
65
+ const options: MapOptions = { container: 'map' };
66
+ const map = new Emap(options);
67
+ ```
68
+
69
+ The ESM build is browser-ready and bundles the mapshaper runtime it needs, so
70
+ Vite/Webpack/Bun consumers should not need to add a `Buffer` polyfill.
71
+
72
+ `BasemapControl` loads MapLibre only when a basemap is first enabled. If you use
73
+ that control, also include MapLibre's stylesheet in your app:
74
+
75
+ ```ts
76
+ import 'maplibre-gl/dist/maplibre-gl.css';
77
+ ```
78
+
59
79
  Live demos in `test/examples/*.html` cover every feature area below.
60
80
 
81
+ ## Browser bundlers (Vite / webpack / esbuild / Bun)
82
+
83
+ `import "@zwishing/emap"` works out of the box — no `resolve.alias`, no
84
+ `Buffer` polyfill, no bundler config. mapshaper is shipped as a sibling ES
85
+ module (`dist/mapshaper-vendor.mjs`) that `dist/emap.mjs` imports by relative
86
+ path; your bundler resolves it automatically from
87
+ `node_modules/@zwishing/emap/dist/`.
88
+
89
+ ```ts
90
+ import { Emap, TopologySource } from "@zwishing/emap";
91
+ import "@zwishing/emap/style.css";
92
+ ```
93
+
94
+ The Web Worker is only needed if you opt into off-thread ops via `workerUrl`;
95
+ deploy `dist/emap-worker.js` and `dist/mapshaper-vendor.js` as same-directory
96
+ static assets then.
97
+
61
98
  ## API tour
62
99
 
63
100
  ### Core map
@@ -77,7 +114,9 @@ map.on('click', (e) => { /* … */ });
77
114
 
78
115
  ```ts
79
116
  const source = await TopologySource.fromUrl('id', url); // GeoJSON / TopoJSON / ZIP
80
- const source2 = await TopologySource.fromBytes('id', buf); // ArrayBuffer / Uint8Array
117
+ const source2 = await TopologySource.fromBytes('id', buf, {
118
+ filename: 'local.geojson',
119
+ }); // ArrayBuffer / Uint8Array
81
120
  source.getExtent();
82
121
  source.getLayers();
83
122
  ```
@@ -154,7 +193,7 @@ Vertex drags / feature translates within a session merge into one undo step. Dat
154
193
  Register validators that run after every committed edit. Failures fire `validationfailed` — the engine doesn't auto-undo, the app decides.
155
194
 
156
195
  ```ts
157
- import { topologyValidator } from 'emap';
196
+ import { topologyValidator } from '@zwishing/emap';
158
197
 
159
198
  const unregister = map.validators.register(topologyValidator({
160
199
  sources: ['china'],
@@ -205,7 +244,7 @@ Attribute-only ops (each / join / rename-fields / sort) preserve the selection a
205
244
  const map = new Emap({
206
245
  container: 'map',
207
246
  workerUrl: '/emap-worker.js', // built alongside dist/emap.js
208
- workerMode: 'auto', // 'auto' | true | false
247
+ useWorker: 'auto', // 'auto' | true | false
209
248
  workerThreshold: 200_000, // vertex count
210
249
  workerPoolSize: 2, // multiple workers (PR-22a)
211
250
  });
@@ -215,6 +254,27 @@ map.on('workerjobend', (e) => console.log('end', e.durationMs));
215
254
  ```
216
255
 
217
256
  The router classifies each op as cheap / expensive and overrides the threshold accordingly. Override the decision globally with `MapOptions.workerRouting?: (info) => boolean`.
257
+ `workerMode` is also accepted as a compatibility alias for `useWorker`; prefer `useWorker` in new code.
258
+
259
+ When worker offloading is enabled, serve both `emap-worker.js` and
260
+ `mapshaper-vendor.js` from the same directory. The worker loads the vendor file
261
+ with `importScripts('mapshaper-vendor.js')`.
262
+
263
+ ```ts
264
+ const map = new Emap({
265
+ container: 'map',
266
+ useWorker: 'auto',
267
+ workerUrl: '/vendor/emap/emap-worker.js',
268
+ });
269
+ ```
270
+
271
+ For bundler projects, copy these package files to that served directory during
272
+ your app build:
273
+
274
+ ```text
275
+ node_modules/@zwishing/emap/dist/emap-worker.js
276
+ node_modules/@zwishing/emap/dist/mapshaper-vendor.js
277
+ ```
218
278
 
219
279
  ### Snapshots
220
280