@atlas-composer/projection-loader 1.1.0-rc.3 → 1.1.0-rc.5

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 CHANGED
@@ -1,3 +1,27 @@
1
+ /**
2
+ * Standalone Composite Projection Loader (Zero Dependencies)
3
+ *
4
+ * A pure JavaScript/TypeScript module that consumes exported composite projection
5
+ * configurations and creates D3-compatible projections using a plugin architecture.
6
+ *
7
+ * This package has ZERO dependencies. Users must register projection factories
8
+ * before loading configurations.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Register projections first
13
+ * import * as d3 from 'd3-geo'
14
+ * import { registerProjection, loadCompositeProjection } from './standalone-projection-loader'
15
+ *
16
+ * registerProjection('mercator', () => d3.geoMercator())
17
+ * registerProjection('albers', () => d3.geoAlbers())
18
+ *
19
+ * // Then load your configuration
20
+ * const projection = loadCompositeProjection(config, { width: 800, height: 600 })
21
+ * ```
22
+ *
23
+ * @packageDocumentation
24
+ */
1
25
  /**
2
26
  * Generic projection-like interface that matches D3 projections
3
27
  * without requiring d3-geo as a dependency
package/dist/index.js CHANGED
@@ -1,8 +1,4 @@
1
1
  // src/standalone-projection-loader.ts
2
- console.log("-----------------------------------------");
3
- console.log("-----------------------------------------");
4
- console.log("-----------------------------------------");
5
- console.log("Standalone Projection Loader Module Loaded");
6
2
  var projectionRegistry = /* @__PURE__ */ new Map();
