ui-router-devtools 0.0.1-alpha.0 → 0.1.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.
- package/LICENSE +9 -0
- package/README.md +161 -0
- package/dist/console.d.ts +5 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +47 -0
- package/dist/console.js.map +1 -0
- package/dist/define.d.ts +8 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +4 -0
- package/dist/define.js.map +1 -0
- package/dist/edges.d.ts +25 -0
- package/dist/edges.d.ts.map +1 -0
- package/dist/edges.js +28 -0
- package/dist/edges.js.map +1 -0
- package/dist/element/chips.d.ts +17 -0
- package/dist/element/chips.d.ts.map +1 -0
- package/dist/element/chips.js +134 -0
- package/dist/element/chips.js.map +1 -0
- package/dist/element/glyphs.d.ts +34 -0
- package/dist/element/glyphs.d.ts.map +1 -0
- package/dist/element/glyphs.js +107 -0
- package/dist/element/glyphs.js.map +1 -0
- package/dist/element/inspector.d.ts +7 -0
- package/dist/element/inspector.d.ts.map +1 -0
- package/dist/element/inspector.js +183 -0
- package/dist/element/inspector.js.map +1 -0
- package/dist/element/links.d.ts +4 -0
- package/dist/element/links.d.ts.map +1 -0
- package/dist/element/links.js +87 -0
- package/dist/element/links.js.map +1 -0
- package/dist/element/log.d.ts +12 -0
- package/dist/element/log.d.ts.map +1 -0
- package/dist/element/log.js +272 -0
- package/dist/element/log.js.map +1 -0
- package/dist/element/map.d.ts +5 -0
- package/dist/element/map.d.ts.map +1 -0
- package/dist/element/map.js +5 -0
- package/dist/element/map.js.map +1 -0
- package/dist/element/mapview.d.ts +17 -0
- package/dist/element/mapview.d.ts.map +1 -0
- package/dist/element/mapview.js +158 -0
- package/dist/element/mapview.js.map +1 -0
- package/dist/element/measure.d.ts +3 -0
- package/dist/element/measure.d.ts.map +1 -0
- package/dist/element/measure.js +9 -0
- package/dist/element/measure.js.map +1 -0
- package/dist/element/nested.d.ts +45 -0
- package/dist/element/nested.d.ts.map +1 -0
- package/dist/element/nested.js +686 -0
- package/dist/element/nested.js.map +1 -0
- package/dist/element/pack.d.ts +75 -0
- package/dist/element/pack.d.ts.map +1 -0
- package/dist/element/pack.js +281 -0
- package/dist/element/pack.js.map +1 -0
- package/dist/element/panel.d.ts +159 -0
- package/dist/element/panel.d.ts.map +1 -0
- package/dist/element/panel.js +1542 -0
- package/dist/element/panel.js.map +1 -0
- package/dist/element/popover.d.ts +12 -0
- package/dist/element/popover.d.ts.map +1 -0
- package/dist/element/popover.js +38 -0
- package/dist/element/popover.js.map +1 -0
- package/dist/element/route.d.ts +75 -0
- package/dist/element/route.d.ts.map +1 -0
- package/dist/element/route.js +883 -0
- package/dist/element/route.js.map +1 -0
- package/dist/element/scrubber.d.ts +4 -0
- package/dist/element/scrubber.d.ts.map +1 -0
- package/dist/element/scrubber.js +67 -0
- package/dist/element/scrubber.js.map +1 -0
- package/dist/element/styles.d.ts +3 -0
- package/dist/element/styles.d.ts.map +1 -0
- package/dist/element/styles.js +2084 -0
- package/dist/element/styles.js.map +1 -0
- package/dist/element/timeline-styles.d.ts +3 -0
- package/dist/element/timeline-styles.d.ts.map +1 -0
- package/dist/element/timeline-styles.js +286 -0
- package/dist/element/timeline-styles.js.map +1 -0
- package/dist/element/timeline.d.ts +9 -0
- package/dist/element/timeline.d.ts.map +1 -0
- package/dist/element/timeline.js +225 -0
- package/dist/element/timeline.js.map +1 -0
- package/dist/element/tree.d.ts +24 -0
- package/dist/element/tree.d.ts.map +1 -0
- package/dist/element/tree.js +149 -0
- package/dist/element/tree.js.map +1 -0
- package/dist/element/viewmap-styles.d.ts +3 -0
- package/dist/element/viewmap-styles.d.ts.map +1 -0
- package/dist/element/viewmap-styles.js +282 -0
- package/dist/element/viewmap-styles.js.map +1 -0
- package/dist/element/viewmap.d.ts +39 -0
- package/dist/element/viewmap.d.ts.map +1 -0
- package/dist/element/viewmap.js +406 -0
- package/dist/element/viewmap.js.map +1 -0
- package/dist/element/viewport.d.ts +31 -0
- package/dist/element/viewport.d.ts.map +1 -0
- package/dist/element/viewport.js +37 -0
- package/dist/element/viewport.js.map +1 -0
- package/dist/element/waterfall.d.ts +85 -0
- package/dist/element/waterfall.d.ts.map +1 -0
- package/dist/element/waterfall.js +284 -0
- package/dist/element/waterfall.js.map +1 -0
- package/dist/fold.d.ts +27 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +104 -0
- package/dist/fold.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lit-ui-router.d.ts +24 -0
- package/dist/lit-ui-router.d.ts.map +1 -0
- package/dist/lit-ui-router.js +102 -0
- package/dist/lit-ui-router.js.map +1 -0
- package/dist/notation.d.ts +28 -0
- package/dist/notation.d.ts.map +1 -0
- package/dist/notation.js +105 -0
- package/dist/notation.js.map +1 -0
- package/dist/performance.d.ts +5 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +66 -0
- package/dist/performance.js.map +1 -0
- package/dist/plugin.d.ts +32 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +21 -0
- package/dist/plugin.js.map +1 -0
- package/dist/recorder.d.ts +30 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +117 -0
- package/dist/recorder.js.map +1 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -0
- package/dist/session-schema.d.ts +31 -0
- package/dist/session-schema.d.ts.map +1 -0
- package/dist/session-schema.js +314 -0
- package/dist/session-schema.js.map +1 -0
- package/dist/session.schema.json +1172 -0
- package/dist/shared/event-schema.d.ts +225 -0
- package/dist/shared/event-schema.d.ts.map +1 -0
- package/dist/shared/event-schema.js +2 -0
- package/dist/shared/event-schema.js.map +1 -0
- package/dist/shared/redaction.d.ts +19 -0
- package/dist/shared/redaction.d.ts.map +1 -0
- package/dist/shared/redaction.js +56 -0
- package/dist/shared/redaction.js.map +1 -0
- package/dist/shared/resolve-timing.d.ts +6 -0
- package/dist/shared/resolve-timing.d.ts.map +1 -0
- package/dist/shared/resolve-timing.js +61 -0
- package/dist/shared/resolve-timing.js.map +1 -0
- package/dist/shared/router-events.d.ts +10 -0
- package/dist/shared/router-events.d.ts.map +1 -0
- package/dist/shared/router-events.js +296 -0
- package/dist/shared/router-events.js.map +1 -0
- package/dist/shared/thrown.d.ts +5 -0
- package/dist/shared/thrown.d.ts.map +1 -0
- package/dist/shared/thrown.js +12 -0
- package/dist/shared/thrown.js.map +1 -0
- package/dist/shared/transition-source.d.ts +4 -0
- package/dist/shared/transition-source.d.ts.map +1 -0
- package/dist/shared/transition-source.js +2 -0
- package/dist/shared/transition-source.js.map +1 -0
- package/dist/shared/views.d.ts +10 -0
- package/dist/shared/views.d.ts.map +1 -0
- package/dist/shared/views.js +67 -0
- package/dist/shared/views.js.map +1 -0
- package/dist/spans.d.ts +15 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +24 -0
- package/dist/spans.js.map +1 -0
- package/dist/testing.d.ts +32 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +28 -0
- package/dist/testing.js.map +1 -0
- package/dist/ui-router-devtools.d.ts +36 -0
- package/dist/ui-router-devtools.d.ts.map +1 -0
- package/dist/ui-router-devtools.js +3 -0
- package/dist/ui-router-devtools.js.map +1 -0
- package/dist/views.d.ts +44 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +43 -0
- package/dist/views.js.map +1 -0
- package/package.json +112 -2
- package/src/console.ts +104 -0
- package/src/define.ts +12 -0
- package/src/edges.ts +64 -0
- package/src/element/chips.ts +187 -0
- package/src/element/glyphs.ts +218 -0
- package/src/element/inspector.ts +315 -0
- package/src/element/links.ts +136 -0
- package/src/element/log.ts +410 -0
- package/src/element/map.ts +22 -0
- package/src/element/mapview.ts +224 -0
- package/src/element/measure.ts +13 -0
- package/src/element/nested.ts +1124 -0
- package/src/element/pack.ts +526 -0
- package/src/element/panel.ts +2378 -0
- package/src/element/popover.ts +64 -0
- package/src/element/route.ts +1481 -0
- package/src/element/scrubber.ts +103 -0
- package/src/element/styles.ts +2084 -0
- package/src/element/timeline-styles.ts +287 -0
- package/src/element/timeline.ts +392 -0
- package/src/element/tree.ts +271 -0
- package/src/element/viewmap-styles.ts +283 -0
- package/src/element/viewmap.ts +733 -0
- package/src/element/viewport.ts +112 -0
- package/src/element/waterfall.ts +585 -0
- package/src/fold.ts +151 -0
- package/src/index.ts +40 -0
- package/src/lit-ui-router.ts +194 -0
- package/src/notation.ts +181 -0
- package/src/performance.ts +142 -0
- package/src/plugin.ts +57 -0
- package/src/recorder.ts +228 -0
- package/src/schema.ts +32 -0
- package/src/session-schema.ts +362 -0
- package/src/spans.ts +53 -0
- package/src/testing.ts +74 -0
- package/src/types/import-meta-env.d.ts +9 -0
- package/src/ui-router-devtools.ts +39 -0
- package/src/views.ts +116 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LitElement } from "lit";
|
|
2
|
+
import type { UIRouter } from "@uirouter/core";
|
|
3
|
+
import type { Recorder } from "./recorder.js";
|
|
4
|
+
import type { Redaction, Session, SpanRecord } from "./schema.js";
|
|
5
|
+
import type { ViewLocator } from "./views.js";
|
|
6
|
+
/** <code><ui-router-devtools></code>: a pill that opens a panel of the router's states, transitions and config. */
|
|
7
|
+
export interface UIRouterDevtools extends LitElement {
|
|
8
|
+
/** The router to record. */
|
|
9
|
+
router: UIRouter | undefined;
|
|
10
|
+
/** How many transitions the log keeps; the attribute is `history`. */
|
|
11
|
+
history: number;
|
|
12
|
+
/** Time resolves by wrapping their `resolveFn`; read when the router attaches. The attribute is `time-resolves`. */
|
|
13
|
+
timeResolves: boolean;
|
|
14
|
+
/** What Export scrubs unless the panel's toggles say otherwise: param keys without their values and messages kept by default. */
|
|
15
|
+
redaction: Redaction;
|
|
16
|
+
/** The recorder behind the panel, for reporters that should share it. */
|
|
17
|
+
readonly recorder: Recorder | undefined;
|
|
18
|
+
/** The session the panel shows, live or imported, scrubbed by `redaction`, which defaults to the element's. */
|
|
19
|
+
session(redaction?: Partial<Redaction>): Session | undefined;
|
|
20
|
+
/** Shows `session` instead of the live router until the panel's Live button is pressed. */
|
|
21
|
+
importSession(session: Session): void;
|
|
22
|
+
/** Spans from a tracer, which the Timeline joins to transitions; setting it replaces them all. It holds the latest 2000. */
|
|
23
|
+
spans: readonly SpanRecord[];
|
|
24
|
+
/** Adds a span, or replaces the one with its `spanId`: a span can be sent when it starts, without `endTime`, and again when it ends. */
|
|
25
|
+
addSpan(span: SpanRecord): void;
|
|
26
|
+
/** Finds a view's element on the page for the Views, such as `litViewLocator` from `ui-router-devtools/lit-ui-router`; without one the Views draw the router's data only. */
|
|
27
|
+
viewLocator: ViewLocator | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** The `<ui-router-devtools>` class; `ui-router-devtools/define` registers it. */
|
|
30
|
+
export declare const UIRouterDevtools: {
|
|
31
|
+
/** Creates an element; `document.createElement('ui-router-devtools')` does too once it is registered. */
|
|
32
|
+
new (): UIRouterDevtools;
|
|
33
|
+
/** The prototype every `<ui-router-devtools>` shares. */
|
|
34
|
+
readonly prototype: UIRouterDevtools;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=ui-router-devtools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-router-devtools.d.ts","mappings":"AAAA,cAAc,kBAAkB;AAChC,cAAc,gBAAgB;AAG9B,cAAc,gBAAgB;AAC9B,cAAc,WAAW,SAAS,kBAAkB;AACpD,cAAc,mBAAmB;;AAGjC,iBAAiB,yBAAyB,WAAW;;CAEnD,QAAQ;;CAER;;CAEA;;CAEA,WAAW;;UAEF,UAAU;;CAEnB,QAAQ,YAAY,QAAQ,aAAa;;CAEzC,cAAc,SAAS;;CAEvB,gBAAgB;;CAEhB,QAAQ,MAAM;;CAEd,aAAa;AACf;;AAGA,OAAO,cAAM,kBAAkB;;SAErB;;UAEC,WAAW;AACtB","names":[],"ignoreList":[],"sources":["../src/ui-router-devtools.ts"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-router-devtools.js","mappings":"AAGA,SAAS,qBAAqB;AA8B9B,OAAO,MAAM,mBAKT","names":[],"ignoreList":[],"sources":["../src/ui-router-devtools.ts"]}
|
package/dist/views.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ViewFill, ViewInfo } from "./schema.js";
|
|
2
|
+
/** A `ui-view` in the nesting `fqn` describes, with the views registered inside it. */
|
|
3
|
+
export interface ViewNode {
|
|
4
|
+
/** The view as the snapshot records it. */
|
|
5
|
+
view: ViewInfo;
|
|
6
|
+
/** The enclosing view's id; null for a view at the top. */
|
|
7
|
+
parent: number | null;
|
|
8
|
+
/** From 1 at the top. */
|
|
9
|
+
depth: number;
|
|
10
|
+
/** The views registered inside this one. */
|
|
11
|
+
children: ViewNode[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* What a renderer adds to the panel's Views: where a view is on the page. The panel calls it when one is set, and
|
|
15
|
+
* only for the live router, never for an imported session.
|
|
16
|
+
*/
|
|
17
|
+
export interface ViewLocator {
|
|
18
|
+
/** Marks the view's place on the page; null takes the mark away. */
|
|
19
|
+
highlight(view: ViewInfo | null): void;
|
|
20
|
+
/** Where the page shows the view, in words; null when the page has no element for it. */
|
|
21
|
+
describe?(view: ViewInfo): string | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Nests views by their `fqn`: a view sits inside the view named by its `fqn` without the last segment. A view whose
|
|
25
|
+
* enclosing view is not registered is drawn at the top. Siblings keep the order they are given in.
|
|
26
|
+
*/
|
|
27
|
+
export declare const viewTree: (views: readonly ViewInfo[]) => ViewNode[];
|
|
28
|
+
/** A view config's target as a state's `views` can write it, `name@anchor`; the root's anchor is empty. */
|
|
29
|
+
export declare const targetText: ({ target }: ViewFill) => string;
|
|
30
|
+
/** The views a state fills, inside the views that hold them, and how many other views the snapshot has. */
|
|
31
|
+
export interface ViewPath {
|
|
32
|
+
/** The state the views are filled by: the one asked for, or the nearest of its ancestors that fills one. */
|
|
33
|
+
state: string;
|
|
34
|
+
/** The view tree pruned to the state's views and the views that hold them, in snapshot order. */
|
|
35
|
+
nodes: ViewNode[];
|
|
36
|
+
/** Views on no branch of `nodes`. */
|
|
37
|
+
others: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The view path of `state`: each view it fills and the views it sits inside. A state that fills none gives the path
|
|
41
|
+
* of the first of `ancestors`, nearest first, that does; null when none of them fills a view.
|
|
42
|
+
*/
|
|
43
|
+
export declare const viewPath: (views: readonly ViewInfo[], state: string, ancestors?: readonly string[]) => ViewPath | null;
|
|
44
|
+
//# sourceMappingURL=views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.d.ts","mappings":"AAAA,cAAc,UAAU,gBAAgB;;AAGxC,iBAAiB,SAAS;;CAExB,MAAM;;CAEN;;CAEA;;CAEA,UAAU;AACZ;;;;;AAMA,iBAAiB,YAAY;;CAE3B,UAAU,MAAM;;CAEhB,UAAU,MAAM;AAClB;;;;;AA0BA,OAAO,cAAM,WAAY,gBAAgB,eAAa;;AAsBtD,OAAO,cAAM,aAAc,EAAE,UAAU;;AAIvC,iBAAiB,SAAS;;CAExB;;CAEA,OAAO;;CAEP;AACF;;;;;AAkBA,OAAO,cAAM,WACX,gBAAgB,YAChB,eACA,kCACC","names":[],"ignoreList":[],"sources":["../src/views.ts"]}
|
package/dist/views.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const parentFqn = (fqn) => {
|
|
2
|
+
const dot = fqn.lastIndexOf(".");
|
|
3
|
+
return dot === -1 ? null : fqn.slice(0, dot);
|
|
4
|
+
};
|
|
5
|
+
const parentOf = (view, byFqn) => {
|
|
6
|
+
const fqn = parentFqn(view.fqn);
|
|
7
|
+
const candidates = fqn === null ? [] : byFqn.get(fqn) ?? [];
|
|
8
|
+
return candidates.find((candidate) => candidate.fill?.state === view.context) ?? candidates[0];
|
|
9
|
+
};
|
|
10
|
+
export const viewTree = (views) => {
|
|
11
|
+
const byFqn = new Map();
|
|
12
|
+
for (const view of views) byFqn.set(view.fqn, [...byFqn.get(view.fqn) ?? [], view]);
|
|
13
|
+
const parents = new Map(views.map((view) => [view.id, parentOf(view, byFqn)?.id ?? null]));
|
|
14
|
+
const build = (parent, depth) => views.flatMap((view) => parents.get(view.id) === parent ? [{
|
|
15
|
+
view,
|
|
16
|
+
parent,
|
|
17
|
+
depth,
|
|
18
|
+
children: build(view.id, depth + 1)
|
|
19
|
+
}] : []);
|
|
20
|
+
return build(null, 1);
|
|
21
|
+
};
|
|
22
|
+
export const targetText = ({ target }) => `${target.name}@${target.anchor}`;
|
|
23
|
+
const prune = (nodes, state) => nodes.flatMap((node) => {
|
|
24
|
+
const children = prune(node.children, state);
|
|
25
|
+
return node.view.fill?.state === state || children.length ? [{
|
|
26
|
+
...node,
|
|
27
|
+
children
|
|
28
|
+
}] : [];
|
|
29
|
+
});
|
|
30
|
+
const count = (nodes) => nodes.reduce((total, node) => total + 1 + count(node.children), 0);
|
|
31
|
+
export const viewPath = (views, state, ancestors = []) => {
|
|
32
|
+
const tree = viewTree(views);
|
|
33
|
+
for (const name of [state, ...ancestors]) {
|
|
34
|
+
const nodes = prune(tree, name);
|
|
35
|
+
if (nodes.length) return {
|
|
36
|
+
state: name,
|
|
37
|
+
nodes,
|
|
38
|
+
others: views.length - count(nodes)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=views.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.js","mappings":"AAyBA,MAAM,aAAa,QAA+B;CAChD,MAAM,MAAM,IAAI,YAAY,GAAG;CAE/B,OAAO,QAAQ,CAAC,IAAI,OAAO,IAAI,MAAM,GAAG,GAAG;AAC7C;AAGA,MAAM,YACJ,MACA,UACyB;CACzB,MAAM,MAAM,UAAU,KAAK,GAAG;CAC9B,MAAM,aAAa,QAAQ,OAAO,CAAC,IAAK,MAAM,IAAI,GAAG,KAAK,CAAC;CAE3D,OACE,WAAW,MAAM,cAAc,UAAU,MAAM,UAAU,KAAK,OAAO,KACrE,WAAW;AAEf;AAMA,OAAO,MAAM,YAAY,UAA2C;CAClE,MAAM,QAAQ,IAAI,IAAwB;CAE1C,KAAK,MAAM,QAAQ,OACjB,MAAM,IAAI,KAAK,KAAK,CAAC,GAAI,MAAM,IAAI,KAAK,GAAG,KAAK,CAAC,GAAI,IAAI,CAAC;CAE5D,MAAM,UAAU,IAAI,IAClB,MAAM,KAAK,SAAS,CAAC,KAAK,IAAI,SAAS,MAAM,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC,CAClE;CAEA,MAAM,SAAS,QAAuB,UACpC,MAAM,SAAS,SACb,QAAQ,IAAI,KAAK,EAAE,MAAM,SACrB,CAAC;EAAE;EAAM;EAAQ;EAAO,UAAU,MAAM,KAAK,IAAI,QAAQ,CAAC;CAAE,CAAC,IAC7D,CAAC,CACP;CAGF,OAAO,MAAM,MAAM,CAAC;AACtB;AAGA,OAAO,MAAM,cAAc,EAAE,aAC3B,GAAG,OAAO,KAAK,GAAG,OAAO;AAY3B,MAAM,SAAS,OAA4B,UACzC,MAAM,SAAS,SAAS;CACtB,MAAM,WAAW,MAAM,KAAK,UAAU,KAAK;CAE3C,OAAO,KAAK,KAAK,MAAM,UAAU,SAAS,SAAS,SAC/C,CAAC;EAAE,GAAG;EAAM;CAAS,CAAC,IACtB,CAAC;AACP,CAAC;AAEH,MAAM,SAAS,UACb,MAAM,QAAQ,OAAO,SAAS,QAAQ,IAAI,MAAM,KAAK,QAAQ,GAAG,CAAC;AAMnE,OAAO,MAAM,YACX,OACA,OACA,YAA+B,CAAC,MACZ;CACpB,MAAM,OAAO,SAAS,KAAK;CAE3B,KAAK,MAAM,QAAQ,CAAC,OAAO,GAAG,SAAS,GAAG;EACxC,MAAM,QAAQ,MAAM,MAAM,IAAI;EAE9B,IAAI,MAAM,QACR,OAAO;GAAE,OAAO;GAAM;GAAO,QAAQ,MAAM,SAAS,MAAM,KAAK;EAAE;CACrE;CAEA,OAAO;AACT","names":[],"ignoreList":[],"sources":["../src/views.ts"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,121 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui-router-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Devtools for any @uirouter/core router: a transition recorder, a Lit panel, a router plugin and Performance and console reporters",
|
|
5
|
+
"homepage": "https://lit-ui-router.dev/packages/ui-router-devtools",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/simshanith/lit-ui-router/issues"
|
|
8
|
+
},
|
|
5
9
|
"license": "MIT",
|
|
10
|
+
"author": "Shane Daniel",
|
|
6
11
|
"repository": {
|
|
7
12
|
"type": "git",
|
|
8
13
|
"url": "git+https://github.com/simshanith/lit-ui-router.git",
|
|
9
14
|
"directory": "packages/ui-router-devtools"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**",
|
|
18
|
+
"!dist/.*/**",
|
|
19
|
+
"src/**/*.ts",
|
|
20
|
+
"!src/specs/**"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./dist/define.js",
|
|
25
|
+
"./dist/plugin.js"
|
|
26
|
+
],
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./console": {
|
|
36
|
+
"types": "./dist/console.d.ts",
|
|
37
|
+
"default": "./dist/console.js"
|
|
38
|
+
},
|
|
39
|
+
"./define": {
|
|
40
|
+
"types": "./dist/define.d.ts",
|
|
41
|
+
"default": "./dist/define.js"
|
|
42
|
+
},
|
|
43
|
+
"./dist/*": "./dist/*",
|
|
44
|
+
"./lit-ui-router": {
|
|
45
|
+
"types": "./dist/lit-ui-router.d.ts",
|
|
46
|
+
"default": "./dist/lit-ui-router.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json",
|
|
49
|
+
"./performance": {
|
|
50
|
+
"types": "./dist/performance.d.ts",
|
|
51
|
+
"default": "./dist/performance.js"
|
|
52
|
+
},
|
|
53
|
+
"./plugin": {
|
|
54
|
+
"types": "./dist/plugin.d.ts",
|
|
55
|
+
"default": "./dist/plugin.js"
|
|
56
|
+
},
|
|
57
|
+
"./session.schema.json": "./dist/session.schema.json",
|
|
58
|
+
"./testing": {
|
|
59
|
+
"types": "./dist/testing.d.ts",
|
|
60
|
+
"default": "./dist/testing.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"d3-hierarchy": "^3.1.2",
|
|
65
|
+
"lit": "^3.0.0",
|
|
66
|
+
"valibot": "^1.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@uirouter/core": "^6.0.8"
|
|
70
|
+
},
|
|
71
|
+
"bundleProbe": {
|
|
72
|
+
".": {
|
|
73
|
+
"free": [
|
|
74
|
+
"lit",
|
|
75
|
+
"d3-hierarchy",
|
|
76
|
+
"valibot"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"./console": {
|
|
80
|
+
"free": [
|
|
81
|
+
"lit",
|
|
82
|
+
"d3-hierarchy",
|
|
83
|
+
"valibot"
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
"./define": {
|
|
87
|
+
"free": [
|
|
88
|
+
"d3-hierarchy",
|
|
89
|
+
"valibot"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"./lit-ui-router": {
|
|
93
|
+
"free": [
|
|
94
|
+
"lit",
|
|
95
|
+
"d3-hierarchy",
|
|
96
|
+
"valibot",
|
|
97
|
+
"lit-ui-router"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
"./performance": {
|
|
101
|
+
"free": [
|
|
102
|
+
"lit",
|
|
103
|
+
"d3-hierarchy",
|
|
104
|
+
"valibot"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"./plugin": {
|
|
108
|
+
"free": [
|
|
109
|
+
"d3-hierarchy",
|
|
110
|
+
"valibot"
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"./testing": {
|
|
114
|
+
"free": [
|
|
115
|
+
"lit",
|
|
116
|
+
"d3-hierarchy",
|
|
117
|
+
"valibot"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
10
120
|
}
|
|
11
|
-
}
|
|
121
|
+
}
|
package/src/console.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { durationOf, fold, type Tx } from './fold.ts';
|
|
2
|
+
import {
|
|
3
|
+
ms,
|
|
4
|
+
paramText,
|
|
5
|
+
pathText,
|
|
6
|
+
resultLine,
|
|
7
|
+
sameParam,
|
|
8
|
+
seq,
|
|
9
|
+
sourceTags,
|
|
10
|
+
statusText,
|
|
11
|
+
} from './notation.ts';
|
|
12
|
+
import type { Recorder } from './recorder.ts';
|
|
13
|
+
import type { Params, RouterEvent } from './schema.ts';
|
|
14
|
+
|
|
15
|
+
const DIM = 'color: GrayText';
|
|
16
|
+
|
|
17
|
+
const paramRows = (before: Params, after: Params) =>
|
|
18
|
+
Object.fromEntries(
|
|
19
|
+
[...new Set([...Object.keys(before), ...Object.keys(after)])].flatMap(
|
|
20
|
+
(key) =>
|
|
21
|
+
sameParam(before[key], after[key])
|
|
22
|
+
? []
|
|
23
|
+
: [
|
|
24
|
+
[
|
|
25
|
+
key,
|
|
26
|
+
{
|
|
27
|
+
before: paramText(before[key]),
|
|
28
|
+
after: paramText(after[key]),
|
|
29
|
+
},
|
|
30
|
+
] as const,
|
|
31
|
+
],
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const phaseLine = (tx: Tx): string =>
|
|
36
|
+
tx.marks
|
|
37
|
+
.filter((mark) => mark.edge === 'start')
|
|
38
|
+
.map(
|
|
39
|
+
(mark) =>
|
|
40
|
+
`${mark.phase}${mark.state ? ` ${mark.state}` : ''} +${ms(mark.t - tx.t)}`,
|
|
41
|
+
)
|
|
42
|
+
.join(', ');
|
|
43
|
+
|
|
44
|
+
const reportTx = (txs: readonly Tx[], tx: Tx) => {
|
|
45
|
+
const result = tx.result;
|
|
46
|
+
|
|
47
|
+
if (!result) return;
|
|
48
|
+
const tags = sourceTags(tx).map((tag) => tag.toUpperCase());
|
|
49
|
+
const took = tx.id < 0 ? '' : ms(durationOf(txs, tx, result.t));
|
|
50
|
+
|
|
51
|
+
const header = [
|
|
52
|
+
seq(tx.id),
|
|
53
|
+
statusText[result.outcome],
|
|
54
|
+
pathText(tx),
|
|
55
|
+
...tags,
|
|
56
|
+
took,
|
|
57
|
+
]
|
|
58
|
+
.filter(Boolean)
|
|
59
|
+
.join(' ');
|
|
60
|
+
|
|
61
|
+
console.groupCollapsed(header);
|
|
62
|
+
|
|
63
|
+
const text = resultLine(tx);
|
|
64
|
+
|
|
65
|
+
if (result.outcome === 'error' || result.outcome === 'invalid')
|
|
66
|
+
console.error(text);
|
|
67
|
+
else if (text) console.log(`%c${text}`, DIM);
|
|
68
|
+
const diff = paramRows(tx.fromParams, tx.toParams);
|
|
69
|
+
|
|
70
|
+
if (Object.keys(diff).length) console.table(diff);
|
|
71
|
+
const phases = phaseLine(tx);
|
|
72
|
+
|
|
73
|
+
if (phases) console.log(`%c${phases}`, DIM);
|
|
74
|
+
|
|
75
|
+
for (const r of tx.resolves.filter((r) => !r.cached))
|
|
76
|
+
console.log(
|
|
77
|
+
`%cresolve ${r.token} (${r.state}) ${ms(r.end - r.start)}${r.ok ? '' : ' failed'}`,
|
|
78
|
+
DIM,
|
|
79
|
+
);
|
|
80
|
+
console.groupEnd();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** One collapsed console group per settled transition; with a recorder it keeps reporting until the returned function is called. */
|
|
84
|
+
export function reportToConsole(
|
|
85
|
+
source: readonly RouterEvent[] | Recorder,
|
|
86
|
+
): () => void {
|
|
87
|
+
if (!('subscribe' in source)) {
|
|
88
|
+
const { txs } = fold(source);
|
|
89
|
+
txs.forEach((tx) => reportTx(txs, tx));
|
|
90
|
+
|
|
91
|
+
return () => {};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const recorder = source;
|
|
95
|
+
|
|
96
|
+
return recorder.subscribe((event) => {
|
|
97
|
+
if (event.type !== 'result' && event.type !== 'invalid') return;
|
|
98
|
+
const key = event.type === 'result' ? event.id : -event.seq;
|
|
99
|
+
const { txs } = fold(recorder.events);
|
|
100
|
+
const tx = txs.find((t) => t.id === key);
|
|
101
|
+
|
|
102
|
+
if (tx) reportTx(txs, tx);
|
|
103
|
+
});
|
|
104
|
+
}
|
package/src/define.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UIRouterDevtools } from './ui-router-devtools.ts';
|
|
2
|
+
|
|
3
|
+
export { UIRouterDevtools };
|
|
4
|
+
|
|
5
|
+
if (!customElements.get('ui-router-devtools'))
|
|
6
|
+
customElements.define('ui-router-devtools', UIRouterDevtools);
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
'ui-router-devtools': UIRouterDevtools;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/edges.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { fold, type Model } from './fold.ts';
|
|
2
|
+
import type { Outcome, Session } from './schema.ts';
|
|
3
|
+
|
|
4
|
+
/** A transition's outcome, or `running` for one that has not settled. */
|
|
5
|
+
export type EdgeOutcome = Outcome | 'running';
|
|
6
|
+
|
|
7
|
+
/** The traffic one ordered pair of states has seen. A router declares no transitions, so every edge is an observed one. */
|
|
8
|
+
export interface ObservedEdge {
|
|
9
|
+
/** The state the transitions left; `''` is the root, which the first transition leaves. */
|
|
10
|
+
from: string;
|
|
11
|
+
/** The state the transitions entered. */
|
|
12
|
+
to: string;
|
|
13
|
+
/** Every transition recorded for the pair, whatever its outcome. */
|
|
14
|
+
count: number;
|
|
15
|
+
/** The count of each outcome the pair's transitions had. */
|
|
16
|
+
outcomes: Partial<Record<EdgeOutcome, number>>;
|
|
17
|
+
/** Transition ids, in start order. */
|
|
18
|
+
ids: number[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The edges of a folded session; the panel keeps its model folded already.
|
|
22
|
+
export const edgesOf = (
|
|
23
|
+
model: Pick<Model, 'states' | 'txs'>,
|
|
24
|
+
): ObservedEdge[] => {
|
|
25
|
+
const known = new Set(model.states.map((state) => state.name));
|
|
26
|
+
const edges = new Map<string, ObservedEdge>();
|
|
27
|
+
|
|
28
|
+
for (const tx of model.txs) {
|
|
29
|
+
if (!known.has(tx.to) || (tx.from !== '' && !known.has(tx.from))) continue;
|
|
30
|
+
|
|
31
|
+
const key = JSON.stringify([tx.from, tx.to]);
|
|
32
|
+
|
|
33
|
+
const edge = edges.get(key) ?? {
|
|
34
|
+
from: tx.from,
|
|
35
|
+
to: tx.to,
|
|
36
|
+
count: 0,
|
|
37
|
+
outcomes: {},
|
|
38
|
+
ids: [],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const outcome = tx.result?.outcome ?? 'running';
|
|
42
|
+
edge.count += 1;
|
|
43
|
+
edge.outcomes[outcome] = (edge.outcomes[outcome] ?? 0) + 1;
|
|
44
|
+
edge.ids.push(tx.id);
|
|
45
|
+
edges.set(key, edge);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return [...edges.values()];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Aggregates a recorded session into one edge per ordered pair of states, in order of first appearance.
|
|
53
|
+
* A target that names no registered state has no edge.
|
|
54
|
+
*/
|
|
55
|
+
export const observedEdges = (
|
|
56
|
+
session: Pick<Session, 'events'>,
|
|
57
|
+
): ObservedEdge[] => edgesOf(fold(session.events));
|
|
58
|
+
|
|
59
|
+
// The line weight for a count: 1px for 1, 2px for 2 to 3, 3px for 4 or more.
|
|
60
|
+
export const edgeWeight = (count: number): 1 | 2 | 3 => {
|
|
61
|
+
if (count >= 4) return 3;
|
|
62
|
+
|
|
63
|
+
return count >= 2 ? 2 : 1;
|
|
64
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Places the Map's count chips: routes and boxes in, a place per chip out. It reads no DOM.
|
|
2
|
+
import type { Size } from './pack.ts';
|
|
3
|
+
import type { Point, Rect, RouteBox, Routed } from './route.ts';
|
|
4
|
+
|
|
5
|
+
export interface ChipWant extends Size {
|
|
6
|
+
/** The route the chip belongs to. */
|
|
7
|
+
id: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Chip extends Rect {
|
|
11
|
+
id: string;
|
|
12
|
+
/** The way the route travels where the chip sits: 0 east, 1 south, 2 west, 3 north. */
|
|
13
|
+
dir: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The line left showing between a chip and the end of the segment it sits on. */
|
|
17
|
+
const SHOW = 4;
|
|
18
|
+
|
|
19
|
+
/** An arrowhead and room beside it, kept clear at a route's ends. */
|
|
20
|
+
const HEAD = 10;
|
|
21
|
+
|
|
22
|
+
const STEP = 4;
|
|
23
|
+
|
|
24
|
+
/** Half the width of the halo an edge is drawn on. */
|
|
25
|
+
const HALO = 3;
|
|
26
|
+
|
|
27
|
+
const overlaps = (a: Rect, b: Rect): boolean =>
|
|
28
|
+
a.x < b.x + b.width &&
|
|
29
|
+
b.x < a.x + a.width &&
|
|
30
|
+
a.y < b.y + b.height &&
|
|
31
|
+
b.y < a.y + a.height;
|
|
32
|
+
|
|
33
|
+
const grown = ({ x, y, width, height }: Rect, by: number): Rect => ({
|
|
34
|
+
x: x - by,
|
|
35
|
+
y: y - by,
|
|
36
|
+
width: width + by * 2,
|
|
37
|
+
height: height + by * 2,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// What a chip may not cover: a leaf, a compound's header row and its border. The room inside a compound is free.
|
|
41
|
+
const solids = (boxes: readonly RouteBox[]): Rect[] =>
|
|
42
|
+
boxes.flatMap(({ rect, head }) => {
|
|
43
|
+
const { x, y, width, height } = rect;
|
|
44
|
+
|
|
45
|
+
if (height <= head + 1) return [rect];
|
|
46
|
+
|
|
47
|
+
return [
|
|
48
|
+
{ x, y, width, height: head },
|
|
49
|
+
{ x: x - 1, y, width: 2, height },
|
|
50
|
+
{ x: x + width - 1, y, width: 2, height },
|
|
51
|
+
{ x, y: y + height - 1, width, height: 2 },
|
|
52
|
+
];
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const segmentsOf = ({ points }: Routed): Rect[] =>
|
|
56
|
+
points.slice(1).map((b, index) => {
|
|
57
|
+
const a = points[index];
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
x: Math.min(a.x, b.x),
|
|
61
|
+
y: Math.min(a.y, b.y),
|
|
62
|
+
width: Math.abs(b.x - a.x),
|
|
63
|
+
height: Math.abs(b.y - a.y),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const dirOf = (a: Point, b: Point): number => {
|
|
68
|
+
if (a.y === b.y) return b.x >= a.x ? 0 : 2;
|
|
69
|
+
|
|
70
|
+
return b.y >= a.y ? 1 : 3;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
interface Spot {
|
|
74
|
+
centre: Point;
|
|
75
|
+
dir: number;
|
|
76
|
+
/** How far the spot is from the middle of the route, along it. */
|
|
77
|
+
off: number;
|
|
78
|
+
/** The chip sits beside the line, not on it. */
|
|
79
|
+
beside: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Places on the line, a step apart, wherever a segment is long enough to show past the chip at both ends.
|
|
83
|
+
const onLine = ({ points, tail }: Routed, size: Size): Spot[] => {
|
|
84
|
+
const lengths = points
|
|
85
|
+
.slice(1)
|
|
86
|
+
.map((b, i) => Math.abs(b.x - points[i].x) + Math.abs(b.y - points[i].y));
|
|
87
|
+
|
|
88
|
+
const half = lengths.reduce((total, length) => total + length, 0) / 2;
|
|
89
|
+
const spots: Spot[] = [];
|
|
90
|
+
let before = 0;
|
|
91
|
+
|
|
92
|
+
lengths.forEach((length, index) => {
|
|
93
|
+
const a = points[index];
|
|
94
|
+
const b = points[index + 1];
|
|
95
|
+
const dir = dirOf(a, b);
|
|
96
|
+
const span = (dir % 2 ? size.height : size.width) / 2 + SHOW;
|
|
97
|
+
const first = span + (index === 0 && tail ? HEAD : 0);
|
|
98
|
+
const last = length - span - (index === lengths.length - 1 ? HEAD : 0);
|
|
99
|
+
|
|
100
|
+
// The steps are counted from the middle of the route, so a chip that can sit there does.
|
|
101
|
+
const offset = (((half - before - first) % STEP) + STEP) % STEP;
|
|
102
|
+
|
|
103
|
+
for (let at = first + offset; at <= last; at += STEP)
|
|
104
|
+
spots.push({
|
|
105
|
+
centre: {
|
|
106
|
+
x: a.x + ((b.x - a.x) / length) * at,
|
|
107
|
+
y: a.y + ((b.y - a.y) / length) * at,
|
|
108
|
+
},
|
|
109
|
+
dir,
|
|
110
|
+
off: Math.abs(before + at - half),
|
|
111
|
+
beside: false,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
before += length;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return spots.toSorted((a, b) => a.off - b.off);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Places beside the middle of each segment, for a route too short to carry its chip.
|
|
121
|
+
const besideLine = ({ points }: Routed, size: Size): Spot[] =>
|
|
122
|
+
points.slice(1).flatMap((b, index) => {
|
|
123
|
+
const a = points[index];
|
|
124
|
+
const dir = dirOf(a, b);
|
|
125
|
+
const mid = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
126
|
+
// The chip meets the line's halo, so nothing shows between them.
|
|
127
|
+
const away = (dir % 2 ? size.width : size.height) / 2 + HALO;
|
|
128
|
+
|
|
129
|
+
return [-1, 1].map((sign) => ({
|
|
130
|
+
centre:
|
|
131
|
+
dir % 2
|
|
132
|
+
? { x: mid.x + sign * away, y: mid.y }
|
|
133
|
+
: { x: mid.x, y: mid.y + sign * away },
|
|
134
|
+
dir,
|
|
135
|
+
off: 0,
|
|
136
|
+
beside: true,
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A place for each wanted chip: on its route as near the middle as leaves it clear of every box, every other route
|
|
142
|
+
* and every other chip, else beside the route. A chip with no clear place is left out.
|
|
143
|
+
*/
|
|
144
|
+
export const placeChips = (
|
|
145
|
+
routed: readonly Routed[],
|
|
146
|
+
boxes: readonly RouteBox[],
|
|
147
|
+
wants: readonly ChipWant[],
|
|
148
|
+
): Chip[] => {
|
|
149
|
+
const blocked = solids(boxes);
|
|
150
|
+
const lines = new Map(routed.map((r) => [r.id, segmentsOf(r)]));
|
|
151
|
+
const chips: Chip[] = [];
|
|
152
|
+
|
|
153
|
+
for (const want of wants) {
|
|
154
|
+
const own = routed.find((r) => r.id === want.id);
|
|
155
|
+
|
|
156
|
+
if (!own) continue;
|
|
157
|
+
|
|
158
|
+
const others = [...lines].flatMap(([id, segments]) =>
|
|
159
|
+
id === want.id ? [] : segments.map((segment) => grown(segment, 3)),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const rectAt = ({ centre }: Spot): Rect => ({
|
|
163
|
+
// A hairline's coordinates sit mid-pixel; the chip keeps to whole ones.
|
|
164
|
+
x: Math.floor(centre.x - want.width / 2 + 0.25),
|
|
165
|
+
y: Math.floor(centre.y - want.height / 2 + 0.25),
|
|
166
|
+
width: want.width,
|
|
167
|
+
height: want.height,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const clear = (spot: Spot): boolean => {
|
|
171
|
+
const rect = rectAt(spot);
|
|
172
|
+
|
|
173
|
+
return ![
|
|
174
|
+
...blocked,
|
|
175
|
+
...others,
|
|
176
|
+
...chips.map((chip) => grown(chip, 2)),
|
|
177
|
+
...(spot.beside ? (lines.get(want.id) ?? []) : []),
|
|
178
|
+
].some((other) => overlaps(rect, other));
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const spot = [...onLine(own, want), ...besideLine(own, want)].find(clear);
|
|
182
|
+
|
|
183
|
+
if (spot) chips.push({ id: want.id, dir: spot.dir, ...rectAt(spot) });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return chips;
|
|
187
|
+
};
|