@packtrack/layout 1.2.0 → 1.3.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 (58) hide show
  1. package/.built/index.d.ts +20 -20
  2. package/.built/index.js +20 -20
  3. package/.built/source/device/channel.d.ts +2 -2
  4. package/.built/source/device/channel.js +4 -8
  5. package/.built/source/device/index.d.ts +10 -0
  6. package/.built/source/device/index.js +8 -0
  7. package/.built/source/district.d.ts +3 -7
  8. package/.built/source/district.js +4 -70
  9. package/.built/source/layout.d.ts +9 -6
  10. package/.built/source/layout.js +85 -86
  11. package/.built/source/monitor.d.ts +8 -0
  12. package/.built/source/monitor.js +8 -0
  13. package/.built/source/position.d.ts +3 -1
  14. package/.built/source/position.js +17 -5
  15. package/.built/source/positioner/index.d.ts +2 -0
  16. package/.built/source/positioner/index.js +2 -0
  17. package/.built/source/positioner/point.d.ts +12 -0
  18. package/.built/source/positioner/point.js +17 -0
  19. package/.built/source/positioner/responder-type.d.ts +4 -0
  20. package/.built/source/positioner/responder-type.js +6 -0
  21. package/.built/source/power-district/activator.d.ts +7 -0
  22. package/.built/source/power-district/activator.js +8 -0
  23. package/.built/source/power-district/index.d.ts +13 -0
  24. package/.built/source/power-district/index.js +14 -0
  25. package/.built/source/power-district/monitor.d.ts +7 -0
  26. package/.built/source/power-district/monitor.js +8 -0
  27. package/.built/source/power-district/reverser.d.ts +7 -0
  28. package/.built/source/power-district/reverser.js +8 -0
  29. package/.built/source/route.d.ts +0 -1
  30. package/.built/source/route.js +1 -8
  31. package/.built/source/router.d.ts +0 -4
  32. package/.built/source/router.js +1 -28
  33. package/.built/source/section.d.ts +1 -10
  34. package/.built/source/section.js +8 -57
  35. package/.built/source/span.d.ts +12 -0
  36. package/.built/source/span.js +77 -0
  37. package/.built/source/throttle.d.ts +8 -0
  38. package/.built/source/throttle.js +8 -0
  39. package/.built/source/tile.js +2 -7
  40. package/.built/source/track.d.ts +1 -2
  41. package/.built/source/track.js +3 -10
  42. package/index.ts +23 -0
  43. package/package.json +4 -4
  44. package/source/device/channel.ts +4 -4
  45. package/source/device/index.ts +2 -19
  46. package/source/district.ts +1 -80
  47. package/source/layout.ts +1 -63
  48. package/source/monitor.ts +1 -10
  49. package/source/positioner/point.ts +2 -11
  50. package/source/positioner/responder-type.ts +1 -5
  51. package/source/power-district/index.ts +0 -5
  52. package/source/route.ts +2 -6
  53. package/source/router.ts +2 -31
  54. package/source/section.ts +10 -65
  55. package/source/throttle.ts +1 -10
  56. package/source/track.ts +3 -7
  57. package/tsconfig.json +7 -8
  58. package/source/index.ts +0 -23
