@packtrack/layout 1.1.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 (73) hide show
  1. package/.built/district.d.ts +2 -0
  2. package/.built/district.js +4 -3
  3. package/.built/index.d.ts +20 -17
  4. package/.built/index.js +20 -17
  5. package/.built/layout.d.ts +6 -0
  6. package/.built/layout.js +40 -11
  7. package/.built/monitor.d.ts +9 -0
  8. package/.built/monitor.js +15 -0
  9. package/.built/position.d.ts +3 -1
  10. package/.built/position.js +16 -0
  11. package/.built/positioner/point.d.ts +1 -1
  12. package/.built/source/device/channel.d.ts +2 -2
  13. package/.built/source/device/channel.js +4 -8
  14. package/.built/source/device/index.d.ts +10 -0
  15. package/.built/source/device/index.js +8 -0
  16. package/.built/source/district.d.ts +3 -7
  17. package/.built/source/district.js +4 -70
  18. package/.built/source/layout.d.ts +9 -6
  19. package/.built/source/layout.js +85 -86
  20. package/.built/source/monitor.d.ts +8 -0
  21. package/.built/source/monitor.js +8 -0
  22. package/.built/source/position.d.ts +3 -1
  23. package/.built/source/position.js +17 -5
  24. package/.built/source/positioner/index.d.ts +2 -0
  25. package/.built/source/positioner/index.js +2 -0
  26. package/.built/source/positioner/point.d.ts +12 -0
  27. package/.built/source/positioner/point.js +17 -0
  28. package/.built/source/positioner/responder-type.d.ts +4 -0
  29. package/.built/source/positioner/responder-type.js +6 -0
  30. package/.built/source/power-district/activator.d.ts +7 -0
  31. package/.built/source/power-district/activator.js +8 -0
  32. package/.built/source/power-district/index.d.ts +13 -0
  33. package/.built/source/power-district/index.js +14 -0
  34. package/.built/source/power-district/monitor.d.ts +7 -0
  35. package/.built/source/power-district/monitor.js +8 -0
  36. package/.built/source/power-district/reverser.d.ts +7 -0
  37. package/.built/source/power-district/reverser.js +8 -0
  38. package/.built/source/route.d.ts +0 -1
  39. package/.built/source/route.js +1 -8
  40. package/.built/source/router.d.ts +0 -4
  41. package/.built/source/router.js +1 -28
  42. package/.built/source/section.d.ts +1 -10
  43. package/.built/source/section.js +8 -57
  44. package/.built/source/span.d.ts +12 -0
  45. package/.built/source/span.js +77 -0
  46. package/.built/source/throttle.d.ts +8 -0
  47. package/.built/source/throttle.js +8 -0
  48. package/.built/source/tile.js +2 -7
  49. package/.built/source/track.d.ts +1 -2
  50. package/.built/source/track.js +3 -10
  51. package/.built/span.d.ts +12 -0
  52. package/.built/span.js +77 -0
  53. package/.built/throttle.d.ts +9 -0
  54. package/.built/throttle.js +15 -0
  55. package/index.ts +23 -0
  56. package/package.json +4 -4
  57. package/source/device/channel.ts +4 -4
  58. package/source/device/index.ts +2 -19
  59. package/source/district.ts +7 -83
  60. package/source/layout.ts +52 -74
  61. package/source/monitor.ts +10 -0
  62. package/source/position.ts +52 -32
  63. package/source/positioner/point.ts +2 -11
  64. package/source/positioner/responder-type.ts +1 -5
  65. package/source/power-district/index.ts +0 -5
  66. package/source/route.ts +2 -6
  67. package/source/router.ts +2 -31
  68. package/source/section.ts +10 -65
  69. package/source/span.ts +88 -0
  70. package/source/throttle.ts +10 -0
  71. package/source/track.ts +3 -7
  72. package/tsconfig.json +7 -8
  73. package/source/index.ts +0 -20
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Section = void 0;
4
- const position_1 = require("./position");
5
- const router_1 = require("./router");
6
- class Section {
1
+ import { SectionPosition } from "./position";
2
+ import { Router } from "./router";
3
+ export class Section {
7
4
  name;
8
5
  district;
9
6
  powerDistrict;
@@ -27,7 +24,7 @@ class Section {
27
24
  if (this.in instanceof Section) {
28
25
  return this.in;
29
26
  }
30
- if (this.in instanceof router_1.Router) {
27
+ if (this.in instanceof Router) {
31
28
  const activeRoute = this.in.activeRoute;
32
29
  if (!activeRoute) {
33
30
  throw new Error(`Router '${this.in.domainName}' has no active route`);
@@ -48,7 +45,7 @@ class Section {
48
45
  if (this.out instanceof Section) {
49
46
  return this.out;
50
47
  }
51
- if (this.out instanceof router_1.Router) {
48
+ if (this.out instanceof Router) {
52
49
  const activeRoute = this.out.activeRoute;
53
50
  if (!activeRoute) {
54
51
  throw new Error(`Router '${this.out.domainName}' has no active route`);
@@ -113,17 +110,6 @@ class Section {
113
110
  tiles
114
111
  };
115
112
  }
116
- dump() {
117
- console.group(`Section ${this.domainName}`);
118
- console.log('in', this.in?.name ?? 'buffer');
119
- console.log('out', this.out?.name ?? 'buffer');
120
- console.group(`tracks`);
121
- for (let track of this.tracks) {
122
- track.dump();
123
- }
124
- console.groupEnd();
125
- console.groupEnd();
126
- }
127
113
  get length() {
128
114
  return this.tracks.reduce((accumulator, track) => accumulator + track.length, 0);
129
115
  }
@@ -153,13 +139,13 @@ class Section {
153
139
  if (!next) {
154
140
  return {
155
141
  sections,
156
- tip: new position_1.SectionPosition(tip, tip.length, false)
142
+ tip: new SectionPosition(tip, tip.length, false)
157
143
  };
158
144
  }
159
145
  if (next instanceof Section) {
160
146
  tip = next;
161
147
  }
162
- if (next instanceof router_1.Router) {
148
+ if (next instanceof Router) {
163
149
  if (!next.activeRoute) {
164
150
  throw new Error(`Router '${next.domainName}' has no active route (routes: ${next.routes.map(route => `'${route.name}'`).join(', ')})`);
165
151
  }
@@ -176,42 +162,7 @@ class Section {
176
162
  }
177
163
  return {
178
164
  sections,
179
- tip: new position_1.SectionPosition(tip, reversed ? -length : tip.length + length, false)
165
+ tip: new SectionPosition(tip, reversed ? -length : tip.length + length, false)
180
166
  };
181
167
  }
182
- toDotReference() {
183
- return `section_${this.name.replace(/-/g, '_')}_${this.district.toDotReference()}`;
184
- }
185
- toDotDefinition() {
186
- return `
187
- ${this.toDotReference()} [ label = ${JSON.stringify(`${this.name}\n${this.length}`)}, shape = box ]
188
- `;
189
- }
190
- toDotConnection() {
191
- return `
192
- ${this.out instanceof Section ? `${this.toDotReference()} -> ${this.out.toDotReference()}` : ''}
193
- `;
194
- }
195
- toSVG() {
196
- return `
197
- <g id=${JSON.stringify(this.domainName).split('.').join('_')}>
198
- <style>
199
-
200
- g#${this.domainName.split('.').join('_')} path {
201
- stroke: hsl(${(this.length / this.tileLength)}deg, 100%, 50%);
202
- }
203
-
204
- </style>
205
-
206
- ${this.tiles.map(tile => tile.toSVG()).join('')}
207
- </g>
208
- `;
209
- }
210
- findSVGPositions() {
211
- return this.tiles.map(tile => ({
212
- x: tile.x,
213
- y: tile.y
214
- }));
215
- }
216
168
  }
217
- exports.Section = Section;
@@ -0,0 +1,12 @@
1
+ import { SectionPosition } from "./position";
2
+ import { Section } from "./section";
3
+ export declare class Span {
4
+ head: SectionPosition;
5
+ inside: Section[];
6
+ tail: SectionPosition;
7
+ constructor(head: SectionPosition, inside: Section[], tail: SectionPosition);
8
+ contains(position: SectionPosition): boolean;
9
+ overlap(peer: Span): boolean;
10
+ get length(): number;
11
+ static trail(start: SectionPosition, end: SectionPosition): Span;
12
+ }
@@ -0,0 +1,77 @@
1
+ export class Span {
2
+ head;
3
+ inside;
4
+ tail;
5
+ constructor(head, inside, tail) {
6
+ this.head = head;
7
+ this.inside = inside;
8
+ this.tail = tail;
9
+ }
10
+ // TODO verify reverse
11
+ contains(position) {
12
+ if (this.inside.includes(position.section)) {
13
+ return true;
14
+ }
15
+ if (position.section == this.head.section) {
16
+ if (this.head.reversed) {
17
+ if (this.head.absolutePosition > position.absolutePosition) {
18
+ return true;
19
+ }
20
+ }
21
+ else {
22
+ if (this.head.offset < position.absolutePosition) {
23
+ return true;
24
+ }
25
+ }
26
+ }
27
+ if (position.section == this.tail.section) {
28
+ if (this.tail.reversed) {
29
+ if (this.tail.absolutePosition < position.absolutePosition) {
30
+ return true;
31
+ }
32
+ }
33
+ else {
34
+ if (this.tail.offset > position.absolutePosition) {
35
+ return true;
36
+ }
37
+ }
38
+ }
39
+ return false;
40
+ }
41
+ overlap(peer) {
42
+ return this.contains(peer.head) || this.contains(peer.tail);
43
+ }
44
+ get length() {
45
+ let length = 0;
46
+ if (this.head.reversed) {
47
+ length += this.head.section.length - this.head.offset;
48
+ }
49
+ else {
50
+ length += this.head.offset;
51
+ }
52
+ for (let section of this.inside) {
53
+ length += section.length;
54
+ }
55
+ if (this.tail.reversed) {
56
+ length += this.tail.section.length - this.tail.offset;
57
+ }
58
+ else {
59
+ length += this.tail.offset;
60
+ }
61
+ return length;
62
+ }
63
+ // TODO verify reverse
64
+ // TODO add efficient algo
65
+ static trail(start, end) {
66
+ let head = start;
67
+ const sections = [];
68
+ const increment = 1;
69
+ while (head.section != end.section) {
70
+ head = head.advance(increment);
71
+ if (head.section != start.section && head.section != end.section && !sections.includes(head.section)) {
72
+ sections.push(head.section);
73
+ }
74
+ }
75
+ return new Span(start, sections, end);
76
+ }
77
+ }
@@ -0,0 +1,8 @@
1
+ import { Device } from "./device/index";
2
+ import { District } from "./district";
3
+ import { Layout } from "./layout";
4
+ export declare class Throttle {
5
+ device: Device;
6
+ scope: District | Layout;
7
+ constructor(device: Device, scope: District | Layout);
8
+ }
@@ -0,0 +1,8 @@
1
+ export class Throttle {
2
+ device;
3
+ scope;
4
+ constructor(device, scope) {
5
+ this.device = device;
6
+ this.scope = scope;
7
+ }
8
+ }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tile = exports.TilePattern = void 0;
4
- class TilePattern {
1
+ export class TilePattern {
5
2
  length;
6
3
  path;
7
4
  // TODO: replace simple paths with rounded versions
@@ -53,8 +50,7 @@ class TilePattern {
53
50
  this.path = path;
54
51
  }
55
52
  }
56
- exports.TilePattern = TilePattern;
57
- class Tile {
53
+ export class Tile {
58
54
  section;
59
55
  x;
60
56
  y;
@@ -75,4 +71,3 @@ class Tile {
75
71
  `;
76
72
  }
77
73
  }
78
- exports.Tile = Tile;
@@ -1,4 +1,4 @@
1
- import { Positioner } from "../positioner";
1
+ import { Positioner } from "./positioner/index";
2
2
  import { Section } from "./section";
3
3
  import { SectionPosition } from "./position";
4
4
  export declare class Track {
@@ -8,5 +8,4 @@ export declare class Track {
8
8
  positioners: Positioner[];
9
9
  constructor(section: Section, length: number, path: string);
10
10
  get head(): SectionPosition;
11
- dump(): void;
12
11
  }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Track = void 0;
4
- const position_1 = require("./position");
5
- class Track {
1
+ import { SectionPosition } from "./position";
2
+ export class Track {
6
3
  section;
7
4
  length;
8
5
  path;
@@ -17,13 +14,9 @@ class Track {
17
14
  let offset = 0;
18
15
  for (let track of this.section.tracks) {
19
16
  if (track == this) {
20
- return new position_1.SectionPosition(this.section, offset, false);
17
+ return new SectionPosition(this.section, offset, false);
21
18
  }
22
19
  offset += track.length;
23
20
  }
24
21
  }
25
- dump() {
26
- console.log(this.length);
27
- }
28
22
  }
29
- exports.Track = Track;
@@ -0,0 +1,12 @@
1
+ import { SectionPosition } from "./position";
2
+ import { Section } from "./section";
3
+ export declare class Span {
4
+ head: SectionPosition;
5
+ inside: Section[];
6
+ tail: SectionPosition;
7
+ constructor(head: SectionPosition, inside: Section[], tail: SectionPosition);
8
+ contains(position: SectionPosition): boolean;
9
+ overlap(peer: Span): boolean;
10
+ get length(): number;
11
+ static trail(start: SectionPosition, end: SectionPosition): Span;
12
+ }
package/.built/span.js ADDED
@@ -0,0 +1,77 @@
1
+ export class Span {
2
+ head;
3
+ inside;
4
+ tail;
5
+ constructor(head, inside, tail) {
6
+ this.head = head;
7
+ this.inside = inside;
8
+ this.tail = tail;
9
+ }
10
+ // TODO verify reverse
11
+ contains(position) {
12
+ if (this.inside.includes(position.section)) {
13
+ return true;
14
+ }
15
+ if (position.section == this.head.section) {
16
+ if (this.head.reversed) {
17
+ if (this.head.absolutePosition > position.absolutePosition) {
18
+ return true;
19
+ }
20
+ }
21
+ else {
22
+ if (this.head.offset < position.absolutePosition) {
23
+ return true;
24
+ }
25
+ }
26
+ }
27
+ if (position.section == this.tail.section) {
28
+ if (this.tail.reversed) {
29
+ if (this.tail.absolutePosition < position.absolutePosition) {
30
+ return true;
31
+ }
32
+ }
33
+ else {
34
+ if (this.tail.offset > position.absolutePosition) {
35
+ return true;
36
+ }
37
+ }
38
+ }
39
+ return false;
40
+ }
41
+ overlap(peer) {
42
+ return this.contains(peer.head) || this.contains(peer.tail);
43
+ }
44
+ get length() {
45
+ let length = 0;
46
+ if (this.head.reversed) {
47
+ length += this.head.section.length - this.head.offset;
48
+ }
49
+ else {
50
+ length += this.head.offset;
51
+ }
52
+ for (let section of this.inside) {
53
+ length += section.length;
54
+ }
55
+ if (this.tail.reversed) {
56
+ length += this.tail.section.length - this.tail.offset;
57
+ }
58
+ else {
59
+ length += this.tail.offset;
60
+ }
61
+ return length;
62
+ }
63
+ // TODO verify reverse
64
+ // TODO add efficient algo
65
+ static trail(start, end) {
66
+ let head = start;
67
+ const sections = [];
68
+ const increment = 1;
69
+ while (head.section != end.section) {
70
+ head = head.advance(increment);
71
+ if (head.section != start.section && head.section != end.section && !sections.includes(head.section)) {
72
+ sections.push(head.section);
73
+ }
74
+ }
75
+ return new Span(start, sections, end);
76
+ }
77
+ }
@@ -0,0 +1,9 @@
1
+ import { Device } from "./device";
2
+ import { District } from "./district";
3
+ import { Layout } from "./layout";
4
+ export declare class Throttle {
5
+ device: Device;
6
+ scope: District | Layout;
7
+ constructor(device: Device, scope: District | Layout);
8
+ dump(): void;
9
+ }
@@ -0,0 +1,15 @@
1
+ import { Layout } from "./layout";
2
+ export class Throttle {
3
+ device;
4
+ scope;
5
+ constructor(device, scope) {
6
+ this.device = device;
7
+ this.scope = scope;
8
+ }
9
+ dump() {
10
+ console.group('Throttle');
11
+ console.log('scope:', this.scope instanceof Layout ? '*' : this.scope.domainName);
12
+ this.device.dump();
13
+ console.groupEnd();
14
+ }
15
+ }
package/index.ts ADDED
@@ -0,0 +1,23 @@
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
+
13
+ export * from './source/power-district/index';
14
+ export * from './source/power-district/activator';
15
+ export * from './source/power-district/monitor';
16
+ export * from './source/power-district/reverser';
17
+
18
+ export * from './source/positioner/index';
19
+ export * from './source/positioner/point';
20
+ export * from './source/positioner/responder-type';
21
+
22
+ export * from './source/device/index';
23
+ export * from './source/device/channel';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@packtrack/layout",
3
- "version": "1.1.0",
4
- "main": ".built/index.js",
5
- "typings": ".built/index.d.ts",
3
+ "version": "1.3.0",
4
+ "main": ".built/source/index.js",
5
+ "typings": ".built/source/index.d.ts",
6
6
  "sideEffects": false,
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "preversion": "tsc"
9
+ "preversion": "npm run build"
10
10
  },
11
11
  "devDependencies": {
12
12
  "typescript": "^5.3.3"
@@ -6,9 +6,9 @@ export class Channel {
6
6
  public name: string
7
7
  ) {}
8
8
 
9
- dump() {
10
- console.log(`Channel '${this.name}' on ${this.device.identifier}`);
11
- }
12
-
13
9
  publish(data: any) {}
10
+
11
+ toString() {
12
+ return `${this.device.identifier}/${this.name}`;
13
+ }
14
14
  }
@@ -4,25 +4,8 @@ export class Device {
4
4
  channels: Channel[] = [];
5
5
 
6
6
  lastDiscovery: { date: Date, address: string };
7
-
7
+
8
8
  constructor(
9
9
  public identifier: string
10
10
  ) {}
11
-
12
- dump() {
13
- console.group(`Device ${this.identifier}`);
14
-
15
- if (this.lastDiscovery) {
16
- console.log(`last discovery: ${this.lastDiscovery.date.toISOString()} ${this.lastDiscovery.address}`);
17
- }
18
-
19
- console.group('channels');
20
-
21
- for (let channel of this.channels) {
22
- channel.dump();
23
- }
24
-
25
- console.groupEnd();
26
- console.groupEnd();
27
- }
28
- }
11
+ }
@@ -1,15 +1,18 @@
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
 
6
7
  export class District {
7
8
  children: District[] = [];
8
-
9
+
9
10
  powerDistricts: PowerDistrict[] = [];
10
11
  sections: Section[] = [];
11
12
  routers: Router[] = [];
12
-
13
+
14
+ monitors: Monitor[] = [];
15
+
13
16
  constructor(
14
17
  public name: string,
15
18
  public parent: District | Layout
@@ -22,83 +25,4 @@ export class District {
22
25
 
23
26
  return `${this.name}.${this.parent.domainName}`;
24
27
  }
25
-
26
- dump() {
27
- console.group(`District ${this.domainName}`);
28
-
29
- if (this.powerDistricts.length) {
30
- console.group('power districts');
31
-
32
- for (let district of this.powerDistricts) {
33
- district.dump();
34
- }
35
-
36
- console.groupEnd();
37
- }
38
-
39
- if (this.sections.length) {
40
- console.group('sections');
41
-
42
- for (let section of this.sections) {
43
- section.dump();
44
- }
45
-
46
- console.groupEnd();
47
- }
48
-
49
- if (this.children.length) {
50
- console.group('children');
51
-
52
- for (let district of this.children) {
53
- district.dump();
54
- }
55
-
56
- console.groupEnd();
57
- }
58
-
59
- console.groupEnd();
60
- }
61
-
62
- toDotReference() {
63
- return `cluster_${this.name.replace(/-/g, '_')}${this.parent instanceof District ? this.parent.toDotReference() : ''}`;
64
- }
65
-
66
- toDotDefinition() {
67
- return `
68
- subgraph ${this.toDotReference()} {
69
- label = ${JSON.stringify(this.name)}
70
-
71
- ${this.sections.map(section => section.toDotDefinition()).join('')}
72
- ${this.routers.map(router => router.toDotDefinition()).join('')}
73
-
74
- ${this.children.map(child => child.toDotDefinition()).join('')}
75
- }
76
- `;
77
- }
78
-
79
- toDotConnection() {
80
- return `
81
- ${this.sections.map(section => section.toDotConnection()).join('')}
82
- ${this.routers.map(router => router.toDotConnection()).join('')}
83
-
84
- ${this.children.map(child => child.toDotConnection()).join('')}
85
- `;
86
- }
87
-
88
- toSVG() {
89
- return `
90
- <g id=${JSON.stringify(this.domainName)}>
91
- ${this.sections.map(section => section.toSVG()).join('')}
92
-
93
- ${this.children.map(child => child.toSVG()).join('')}
94
- </g>
95
- `;
96
- }
97
-
98
- findSVGPositions() {
99
- return [
100
- ...this.sections.map(section => section.findSVGPositions()),
101
- ...this.children.map(child => child.findSVGPositions())
102
- ];
103
- }
104
- }
28
+ }