@dirkwa/s-100 0.0.0-stage → 0.0.1

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/lua/host.lua ADDED
@@ -0,0 +1,182 @@
1
+ -- S-100 Part 9a host functions over the DS (dataset) and FC (feature catalogue) tables.
2
+
3
+ local UNKNOWN = '13BD40516CF742E886D5B4125DBB89742A043D0050E44B568CBB1FDDA8B464FF'
4
+ local KIND_NAME = { 'Point', 'MultiPoint', 'Curve', 'CompositeCurve', 'Surface' }
5
+
6
+ OUT = {}
7
+ ERRORS = {}
8
+
9
+ local function keys(t)
10
+ local r = {}
11
+ for k in pairs(t) do r[#r + 1] = k end
12
+ table.sort(r)
13
+ return r
14
+ end
15
+
16
+ local function container(attrs, path)
17
+ if path == nil or path == '' then return attrs end
18
+ local cur = attrs
19
+ for code, idx in string.gmatch(path, '([^:;]+):(%d+)') do
20
+ idx = tonumber(idx)
21
+ local n, found = 0, nil
22
+ for _, a in ipairs(cur) do
23
+ if a.c == code then
24
+ n = n + 1
25
+ if n == idx then found = a break end
26
+ end
27
+ end
28
+ if not found then return {} end
29
+ cur = found.k or {}
30
+ end
31
+ return cur
32
+ end
33
+
34
+ local function simpleValues(attrs, path, code)
35
+ local r = {}
36
+ for _, a in ipairs(container(attrs, path)) do
37
+ if a.c == code and not a.k then
38
+ r[#r + 1] = (a.v == '' and UNKNOWN) or a.v
39
+ end
40
+ end
41
+ return r
42
+ end
43
+
44
+ local function complexCount(attrs, path, code)
45
+ local n = 0
46
+ for _, a in ipairs(container(attrs, path)) do
47
+ if a.c == code then n = n + 1 end
48
+ end
49
+ return n
50
+ end
51
+
52
+ local function assocIds(list, assoc, role)
53
+ local r = {}
54
+ for _, x in ipairs(list or {}) do
55
+ if x.a == assoc and (role == nil or x.r == role) then r[#r + 1] = x.i end
56
+ end
57
+ return r
58
+ end
59
+
60
+ local function kindOf(sid) return string.match(sid, '^([^|]+)') end
61
+
62
+ local function orientation(o)
63
+ if o == 1 then return 'Forward' elseif o == 2 then return 'Reverse' end
64
+ return nil
65
+ end
66
+
67
+ local function spatialAssociation(ref)
68
+ return CreateSpatialAssociation(kindOf(ref.s), ref.s, orientation(ref.o), ref.mn, ref.mx)
69
+ end
70
+
71
+ local function point(x, y, z)
72
+ return CreatePoint(tostring(x), tostring(y), z and tostring(z) or nil)
73
+ end
74
+
75
+ function HostGetFeatureIDs() return DS.FI end
76
+ function HostFeatureGetCode(id) return DS.F[id].c end
77
+ function HostGetInformationTypeIDs() return keys(DS.I) end
78
+ function HostInformationTypeGetCode(id) return DS.I[id].c end
79
+
80
+ function HostFeatureGetSimpleAttribute(id, path, code) return simpleValues(DS.F[id].a, path, code) end
81
+ function HostFeatureGetComplexAttributeCount(id, path, code) return complexCount(DS.F[id].a, path, code) end
82
+ function HostInformationTypeGetSimpleAttribute(id, path, code) return simpleValues(DS.I[id].a, path, code) end
83
+ function HostInformationTypeGetComplexAttributeCount(id, path, code) return complexCount(DS.I[id].a, path, code) end
84
+
85
+ function HostFeatureGetSpatialAssociations(id)
86
+ local r = {}
87
+ for _, ref in ipairs(DS.F[id].sp) do r[#r + 1] = spatialAssociation(ref) end
88
+ return r
89
+ end
90
+
91
+ function HostFeatureGetAssociatedFeatureIDs(id, assoc, role) return assocIds(DS.F[id].fa, assoc, role) end
92
+ function HostFeatureGetAssociatedInformationIDs(id, assoc, role) return assocIds(DS.F[id].ia, assoc, role) end
93
+
94
+ function HostGetSpatialIDs() return keys(DS.SP) end
95
+
96
+ function HostGetSpatial(sid)
97
+ local s = DS.SP[sid]
98
+ if not s then return nil end
99
+ if s.k == 1 then
100
+ return point(s.x, s.y, s.z)
101
+ elseif s.k == 2 then
102
+ local pts = {}
103
+ local p = s.p
104
+ for i = 1, #p, 3 do
105
+ local z = p[i + 2]
106
+ pts[#pts + 1] = point(p[i], p[i + 1], (z == z) and z or nil)
107
+ end
108
+ return CreateMultiPoint(pts)
109
+ elseif s.k == 3 then
110
+ local cps = {}
111
+ local xy = s.xy or {}
112
+ for i = 1, #xy, 2 do cps[#cps + 1] = point(xy[i], xy[i + 1]) end
113
+ local b = s.b and CreateSpatialAssociation('Point', 'Point|' .. s.b) or nil
114
+ local e = s.e and CreateSpatialAssociation('Point', 'Point|' .. s.e) or nil
115
+ return CreateCurve(b, e, { CreateCurveSegment(cps, 'Loxodromic') })
116
+ elseif s.k == 4 then
117
+ local r = {}
118
+ for _, ref in ipairs(s.r) do r[#r + 1] = spatialAssociation(ref) end
119
+ return CreateCompositeCurve(r)
120
+ elseif s.k == 5 then
121
+ local outer, inner = nil, {}
122
+ for _, ref in ipairs(s.r) do
123
+ if ref.u == 1 then outer = spatialAssociation(ref) else inner[#inner + 1] = spatialAssociation(ref) end
124
+ end
125
+ return CreateSurface(outer, inner)
126
+ end
127
+ end
128
+
129
+ function HostSpatialGetAssociatedInformationIDs(sid, assoc, role)
130
+ local s = DS.SP[sid]
131
+ return assocIds(s and s.ia, assoc, role)
132
+ end
133
+
134
+ function HostSpatialGetAssociatedFeatureIDs(sid) return DS.SF[sid] or {} end
135
+
136
+ function HostGetFeatureTypeCodes() return keys(FC.F) end
137
+ function HostGetInformationTypeCodes() return keys(FC.I) end
138
+ function HostGetSimpleAttributeTypeCodes() return keys(FC.S) end
139
+ function HostGetComplexAttributeTypeCodes() return keys(FC.C) end
140
+ function HostGetRoleTypeCodes() return FC.R end
141
+ function HostGetInformationAssociationTypeCodes() return FC.IA end
142
+ function HostGetFeatureAssociationTypeCodes() return FC.FA end
143
+
144
+ local function bindings(b)
145
+ local r = {}
146
+ for code, upper in pairs(b or {}) do
147
+ r[code] = { Type = 'AttributeBinding', AttributeCode = code, LowerMultiplicity = 0, UpperMultiplicity = upper or nil, Sequential = false, PermittedValues = {} }
148
+ end
149
+ return r
150
+ end
151
+
152
+ function HostGetFeatureTypeInfo(code)
153
+ if not FC.F[code] then return nil end
154
+ return { Type = 'FeatureType', Code = code, AttributeBindings = bindings(FC.F[code]) }
155
+ end
156
+
157
+ function HostGetInformationTypeInfo(code)
158
+ return { Type = 'InformationType', Code = code, AttributeBindings = bindings(FC.I[code]) }
159
+ end
160
+
161
+ function HostGetSimpleAttributeTypeInfo(code)
162
+ return { Type = 'SimpleAttribute', Code = code, ValueType = FC.S[code] }
163
+ end
164
+
165
+ function HostGetComplexAttributeTypeInfo(code)
166
+ return { Type = 'ComplexAttribute', Code = code, AttributeBindings = bindings(FC.C[code]) }
167
+ end
168
+
169
+ function HostSpatialRelate() error('HostSpatialRelate is not supported') end
170
+
171
+ function HostDebuggerEntry(action, message)
172
+ if action == 'trace' and type(message) == 'string' and string.sub(message, 1, 5) == 'Error' then
173
+ ERRORS[#ERRORS + 1] = message
174
+ elseif action == 'first_chance_error' then
175
+ ERRORS[#ERRORS + 1] = tostring(message)
176
+ end
177
+ end
178
+
179
+ function HostPortrayalEmit(featureReference, drawingInstructions, observed)
180
+ OUT[#OUT + 1] = featureReference .. '\t' .. drawingInstructions
181
+ return true
182
+ end
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@dirkwa/s-100",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "S-100 reader and IHO portrayal for Signal K plotters and chart providers",
5
+ "license": "Apache-2.0",
6
+ "keywords": [
7
+ "s-100",
8
+ "s-101",
9
+ "enc",
10
+ "iho",
11
+ "nautical-chart",
12
+ "ecdis",
13
+ "signalk"
14
+ ],
15
+ "homepage": "https://github.com/dirkwa/s-100#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/dirkwa/s-100/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/dirkwa/s-100.git"
22
+ },
23
+ "type": "module",
24
+ "exports": {
25
+ "./*": {
26
+ "types": "./dist/*.d.ts",
27
+ "default": "./dist/*.js"
28
+ },
29
+ "./lua/host.lua": "./lua/host.lua",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "lua"
35
+ ],
36
+ "engines": {
37
+ "node": ">=22.18"
38
+ },
39
+ "scripts": {
40
+ "assets": "node tools/build-assets.ts $S101_PC data/fc-s101.json demo/assets",
41
+ "fc": "python3 tools/fc2json.py $S101_FC data/fc-s101.json",
42
+ "demo:build": "esbuild demo/main.ts src/worker.ts --bundle --format=esm --platform=browser --target=es2022 --outdir=demo --entry-names=[name] --external:module --external:fs --external:path --external:url --external:child_process --external:crypto && cp node_modules/wasmoon/dist/glue.wasm node_modules/ol/ol.css demo/",
43
+ "demo": "npm run demo:build && cd demo && python3 -m http.server 8765",
44
+ "typecheck": "tsc --noEmit",
45
+ "format": "prettier --write . && eslint --fix .",
46
+ "ci-lint": "eslint . && prettier --check .",
47
+ "test": "node --test test/*.test.ts",
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "prepack": "npm run build"
50
+ },
51
+ "dependencies": {
52
+ "wasmoon": "^1.16.0"
53
+ },
54
+ "peerDependencies": {
55
+ "ol": "^10.11.0"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "ol": {
59
+ "optional": true
60
+ }
61
+ },
62
+ "devDependencies": {
63
+ "@eslint/js": "^10.0.1",
64
+ "@types/node": "^22.20.7",
65
+ "esbuild": "^0.28.2",
66
+ "eslint": "^10.16.0",
67
+ "eslint-config-prettier": "^10.1.9",
68
+ "eslint-plugin-prettier": "^5.5.7",
69
+ "jiti": "^2.7.0",
70
+ "ol": "^10.11.0",
71
+ "prettier": "^3.10.2",
72
+ "typescript": "5.9",
73
+ "typescript-eslint": "^8.74.0"
74
+ }
75
+ }