skillet-shared 0.2.0 → 0.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.
- package/dist/analytics.d.ts +1 -0
- package/dist/analytics.js +16 -0
- package/dist/dom.d.ts +1 -0
- package/dist/dom.js +6 -0
- package/dist/wire-route.d.ts +19 -0
- package/dist/wire-route.js +59 -0
- package/package.json +13 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startAnalytics(): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// A hit counter on every page the site serves. GoatCounter counts page views
|
|
2
|
+
// and sets no cookies, so no page asks first; /privacy/ says what it collects.
|
|
3
|
+
const COUNTER = 'https://cmdcolin.goatcounter.com/count';
|
|
4
|
+
// A browser a script is driving counts nothing: the harnesses that screenshot
|
|
5
|
+
// and record these pages are nobody's visit.
|
|
6
|
+
export function startAnalytics() {
|
|
7
|
+
if (navigator.webdriver)
|
|
8
|
+
return;
|
|
9
|
+
if (document.querySelector('script[data-goatcounter]'))
|
|
10
|
+
return;
|
|
11
|
+
const tag = document.createElement('script');
|
|
12
|
+
tag.async = true;
|
|
13
|
+
tag.src = 'https://gc.zgo.at/count.js';
|
|
14
|
+
tag.dataset.goatcounter = COUNTER;
|
|
15
|
+
document.head.append(tag);
|
|
16
|
+
}
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const need: (id: string) => HTMLElement;
|
package/dist/dom.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type Point = readonly [number, number];
|
|
2
|
+
/**
|
|
3
|
+
* A run through the given corners, each rounded off by `radius`.
|
|
4
|
+
*
|
|
5
|
+
* The radius is capped at half of the shorter leg either side of a corner, so a
|
|
6
|
+
* short leg between two turns rounds to what fits instead of overshooting into
|
|
7
|
+
* the next one. Two points are a straight line and no corner at all.
|
|
8
|
+
*/
|
|
9
|
+
export declare function route(pts: readonly Point[], radius: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* The head on the end of a run: a triangle whose tip is the last point and
|
|
12
|
+
* whose base sits `len` back along the last leg, `half` to either side of it.
|
|
13
|
+
*
|
|
14
|
+
* Off the same list the wire is routed from, so the head cannot point somewhere
|
|
15
|
+
* the wire does not go. The two numbers are the drawing's, not this file's —
|
|
16
|
+
* the miniature and the card set their type at different sizes and their heads
|
|
17
|
+
* with it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function arrowhead(pts: readonly Point[], len: number, half: number): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const round = (n) => Math.round(n * 1000) / 1000;
|
|
2
|
+
const at = (p) => `${round(p[0])} ${round(p[1])}`;
|
|
3
|
+
const dist = (a, b) => Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
4
|
+
// `by` units from `from` along the line to `to`. Clamped by the caller, not
|
|
5
|
+
// here: a zero-length leg has no direction to travel, and the corner it belongs
|
|
6
|
+
// to is the one place that knows what to do about it.
|
|
7
|
+
const toward = (from, to, by) => {
|
|
8
|
+
const d = dist(from, to);
|
|
9
|
+
if (d === 0)
|
|
10
|
+
return from;
|
|
11
|
+
return [
|
|
12
|
+
from[0] + ((to[0] - from[0]) * by) / d,
|
|
13
|
+
from[1] + ((to[1] - from[1]) * by) / d,
|
|
14
|
+
];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A run through the given corners, each rounded off by `radius`.
|
|
18
|
+
*
|
|
19
|
+
* The radius is capped at half of the shorter leg either side of a corner, so a
|
|
20
|
+
* short leg between two turns rounds to what fits instead of overshooting into
|
|
21
|
+
* the next one. Two points are a straight line and no corner at all.
|
|
22
|
+
*/
|
|
23
|
+
export function route(pts, radius) {
|
|
24
|
+
if (pts.length === 0)
|
|
25
|
+
return '';
|
|
26
|
+
const d = [`M${at(pts[0])}`];
|
|
27
|
+
for (let i = 1; i < pts.length - 1; i++) {
|
|
28
|
+
const prev = pts[i - 1];
|
|
29
|
+
const corner = pts[i];
|
|
30
|
+
const next = pts[i + 1];
|
|
31
|
+
const r = Math.min(radius, dist(prev, corner) / 2, dist(corner, next) / 2);
|
|
32
|
+
d.push(`L${at(toward(corner, prev, r))}`);
|
|
33
|
+
d.push(`Q${at(corner)} ${at(toward(corner, next, r))}`);
|
|
34
|
+
}
|
|
35
|
+
d.push(`L${at(pts[pts.length - 1])}`);
|
|
36
|
+
return d.join('');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The head on the end of a run: a triangle whose tip is the last point and
|
|
40
|
+
* whose base sits `len` back along the last leg, `half` to either side of it.
|
|
41
|
+
*
|
|
42
|
+
* Off the same list the wire is routed from, so the head cannot point somewhere
|
|
43
|
+
* the wire does not go. The two numbers are the drawing's, not this file's —
|
|
44
|
+
* the miniature and the card set their type at different sizes and their heads
|
|
45
|
+
* with it.
|
|
46
|
+
*/
|
|
47
|
+
export function arrowhead(pts, len, half) {
|
|
48
|
+
if (pts.length < 2)
|
|
49
|
+
return '';
|
|
50
|
+
const tip = pts[pts.length - 1];
|
|
51
|
+
const back = toward(tip, pts[pts.length - 2], len);
|
|
52
|
+
// The perpendicular to the last leg, at unit length times `half`.
|
|
53
|
+
const [dx, dy] = [tip[0] - back[0], tip[1] - back[1]];
|
|
54
|
+
const n = Math.hypot(dx, dy);
|
|
55
|
+
if (n === 0)
|
|
56
|
+
return '';
|
|
57
|
+
const [px, py] = [(-dy / n) * half, (dx / n) * half];
|
|
58
|
+
return `M${at([back[0] + px, back[1] + py])}L${at(tip)}L${at([back[0] - px, back[1] - py])}Z`;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skillet-shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Code shared by bender and videoskillet",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Colin Diesh",
|
|
@@ -19,6 +19,18 @@
|
|
|
19
19
|
"types": "./dist/posts.d.ts",
|
|
20
20
|
"default": "./dist/posts.js"
|
|
21
21
|
},
|
|
22
|
+
"./analytics": {
|
|
23
|
+
"types": "./dist/analytics.d.ts",
|
|
24
|
+
"default": "./dist/analytics.js"
|
|
25
|
+
},
|
|
26
|
+
"./dom": {
|
|
27
|
+
"types": "./dist/dom.d.ts",
|
|
28
|
+
"default": "./dist/dom.js"
|
|
29
|
+
},
|
|
30
|
+
"./wire-route": {
|
|
31
|
+
"types": "./dist/wire-route.d.ts",
|
|
32
|
+
"default": "./dist/wire-route.js"
|
|
33
|
+
},
|
|
22
34
|
"./tokens.css": "./dist/tokens.css"
|
|
23
35
|
},
|
|
24
36
|
"files": [
|