@versatiles/svelte 1.1.2 → 2.0.0

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.
Files changed (42) hide show
  1. package/dist/components/BasicMap/BasicMap.svelte +4 -4
  2. package/dist/components/BasicMap/BasicMap.svelte.d.ts +2 -2
  3. package/dist/components/MapEditor/MapEditor.svelte +16 -3
  4. package/dist/components/MapEditor/components/Editor.svelte +46 -40
  5. package/dist/components/MapEditor/components/Editor.svelte.d.ts +1 -1
  6. package/dist/components/MapEditor/components/EditorFill.svelte +7 -9
  7. package/dist/components/MapEditor/components/EditorStroke.svelte +9 -11
  8. package/dist/components/MapEditor/components/EditorSymbol.svelte +15 -21
  9. package/dist/components/MapEditor/components/InputRow.svelte +34 -0
  10. package/dist/components/MapEditor/components/InputRow.svelte.d.ts +9 -0
  11. package/dist/components/MapEditor/components/Sidebar.svelte +115 -108
  12. package/dist/components/MapEditor/components/SidebarPanel.svelte +92 -0
  13. package/dist/components/MapEditor/components/SidebarPanel.svelte.d.ts +10 -0
  14. package/dist/components/MapEditor/components/SymbolSelector.svelte +7 -15
  15. package/dist/components/MapEditor/lib/element/abstract.d.ts +3 -3
  16. package/dist/components/MapEditor/lib/element/abstract.js +1 -1
  17. package/dist/components/MapEditor/lib/element/line.d.ts +3 -4
  18. package/dist/components/MapEditor/lib/element/line.js +0 -1
  19. package/dist/components/MapEditor/lib/element/marker.d.ts +4 -4
  20. package/dist/components/MapEditor/lib/element/polygon.d.ts +3 -3
  21. package/dist/components/MapEditor/lib/geometry_manager.d.ts +20 -10
  22. package/dist/components/MapEditor/lib/geometry_manager.js +44 -52
  23. package/dist/components/MapEditor/lib/map_layer/abstract.d.ts +3 -2
  24. package/dist/components/MapEditor/lib/map_layer/abstract.js +3 -0
  25. package/dist/components/MapEditor/lib/map_layer/fill.d.ts +4 -3
  26. package/dist/components/MapEditor/lib/map_layer/fill.js +9 -8
  27. package/dist/components/MapEditor/lib/map_layer/line.d.ts +4 -3
  28. package/dist/components/MapEditor/lib/map_layer/line.js +15 -14
  29. package/dist/components/MapEditor/lib/map_layer/symbol.d.ts +5 -4
  30. package/dist/components/MapEditor/lib/map_layer/symbol.js +28 -46
  31. package/dist/components/MapEditor/lib/state/constants.d.ts +4 -0
  32. package/dist/components/MapEditor/lib/state/constants.js +22 -0
  33. package/dist/components/MapEditor/lib/state/manager.d.ts +16 -0
  34. package/dist/components/MapEditor/lib/state/manager.js +76 -0
  35. package/dist/components/MapEditor/lib/state/reader.d.ts +21 -14
  36. package/dist/components/MapEditor/lib/state/reader.js +259 -142
  37. package/dist/components/MapEditor/lib/state/types.d.ts +27 -12
  38. package/dist/components/MapEditor/lib/state/writer.d.ts +18 -14
  39. package/dist/components/MapEditor/lib/state/writer.js +182 -169
  40. package/dist/components/MapEditor/lib/utils.d.ts +2 -5
  41. package/dist/components/MapEditor/lib/utils.js +0 -19
  42. package/package.json +19 -19
@@ -8,10 +8,16 @@ export const dashArrays = new Map([
8
8
  [2, { name: 'dotted', array: [0, 2] }]
9
9
  ]);
