@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
@@ -1,6 +1,6 @@
1
1
  import { Layout } from "./layout";
2
2
  import { Monitor } from "./monitor";
3
- import { PowerDistrict } from "./power-district";
3
+ import { PowerDistrict } from "./power-district/index";
4
4
  import { Router } from "./router";
5
5
  import { Section } from "./section";
6
6
 
@@ -25,83 +25,4 @@ export class District {
25
25
 
26
26
  return `${this.name}.${this.parent.domainName}`;
27
27
  }
28
-
29
- dump() {
30
- console.group(`District ${this.domainName}`);
31
-
32
- if (this.powerDistricts.length) {
33
- console.group('power districts');
34
-
35
- for (let district of this.powerDistricts) {
36
- district.dump();
37
- }
38
-
39
- console.groupEnd();
40
- }
41
-
42
- if (this.sections.length) {
43
- console.group('sections');
44
-
45
- for (let section of this.sections) {
46
- section.dump();
47
- }
48
-
49
- console.groupEnd();
50
- }
51
-
52
- if (this.children.length) {
53
- console.group('children');
54
-
55
- for (let district of this.children) {
56
- district.dump();
57
- }
58
-
59
- console.groupEnd();
60
- }
61
-
62
- console.groupEnd();
63
- }
64
-
65
- toDotReference() {
66
- return `cluster_${this.name.replace(/-/g, '_')}${this.parent instanceof District ? this.parent.toDotReference() : ''}`;
67
- }
68
-
69
- toDotDefinition() {
70
- return `
71
- subgraph ${this.toDotReference()} {
72
- label = ${JSON.stringify(this.name)}
73
-
74
- ${this.sections.map(section => section.toDotDefinition()).join('')}
75
- ${this.routers.map(router => router.toDotDefinition()).join('')}
76
-
77
- ${this.children.map(child => child.toDotDefinition()).join('')}
78
- }
79
- `;
80
- }
81
-
82
- toDotConnection() {
83
- return `
84
- ${this.sections.map(section => section.toDotConnection()).join('')}
85
- ${this.routers.map(router => router.toDotConnection()).join('')}
86
-
87
- ${this.children.map(child => child.toDotConnection()).join('')}
88
- `;
89
- }
90
-
91
- toSVG() {
92
- return `
93
- <g id=${JSON.stringify(this.domainName)}>
94
- ${this.sections.map(section => section.toSVG()).join('')}
95
-
96
- ${this.children.map(child => child.toSVG()).join('')}
97
- </g>
98
- `;
99
- }
100
-
101
- findSVGPositions() {
102
- return [
103
- ...this.sections.map(section => section.findSVGPositions()),
104
- ...this.children.map(child => child.findSVGPositions())
105
- ];
106
- }
107
28
  }
package/source/layout.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { District } from "./district";
2
- import { PowerDistrict } from "./power-district";
2
+ import { PowerDistrict } from "./power-district/index";
3
3
  import { Route } from "./route";
4
4
  import { Router } from "./router";
5
5
  import { Section } from "./section";
@@ -400,66 +400,4 @@ export class Layout {
400
400
 
401
401
  return powerDistrict;
402
402
  }
403
-
404
- toDot() {
405
- let dot = 'digraph G {';
406
-
407
- for (let district of this.districts) {
408
- dot += district.toDotDefinition();
409
- }
410
-
411
- for (let district of this.districts) {
412
- dot += district.toDotConnection();
413
- }
414
-
415
- return `${dot}}`;
416
- }
417
-
418
- toSVG(inject = '') {
419
- const positons = this.districts.map(district => district.findSVGPositions()).flat(Infinity);
420
-
421
- const width = Math.max(...positons.map(position => position.x));
422
- const height = Math.max(...positons.map(position => position.y));
423
-
424
- let svg = `<svg width="100vw" height="100vh" viewBox="0 0 ${width + 1} ${height + 1}" xmlns="http://www.w3.org/2000/svg">
425
- <style>
426
-
427
- path {
428
- fill: none;
429
- stroke: #000;
430
- stroke-width: 0.2;
431
- }
432
-
433
- </style>
434
- `;
435
-
436
- for (let district of this.districts) {
437
- svg += district.toSVG();
438
- }
439
-
440
- return `${svg}${inject}</svg>`;
441
- }
442
-
443
- dump() {
444
- console.group(`Layout ${this.name}`);
445
- console.log('devices');
446
-
447
- for (let device of this.devices) {
448
- device.dump();
449
- }
450
-
451
- console.log('responder types');
452
-
453
- for (let type of this.responderType) {
454
- type.dump();
455
- }
456
-
457
- console.log('districts');
458
-
459
- for (let district of this.districts) {
460
- district.dump();
461
- }
462
-
463
- console.groupEnd();
464
- }
465
403
  }
package/source/monitor.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Device } from "./device";
1
+ import { Device } from "./device/index";
2
2
  import { District } from "./district";
