forked from denoland/docland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.ts
133 lines (122 loc) · 3.14 KB
/
shared.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2021 the Deno authors. All rights reserved. MIT license.
import type { StyleOverride } from "./components/styles.ts";
import {
getState as nanoGetSate,
setState as nanoSetState,
setup,
Store,
twColors,
virtualSheet,
} from "./deps.ts";
import type { DocNode, DocNodeNamespace } from "./deps.ts";
export const store = new Store({
entries: [],
namespaces: [],
url: "",
includePrivate: false,
});
export interface StoreState {
entries: DocNode[];
namespaces: DocNodeNamespace[];
url: string;
includePrivate: boolean;
}
export const sheet = virtualSheet();
setup({
sheet,
theme: {
backgroundSize: {
"4": "1rem",
},
colors: {
transparent: "transparent",
current: "currentColor",
black: twColors.black,
white: twColors.white,
gray: twColors.coolGray,
red: twColors.red,
yellow: twColors.amber,
green: twColors.emerald,
cyan: twColors.cyan,
blue: twColors.lightBlue,
indigo: twColors.indigo,
purple: twColors.fuchsia,
pink: twColors.pink,
},
fontFamily: {
"sans": [
"Inter var",
"system-ui",
"Segoe UI",
"Roboto",
"Helvetica Neue",
"Arial",
"Noto Sans",
"sans-serif",
],
"mono": [
"Menlo",
"Monaco",
"Lucida Console",
"Consolas",
"Liberation Mono",
"Courier New",
"monospace",
],
},
},
});
export const PRINT_THEME = "printer_styles";
export const STYLE_OVERRIDE = "style_override";
interface GetState {
(id: typeof STYLE_OVERRIDE): StyleOverride | undefined;
// deno-lint-ignore no-explicit-any
(id: string): any;
}
interface SetState {
(
id: typeof STYLE_OVERRIDE,
value: StyleOverride | undefined,
// deno-lint-ignore no-explicit-any
): Map<string, any>;
// deno-lint-ignore no-explicit-any
(id: string, value: any): Map<string, any>;
}
export const getState = nanoGetSate as GetState;
export const setState = nanoSetState as SetState;
/** Labels for known "builtin" library documentation. */
const BUILTIN_LABELS: Record<string, string> = {
"stable": "Deno CLI APIs",
"unstable": "Deno CLI APIs (unstable)",
"esnext": "ESNext APIs",
"dom": "DOM APIs",
};
const BUILTIN_RE = /^deno\/([^@\/]+)(?:@([^\/]+))?\//;
const VERSIONED_LIBS: string[] = ["stable", "unstable"];
export function getLibWithVersion(url: string): [string, string | undefined] {
const match = BUILTIN_RE.exec(url);
if (match) {
const [, lib, version] = match;
const label = BUILTIN_LABELS[lib];
if (label) {
return [
label,
version ?? (VERSIONED_LIBS.includes(lib) ? "latest" : undefined),
];
}
}
return [url.replace(/^\S+\/{2}/, ""), undefined];
}
/** Return a label for a URL, attempting to match the URL to the builtin label,
* otherwise returning a string with the protocol stripped from the URL. */
export function getUrlLabel(url: string) {
const match = BUILTIN_RE.exec(url);
if (match) {
const [, lib] = match;
const label = BUILTIN_LABELS[lib];
if (label) {
return label;
}
}
return url.replace(/^\S+\/{2}/, "");
}