10
10
  export class MapLayerLine extends MapLayer {
11
- color = writable('#ff0000');
12
- dashed = writable(0);
13
- visible = writable(true);
14
- width = writable(2);
11
+ static defaultStyle = {
12
+ color: '#ff0000',
13
+ pattern: 0,
14
+ visible: true,
15
+ width: 2
16
+ };
17
+ color = writable(MapLayerLine.defaultStyle.color);
18
+ dashed = writable(MapLayerLine.defaultStyle.pattern);
19
+ visible = writable(MapLayerLine.defaultStyle.visible);
20
+ width = writable(MapLayerLine.defaultStyle.width);
15
21
  dashArray = derived(this.dashed, (dashed) => dashArrays.get(dashed)?.array ?? [100]);
16
22
  constructor(manager, id, source) {
17
23
  super(manager, id);
@@ -26,19 +32,19 @@ export class MapLayerLine extends MapLayer {
26
32
  });
27
33
  this.color.subscribe((v) => {
28
34
  this.updatePaint('line-color', Color.parse(v));
29
- this.manager.saveState();
35
+ this.manager.state.log();
30
36
  });
31
37
  this.dashArray.subscribe((v) => {
32
38
  this.updatePaint('line-dasharray', v);
33
- this.manager.saveState();
39
+ this.manager.state.log();
34
40
  });
35
41
  this.visible.subscribe((v) => {
36
42
  this.updateLayout('visibility', v ? 'visible' : 'none');
37
- this.manager.saveState();
43
+ this.manager.state.log();
38
44
  });
39
45
  this.width.subscribe((v) => {
40
46
  this.updatePaint('line-width', v);
41
- this.manager.saveState();
47
+ this.manager.state.log();
42
48
  });
43
49
  }
44
50
  getState() {
@@ -47,12 +53,7 @@ export class MapLayerLine extends MapLayer {
47
53
  pattern: get(this.dashed),
48
54
  visible: get(this.visible),
49
55
  width: get(this.width)
50
- }, {
51
- color: '#ff0000',
52
- pattern: 0,
53
- visible: true,
54
- width: 2
55
- });
56
+ }, MapLayerLine.defaultStyle);
56
57
  }