3
3
  import { Layout } from "./layout";
4
4
 
@@ -7,13 +7,4 @@ export class Monitor {
7
7
  public device: Device,
8
8
  public scope: District | Layout
9
9
  ) { }
10
-
11
- dump() {
12
- console.group('Monitor');
13
- console.log('scope:', this.scope instanceof Layout ? '*' : this.scope.domainName);
14
-
15
- this.device.dump();
16
-
17
- console.groupEnd();
18
- }
19
10
  }
@@ -1,4 +1,4 @@
1
- import { Positioner } from ".";
1
+ import { Positioner } from "./index";
2
2
  import { Channel } from "../device/channel";
3
3
  import { Track } from "../track";
4
4
  import { ResponderType } from "./responder-type";
@@ -16,13 +16,4 @@ export class PointPositioner extends Positioner {
16
16
  get position() {
17
17
  return this.track.head.advance(this.offset);
18
18
  }
19
-
20
- dump() {
21
- console.group('Point positioner');
22
- console.log('offset:', this.offset);
23
-
24
- this.channel.dump();
25
-
26
- console.groupEnd();
27
- }
28
- }
19
+ }
@@ -2,8 +2,4 @@ export class ResponderType {
2
2
  constructor(
3
3
  public name: string
4
4
  ) {}
5
-
6
- dump() {
7
- console.log(`Responder Type '${this.name}'`);
8
- }
9
- }
5
+ }
@@ -1,5 +1,4 @@
1
1
  import { PowerDistrictActivator } from "./activator";
2
- import { Device } from "../device/index";
3
2
  import { District } from "../district";
4
3
  import { PowerDistrictMonitor } from "./monitor";
5
4
  import { PowerDistrictReverser } from "./reverser";
@@ -17,8 +16,4 @@ export class PowerDistrict {
17
16
  get domainName() {
18
17
  return `${this.name}.${this.district.domainName}`;
19
18
  }
20
-
21
- dump() {
22
- console.log(this.name);
23
- }
24
19
  }
