@packtrack/layout 1.0.1 → 1.0.4

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 (47) hide show
  1. package/.built/device/channel.d.ts +8 -0
  2. package/.built/device/channel.js +16 -0
  3. package/.built/device/device.d.ts +11 -0
  4. package/.built/device/device.js +24 -0
  5. package/.built/positioner/index.d.ts +2 -0
  6. package/.built/positioner/index.js +6 -0
  7. package/.built/positioner/point.d.ts +13 -0
  8. package/.built/positioner/point.js +27 -0
  9. package/.built/positioner/responder-type.d.ts +5 -0
  10. package/.built/positioner/responder-type.js +13 -0
  11. package/.built/source/device/channel.d.ts +8 -0
  12. package/.built/source/device/channel.js +16 -0
  13. package/.built/source/device/device.d.ts +11 -0
  14. package/.built/source/device/device.js +24 -0
  15. package/.built/source/district.d.ts +20 -0
  16. package/.built/source/district.js +86 -0
  17. package/.built/source/layout.d.ts +29 -0
  18. package/.built/source/layout.js +286 -0
  19. package/.built/source/position.d.ts +10 -0
  20. package/.built/source/position.js +33 -0
  21. package/.built/source/power-district.d.ts +8 -0
  22. package/.built/source/power-district.js +18 -0
  23. package/.built/source/route.d.ts +10 -0
  24. package/.built/source/route.js +17 -0
  25. package/.built/source/router.d.ts +14 -0
  26. package/.built/source/router.js +40 -0
  27. package/.built/source/section.d.ts +40 -0
  28. package/.built/source/section.js +217 -0
  29. package/.built/source/tile.d.ts +57 -0
  30. package/.built/source/tile.js +78 -0
  31. package/.built/source/track.d.ts +12 -0
  32. package/.built/source/track.js +29 -0
  33. package/index.ts +9 -399
  34. package/package.json +9 -1
  35. package/positioner/point.ts +2 -2
  36. package/{district.ts → source/district.ts} +1 -1
  37. package/source/layout.ts +399 -0
  38. package/{track.ts → source/track.ts} +1 -1
  39. package/tsconfig.json +9 -0
  40. /package/{device → source/device}/channel.ts +0 -0
  41. /package/{device → source/device}/device.ts +0 -0
  42. /package/{position.ts → source/position.ts} +0 -0
  43. /package/{power-district.ts → source/power-district.ts} +0 -0
  44. /package/{route.ts → source/route.ts} +0 -0
  45. /package/{router.ts → source/router.ts} +0 -0
  46. /package/{section.ts → source/section.ts} +0 -0
  47. /package/{tile.ts → source/tile.ts} +0 -0