57
58
  setState(state) {
58
59
  if (state.color)
@@ -2,7 +2,7 @@ import { type Writable } from 'svelte/store';
2
2
  import type { LayerSymbol } from './types.js';
3
3
  import { MapLayer } from './abstract.js';
4
4
  import type { GeometryManager } from '../geometry_manager.js';
5
- import type { StateObject } from '../state/types.js';
5
+ import type { StateStyle } from '../state/types.js';
6
6
  interface LabelAlign {
7
7
  index: 0 | 1 | 2 | 3 | 4;
8
8
  name: string;
@@ -10,19 +10,20 @@ interface LabelAlign {
10
10
  }
11
11
  export declare const labelPositions: LabelAlign[];
12
12
  export declare class MapLayerSymbol extends MapLayer<LayerSymbol> {
13
+ static readonly defaultStyle: StateStyle;
13
14
  color: Writable<string>;
14
15
  halo: Writable<number>;
15
16
  rotate: Writable<number>;
16
17
  size: Writable<number>;
17
18
  symbolIndex: Writable<number>;
18
19
  label: Writable<string>;
19
- labelAlign: Writable<0 | 2 | 1 | 4 | 3>;
20
+ labelAlign: Writable<number>;
20
21
  symbolInfo: import("svelte/store").Readable<import("../symbols.js").SymbolInfo>;
21
22
  textAnchor: import("svelte/store").Readable<"center" | "top" | "bottom" | "right" | "left" | undefined>;
22
23
  textVariableAnchor: import("svelte/store").Readable<("center" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top" | "bottom" | "right" | "left")[] | undefined>;
23
24
  constructor(manager: GeometryManager, id: string, source: string);
24
- getState(): StateObject | undefined;
25
- setState(state: StateObject): void;
25
+ getState(): StateStyle | undefined;
26
+ setState(state: StateStyle): void;
26
27
  getGeoJSONProperties(): GeoJSON.GeoJsonProperties;
27
28
  setGeoJSONProperties(properties: GeoJSON.GeoJsonProperties): void;
28
29
  }
@@ -10,23 +10,23 @@ export const labelPositions = [
10
10
  { index: 3, name: 'top', anchor: 'bottom' },
11
11
  { index: 4, name: 'bottom', anchor: 'top' }
12
12
  ];
13
- const defaultStyle = {
14
- color: '#ff0000',
15
- rotate: 0,
16
- size: 1,
17
- halo: 1,
18
- pattern: 38,
19
- label: '',
20
- align: 0
21
- };
22
13
  export class MapLayerSymbol extends MapLayer {
23
- color = writable(defaultStyle.color);
24
- halo = writable(defaultStyle.halo);
25
- rotate = writable(defaultStyle.rotate);
26
- size = writable(defaultStyle.size);
27
- symbolIndex = writable(defaultStyle.pattern);
28
- label = writable(defaultStyle.label);
29
- labelAlign = writable(defaultStyle.align);
14
+ static defaultStyle = {
15
+ color: '#ff0000',
16
+ rotate: 0,
17
+ size: 1,
18
+ halo: 1,
19
+ pattern: 38,
20
+ label: '',
21
+ align: 0
22
+ };
23
+ color = writable(MapLayerSymbol.defaultStyle.color);
24
+ halo = writable(MapLayerSymbol.defaultStyle.halo);
25
+ rotate = writable(MapLayerSymbol.defaultStyle.rotate);
26
+ size = writable(MapLayerSymbol.defaultStyle.size);
27
+ symbolIndex = writable(MapLayerSymbol.defaultStyle.pattern);
28
+ label = writable(MapLayerSymbol.defaultStyle.label);
29
+ labelAlign = writable(MapLayerSymbol.defaultStyle.align);
30
30
  symbolInfo = derived(this.symbolIndex, (index) => getSymbol(index));
31
31
  textAnchor = derived(this.labelAlign, (index) => {
32
32
  return lookupLabelAlign(index).anchor;
@@ -45,9 +45,9 @@ export class MapLayerSymbol extends MapLayer {
45
45
  'icon-image': get(this.symbolInfo).image,
46
46
  'icon-offset': get(this.symbolInfo).offset,
47
47
  'icon-allow-overlap': true,
48
- 'icon-rotate': defaultStyle.rotate,
49
- 'icon-size': defaultStyle.size,
50
- 'text-field': defaultStyle.label,
48
+ 'icon-rotate': get(this.rotate),
49
+ 'icon-size': get(this.size),
50
+ 'text-field': get(this.label),
51
51
  'text-font': ['noto_sans_regular'],
52
52
  'text-justify': 'left',
53
53
  'text-overlap': 'always',
@@ -55,44 +55,27 @@ export class MapLayerSymbol extends MapLayer {
55
55
  'text-variable-anchor': get(this.textVariableAnchor),
56
56
  'text-anchor': get(this.textAnchor)
57
57
  }, {
58
- 'icon-color': defaultStyle.color,
58
+ 'icon-color': get(this.color),
59
59
  'icon-halo-blur': 0,
60
60
  'icon-halo-color': '#FFFFFF',
61
- 'icon-halo-width': defaultStyle.halo,
61
+ 'icon-halo-width': get(this.halo),
62
62
  'icon-opacity': 1,
63
63
  'text-halo-blur': 0,
64
64
  'text-halo-color': '#FFFFFF',
65
- 'text-halo-width': defaultStyle.halo
66
- });
67
- this.color.subscribe((v) => {
68
- this.updatePaint('icon-color', Color.parse(v));
69
- this.manager.saveState();
65
+ 'text-halo-width': get(this.halo)
70
66
  });
67
+ this.color.subscribe((v) => this.updatePaint('icon-color', Color.parse(v)));
71
68
  this.halo.subscribe((v) => {
72
69
  this.updatePaint('icon-halo-width', v);
73
70
  this.updatePaint('text-halo-width', v);
74
- this.manager.saveState();
75
- });
76
- this.label.subscribe((v) => {
77
- this.updateLayout('text-field', v);
78
- this.manager.saveState();
79
- });
80
- this.textAnchor.subscribe((v) => {
81
- this.updateLayout('text-anchor', v);
82
- this.manager.saveState();
83
- });
84
- this.textVariableAnchor.subscribe((v) => {
85
- this.updateLayout('text-variable-anchor', v);
86
- this.manager.saveState();
87
- });
88
- this.rotate.subscribe((v) => {
89
- this.updateLayout('icon-rotate', v);
90
- this.manager.saveState();
91
71
  });
72
+ this.label.subscribe((v) => this.updateLayout('text-field', v));
73
+ this.textAnchor.subscribe((v) => this.updateLayout('text-anchor', v));
74
+ this.textVariableAnchor.subscribe((v) => this.updateLayout('text-variable-anchor', v));
75
+ this.rotate.subscribe((v) => this.updateLayout('icon-rotate', v));
92
76
  this.size.subscribe((v) => {
93
77
  this.updateLayout('icon-size', v);
94
78
  this.updateLayout('text-size', v * 16);
95
- this.manager.saveState();
96
79
  });
97
80
  this.symbolInfo.subscribe((v) => {
98
81
  if (v.image == null) {
@@ -102,7 +85,6 @@ export class MapLayerSymbol extends MapLayer {
102
85
  this.updateLayout('icon-image', v.image);
103
86
  this.updateLayout('icon-offset', v.offset);
104
87
  }
105
- this.manager.saveState();
106
88
  });
107
89
  }
108
90
  getState() {
@@ -114,7 +96,7 @@ export class MapLayerSymbol extends MapLayer {
114
96
  pattern: get(this.symbolIndex),
115
97
  label: get(this.label),
116
98
  align: get(this.labelAlign)
117
- }, defaultStyle);
99
+ }, MapLayerSymbol.defaultStyle);
118
100
  }
119
101
  setState(state) {
120
102
  if (state.color)
@@ -0,0 +1,4 @@
1
+ export declare const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
2
+ export declare const BASE64_CODE2BITS: [boolean, boolean, boolean, boolean, boolean, boolean][];
3
+ export declare const CHAR_VALUE2CODE: number[];
4
+ export declare const CHAR_CODE2VALUE: number[];
@@ -0,0 +1,22 @@
1
+ export const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
2
+ export const BASE64_CODE2BITS = [];
3
+ for (let i = 0; i < BASE64_CHARS.length; i++) {
4
+ BASE64_CODE2BITS[BASE64_CHARS.charCodeAt(i)] = [
5
+ (i & 32) > 0,
6
+ (i & 16) > 0,
7
+ (i & 8) > 0,
8
+ (i & 4) > 0,
9
+ (i & 2) > 0,
10
+ (i & 1) > 0
11
+ ];
12
+ }
13
+ export const CHAR_VALUE2CODE = [
14
+ 32, 101, 116, 97, 110, 105, 111, 115, 114, 108, 100, 104, 99, 117, 109, 112, 102, 103, 46, 121,
15
+ 98, 119, 44, 118, 48, 107, 49, 83, 84, 67, 50, 56, 53, 65, 57, 120, 51, 73, 45, 54, 52, 55, 77,
16
+ 66, 34, 39, 80, 69, 78, 70, 82, 68, 85, 113, 76, 71, 74, 72, 79, 87, 106, 122, 47, 60, 62, 75, 41,
17
+ 40, 86, 89, 58, 81, 90, 88, 59, 63, 94, 38, 43, 91, 93, 36, 33, 42, 61, 126, 95, 123, 64, 0, 1, 2,
18
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
19
+ 29, 30, 31, 35, 37, 92, 96, 124, 125, 127
20
+ ];
21
+ export const CHAR_CODE2VALUE = [];
22
+ CHAR_VALUE2CODE.forEach((c, v) => (CHAR_CODE2VALUE[c] = v));
@@ -0,0 +1,16 @@
1
+ import type { GeometryManager } from '../geometry_manager.js';
2
+ export declare class StateManager {
3
+ geometryManager: GeometryManager;
4
+ constructor(geometryManager: GeometryManager);
5
+ getHash(): string;
6
+ setHash(hash: string): void;
7
+ private history;
8
+ private historyIndex;
9
+ undoEnabled: import("svelte/store").Writable<boolean>;
10
+ redoEnabled: import("svelte/store").Writable<boolean>;
11
+ private resetHistory;
12
+ log(): void;
13
+ undo(): void;
14
+ redo(): void;
15
+ private updateButtons;
16
+ }
@@ -0,0 +1,76 @@
1
+ import { writable } from 'svelte/store';
2
+ import { StateReader } from './reader.js';
3
+ import { StateWriter } from './writer.js';
4
+ const MAXLENGTH = 100;
5
+ export class StateManager {
6
+ geometryManager;
7
+ constructor(geometryManager) {
8
+ this.geometryManager = geometryManager;
9
+ this.resetHistory();
10
+ }
11
+ getHash() {
12
+ const writer = new StateWriter();
13
+ writer.writeRoot(this.geometryManager.getState());
14
+ return writer.asBase64();
15
+ }
16
+ setHash(hash) {
17
+ if (!hash)
18
+ return;
19
+ try {
20
+ const state = StateReader.fromBase64(hash).readRoot();
21
+ this.geometryManager.setState(state);
22
+ this.resetHistory();
23
+ }
24
+ catch (error) {
25
+ console.error(error);
26
+ }
27
+ }
28
+ // History of state hashes
29
+ // The first element is the most recent state
30
+ history = [];
31
+ // The index of the current state in the history
32
+ // 0 means the most recent state
33
+ // 1 means the second most recent state
34
+ historyIndex = 0;
35
+ undoEnabled = writable(false);
36
+ redoEnabled = writable(false);
37
+ resetHistory() {
38
+ this.history = [this.geometryManager.getState()];
39
+ this.historyIndex = 0;
40
+ this.updateButtons();
41
+ }
42
+ log() {
43
+ const state = this.geometryManager.getState();
44
+ state.map = undefined; // Remove map state from history
45
+ if (this.historyIndex > 0) {
46
+ this.history.splice(0, this.historyIndex);
47
+ this.historyIndex = 0;
48
+ }
49
+ this.history.unshift(state);
50
+ // Remove old history
51
+ if (this.history.length > MAXLENGTH) {
52
+ this.history.length = MAXLENGTH;
53
+ }
54
+ this.updateButtons();
55
+ }
56
+ undo() {
57
+ if (this.historyIndex < this.history.length - 1) {
58
+ this.historyIndex++;
59
+ const state = this.history[this.historyIndex];
60
+ this.geometryManager.setState(state);
61
+ this.updateButtons();
62
+ }
63
+ }
64
+ redo() {
65
+ if (this.historyIndex > 0) {
66
+ this.historyIndex--;
67
+ const state = this.history[this.historyIndex];
68
+ this.geometryManager.setState(state);
69
+ this.updateButtons();
70
+ }
71
+ }
72
+ updateButtons() {
73
+ this.undoEnabled.set(this.historyIndex < this.history.length - 1);
74
+ this.redoEnabled.set(this.historyIndex > 0);
75
+ }
76
+ }
@@ -1,17 +1,24 @@
1
- import type { StateObject } from './types.js';
1
+ import type { StateElementLine, StateElementMarker, StateElementPolygon, StateRoot, StateStyle } from './types.js';
2
2
  export declare class StateReader {
3
- private buffer;
4
- private offset;
5
- constructor(buffer: Uint8Array | number[]);
6
- readByte(): number;
7
- readUnsignedInteger(): number;
8
- readSignedInteger(): number;
9
- readString(): string;
10
- readBoolean(): boolean;
11
- static fromBase64compressed(base64: string): Promise<StateReader>;
12
- static fromBase64(base64: string): Promise<StateReader>;
13
- readObject(): StateObject;
14
- readDifferential(count: number): number[];
3
+ bits: boolean[];
4
+ offset: number;
5
+ constructor(bits: boolean[]);
6
+ static fromBase64(text: string): StateReader;
7
+ static fromBitString(text: string): StateReader;
8
+ ended(): boolean;
9
+ readBit(): boolean;
10
+ readInteger(bits: number, signed?: true): number;
11
+ read6pack(): number;
12
+ readVarint(signed?: true): number;
13
+ readArray<T>(cb: () => T): T[];
14
+ readPoint(level?: number): [number, number];
15
+ readPoints(level?: number): [number, number][];
16
+ readRoot(): StateRoot;
17
+ readMap(): NonNullable<StateRoot['map']>;
18
+ readElementMarker(): StateElementMarker;
19
+ readElementLine(): StateElementLine;
20
+ readElementPolygon(): StateElementPolygon;
21
+ readStyle(): StateStyle;
15
22
  readColor(): string;
16
- readType(): string;
23
+ readString(): string;
17
24
  }