@atlas-composer/projection-loader 1.1.0-rc.12 → 1.1.0-rc.14
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 +15 -16
- package/dist/index.js +193 -134
- package/dist/index.js.map +1 -1
- package/package.json +14 -11
- package/LICENSE +0 -21
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* A pure JavaScript/TypeScript module that consumes exported composite projection
|
|
5
5
|
* configurations and creates D3-compatible projections using a plugin architecture.
|
|
6
6
|
*
|
|
7
|
-
* This package
|
|
8
|
-
*
|
|
7
|
+
* This package uses @atlas-composer/projection-core for the shared composite
|
|
8
|
+
* projection building logic. Users must register projection factories before
|
|
9
|
+
* loading configurations.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```typescript
|
|
@@ -28,48 +29,46 @@
|
|
|
28
29
|
*
|
|
29
30
|
* Note: D3 projections use getter/setter pattern where calling without
|
|
30
31
|
* arguments returns the current value, and with arguments sets and returns this.
|
|
31
|
-
* We use 'any' for setter return types to maintain compatibility with D3's
|
|
32
|
-
* projection types that return their specific projection type (e.g., GeoConicProjection).
|
|
33
32
|
*/
|
|
34
33
|
interface ProjectionLike {
|
|
35
34
|
(coordinates: [number, number]): [number, number] | null;
|
|
36
35
|
center?: {
|
|
37
36
|
(): [number, number];
|
|
38
|
-
(center: [number, number]):
|
|
37
|
+
(center: [number, number]): ProjectionLike;
|
|
39
38
|
};
|
|
40
39
|
rotate?: {
|
|
41
40
|
(): [number, number, number];
|
|
42
|
-
(angles: [number, number, number]):
|
|
41
|
+
(angles: [number, number, number]): ProjectionLike;
|
|
43
42
|
};
|
|
44
43
|
parallels?: {
|
|
45
44
|
(): [number, number];
|
|
46
|
-
(parallels: [number, number]):
|
|
45
|
+
(parallels: [number, number]): ProjectionLike;
|
|
47
46
|
};
|
|
48
47
|
scale?: {
|
|
49
48
|
(): number;
|
|
50
|
-
(scale: number):
|
|
49
|
+
(scale: number): ProjectionLike;
|
|
51
50
|
};
|
|
52
51
|
translate?: {
|
|
53
52
|
(): [number, number];
|
|
54
|
-
(translate: [number, number]):
|
|
53
|
+
(translate: [number, number]): ProjectionLike;
|
|
55
54
|
};
|
|
56
55
|
clipExtent?: {
|
|
57
56
|
(): [[number, number], [number, number]] | null;
|
|
58
|
-
(extent: [[number, number], [number, number]] | null):
|
|
57
|
+
(extent: [[number, number], [number, number]] | null): ProjectionLike;
|
|
59
58
|
};
|
|
60
59
|
clipAngle?: {
|
|
61
60
|
(): number;
|
|
62
|
-
(angle: number):
|
|
61
|
+
(angle: number): ProjectionLike;
|
|
63
62
|
};
|
|
64
63
|
stream?: (stream: StreamLike) => StreamLike;
|
|
65
64
|
precision?: {
|
|
66
65
|
(): number;
|
|
67
|
-
(precision: number):
|
|
66
|
+
(precision: number): ProjectionLike;
|
|
68
67
|
};
|
|
69
|
-
fitExtent?: (extent: [[number, number], [number, number]], object: any) =>
|
|
70
|
-
fitSize?: (size: [number, number], object: any) =>
|
|
71
|
-
fitWidth?: (width: number, object: any) =>
|
|
72
|
-
fitHeight?: (height: number, object: any) =>
|
|
68
|
+
fitExtent?: (extent: [[number, number], [number, number]], object: any) => ProjectionLike;
|
|
69
|
+
fitSize?: (size: [number, number], object: any) => ProjectionLike;
|
|
70
|
+
fitWidth?: (width: number, object: any) => ProjectionLike;
|
|
71
|
+
fitHeight?: (height: number, object: any) => ProjectionLike;
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
75
74
|
* Stream protocol interface for D3 geographic transforms
|
package/dist/index.js
CHANGED
|
@@ -1,100 +1,76 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
projectionRegistry.set(id, factory);
|
|
5
|
-
}
|
|
6
|
-
function registerProjections(factories) {
|
|
7
|
-
for (const [id, factory] of Object.entries(factories)) {
|
|
8
|
-
registerProjection(id, factory);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function unregisterProjection(id) {
|
|
12
|
-
return projectionRegistry.delete(id);
|
|
13
|
-
}
|
|
14
|
-
function clearProjections() {
|
|
15
|
-
projectionRegistry.clear();
|
|
1
|
+
// ../projection-core/dist/index.js
|
|
2
|
+
function isPointInBounds(lon, lat, bounds, tolerance = 0) {
|
|
3
|
+
return lon >= bounds.minLon - tolerance && lon <= bounds.maxLon + tolerance && lat >= bounds.minLat - tolerance && lat <= bounds.maxLat + tolerance;
|
|
16
4
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
5
|
+
function boundsFromArray(bounds) {
|
|
6
|
+
return {
|
|
7
|
+
minLon: bounds[0][0],
|
|
8
|
+
minLat: bounds[0][1],
|
|
9
|
+
maxLon: bounds[1][0],
|
|
10
|
+
maxLat: bounds[1][1]
|
|
11
|
+
};
|
|
19
12
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
13
|
+
function calculateClipExtentFromPixelOffset(center, pixelClipExtent, epsilon = 1e-6) {
|
|
14
|
+
const [x1, y1, x2, y2] = pixelClipExtent;
|
|
15
|
+
return [
|
|
16
|
+
[center[0] + x1 + epsilon, center[1] + y1 + epsilon],
|
|
17
|
+
[center[0] + x2 - epsilon, center[1] + y2 - epsilon]
|
|
18
|
+
];
|
|
22
19
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
throw new Error(`Unsupported configuration version: ${config.version}`);
|
|
27
|
-
}
|
|
28
|
-
if (!config.territories || config.territories.length === 0) {
|
|
29
|
-
throw new Error("Configuration must contain at least one territory");
|
|
20
|
+
function normalizeBounds(bounds) {
|
|
21
|
+
if ("minLon" in bounds) {
|
|
22
|
+
return bounds;
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
console.log("[CompositeProjection] Created sub-projections:", {
|
|
41
|
-
territories: config.territories.map((t) => ({ code: t.code, name: t.name })),
|
|
42
|
-
count: subProjections.length
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
let capturedPoint = null;
|
|
46
|
-
const pointStream = {
|
|
47
|
-
point: (x, y) => {
|
|
48
|
-
capturedPoint = [x, y];
|
|
49
|
-
},
|
|
50
|
-
lineStart: () => {
|
|
51
|
-
},
|
|
52
|
-
lineEnd: () => {
|
|
53
|
-
},
|
|
54
|
-
polygonStart: () => {
|
|
55
|
-
},
|
|
56
|
-
polygonEnd: () => {
|
|
57
|
-
},
|
|
58
|
-
sphere: () => {
|
|
24
|
+
return boundsFromArray(bounds);
|
|
25
|
+
}
|
|
26
|
+
function invertWithBoundsValidation(screenCoords, entries, options = {}) {
|
|
27
|
+
const { tolerance = 0.01, debug = false } = options;
|
|
28
|
+
const [x, y] = screenCoords;
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
const { projection, bounds, id } = entry;
|
|
31
|
+
if (!projection.invert) {
|
|
32
|
+
continue;
|
|
59
33
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const [lon, lat] = coordinates;
|
|
72
|
-
capturedPoint = null;
|
|
73
|
-
for (const { subProj, stream } of subProjPoints) {
|
|
74
|
-
if (subProj.bounds) {
|
|
75
|
-
const [[minLon, minLat], [maxLon, maxLat]] = subProj.bounds;
|
|
76
|
-
if (lon >= minLon && lon <= maxLon && lat >= minLat && lat <= maxLat) {
|
|
77
|
-
stream.point(lon, lat);
|
|
78
|
-
if (capturedPoint) {
|
|
79
|
-
return capturedPoint;
|
|
34
|
+
try {
|
|
35
|
+
const result = projection.invert([x, y]);
|
|
36
|
+
if (!result || !Array.isArray(result) || result.length < 2) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const [lon, lat] = result;
|
|
40
|
+
if (bounds) {
|
|
41
|
+
const geoBounds = normalizeBounds(bounds);
|
|
42
|
+
if (isPointInBounds(lon, lat, geoBounds, tolerance)) {
|
|
43
|
+
if (debug) {
|
|
44
|
+
console.log(`[Invert] Matched ${id}: [${x}, ${y}] -> [${lon}, ${lat}]`);
|
|
80
45
|
}
|
|
46
|
+
return { coordinates: result, territoryId: id };
|
|
47
|
+
} else if (debug) {
|
|
48
|
+
console.log(`[Invert] Rejected ${id}: [${lon}, ${lat}] outside bounds`);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
if (debug) {
|
|
52
|
+
console.log(`[Invert] No bounds for ${id}, accepting [${lon}, ${lat}]`);
|
|
81
53
|
}
|
|
54
|
+
return { coordinates: result, territoryId: id };
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (debug) {
|
|
58
|
+
console.warn(`[Invert] Error in ${id}:`, error);
|
|
82
59
|
}
|
|
83
60
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
}
|
|
62
|
+
if (debug) {
|
|
63
|
+
console.log(`[Invert] Failed to invert [${x}, ${y}]`);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function createStreamMultiplexer(projections) {
|
|
68
|
+
return (stream) => {
|
|
69
|
+
const streams = projections.map((p) => p.stream(stream));
|
|
88
70
|
return {
|
|
89
71
|
point: (x, y) => {
|
|
90
72
|
for (const s of streams) s.point(x, y);
|
|
91
73
|
},
|
|
92
|
-
sphere: () => {
|
|
93
|
-
for (const s of streams) {
|
|
94
|
-
if (s.sphere)
|
|
95
|
-
s.sphere();
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
74
|
lineStart: () => {
|
|
99
75
|
for (const s of streams) s.lineStart();
|
|
100
76
|
},
|
|
@@ -106,64 +82,149 @@ function loadCompositeProjection(config, options) {
|
|
|
106
82
|
},
|
|
107
83
|
polygonEnd: () => {
|
|
108
84
|
for (const s of streams) s.polygonEnd();
|
|
85
|
+
},
|
|
86
|
+
sphere: () => {
|
|
87
|
+
for (const s of streams) {
|
|
88
|
+
if (s.sphere)
|
|
89
|
+
s.sphere();
|
|
90
|
+
}
|
|
109
91
|
}
|
|
110
92
|
};
|
|
111
93
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
}
|
|
95
|
+
function createPointCaptureStream() {
|
|
96
|
+
let capturedPoint = null;
|
|
97
|
+
const pointStream = {
|
|
98
|
+
point: (x, y) => {
|
|
99
|
+
capturedPoint = [x, y];
|
|
100
|
+
},
|
|
101
|
+
lineStart: () => {
|
|
102
|
+
},
|
|
103
|
+
lineEnd: () => {
|
|
104
|
+
},
|
|
105
|
+
polygonStart: () => {
|
|
106
|
+
},
|
|
107
|
+
polygonEnd: () => {
|
|
108
|
+
},
|
|
109
|
+
sphere: () => {
|
|
115
110
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
pointStream,
|
|
114
|
+
getCapturedPoint: () => capturedPoint,
|
|
115
|
+
resetCapture: () => {
|
|
116
|
+
capturedPoint = null;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function normalizeBounds2(bounds) {
|
|
121
|
+
if ("minLon" in bounds) {
|
|
122
|
+
return bounds;
|
|
123
|
+
}
|
|
124
|
+
return boundsFromArray(bounds);
|
|
125
|
+
}
|
|
126
|
+
function buildCompositeProjection(config) {
|
|
127
|
+
const { entries, debug = false } = config;
|
|
128
|
+
if (entries.length === 0) {
|
|
129
|
+
throw new Error("Cannot build composite projection with no entries");
|
|
130
|
+
}
|
|
131
|
+
const { pointStream, getCapturedPoint, resetCapture } = createPointCaptureStream();
|
|
132
|
+
const entryStreams = entries.map((entry) => ({
|
|
133
|
+
entry,
|
|
134
|
+
stream: entry.projection.stream(pointStream)
|
|
135
|
+
}));
|
|
136
|
+
const project = (coordinates) => {
|
|
137
|
+
const [lon, lat] = coordinates;
|
|
138
|
+
resetCapture();
|
|
139
|
+
for (const { entry, stream } of entryStreams) {
|
|
140
|
+
if (entry.bounds) {
|
|
141
|
+
const bounds = normalizeBounds2(entry.bounds);
|
|
142
|
+
if (isPointInBounds(lon, lat, bounds)) {
|
|
143
|
+
stream.point(lon, lat);
|
|
144
|
+
const captured = getCapturedPoint();
|
|
145
|
+
if (captured) {
|
|
146
|
+
return captured;
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
|
-
if (debug) {
|
|
149
|
-
console.log(`[Invert] Failed to invert coordinates [${x}, ${y}]`);
|
|
150
|
-
}
|
|
151
151
|
return null;
|
|
152
152
|
};
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const composite = project;
|
|
154
|
+
composite.stream = createStreamMultiplexer(entries.map((e) => e.projection));
|
|
155
|
+
composite.invert = (coords) => {
|
|
156
|
+
const result = invertWithBoundsValidation(coords, entries, { debug });
|
|
157
|
+
return (result == null ? void 0 : result.coordinates) ?? null;
|
|
158
|
+
};
|
|
159
|
+
composite.scale = function(_s) {
|
|
160
|
+
var _a;
|
|
155
161
|
if (arguments.length === 0) {
|
|
156
|
-
return
|
|
162
|
+
return ((_a = entries[0]) == null ? void 0 : _a.projection.scale()) ?? 1;
|
|
157
163
|
}
|
|
158
|
-
return
|
|
164
|
+
return composite;
|
|
159
165
|
};
|
|
160
|
-
|
|
166
|
+
composite.translate = function(_t) {
|
|
167
|
+
var _a;
|
|
161
168
|
if (arguments.length === 0) {
|
|
162
|
-
return [
|
|
169
|
+
return ((_a = entries[0]) == null ? void 0 : _a.projection.translate()) ?? [0, 0];
|
|
163
170
|
}
|
|
164
|
-
return
|
|
171
|
+
return composite;
|
|
165
172
|
};
|
|
166
|
-
return
|
|
173
|
+
return composite;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/standalone-projection-loader.ts
|
|
177
|
+
var projectionRegistry = /* @__PURE__ */ new Map();
|
|
178
|
+
function registerProjection(id, factory) {
|
|
179
|
+
projectionRegistry.set(id, factory);
|
|
180
|
+
}
|
|
181
|
+
function registerProjections(factories) {
|
|
182
|
+
for (const [id, factory] of Object.entries(factories)) {
|
|
183
|
+
registerProjection(id, factory);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function unregisterProjection(id) {
|
|
187
|
+
return projectionRegistry.delete(id);
|
|
188
|
+
}
|
|
189
|
+
function clearProjections() {
|
|
190
|
+
projectionRegistry.clear();
|
|
191
|
+
}
|
|
192
|
+
function getRegisteredProjections() {
|
|
193
|
+
return Array.from(projectionRegistry.keys());
|
|
194
|
+
}
|
|
195
|
+
function isProjectionRegistered(id) {
|
|
196
|
+
return projectionRegistry.has(id);
|
|
197
|
+
}
|
|
198
|
+
function loadCompositeProjection(config, options) {
|
|
199
|
+
const { width, height, debug = false } = options;
|
|
200
|
+
if (config.version !== "1.0") {
|
|
201
|
+
throw new Error(`Unsupported configuration version: ${config.version}`);
|
|
202
|
+
}
|
|
203
|
+
if (!config.territories || config.territories.length === 0) {
|
|
204
|
+
throw new Error("Configuration must contain at least one territory");
|
|
205
|
+
}
|
|
206
|
+
const entries = config.territories.map((territory) => {
|
|
207
|
+
const proj = createSubProjection(territory, width, height, config.referenceScale, debug);
|
|
208
|
+
return {
|
|
209
|
+
id: territory.code,
|
|
210
|
+
name: territory.name,
|
|
211
|
+
projection: proj,
|
|
212
|
+
bounds: {
|
|
213
|
+
minLon: territory.bounds[0][0],
|
|
214
|
+
minLat: territory.bounds[0][1],
|
|
215
|
+
maxLon: territory.bounds[1][0],
|
|
216
|
+
maxLat: territory.bounds[1][1]
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
if (debug) {
|
|
221
|
+
console.log("[CompositeProjection] Created sub-projections:", {
|
|
222
|
+
territories: config.territories.map((t) => ({ code: t.code, name: t.name })),
|
|
223
|
+
count: entries.length
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const composite = buildCompositeProjection({ entries, debug });
|
|
227
|
+
return composite;
|
|
167
228
|
}
|
|
168
229
|
function createSubProjection(territory, width, height, referenceScale, debug) {
|
|
169
230
|
var _a, _b, _c;
|
|
@@ -212,18 +273,16 @@ function createSubProjection(territory, width, height, referenceScale, debug) {
|
|
|
212
273
|
]);
|
|
213
274
|
}
|
|
214
275
|
if (layout.pixelClipExtent && projection.clipExtent) {
|
|
215
|
-
const [x1, y1, x2, y2] = layout.pixelClipExtent;
|
|
216
|
-
const epsilon = 1e-6;
|
|
217
276
|
const territoryCenter = ((_a = projection.translate) == null ? void 0 : _a.call(projection)) || [width / 2, height / 2];
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
projection.clipExtent(
|
|
277
|
+
const clipExtent = calculateClipExtentFromPixelOffset(
|
|
278
|
+
territoryCenter,
|
|
279
|
+
layout.pixelClipExtent
|
|
280
|
+
);
|
|
281
|
+
projection.clipExtent(clipExtent);
|
|
223
282
|
if (debug) {
|
|
224
283
|
console.log(
|
|
225
284
|
`[Clipping] Applied pixelClipExtent for ${territory.code}:`,
|
|
226
|
-
`original:
|
|
285
|
+
`original: ${JSON.stringify(layout.pixelClipExtent)} -> transformed: ${JSON.stringify(clipExtent)}`
|
|
227
286
|
);
|
|
228
287
|
}
|
|
229
288
|
} else if (projection.clipExtent) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/stand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AA,CAAU,SAAS,CAAC,CAAA,CAAE,CAAA;AAAA,IACzF;AAGA,IAAA,IAAI,CAAC,SAAA,CAAU,UAAA,IAAc,CAAC,SAAA,CAAU,WAAW,EAAA,IAAM,CAAC,SAAA,CAAU,UAAA,CAAW,UAAA,EAAY;AACzF,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,UAAA,EAAa,SAAA,CAAU,IAAI,CAAA,oFAAA,CAAsF,CAAA;AAAA,IACnI;AAEA,IAAA,IAAI,CAAC,UAAU,MAAA,EAAQ;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,UAAA,EAAa,SAAA,CAAU,IAAI,CAAA,eAAA,CAAiB,CAAA;AAAA,IAC9D;AAAA,EACF;AAEA,EAAA,OAAO,IAAA;AACT;AAkBO,SAAS,YAAA,CACd,YACA,OAAA,EACgB;AAChB,EAAA,IAAI,MAAA;AAEJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAA,CAAK,MAAM,UAAU,CAAA;AAAA,EAChC,SACO,KAAA,EAAO;AACZ,IAAA,MAAM,IAAI,MAAM,CAAA,cAAA,EAAiB,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAe,CAAA,CAAE,CAAA;AAAA,EAC7F;AAEA,EAAA,cAAA,CAAe,MAAM,CAAA;AACrB,EAAA,OAAO,uBAAA,CAAwB,QAAQ,OAAO,CAAA;AAChD","file":"index.js","sourcesContent":["/**\n * Standalone Composite Projection Loader (Zero Dependencies)\n *\n * A pure JavaScript/TypeScript module that consumes exported composite projection\n * configurations and creates D3-compatible projections using a plugin architecture.\n *\n * This package has ZERO dependencies. Users must register projection factories\n * before loading configurations.\n *\n * @example\n * ```typescript\n * // Register projections first\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from './standalone-projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Then load your configuration\n * const projection = loadCompositeProjection(config, { width: 800, height: 600 })\n * ```\n *\n * @packageDocumentation\n */\n\n/**\n * Generic projection-like interface that matches D3 projections\n * without requiring d3-geo as a dependency\n *\n * Note: D3 projections use getter/setter pattern where calling without\n * arguments returns the current value, and with arguments sets and returns this.\n * We use 'any' for setter return types to maintain compatibility with D3's\n * projection types that return their specific projection type (e.g., GeoConicProjection).\n */\nexport interface ProjectionLike {\n (coordinates: [number, number]): [number, number] | null\n center?: {\n (): [number, number]\n (center: [number, number]): any\n }\n rotate?: {\n (): [number, number, number]\n (angles: [number, number, number]): any\n }\n parallels?: {\n (): [number, number]\n (parallels: [number, number]): any\n }\n scale?: {\n (): number\n (scale: number): any\n }\n translate?: {\n (): [number, number]\n (translate: [number, number]): any\n }\n clipExtent?: {\n (): [[number, number], [number, number]] | null\n (extent: [[number, number], [number, number]] | null): any\n }\n clipAngle?: {\n (): number\n (angle: number): any\n }\n stream?: (stream: StreamLike) => StreamLike\n precision?: {\n (): number\n (precision: number): any\n }\n fitExtent?: (extent: [[number, number], [number, number]], object: any) => any\n fitSize?: (size: [number, number], object: any) => any\n fitWidth?: (width: number, object: any) => any\n fitHeight?: (height: number, object: any) => any\n}\n\n/**\n * Stream protocol interface for D3 geographic transforms\n */\nexport interface StreamLike {\n point: (x: number, y: number) => void\n lineStart: () => void\n lineEnd: () => void\n polygonStart: () => void\n polygonEnd: () => void\n sphere?: () => void\n}\n\n/**\n * Factory function that creates a projection instance\n */\nexport type ProjectionFactory = () => ProjectionLike\n\n/**\n * Exported configuration format (subset needed for loading)\n */\nexport interface ExportedConfig {\n version: string\n metadata: {\n atlasId: string\n atlasName: string\n exportDate?: string\n createdWith?: string\n notes?: string\n }\n pattern: string\n referenceScale?: number\n canvasDimensions?: {\n width: number\n height: number\n }\n territories: Territory[]\n}\n\nexport interface Territory {\n code: string\n name: string\n role: string\n projection: {\n id: string\n family: string\n parameters: ProjectionParameters\n }\n layout: Layout\n bounds: [[number, number], [number, number]]\n}\n\nexport interface ProjectionParameters {\n center?: [number, number]\n rotate?: [number, number, number]\n scaleMultiplier?: number\n parallels?: [number, number]\n clipAngle?: number\n precision?: number\n}\n\nexport interface Layout {\n translateOffset?: [number, number]\n /** Pixel-based clip extent relative to territory center [x1, y1, x2, y2] */\n pixelClipExtent?: [number, number, number, number] | null\n}\n\n/**\n * Options for creating the composite projection\n */\nexport interface LoaderOptions {\n /** Canvas width in pixels */\n width: number\n /** Canvas height in pixels */\n height: number\n /** Whether to apply clipping to territories (default: true) */\n enableClipping?: boolean\n /** Debug mode - logs territory selection (default: false) */\n debug?: boolean\n}\n\n/**\n * Runtime registry for projection factories\n * Users must register projections before loading configurations\n */\nconst projectionRegistry = new Map<string, ProjectionFactory>()\n\n/**\n * Register a projection factory with a given ID\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection } from '@atlas-composer/projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n * ```\n *\n * @param id - Projection identifier (e.g., 'mercator', 'albers')\n * @param factory - Function that creates a new projection instance\n */\nexport function registerProjection(id: string, factory: ProjectionFactory): void {\n projectionRegistry.set(id, factory)\n}\n\n/**\n * Register multiple projections at once\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjections } from '@atlas-composer/projection-loader'\n *\n * registerProjections({\n * 'mercator': () => d3.geoMercator(),\n * 'albers': () => d3.geoAlbers(),\n * 'conic-equal-area': () => d3.geoConicEqualArea()\n * })\n * ```\n *\n * @param factories - Object mapping projection IDs to factory functions\n */\nexport function registerProjections(factories: Record<string, ProjectionFactory>): void {\n for (const [id, factory] of Object.entries(factories)) {\n registerProjection(id, factory)\n }\n}\n\n/**\n * Unregister a projection\n *\n * @param id - Projection identifier to remove\n * @returns True if the projection was removed, false if it wasn't registered\n */\nexport function unregisterProjection(id: string): boolean {\n return projectionRegistry.delete(id)\n}\n\n/**\n * Clear all registered projections\n */\nexport function clearProjections(): void {\n projectionRegistry.clear()\n}\n\n/**\n * Get list of currently registered projection IDs\n *\n * @returns Array of registered projection identifiers\n */\nexport function getRegisteredProjections(): string[] {\n return Array.from(projectionRegistry.keys())\n}\n\n/**\n * Check if a projection is registered\n *\n * @param id - Projection identifier to check\n * @returns True if the projection is registered\n */\nexport function isProjectionRegistered(id: string): boolean {\n return projectionRegistry.has(id)\n}\n\n/**\n * Create a minimal projection wrapper (similar to d3.geoProjection)\n * This allows us to avoid the d3-geo dependency\n */\n\n/**\n * Create a D3-compatible projection from an exported composite projection configuration\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Load configuration\n * const config = JSON.parse(jsonString)\n *\n * // Create projection\n * const projection = loadCompositeProjection(config, {\n * width: 800,\n * height: 600\n * })\n *\n * // Use with D3\n * const path = d3.geoPath(projection)\n * svg.selectAll('path')\n * .data(countries.features)\n * .join('path')\n * .attr('d', path)\n * ```\n *\n * @param config - Exported composite projection configuration\n * @param options - Canvas dimensions and options\n * @returns D3-compatible projection that routes geometry to appropriate sub-projections\n */\nexport function loadCompositeProjection(\n config: ExportedConfig,\n options: LoaderOptions,\n): ProjectionLike {\n const { width, height, debug = false } = options\n\n // Validate configuration version\n if (config.version !== '1.0') {\n throw new Error(`Unsupported configuration version: ${config.version}`)\n }\n\n if (!config.territories || config.territories.length === 0) {\n throw new Error('Configuration must contain at least one territory')\n }\n\n // Create sub-projections for each territory\n const subProjections = config.territories.map((territory) => {\n const proj = createSubProjection(territory, width, height, config.referenceScale, debug)\n\n return {\n territory,\n projection: proj,\n bounds: territory.bounds,\n }\n })\n\n if (debug) {\n console.log('[CompositeProjection] Created sub-projections:', {\n territories: config.territories.map(t => ({ code: t.code, name: t.name })),\n count: subProjections.length,\n })\n }\n\n // Point capture mechanism (like Atlas Composer's CompositeProjection)\n let capturedPoint: [number, number] | null = null\n const pointStream = {\n point: (x: number, y: number) => {\n capturedPoint = [x, y]\n },\n lineStart: () => {},\n lineEnd: () => {},\n polygonStart: () => {},\n polygonEnd: () => {},\n sphere: () => {},\n }\n\n // Create point capture for each sub-projection\n const subProjPoints = subProjections.map(subProj => ({\n subProj: {\n territoryCode: subProj.territory.code,\n territoryName: subProj.territory.name,\n bounds: subProj.bounds,\n projection: subProj.projection,\n },\n stream: subProj.projection.stream(pointStream),\n }))\n\n // Main projection function (like Atlas Composer's CompositeProjection)\n const compositeProjection = (coordinates: [number, number]): [number, number] | null => {\n const [lon, lat] = coordinates\n\n capturedPoint = null\n\n // Try each sub-projection's bounds\n for (const { subProj, stream } of subProjPoints) {\n if (subProj.bounds) {\n const [[minLon, minLat], [maxLon, maxLat]] = subProj.bounds\n\n if (lon >= minLon && lon <= maxLon && lat >= minLat && lat <= maxLat) {\n // Project through stream (offset already applied in projection.translate)\n stream.point(lon, lat)\n\n if (capturedPoint) {\n return capturedPoint\n }\n }\n }\n }\n\n // No match found\n return null\n }\n\n // Multiplex stream (like Atlas Composer's CompositeProjection)\n ;(compositeProjection as any).stream = (stream: any) => {\n const streams = subProjections.map(sp => sp.projection.stream(stream))\n return {\n point: (x: number, y: number) => {\n for (const s of streams) s.point(x, y)\n },\n sphere: () => {\n for (const s of streams) {\n if (s.sphere)\n s.sphere()\n }\n },\n lineStart: () => {\n for (const s of streams) s.lineStart()\n },\n lineEnd: () => {\n for (const s of streams) s.lineEnd()\n },\n polygonStart: () => {\n for (const s of streams) s.polygonStart()\n },\n polygonEnd: () => {\n for (const s of streams) s.polygonEnd()\n },\n }\n }\n\n // Add invert method (like Atlas Composer's CompositeProjection)\n // Validates inverted coordinates against territory bounds to ensure correct territory match\n ;(compositeProjection as any).invert = (coordinates: [number, number]) => {\n if (!coordinates || !Array.isArray(coordinates) || coordinates.length < 2) {\n return null\n }\n\n const [x, y] = coordinates\n\n // Try each sub-projection's invert and validate against territory bounds\n for (const { projection, bounds } of subProjections) {\n if ((projection as any).invert) {\n try {\n const result = (projection as any).invert([x, y])\n if (result && Array.isArray(result) && result.length >= 2) {\n const [lon, lat] = result\n\n // Validate that the inverted coordinates fall within this territory's bounds\n if (bounds && bounds.length === 2 && bounds[0].length === 2 && bounds[1].length === 2) {\n const [[minLon, minLat], [maxLon, maxLat]] = bounds\n\n // Check if coordinates are within bounds (with small tolerance for edge cases)\n const tolerance = 0.01 // Small tolerance for floating point comparison\n if (lon >= minLon - tolerance && lon <= maxLon + tolerance\n && lat >= minLat - tolerance && lat <= maxLat + tolerance) {\n if (debug) {\n console.log(`[Invert] Successfully inverted [${x}, ${y}] to [${lon}, ${lat}] (validated bounds)`)\n }\n return result as [number, number]\n }\n else if (debug) {\n console.log(`[Invert] Rejected inversion [${lon}, ${lat}] - outside bounds ${JSON.stringify(bounds)}`)\n }\n }\n else {\n // If no bounds available, accept the first successful invert (legacy behavior)\n if (debug) {\n console.log(`[Invert] No bounds for validation, accepting [${lon}, ${lat}]`)\n }\n return result as [number, number]\n }\n }\n }\n catch (error) {\n // Continue to next projection\n if (debug) {\n console.warn('[Invert] Error in sub-projection invert:', error)\n }\n }\n }\n }\n\n if (debug) {\n console.log(`[Invert] Failed to invert coordinates [${x}, ${y}]`)\n }\n return null\n }\n\n // Add scale and translate methods (like Atlas Composer's CompositeProjection)\n ;(compositeProjection as any).scale = function (_s?: number): any {\n if (arguments.length === 0) {\n // Return scale from first sub-projection as reference\n return subProjections[0] ? subProjections[0].projection.scale?.() || 1 : 1\n }\n // Setting scale - not typically used for composite projections\n // Individual territories manage their own scales\n return compositeProjection\n }\n\n ;(compositeProjection as any).translate = function (_t?: [number, number]): any {\n if (arguments.length === 0) {\n // Return center point as reference\n return [width / 2, height / 2]\n }\n // Setting translate - not typically used for composite projections\n // Individual territories manage their own translations\n return compositeProjection\n }\n\n return compositeProjection as ProjectionLike\n}\n\n/**\n * Create a sub-projection for a single territory\n */\nfunction createSubProjection(\n territory: Territory,\n width: number,\n height: number,\n referenceScale?: number,\n debug?: boolean,\n): ProjectionLike {\n // Extract projection info and parameters from nested projection object\n const { layout } = territory\n const projectionId = territory.projection.id\n const parameters = territory.projection.parameters\n\n if (!projectionId || !parameters) {\n throw new Error(`Territory ${territory.code} missing projection configuration`)\n }\n\n // Get projection factory from registry\n const factory = projectionRegistry.get(projectionId)\n if (!factory) {\n const registered = getRegisteredProjections()\n const availableList = registered.length > 0 ? registered.join(', ') : 'none'\n throw new Error(\n `Projection \"${projectionId}\" is not registered. `\n + `Available projections: ${availableList}. `\n + `Use registerProjection('${projectionId}', factory) to register it.`,\n )\n }\n\n // Create projection instance\n const projection = factory()\n\n // Apply parameters\n if (parameters.center && projection.center) {\n projection.center(parameters.center)\n }\n\n if (parameters.rotate && projection.rotate) {\n // Ensure rotate has exactly 3 elements\n const rotate = Array.isArray(parameters.rotate)\n ? [...parameters.rotate, 0, 0].slice(0, 3) as [number, number, number]\n : [0, 0, 0] as [number, number, number]\n projection.rotate(rotate)\n }\n\n if (parameters.parallels && projection.parallels) {\n // Ensure parallels has exactly 2 elements\n const parallels = Array.isArray(parameters.parallels)\n ? [...parameters.parallels, 0].slice(0, 2) as [number, number]\n : [0, 60] as [number, number]\n projection.parallels(parallels)\n }\n\n // Handle scale using scaleMultiplier and referenceScale\n if (projection.scale && parameters.scaleMultiplier) {\n const effectiveReferenceScale = referenceScale || 2700 // Default reference scale\n const calculatedScale = effectiveReferenceScale * parameters.scaleMultiplier\n projection.scale(calculatedScale)\n }\n\n // Apply additional parameters\n if (parameters.clipAngle && projection.clipAngle) {\n projection.clipAngle(parameters.clipAngle)\n }\n\n if (parameters.precision && projection.precision) {\n projection.precision(parameters.precision)\n }\n\n // Apply layout translate\n if (projection.translate) {\n const [offsetX, offsetY] = layout.translateOffset || [0, 0] // Default to center if missing\n projection.translate([\n width / 2 + offsetX,\n height / 2 + offsetY,\n ])\n }\n\n // Apply clipping - this is CRITICAL for composite projections\n // Each sub-projection MUST have clipping to avoid geometry processing conflicts\n if (layout.pixelClipExtent && projection.clipExtent) {\n // pixelClipExtent is in pixel coordinates relative to territory center\n // Format: [x1, y1, x2, y2] as direct pixel offsets\n const [x1, y1, x2, y2] = layout.pixelClipExtent\n const epsilon = 1e-6 // Small value for padding\n\n // Get territory center from translate\n const territoryCenter = projection.translate?.() || [width / 2, height / 2]\n\n const pixelClipExtent: [[number, number], [number, number]] = [\n [territoryCenter[0] + x1 + epsilon, territoryCenter[1] + y1 + epsilon],\n [territoryCenter[0] + x2 - epsilon, territoryCenter[1] + y2 - epsilon],\n ]\n\n projection.clipExtent(pixelClipExtent)\n if (debug) {\n console.log(\n `[Clipping] Applied pixelClipExtent for ${territory.code}:`,\n `original: [${x1}, ${y1}, ${x2}, ${y2}] -> transformed: ${JSON.stringify(pixelClipExtent)}`,\n )\n }\n }\n else if (projection.clipExtent) {\n // If no clip extent is specified, create a default one based on territory bounds\n const bounds = territory.bounds\n if (bounds && bounds.length === 2 && bounds[0].length === 2 && bounds[1].length === 2) {\n // Convert geographic bounds to pixel bounds (approximate)\n const scale = projection.scale?.() || 1\n const translate = projection.translate?.() || [0, 0]\n\n // Create a reasonable clip extent based on the geographic bounds\n const padding = scale * 0.1 // 10% padding\n const clipExtent: [[number, number], [number, number]] = [\n [translate[0] - padding, translate[1] - padding],\n [translate[0] + padding, translate[1] + padding],\n ]\n\n projection.clipExtent(clipExtent)\n\n if (debug) {\n console.log(`[Clipping] Applied default clip extent for ${territory.code}:`, clipExtent)\n }\n }\n }\n\n return projection\n}\n\n/**\n * Validate an exported configuration\n *\n * @param config - Configuration to validate\n * @returns True if valid, throws error otherwise\n */\nexport function validateConfig(config: any): config is ExportedConfig {\n if (!config || typeof config !== 'object') {\n throw new Error('Configuration must be an object')\n }\n\n if (!config.version) {\n throw new Error('Configuration must have a version field')\n }\n\n if (!config.metadata || !config.metadata.atlasId) {\n throw new Error('Configuration must have metadata with atlasId')\n }\n\n if (!config.territories || !Array.isArray(config.territories)) {\n throw new Error('Configuration must have territories array')\n }\n\n if (config.territories.length === 0) {\n throw new Error('Configuration must have at least one territory')\n }\n\n // Validate each territory\n for (const territory of config.territories) {\n if (!territory.code) {\n throw new Error(`Territory missing required field 'code': ${JSON.stringify(territory)}`)\n }\n\n // Check for required nested projection format\n if (!territory.projection || !territory.projection.id || !territory.projection.parameters) {\n throw new Error(`Territory ${territory.code} missing projection configuration. Required: projection.id and projection.parameters`)\n }\n\n if (!territory.bounds) {\n throw new Error(`Territory ${territory.code} missing bounds`)\n }\n }\n\n return true\n}\n\n/**\n * Load composite projection from JSON string\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadFromJSON } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n *\n * // Load from JSON\n * const jsonString = fs.readFileSync('france-composite.json', 'utf-8')\n * const projection = loadFromJSON(jsonString, { width: 800, height: 600 })\n * ```\n */\nexport function loadFromJSON(\n jsonString: string,\n options: LoaderOptions,\n): ProjectionLike {\n let config: any\n\n try {\n config = JSON.parse(jsonString)\n }\n catch (error) {\n throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : 'Unknown error'}`)\n }\n\n validateConfig(config)\n return loadCompositeProjection(config, options)\n}\n\n// Default export\nexport default {\n // Core loading functions\n loadCompositeProjection,\n loadFromJSON,\n validateConfig,\n\n // Registry management\n registerProjection,\n registerProjections,\n unregisterProjection,\n clearProjections,\n getRegisteredProjections,\n isProjectionRegistered,\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../projection-core/src/bounds/checker.ts","../../projection-core/src/bounds/clip-extent.ts","../../projection-core/src/invert/validator.ts","../../projection-core/src/stream/multiplexer.ts","../../projection-core/src/stream/point-capture.ts","../../projection-core/src/composite/builder.ts","../src/standalone-projection-loader.ts"],"names":["normalizeBounds"],"mappings":";AA2BO,SAAS,eAAA,CACd,GAAA,EACA,GAAA,EACA,MAAA,EACA,YAAY,CAAA,EACH;AACT,EAAA,OACE,GAAA,IAAO,MAAA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SACO,KAAA,EAAO;AACZ,IAAA,MAAM,IAAI,MAAM,CAAA,cAAA,EAAiB,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAe,CAAA,CAAE,CAAA;AAAA,EAC7F;AAEA,EAAA,cAAA,CAAe,MAAM,CAAA;AACrB,EAAA,OAAO,uBAAA,CAAwB,QAAQ,OAAO,CAAA;AAChD","file":"index.js","sourcesContent":["/**\n * Bounds Checker\n *\n * Pure functions for checking if geographic points fall within bounds.\n * Used by composite projections to route points to the correct sub-projection.\n */\n\nimport type { GeoBounds, GeoBoundsArray } from '../types'\n\n/**\n * Check if a geographic point is within the given bounds\n *\n * @param lon - Longitude of the point\n * @param lat - Latitude of the point\n * @param bounds - Geographic bounds to check against\n * @param tolerance - Optional tolerance for edge cases (default: 0)\n * @returns True if the point is within bounds\n *\n * @example\n * ```typescript\n * const bounds = { minLon: -10, minLat: 35, maxLon: 5, maxLat: 45 }\n *\n * isPointInBounds(-5, 40, bounds) // true (inside Portugal/Spain)\n * isPointInBounds(10, 50, bounds) // false (outside bounds)\n * isPointInBounds(-10, 35, bounds, 0.01) // true (on edge, with tolerance)\n * ```\n */\nexport function isPointInBounds(\n lon: number,\n lat: number,\n bounds: GeoBounds,\n tolerance = 0,\n): boolean {\n return (\n lon >= bounds.minLon - tolerance\n && lon <= bounds.maxLon + tolerance\n && lat >= bounds.minLat - tolerance\n && lat <= bounds.maxLat + tolerance\n )\n}\n\n/**\n * Convert a bounds array to a GeoBounds object\n *\n * @param bounds - Bounds array [[minLon, minLat], [maxLon, maxLat]]\n * @returns GeoBounds object\n *\n * @example\n * ```typescript\n * const arrayBounds: GeoBoundsArray = [[-10, 35], [5, 45]]\n * const objectBounds = boundsFromArray(arrayBounds)\n * // { minLon: -10, minLat: 35, maxLon: 5, maxLat: 45 }\n * ```\n */\nexport function boundsFromArray(bounds: GeoBoundsArray): GeoBounds {\n return {\n minLon: bounds[0][0],\n minLat: bounds[0][1],\n maxLon: bounds[1][0],\n maxLat: bounds[1][1],\n }\n}\n\n/**\n * Convert a GeoBounds object to a bounds array\n *\n * @param bounds - GeoBounds object\n * @returns Bounds array [[minLon, minLat], [maxLon, maxLat]]\n *\n * @example\n * ```typescript\n * const objectBounds = { minLon: -10, minLat: 35, maxLon: 5, maxLat: 45 }\n * const arrayBounds = boundsToArray(objectBounds)\n * // [[-10, 35], [5, 45]]\n * ```\n */\nexport function boundsToArray(bounds: GeoBounds): GeoBoundsArray {\n return [\n [bounds.minLon, bounds.minLat],\n [bounds.maxLon, bounds.maxLat],\n ]\n}\n","/**\n * Clip Extent Calculator\n *\n * Pure functions for calculating clip extents from geographic bounds\n * or pixel offsets. Used by composite projections to properly clip\n * each territory's rendering area.\n */\n\nimport type { ClipExtentOptions, GeoBounds, ProjectionLike } from '../types'\n\n/**\n * Calculate clip extent from geographic bounds\n *\n * Projects the corner points of geographic bounds to get the corresponding\n * screen coordinates for clipping. This is critical for composite projections\n * to ensure each territory only renders within its designated area.\n *\n * @param projection - The projection to use for transforming bounds\n * @param bounds - Geographic bounds { minLon, minLat, maxLon, maxLat }\n * @param options - Optional configuration (epsilon for padding)\n * @returns Clip extent [[x0, y0], [x1, y1]] or null if projection fails\n *\n * @example\n * ```typescript\n * const bounds = { minLon: -10, minLat: 35, maxLon: 5, maxLat: 45 }\n * const clipExtent = calculateClipExtentFromBounds(projection, bounds)\n *\n * if (clipExtent) {\n * projection.clipExtent(clipExtent)\n * }\n * ```\n */\nexport function calculateClipExtentFromBounds(\n projection: ProjectionLike,\n bounds: GeoBounds,\n options: ClipExtentOptions = {},\n): [[number, number], [number, number]] | null {\n const { epsilon = 1e-6 } = options\n\n // Project the corner points\n // Note: Geographic coordinates are [lon, lat] where:\n // - minLon is west, maxLon is east\n // - minLat is south, maxLat is north\n // In screen coordinates:\n // - topLeft corresponds to [minLon, maxLat] (northwest corner)\n // - bottomRight corresponds to [maxLon, minLat] (southeast corner)\n const topLeft = projection([\n bounds.minLon + epsilon,\n bounds.maxLat - epsilon,\n ])\n const bottomRight = projection([\n bounds.maxLon - epsilon,\n bounds.minLat + epsilon,\n ])\n\n if (!topLeft || !bottomRight) {\n return null\n }\n\n return [\n [topLeft[0], topLeft[1]],\n [bottomRight[0], bottomRight[1]],\n ]\n}\n\n/**\n * Calculate clip extent from pixel offsets\n *\n * Converts a pixel-based clip extent (relative to territory center)\n * to absolute screen coordinates. Used when clip extent is stored\n * as offsets in exported configurations.\n *\n * @param center - The territory center in screen coordinates [x, y]\n * @param pixelClipExtent - Pixel offsets [x1, y1, x2, y2] relative to center\n * @param epsilon - Small value for padding (default: 1e-6)\n * @returns Clip extent [[x0, y0], [x1, y1]] in absolute screen coordinates\n *\n * @example\n * ```typescript\n * const center = [400, 300] // Territory center in pixels\n * const offsets = [-100, -80, 100, 80] // Relative clip bounds\n *\n * const clipExtent = calculateClipExtentFromPixelOffset(center, offsets)\n * // [[300, 220], [500, 380]]\n *\n * projection.clipExtent(clipExtent)\n * ```\n */\nexport function calculateClipExtentFromPixelOffset(\n center: [number, number],\n pixelClipExtent: [number, number, number, number],\n epsilon = 1e-6,\n): [[number, number], [number, number]] {\n const [x1, y1, x2, y2] = pixelClipExtent\n\n return [\n [center[0] + x1 + epsilon, center[1] + y1 + epsilon],\n [center[0] + x2 - epsilon, center[1] + y2 - epsilon],\n ]\n}\n","/**\n * Invert Validator\n *\n * Validates inverted coordinates against territory bounds to ensure\n * correct territory matching. This is critical for composite projections\n * where multiple territories may overlap in screen space.\n */\n\nimport type { GeoBounds, GeoBoundsArray, InvertOptions, InvertResult, SubProjectionEntry } from '../types'\n\nimport { boundsFromArray, isPointInBounds } from '../bounds/checker'\n\n/**\n * Normalize bounds to GeoBounds format\n */\nfunction normalizeBounds(bounds: GeoBounds | GeoBoundsArray): GeoBounds {\n if ('minLon' in bounds) {\n return bounds\n }\n return boundsFromArray(bounds)\n}\n\n/**\n * Invert screen coordinates with bounds validation\n *\n * Tries each sub-projection's invert method and validates the result\n * against the territory's geographic bounds. This ensures that when\n * multiple territories overlap in screen space (common in composite\n * projections), the correct territory is identified.\n *\n * @param screenCoords - Screen coordinates [x, y] to invert\n * @param entries - Array of sub-projection entries with bounds\n * @param options - Optional configuration (tolerance, debug)\n * @returns InvertResult with coordinates and territoryId, or null if no match\n *\n * @example\n * ```typescript\n * const entries = [\n * { id: 'mainland', projection: mainlandProj, bounds: mainlandBounds },\n * { id: 'alaska', projection: alaskaProj, bounds: alaskaBounds },\n * ]\n *\n * const result = invertWithBoundsValidation([400, 300], entries)\n *\n * if (result) {\n * console.log(`Clicked on ${result.territoryId} at [${result.coordinates}]`)\n * }\n * ```\n */\nexport function invertWithBoundsValidation(\n screenCoords: [number, number],\n entries: SubProjectionEntry[],\n options: InvertOptions = {},\n): InvertResult | null {\n const { tolerance = 0.01, debug = false } = options\n const [x, y] = screenCoords\n\n for (const entry of entries) {\n const { projection, bounds, id } = entry\n\n if (!projection.invert) {\n continue\n }\n\n try {\n const result = projection.invert([x, y])\n\n if (!result || !Array.isArray(result) || result.length < 2) {\n continue\n }\n\n const [lon, lat] = result\n\n if (bounds) {\n const geoBounds = normalizeBounds(bounds)\n\n if (isPointInBounds(lon, lat, geoBounds, tolerance)) {\n if (debug) {\n console.log(`[Invert] Matched ${id}: [${x}, ${y}] -> [${lon}, ${lat}]`)\n }\n return { coordinates: result as [number, number], territoryId: id }\n }\n else if (debug) {\n console.log(`[Invert] Rejected ${id}: [${lon}, ${lat}] outside bounds`)\n }\n }\n else {\n // No bounds available, accept first successful invert (legacy behavior)\n if (debug) {\n console.log(`[Invert] No bounds for ${id}, accepting [${lon}, ${lat}]`)\n }\n return { coordinates: result as [number, number], territoryId: id }\n }\n }\n catch (error) {\n if (debug) {\n console.warn(`[Invert] Error in ${id}:`, error)\n }\n }\n }\n\n if (debug) {\n console.log(`[Invert] Failed to invert [${x}, ${y}]`)\n }\n\n return null\n}\n","/**\n * Stream Multiplexer\n *\n * Creates a stream that fans out geometry to multiple projections.\n * Used by composite projections to render all territories simultaneously.\n *\n * When d3.geoPath renders geometry through a composite projection,\n * the multiplexed stream ensures each sub-projection receives the\n * full geometry and applies its own clipping/transform.\n */\n\nimport type { ProjectionLike, StreamLike } from '../types'\n\n/**\n * Create a stream multiplexer for multiple projections\n *\n * @param projections - Array of projections to multiplex to\n * @returns Function that creates a multiplexed stream\n *\n * @example\n * ```typescript\n * const multiplex = createStreamMultiplexer([mainlandProj, alaskaProj, hawaiiProj])\n *\n * // Use as projection.stream method\n * compositeProjection.stream = multiplex\n *\n * // When d3.geoPath renders, all projections receive the geometry\n * const path = d3.geoPath(compositeProjection)\n * svg.selectAll('path')\n * .data(countries.features)\n * .join('path')\n * .attr('d', path)\n * ```\n */\nexport function createStreamMultiplexer(\n projections: ProjectionLike[],\n): (stream: StreamLike) => StreamLike {\n return (stream: StreamLike): StreamLike => {\n const streams = projections.map(p => p.stream(stream))\n\n return {\n point: (x: number, y: number) => {\n for (const s of streams) s.point(x, y)\n },\n lineStart: () => {\n for (const s of streams) s.lineStart()\n },\n lineEnd: () => {\n for (const s of streams) s.lineEnd()\n },\n polygonStart: () => {\n for (const s of streams) s.polygonStart()\n },\n polygonEnd: () => {\n for (const s of streams) s.polygonEnd()\n },\n sphere: () => {\n for (const s of streams) {\n if (s.sphere)\n s.sphere()\n }\n },\n }\n }\n}\n","/**\n * Point Capture Stream\n *\n * Creates a stream that captures projected point coordinates.\n * Used by composite projections to determine which sub-projection\n * successfully projects a geographic point.\n *\n * The pattern follows d3-composite-projections (albersUsa) approach:\n * 1. Create a point stream that stores the projected coordinates\n * 2. Pipe geographic coordinates through each sub-projection's stream\n * 3. Check if the point was captured (projection succeeded)\n */\n\nimport type { PointCaptureResult, StreamLike } from '../types'\n\n/**\n * Create a point capture stream for projection routing\n *\n * @returns Object with pointStream, getCapturedPoint, and resetCapture\n *\n * @example\n * ```typescript\n * const { pointStream, getCapturedPoint, resetCapture } = createPointCaptureStream()\n *\n * // Create capture stream for a projection\n * const captureStream = projection.stream(pointStream)\n *\n * // Project a point\n * resetCapture()\n * captureStream.point(longitude, latitude)\n *\n * // Check result\n * const projected = getCapturedPoint()\n * if (projected) {\n * console.log(`Projected to [${projected[0]}, ${projected[1]}]`)\n * }\n * ```\n */\nexport function createPointCaptureStream(): PointCaptureResult {\n let capturedPoint: [number, number] | null = null\n\n const pointStream: StreamLike = {\n point: (x: number, y: number) => {\n capturedPoint = [x, y]\n },\n lineStart: () => {},\n lineEnd: () => {},\n polygonStart: () => {},\n polygonEnd: () => {},\n sphere: () => {},\n }\n\n return {\n pointStream,\n getCapturedPoint: () => capturedPoint,\n resetCapture: () => {\n capturedPoint = null\n },\n }\n}\n","/**\n * Composite Projection Builder\n *\n * Creates a D3-compatible composite projection from multiple sub-projections.\n * This follows the same pattern as d3-composite-projections (albersUsa).\n *\n * The composite projection:\n * 1. Routes projection calls to the correct sub-projection based on bounds\n * 2. Multiplexes geometry streaming to all sub-projections for rendering\n * 3. Validates invert operations against territory bounds\n */\n\nimport type {\n CompositeProjectionConfig,\n GeoBounds,\n GeoBoundsArray,\n ProjectionLike,\n} from '../types'\n\nimport { boundsFromArray, isPointInBounds } from '../bounds/checker'\nimport { invertWithBoundsValidation } from '../invert/validator'\nimport { createStreamMultiplexer } from '../stream/multiplexer'\nimport { createPointCaptureStream } from '../stream/point-capture'\n\n/**\n * Normalize bounds to GeoBounds format\n */\nfunction normalizeBounds(bounds: GeoBounds | GeoBoundsArray): GeoBounds {\n if ('minLon' in bounds) {\n return bounds\n }\n return boundsFromArray(bounds)\n}\n\n/**\n * Build a composite projection from sub-projection entries\n *\n * Creates a D3-compatible projection that routes geographic points to the\n * appropriate sub-projection based on territory bounds. When rendering,\n * geometry is multiplexed to all sub-projections so each territory renders\n * its portion of the world.\n *\n * @param config - Configuration with entries and optional debug flag\n * @returns D3-compatible composite projection\n *\n * @example\n * ```typescript\n * // Create sub-projections (e.g., using d3-geo)\n * const mainlandProj = d3.geoAlbers()\n * .center([0, 38])\n * .rotate([96, 0])\n * .scale(1000)\n *\n * const alaskaProj = d3.geoConicEqualArea()\n * .center([0, 64])\n * .rotate([154, 0])\n * .scale(400)\n *\n * // Build composite\n * const composite = buildCompositeProjection({\n * entries: [\n * {\n * id: 'mainland',\n * name: 'Mainland USA',\n * projection: mainlandProj,\n * bounds: { minLon: -125, minLat: 24, maxLon: -66, maxLat: 50 }\n * },\n * {\n * id: 'alaska',\n * name: 'Alaska',\n * projection: alaskaProj,\n * bounds: { minLon: -180, minLat: 51, maxLon: -129, maxLat: 72 }\n * },\n * ],\n * })\n *\n * // Use with D3\n * const path = d3.geoPath(composite)\n * svg.selectAll('path')\n * .data(countries.features)\n * .join('path')\n * .attr('d', path)\n * ```\n */\nexport function buildCompositeProjection(\n config: CompositeProjectionConfig,\n): ProjectionLike {\n const { entries, debug = false } = config\n\n if (entries.length === 0) {\n throw new Error('Cannot build composite projection with no entries')\n }\n\n // Create point capture mechanism\n const { pointStream, getCapturedPoint, resetCapture } = createPointCaptureStream()\n\n // Create point capture streams for each entry\n const entryStreams = entries.map(entry => ({\n entry,\n stream: entry.projection.stream(pointStream),\n }))\n\n // Main projection function - routes to correct sub-projection based on bounds\n const project = (coordinates: [number, number]): [number, number] | null => {\n const [lon, lat] = coordinates\n resetCapture()\n\n for (const { entry, stream } of entryStreams) {\n if (entry.bounds) {\n const bounds = normalizeBounds(entry.bounds)\n\n if (isPointInBounds(lon, lat, bounds)) {\n stream.point(lon, lat)\n const captured = getCapturedPoint()\n\n if (captured) {\n return captured\n }\n }\n }\n }\n\n return null\n }\n\n // Cast to ProjectionLike and add required methods\n const composite = project as ProjectionLike\n\n // Stream method - multiplex to all sub-projections\n composite.stream = createStreamMultiplexer(entries.map(e => e.projection))\n\n // Invert method - with bounds validation\n composite.invert = (coords: [number, number]) => {\n const result = invertWithBoundsValidation(coords, entries, { debug })\n return result?.coordinates ?? null\n }\n\n // Scale getter/setter - returns reference from first sub-projection\n composite.scale = function (_s?: number): any {\n if (arguments.length === 0) {\n return entries[0]?.projection.scale() ?? 1\n }\n // Setting scale on composite is a no-op (individual territories manage their scales)\n return composite\n } as ProjectionLike['scale']\n\n // Translate getter/setter - returns reference translate\n composite.translate = function (_t?: [number, number]): any {\n if (arguments.length === 0) {\n return entries[0]?.projection.translate() ?? [0, 0]\n }\n // Setting translate on composite is a no-op (individual territories manage their translates)\n return composite\n } as ProjectionLike['translate']\n\n return composite\n}\n","/**\n * Standalone Composite Projection Loader (Zero Dependencies)\n *\n * A pure JavaScript/TypeScript module that consumes exported composite projection\n * configurations and creates D3-compatible projections using a plugin architecture.\n *\n * This package uses @atlas-composer/projection-core for the shared composite\n * projection building logic. Users must register projection factories before\n * loading configurations.\n *\n * @example\n * ```typescript\n * // Register projections first\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from './standalone-projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Then load your configuration\n * const projection = loadCompositeProjection(config, { width: 800, height: 600 })\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { ProjectionLike as CoreProjectionLike, SubProjectionEntry } from '@atlas-composer/projection-core'\n\nimport {\n buildCompositeProjection,\n calculateClipExtentFromPixelOffset,\n} from '@atlas-composer/projection-core'\n\n/**\n * Generic projection-like interface that matches D3 projections\n * without requiring d3-geo as a dependency\n *\n * Note: D3 projections use getter/setter pattern where calling without\n * arguments returns the current value, and with arguments sets and returns this.\n */\nexport interface ProjectionLike {\n (coordinates: [number, number]): [number, number] | null\n center?: {\n (): [number, number]\n (center: [number, number]): ProjectionLike\n }\n rotate?: {\n (): [number, number, number]\n (angles: [number, number, number]): ProjectionLike\n }\n parallels?: {\n (): [number, number]\n (parallels: [number, number]): ProjectionLike\n }\n scale?: {\n (): number\n (scale: number): ProjectionLike\n }\n translate?: {\n (): [number, number]\n (translate: [number, number]): ProjectionLike\n }\n clipExtent?: {\n (): [[number, number], [number, number]] | null\n (extent: [[number, number], [number, number]] | null): ProjectionLike\n }\n clipAngle?: {\n (): number\n (angle: number): ProjectionLike\n }\n stream?: (stream: StreamLike) => StreamLike\n precision?: {\n (): number\n (precision: number): ProjectionLike\n }\n fitExtent?: (extent: [[number, number], [number, number]], object: any) => ProjectionLike\n fitSize?: (size: [number, number], object: any) => ProjectionLike\n fitWidth?: (width: number, object: any) => ProjectionLike\n fitHeight?: (height: number, object: any) => ProjectionLike\n}\n\n/**\n * Stream protocol interface for D3 geographic transforms\n */\nexport interface StreamLike {\n point: (x: number, y: number) => void\n lineStart: () => void\n lineEnd: () => void\n polygonStart: () => void\n polygonEnd: () => void\n sphere?: () => void\n}\n\n/**\n * Factory function that creates a projection instance\n */\nexport type ProjectionFactory = () => ProjectionLike\n\n/**\n * Exported configuration format (subset needed for loading)\n */\nexport interface ExportedConfig {\n version: string\n metadata: {\n atlasId: string\n atlasName: string\n exportDate?: string\n createdWith?: string\n notes?: string\n }\n pattern: string\n referenceScale?: number\n canvasDimensions?: {\n width: number\n height: number\n }\n territories: Territory[]\n}\n\nexport interface Territory {\n code: string\n name: string\n role: string\n projection: {\n id: string\n family: string\n parameters: ProjectionParameters\n }\n layout: Layout\n bounds: [[number, number], [number, number]]\n}\n\nexport interface ProjectionParameters {\n center?: [number, number]\n rotate?: [number, number, number]\n scaleMultiplier?: number\n parallels?: [number, number]\n clipAngle?: number\n precision?: number\n}\n\nexport interface Layout {\n translateOffset?: [number, number]\n /** Pixel-based clip extent relative to territory center [x1, y1, x2, y2] */\n pixelClipExtent?: [number, number, number, number] | null\n}\n\n/**\n * Options for creating the composite projection\n */\nexport interface LoaderOptions {\n /** Canvas width in pixels */\n width: number\n /** Canvas height in pixels */\n height: number\n /** Whether to apply clipping to territories (default: true) */\n enableClipping?: boolean\n /** Debug mode - logs territory selection (default: false) */\n debug?: boolean\n}\n\n/**\n * Runtime registry for projection factories\n * Users must register projections before loading configurations\n */\nconst projectionRegistry = new Map<string, ProjectionFactory>()\n\n/**\n * Register a projection factory with a given ID\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection } from '@atlas-composer/projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n * ```\n *\n * @param id - Projection identifier (e.g., 'mercator', 'albers')\n * @param factory - Function that creates a new projection instance\n */\nexport function registerProjection(id: string, factory: ProjectionFactory): void {\n projectionRegistry.set(id, factory)\n}\n\n/**\n * Register multiple projections at once\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjections } from '@atlas-composer/projection-loader'\n *\n * registerProjections({\n * 'mercator': () => d3.geoMercator(),\n * 'albers': () => d3.geoAlbers(),\n * 'conic-equal-area': () => d3.geoConicEqualArea()\n * })\n * ```\n *\n * @param factories - Object mapping projection IDs to factory functions\n */\nexport function registerProjections(factories: Record<string, ProjectionFactory>): void {\n for (const [id, factory] of Object.entries(factories)) {\n registerProjection(id, factory)\n }\n}\n\n/**\n * Unregister a projection\n *\n * @param id - Projection identifier to remove\n * @returns True if the projection was removed, false if it wasn't registered\n */\nexport function unregisterProjection(id: string): boolean {\n return projectionRegistry.delete(id)\n}\n\n/**\n * Clear all registered projections\n */\nexport function clearProjections(): void {\n projectionRegistry.clear()\n}\n\n/**\n * Get list of currently registered projection IDs\n *\n * @returns Array of registered projection identifiers\n */\nexport function getRegisteredProjections(): string[] {\n return Array.from(projectionRegistry.keys())\n}\n\n/**\n * Check if a projection is registered\n *\n * @param id - Projection identifier to check\n * @returns True if the projection is registered\n */\nexport function isProjectionRegistered(id: string): boolean {\n return projectionRegistry.has(id)\n}\n\n/**\n * Create a minimal projection wrapper (similar to d3.geoProjection)\n * This allows us to avoid the d3-geo dependency\n */\n\n/**\n * Create a D3-compatible projection from an exported composite projection configuration\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Load configuration\n * const config = JSON.parse(jsonString)\n *\n * // Create projection\n * const projection = loadCompositeProjection(config, {\n * width: 800,\n * height: 600\n * })\n *\n * // Use with D3\n * const path = d3.geoPath(projection)\n * svg.selectAll('path')\n * .data(countries.features)\n * .join('path')\n * .attr('d', path)\n * ```\n *\n * @param config - Exported composite projection configuration\n * @param options - Canvas dimensions and options\n * @returns D3-compatible projection that routes geometry to appropriate sub-projections\n */\nexport function loadCompositeProjection(\n config: ExportedConfig,\n options: LoaderOptions,\n): ProjectionLike {\n const { width, height, debug = false } = options\n\n // Validate configuration version\n if (config.version !== '1.0') {\n throw new Error(`Unsupported configuration version: ${config.version}`)\n }\n\n if (!config.territories || config.territories.length === 0) {\n throw new Error('Configuration must contain at least one territory')\n }\n\n // Create sub-projections for each territory and convert to SubProjectionEntry format\n const entries: SubProjectionEntry[] = config.territories.map((territory) => {\n const proj = createSubProjection(territory, width, height, config.referenceScale, debug)\n\n return {\n id: territory.code,\n name: territory.name,\n projection: proj as CoreProjectionLike,\n bounds: {\n minLon: territory.bounds[0][0],\n minLat: territory.bounds[0][1],\n maxLon: territory.bounds[1][0],\n maxLat: territory.bounds[1][1],\n },\n }\n })\n\n if (debug) {\n console.log('[CompositeProjection] Created sub-projections:', {\n territories: config.territories.map(t => ({ code: t.code, name: t.name })),\n count: entries.length,\n })\n }\n\n // Use projection-core to build the composite projection\n const composite = buildCompositeProjection({ entries, debug })\n\n return composite as ProjectionLike\n}\n\n/**\n * Create a sub-projection for a single territory\n */\nfunction createSubProjection(\n territory: Territory,\n width: number,\n height: number,\n referenceScale?: number,\n debug?: boolean,\n): ProjectionLike {\n // Extract projection info and parameters from nested projection object\n const { layout } = territory\n const projectionId = territory.projection.id\n const parameters = territory.projection.parameters\n\n if (!projectionId || !parameters) {\n throw new Error(`Territory ${territory.code} missing projection configuration`)\n }\n\n // Get projection factory from registry\n const factory = projectionRegistry.get(projectionId)\n if (!factory) {\n const registered = getRegisteredProjections()\n const availableList = registered.length > 0 ? registered.join(', ') : 'none'\n throw new Error(\n `Projection \"${projectionId}\" is not registered. `\n + `Available projections: ${availableList}. `\n + `Use registerProjection('${projectionId}', factory) to register it.`,\n )\n }\n\n // Create projection instance\n const projection = factory()\n\n // Apply parameters\n if (parameters.center && projection.center) {\n projection.center(parameters.center)\n }\n\n if (parameters.rotate && projection.rotate) {\n // Ensure rotate has exactly 3 elements\n const rotate = Array.isArray(parameters.rotate)\n ? [...parameters.rotate, 0, 0].slice(0, 3) as [number, number, number]\n : [0, 0, 0] as [number, number, number]\n projection.rotate(rotate)\n }\n\n if (parameters.parallels && projection.parallels) {\n // Ensure parallels has exactly 2 elements\n const parallels = Array.isArray(parameters.parallels)\n ? [...parameters.parallels, 0].slice(0, 2) as [number, number]\n : [0, 60] as [number, number]\n projection.parallels(parallels)\n }\n\n // Handle scale using scaleMultiplier and referenceScale\n if (projection.scale && parameters.scaleMultiplier) {\n const effectiveReferenceScale = referenceScale || 2700 // Default reference scale\n const calculatedScale = effectiveReferenceScale * parameters.scaleMultiplier\n projection.scale(calculatedScale)\n }\n\n // Apply additional parameters\n if (parameters.clipAngle && projection.clipAngle) {\n projection.clipAngle(parameters.clipAngle)\n }\n\n if (parameters.precision && projection.precision) {\n projection.precision(parameters.precision)\n }\n\n // Apply layout translate\n if (projection.translate) {\n const [offsetX, offsetY] = layout.translateOffset || [0, 0] // Default to center if missing\n projection.translate([\n width / 2 + offsetX,\n height / 2 + offsetY,\n ])\n }\n\n // Apply clipping - this is CRITICAL for composite projections\n // Each sub-projection MUST have clipping to avoid geometry processing conflicts\n if (layout.pixelClipExtent && projection.clipExtent) {\n // Get territory center from translate\n const territoryCenter = projection.translate?.() || [width / 2, height / 2]\n\n // Use core utility for clip extent calculation\n const clipExtent = calculateClipExtentFromPixelOffset(\n territoryCenter,\n layout.pixelClipExtent,\n )\n\n projection.clipExtent(clipExtent)\n if (debug) {\n console.log(\n `[Clipping] Applied pixelClipExtent for ${territory.code}:`,\n `original: ${JSON.stringify(layout.pixelClipExtent)} -> transformed: ${JSON.stringify(clipExtent)}`,\n )\n }\n }\n else if (projection.clipExtent) {\n // If no clip extent is specified, create a default one based on territory bounds\n const bounds = territory.bounds\n if (bounds && bounds.length === 2 && bounds[0].length === 2 && bounds[1].length === 2) {\n // Convert geographic bounds to pixel bounds (approximate)\n const scale = projection.scale?.() || 1\n const translate = projection.translate?.() || [0, 0]\n\n // Create a reasonable clip extent based on the geographic bounds\n const padding = scale * 0.1 // 10% padding\n const clipExtent: [[number, number], [number, number]] = [\n [translate[0] - padding, translate[1] - padding],\n [translate[0] + padding, translate[1] + padding],\n ]\n\n projection.clipExtent(clipExtent)\n\n if (debug) {\n console.log(`[Clipping] Applied default clip extent for ${territory.code}:`, clipExtent)\n }\n }\n }\n\n return projection\n}\n\n/**\n * Validate an exported configuration\n *\n * @param config - Configuration to validate\n * @returns True if valid, throws error otherwise\n */\nexport function validateConfig(config: any): config is ExportedConfig {\n if (!config || typeof config !== 'object') {\n throw new Error('Configuration must be an object')\n }\n\n if (!config.version) {\n throw new Error('Configuration must have a version field')\n }\n\n if (!config.metadata || !config.metadata.atlasId) {\n throw new Error('Configuration must have metadata with atlasId')\n }\n\n if (!config.territories || !Array.isArray(config.territories)) {\n throw new Error('Configuration must have territories array')\n }\n\n if (config.territories.length === 0) {\n throw new Error('Configuration must have at least one territory')\n }\n\n // Validate each territory\n for (const territory of config.territories) {\n if (!territory.code) {\n throw new Error(`Territory missing required field 'code': ${JSON.stringify(territory)}`)\n }\n\n // Check for required nested projection format\n if (!territory.projection || !territory.projection.id || !territory.projection.parameters) {\n throw new Error(`Territory ${territory.code} missing projection configuration. Required: projection.id and projection.parameters`)\n }\n\n if (!territory.bounds) {\n throw new Error(`Territory ${territory.code} missing bounds`)\n }\n }\n\n return true\n}\n\n/**\n * Load composite projection from JSON string\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadFromJSON } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n *\n * // Load from JSON\n * const jsonString = fs.readFileSync('france-composite.json', 'utf-8')\n * const projection = loadFromJSON(jsonString, { width: 800, height: 600 })\n * ```\n */\nexport function loadFromJSON(\n jsonString: string,\n options: LoaderOptions,\n): ProjectionLike {\n let config: any\n\n try {\n config = JSON.parse(jsonString)\n }\n catch (error) {\n throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : 'Unknown error'}`)\n }\n\n validateConfig(config)\n return loadCompositeProjection(config, options)\n}\n\n// Default export\nexport default {\n // Core loading functions\n loadCompositeProjection,\n loadFromJSON,\n validateConfig,\n\n // Registry management\n registerProjection,\n registerProjections,\n unregisterProjection,\n clearProjections,\n getRegisteredProjections,\n isProjectionRegistered,\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlas-composer/projection-loader",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.0-rc.
|
|
4
|
+
"version": "1.1.0-rc.14",
|
|
5
5
|
"description": "Zero-dependency standalone loader for composite map projections with plugin architecture. Supports Atlas composer 2.0+ presets with backward compatibility.",
|
|
6
6
|
"author": "Lucas Poulain (ShallowRed)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,6 +46,15 @@
|
|
|
46
46
|
"README.md",
|
|
47
47
|
"dist"
|
|
48
48
|
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"dev": "tsup --watch",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:watch": "vitest",
|
|
55
|
+
"size": "size-limit",
|
|
56
|
+
"size:why": "size-limit --why"
|
|
57
|
+
},
|
|
49
58
|
"size-limit": [
|
|
50
59
|
{
|
|
51
60
|
"name": "Main bundle (ESM)",
|
|
@@ -72,6 +81,9 @@
|
|
|
72
81
|
"optional": true
|
|
73
82
|
}
|
|
74
83
|
},
|
|
84
|
+
"dependencies": {
|
|
85
|
+
"@atlas-composer/projection-core": "workspace:*"
|
|
86
|
+
},
|
|
75
87
|
"devDependencies": {
|
|
76
88
|
"@size-limit/preset-small-lib": "^11.2.0",
|
|
77
89
|
"@types/d3-geo": "^3.1.0",
|
|
@@ -80,14 +92,5 @@
|
|
|
80
92
|
"tsup": "^8.0.0",
|
|
81
93
|
"typescript": "~5.9.3",
|
|
82
94
|
"vitest": "^3.2.4"
|
|
83
|
-
},
|
|
84
|
-
"scripts": {
|
|
85
|
-
"build": "tsup",
|
|
86
|
-
"dev": "tsup --watch",
|
|
87
|
-
"typecheck": "tsc --noEmit",
|
|
88
|
-
"test": "vitest run",
|
|
89
|
-
"test:watch": "vitest",
|
|
90
|
-
"size": "size-limit",
|
|
91
|
-
"size:why": "size-limit --why"
|
|
92
95
|
}
|
|
93
|
-
}
|
|
96
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Lucas Poulain
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|