@ignite-ember/ui-react 0.0.0-stage → 0.2.1
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 +202 -0
- package/NOTICE +5 -0
- package/README.md +260 -2
- package/dist/CopySource.d.ts +4 -0
- package/dist/CopySource.d.ts.map +1 -0
- package/dist/CopySource.js +50 -0
- package/dist/CopySource.js.map +1 -0
- package/dist/DataTable.d.ts +77 -0
- package/dist/DataTable.d.ts.map +1 -0
- package/dist/DataTable.js +45 -0
- package/dist/DataTable.js.map +1 -0
- package/dist/Dialog.d.ts +41 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +94 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +97 -0
- package/dist/ErrorBoundary.d.ts.map +1 -0
- package/dist/ErrorBoundary.js +97 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/LiveRegion.d.ts +41 -0
- package/dist/LiveRegion.d.ts.map +1 -0
- package/dist/LiveRegion.js +76 -0
- package/dist/LiveRegion.js.map +1 -0
- package/dist/Markdown.d.ts +22 -0
- package/dist/Markdown.d.ts.map +1 -0
- package/dist/Markdown.js +56 -0
- package/dist/Markdown.js.map +1 -0
- package/dist/MarkdownInline.d.ts +53 -0
- package/dist/MarkdownInline.d.ts.map +1 -0
- package/dist/MarkdownInline.js +159 -0
- package/dist/MarkdownInline.js.map +1 -0
- package/dist/MenuIcon.d.ts +60 -0
- package/dist/MenuIcon.d.ts.map +1 -0
- package/dist/MenuIcon.js +102 -0
- package/dist/MenuIcon.js.map +1 -0
- package/dist/Mermaid.d.ts +40 -0
- package/dist/Mermaid.d.ts.map +1 -0
- package/dist/Mermaid.js +121 -0
- package/dist/Mermaid.js.map +1 -0
- package/dist/Monogram.d.ts +46 -0
- package/dist/Monogram.d.ts.map +1 -0
- package/dist/Monogram.js +96 -0
- package/dist/Monogram.js.map +1 -0
- package/dist/OverflowMenu.d.ts +60 -0
- package/dist/OverflowMenu.d.ts.map +1 -0
- package/dist/OverflowMenu.js +149 -0
- package/dist/OverflowMenu.js.map +1 -0
- package/dist/Shell.d.ts +67 -0
- package/dist/Shell.d.ts.map +1 -0
- package/dist/Shell.js +44 -0
- package/dist/Shell.js.map +1 -0
- package/dist/Skeleton.d.ts +62 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +56 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/Split.d.ts +85 -0
- package/dist/Split.d.ts.map +1 -0
- package/dist/Split.js +156 -0
- package/dist/Split.js.map +1 -0
- package/dist/Tabs.d.ts +77 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +91 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Toast.d.ts +98 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +129 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Tooltip.d.ts +24 -0
- package/dist/Tooltip.d.ts.map +1 -0
- package/dist/Tooltip.js +166 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/controls.d.ts +117 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +59 -0
- package/dist/controls.js.map +1 -0
- package/dist/cx.d.ts +3 -0
- package/dist/cx.d.ts.map +1 -0
- package/dist/cx.js +5 -0
- package/dist/cx.js.map +1 -0
- package/dist/fenceInfo.d.ts +26 -0
- package/dist/fenceInfo.d.ts.map +1 -0
- package/dist/fenceInfo.js +22 -0
- package/dist/fenceInfo.js.map +1 -0
- package/dist/formControls.d.ts +143 -0
- package/dist/formControls.d.ts.map +1 -0
- package/dist/formControls.js +108 -0
- package/dist/formControls.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +95 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +93 -0
- package/dist/layout.js.map +1 -0
- package/dist/primitives.d.ts +33 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +33 -0
- package/dist/primitives.js.map +1 -0
- package/dist/progress.d.ts +64 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +51 -0
- package/dist/progress.js.map +1 -0
- package/dist/text.d.ts +63 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +61 -0
- package/dist/text.js.map +1 -0
- package/package.json +56 -4
- package/src/CopySource.tsx +67 -0
- package/src/DataTable.tsx +120 -0
- package/src/Dialog.tsx +158 -0
- package/src/ErrorBoundary.tsx +137 -0
- package/src/LiveRegion.tsx +127 -0
- package/src/Markdown.tsx +75 -0
- package/src/MarkdownInline.tsx +177 -0
- package/src/MenuIcon.tsx +209 -0
- package/src/Mermaid.tsx +144 -0
- package/src/Monogram.tsx +112 -0
- package/src/OverflowMenu.tsx +359 -0
- package/src/Shell.tsx +99 -0
- package/src/Skeleton.tsx +98 -0
- package/src/Split.tsx +267 -0
- package/src/Tabs.tsx +194 -0
- package/src/Toast.tsx +269 -0
- package/src/Tooltip.tsx +213 -0
- package/src/controls.tsx +159 -0
- package/src/cx.ts +4 -0
- package/src/fenceInfo.ts +36 -0
- package/src/formControls.tsx +249 -0
- package/src/index.ts +149 -0
- package/src/layout.tsx +141 -0
- package/src/primitives.tsx +33 -0
- package/src/progress.tsx +129 -0
- package/src/text.tsx +99 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import ReactMarkdown from "react-markdown";
|
|
4
|
+
import remarkGfm from "remark-gfm";
|
|
5
|
+
/**
|
|
6
|
+
* Markdown rendered as one flowing line of text.
|
|
7
|
+
*
|
|
8
|
+
* For previews: a list row, a snippet, anywhere a document has to be
|
|
9
|
+
* recognisable in two lines. Showing the raw source there leaks `##`
|
|
10
|
+
* and `**` into prose; rendering it normally is worse, because a
|
|
11
|
+
* heading at heading size in a 11.5px row is a heading, and a bullet
|
|
12
|
+
* list becomes four lines where there was room for two.
|
|
13
|
+
*
|
|
14
|
+
* So every block becomes inline. Headings keep their emphasis but not
|
|
15
|
+
* their size, list items are separated by middots rather than laid
|
|
16
|
+
* out, and code keeps its face. The result reads as the sentence the
|
|
17
|
+
* author wrote, which is what a preview is for.
|
|
18
|
+
*
|
|
19
|
+
* Two constraints are load-bearing, both from where this gets used:
|
|
20
|
+
*
|
|
21
|
+
* - **Nothing interactive.** These previews sit inside a `<button>`
|
|
22
|
+
* that opens the document. A link inside a button is invalid, and
|
|
23
|
+
* worse, it is a second click target inside the first.
|
|
24
|
+
* - **Nothing that loads.** An image in a preview is a network
|
|
25
|
+
* request to render two lines of text, and a broken one is an icon
|
|
26
|
+
* where a sentence should be.
|
|
27
|
+
*/
|
|
28
|
+
/** Blocks flow inline, so a preview is one sentence rather than a page. */
|
|
29
|
+
const INLINE_COMPONENTS = {
|
|
30
|
+
// Emphasis without the size. A document whose first line is a
|
|
31
|
+
// heading should read as its first line, not as a title.
|
|
32
|
+
h1: ({ children }) => _jsx("strong", { className: "mdi-heading", children: children }),
|
|
33
|
+
h2: ({ children }) => _jsx("strong", { className: "mdi-heading", children: children }),
|
|
34
|
+
h3: ({ children }) => _jsx("strong", { className: "mdi-heading", children: children }),
|
|
35
|
+
h4: ({ children }) => _jsx("strong", { className: "mdi-heading", children: children }),
|
|
36
|
+
h5: ({ children }) => _jsx("strong", { className: "mdi-heading", children: children }),
|
|
37
|
+
h6: ({ children }) => _jsx("strong", { className: "mdi-heading", children: children }),
|
|
38
|
+
p: ({ children }) => _jsx("span", { className: "mdi-block", children: children }),
|
|
39
|
+
blockquote: ({ children }) => _jsx("span", { className: "mdi-block", children: children }),
|
|
40
|
+
ul: ({ children }) => _jsx("span", { className: "mdi-block", children: children }),
|
|
41
|
+
ol: ({ children }) => _jsx("span", { className: "mdi-block", children: children }),
|
|
42
|
+
li: ({ children }) => _jsx("span", { className: "mdi-item", children: children }),
|
|
43
|
+
// A fenced block and an inline span both become inline code: the
|
|
44
|
+
// point of showing code in a preview is that it is code.
|
|
45
|
+
pre: ({ children }) => _jsx("span", { className: "mdi-block", children: children }),
|
|
46
|
+
code: ({ children }) => _jsx("code", { className: "mdi-code", children: children }),
|
|
47
|
+
// Text only. The row itself is the link.
|
|
48
|
+
a: ({ children }) => _jsx("span", { children: children }),
|
|
49
|
+
img: () => null,
|
|
50
|
+
hr: () => null,
|
|
51
|
+
br: () => _jsx("span", { children: " " }),
|
|
52
|
+
// Tables flatten to their cells. A preview of a table is not a
|
|
53
|
+
// table, and rendering one inside two clamped lines produces a
|
|
54
|
+
// column of single characters.
|
|
55
|
+
table: ({ children }) => _jsx("span", { className: "mdi-block", children: children }),
|
|
56
|
+
thead: () => null,
|
|
57
|
+
tbody: ({ children }) => _jsx("span", { children: children }),
|
|
58
|
+
tr: ({ children }) => _jsx("span", { className: "mdi-item", children: children }),
|
|
59
|
+
td: ({ children }) => _jsx("span", { className: "mdi-cell", children: children }),
|
|
60
|
+
th: ({ children }) => _jsx("span", { className: "mdi-cell", children: children }),
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Repair markdown cut mid-syntax.
|
|
64
|
+
*
|
|
65
|
+
* Previews arrive pre-truncated, and the cut lands wherever it lands
|
|
66
|
+
* — often inside `**bold` or an unclosed backtick. Rendered as-is the
|
|
67
|
+
* marker shows up literally, which is the thing this component
|
|
68
|
+
* exists to stop. Closing what was left open is cheaper than asking
|
|
69
|
+
* every producer of a preview to cut carefully.
|
|
70
|
+
*/
|
|
71
|
+
export function closeOpenMarks(text) {
|
|
72
|
+
let out = text;
|
|
73
|
+
// Fences first: an unclosed one swallows everything after it.
|
|
74
|
+
if ((out.match(/^```/gm) ?? []).length % 2 === 1)
|
|
75
|
+
out += "\n```";
|
|
76
|
+
// Then inline runs, longest marker first so `**` is not read as two
|
|
77
|
+
// single `*`.
|
|
78
|
+
for (const mark of ["**", "`", "*", "_"]) {
|
|
79
|
+
const count = out.split(mark).length - 1;
|
|
80
|
+
if (count % 2 === 1)
|
|
81
|
+
out += mark;
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Drop a leading line that only repeats the document's name.
|
|
87
|
+
*
|
|
88
|
+
* Most documents open with their own title. In a list the name is
|
|
89
|
+
* already the row's first line, so rendering it again spends the
|
|
90
|
+
* preview — the two lines somebody reads to tell this document from
|
|
91
|
+
* the next one — saying what they just read.
|
|
92
|
+
*
|
|
93
|
+
* Heading or plain line: the duplication is the same either way, and
|
|
94
|
+
* whether the author marked it up is not the reader's problem. The
|
|
95
|
+
* line has to *be* the name, though, not merely open with it —
|
|
96
|
+
* "Session handling is a signed JWT flow" is the first sentence of
|
|
97
|
+
* the document and belongs in the preview.
|
|
98
|
+
*/
|
|
99
|
+
export function dropEchoedTitle(text, name) {
|
|
100
|
+
const title = name.trim().toLowerCase();
|
|
101
|
+
if (!title)
|
|
102
|
+
return text;
|
|
103
|
+
const lines = text.split("\n");
|
|
104
|
+
let i = 0;
|
|
105
|
+
while (i < lines.length && !lines[i].trim())
|
|
106
|
+
i++;
|
|
107
|
+
const first = lines[i]?.trim() ?? "";
|
|
108
|
+
const heading = first.replace(/^#{1,6}\s+/, "").trim();
|
|
109
|
+
// Only when it *is* the title, not when it merely starts with it —
|
|
110
|
+
// "Session handling in detail" is a different heading.
|
|
111
|
+
if (heading.toLowerCase() !== title)
|
|
112
|
+
return text;
|
|
113
|
+
return lines
|
|
114
|
+
.slice(i + 1)
|
|
115
|
+
.join("\n")
|
|
116
|
+
.trimStart();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Markdown rendered as one flowing line of text.
|
|
120
|
+
*
|
|
121
|
+
* Every block becomes inline: headings keep their emphasis but not
|
|
122
|
+
* their size, list items are separated by middots, tables flatten to
|
|
123
|
+
* their cells, and links and images are dropped to their text or to
|
|
124
|
+
* nothing. `limit` bounds the work, not the appearance: the clamp is
|
|
125
|
+
* visual, and a document longer than `limit` is cut with an ellipsis,
|
|
126
|
+
* back to a word boundary when one falls in the last 40% of it.
|
|
127
|
+
*
|
|
128
|
+
* @param text — the markdown to render as one flowing line.
|
|
129
|
+
* @param name — the document's name, so a title echo can be dropped.
|
|
130
|
+
* @param limit — characters to keep; the clamp is visual, and this
|
|
131
|
+
* bounds the work.
|
|
132
|
+
* @param className — added to the element's classes, beside the one the
|
|
133
|
+
* theme gives it.
|
|
134
|
+
*/
|
|
135
|
+
export function MarkdownInline({ text,
|
|
136
|
+
/** The document's name, so a title echo can be dropped. */
|
|
137
|
+
name = "",
|
|
138
|
+
/** Characters to keep. The clamp is visual; this bounds the work. */
|
|
139
|
+
limit = 320, className = "", }) {
|
|
140
|
+
const source = useMemo(() => {
|
|
141
|
+
const body = dropEchoedTitle(String(text || ""), name);
|
|
142
|
+
if (body.length <= limit)
|
|
143
|
+
return closeOpenMarks(body);
|
|
144
|
+
// Cut back to a space so the preview does not end mid-word.
|
|
145
|
+
const cut = body.slice(0, limit);
|
|
146
|
+
const space = cut.lastIndexOf(" ");
|
|
147
|
+
const kept = space > limit * 0.6 ? cut.slice(0, space) : cut;
|
|
148
|
+
// Inside an unclosed fence the ellipsis goes in before the repair:
|
|
149
|
+
// after it, the closing fence would read "```…", which is not one.
|
|
150
|
+
if ((kept.match(/^```/gm) ?? []).length % 2 === 1) {
|
|
151
|
+
return closeOpenMarks(kept + "…");
|
|
152
|
+
}
|
|
153
|
+
return closeOpenMarks(kept) + "…";
|
|
154
|
+
}, [text, name, limit]);
|
|
155
|
+
if (!source.trim())
|
|
156
|
+
return null;
|
|
157
|
+
return (_jsx("span", { className: className ? `mdi ${className}` : "mdi", children: _jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], components: INLINE_COMPONENTS, children: source }) }));
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=MarkdownInline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownInline.js","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AAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAExB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC;IAEhC,OAAO,CACL,eAAM,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK,YACrD,KAAC,aAAa,IAAC,aAAa,EAAE,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,iBAAiB,YACrE,MAAM,GACO,GACX,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The small glyphs beside a menu item.
|
|
3
|
+
*
|
|
4
|
+
* A menu of five verbs reads as five equal options, and picking the
|
|
5
|
+
* wrong one of Archive and Remove costs quite differently. An icon is
|
|
6
|
+
* what makes a list scannable: the shape is recognised before the
|
|
7
|
+
* word is read, so the item somebody wants is found by looking rather
|
|
8
|
+
* than by reading the list from the top each time.
|
|
9
|
+
*
|
|
10
|
+
* **One set, one grammar.** All of them are 16×16, drawn in strokes
|
|
11
|
+
* of the same weight on the same grid, and coloured ``currentColor``
|
|
12
|
+
* so a disabled item's icon dims with its label and a destructive
|
|
13
|
+
* one turns red with it. Mixing a filled glyph into a stroked set is
|
|
14
|
+
* the single most obvious way to make a menu look assembled from
|
|
15
|
+
* parts.
|
|
16
|
+
*
|
|
17
|
+
* Inline rather than a sprite or a font: these are small paths used
|
|
18
|
+
* in a few menus, and a build step, a network request or a font with
|
|
19
|
+
* a flash of missing glyphs are all more machinery than the problem
|
|
20
|
+
* has.
|
|
21
|
+
*/
|
|
22
|
+
export type MenuIconName = "open" | "rename" | "export" | "share" | "archive" | "restore" | "remove" | "document" | "document-add" | "folder" | "folder-add" | "outdent" | "compare" | "lineage" | "code" | "list-bullet" | "list-ordered" | "list-task" | "quote" | "code-block" | "table" | "divider" | "link" | "image" | "undo" | "redo" | "resolve" | "reopen" | "lock" | "unlock" | "bell" | "copy" | "check";
|
|
23
|
+
/** What a {@link MenuIcon} takes. */
|
|
24
|
+
export interface MenuIconProps {
|
|
25
|
+
/** One of igni's own icons. */
|
|
26
|
+
name?: MenuIconName;
|
|
27
|
+
/**
|
|
28
|
+
* An SVG path, for an icon igni does not have.
|
|
29
|
+
*
|
|
30
|
+
* Here because the alternative is a closed union, and an extension
|
|
31
|
+
* cannot add a member to one. `PageKind` had the same problem and
|
|
32
|
+
* was opened for the same reason: what exists is decided at install
|
|
33
|
+
* time by what an administrator put on the machine, not at compile
|
|
34
|
+
* time by us.
|
|
35
|
+
*
|
|
36
|
+
* Drawn on a 16×16 grid, stroked rather than filled, to match. A
|
|
37
|
+
* path that assumes a different viewBox will look like it belongs
|
|
38
|
+
* to a different application, which is the one thing this whole
|
|
39
|
+
* package exists to prevent.
|
|
40
|
+
*/
|
|
41
|
+
path?: string;
|
|
42
|
+
/** Added to the element's classes, beside the one the theme gives it. */
|
|
43
|
+
className?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One of igni's own icons, drawn on a 16×16 grid.
|
|
47
|
+
*
|
|
48
|
+
* Every icon is drawn in one grammar: 16×16, strokes of the same
|
|
49
|
+
* weight, `currentColor`. A name that is not in the set draws nothing, rather
|
|
50
|
+
* than a broken box: the label says what the item does, and the icon
|
|
51
|
+
* is only how it is found.
|
|
52
|
+
*
|
|
53
|
+
* @param name — one of igni's own icons.
|
|
54
|
+
* @param path — an SVG path, for an icon igni does not have; it is
|
|
55
|
+
* drawn on the same 16×16 grid, stroked rather than filled.
|
|
56
|
+
* @param className — added to the element's classes, beside the one the
|
|
57
|
+
* theme gives it.
|
|
58
|
+
*/
|
|
59
|
+
export declare function MenuIcon({ name, path, className }: MenuIconProps): import("react").JSX.Element | null;
|
|
60
|
+
//# sourceMappingURL=MenuIcon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MenuIcon.d.ts","sourceRoot":"","sources":["../src/MenuIcon.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,QAAQ,GACR,UAAU,GACV,cAAc,GACd,QAAQ,GACR,YAAY,GACZ,SAAS,GACT,SAAS,GACT,SAAS,GAGT,MAAM,GACN,aAAa,GACb,cAAc,GACd,WAAW,GACX,OAAO,GACP,YAAY,GACZ,OAAO,GACP,SAAS,GACT,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,GACT,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,MAAM,GAEN,MAAM,GACN,OAAO,CAAC;AAiGZ,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,aAAa,sCAgBhE"}
|
package/dist/MenuIcon.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** The drawing for each name, on a 16×16 grid. */
|
|
3
|
+
const PATHS = {
|
|
4
|
+
// A page with a corner turned.
|
|
5
|
+
open: "M9 1.5H4.5A1.5 1.5 0 0 0 3 3v10a1.5 1.5 0 0 0 1.5 1.5h7A1.5 1.5 0 0 0 13 13V5.5zM9 1.5V5.5h4",
|
|
6
|
+
// A pencil across a line.
|
|
7
|
+
rename: "M11.2 2.3 13.7 4.8 6.2 12.3 3 13l.7-3.2zM2.5 14.5h11",
|
|
8
|
+
// Out of a tray, downwards — the file leaves.
|
|
9
|
+
export: "M8 2v7m0 0 2.8-2.8M8 9 5.2 6.2M2.8 10.5v2.2a1 1 0 0 0 1 1h8.4a1 1 0 0 0 1-1v-2.2",
|
|
10
|
+
// Two nodes joined to a third: one thing, several people.
|
|
11
|
+
share: "M5.6 9.3 10.4 12M10.4 4 5.6 6.7M12 2.2a1.8 1.8 0 1 1 0 3.6 1.8 1.8 0 0 1 0-3.6zM4 6.2a1.8 1.8 0 1 1 0 3.6 1.8 1.8 0 0 1 0-3.6zM12 10.2a1.8 1.8 0 1 1 0 3.6 1.8 1.8 0 0 1 0-3.6z",
|
|
12
|
+
// A box with a lid, and a handle on the drawer.
|
|
13
|
+
archive: "M2 3.2h12v2.6H2zM3 5.8v7a.8.8 0 0 0 .8.8h8.4a.8.8 0 0 0 .8-.8v-7M6.4 8.4h3.2",
|
|
14
|
+
// The same box, with the arrow coming back up out of it.
|
|
15
|
+
restore: "M2 3.2h12v2.6H2zM3 5.8v7a.8.8 0 0 0 .8.8h8.4a.8.8 0 0 0 .8-.8v-7M8 11.6V7.4m0 0L6.2 9.2M8 7.4l1.8 1.8",
|
|
16
|
+
// A bin. Deliberately the least like the archive of any of these.
|
|
17
|
+
remove: "M2.8 4.3h10.4M6.4 4.3V2.9a.7.7 0 0 1 .7-.7h1.8a.7.7 0 0 1 .7.7v1.4M4.2 4.3l.6 8.5a.9.9 0 0 0 .9.8h4.6a.9.9 0 0 0 .9-.8l.6-8.5M6.7 6.8v4.2M9.3 6.8v4.2",
|
|
18
|
+
// A page. The same shape as ``open`` without the action.
|
|
19
|
+
document: "M9 1.5H4.5A1.5 1.5 0 0 0 3 3v10a1.5 1.5 0 0 0 1.5 1.5h7A1.5 1.5 0 0 0 13 13V5.5zM9 1.5V5.5h4M5.5 8.5h5M5.5 11h3",
|
|
20
|
+
// The same page and folder, with the plus that makes one. Drawn
|
|
21
|
+
// from the same outlines rather than new shapes: "new document"
|
|
22
|
+
// and "document" should be recognisably the same noun.
|
|
23
|
+
"document-add": "M8.4 1.5H4.5A1.5 1.5 0 0 0 3 3v10a1.5 1.5 0 0 0 1.5 1.5h3.2M8.4 1.5V5.5h3.6M11.8 8.8v4.6M9.5 11.1h4.6",
|
|
24
|
+
folder: "M1.8 4.2a1 1 0 0 1 1-1h3.1l1.4 1.6h5.9a1 1 0 0 1 1 1v6.4a1 1 0 0 1-1 1H2.8a1 1 0 0 1-1-1z",
|
|
25
|
+
"folder-add": "M1.8 4.2a1 1 0 0 1 1-1h3.1l1.4 1.6h5.9a1 1 0 0 1 1 1v1.5M1.8 4.2v8.4a1 1 0 0 0 1 1h4.9M11.4 8.8v4.6M9.1 11.1h4.6",
|
|
26
|
+
// Up and to the left: out of where it is, to the level above.
|
|
27
|
+
outdent: "M13 4H6M13 8H8.5M13 12H6M4.5 5.5 2 8l2.5 2.5",
|
|
28
|
+
// Two columns, side by side.
|
|
29
|
+
compare: "M6.4 2.5v11M9.6 2.5v11M2 2.5h12v11H2zM2 2.5",
|
|
30
|
+
// Chevrons, the way code is written about.
|
|
31
|
+
code: "M5.8 4.6 1.8 8l4 3.4M10.2 4.6 14.2 8l-4 3.4",
|
|
32
|
+
// Three dots with three lines. The dots are round rather than
|
|
33
|
+
// square so a bullet list and a checklist are not the same
|
|
34
|
+
// silhouette at a glance.
|
|
35
|
+
"list-bullet": "M6.2 4.2h7.6M6.2 8h7.6M6.2 11.8h7.6M2.6 3.6a.6.6 0 1 1 0 1.2.6.6 0 0 1 0-1.2zM2.6 7.4a.6.6 0 1 1 0 1.2.6.6 0 0 1 0-1.2zM2.6 11.2a.6.6 0 1 1 0 1.2.6.6 0 0 1 0-1.2z",
|
|
36
|
+
"list-ordered": "M6.4 4.2h7.4M6.4 8h7.4M6.4 11.8h7.4M2 3.2h1v2.4M1.7 5.6h1.8M1.7 9.6h2l-2 2.6h2.2",
|
|
37
|
+
// A tick in a box, against the bullet list's round dots.
|
|
38
|
+
"list-task": "M6.6 4.2h7.2M6.6 11.8h7.2M1.4 2.7h3.4v3.4H1.4zM1.4 10.3h3.4v3.4H1.4zM2.1 11.9l.9.9 1.4-1.6",
|
|
39
|
+
// The bar a quote is set behind, with the lines it holds.
|
|
40
|
+
quote: "M2.6 3.4v9.2M5.8 5h8M5.8 8h8M5.8 11h5.4",
|
|
41
|
+
// A fence: the chevrons again, boxed.
|
|
42
|
+
"code-block": "M1.8 3.2h12.4v9.6H1.8zM6.2 6.4 4.4 8l1.8 1.6M9.8 6.4 11.6 8l-1.8 1.6",
|
|
43
|
+
// A grid with its header row set apart, which is what makes a
|
|
44
|
+
// table a table rather than a box with lines in it.
|
|
45
|
+
table: "M1.8 3.2h12.4v9.6H1.8zM1.8 6.4h12.4M6.4 6.4v6.4M10.2 6.4v6.4",
|
|
46
|
+
divider: "M2 8h12",
|
|
47
|
+
// A chain of two links, at an angle.
|
|
48
|
+
link: "M6.6 9.4 9.4 6.6M6.9 4.6 8.4 3.1a2.6 2.6 0 0 1 3.7 3.7l-1.5 1.5M9.1 11.4l-1.5 1.5a2.6 2.6 0 0 1-3.7-3.7l1.5-1.5",
|
|
49
|
+
// A frame with a horizon and a sun: recognisable at this size in
|
|
50
|
+
// a way a literal photograph is not.
|
|
51
|
+
image: "M1.8 3.2h12.4v9.6H1.8zM1.8 10.4l3.4-3.2 3 2.8 2.2-2 3.8 3.4M10.6 5.6a.9.9 0 1 1 0 1.8.9.9 0 0 1 0-1.8z",
|
|
52
|
+
// A tick in a circle: settled, and closed. The checklist glyph
|
|
53
|
+
// was standing in for this and said the wrong thing — a checklist
|
|
54
|
+
// is a kind of list, not a ruling on a conversation.
|
|
55
|
+
resolve: "M8 1.6a6.4 6.4 0 1 1 0 12.8A6.4 6.4 0 0 1 8 1.6zM5.2 8.2l1.9 1.9 3.7-4",
|
|
56
|
+
// The same circle, opened again: an arrow coming back round.
|
|
57
|
+
reopen: "M13.4 8a5.4 5.4 0 1 1-1.9-4.1M13.6 2.4v3.4h-3.4",
|
|
58
|
+
// A padlock, shackle closed. Shown beside a colleague who cannot
|
|
59
|
+
// open the document — a state, not an action, which is why it is
|
|
60
|
+
// the only icon here that is never on a button of its own.
|
|
61
|
+
lock: "M4.2 7.2h7.6a.8.8 0 0 1 .8.8v5a.8.8 0 0 1-.8.8H4.2a.8.8 0 0 1-.8-.8V8a.8.8 0 0 1 .8-.8zM5.6 7.2V4.9a2.4 2.4 0 0 1 4.8 0v2.3",
|
|
62
|
+
// The same padlock with the shackle swung open. Drawn from the
|
|
63
|
+
// same body so the two read as one object in two states rather
|
|
64
|
+
// than as two icons — the whole point is noticing that it changed.
|
|
65
|
+
unlock: "M4.2 7.2h7.6a.8.8 0 0 1 .8.8v5a.8.8 0 0 1-.8.8H4.2a.8.8 0 0 1-.8-.8V8a.8.8 0 0 1 .8-.8zM5.6 7.2V4.9a2.4 2.4 0 0 1 4.8 0",
|
|
66
|
+
undo: "M4.2 6.6H10a3.4 3.4 0 0 1 0 6.8H6.6M4.2 6.6l2.6-2.6M4.2 6.6l2.6 2.6",
|
|
67
|
+
redo: "M11.8 6.6H6a3.4 3.4 0 0 0 0 6.8h3.4M11.8 6.6 9.2 4M11.8 6.6 9.2 9.2",
|
|
68
|
+
// A node with two feeding into it: what this was built on.
|
|
69
|
+
// A bell, drawn at the same weight as the rest: the clapper is a
|
|
70
|
+
// separate stroke so it reads at 14px, where a single outline
|
|
71
|
+
// closes up into a blob.
|
|
72
|
+
bell: "M8 2.2a3.8 3.8 0 0 0-3.8 3.8c0 3-1.1 4-1.1 4h9.8s-1.1-1-1.1-4A3.8 3.8 0 0 0 8 2.2zM9.3 12.2a1.5 1.5 0 0 1-2.6 0",
|
|
73
|
+
// Two pages, one over the other: the source, duplicated.
|
|
74
|
+
copy: "M5.6 5.6h7a.8.8 0 0 1 .8.8v7a.8.8 0 0 1-.8.8h-7a.8.8 0 0 1-.8-.8v-7a.8.8 0 0 1 .8-.8zM3.2 10.4h-.4a.8.8 0 0 1-.8-.8v-7a.8.8 0 0 1 .8-.8h7a.8.8 0 0 1 .8.8v.4",
|
|
75
|
+
// The tick on its own, without the circle ``resolve`` draws it in.
|
|
76
|
+
check: "M3 8.4l3.2 3.2L13 4.8",
|
|
77
|
+
lineage: "M3.6 4.2h3.1a2 2 0 0 1 2 2v3.6a2 2 0 0 0 2 2h1.7M3.6 11.8h3.1M1.4 2.8a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zM1.4 10.4a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zM13.2 10.4a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8z",
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* One of igni's own icons, drawn on a 16×16 grid.
|
|
81
|
+
*
|
|
82
|
+
* Every icon is drawn in one grammar: 16×16, strokes of the same
|
|
83
|
+
* weight, `currentColor`. A name that is not in the set draws nothing, rather
|
|
84
|
+
* than a broken box: the label says what the item does, and the icon
|
|
85
|
+
* is only how it is found.
|
|
86
|
+
*
|
|
87
|
+
* @param name — one of igni's own icons.
|
|
88
|
+
* @param path — an SVG path, for an icon igni does not have; it is
|
|
89
|
+
* drawn on the same 16×16 grid, stroked rather than filled.
|
|
90
|
+
* @param className — added to the element's classes, beside the one the
|
|
91
|
+
* theme gives it.
|
|
92
|
+
*/
|
|
93
|
+
export function MenuIcon({ name, path, className }) {
|
|
94
|
+
const d = path ?? (name ? PATHS[name] : undefined);
|
|
95
|
+
// An unknown name draws nothing rather than a broken box. The
|
|
96
|
+
// label is the thing that says what the item does; the icon is how
|
|
97
|
+
// it is found again.
|
|
98
|
+
if (!d)
|
|
99
|
+
return null;
|
|
100
|
+
return (_jsx("svg", { className: className ? `menu-icon ${className}` : "menu-icon", viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: d }) }));
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=MenuIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MenuIcon.js","sourceRoot":"","sources":["../src/MenuIcon.tsx"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D;IAC/D,+DAA+D;IAC/D,mEAAmE;IACnE,MAAM,EACJ,yHAAyH;IAC3H,IAAI,EAAE,qEAAqE;IAC3E,IAAI,EAAE,qEAAqE;IAC3E,2DAA2D;IAC3D,iEAAiE;IACjE,8DAA8D;IAC9D,yBAAyB;IACzB,IAAI,EAAE,iHAAiH;IACvH,yDAAyD;IACzD,IAAI,EAAE,8JAA8J;IACpK,mEAAmE;IACnE,KAAK,EAAE,uBAAuB;IAC9B,OAAO,EACL,qNAAqN;CACxN,CAAC;AAyBF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAiB;IAC/D,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACnD,8DAA8D;IAC9D,mEAAmE;IACnE,qBAAqB;IACrB,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,OAAO,CACL,cACE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa,SAAS,EAAE,CAAC,CAAC,CAAC,WAAW,EAC7D,OAAO,EAAC,WAAW,iBACP,MAAM,EAClB,SAAS,EAAC,OAAO,YAEjB,eAAM,CAAC,EAAE,CAAC,GAAI,GACV,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type MermaidTheme = "default" | "dark";
|
|
2
|
+
interface MermaidConfig {
|
|
3
|
+
startOnLoad: boolean;
|
|
4
|
+
securityLevel: "strict";
|
|
5
|
+
theme: MermaidTheme;
|
|
6
|
+
themeVariables: {
|
|
7
|
+
fontFamily: string;
|
|
8
|
+
background: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface MermaidLib {
|
|
12
|
+
initialize: (config: MermaidConfig) => void;
|
|
13
|
+
render: (id: string, src: string) => Promise<{
|
|
14
|
+
svg: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Mermaid, configured for the theme in force right now.
|
|
19
|
+
*
|
|
20
|
+
* Mermaid is about 700KB, so it arrives only if a document has one;
|
|
21
|
+
* the bundler caches the module, so asking again costs nothing.
|
|
22
|
+
* Configured on every call rather than once, because the theme is
|
|
23
|
+
* read when it is configured — a diagram drawn after a switch to
|
|
24
|
+
* dark has to be drawn in dark.
|
|
25
|
+
*/
|
|
26
|
+
export declare function loadMermaid(): Promise<MermaidLib>;
|
|
27
|
+
/**
|
|
28
|
+
* A mermaid diagram.
|
|
29
|
+
*
|
|
30
|
+
* `source` is the text inside the fence. A diagram that does not
|
|
31
|
+
* parse is shown as its own source rather than as a blank box: it is
|
|
32
|
+
* usually a diagram somebody is halfway through writing.
|
|
33
|
+
*
|
|
34
|
+
* @param source — the text inside the fence.
|
|
35
|
+
*/
|
|
36
|
+
export declare function MermaidBlock({ source }: {
|
|
37
|
+
source: string;
|
|
38
|
+
}): import("react").JSX.Element;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=Mermaid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mermaid.d.ts","sourceRoot":"","sources":["../src/Mermaid.tsx"],"names":[],"mappings":"AAgCA,KAAK,YAAY,GAAG,SAAS,GAAG,MAAM,CAAC;AAEvC,UAAU,aAAa;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,QAAQ,CAAC;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,cAAc,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5D;AAED,UAAU,UAAU;IAClB,UAAU,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IAC5C,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/D;AA4BD;;;;;;;;GAQG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,UAAU,CAAC,CAavD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,+BAsC1D"}
|
package/dist/Mermaid.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Mermaid diagrams.
|
|
4
|
+
*
|
|
5
|
+
* ```mermaid``` becomes a diagram, in a document exactly as it
|
|
6
|
+
* already does in chat.
|
|
7
|
+
*
|
|
8
|
+
* **A fence, deliberately.** This is what lets a document carry a
|
|
9
|
+
* diagram while staying markdown: the source is a code block, so it
|
|
10
|
+
* diffs a line at a time, chunks for search, survives the editor's
|
|
11
|
+
* round trip untouched, and reads as its own source in any other
|
|
12
|
+
* markdown tool. The alternative — embedding HTML, or a bespoke
|
|
13
|
+
* node type — would cost every one of those. ``fenceInfo`` is the
|
|
14
|
+
* helper that spots one.
|
|
15
|
+
*
|
|
16
|
+
* Shared by the chat and the document view rather than copied.
|
|
17
|
+
* There was one mermaid renderer living inside ``ChatItems`` and a
|
|
18
|
+
* document could not reach it, which is the usual way two renderers
|
|
19
|
+
* of the same thing start disagreeing about what it looks like.
|
|
20
|
+
*
|
|
21
|
+
* **`mermaid` is a peer dependency**, loaded on demand. An
|
|
22
|
+
* extension that never renders a diagram never downloads it; one
|
|
23
|
+
* that does must have it installed. This is the only export under
|
|
24
|
+
* the floor that asks anything of your package.json.
|
|
25
|
+
*
|
|
26
|
+
* ``SpecBlock`` used to live here and does not any more: it reaches
|
|
27
|
+
* into the app for the ``json-render`` renderer, so it could not be
|
|
28
|
+
* published without publishing that too. It is app code now.
|
|
29
|
+
*/
|
|
30
|
+
import { useEffect, useRef, useState } from "react";
|
|
31
|
+
import { CopySource } from "./CopySource.js";
|
|
32
|
+
// Mermaid draws into a scratch element by id, and the id becomes the
|
|
33
|
+
// SVG's own and scopes the <style> it injects. One counter for the
|
|
34
|
+
// page, so no two renders anywhere on it share one — not across
|
|
35
|
+
// blocks, not across React roots, not across an edit in flight.
|
|
36
|
+
let mermaidId = 0;
|
|
37
|
+
/**
|
|
38
|
+
* A mermaid theme matching igni's.
|
|
39
|
+
*
|
|
40
|
+
* ``default`` is the colourful light palette and ``dark`` its dark
|
|
41
|
+
* counterpart. Both run in colour — ``neutral``, which reads like
|
|
42
|
+
* the safe choice, is what made every diagram grey.
|
|
43
|
+
*/
|
|
44
|
+
function mermaidTheme() {
|
|
45
|
+
if (typeof document === "undefined")
|
|
46
|
+
return "default";
|
|
47
|
+
const explicit = document.documentElement.dataset.theme;
|
|
48
|
+
if (explicit === "dark")
|
|
49
|
+
return "dark";
|
|
50
|
+
if (explicit === "light")
|
|
51
|
+
return "default";
|
|
52
|
+
if (typeof window !== "undefined" && window.matchMedia) {
|
|
53
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
54
|
+
? "dark"
|
|
55
|
+
: "default";
|
|
56
|
+
}
|
|
57
|
+
return "default";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Mermaid, configured for the theme in force right now.
|
|
61
|
+
*
|
|
62
|
+
* Mermaid is about 700KB, so it arrives only if a document has one;
|
|
63
|
+
* the bundler caches the module, so asking again costs nothing.
|
|
64
|
+
* Configured on every call rather than once, because the theme is
|
|
65
|
+
* read when it is configured — a diagram drawn after a switch to
|
|
66
|
+
* dark has to be drawn in dark.
|
|
67
|
+
*/
|
|
68
|
+
export async function loadMermaid() {
|
|
69
|
+
// Inline on purpose: `mermaid` is an optional peer dependency.
|
|
70
|
+
const lib = (await import("mermaid")).default;
|
|
71
|
+
lib.initialize({
|
|
72
|
+
startOnLoad: false,
|
|
73
|
+
securityLevel: "strict",
|
|
74
|
+
theme: mermaidTheme(),
|
|
75
|
+
themeVariables: {
|
|
76
|
+
fontFamily: "var(--font-ui)",
|
|
77
|
+
background: "transparent",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
return lib;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A mermaid diagram.
|
|
84
|
+
*
|
|
85
|
+
* `source` is the text inside the fence. A diagram that does not
|
|
86
|
+
* parse is shown as its own source rather than as a blank box: it is
|
|
87
|
+
* usually a diagram somebody is halfway through writing.
|
|
88
|
+
*
|
|
89
|
+
* @param source — the text inside the fence.
|
|
90
|
+
*/
|
|
91
|
+
export function MermaidBlock({ source }) {
|
|
92
|
+
const frame = useRef(null);
|
|
93
|
+
const [error, setError] = useState(null);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
let cancelled = false;
|
|
96
|
+
setError(null);
|
|
97
|
+
void loadMermaid()
|
|
98
|
+
.then((lib) => lib.render(`mermaid-${++mermaidId}`, source))
|
|
99
|
+
.then(({ svg }) => {
|
|
100
|
+
if (cancelled || !frame.current)
|
|
101
|
+
return;
|
|
102
|
+
frame.current.innerHTML = svg;
|
|
103
|
+
})
|
|
104
|
+
.catch((e) => {
|
|
105
|
+
if (cancelled)
|
|
106
|
+
return;
|
|
107
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
108
|
+
});
|
|
109
|
+
return () => {
|
|
110
|
+
cancelled = true;
|
|
111
|
+
};
|
|
112
|
+
}, [source]);
|
|
113
|
+
if (error) {
|
|
114
|
+
// The source, not a blank box. A diagram that does not parse is
|
|
115
|
+
// usually a diagram somebody is halfway through writing, and
|
|
116
|
+
// hiding what they wrote is the least helpful response to that.
|
|
117
|
+
return (_jsx("pre", { className: "mermaid-error", title: `Mermaid render failed: ${error}`, children: source }));
|
|
118
|
+
}
|
|
119
|
+
return (_jsxs("div", { className: "mermaid-diagram", children: [_jsx(CopySource, { source: source }), _jsx("div", { ref: frame })] }));
|
|
120
|
+
}
|
|
121
|
+
//# sourceMapp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AC;IACD,OAAO,CACL,eAAK,SAAS,EAAC,iBAAiB,aAC9B,KAAC,UAAU,IAAC,MAAM,EAAE,MAAM,GAAI,EAC9B,cAAK,GAAG,EAAE,KAAK,GAAI,IACf,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two letters standing in for a face.
|
|
3
|
+
*
|
|
4
|
+
* Not an avatar. Nothing in the product stores an uploaded picture —
|
|
5
|
+
* there is no `avatar_url` on a user anywhere in the server — and a
|
|
6
|
+
* generic silhouette for everybody says strictly less than two
|
|
7
|
+
* letters of somebody's own name. The portal draws the same thing
|
|
8
|
+
* from the same source, so the two surfaces agree about what a person
|
|
9
|
+
* looks like.
|
|
10
|
+
*
|
|
11
|
+
* The colour is derived from the name rather than chosen, so the same
|
|
12
|
+
* person is the same colour on every machine and across restarts.
|
|
13
|
+
* That is the whole point: the monogram is a recognition aid, and one
|
|
14
|
+
* that changed colour per session would be decoration.
|
|
15
|
+
*/
|
|
16
|
+
export declare function initialsOf(name: string): string;
|
|
17
|
+
/** A stable hue for a name. Same person, same colour, every time. */
|
|
18
|
+
export declare function hueOf(name: string): number;
|
|
19
|
+
/**
|
|
20
|
+
* The same colour, written as ``#rrggbb``.
|
|
21
|
+
*
|
|
22
|
+
* For the places that cannot take ``hsl()``. The collaborative
|
|
23
|
+
* caret is one: it validates against ``/^#[0-9a-fA-F]{6}$/`` and
|
|
24
|
+
* quietly renders anything else transparent — a cursor that is
|
|
25
|
+
* there, labelled with the right name, and invisible.
|
|
26
|
+
*
|
|
27
|
+
* Derived from the same hue as the monogram, so somebody's caret and
|
|
28
|
+
* their initials are the same colour.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hexOf(name: string, saturation?: number, lightness?: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* Two letters standing in for a face.
|
|
33
|
+
*
|
|
34
|
+
* Not an avatar: nothing stores an uploaded picture, so the two
|
|
35
|
+
* letters come from the name. The colour comes from the name too, so
|
|
36
|
+
* the same person is the same colour on every machine and across
|
|
37
|
+
* restarts.
|
|
38
|
+
*
|
|
39
|
+
* @param name — the name the initials and the colour are derived from.
|
|
40
|
+
* @param size — the width and height of the square, in pixels.
|
|
41
|
+
*/
|
|
42
|
+
export declare function Monogram({ name, size }: {
|
|
43
|
+
name: string;
|
|
44
|
+
size?: number;
|
|
45
|
+
}): import("react").JSX.Element;
|
|
46
|
+
//# sourceMappingURL=Monogram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Monogram.d.ts","sourceRoot":"","sources":["../src/Monogram.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB/C;AAED,qEAAqE;AACrE,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EACZ,UAAU,SAAO,EACjB,SAAS,SAAO,GACf,MAAM,CAqBR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAS,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,+BAmB5E"}
|