@kispace-io/gs-lib 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,8 +20,9 @@ export declare const toOlStyle: (gsStyle: GsStyle) => Style;
20
20
  export declare const toOlFeature: (feature: GsFeature) => Feature;
21
21
  export declare const OL_SOURCES: any;
22
22
  export declare const toOlSource: (source: GsSource, olLayer?: TileLayer<TileSource>) => any;
23
+ export declare const resolveScriptLang: (src: string, lang?: string) => string;
23
24
  export declare const OL_LAYERS: any;
24
- export declare const toOlLayer: (layer: GsLayer) => BaseLayer;
25
+ export declare const toOlLayer: (layer: GsLayer, env?: any) => BaseLayer;
25
26
  export declare class GsOlControl extends Control {
26
27
  constructor(options?: any);
27
28
  getElement(): HTMLElement;
@@ -1 +1 @@
1
- {"version":3,"file":"gs-gs2ol.d.ts","sourceRoot":"","sources":["../../src/ol/gs-gs2ol.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,SAAS,EACT,SAAS,EACT,WAAW,EACX,UAAU,EACV,MAAM,EACN,YAAY,EACZ,OAAO,EAEP,KAAK,EACL,SAAS,EACT,QAAQ,EAGR,aAAa,EACb,OAAO,EACP,WAAW,EAYd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAO,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAC;AAElC,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,EAAC,MAAM,IAAI,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAC,MAAM,UAAU,CAAC;AAO9F,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,UAAU,MAAM,gBAAgB,CAAC;AAExC,OAAO,SAAS,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAC,OAAO,EAAC,MAAM,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ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,IAAI,CAAC;AAC3B,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,EACH,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EAIf,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,gBAkBxC,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,iBAUzC,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,YAAY,YAAY,oGAMnD,CAAA;AAuBD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,GAAG,UAAU,CAKxE;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,aAI3C"}
@@ -0,0 +1,21 @@
1
+ export interface ScriptedVars {
2
+ params: Record<string, any>;
3
+ env: Record<string, string>;
4
+ viewState: {
5
+ extent: number[];
6
+ zoom: number;
7
+ projection: string;
8
+ };
9
+ signal?: AbortSignal;
10
+ }
11
+ export interface ScriptedRuntime {
12
+ run(src: string, vars: ScriptedVars): Promise<unknown>;
13
+ }
14
+ declare class ScriptedRuntimeRegistryImpl {
15
+ private runtimes;
16
+ register(lang: string, runtime: ScriptedRuntime): void;
17
+ get(lang: string): ScriptedRuntime | undefined;
18
+ }
19
+ export declare const scriptedRuntimeRegistry: ScriptedRuntimeRegistryImpl;
20
+ export {};
21
+ //# sourceMappingURL=scripted-runtime-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scripted-runtime-registry.d.ts","sourceRoot":"","sources":["../src/scripted-runtime-registry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3B,SAAS,EAAE;QAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;IACjE,MAAM,CAAC,EAAE,WAAW,CAAA;CACvB;AAED,MAAM,WAAW,eAAe;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACzD;AAED,cAAM,2BAA2B;IAC7B,OAAO,CAAC,QAAQ,CAAqC;IAErD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI;IAItD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;CAGjD;AAED,eAAO,MAAM,uBAAuB,6BAAoC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kispace-io/gs-lib",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "license": "EPL-2.0",
6
6
  "repository": {
@@ -39,7 +39,7 @@
39
39
  "uuid": "^11.1.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@kispace-io/appspace": "^1.0.0",
42
+ "@kispace-io/core": "*",
43
43
  "esbuild": "^0.27.0"
44
44
  },
45
45
  "publishConfig": {
package/src/gs-litns.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Re-export all Lit APIs from appspace's externals/lit module - single source of truth
2
- export * as lit from "@kispace-io/appspace/externals/lit";
2
+ export * as lit from "@kispace-io/core/externals/lit";
3
3
 
4
- import "@kispace-io/appspace/externals/webawesome";
4
+ import "@kispace-io/core/externals/webawesome";
5
5
 
package/src/gs-model.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { v4 as uuidv4 } from '@kispace-io/appspace/externals/third-party'
1
+ import { v4 as uuidv4 } from '@kispace-io/core/externals/third-party'
2
2
 
3
3
  export const KEY_LABEL = "label";
4
4
  export const KEY_NAME = "name";
@@ -71,11 +71,11 @@ export interface GsState {
71
71
  }
72
72
 
73
73
  export enum GsSourceType {
74
- OSM = "OSM", GeoJSON = "GeoJSON", Features = "Features", KML = "KML", GeoTIFF = "GeoTIFF", GPX = "GPX", BM = "BM", WMS = "WMS", WMTS = "WMTS", XYZ = "XYZ"
74
+ OSM = "OSM", GeoJSON = "GeoJSON", Features = "Features", KML = "KML", GeoTIFF = "GeoTIFF", GPX = "GPX", BM = "BM", WMS = "WMS", WMTS = "WMTS", XYZ = "XYZ", Scripted = "Scripted"
75
75
  }
76
76
 
77
77
  export enum GsLayerType {
78
- TILE = "TILE", VECTOR = "VECTOR", GROUP = "GROUP"
78
+ TILE = "TILE", VECTOR = "VECTOR", GROUP = "GROUP", SCRIPTED = "SCRIPTED"
79
79
  }
80
80
 
81
81
  export enum GsGeometryType {
@@ -118,6 +118,12 @@ export interface GsLayer extends GsState {
118
118
  visible?: boolean
119
119
  }
120
120
 
121
+ export interface GsScriptedVectorLayer extends GsLayer {
122
+ type: GsLayerType.SCRIPTED
123
+ lang?: string
124
+ params?: Record<string, any>
125
+ }
126
+
121
127
  export interface GsScript extends GsState {
122
128
  src: string,
123
129
  }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Core exports - renderer-agnostic model and utilities
2
2
  // For renderer-specific functionality, import from '@kispace-io/gs-lib/ol' or '@kispace-io/gs-lib/ml'
3
3
  export * from "./gs-model"
4
+ export * from "./scripted-runtime-registry"
4
5
 
5
6
  // Map renderer interface (no implementation)
6
7
  export * from "./map-renderer"
@@ -10,8 +10,8 @@ import {
10
10
  LayerSpecification,
11
11
  SourceSpecification
12
12
  } from 'maplibre-gl';
13
- import { v4 as uuidv4 } from '@kispace-io/appspace/externals/third-party';
14
- import { subscribe, publish } from '@kispace-io/appspace/core/events';
13
+ import { v4 as uuidv4 } from '@kispace-io/core/externals/third-party';
14
+ import { subscribe, publish } from '@kispace-io/core/core/events';
15
15
  import { GsMlControl, GsMlControlAdapter, GsMlOverlayAdapter } from './gs-ml-adapters';
16
16
 
17
17
  import {
@@ -1,5 +1,5 @@
1
1
  import { Map, Popup, IControl, LngLatLike } from 'maplibre-gl';
2
- import { render as litRender } from "@kispace-io/appspace/externals/lit";
2
+ import { render as litRender } from "@kispace-io/core/externals/lit";
3
3
 
4
4
  /**
5
5
  * MapLibre Control adapter for user modules
@@ -10,6 +10,7 @@ import {
10
10
  GsLayerType,
11
11
  GsMap,
12
12
  GsOverlay,
13
+ GsScriptedVectorLayer,
13
14
  GsSource,
14
15
  GsSourceType,
15
16
  GsState,
@@ -28,6 +29,7 @@ import {
28
29
  KEY_UUID,
29
30
  KEY_URL
30
31
  } from "../gs-model";
32
+ import { scriptedRuntimeRegistry, type ScriptedVars } from "../scripted-runtime-registry";
31
33
  import {Feature, Map, Overlay, View} from "ol";
32
34
  import {MapOptions} from "ol/Map";
33
35
  import BaseObject from "ol/Object";
@@ -38,6 +40,8 @@ import {optionsFromCapabilities} from "ol/source/WMTS";
38
40
  import FeatureFormat from "ol/format/Feature";
39
41
  import WMTSCapabilities from "ol/format/WMTSCapabilities";
40
42
  import VectorSource from "ol/source/Vector";
43
+ import {bbox} from "ol/loadingstrategy";
44
+ import {transformExtent} from "ol/proj";
41
45
  import {GeoJSON, GPX} from "ol/format";
42
46
  import TileLayer from "ol/layer/Tile";
43
47
  import TileSource from "ol/source/Tile";
@@ -48,8 +52,8 @@ import LayerGroup from "ol/layer/Group";
48
52
  import {Control} from "ol/control";
49
53
  import * as ol from "./gs-olns"
50
54
  import {lit} from "../gs-litns";
51
- import {v4 as uuidv4} from '@kispace-io/appspace/externals/third-party'
52
- import {subscribe, publish, unsubscribe} from '@kispace-io/appspace/core/events'
55
+ import {v4 as uuidv4} from '@kispace-io/core/externals/third-party'
56
+ import {subscribe, publish, unsubscribe} from '@kispace-io/core/core/events'
53
57
  import {GsControlAdapter, GsOverlayAdapter} from "./gs-ol-adapters";
54
58
  import {rtUtils} from "../index";
55
59
  import Layer from "ol/layer/Layer";
@@ -339,6 +343,13 @@ export const toOlSource = (source: GsSource, olLayer?: TileLayer<TileSource>) =>
339
343
  return withState(source, OL_SOURCES[source.type](source, olLayer))
340
344
  }
341
345
 
346
+ export const resolveScriptLang = (src: string, lang?: string): string => {
347
+ if (lang) return lang
348
+ const ext = src.split('?')[0].split('.').pop()?.toLowerCase() ?? ''
349
+ if (ext === 'py') return 'python'
350
+ return 'javascript'
351
+ }
352
+
342
353
  export const OL_LAYERS: any = {}
343
354
  OL_LAYERS[GsLayerType.TILE] = (layer: GsLayer) => {
344
355
  const tileLayer = new TileLayer()
@@ -358,8 +369,60 @@ OL_LAYERS[GsLayerType.GROUP] = (layer: GsLayer) => {
358
369
  applyMapboxStyle(group, layer.source.url).then()
359
370
  return group
360
371
  }
361
- export const toOlLayer = (layer: GsLayer) => {
362
- const olLayer: BaseLayer = withState(layer, OL_LAYERS[layer.type](layer))
372
+ OL_LAYERS[GsLayerType.SCRIPTED] = (layer: GsScriptedVectorLayer, env: any) => {
373
+ const src = layer.source.url!
374
+ const lang = resolveScriptLang(src, layer.lang)
375
+ const runtime = scriptedRuntimeRegistry.get(lang)
376
+ if (!runtime) throw new Error(`No scripted runtime registered for lang "${lang}"`)
377
+
378
+ let olVectorLayer: VectorLayer<VectorSource>
379
+ const source = new VectorSource({
380
+ loader: async (extent, resolution, projection, success, failure) => {
381
+ const view = olVectorLayer?.getMapInternal()?.getView()
382
+ const vars: ScriptedVars = {
383
+ params: layer.params ?? {},
384
+ env: env ?? {},
385
+ viewState: {
386
+ extent: transformExtent(extent, projection, 'EPSG:4326'),
387
+ zoom: view?.getZoomForResolution(resolution) ?? 0,
388
+ projection: 'EPSG:4326',
389
+ },
390
+ }
391
+ try {
392
+ const result = await runtime.run(src, vars)
393
+ const format = new GeoJSON()
394
+ source.clear()
395
+ const allFeatures: any[] = []
396
+ const readBatch = (data: any) => {
397
+ const features = format.readFeatures(data, {
398
+ dataProjection: 'EPSG:4326',
399
+ featureProjection: projection,
400
+ })
401
+ source.addFeatures(features)
402
+ allFeatures.push(...features)
403
+ }
404
+ if (result && typeof (result as any)[Symbol.asyncIterator] === 'function') {
405
+ for await (const batch of result as AsyncIterable<any>) {
406
+ readBatch(batch)
407
+ }
408
+ } else {
409
+ readBatch(result)
410
+ }
411
+ success!(allFeatures)
412
+ } catch (e) {
413
+ console.error('Scripted layer error:', e)
414
+ failure!()
415
+ }
416
+ },
417
+ strategy: bbox,
418
+ })
419
+
420
+ olVectorLayer = new VectorLayer({ source })
421
+ return olVectorLayer
422
+ }
423
+
424
+ export const toOlLayer = (layer: GsLayer, env?: any) => {
425
+ const olLayer: BaseLayer = withState(layer, OL_LAYERS[layer.type](layer, env))
363
426
  olLayer.set(KEY_LABEL, layer.type)
364
427
  olLayer.set(KEY_NAME, layer.name)
365
428
  olLayer.set(KEY_GS_MANAGED, true)
@@ -606,7 +669,7 @@ export const toOlMap = async (gsMap: GsMap, options?: MapOptions, env?: any, imp
606
669
  projection: gsMap.view.projection || DEFAULT_GSMAP.view.projection
607
670
  }))
608
671
  for (const layer of gsMap.layers || []) {
609
- const olLayer = toOlLayer(layer)
672
+ const olLayer = toOlLayer(layer, env)
610
673
  olMap.addLayer(olLayer)
611
674
  }
612
675
 
@@ -1,6 +1,6 @@
1
1
  import {Map} from "ol";
2
2
  import {GsOlControl, GsOlOverlay} from "./gs-gs2ol";
3
- import {render as litRender} from "@kispace-io/appspace/externals/lit";
3
+ import {render as litRender} from "@kispace-io/core/externals/lit";
4
4
 
5
5
  export class GsOlAdapter<T extends GsOlControl | GsOlOverlay> {
6
6
  protected map: Map;
@@ -24,6 +24,8 @@ export const toGsLayerType = (tag: string) => {
24
24
  case "bm":
25
25
  case "basemap.de":
26
26
  return GsLayerType.GROUP
27
+ case "scripted":
28
+ return GsLayerType.SCRIPTED
27
29
  default:
28
30
  return GsLayerType.VECTOR
29
31
  }
@@ -0,0 +1,37 @@
1
+ export interface ScriptedVars {
2
+ params: Record<string, any>
3
+ env: Record<string, string>
4
+ viewState: { extent: number[], zoom: number, projection: string }
5
+ signal?: AbortSignal
6
+ }
7
+
8
+ export interface ScriptedRuntime {
9
+ run(src: string, vars: ScriptedVars): Promise<unknown>
10
+ }
11
+
12
+ class ScriptedRuntimeRegistryImpl {
13
+ private runtimes = new Map<string, ScriptedRuntime>()
14
+
15
+ register(lang: string, runtime: ScriptedRuntime): void {
16
+ this.runtimes.set(lang, runtime)
17
+ }
18
+
19
+ get(lang: string): ScriptedRuntime | undefined {
20
+ return this.runtimes.get(lang)
21
+ }
22
+ }
23
+
24
+ export const scriptedRuntimeRegistry = new ScriptedRuntimeRegistryImpl()
25
+
26
+ const jsRuntime: ScriptedRuntime = {
27
+ async run(src: string, vars: ScriptedVars): Promise<unknown> {
28
+ const mod = await import(/* @vite-ignore */ src)
29
+ const fn = mod instanceof Function ? mod : mod.default
30
+ if (typeof fn !== 'function') {
31
+ throw new Error(`Scripted layer module at "${src}" must export a default function`)
32
+ }
33
+ return fn(vars)
34
+ }
35
+ }
36
+
37
+ scriptedRuntimeRegistry.register('javascript', jsRuntime)