package/source/route.ts CHANGED
@@ -4,13 +4,9 @@ import { Section } from "./section";
4
4
  export class Route {
5
5
  in: Section;
6
6
  out: Section;
7
-
7
+
8
8
  constructor(
9
9
  public name: string,
10
10
  public router: Router,
11
11
  ) {}
12
-
13
- dump() {
14
- console.log(`Route ${this.name}: ${this.in.domainName} → ${this.out.domainName}`);
15
- }
16
- }
12
+ }
package/source/router.ts CHANGED
@@ -5,7 +5,7 @@ export class Router {
5
5
  activeRoute?: Route;
6
6
 
7
7
  routes: Route[] = [];
8
-
8
+
9
9
  constructor(
10
10
  public name: string,
11
11
  public district: District
@@ -14,33 +14,4 @@ export class Router {
14
14
  get domainName() {
15
15
  return `${this.name}.${this.district.domainName}`;
16
16
  }
17
-
18
- dump() {
19
- console.group(`Router ${this.domainName}`);
20
-
21
- for (let route of this.routes) {
22
- route.dump();
23
- }
24
-
25
- console.groupEnd();
26
- }
27
-
28
- toDotReference() {
29
- return `router_${this.name.replace(/-/g, '_')}_${this.district.toDotReference()}`;
30
- }
31
-
32
- toDotDefinition() {
33
- return `
34
- ${this.toDotReference()} [ label = ${JSON.stringify(this.name)}, shape = diamond ]
35
- `;
36
- }
37
-
38
- toDotConnection() {
39
- return `
40
- ${this.routes.map(route => `
41
- ${route.in.toDotReference()} -> ${this.toDotReference()} [ headlabel = ${JSON.stringify(route.name)} ]
42
- ${this.toDotReference()} -> ${route.out.toDotReference()} [ taillabel = ${JSON.stringify(route.name)} ]
43
- `).join('')}
44
- `;
45
- }
46
- }
17
+ }
package/source/section.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import { District } from "./district";
2
2
  import { SectionPosition } from "./position";
3
- import { PowerDistrict } from "./power-district";
3
+ import { PowerDistrict } from "./power-district/index";
4
4
  import { Router } from "./router";
5
5
  import { Tile } from "./tile";
6
6
  import { Track } from "./track";
7
7
 
8
8
  export class Section {
9
9
  powerDistrict: PowerDistrict;
10
-
10
+
11
11
  tracks: Track[] = [];
12
12
  tiles: Tile[] = [];
13
-
13
+
14
14
  in?: Router | Section;
15
15
  out?: Router | Section;
16
-
16
+
17
17
  constructor(
18
18
  public name: string,
19
19
  public district: District
@@ -87,14 +87,14 @@ export class Section {
87
87
  start: 0,
88
88
  end: this.tiles[this.tiles.length - 1].pattern.length
89
89
  },
90
-
90
+
91
91
  tiles: [...this.tiles]
92
92
  };
93
93
  }
94
94
 
95
95
  let start = 0;
96
96
  let end = this.length;
97
-
97
+
98
98
  // only use the position limit if it is within our section
99
99
  if (startPosition.section == this) {
100
100
  end = startPosition.absolutePosition;
@@ -131,7 +131,7 @@ export class Section {
131
131
  if (start <= passed) {
132
132
  offset.start = (start + length - passed) * tile.pattern.length / length;
133
133
  }
134
-
134
+
135
135
  if (end >= passed) {
136
136
  offset.end = 0.5; // (start + length - passed) * tile.pattern.length / length;
137
137
  }
@@ -139,29 +139,13 @@ export class Section {
139
139
 
140
140
  passed += length;
141
141
  }
142
-
142
+
143
143
  return {
144
144
  offset,
145
145
  tiles
146
146
  };
147
147
  }
148
-
149
- dump() {
150
- console.group(`Section ${this.domainName}`);
151
-
152
- console.log('in', this.in?.name ?? 'buffer');
153
- console.log('out', this.out?.name ?? 'buffer');
154
-
155
- console.group(`tracks`);
156
-
157
- for (let track of this.tracks) {
158
- track.dump();
159
- }
160
-
161
- console.groupEnd();
162
- console.groupEnd();
163
- }
164
-
148
+
165
149
  get length() {
166
150
  return this.tracks.reduce((accumulator, track) => accumulator + track.length, 0);
167
151
  }
@@ -227,43 +211,4 @@ export class Section {
227
211
  tip: new SectionPosition(tip, reversed ? -length : tip.length + length, false)
228
212
  };
229
213
  }
230
-
231
- toDotReference() {
232
- return `section_${this.name.replace(/-/g, '_')}_${this.district.toDotReference()}`;
233
- }
234
-
235
- toDotDefinition() {
236
- return `
237
- ${this.toDotReference()} [ label = ${JSON.stringify(`${this.name}\n${this.length}`)}, shape = box ]
238
- `;
239
- }
240
-
241
- toDotConnection() {
242
- return `
243
- ${this.out instanceof Section ? `${this.toDotReference()} -> ${this.out.toDotReference()}` : ''}
244
- `;
245
- }
246
-
247
- toSVG() {
248
- return `
249
- <g id=${JSON.stringify(this.domainName).split('.').join('_')}>
250
- <style>
251
-
252
- g#${this.domainName.split('.').join('_')} path {
253
- stroke: hsl(${(this.length / this.tileLength)}deg, 100%, 50%);
254
- }
255
-
256
- </style>
257
-
258
- ${this.tiles.map(tile => tile.toSVG()).join('')}
259
- </g>
260
- `;
261
- }
262
-
263
- findSVGPositions() {
264
- return this.tiles.map(tile => ({
265
- x: tile.x,
266
- y: tile.y
267
- }));
268
- }
269
- }
214
+ }
@@ -1,4 +1,4 @@
1
- import { Device } from "./device";
1
+ import { Device } from "./device/index";
2
2
  import { District } from "./district";
3
3
  import { Layout } from "./layout";
4
4
 
@@ -7,13 +7,4 @@ export class Throttle {
7
7
  public device: Device,
8
8
  public scope: District | Layout
9
9
  ) { }
10
-
11
- dump() {
12
- console.group('Throttle');
13
- console.log('scope:', this.scope instanceof Layout ? '*' : this.scope.domainName);
14
-
15
- this.device.dump();
16
-
17
- console.groupEnd();
18
- }
19
10
  }
package/source/track.ts CHANGED
@@ -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
 
@@ -19,12 +19,8 @@ export class Track {
19
19
  if (track == this) {
20
20
  return new SectionPosition(this.section, offset, false);
21
21
  }
22
-
22
+
23
23
  offset += track.length;
24
24
  }
25
25
  }
26
-
27
- dump() {
28
- console.log(this.length);
29
- }
30
- }
26
+ }
package/tsconfig.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "outDir": ".built",
4
- "module": "esnext",
5
- "moduleResolution": "node",
6
3
  "target": "esnext",
7
- "declaration": true
8
- },
9
- "include": [
10
- "source"
11
- ]
4
+ "module": "esnext",
5
+ "outDir": ".built",
6
+ "declaration": true,
7
+ "lib": [
8
+ "esnext"
9
+ ]
10
+ }
12
11
  }
package/source/index.ts DELETED
@@ -1,23 +0,0 @@
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
-
13
- export * from './power-district/index';
14
- export * from './power-district/activator';
15
- export * from './power-district/monitor';
16
- export * from './power-district/reverser';
17
-
18
- export * from './positioner/index';
19
- export * from './positioner/point';
20
- export * from './positioner/responder-type';
21
-
22
- export * from './device/index';
23
- export * from './device/channel';