@@ -0,0 +1,8 @@
1
+ import { Device } from "./device";
2
+ export declare class Channel {
3
+ device: Device;
4
+ name: string;
5
+ constructor(device: Device, name: string);
6
+ dump(): void;
7
+ publish(data: any): void;
8
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Channel = void 0;
4
+ class Channel {
5
+ device;
6
+ name;
7
+ constructor(device, name) {
8
+ this.device = device;
9
+ this.name = name;
10
+ }
11
+ dump() {
12
+ console.log(`Channel '${this.name}' on ${this.device.identifier}`);
13
+ }
14
+ publish(data) { }
15
+ }
16
+ exports.Channel = Channel;
@@ -0,0 +1,11 @@
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
+ dump(): void;
11
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Device = void 0;
4
+ class Device {
5
+ identifier;
6
+ channels = [];
7
+ lastDiscovery;
8
+ constructor(identifier) {
9
+ this.identifier = identifier;
10
+ }
11
+ dump() {
12
+ console.group(`Device ${this.identifier}`);
13
+ if (this.lastDiscovery) {
14
+ console.log(`last discovery: ${this.lastDiscovery.date.toISOString()} ${this.lastDiscovery.address}`);
15
+ }
16
+ console.group('channels');
17
+ for (let channel of this.channels) {
18
+ channel.dump();
19
+ }
20
+ console.groupEnd();
21
+ console.groupEnd();
22
+ }
23
+ }
24
+ exports.Device = Device;
@@ -0,0 +1,2 @@
1
+ export declare class Positioner {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Positioner = void 0;
4
+ class Positioner {
5
+ }
6
+ exports.Positioner = Positioner;
@@ -0,0 +1,13 @@
1
+ import { Positioner } from ".";
2
+ import { Channel } from "../source/device/channel";
3
+ import { Track } from "../source/track";
4
+ import { ResponderType } from "./responder-type";
5
+ export declare class PointPositioner extends Positioner {
6
+ track: Track;
7
+ offset: number;
8
+ channel: Channel;
9
+ responder: ResponderType;
10
+ constructor(track: Track, offset: number, channel: Channel, responder: ResponderType);
11
+ get position(): any;
12
+ dump(): void;
13
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PointPositioner = void 0;
4
+ const _1 = require(".");
5
+ class PointPositioner extends _1.Positioner {
6
+ track;
7
+ offset;
8
+ channel;
9
+ responder;
10
+ constructor(track, offset, channel, responder) {
11
+ super();
12
+ this.track = track;
13
+ this.offset = offset;
14
+ this.channel = channel;
15
+ this.responder = responder;
16
+ }
17
+ get position() {
18
+ return this.track.head.advance(this.offset);
19
+ }
20
+ dump() {
21
+ console.group('Point positioner');
22
+ console.log('offset:', this.offset);
23
+ this.channel.dump();
24
+ console.groupEnd();
25
+ }
26
+ }
27
+ exports.PointPositioner = PointPositioner;
@@ -0,0 +1,5 @@
1
+ export declare class ResponderType {
2
+ name: string;
3
+ constructor(name: string);
4
+ dump(): void;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResponderType = void 0;
4
+ class ResponderType {
5
+ name;
6
+ constructor(name) {
7
+ this.name = name;
8
+ }
9
+ dump() {
10
+ console.log(`Responder Type '${this.name}'`);
11
+ }
12
+ }
13
+ exports.ResponderType = ResponderType;
@@ -0,0 +1,8 @@
1
+ import { Device } from "./device";
2
+ export declare class Channel {
3
+ device: Device;
4
+ name: string;
5
+ constructor(device: Device, name: string);
6
+ dump(): void;
7
+ publish(data: any): void;
8
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Channel = void 0;
4
+ class Channel {
5
+ device;
6
+ name;
7
+ constructor(device, name) {
8
+ this.device = device;
9
+ this.name = name;
10
+ }
11
+ dump() {
12
+ console.log(`Channel '${this.name}' on ${this.device.identifier}`);
13
+ }
14
+ publish(data) { }
15
+ }
16
+ exports.Channel = Channel;
@@ -0,0 +1,11 @@
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
+ dump(): void;
11
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Device = void 0;
4
+ class Device {
5
+ identifier;
6
+ channels = [];
7
+ lastDiscovery;
8
+ constructor(identifier) {
9
+ this.identifier = identifier;
10
+ }
11
+ dump() {
12
+ console.group(`Device ${this.identifier}`);
13
+ if (this.lastDiscovery) {
14
+ console.log(`last discovery: ${this.lastDiscovery.date.toISOString()} ${this.lastDiscovery.address}`);
15
+ }
16
+ console.group('channels');
17
+ for (let channel of this.channels) {
18
+ channel.dump();
19
+ }
20
+ console.groupEnd();
21
+ console.groupEnd();
22
+ }
23
+ }
24
+ exports.Device = Device;
@@ -0,0 +1,20 @@
1
+ import { Layout } from "./layout";
2
+ import { PowerDistrict } from "./power-district";
3
+ import { Router } from "./router";
4
+ import { Section } from "./section";
5
+ export declare class District {
6
+ name: string;
7
+ parent: District | Layout;
8
+ children: District[];
9
+ powerDistricts: PowerDistrict[];
10
+ sections: Section[];
11
+ routers: Router[];
12
+ constructor(name: string, parent: District | Layout);
13
+ get domainName(): string;
14
+ dump(): void;
15
+ toDotReference(): any;
16
+ toDotDefinition(): any;
17
+ toDotConnection(): any;
18
+ toSVG(): any;
19
+ findSVGPositions(): any;
20
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.District = void 0;
4
+ const layout_1 = require("./layout");
5
+ class District {
6
+ name;
7
+ parent;
8
+ children = [];
9
+ powerDistricts = [];
10
+ sections = [];
11
+ routers = [];
12
+ constructor(name, parent) {
13
+ this.name = name;
14
+ this.parent = parent;
15
+ }
16
+ get domainName() {
17
+ if (this.parent instanceof layout_1.Layout) {
18
+ return `${this.name}.${this.parent.name}`;
19
+ }
20
+ return `${this.name}.${this.parent.domainName}`;
21
+ }
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
+ }
86
+ exports.District = District;
@@ -0,0 +1,29 @@
1
+ import { District } from "./district";
2
+ import { PowerDistrict } from "./power-district";
3
+ import { Router } from "./router";
4
+ import { Section } from "./section";
5
+ import { Device } from "./device/device";
6
+ import { ResponderType } from "../positioner/responder-type";
7
+ import { Channel } from "./device/channel";
8
+ export declare class Layout {
9
+ name: string;
10
+ districts: District[];
11
+ devices: Device[];
12
+ responderType: ResponderType[];
13
+ get allDistricts(): District[];
14
+ static from(document: any): Layout;
15
+ loadDistrict(source: any, parent: District | Layout): District;
16
+ linkDistrict(source: any, district: District): void;
17
+ loadSection(source: any, district: District): void;
18
+ findDevice(identifier: string): Device;
19
+ findChannel(device: Device, name: string): Channel;
20
+ findResponderType(name: string): ResponderType;
21
+ linkSection(source: any, section: Section): void;
22
+ findSection(path: string, base: District, source?: District): any;
23
+ loadRouter(source: any, district: District): Router;
24
+ linkRouter(source: any, router: Router): void;
25
+ loadPowerDistrict(source: any, district: District): PowerDistrict;
26
+ toDot(): string;
27
+ toSVG(inject?: string): string;
28
+ dump(): void;
29
+ }
@@ -0,0 +1,286 @@
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 {
16
+ name;
17
+ districts = [];
18
+ devices = [];
19
+ responderType = [];
20
+ get allDistricts() {
21
+ const districts = [];
22
+ function walkDistrict(district) {
23
+ districts.push(district);
24
+ for (let child of district.children) {
25
+ walkDistrict(child);
26
+ }
27
+ }
28
+ for (let district of this.districts) {
29
+ walkDistrict(district);
30
+ }
31
+ return districts;
32
+ }
33
+ static from(document) {
34
+ const layout = new Layout();
35
+ const railway = document.firstChild;
36
+ layout.name = railway.getAttribute('name');
37
+ const version = railway.getAttribute('version');
38
+ 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
+ }
44
+ district = district.nextSibling;
45
+ }
46
+ district = railway.firstChild;
47
+ let index = 0;
48
+ while (district) {
49
+ if (district.tagName == 'district') {
50
+ layout.linkDistrict(district, layout.districts[index]);
51
+ index++;
52
+ }
53
+ district = district.nextSibling;
54
+ }
55
+ }
56
+ else {
57
+ throw new Error(`unsupported railway definition file version '${version}'`);
58
+ }
59
+ return layout;
60
+ }
61
+ loadDistrict(source, parent) {
62
+ const district = new district_1.District(source.getAttribute('name'), parent);
63
+ let child = source.firstChild;
64
+ while (child) {
65
+ if (child.tagName == 'power-districts') {
66
+ let powerDistrict = child.firstChild;
67
+ while (powerDistrict) {
68
+ if (powerDistrict.tagName == 'power-district') {
69
+ district.powerDistricts.push(this.loadPowerDistrict(powerDistrict, district));
70
+ }
71
+ powerDistrict = powerDistrict.nextSibling;
72
+ }
73
+ }
74
+ if (child.tagName == 'section') {
75
+ this.loadSection(child, district);
76
+ }
77
+ if (child.tagName == 'router') {
78
+ district.routers.push(this.loadRouter(child, district));
79
+ }
80
+ if (child.tagName == 'district') {
81
+ district.children.push(this.loadDistrict(child, district));
82
+ }
83
+ child = child.nextSibling;
84
+ }
85
+ return district;
86
+ }
87
+ linkDistrict(source, district) {
88
+ let child = source.firstChild;
89
+ let sectionIndex = 0;
90
+ let childIndex = 0;
91
+ while (child) {
92
+ if (child.tagName == 'section') {
93
+ this.linkSection(child, district.sections[sectionIndex]);
94
+ sectionIndex++;
95
+ }
96
+ if (child.tagName == 'router') {
97
+ this.linkRouter(child, district.routers.find(router => router.name == child.getAttribute('name')));
98
+ }
99
+ if (child.tagName == 'district') {
100
+ this.linkDistrict(child, district.children[childIndex]);
101
+ childIndex++;
102
+ }
103
+ child = child.nextSibling;
104
+ }
105
+ }
106
+ loadSection(source, district) {
107
+ const section = new section_1.Section(source.getAttribute('name'), district);
108
+ district.sections.push(section);
109
+ let child = source.firstChild;
110
+ while (child) {
111
+ if (child.tagName == 'tracks') {
112
+ let trackNode = child.firstChild;
113
+ while (trackNode) {
114
+ if (trackNode.tagName == 'track') {
115
+ const track = new track_1.Track(section, +trackNode.getAttribute('length'), trackNode.getAttribute('path'));
116
+ section.tracks.push(track);
117
+ let trackChild = trackNode.firstChild;
118
+ while (trackChild) {
119
+ if (trackChild.tagName == 'positioners') {
120
+ let positioner = trackChild.firstChild;
121
+ while (positioner) {
122
+ if (positioner.tagName == 'point') {
123
+ const device = this.findDevice(positioner.getAttribute('device'));
124
+ const channel = this.findChannel(device, positioner.getAttribute('channel'));
125
+ const responderType = this.findResponderType(positioner.getAttribute('responder'));
126
+ track.positioners.push(new point_1.PointPositioner(track, +positioner.getAttribute('offset'), channel, responderType));
127
+ }
128
+ positioner = positioner.nextSibling;
129
+ }
130
+ }
131
+ trackChild = trackChild.nextSibling;
132
+ }
133
+ }
134
+ trackNode = trackNode.nextSibling;
135
+ }
136
+ }
137
+ if (child.tagName == 'tile') {
138
+ const pattern = child.getAttribute('pattern');
139
+ if (!(pattern in tile_1.TilePattern.patterns)) {
140
+ throw new Error(`Unknown tile pattern '${pattern}' in tile ${section.tiles.length + 1} in ${section.domainName}`);
141
+ }
142
+ section.tiles.push(new tile_1.Tile(section, +child.getAttribute('x'), +child.getAttribute('y'), tile_1.TilePattern.patterns[pattern]));
143
+ }
144
+ child = child.nextSibling;
145
+ }
146
+ }
147
+ findDevice(identifier) {
148
+ let device = this.devices.find(device => device.identifier == identifier);
149
+ if (device) {
150
+ return device;
151
+ }
152
+ device = new device_1.Device(identifier);
153
+ this.devices.push(device);
154
+ return device;
155
+ }
156
+ findChannel(device, name) {
157
+ let channel = device.channels.find(channel => channel.name == name);
158
+ if (channel) {
159
+ return channel;
160
+ }
161
+ channel = new channel_1.Channel(device, name);
162
+ device.channels.push(channel);
163
+ return channel;
164
+ }
165
+ findResponderType(name) {
166
+ let type = this.responderType.find(type => type.name == name);
167
+ if (type) {
168
+ return type;
169
+ }
170
+ type = new responder_type_1.ResponderType(name);
171
+ this.responderType.push(type);
172
+ return type;
173
+ }
174
+ linkSection(source, section) {
175
+ let child = source.firstChild;
176
+ while (child) {
177
+ if (child.tagName == 'out') {
178
+ const out = this.findSection(child.getAttribute('section'), section.district);
179
+ section.out = out;
180
+ out.in = section;
181
+ }
182
+ child = child.nextSibling;
183
+ }
184
+ }
185
+ findSection(path, base, source = base) {
186
+ const parts = path.split('.');
187
+ if (parts.length == 0) {
188
+ throw `section '${path}' not found from '${source.name}': invalid name`;
189
+ }
190
+ if (parts.length == 1) {
191
+ const localSection = base.sections.find(section => section.name == parts[0]);
192
+ if (!localSection) {
193
+ throw new Error(`Section '${path}' not found from '${source.name}': section does not exist in '${base.name}'`);
194
+ }
195
+ return localSection;
196
+ }
197
+ const sectionName = parts.pop();
198
+ let pool = base;
199
+ for (let index = 0; index < parts.length; index++) {
200
+ if (pool instanceof Layout || !pool.parent) {
201
+ throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a parent`);
202
+ }
203
+ pool = pool.parent;
204
+ }
205
+ for (let part of parts) {
206
+ const child = (pool instanceof district_1.District ? pool.children : pool.districts).find(child => child.name == part);
207
+ if (!child) {
208
+ throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a child named '${part}'`);
209
+ }
210
+ pool = child;
211
+ }
212
+ if (pool instanceof Layout) {
213
+ throw new Error(`Section '${path}' could not be found from '${source.name}': a layout cannot directly include a section`);
214
+ }
215
+ return this.findSection(sectionName, pool, source);
216
+ }
217
+ loadRouter(source, district) {
218
+ const router = new router_1.Router(source.getAttribute('name'), district);
219
+ return router;
220
+ }
221
+ linkRouter(source, router) {
222
+ let child = source.firstChild;
223
+ while (child) {
224
+ if (child.tagName == 'route') {
225
+ const route = new route_1.Route(child.getAttribute('name'), router);
226
+ route.in = this.findSection(child.getAttribute('in'), router.district);
227
+ route.in.out = router;
228
+ route.out = this.findSection(child.getAttribute('out'), router.district);
229
+ route.out.in = router;
230
+ router.routes.push(route);
231
+ }
232
+ child = child.nextSibling;
233
+ }
234
+ }
235
+ 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();
282
+ }
283
+ console.groupEnd();
284
+ }
285
+ }
286
+ exports.Layout = Layout;
@@ -0,0 +1,10 @@
1
+ import { Section } from './section.js';
2
+ export declare class SectionPosition {
3
+ section: Section;
4
+ offset: number;
5
+ reversed: boolean;
6
+ constructor(section: Section, offset: number, reversed: boolean);
7
+ get absolutePosition(): number;
8
+ advance(distance: number): any;
9
+ toString(): string;
10
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SectionPosition = void 0;
4
+ class SectionPosition {
5
+ section;
6
+ offset;
7
+ reversed;
8
+ constructor(section, offset, reversed) {
9
+ this.section = section;
10
+ this.offset = offset;
11
+ this.reversed = reversed;
12
+ }
13
+ get absolutePosition() {
14
+ if (this.reversed) {
15
+ return this.section.length - this.offset;
16
+ }
17
+ return this.offset;
18
+ }
19
+ advance(distance) {
20
+ if (this.offset + distance > this.section.length) {
21
+ const next = this.section.next(this.reversed);
22
+ if (!next) {
23
+ throw new Error(`Illegal advancement ${this} + ${distance}`);
24
+ }
25
+ return new SectionPosition(next, 0, this.reversed).advance(this.offset + distance - this.section.length);
26
+ }
27
+ return new SectionPosition(this.section, this.offset + distance, this.reversed);
28
+ }
29
+ toString() {
30
+ return `${this.section.name} @ ${this.offset.toFixed(1)} ${this.reversed ? 'backward' : 'forward'}`;
31
+ }
32
+ }
33
+ exports.SectionPosition = SectionPosition;