7
3
  function registerProjection(id, factory) {
8
4
  projectionRegistry.set(id, factory);
@@ -94,75 +90,33 @@ function loadCompositeProjection(config, options) {
94
90
  }
95
91
  return {
96
92
  point: (x, y) => {
97
- try {
98
- for (const s of streams) {
99
- if (s && typeof s.point === "function") {
100
- s.point(x, y);
101
- }
102
- }
103
- } catch (error) {
104
- if (debug)
105
- console.error("[Stream] Error in point():", error);
93
+ for (const s of streams) {
94
+ if (s) s.point(x, y);
106
95
  }
107
96
  },
108
97
  sphere: () => {
109
- try {
110
- for (const s of streams) {
111
- if (s && typeof s.sphere === "function") {
112
- s.sphere();
113
- }
114
- }
115
- } catch (error) {
116
- if (debug)
117
- console.error("[Stream] Error in sphere():", error);
98
+ for (const s of streams) {
99
+ if (s && s.sphere) s.sphere();
118
100
  }
119
101
  },
120
102
  lineStart: () => {
121
- try {
122
- for (const s of streams) {
123
- if (s && typeof s.lineStart === "function") {
124
- s.lineStart();
125
- }
126
- }
127
- } catch (error) {
128
- if (debug)
129
- console.error("[Stream] Error in lineStart():", error);
103
+ for (const s of streams) {
104
+ if (s) s.lineStart();
130
105
  }
131
106
  },
132
107
  lineEnd: () => {
133
- try {
134
- for (const s of streams) {
135
- if (s && typeof s.lineEnd === "function") {
136
- s.lineEnd();
137
- }
138
- }
139
- } catch (error) {
140
- if (debug)
141
- console.error("[Stream] Error in lineEnd():", error);
108
+ for (const s of streams) {
109
+ if (s) s.lineEnd();
142
110
  }
143
111
  },
144
112
  polygonStart: () => {
145
- try {
146
- for (const s of streams) {
147
- if (s && typeof s.polygonStart === "function") {
148
- s.polygonStart();
149
- }
150
- }
151
- } catch (error) {
152
- if (debug)
153
- console.error("[Stream] Error in polygonStart():", error);
113
+ for (const s of streams) {
114
+ if (s) s.polygonStart();
154
115
  }
155
116
  },
156
117
  polygonEnd: () => {
157
- try {
158
- for (const s of streams) {
159
- if (s && typeof s.polygonEnd === "function") {
160
- s.polygonEnd();
161
- }
162
- }
163
- } catch (error) {
164
- if (debug)
165
- console.error("[Stream] Error in polygonEnd():", error);
118
+ for (const s of streams) {
119
+ if (s) s.polygonEnd();
166
120
  }
167
121
  }
168
122
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/standalone-projection-loader.ts"],"names":[],"mappings":";AAwBA,OAAA,CAAQ,IAAI,2CAA2C,CAAA;AACvD,OAAA,CAAQ,IAAI,2CAA2C,CAAA;AACvD,OAAA,CAAQ,IAAI,2CAA2C,CAAA;AACvD,OAAA,CAAQ,IAAI,4CAA4C,CAAA;AA8IxD,IA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E,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AAAA,IACxI;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 */\nconsole.log('-----------------------------------------')\nconsole.log('-----------------------------------------')\nconsole.log('-----------------------------------------')\nconsole.log('Standalone Projection Loader Module Loaded')\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 invert?: (coordinates: [number, number]) => [number, number] | null\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 // Support multiple formats\n projectionId?: string // Legacy format\n projectionFamily?: string // Migration script format\n projection?: {\n id: string\n family: string\n parameters: ProjectionParameters\n } // New format\n parameters?: ProjectionParameters // Used in legacy and migration formats\n layout: Layout\n bounds: [[number, number], [number, number]]\n}\n\nexport interface ProjectionParameters {\n center?: [number, number]\n rotate?: [number, number, number]\n // Legacy format support\n scale?: number\n baseScale?: number\n scaleMultiplier?: number\n parallels?: [number, number]\n // Additional parameters from new format\n translate?: [number, number]\n clipAngle?: number\n precision?: number\n}\n\nexport interface Layout {\n translateOffset?: [number, number] // Make optional for migration script format\n clipExtent?: [[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// Remove unused createProjectionWrapper function\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(({ territory, projection, bounds }) => ({\n territory,\n projection,\n bounds,\n stream: projection.stream ? projection.stream(pointStream) : null,\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 { bounds, stream } of subProjPoints) {\n if (stream\n && lon >= bounds[0][0] && lon <= bounds[1][0]\n && lat >= bounds[0][1] && lat <= bounds[1][1]) {\n // Use the stream to project the point (D3 expects degrees, not radians)\n stream.point(lon, lat)\n if (capturedPoint) {\n return capturedPoint\n }\n }\n }\n\n // Fallback: try first projection if no bounds matched\n if (subProjPoints[0] && subProjPoints[0].stream) {\n subProjPoints[0].stream.point(lon, lat)\n if (capturedPoint) {\n return capturedPoint\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: StreamLike) => {\n const streams = subProjections.map(sp => sp.projection.stream(stream))\n\n if (debug) {\n console.log(`[Stream] Created multiplex stream with ${streams.length}/${subProjections.length} sub-streams`)\n }\n\n return {\n point: (x: number, y: number) => {\n try {\n for (const s of streams) {\n if (s && typeof s.point === 'function') {\n s.point(x, y)\n }\n }\n }\n catch (error) {\n if (debug)\n console.error('[Stream] Error in point():', error)\n }\n },\n sphere: () => {\n try {\n for (const s of streams) {\n if (s && typeof s.sphere === 'function') {\n s.sphere()\n }\n }\n }\n catch (error) {\n if (debug)\n console.error('[Stream] Error in sphere():', error)\n }\n },\n lineStart: () => {\n try {\n for (const s of streams) {\n if (s && typeof s.lineStart === 'function') {\n s.lineStart()\n }\n }\n }\n catch (error) {\n if (debug)\n console.error('[Stream] Error in lineStart():', error)\n }\n },\n lineEnd: () => {\n try {\n for (const s of streams) {\n if (s && typeof s.lineEnd === 'function') {\n s.lineEnd()\n }\n }\n }\n catch (error) {\n if (debug)\n console.error('[Stream] Error in lineEnd():', error)\n }\n },\n polygonStart: () => {\n try {\n for (const s of streams) {\n if (s && typeof s.polygonStart === 'function') {\n s.polygonStart()\n }\n }\n }\n catch (error) {\n if (debug)\n console.error('[Stream] Error in polygonStart():', error)\n }\n },\n polygonEnd: () => {\n try {\n for (const s of streams) {\n if (s && typeof s.polygonEnd === 'function') {\n s.polygonEnd()\n }\n }\n }\n catch (error) {\n if (debug)\n console.error('[Stream] Error in polygonEnd():', error)\n }\n },\n }\n }\n\n // Add invert method (like Atlas Composer's CompositeProjection)\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\n for (const { projection } of subProjections) {\n if (projection.invert) {\n try {\n const result = projection.invert([x, y])\n if (result && Array.isArray(result) && result.length >= 2) {\n return result as [number, number]\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 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 * Infer projection ID from family and parameters (for migration script format)\n */\nfunction inferProjectionIdFromFamily(family: string, parameters: ProjectionParameters): string {\n // Common projection mappings based on family and parameters\n switch (family.toUpperCase()) {\n case 'CYLINDRICAL':\n return 'mercator' // Most common cylindrical projection\n case 'CONIC':\n return parameters.parallels ? 'conic-conformal' : 'conic-equal-area'\n case 'AZIMUTHAL':\n return 'azimuthal-equal-area'\n default:\n // Fallback to mercator if we can't determine\n console.warn(`Unknown projection family: ${family}, falling back to mercator`)\n return 'mercator'\n }\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 multiple formats\n let projectionId: string\n let parameters: ProjectionParameters\n const { layout } = territory\n\n if (territory.projection) {\n // New format: nested projection object\n projectionId = territory.projection.id\n parameters = territory.projection.parameters\n }\n else if (territory.projectionId && territory.parameters) {\n // Legacy format: direct properties\n projectionId = territory.projectionId\n parameters = territory.parameters\n }\n else if (territory.projectionFamily && territory.parameters) {\n // Migration script format: has projectionFamily but missing projectionId\n // Try to infer projection ID from family and parameters\n projectionId = inferProjectionIdFromFamily(territory.projectionFamily as string, territory.parameters)\n parameters = territory.parameters\n }\n else {\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 - support both legacy (scale) and new (scaleMultiplier + referenceScale) formats\n if (projection.scale) {\n if (parameters.scale) {\n // Legacy format: use direct scale value\n projection.scale(parameters.scale)\n }\n else if (parameters.scaleMultiplier) {\n // New format: calculate scale from reference scale and multiplier\n const effectiveReferenceScale = referenceScale || 2700 // Default reference scale\n const calculatedScale = effectiveReferenceScale * parameters.scaleMultiplier\n projection.scale(calculatedScale)\n }\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 parameter-level translate (additional adjustment)\n if (parameters.translate && projection.translate) {\n const currentTranslate = projection.translate()\n const [additionalX, additionalY] = parameters.translate\n projection.translate([\n currentTranslate[0] + additionalX,\n currentTranslate[1] + additionalY,\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.clipExtent && projection.clipExtent) {\n projection.clipExtent(layout.clipExtent)\n }\n else if (projection.clipExtent) {\n // If no clip extent is specified, create a default one based on territory bounds\n // This prevents the projection from processing geometry outside its area\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 // This is a simplified approach - in practice, you'd want more precise clipping\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 projection info in either format\n const hasLegacyFormat = territory.projectionId && territory.parameters\n const hasNewFormat = territory.projection && territory.projection.id && territory.projection.parameters\n const hasIncompleteFormat = territory.projectionFamily && territory.parameters // Migration script format\n\n if (!hasLegacyFormat && !hasNewFormat && !hasIncompleteFormat) {\n throw new Error(`Territory ${territory.code} missing projection configuration. Available fields: ${Object.keys(territory).join(', ')}`)\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":["../src/standalone-projection-loader.ts"],"names":[],"mappings":";AAsKA,IAAM,kBAAA,uBAAyB,GAAA,EAA+B;AAiBvD,SAAS,kBAAA,CAAmB,IAAY,OAAA,EAAkC;AAC/E,EAAA,kBAAA,CAAmB,GAAA,CAAI,IAAI,OAAO,CAAA;AACpC;AAmBO,SAAS,oBAAoB,SAAA,EAAoD;AACtF,EAAA,KAAA,MAAW,CAAC,EAAA,EAAI,OAAO,KAAK,MAAA,CAAO,OAAA,CAAQ,SAAS,CAAA,EAAG;AACrD,IAAA,kBAAA,CAAmB,IAAI,OAAO,CAAA;AAAA,EAChC;AACF;AAQO,SAAS,qBAAqB,EAAA,EAAqB;AACxD,EAAA,OAAO,kBAAA,CAAmB,OAAO,EAAE,CAAA;AACrC;AAKO,SAAS,gBAAA,GAAyB;AACvC,EAAA,kBAAA,CAAmB,KAAA,EAAM;AAC3B;AAOO,SAAS,wBAAA,GAAqC;AACnD,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,kBAAA,CAAmB,IAAA,EAAM,CAAA;AAC7C;AAQO,SAAS,uBAAuB,EAAA,EAAqB;AAC1D,EAAA,OAAO,kBAAA,CAAmB,IAAI,EAAE,CAAA;AAClC;AAqCO,SAAS,uBAAA,CACd,QACA,OAAA,EACgB;AAChB,EAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAQ,KAAA,GAAQ,OAAM,GAAI,OAAA;AAGzC,EAAA,IAAI,MAAA,CAAO,YAAY,KAAA,EAAO;AAC5B,IAAA,MAAM,IAAI,KAAA,CAA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A,IAAM,UAAU,UAAA,CAAW,UAAA;AAC7F,IAAA,MAAM,mBAAA,GAAsB,SAAA,CAAU,gBAAA,IAAoB,SAAA,CAAU,UAAA;AAEpE,IAAA,IAAI,CAAC,eAAA,IAAmB,CAAC,YAAA,IAAgB,CAAC,mBAAA,EAAqB;AAC7D,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,UAAA,EAAa,SAAA,CAAU,IAAI,CAAA,qDAAA,EAAwD,MAAA,CAAO,IAAA,CAAK,SAAS,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AAAA,IACxI;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 */\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 invert?: (coordinates: [number, number]) => [number, number] | null\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 // Support multiple formats\n projectionId?: string // Legacy format\n projectionFamily?: string // Migration script format\n projection?: {\n id: string\n family: string\n parameters: ProjectionParameters\n } // New format\n parameters?: ProjectionParameters // Used in legacy and migration formats\n layout: Layout\n bounds: [[number, number], [number, number]]\n}\n\nexport interface ProjectionParameters {\n center?: [number, number]\n rotate?: [number, number, number]\n // Legacy format support\n scale?: number\n baseScale?: number\n scaleMultiplier?: number\n parallels?: [number, number]\n // Additional parameters from new format\n translate?: [number, number]\n clipAngle?: number\n precision?: number\n}\n\nexport interface Layout {\n translateOffset?: [number, number] // Make optional for migration script format\n clipExtent?: [[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// Remove unused createProjectionWrapper function\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(({ territory, projection, bounds }) => ({\n territory,\n projection,\n bounds,\n stream: projection.stream ? projection.stream(pointStream) : null,\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 { bounds, stream } of subProjPoints) {\n if (stream\n && lon >= bounds[0][0] && lon <= bounds[1][0]\n && lat >= bounds[0][1] && lat <= bounds[1][1]) {\n // Use the stream to project the point (D3 expects degrees, not radians)\n stream.point(lon, lat)\n if (capturedPoint) {\n return capturedPoint\n }\n }\n }\n\n // Fallback: try first projection if no bounds matched\n if (subProjPoints[0] && subProjPoints[0].stream) {\n subProjPoints[0].stream.point(lon, lat)\n if (capturedPoint) {\n return capturedPoint\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: StreamLike) => {\n const streams = subProjections.map(sp => sp.projection.stream(stream))\n\n if (debug) {\n console.log(`[Stream] Created multiplex stream with ${streams.length}/${subProjections.length} sub-streams`)\n }\n\n return {\n point: (x: number, y: number) => {\n for (const s of streams) {\n if (s) s.point(x, y)\n }\n },\n sphere: () => {\n for (const s of streams) {\n if (s && s.sphere) s.sphere()\n }\n },\n lineStart: () => {\n for (const s of streams) {\n if (s) s.lineStart()\n }\n },\n lineEnd: () => {\n for (const s of streams) {\n if (s) s.lineEnd()\n }\n },\n polygonStart: () => {\n for (const s of streams) {\n if (s) s.polygonStart()\n }\n },\n polygonEnd: () => {\n for (const s of streams) {\n if (s) s.polygonEnd()\n }\n },\n }\n }\n\n // Add invert method (like Atlas Composer's CompositeProjection)\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\n for (const { projection } of subProjections) {\n if (projection.invert) {\n try {\n const result = projection.invert([x, y])\n if (result && Array.isArray(result) && result.length >= 2) {\n return result as [number, number]\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 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 * Infer projection ID from family and parameters (for migration script format)\n */\nfunction inferProjectionIdFromFamily(family: string, parameters: ProjectionParameters): string {\n // Common projection mappings based on family and parameters\n switch (family.toUpperCase()) {\n case 'CYLINDRICAL':\n return 'mercator' // Most common cylindrical projection\n case 'CONIC':\n return parameters.parallels ? 'conic-conformal' : 'conic-equal-area'\n case 'AZIMUTHAL':\n return 'azimuthal-equal-area'\n default:\n // Fallback to mercator if we can't determine\n console.warn(`Unknown projection family: ${family}, falling back to mercator`)\n return 'mercator'\n }\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 multiple formats\n let projectionId: string\n let parameters: ProjectionParameters\n const { layout } = territory\n\n if (territory.projection) {\n // New format: nested projection object\n projectionId = territory.projection.id\n parameters = territory.projection.parameters\n }\n else if (territory.projectionId && territory.parameters) {\n // Legacy format: direct properties\n projectionId = territory.projectionId\n parameters = territory.parameters\n }\n else if (territory.projectionFamily && territory.parameters) {\n // Migration script format: has projectionFamily but missing projectionId\n // Try to infer projection ID from family and parameters\n projectionId = inferProjectionIdFromFamily(territory.projectionFamily as string, territory.parameters)\n parameters = territory.parameters\n }\n else {\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 - support both legacy (scale) and new (scaleMultiplier + referenceScale) formats\n if (projection.scale) {\n if (parameters.scale) {\n // Legacy format: use direct scale value\n projection.scale(parameters.scale)\n }\n else if (parameters.scaleMultiplier) {\n // New format: calculate scale from reference scale and multiplier\n const effectiveReferenceScale = referenceScale || 2700 // Default reference scale\n const calculatedScale = effectiveReferenceScale * parameters.scaleMultiplier\n projection.scale(calculatedScale)\n }\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 parameter-level translate (additional adjustment)\n if (parameters.translate && projection.translate) {\n const currentTranslate = projection.translate()\n const [additionalX, additionalY] = parameters.translate\n projection.translate([\n currentTranslate[0] + additionalX,\n currentTranslate[1] + additionalY,\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.clipExtent && projection.clipExtent) {\n projection.clipExtent(layout.clipExtent)\n }\n else if (projection.clipExtent) {\n // If no clip extent is specified, create a default one based on territory bounds\n // This prevents the projection from processing geometry outside its area\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 // This is a simplified approach - in practice, you'd want more precise clipping\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 projection info in either format\n const hasLegacyFormat = territory.projectionId && territory.parameters\n const hasNewFormat = territory.projection && territory.projection.id && territory.projection.parameters\n const hasIncompleteFormat = territory.projectionFamily && territory.parameters // Migration script format\n\n if (!hasLegacyFormat && !hasNewFormat && !hasIncompleteFormat) {\n throw new Error(`Territory ${territory.code} missing projection configuration. Available fields: ${Object.keys(territory).join(', ')}`)\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.3",
4
+ "version": "1.1.0-rc.5",
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",