package/.built/index.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- export * from './district';
2
- export * from './layout';
3
- export * from './position';
4
- export * from './route';
5
- export * from './router';
6
- export * from './section';
7
- export * from './span';
8
- export * from './tile';
9
- export * from './track';
10
- export * from './monitor';
11
- export * from './throttle';
12
- export * from './power-district/index';
13
- export * from './power-district/activator';
14
- export * from './power-district/monitor';
15
- export * from './power-district/reverser';
16
- export * from './positioner/index';
17
- export * from './positioner/point';
18
- export * from './positioner/responder-type';
19
- export * from './device/index';
20
- export * from './device/channel';
1
+ export * from './source/district';
2
+ export * from './source/layout';
3
+ export * from './source/position';
4
+ export * from './source/route';
5
+ export * from './source/router';
6
+ export * from './source/section';
7
+ export * from './source/span';
8
+ export * from './source/tile';
9
+ export * from './source/track';
10
+ export * from './source/monitor';
11
+ export * from './source/throttle';
12
+ export * from './source/power-district/index';
13
+ export * from './source/power-district/activator';
14
+ export * from './source/power-district/monitor';
15
+ export * from './source/power-district/reverser';
16
+ export * from './source/positioner/index';
17
+ export * from './source/positioner/point';
18
+ export * from './source/positioner/responder-type';
19
+ export * from './source/device/index';
20
+ export * from './source/device/channel';
package/.built/index.js CHANGED
@@ -1,20 +1,20 @@
1
- export * from './district';
2
- export * from './layout';
3
- export * from './position';
4
- export * from './route';
5
- export * from './router';
6
- export * from './section';
7
- export * from './span';
8
- export * from './tile';
9
- export * from './track';
10
- export * from './monitor';
11
- export * from './throttle';
12
- export * from './power-district/index';
13
- export * from './power-district/activator';
14
- export * from './power-district/monitor';
15
- export * from './power-district/reverser';
16
- export * from './positioner/index';
17
- export * from './positioner/point';
18
- export * from './positioner/responder-type';
19
- export * from './device/index';
20
- export * from './device/channel';
1
+ export * from './source/district';
2
+ export * from './source/layout';
3
+ export * from './source/position';
4
+ export * from './source/route';
5
+ export * from './source/router';
6
+ export * from './source/section';
7
+ export * from './source/span';
8
+ export * from './source/tile';
9
+ export * from './source/track';
10
+ export * from './source/monitor';
11
+ export * from './source/throttle';
12
+ export * from './source/power-district/index';
13
+ export * from './source/power-district/activator';
14
+ export * from './source/power-district/monitor';
15
+ export * from './source/power-district/reverser';
16
+ export * from './source/positioner/index';
17
+ export * from './source/positioner/point';
18
+ export * from './source/positioner/responder-type';
19
+ export * from './source/device/index';
20
+ export * from './source/device/channel';
@@ -1,8 +1,8 @@
1
- import { Device } from "./device";
1
+ import { Device } from "./index";
2
2
  export declare class Channel {
3
3
  device: Device;
4
4
  name: string;
5
5
  constructor(device: Device, name: string);
6
- dump(): void;
7
6
  publish(data: any): void;
7
+ toString(): string;
8
8
  }
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Channel = void 0;
4
- class Channel {
1
+ export class Channel {
5
2
  device;
6
3
  name;
7
4
  constructor(device, name) {
8
5
  this.device = device;
9
6
  this.name = name;
10
7
  }
11
- dump() {
12
- console.log(`Channel '${this.name}' on ${this.device.identifier}`);
13
- }
14
8
  publish(data) { }
9
+ toString() {
10
+ return `${this.device.identifier}/${this.name}`;
11
+ }
15
12
  }
16
- exports.Channel = Channel;
@@ -0,0 +1,10 @@
1
+ import { Channel } from "./channel";
2
+ export declare class Device {
3
+ identifier: string;
4
+ channels: Channel[];
5
+ lastDiscovery: {
6
+ date: Date;
7
+ address: string;
8
+ };
9
+ constructor(identifier: string);
10
+ }
@@ -0,0 +1,8 @@
1
+ export class Device {
2
+ identifier;
3
+ channels = [];
4
+ lastDiscovery;
5
+ constructor(identifier) {
6
+ this.identifier = identifier;
7
+ }
8
+ }
@@ -1,5 +1,6 @@
1
1
  import { Layout } from "./layout";
2
- import { PowerDistrict } from "./power-district";
2
+ import { Monitor } from "./monitor";
3
+ import { PowerDistrict } from "./power-district/index";
3
4
  import { Router } from "./router";
4
5
  import { Section } from "./section";
5
6
  export declare class District {
@@ -9,12 +10,7 @@ export declare class District {
9
10
  powerDistricts: PowerDistrict[];
10
11
  sections: Section[];
11
12
  routers: Router[];
13
+ monitors: Monitor[];
12
14
  constructor(name: string, parent: District | Layout);
13
15
  get domainName(): string;
14
- dump(): void;
15
- toDotReference(): any;
16
- toDotDefinition(): any;
17
- toDotConnection(): any;
18
- toSVG(): any;
19
- findSVGPositions(): any;
20
16
  }
@@ -1,86 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.District = void 0;
4
- const layout_1 = require("./layout");
5
- class District {
1
+ import { Layout } from "./layout";
2
+ export class District {
6
3
  name;
7
4
  parent;
8
5
  children = [];
9
6
  powerDistricts = [];
10
7
  sections = [];
11
8
  routers = [];
9
+ monitors = [];
12
10
  constructor(name, parent) {
13
11
  this.name = name;
14
12
  this.parent = parent;
15
13
  }
16
14
  get domainName() {
17
- if (this.parent instanceof layout_1.Layout) {
15
+ if (this.parent instanceof Layout) {
18
16
  return `${this.name}.${this.parent.name}`;
19
17
  }
20
18
  return `${this.name}.${this.parent.domainName}`;
21
19
  }
22
- dump() {
23
- console.group(`District ${this.domainName}`);
24
- if (this.powerDistricts.length) {
25
- console.group('power districts');
26
- for (let district of this.powerDistricts) {
27
- district.dump();
28
- }
29
- console.groupEnd();
30
- }
31
- if (this.sections.length) {
32
- console.group('sections');
33
- for (let section of this.sections) {
34
- section.dump();
35
- }
36
- console.groupEnd();
37
- }
38
- if (this.children.length) {
39
- console.group('children');
40
- for (let district of this.children) {
41
- district.dump();
42
- }
43
- console.groupEnd();
44
- }
45
- console.groupEnd();
46
- }
47
- toDotReference() {
48
- return `cluster_${this.name.replace(/-/g, '_')}${this.parent instanceof District ? this.parent.toDotReference() : ''}`;
49
- }
50
- toDotDefinition() {
51
- return `
52
- subgraph ${this.toDotReference()} {
53
- label = ${JSON.stringify(this.name)}
54
-
55
- ${this.sections.map(section => section.toDotDefinition()).join('')}
56
- ${this.routers.map(router => router.toDotDefinition()).join('')}
57
-
58
- ${this.children.map(child => child.toDotDefinition()).join('')}
59
- }
60
- `;
61
- }
62
- toDotConnection() {
63
- return `
64
- ${this.sections.map(section => section.toDotConnection()).join('')}
65
- ${this.routers.map(router => router.toDotConnection()).join('')}
66
-
67
- ${this.children.map(child => child.toDotConnection()).join('')}
68
- `;
69
- }
70
- toSVG() {
71
- return `
72
- <g id=${JSON.stringify(this.domainName)}>
73
- ${this.sections.map(section => section.toSVG()).join('')}
74
-
75
- ${this.children.map(child => child.toSVG()).join('')}
76
- </g>
77
- `;
78
- }
79
- findSVGPositions() {
80
- return [
81
- ...this.sections.map(section => section.findSVGPositions()),
82
- ...this.children.map(child => child.findSVGPositions())
83
- ];
84
- }
85
20
  }
86
- exports.District = District;
@@ -1,17 +1,23 @@
1
1
  import { District } from "./district";
2
- import { PowerDistrict } from "./power-district";
2
+ import { PowerDistrict } from "./power-district/index";
3
3
  import { Router } from "./router";
4
4
  import { Section } from "./section";
5
- import { Device } from "./device/device";
6
- import { ResponderType } from "../positioner/responder-type";
5
+ import { Device } from "./device/index";
6
+ import { ResponderType } from "./positioner/responder-type";
7
7
  import { Channel } from "./device/channel";
8
+ import { Monitor } from "./monitor";
9
+ import { Throttle } from "./throttle";
8
10
  export declare class Layout {
9
11
  name: string;
10
12
  districts: District[];
11
13
  devices: Device[];
12
14
  responderType: ResponderType[];
15
+ monitors: Monitor[];
16
+ throttles: Throttle[];
13
17
  get allDistricts(): District[];
14
18
  static from(document: any): Layout;
19
+ loadMonitor(source: any, parent: District | Layout): Monitor;
20
+ loadThrottle(source: any, parent: District | Layout): Throttle;
15
21
  loadDistrict(source: any, parent: District | Layout): District;
16
22
  linkDistrict(source: any, district: District): void;
17
23
  loadSection(source: any, district: District): void;
@@ -23,7 +29,4 @@ export declare class Layout {
23
29
  loadRouter(source: any, district: District): Router;
24
30
  linkRouter(source: any, router: Router): void;
25
31
  loadPowerDistrict(source: any, district: District): PowerDistrict;
26
- toDot(): string;
27
- toSVG(inject?: string): string;
28
- dump(): void;
29
32
  }
@@ -1,22 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Layout = void 0;
4
- const district_1 = require("./district");
5
- const power_district_1 = require("./power-district");
6
- const route_1 = require("./route");
7
- const router_1 = require("./router");
8
- const section_1 = require("./section");
9
- const tile_1 = require("./tile");
10
- const track_1 = require("./track");
11
- const point_1 = require("../positioner/point");
12
- const device_1 = require("./device/device");
13
- const responder_type_1 = require("../positioner/responder-type");
14
- const channel_1 = require("./device/channel");
15
- class Layout {
1
+ import { District } from "./district";
2
+ import { PowerDistrict } from "./power-district/index";
3
+ import { Route } from "./route";
4
+ import { Router } from "./router";
5
+ import { Section } from "./section";
6
+ import { TilePattern, Tile } from "./tile";
7
+ import { Track } from "./track";
8
+ import { Device } from "./device/index";
9
+ import { ResponderType } from "./positioner/responder-type";
10
+ import { Channel } from "./device/channel";
11
+ import { PointPositioner } from "./positioner/point";
12
+ import { PowerDistrictActivator } from "./power-district/activator";
13
+ import { PowerDistrictReverser } from "./power-district/reverser";
14
+ import { PowerDistrictMonitor } from "./power-district/monitor";
15
+ import { Monitor } from "./monitor";
16
+ import { Throttle } from "./throttle";
17
+ export class Layout {
16
18
  name;
17
19
  districts = [];
18
20
  devices = [];
19
21
  responderType = [];
22
+ monitors = [];
23
+ throttles = [];
20
24
  get allDistricts() {
21
25
  const districts = [];
22
26
  function walkDistrict(district) {
@@ -36,30 +40,44 @@ class Layout {
36
40
  layout.name = railway.getAttribute('name');
37
41
  const version = railway.getAttribute('version');
38
42
  if (version == '1') {
39
- let district = railway.firstChild;
40
- while (district) {
41
- if (district.tagName == 'district') {
42
- layout.districts.push(layout.loadDistrict(district, layout));
43
+ let child = railway.firstChild;
44
+ while (child) {
45
+ if (child.tagName == 'district') {
46
+ layout.districts.push(layout.loadDistrict(child, layout));
43
47
  }
44
- district = district.nextSibling;
48
+ if (child.tagName == 'monitor') {
49
+ layout.monitors.push(layout.loadMonitor(child, layout));
50
+ }
51
+ if (child.tagName == 'throttle') {
52
+ layout.throttles.push(layout.loadThrottle(child, layout));
53
+ }
54
+ child = child.nextSibling;
45
55
  }
46
- district = railway.firstChild;
56
+ child = railway.firstChild;
47
57
  let index = 0;
48
- while (district) {
49
- if (district.tagName == 'district') {
50
- layout.linkDistrict(district, layout.districts[index]);
58
+ while (child) {
59
+ if (child.tagName == 'district') {
60
+ layout.linkDistrict(child, layout.districts[index]);
51
61
  index++;
52
62
  }
53
- district = district.nextSibling;
63
+ child = child.nextSibling;
54
64
  }
55
65
  }
56
66
  else {
57
- throw new Error(`unsupported railway definition file version '${version}'`);
67
+ throw new Error(`Unsupported railway definition file version '${version}'`);
58
68
  }
59
69
  return layout;
60
70
  }
71
+ loadMonitor(source, parent) {
72
+ const montior = new Monitor(this.findDevice(source.getAttribute('device')), parent);
73
+ return montior;
74
+ }
75
+ loadThrottle(source, parent) {
76
+ const throttle = new Throttle(this.findDevice(source.getAttribute('device')), parent);
77
+ return throttle;
78
+ }
61
79
  loadDistrict(source, parent) {
62
- const district = new district_1.District(source.getAttribute('name'), parent);
80
+ const district = new District(source.getAttribute('name'), parent);
63
81
  let child = source.firstChild;
64
82
  while (child) {
65
83
  if (child.tagName == 'power-districts') {
@@ -80,6 +98,9 @@ class Layout {
80
98
  if (child.tagName == 'district') {
81
99
  district.children.push(this.loadDistrict(child, district));
82
100
  }
101
+ if (child.tagName == 'monitor') {
102
+ district.monitors.push(this.loadMonitor(child, district));
103
+ }
83
104
  child = child.nextSibling;
84
105
  }
85
106
  return district;
@@ -104,7 +125,7 @@ class Layout {
104
125
  }
105
126
  }
106
127
  loadSection(source, district) {
107
- const section = new section_1.Section(source.getAttribute('name'), district);
128
+ const section = new Section(source.getAttribute('name'), district);
108
129
  district.sections.push(section);
109
130
  let child = source.firstChild;
110
131
  while (child) {
@@ -112,7 +133,7 @@ class Layout {
112
133
  let trackNode = child.firstChild;
113
134
  while (trackNode) {
114
135
  if (trackNode.tagName == 'track') {
115
- const track = new track_1.Track(section, +trackNode.getAttribute('length'), trackNode.getAttribute('path'));
136
+ const track = new Track(section, +trackNode.getAttribute('length'), trackNode.getAttribute('path'));
116
137
  section.tracks.push(track);
117
138
  let trackChild = trackNode.firstChild;
118
139
  while (trackChild) {
@@ -123,7 +144,7 @@ class Layout {
123
144
  const device = this.findDevice(positioner.getAttribute('device'));
124
145
  const channel = this.findChannel(device, positioner.getAttribute('channel'));
125
146
  const responderType = this.findResponderType(positioner.getAttribute('responder'));
126
- track.positioners.push(new point_1.PointPositioner(track, +positioner.getAttribute('offset'), channel, responderType));
147
+ track.positioners.push(new PointPositioner(track, +positioner.getAttribute('offset'), channel, responderType));
127
148
  }
128
149
  positioner = positioner.nextSibling;
129
150
  }
@@ -136,10 +157,10 @@ class Layout {
136
157
  }
137
158
  if (child.tagName == 'tile') {
138
159
  const pattern = child.getAttribute('pattern');
139
- if (!(pattern in tile_1.TilePattern.patterns)) {
160
+ if (!(pattern in TilePattern.patterns)) {
140
161
  throw new Error(`Unknown tile pattern '${pattern}' in tile ${section.tiles.length + 1} in ${section.domainName}`);
141
162
  }
142
- section.tiles.push(new tile_1.Tile(section, +child.getAttribute('x'), +child.getAttribute('y'), tile_1.TilePattern.patterns[pattern]));
163
+ section.tiles.push(new Tile(section, +child.getAttribute('x'), +child.getAttribute('y'), TilePattern.patterns[pattern]));
143
164
  }
144
165
  child = child.nextSibling;
145
166
  }
@@ -149,7 +170,7 @@ class Layout {
149
170
  if (device) {
150
171
  return device;
151
172
  }
152
- device = new device_1.Device(identifier);
173
+ device = new Device(identifier);
153
174
  this.devices.push(device);
154
175
  return device;
155
176
  }
@@ -158,7 +179,7 @@ class Layout {
158
179
  if (channel) {
159
180
  return channel;
160
181
  }
161
- channel = new channel_1.Channel(device, name);
182
+ channel = new Channel(device, name);
162
183
  device.channels.push(channel);
163
184
  return channel;
164
185
  }
@@ -167,7 +188,7 @@ class Layout {
167
188
  if (type) {
168
189
  return type;
169
190
  }
170
- type = new responder_type_1.ResponderType(name);
191
+ type = new ResponderType(name);
171
192
  this.responderType.push(type);
172
193
  return type;
173
194
  }
@@ -203,7 +224,7 @@ class Layout {
203
224
  pool = pool.parent;
204
225
  }
205
226
  for (let part of parts) {
206
- const child = (pool instanceof district_1.District ? pool.children : pool.districts).find(child => child.name == part);
227
+ const child = (pool instanceof District ? pool.children : pool.districts).find(child => child.name == part);
207
228
  if (!child) {
208
229
  throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a child named '${part}'`);
209
230
  }
@@ -215,72 +236,50 @@ class Layout {
215
236
  return this.findSection(sectionName, pool, source);
216
237
  }
217
238
  loadRouter(source, district) {
218
- const router = new router_1.Router(source.getAttribute('name'), district);
239
+ const router = new Router(source.getAttribute('name'), district);
219
240
  return router;
220
241
  }
221
242
  linkRouter(source, router) {
222
243
  let child = source.firstChild;
244
+ let active;
223
245
  while (child) {
224
246
  if (child.tagName == 'route') {
225
- const route = new route_1.Route(child.getAttribute('name'), router);
247
+ const route = new Route(child.getAttribute('name'), router);
226
248
  route.in = this.findSection(child.getAttribute('in'), router.district);
227
249
  route.in.out = router;
228
250
  route.out = this.findSection(child.getAttribute('out'), router.district);
229
251
  route.out.in = router;
252
+ if (child.hasAttribute('active')) {
253
+ if (active) {
254
+ throw new Error(`Router '${router.domainName}' has multiple active routes (${active.name}, ${route.name}).`);
255
+ }
256
+ active = route;
257
+ }
230
258
  router.routes.push(route);
231
259
  }
232
260
  child = child.nextSibling;
233
261
  }
262
+ router.activeRoute = active;
234
263
  }
235
264
  loadPowerDistrict(source, district) {
236
- const powerDistrict = new power_district_1.PowerDistrict(source.getAttribute('name'), district);
237
- return powerDistrict;
238
- }
239
- toDot() {
240
- let dot = 'digraph G {';
241
- for (let district of this.districts) {
242
- dot += district.toDotDefinition();
243
- }
244
- for (let district of this.districts) {
245
- dot += district.toDotConnection();
246
- }
247
- return `${dot}}`;
248
- }
249
- toSVG(inject = '') {
250
- const positons = this.districts.map(district => district.findSVGPositions()).flat(Infinity);
251
- const width = Math.max(...positons.map(position => position.x));
252
- const height = Math.max(...positons.map(position => position.y));
253
- let svg = `<svg width="100vw" height="100vh" viewBox="0 0 ${width + 1} ${height + 1}" xmlns="http://www.w3.org/2000/svg">
254
- <style>
255
-
256
- path {
257
- fill: none;
258
- stroke: #000;
259
- stroke-width: 0.2;
260
- }
261
-
262
- </style>
263
- `;
264
- for (let district of this.districts) {
265
- svg += district.toSVG();
266
- }
267
- return `${svg}${inject}</svg>`;
268
- }
269
- dump() {
270
- console.group(`Layout ${this.name}`);
271
- console.log('devices');
272
- for (let device of this.devices) {
273
- device.dump();
274
- }
275
- console.log('responder types');
276
- for (let type of this.responderType) {
277
- type.dump();
278
- }
279
- console.log('districts');
280
- for (let district of this.districts) {
281
- district.dump();
265
+ const powerDistrict = new PowerDistrict(source.getAttribute('name'), district);
266
+ let actor = source.firstChild;
267
+ while (actor) {
268
+ if (actor.tagName == 'activator' || actor.tagName == 'reverser' || actor.tagName == 'monitor') {
269
+ const device = this.findDevice(actor.getAttribute('device'));
270
+ const channel = this.findChannel(device, actor.getAttribute('channel'));
271
+ if (actor.tagName == 'activator') {
272
+ powerDistrict.activator = new PowerDistrictActivator(device, channel);
273
+ }
274
+ if (actor.tagName == 'reverser') {
275
+ powerDistrict.reverser = new PowerDistrictReverser(device, channel);
276
+ }
277
+ if (actor.tagName == 'monitor') {
278
+ powerDistrict.monitor = new PowerDistrictMonitor(device, channel);
279
+ }
280
+ }
281
+ actor = actor.nextSibling;
282
282
  }
283
- console.groupEnd();
283
+ return powerDistrict;
284
284
  }
285
285
  }
286
- exports.Layout = Layout;
@@ -0,0 +1,8 @@
1
+ import { Device } from "./device/index";
2
+ import { District } from "./district";
3
+ import { Layout } from "./layout";
4
+ export declare class Monitor {
5
+ device: Device;
6
+ scope: District | Layout;
7
+ constructor(device: Device, scope: District | Layout);
8
+ }
@@ -0,0 +1,8 @@
1
+ export class Monitor {
2
+ device;
3
+ scope;
4
+ constructor(device, scope) {
5
+ this.device = device;
6
+ this.scope = scope;
7
+ }
8
+ }
@@ -5,6 +5,8 @@ export declare class SectionPosition {
5
5
  reversed: boolean;
6
6
  constructor(section: Section, offset: number, reversed: boolean);
7
7
  get absolutePosition(): number;
8
- advance(distance: number): any;
8
+ advance(distance: number): SectionPosition;
9
+ private invert;
9
10
  toString(): string;
11
+ toPackTrackValue(): string;
10
12
  }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SectionPosition = void 0;
4
- class SectionPosition {
1
+ export class SectionPosition {
5
2
  section;
6
3
  offset;
7
4
  reversed;
@@ -9,14 +6,23 @@ class SectionPosition {
9
6
  this.section = section;
10
7
  this.offset = offset;
11
8
  this.reversed = reversed;
9
+ if (offset > section.length || offset < 0) {
10
+ throw new Error(`Offset ${offset} out of range for section '${section.domainName}' (0 - ${section.length})`);
11
+ }
12
12
  }
13
+ // returns the absolute position of the point inside the section
14
+ // regardless of direction
13
15
  get absolutePosition() {
14
16
  if (this.reversed) {
15
17
  return this.section.length - this.offset;
16
18
  }
17
19
  return this.offset;
18
20
  }
21
+ // TODO verify reverse
19
22
  advance(distance) {
23
+ if (distance < 0) {
24
+ return this.invert().advance(-distance).invert();
25
+ }
20
26
  if (this.offset + distance > this.section.length) {
21
27
  const next = this.section.next(this.reversed);
22
28
  if (!next) {
@@ -26,8 +32,14 @@ class SectionPosition {
26
32
  }
27
33
  return new SectionPosition(this.section, this.offset + distance, this.reversed);
28
34
  }
35
+ // reverse direction
36
+ invert() {
37
+ return new SectionPosition(this.section, this.section.length - this.offset, !this.reversed);
38
+ }
29
39
  toString() {
30
40
  return `${this.section.name} @ ${this.offset.toFixed(1)} ${this.reversed ? 'backward' : 'forward'}`;
31
41
  }
42
+ toPackTrackValue() {
43
+ return `${this.section.domainName}@${this.offset}${this.reversed ? 'R' : 'F'}`;
44
+ }
32
45
  }
33
- exports.SectionPosition = SectionPosition;
@@ -0,0 +1,2 @@
1
+ export declare class Positioner {
2
+ }
@@ -0,0 +1,2 @@
1
+ export class Positioner {
2
+ }