geoplegma-js 0.0.2-beta → 0.0.3-beta
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.cjs +15 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/native/napi.node +0 -0
- package/package.json +8 -6
package/dist/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
const module$1 = __toESM(require("module"));
|
|
25
25
|
const url = __toESM(require("url"));
|
|
26
26
|
const path = __toESM(require("path"));
|
|
27
|
+
const fs = __toESM(require("fs"));
|
|
27
28
|
|
|
28
29
|
//#region src/utils.ts
|
|
29
30
|
function decodeZones(zones) {
|
|
@@ -79,9 +80,20 @@ function decodeNeighbors(jsZones, zoneIndex) {
|
|
|
79
80
|
|
|
80
81
|
//#endregion
|
|
81
82
|
//#region src/native-loader.ts
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
83
|
+
if (typeof process === "undefined" || !process.versions?.node) throw new Error("geoplegma-js requires Node.js");
|
|
84
|
+
const __filename$1 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
85
|
+
const __dirname$1 = path.default.dirname(__filename$1);
|
|
86
|
+
const addonPath = path.default.join(__dirname$1, "native", "napi.node");
|
|
87
|
+
if (!(0, fs.existsSync)(addonPath)) throw new Error(`Native addon not found at: ${addonPath}`);
|
|
88
|
+
let bindings;
|
|
89
|
+
try {
|
|
90
|
+
const require$1 = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
91
|
+
bindings = require$1(addonPath);
|
|
92
|
+
} catch (requireError) {
|
|
93
|
+
const module$2 = { exports: {} };
|
|
94
|
+
process.dlopen(module$2, addonPath);
|
|
95
|
+
bindings = module$2.exports;
|
|
96
|
+
}
|
|
85
97
|
var native_loader_default = bindings;
|
|
86
98
|
|
|
87
99
|
//#endregion
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["zones: any","decodedZones: any","jsZones: any","zoneIndex: any","__dirname","require","bindings","name: string","refinement_level: number","bbox?: number[][]","config?: Config","point?: number[]","relative_depth: number","parentZoneId: string","zoneId: string"],"sources":["../src/utils.ts","../src/native-loader.ts","../src/extend.ts"],"sourcesContent":["// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\n// for now the type is `any`, I will add other types in other PRs\nexport function decodeZones(zones: any) {\n const decodedZones: any = [];\n const bufferIds = Buffer.from(zones.utf8Ids);\n const bufferCoords = new Float64Array(zones.regionCoords);\n\n for (let i = 0; i < zones.idOffsets.length; i++) {\n const start = zones.idOffsets[i];\n const end =\n i + 1 < zones.idOffsets.length\n ? zones.idOffsets[i + 1]\n : bufferIds.length;\n const id = new TextDecoder(\"utf-8\").decode(bufferIds.subarray(start, end));\n\n // region coords\n const vertexCount = zones.vertexCount[i];\n const regionStart = zones.regionOffsets[i];\n const bufferRegion = bufferCoords.subarray(\n regionStart,\n regionStart + vertexCount * 2\n );\n const region = [];\n for (let j = 0; j < bufferRegion.length; j += 2) {\n region.push([bufferRegion[j], bufferRegion[j + 1]]);\n }\n\n // children\n const children = decodeChildren(zones, i);\n\n // neighbors\n const neighbors = decodeNeighbors(zones, i);\n\n decodedZones.push({\n id,\n center: [zones.centerX[i], zones.centerY[i]],\n vertexCount,\n region,\n children,\n neighbors,\n });\n }\n\n return decodedZones;\n}\n\nexport function decodeChildren(jsZones: any, zoneIndex: any) {\n const children = [];\n const start = jsZones.childrenOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.childrenOffsets.length\n ? jsZones.childrenOffsets[zoneIndex + 1]\n : jsZones.childrenIdOffsets.length;\n const buffer = new Float64Array(jsZones.childrenUtf8Ids);\n\n // childrenOffsets -> [0, 6, 12,...]\n // childrenIdOffsets -> [0, 18, 36,...]\n for (let i = start; i < end; i++) {\n const childStart = jsZones.childrenIdOffsets[i];\n const childEnd =\n i + 1 < jsZones.childrenIdOffsets.length\n ? jsZones.childrenIdOffsets[i + 1]\n : jsZones.childrenUtf8Ids.length;\n children.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(childStart, childEnd))\n );\n }\n\n return children;\n}\n\nexport function decodeNeighbors(jsZones: any, zoneIndex: any) {\n const neighbors = [];\n const start = jsZones.neighborsOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.neighborsOffsets.length\n ? jsZones.neighborsOffsets[zoneIndex + 1]\n : jsZones.neighborsIdOffsets.length;\n\n const buffer = new Float64Array(jsZones.neighborsUtf8Ids);\n for (let i = start; i < end; i++) {\n const nStart = jsZones.neighborsIdOffsets[i];\n const nEnd =\n i + 1 < jsZones.neighborsIdOffsets.length\n ? jsZones.neighborsIdOffsets[i + 1]\n : jsZones.neighborsUtf8Ids.length;\n neighbors.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(nStart, nEnd))\n );\n }\n return neighbors;\n}\n","// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\nimport { createRequire } from \"module\";\nimport { fileURLToPath } from \"url\";\nimport path from \"path\";\n\nconst
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["zones: any","decodedZones: any","jsZones: any","zoneIndex: any","__filename","__dirname","require","module","bindings","name: string","refinement_level: number","bbox?: number[][]","config?: Config","point?: number[]","relative_depth: number","parentZoneId: string","zoneId: string"],"sources":["../src/utils.ts","../src/native-loader.ts","../src/extend.ts"],"sourcesContent":["// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\n// for now the type is `any`, I will add other types in other PRs\nexport function decodeZones(zones: any) {\n const decodedZones: any = [];\n const bufferIds = Buffer.from(zones.utf8Ids);\n const bufferCoords = new Float64Array(zones.regionCoords);\n\n for (let i = 0; i < zones.idOffsets.length; i++) {\n const start = zones.idOffsets[i];\n const end =\n i + 1 < zones.idOffsets.length\n ? zones.idOffsets[i + 1]\n : bufferIds.length;\n const id = new TextDecoder(\"utf-8\").decode(bufferIds.subarray(start, end));\n\n // region coords\n const vertexCount = zones.vertexCount[i];\n const regionStart = zones.regionOffsets[i];\n const bufferRegion = bufferCoords.subarray(\n regionStart,\n regionStart + vertexCount * 2\n );\n const region = [];\n for (let j = 0; j < bufferRegion.length; j += 2) {\n region.push([bufferRegion[j], bufferRegion[j + 1]]);\n }\n\n // children\n const children = decodeChildren(zones, i);\n\n // neighbors\n const neighbors = decodeNeighbors(zones, i);\n\n decodedZones.push({\n id,\n center: [zones.centerX[i], zones.centerY[i]],\n vertexCount,\n region,\n children,\n neighbors,\n });\n }\n\n return decodedZones;\n}\n\nexport function decodeChildren(jsZones: any, zoneIndex: any) {\n const children = [];\n const start = jsZones.childrenOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.childrenOffsets.length\n ? jsZones.childrenOffsets[zoneIndex + 1]\n : jsZones.childrenIdOffsets.length;\n const buffer = new Float64Array(jsZones.childrenUtf8Ids);\n\n // childrenOffsets -> [0, 6, 12,...]\n // childrenIdOffsets -> [0, 18, 36,...]\n for (let i = start; i < end; i++) {\n const childStart = jsZones.childrenIdOffsets[i];\n const childEnd =\n i + 1 < jsZones.childrenIdOffsets.length\n ? jsZones.childrenIdOffsets[i + 1]\n : jsZones.childrenUtf8Ids.length;\n children.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(childStart, childEnd))\n );\n }\n\n return children;\n}\n\nexport function decodeNeighbors(jsZones: any, zoneIndex: any) {\n const neighbors = [];\n const start = jsZones.neighborsOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.neighborsOffsets.length\n ? jsZones.neighborsOffsets[zoneIndex + 1]\n : jsZones.neighborsIdOffsets.length;\n\n const buffer = new Float64Array(jsZones.neighborsUtf8Ids);\n for (let i = start; i < end; i++) {\n const nStart = jsZones.neighborsIdOffsets[i];\n const nEnd =\n i + 1 < jsZones.neighborsIdOffsets.length\n ? jsZones.neighborsIdOffsets[i + 1]\n : jsZones.neighborsUtf8Ids.length;\n neighbors.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(nStart, nEnd))\n );\n }\n return neighbors;\n}\n","// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\nimport { createRequire } from \"module\";\nimport { fileURLToPath } from \"url\";\nimport path from \"path\";\nimport { existsSync } from \"fs\";\n\nif (typeof process === 'undefined' || !process.versions?.node) {\n throw new Error('geoplegma-js requires Node.js');\n}\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst addonPath = path.join(__dirname, 'native', 'napi.node');\n\nif (!existsSync(addonPath)) {\n throw new Error(`Native addon not found at: ${addonPath}`);\n}\n\nlet bindings;\n\ntry {\n const require = createRequire(import.meta.url);\n bindings = require(addonPath);\n} catch (requireError) {\n // Fallback to process.dlopen for ESM compatibility\n const module = { exports: {} };\n process.dlopen(module, addonPath);\n bindings = module.exports;\n}\n\nexport default bindings;\n","// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\nimport { decodeZones } from \"./utils\";\n\nimport bindings from \"./native-loader\";\n\nconst { Dggrs: Aux } = bindings;\n\ninterface Config {\n region: boolean;\n center: boolean;\n vertexCount: boolean;\n children: boolean;\n neighbors: boolean;\n areaSqm: boolean;\n densify: boolean;\n}\n\nexport class Dggrs extends Aux {\n constructor(name: string) {\n super(name);\n }\n zonesFromBbox(refinement_level: number, bbox?: number[][], config?: Config) {\n return decodeZones(super.zonesFromBbox(refinement_level, bbox, config));\n }\n zoneFromPoint(refinement_level: number, point?: number[], config?: Config) {\n return decodeZones(super.zoneFromPoint(refinement_level, point, config));\n }\n zonesFromParent(\n relative_depth: number,\n parentZoneId: string,\n config?: Config\n ): any {\n return decodeZones(\n super.zonesFromParent(relative_depth, parentZoneId, config)\n );\n }\n zoneFromId(zoneId: string, config?: Config): any {\n return decodeZones(super.zoneFromId(zoneId, config));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAgB,YAAYA,OAAY;CACtC,MAAMC,eAAoB,CAAE;CAC5B,MAAM,YAAY,OAAO,KAAK,MAAM,QAAQ;CAC5C,MAAM,eAAe,IAAI,aAAa,MAAM;AAE5C,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,UAAU,QAAQ,KAAK;EAC/C,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AC,cACAH,QACK;AACL,SAAO,YACL,MAAM,gBAAgB,gBAAgB,cAAc,OAAO,CAC5D;CACF;CACD,WAAWI,QAAgBJ,QAAsB;AAC/C,SAAO,YAAY,MAAM,WAAW,QAAQ,OAAO,CAAC;CACrD;AACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "module";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import { existsSync } from "fs";
|
|
4
5
|
|
|
5
6
|
//#region src/utils.ts
|
|
6
7
|
function decodeZones(zones) {
|
|
@@ -56,9 +57,20 @@ function decodeNeighbors(jsZones, zoneIndex) {
|
|
|
56
57
|
|
|
57
58
|
//#endregion
|
|
58
59
|
//#region src/native-loader.ts
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
60
|
+
if (typeof process === "undefined" || !process.versions?.node) throw new Error("geoplegma-js requires Node.js");
|
|
61
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
62
|
+
const __dirname = path.dirname(__filename);
|
|
63
|
+
const addonPath = path.join(__dirname, "native", "napi.node");
|
|
64
|
+
if (!existsSync(addonPath)) throw new Error(`Native addon not found at: ${addonPath}`);
|
|
65
|
+
let bindings;
|
|
66
|
+
try {
|
|
67
|
+
const require = createRequire(import.meta.url);
|
|
68
|
+
bindings = require(addonPath);
|
|
69
|
+
} catch (requireError) {
|
|
70
|
+
const module = { exports: {} };
|
|
71
|
+
process.dlopen(module, addonPath);
|
|
72
|
+
bindings = module.exports;
|
|
73
|
+
}
|
|
62
74
|
var native_loader_default = bindings;
|
|
63
75
|
|
|
64
76
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["zones: any","decodedZones: any","jsZones: any","zoneIndex: any","bindings","name: string","refinement_level: number","bbox?: number[][]","config?: Config","point?: number[]","relative_depth: number","parentZoneId: string","zoneId: string"],"sources":["../src/utils.ts","../src/native-loader.ts","../src/extend.ts"],"sourcesContent":["// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\n// for now the type is `any`, I will add other types in other PRs\nexport function decodeZones(zones: any) {\n const decodedZones: any = [];\n const bufferIds = Buffer.from(zones.utf8Ids);\n const bufferCoords = new Float64Array(zones.regionCoords);\n\n for (let i = 0; i < zones.idOffsets.length; i++) {\n const start = zones.idOffsets[i];\n const end =\n i + 1 < zones.idOffsets.length\n ? zones.idOffsets[i + 1]\n : bufferIds.length;\n const id = new TextDecoder(\"utf-8\").decode(bufferIds.subarray(start, end));\n\n // region coords\n const vertexCount = zones.vertexCount[i];\n const regionStart = zones.regionOffsets[i];\n const bufferRegion = bufferCoords.subarray(\n regionStart,\n regionStart + vertexCount * 2\n );\n const region = [];\n for (let j = 0; j < bufferRegion.length; j += 2) {\n region.push([bufferRegion[j], bufferRegion[j + 1]]);\n }\n\n // children\n const children = decodeChildren(zones, i);\n\n // neighbors\n const neighbors = decodeNeighbors(zones, i);\n\n decodedZones.push({\n id,\n center: [zones.centerX[i], zones.centerY[i]],\n vertexCount,\n region,\n children,\n neighbors,\n });\n }\n\n return decodedZones;\n}\n\nexport function decodeChildren(jsZones: any, zoneIndex: any) {\n const children = [];\n const start = jsZones.childrenOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.childrenOffsets.length\n ? jsZones.childrenOffsets[zoneIndex + 1]\n : jsZones.childrenIdOffsets.length;\n const buffer = new Float64Array(jsZones.childrenUtf8Ids);\n\n // childrenOffsets -> [0, 6, 12,...]\n // childrenIdOffsets -> [0, 18, 36,...]\n for (let i = start; i < end; i++) {\n const childStart = jsZones.childrenIdOffsets[i];\n const childEnd =\n i + 1 < jsZones.childrenIdOffsets.length\n ? jsZones.childrenIdOffsets[i + 1]\n : jsZones.childrenUtf8Ids.length;\n children.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(childStart, childEnd))\n );\n }\n\n return children;\n}\n\nexport function decodeNeighbors(jsZones: any, zoneIndex: any) {\n const neighbors = [];\n const start = jsZones.neighborsOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.neighborsOffsets.length\n ? jsZones.neighborsOffsets[zoneIndex + 1]\n : jsZones.neighborsIdOffsets.length;\n\n const buffer = new Float64Array(jsZones.neighborsUtf8Ids);\n for (let i = start; i < end; i++) {\n const nStart = jsZones.neighborsIdOffsets[i];\n const nEnd =\n i + 1 < jsZones.neighborsIdOffsets.length\n ? jsZones.neighborsIdOffsets[i + 1]\n : jsZones.neighborsUtf8Ids.length;\n neighbors.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(nStart, nEnd))\n );\n }\n return neighbors;\n}\n","// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\nimport { createRequire } from \"module\";\nimport { fileURLToPath } from \"url\";\nimport path from \"path\";\n\nconst
|
|
1
|
+
{"version":3,"file":"index.js","names":["zones: any","decodedZones: any","jsZones: any","zoneIndex: any","bindings","name: string","refinement_level: number","bbox?: number[][]","config?: Config","point?: number[]","relative_depth: number","parentZoneId: string","zoneId: string"],"sources":["../src/utils.ts","../src/native-loader.ts","../src/extend.ts"],"sourcesContent":["// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\n// for now the type is `any`, I will add other types in other PRs\nexport function decodeZones(zones: any) {\n const decodedZones: any = [];\n const bufferIds = Buffer.from(zones.utf8Ids);\n const bufferCoords = new Float64Array(zones.regionCoords);\n\n for (let i = 0; i < zones.idOffsets.length; i++) {\n const start = zones.idOffsets[i];\n const end =\n i + 1 < zones.idOffsets.length\n ? zones.idOffsets[i + 1]\n : bufferIds.length;\n const id = new TextDecoder(\"utf-8\").decode(bufferIds.subarray(start, end));\n\n // region coords\n const vertexCount = zones.vertexCount[i];\n const regionStart = zones.regionOffsets[i];\n const bufferRegion = bufferCoords.subarray(\n regionStart,\n regionStart + vertexCount * 2\n );\n const region = [];\n for (let j = 0; j < bufferRegion.length; j += 2) {\n region.push([bufferRegion[j], bufferRegion[j + 1]]);\n }\n\n // children\n const children = decodeChildren(zones, i);\n\n // neighbors\n const neighbors = decodeNeighbors(zones, i);\n\n decodedZones.push({\n id,\n center: [zones.centerX[i], zones.centerY[i]],\n vertexCount,\n region,\n children,\n neighbors,\n });\n }\n\n return decodedZones;\n}\n\nexport function decodeChildren(jsZones: any, zoneIndex: any) {\n const children = [];\n const start = jsZones.childrenOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.childrenOffsets.length\n ? jsZones.childrenOffsets[zoneIndex + 1]\n : jsZones.childrenIdOffsets.length;\n const buffer = new Float64Array(jsZones.childrenUtf8Ids);\n\n // childrenOffsets -> [0, 6, 12,...]\n // childrenIdOffsets -> [0, 18, 36,...]\n for (let i = start; i < end; i++) {\n const childStart = jsZones.childrenIdOffsets[i];\n const childEnd =\n i + 1 < jsZones.childrenIdOffsets.length\n ? jsZones.childrenIdOffsets[i + 1]\n : jsZones.childrenUtf8Ids.length;\n children.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(childStart, childEnd))\n );\n }\n\n return children;\n}\n\nexport function decodeNeighbors(jsZones: any, zoneIndex: any) {\n const neighbors = [];\n const start = jsZones.neighborsOffsets[zoneIndex];\n const end =\n zoneIndex + 1 < jsZones.neighborsOffsets.length\n ? jsZones.neighborsOffsets[zoneIndex + 1]\n : jsZones.neighborsIdOffsets.length;\n\n const buffer = new Float64Array(jsZones.neighborsUtf8Ids);\n for (let i = start; i < end; i++) {\n const nStart = jsZones.neighborsIdOffsets[i];\n const nEnd =\n i + 1 < jsZones.neighborsIdOffsets.length\n ? jsZones.neighborsIdOffsets[i + 1]\n : jsZones.neighborsUtf8Ids.length;\n neighbors.push(\n new TextDecoder(\"utf-8\").decode(buffer.subarray(nStart, nEnd))\n );\n }\n return neighbors;\n}\n","// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\nimport { createRequire } from \"module\";\nimport { fileURLToPath } from \"url\";\nimport path from \"path\";\nimport { existsSync } from \"fs\";\n\nif (typeof process === 'undefined' || !process.versions?.node) {\n throw new Error('geoplegma-js requires Node.js');\n}\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst addonPath = path.join(__dirname, 'native', 'napi.node');\n\nif (!existsSync(addonPath)) {\n throw new Error(`Native addon not found at: ${addonPath}`);\n}\n\nlet bindings;\n\ntry {\n const require = createRequire(import.meta.url);\n bindings = require(addonPath);\n} catch (requireError) {\n // Fallback to process.dlopen for ESM compatibility\n const module = { exports: {} };\n process.dlopen(module, addonPath);\n bindings = module.exports;\n}\n\nexport default bindings;\n","// Copyright 2025 contributors to the GeoPlegma project.\n// Originally authored by João Manuel (GeoInsight GmbH, joao.manuel@geoinsight.ai)\n//\n// Licenced under the Apache Licence, Version 2.0 <LICENCE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENCE-MIT or http://opensource.org/licenses/MIT>, at your\n// discretion. This file may not be copied, modified, or distributed\n// except according to those terms.\n\nimport { decodeZones } from \"./utils\";\n\nimport bindings from \"./native-loader\";\n\nconst { Dggrs: Aux } = bindings;\n\ninterface Config {\n region: boolean;\n center: boolean;\n vertexCount: boolean;\n children: boolean;\n neighbors: boolean;\n areaSqm: boolean;\n densify: boolean;\n}\n\nexport class Dggrs extends Aux {\n constructor(name: string) {\n super(name);\n }\n zonesFromBbox(refinement_level: number, bbox?: number[][], config?: Config) {\n return decodeZones(super.zonesFromBbox(refinement_level, bbox, config));\n }\n zoneFromPoint(refinement_level: number, point?: number[], config?: Config) {\n return decodeZones(super.zoneFromPoint(refinement_level, point, config));\n }\n zonesFromParent(\n relative_depth: number,\n parentZoneId: string,\n config?: Config\n ): any {\n return decodeZones(\n super.zonesFromParent(relative_depth, parentZoneId, config)\n );\n }\n zoneFromId(zoneId: string, config?: Config): any {\n return decodeZones(super.zoneFromId(zoneId, config));\n }\n}\n"],"mappings":";;;;;;AAUA,SAAgB,YAAYA,OAAY;CACtC,MAAMC,eAAoB,CAAE;CAC5B,MAAM,YAAY,OAAO,KAAK,MAAM,QAAQ;CAC5C,MAAM,eAAe,IAAI,aAAa,MAAM;AAE5C,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,UAAU,QAAQ,KAAK;EAC/C,MAAM,QAAQ,MAAM,UAAU;EAC9B,MAAM,MACJ,IAAI,IAAI,MAAM,UAAU,SACpB,MAAM,UAAU,IAAI,KACpB,UAAU;EAChB,MAAM,KAAK,IAAI,YAAY,SAAS,OAAO,UAAU,SAAS,OAAO,IAAI,CAAC;EAG1E,MAAM,cAAc,MAAM,YAAY;EACtC,MAAM,cAAc,MAAM,cAAc;EACxC,MAAM,eAAe,aAAa,SACh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
|
1
1
|
{
|
|
2
2
|
"name": "geoplegma-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-beta",
|
|
4
4
|
"description": "A JavaScript library for GeoPlegma.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,14 +14,16 @@
|
|
|
14
14
|
},
|
|
15
15
|
"author": "João Manuel <joaocsmanuel@gmail.com>",
|
|
16
16
|
"files": [
|
|
17
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"native/*.node"
|
|
18
19
|
],
|
|
19
|
-
"main": "./dist/index.
|
|
20
|
-
"module": "./dist/index.mjs",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"node": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
}
|
|
25
27
|
},
|
|
26
28
|
"publishConfig": {
|
|
27
29
|
"access": "public"
|