@diegopluna/narvi 0.5.8 → 0.5.10
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/components/dialog/ConfirmDialog.svelte +1 -2
- package/dist/components/dialog/DialogDescription.svelte +2 -2
- package/dist/components/dialog/DialogTitle.svelte +2 -2
- package/dist/components/input/Input.svelte +156 -15
- package/dist/components/input/Input.svelte.d.ts +17 -3
- package/dist/components/markdown/Markdown.svelte +68 -7
- package/dist/components/markdown/Markdown.svelte.d.ts +9 -0
- package/dist/components/markdown/MarkdownBlocks.svelte +4 -3
- package/dist/components/markdown/MarkdownCode.svelte +108 -9
- package/dist/components/markdown/MarkdownCode.svelte.d.ts +5 -1
- package/dist/components/markdown/MarkdownHtmlPreview.svelte +186 -0
- package/dist/components/markdown/MarkdownHtmlPreview.svelte.d.ts +11 -0
- package/dist/components/markdown/MarkdownPreview.svelte +17 -0
- package/dist/components/markdown/MarkdownPreview.svelte.d.ts +6 -0
- package/dist/components/markdown/MarkdownTable.svelte +61 -4
- package/dist/components/markdown/context.d.ts +21 -0
- package/dist/components/markdown/labels.d.ts +12 -0
- package/dist/components/markdown/labels.js +5 -0
- package/dist/components/markdown/preview.d.ts +9 -0
- package/dist/components/markdown/preview.js +14 -0
- package/dist/components/markdown/static.d.ts +2 -0
- package/dist/components/markdown/static.js +5 -1
- package/dist/components/markdown/table-image.d.ts +15 -0
- package/dist/components/markdown/table-image.js +342 -0
- package/dist/components/message/MessageAction.svelte +17 -2
- package/dist/components/message/MessageAction.svelte.d.ts +7 -0
- package/dist/internal/Glyph.svelte +11 -0
- package/dist/internal/Glyph.svelte.d.ts +2 -0
- package/dist/internal/closing.svelte.d.ts +0 -6
- package/dist/internal/closing.svelte.js +0 -33
- package/dist/internal/markers.stylex.d.ts +4 -0
- package/dist/internal/markers.stylex.js +2 -0
- package/dist/markdown/highlight.d.ts +2 -2
- package/dist/markdown/highlight.js +2 -2
- package/dist/markdown/html.d.ts +3 -1
- package/dist/markdown/html.js +6 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +2 -2
- package/dist/markdown/table.d.ts +20 -1
- package/dist/markdown/table.js +111 -0
- package/package.json +19 -19
- package/skills/building-ui/SKILL.md +5 -5
- package/skills/building-ui/references/components.md +26 -26
- package/skills/markdown/SKILL.md +26 -7
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -198,11 +198,15 @@ function block(node, tight, depth, ctx) {
|
|
|
198
198
|
// A diagram, or any language a plugin draws, is a part of its own
|
|
199
199
|
if (ctx.language(node.lang))
|
|
200
200
|
throw NOT_PLAIN;
|
|
201
|
+
// One that has been shown rendered is drawn by its component, which holds the toggle
|
|
202
|
+
if (ctx.woken(node.id))
|
|
203
|
+
throw NOT_PLAIN;
|
|
201
204
|
return codeHtml(node, {
|
|
202
205
|
labels: ctx.labels,
|
|
203
206
|
highlight: ctx.highlight,
|
|
204
207
|
lineNumbers: ctx.code.lineNumbers,
|
|
205
|
-
download: ctx.code.download
|
|
208
|
+
download: ctx.code.download,
|
|
209
|
+
preview: ctx.preview(node.lang)
|
|
206
210
|
});
|
|
207
211
|
case 'table':
|
|
208
212
|
// One whose menu has been asked for is drawn by its component, which holds the menu
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A table drawn as a PNG, as it is on the screen: for "Copy as PNG". Loaded the first time a
|
|
3
|
+
* table is copied that way.
|
|
4
|
+
*
|
|
5
|
+
* It is drawn from the layout the browser has already worked out, not from a copy of the
|
|
6
|
+
* table in an SVG `<foreignObject>`: each cell's place and fill, and each word's place, font
|
|
7
|
+
* and colour, are read from the page (client rects and computed styles) and painted onto a
|
|
8
|
+
* canvas. Nothing is cloned and nothing is fetched, so the picture is what the reader sees,
|
|
9
|
+
* in the theme they see it in, including the columns scrolled out of view.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A table as a PNG, as it is drawn on the page now. A picture from another site, which would
|
|
13
|
+
* keep the canvas from being read, is left out: the table is drawn again without pictures.
|
|
14
|
+
*/
|
|
15
|
+
export declare function tableImage(table: HTMLTableElement): Promise<Blob>;
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A table drawn as a PNG, as it is on the screen: for "Copy as PNG". Loaded the first time a
|
|
3
|
+
* table is copied that way.
|
|
4
|
+
*
|
|
5
|
+
* It is drawn from the layout the browser has already worked out, not from a copy of the
|
|
6
|
+
* table in an SVG `<foreignObject>`: each cell's place and fill, and each word's place, font
|
|
7
|
+
* and colour, are read from the page (client rects and computed styles) and painted onto a
|
|
8
|
+
* canvas. Nothing is cloned and nothing is fetched, so the picture is what the reader sees,
|
|
9
|
+
* in the theme they see it in, including the columns scrolled out of view.
|
|
10
|
+
*/
|
|
11
|
+
/** As sharp as the screen, and no more than three times the table's size. */
|
|
12
|
+
const MAX_SCALE = 3;
|
|
13
|
+
/** Room around the table, in the colour behind it. */
|
|
14
|
+
const MARGIN = 16;
|
|
15
|
+
/** Whether a computed colour paints nothing. */
|
|
16
|
+
function clear(color) {
|
|
17
|
+
return (color === '' ||
|
|
18
|
+
color === 'transparent' ||
|
|
19
|
+
/^rgba\(.*,\s*0\)$/.test(color) ||
|
|
20
|
+
/\/\s*0%?\s*\)$/.test(color));
|
|
21
|
+
}
|
|
22
|
+
/** The colour of an inset box shadow, as Narvi draws a frame's edge, or null. */
|
|
23
|
+
function edgeColor(shadow) {
|
|
24
|
+
if (!shadow || shadow === 'none' || !shadow.includes('inset'))
|
|
25
|
+
return null;
|
|
26
|
+
const color = /^(?:[a-z-]+\([^)]*(?:\([^)]*\)[^)]*)*\)|#[0-9a-f]+|[a-z]+)/i.exec(shadow.trim());
|
|
27
|
+
return color && !clear(color[0]) ? color[0] : null;
|
|
28
|
+
}
|
|
29
|
+
function roundRect(ctx, rect, radius) {
|
|
30
|
+
ctx.beginPath();
|
|
31
|
+
if (radius > 0 && typeof ctx.roundRect === 'function')
|
|
32
|
+
ctx.roundRect(rect.left, rect.top, rect.width, rect.height, radius);
|
|
33
|
+
else
|
|
34
|
+
ctx.rect(rect.left, rect.top, rect.width, rect.height);
|
|
35
|
+
}
|
|
36
|
+
function fontOf(style) {
|
|
37
|
+
return `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
|
|
38
|
+
}
|
|
39
|
+
/** An inline SVG as a picture: its own markup, with `currentColor` made the colour it is drawn in. */
|
|
40
|
+
function svgImage(svg) {
|
|
41
|
+
const copy = svg.cloneNode(true);
|
|
42
|
+
const rect = svg.getBoundingClientRect();
|
|
43
|
+
copy.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
44
|
+
copy.setAttribute('width', String(rect.width));
|
|
45
|
+
copy.setAttribute('height', String(rect.height));
|
|
46
|
+
copy.style.color = getComputedStyle(svg).color;
|
|
47
|
+
const image = new Image();
|
|
48
|
+
const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(copy.outerHTML)}`;
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
image.onload = () => resolve(image);
|
|
51
|
+
image.onerror = () => resolve(null);
|
|
52
|
+
image.src = url;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
class Painter {
|
|
56
|
+
ctx;
|
|
57
|
+
images;
|
|
58
|
+
/** Pictures to draw once they have loaded: an inline SVG is read as an image first. */
|
|
59
|
+
pictures = [];
|
|
60
|
+
segmenter = typeof Intl !== 'undefined' && 'Segmenter' in Intl
|
|
61
|
+
? new Intl.Segmenter(undefined, { granularity: 'grapheme' })
|
|
62
|
+
: null;
|
|
63
|
+
constructor(ctx, images) {
|
|
64
|
+
this.ctx = ctx;
|
|
65
|
+
this.images = images;
|
|
66
|
+
}
|
|
67
|
+
async done() {
|
|
68
|
+
await Promise.all(this.pictures);
|
|
69
|
+
}
|
|
70
|
+
/** An element's fill, under each box it is drawn in: a line of inline code that wraps has two. */
|
|
71
|
+
fill(element, style) {
|
|
72
|
+
if (clear(style.backgroundColor))
|
|
73
|
+
return;
|
|
74
|
+
const radius = parseFloat(style.borderTopLeftRadius) || 0;
|
|
75
|
+
this.ctx.fillStyle = style.backgroundColor;
|
|
76
|
+
for (const rect of element.getClientRects()) {
|
|
77
|
+
roundRect(this.ctx, rect, Math.min(radius, rect.height / 2));
|
|
78
|
+
this.ctx.fill();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** A cell's own lines, as `border-*` draws them. */
|
|
82
|
+
borders(rect, style) {
|
|
83
|
+
const side = (width, kind, color, draw) => {
|
|
84
|
+
const w = parseFloat(width) || 0;
|
|
85
|
+
if (w <= 0 || kind === 'none' || kind === 'hidden' || clear(color))
|
|
86
|
+
return;
|
|
87
|
+
const r = draw(w);
|
|
88
|
+
this.ctx.fillStyle = color;
|
|
89
|
+
this.ctx.fillRect(r.left, r.top, r.width, r.height);
|
|
90
|
+
};
|
|
91
|
+
const { left, top, width, height } = rect;
|
|
92
|
+
side(style.borderTopWidth, style.borderTopStyle, style.borderTopColor, (w) => ({
|
|
93
|
+
left,
|
|
94
|
+
top: top - w / 2,
|
|
95
|
+
width,
|
|
96
|
+
height: w
|
|
97
|
+
}));
|
|
98
|
+
side(style.borderBottomWidth, style.borderBottomStyle, style.borderBottomColor, (w) => ({
|
|
99
|
+
left,
|
|
100
|
+
top: top + height - w / 2,
|
|
101
|
+
width,
|
|
102
|
+
height: w
|
|
103
|
+
}));
|
|
104
|
+
side(style.borderLeftWidth, style.borderLeftStyle, style.borderLeftColor, (w) => ({
|
|
105
|
+
left: left - w / 2,
|
|
106
|
+
top,
|
|
107
|
+
width: w,
|
|
108
|
+
height
|
|
109
|
+
}));
|
|
110
|
+
side(style.borderRightWidth, style.borderRightStyle, style.borderRightColor, (w) => ({
|
|
111
|
+
left: left + width - w / 2,
|
|
112
|
+
top,
|
|
113
|
+
width: w,
|
|
114
|
+
height
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
/** What is in an element: its fills, its pictures and its words, in the order they are drawn. */
|
|
118
|
+
contents(element, lines) {
|
|
119
|
+
for (const child of element.childNodes) {
|
|
120
|
+
if (child.nodeType === Node.TEXT_NODE) {
|
|
121
|
+
this.text(child, lines);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (!(child instanceof Element))
|
|
125
|
+
continue;
|
|
126
|
+
const style = getComputedStyle(child);
|
|
127
|
+
if (style.display === 'none' || style.visibility === 'hidden')
|
|
128
|
+
continue;
|
|
129
|
+
const decoration = style.textDecorationLine;
|
|
130
|
+
const color = clear(style.textDecorationColor) ? style.color : style.textDecorationColor;
|
|
131
|
+
const inner = {
|
|
132
|
+
under: decoration.includes('underline') ? color : lines.under,
|
|
133
|
+
through: decoration.includes('line-through') ? color : lines.through
|
|
134
|
+
};
|
|
135
|
+
this.fill(child, style);
|
|
136
|
+
if (child instanceof SVGSVGElement) {
|
|
137
|
+
if (this.images)
|
|
138
|
+
this.svg(child);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (child instanceof HTMLImageElement) {
|
|
142
|
+
if (this.images && child.complete && child.naturalWidth > 0) {
|
|
143
|
+
const r = child.getBoundingClientRect();
|
|
144
|
+
this.ctx.drawImage(child, r.left, r.top, r.width, r.height);
|
|
145
|
+
}
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
this.contents(child, inner);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
svg(svg) {
|
|
152
|
+
const rect = svg.getBoundingClientRect();
|
|
153
|
+
if (rect.width === 0 || rect.height === 0)
|
|
154
|
+
return;
|
|
155
|
+
// Drawn in the place it has now, once it has loaded; nothing is drawn over it later
|
|
156
|
+
const { ctx } = this;
|
|
157
|
+
const transform = ctx.getTransform();
|
|
158
|
+
this.pictures.push(svgImage(svg).then((image) => {
|
|
159
|
+
if (!image)
|
|
160
|
+
return;
|
|
161
|
+
ctx.save();
|
|
162
|
+
ctx.setTransform(transform);
|
|
163
|
+
ctx.drawImage(image, rect.left, rect.top, rect.width, rect.height);
|
|
164
|
+
ctx.restore();
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
/** The pieces of text that are drawn on their own: each word, or each character of a word that wraps. */
|
|
168
|
+
pieces(text) {
|
|
169
|
+
const out = [];
|
|
170
|
+
for (const match of text.matchAll(/\S+/g)) {
|
|
171
|
+
out.push({ start: match.index, end: match.index + match[0].length });
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
characters(text, start, end) {
|
|
176
|
+
const word = text.slice(start, end);
|
|
177
|
+
const out = [];
|
|
178
|
+
let at = start;
|
|
179
|
+
const parts = this.segmenter
|
|
180
|
+
? Array.from(this.segmenter.segment(word), (part) => part.segment)
|
|
181
|
+
: Array.from(word);
|
|
182
|
+
for (const part of parts) {
|
|
183
|
+
out.push({ start: at, end: at + part.length });
|
|
184
|
+
at += part.length;
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
text(node, lines) {
|
|
189
|
+
const value = node.data;
|
|
190
|
+
if (!/\S/.test(value) || !node.parentElement)
|
|
191
|
+
return;
|
|
192
|
+
const style = getComputedStyle(node.parentElement);
|
|
193
|
+
if (style.visibility === 'hidden')
|
|
194
|
+
return;
|
|
195
|
+
const { ctx } = this;
|
|
196
|
+
ctx.font = fontOf(style);
|
|
197
|
+
ctx.fillStyle = style.color;
|
|
198
|
+
ctx.textBaseline = 'alphabetic';
|
|
199
|
+
ctx.textAlign = 'left';
|
|
200
|
+
if ('letterSpacing' in ctx)
|
|
201
|
+
ctx.letterSpacing = style.letterSpacing === 'normal' ? '0px' : style.letterSpacing;
|
|
202
|
+
const size = parseFloat(style.fontSize) || 16;
|
|
203
|
+
const range = document.createRange();
|
|
204
|
+
const draw = (start, end) => {
|
|
205
|
+
range.setStart(node, start);
|
|
206
|
+
range.setEnd(node, end);
|
|
207
|
+
const rects = [...range.getClientRects()].filter((r) => r.width > 0);
|
|
208
|
+
if (rects.length !== 1)
|
|
209
|
+
return false;
|
|
210
|
+
const rect = rects[0];
|
|
211
|
+
const piece = value.slice(start, end);
|
|
212
|
+
const metrics = ctx.measureText(piece);
|
|
213
|
+
const ascent = metrics.fontBoundingBoxAscent ?? size * 0.8;
|
|
214
|
+
const descent = metrics.fontBoundingBoxDescent ?? size * 0.2;
|
|
215
|
+
// The text's box is its font's ascent and descent; the baseline is the ascent down from
|
|
216
|
+
// the top of what is left once they are centred in it
|
|
217
|
+
const baseline = rect.top + (rect.height - ascent - descent) / 2 + ascent;
|
|
218
|
+
ctx.fillText(piece, rect.left, baseline);
|
|
219
|
+
const thickness = Math.max(1, size / 16);
|
|
220
|
+
if (lines.under) {
|
|
221
|
+
ctx.fillStyle = lines.under;
|
|
222
|
+
ctx.fillRect(rect.left, baseline + Math.max(1, descent * 0.35), rect.width, thickness);
|
|
223
|
+
ctx.fillStyle = style.color;
|
|
224
|
+
}
|
|
225
|
+
if (lines.through) {
|
|
226
|
+
ctx.fillStyle = lines.through;
|
|
227
|
+
ctx.fillRect(rect.left, baseline - size * 0.3, rect.width, thickness);
|
|
228
|
+
ctx.fillStyle = style.color;
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
};
|
|
232
|
+
for (const { start, end } of this.pieces(value)) {
|
|
233
|
+
// A word that the line broke inside, such as a run of CJK with no spaces, is drawn a
|
|
234
|
+
// character at a time
|
|
235
|
+
if (!draw(start, end))
|
|
236
|
+
for (const character of this.characters(value, start, end))
|
|
237
|
+
draw(character.start, character.end);
|
|
238
|
+
}
|
|
239
|
+
range.detach();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** The colours behind an element, from the page down: drawn in that order, they are what shows. */
|
|
243
|
+
function backgrounds(element) {
|
|
244
|
+
const out = [];
|
|
245
|
+
for (let at = element; at; at = at.parentElement) {
|
|
246
|
+
const color = getComputedStyle(at).backgroundColor;
|
|
247
|
+
if (!clear(color))
|
|
248
|
+
out.unshift(color);
|
|
249
|
+
// An opaque colour hides everything under it
|
|
250
|
+
if (/^rgb\(/.test(color))
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
function draw(table, images) {
|
|
256
|
+
const frame = table.parentElement ?? table;
|
|
257
|
+
const box = table.getBoundingClientRect();
|
|
258
|
+
const scale = Math.min(MAX_SCALE, Math.max(1, window.devicePixelRatio || 1));
|
|
259
|
+
const canvas = document.createElement('canvas');
|
|
260
|
+
canvas.width = Math.ceil((box.width + MARGIN * 2) * scale);
|
|
261
|
+
canvas.height = Math.ceil((box.height + MARGIN * 2) * scale);
|
|
262
|
+
const ctx = canvas.getContext('2d');
|
|
263
|
+
if (!ctx)
|
|
264
|
+
throw new Error('No canvas to draw on');
|
|
265
|
+
ctx.scale(scale, scale);
|
|
266
|
+
// What is behind the table, so a dark table is not pasted onto white
|
|
267
|
+
const behind = backgrounds(frame);
|
|
268
|
+
// A page that paints nothing shows the browser's own white
|
|
269
|
+
if (behind.length === 0)
|
|
270
|
+
behind.push('#fff');
|
|
271
|
+
for (const color of behind) {
|
|
272
|
+
ctx.fillStyle = color;
|
|
273
|
+
ctx.fillRect(0, 0, box.width + MARGIN * 2, box.height + MARGIN * 2);
|
|
274
|
+
}
|
|
275
|
+
// From here on, a place on the page is the same place on the canvas
|
|
276
|
+
ctx.translate(MARGIN - box.left, MARGIN - box.top);
|
|
277
|
+
const frameStyle = getComputedStyle(frame);
|
|
278
|
+
const radius = parseFloat(frameStyle.borderTopLeftRadius) || 0;
|
|
279
|
+
const shape = { left: box.left, top: box.top, width: box.width, height: box.height };
|
|
280
|
+
ctx.save();
|
|
281
|
+
roundRect(ctx, shape, radius);
|
|
282
|
+
ctx.clip();
|
|
283
|
+
const painter = new Painter(ctx, images);
|
|
284
|
+
painter.fill(table, getComputedStyle(table));
|
|
285
|
+
for (const row of table.rows) {
|
|
286
|
+
painter.fill(row, getComputedStyle(row));
|
|
287
|
+
for (const cell of row.cells) {
|
|
288
|
+
const style = getComputedStyle(cell);
|
|
289
|
+
const rect = cell.getBoundingClientRect();
|
|
290
|
+
if (!clear(style.backgroundColor)) {
|
|
291
|
+
ctx.fillStyle = style.backgroundColor;
|
|
292
|
+
ctx.fillRect(rect.left, rect.top, rect.width, rect.height);
|
|
293
|
+
}
|
|
294
|
+
painter.borders(rect, style);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
for (const row of table.rows)
|
|
298
|
+
for (const cell of row.cells)
|
|
299
|
+
painter.contents(cell, { under: null, through: null });
|
|
300
|
+
return painter.done().then(() => {
|
|
301
|
+
ctx.restore();
|
|
302
|
+
// The frame's edge, which Narvi draws as an inset shadow, over the cells it rounds off
|
|
303
|
+
const edge = edgeColor(frameStyle.boxShadow);
|
|
304
|
+
if (edge) {
|
|
305
|
+
ctx.strokeStyle = edge;
|
|
306
|
+
ctx.lineWidth = 1;
|
|
307
|
+
roundRect(ctx, {
|
|
308
|
+
left: box.left + 0.5,
|
|
309
|
+
top: box.top + 0.5,
|
|
310
|
+
width: box.width - 1,
|
|
311
|
+
height: box.height - 1
|
|
312
|
+
}, Math.max(0, radius - 0.5));
|
|
313
|
+
ctx.stroke();
|
|
314
|
+
}
|
|
315
|
+
return canvas;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
function toBlob(canvas) {
|
|
319
|
+
return new Promise((resolve, reject) => {
|
|
320
|
+
try {
|
|
321
|
+
canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error('The table could not be drawn'))), 'image/png');
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
reject(error);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* A table as a PNG, as it is drawn on the page now. A picture from another site, which would
|
|
330
|
+
* keep the canvas from being read, is left out: the table is drawn again without pictures.
|
|
331
|
+
*/
|
|
332
|
+
export async function tableImage(table) {
|
|
333
|
+
await document.fonts?.ready;
|
|
334
|
+
try {
|
|
335
|
+
return await toBlob(await draw(table, true));
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
if (!(error instanceof DOMException && error.name === 'SecurityError'))
|
|
339
|
+
throw error;
|
|
340
|
+
return toBlob(await draw(table, false));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { Sx } from '../../internal/sx.js';
|
|
5
5
|
import { colors } from '../../tokens.stylex.js';
|
|
6
6
|
import { media } from '../../media.stylex.js';
|
|
7
|
-
import Button, { buttonHtml, type ButtonProps } from '../button/Button.svelte';
|
|
7
|
+
import Button, { buttonClass, buttonHtml, type ButtonProps } from '../button/Button.svelte';
|
|
8
8
|
|
|
9
9
|
export type MessageActionProps = Omit<
|
|
10
10
|
ButtonProps,
|
|
@@ -34,11 +34,26 @@
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
+
/** An action's class, as the component draws it: for a button made by hand. */
|
|
38
|
+
export function actionClass(options: {
|
|
39
|
+
pressed?: boolean | undefined;
|
|
40
|
+
sx?: Sx | undefined;
|
|
41
|
+
}): string {
|
|
42
|
+
return buttonClass({
|
|
43
|
+
variant: 'ghost',
|
|
44
|
+
size: 'sm',
|
|
45
|
+
iconOnly: true,
|
|
46
|
+
sx: [styles.action, options.pressed && styles.pressed, options.sx]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
37
50
|
/** An action as markup, as the component draws it. `label` and `attributes` are escaped already. */
|
|
38
51
|
export function actionHtml(options: {
|
|
39
52
|
label: string;
|
|
40
53
|
attributes?: string | undefined;
|
|
41
54
|
sx?: Sx | undefined;
|
|
55
|
+
/** Marks a toggle as on; give `aria-pressed` in `attributes` as well. */
|
|
56
|
+
pressed?: boolean | undefined;
|
|
42
57
|
inner: string;
|
|
43
58
|
/** As `buttonHtml` takes it: the button and its icon, with nothing between. */
|
|
44
59
|
bare?: boolean | undefined;
|
|
@@ -48,7 +63,7 @@
|
|
|
48
63
|
variant: 'ghost',
|
|
49
64
|
size: 'sm',
|
|
50
65
|
iconOnly: true,
|
|
51
|
-
sx: [styles.action, options.sx],
|
|
66
|
+
sx: [styles.action, options.pressed && styles.pressed, options.sx],
|
|
52
67
|
attributes: ` aria-label="${options.label}" data-slot="message-action"${options.attributes ?? ''}`,
|
|
53
68
|
inner: options.inner
|
|
54
69
|
});
|
|
@@ -11,11 +11,18 @@ export type MessageActionProps = Omit<ButtonProps, 'children' | 'variant' | 'siz
|
|
|
11
11
|
/** A 16px icon. */
|
|
12
12
|
children?: Snippet | undefined;
|
|
13
13
|
};
|
|
14
|
+
/** An action's class, as the component draws it: for a button made by hand. */
|
|
15
|
+
export declare function actionClass(options: {
|
|
16
|
+
pressed?: boolean | undefined;
|
|
17
|
+
sx?: Sx | undefined;
|
|
18
|
+
}): string;
|
|
14
19
|
/** An action as markup, as the component draws it. `label` and `attributes` are escaped already. */
|
|
15
20
|
export declare function actionHtml(options: {
|
|
16
21
|
label: string;
|
|
17
22
|
attributes?: string | undefined;
|
|
18
23
|
sx?: Sx | undefined;
|
|
24
|
+
/** Marks a toggle as on; give `aria-pressed` in `attributes` as well. */
|
|
25
|
+
pressed?: boolean | undefined;
|
|
19
26
|
inner: string;
|
|
20
27
|
/** As `buttonHtml` takes it: the button and its icon, with nothing between. */
|
|
21
28
|
bare?: boolean | undefined;
|
|
@@ -26,6 +26,17 @@
|
|
|
26
26
|
'M1.75 8S4 3.75 8 3.75 14.25 8 14.25 8 12 12.25 8 12.25 1.75 8 1.75 8Z',
|
|
27
27
|
'M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z'
|
|
28
28
|
],
|
|
29
|
+
// Showing and hiding a password: Lucide's eye and eye-off, on this grid
|
|
30
|
+
reveal: [
|
|
31
|
+
'M1.37 8.23a.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 13.26 0 .67.67 0 0 1 0 .46 7.17 7.17 0 0 1-13.26 0',
|
|
32
|
+
'M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z'
|
|
33
|
+
],
|
|
34
|
+
conceal: [
|
|
35
|
+
'M7.16 3.38a7.16 7.16 0 0 1 7.47 4.39.67.67 0 0 1 0 .46 7.16 7.16 0 0 1-.96 1.66',
|
|
36
|
+
'M9.39 9.44a2 2 0 0 1-2.83-2.83',
|
|
37
|
+
'M11.65 11.67a7.17 7.17 0 0 1-10.28-3.44.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 2.96-3.43',
|
|
38
|
+
'M1.33 1.33l13.34 13.34'
|
|
39
|
+
],
|
|
29
40
|
globe: [
|
|
30
41
|
'M14 8A6 6 0 1 1 2 8a6 6 0 0 1 12 0Z',
|
|
31
42
|
'M2 8h12',
|
|
@@ -13,6 +13,8 @@ declare const paths: {
|
|
|
13
13
|
readonly terminal: readonly ["M3.5 4.5l3 3.25-3 3.25", "M8 11.5h4.5"];
|
|
14
14
|
readonly pencil: readonly ["M10.5 3.5 12.5 5.5", "M3 13l.5-2.5 7.75-7.75a1.4 1.4 0 0 1 2 2L5.5 12.5Z"];
|
|
15
15
|
readonly eye: readonly ["M1.75 8S4 3.75 8 3.75 14.25 8 14.25 8 12 12.25 8 12.25 1.75 8 1.75 8Z", "M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z"];
|
|
16
|
+
readonly reveal: readonly ["M1.37 8.23a.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 13.26 0 .67.67 0 0 1 0 .46 7.17 7.17 0 0 1-13.26 0", "M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z"];
|
|
17
|
+
readonly conceal: readonly ["M7.16 3.38a7.16 7.16 0 0 1 7.47 4.39.67.67 0 0 1 0 .46 7.16 7.16 0 0 1-.96 1.66", "M9.39 9.44a2 2 0 0 1-2.83-2.83", "M11.65 11.67a7.17 7.17 0 0 1-10.28-3.44.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 2.96-3.43", "M1.33 1.33l13.34 13.34"];
|
|
16
18
|
readonly globe: readonly ["M14 8A6 6 0 1 1 2 8a6 6 0 0 1 12 0Z", "M2 8h12", "M8 2c1.7 1.7 2.5 3.7 2.5 6S9.7 12.3 8 14C6.3 12.3 5.5 10.3 5.5 8S6.3 3.7 8 2Z"];
|
|
17
19
|
readonly sparkle: readonly ["M8 2.5 9.4 6.6 13.5 8 9.4 9.4 8 13.5 6.6 9.4 2.5 8 6.6 6.6Z"];
|
|
18
20
|
readonly squarePen: readonly ["M8 2.75H4.25C3.56 2.75 3 3.31 3 4v7.75c0 .69.56 1.25 1.25 1.25H12c.69 0 1.25-.56 1.25-1.25V8", "M12.25 1.75a.67.67 0 0 1 2 2L8.24 9.76a1.33 1.33 0 0 1-.57.34l-1.92.56a.33.33 0 0 1-.41-.41l.56-1.92a1.33 1.33 0 0 1 .34-.57Z"];
|
|
@@ -8,9 +8,3 @@ export declare function provideDialogOpen(open: () => boolean): void;
|
|
|
8
8
|
export declare function keepWhileClosing(element: () => Element | undefined): () => Node[] | undefined;
|
|
9
9
|
/** Puts the kept nodes in an element. */
|
|
10
10
|
export declare const place: (nodes: Node[]) => (element: Element) => void;
|
|
11
|
-
/**
|
|
12
|
-
* A ui-sdk part's props, with its binding let go of after Svelte's teardown when its element has
|
|
13
|
-
* left the page. Spread them on the part's element. An element that stays, binding again, lets
|
|
14
|
-
* go at once, before it binds.
|
|
15
|
-
*/
|
|
16
|
-
export declare function unbindLater<T extends object>(props: T): T;
|
|
@@ -8,13 +8,6 @@
|
|
|
8
8
|
* - The text is kept. Once the dialog's `open` turns false, its title and description show what
|
|
9
9
|
* they showed until the dialog has gone, so it does not read "Revoke ?" as it fades. Opened
|
|
10
10
|
* again, they follow their content again.
|
|
11
|
-
* - A part that leaves the page lets ui-sdk go of it after Svelte's teardown. ui-sdk clears
|
|
12
|
-
* a title's or a description's flag as the part unbinds, at once, and that re-applies the
|
|
13
|
-
* dialog's props. Inside a teardown Svelte reads state as it was before the update, so the
|
|
14
|
-
* props still said open, and the dialog was written open again: blank, its backdrop taking
|
|
15
|
-
* every click on the page. Unbound a microtask later, ui-sdk reads the props as they are.
|
|
16
|
-
* ui-sdk 0.1.0-beta.8 fixed it at its root (a part's unbind reads the options last delivered),
|
|
17
|
-
* so this can go once Narvi moves past beta.7.
|
|
18
11
|
*/
|
|
19
12
|
import { getContext, setContext, untrack } from 'svelte';
|
|
20
13
|
const OPEN = Symbol('narvi.dialog-open');
|
|
@@ -48,29 +41,3 @@ export function keepWhileClosing(element) {
|
|
|
48
41
|
}
|
|
49
42
|
/** Puts the kept nodes in an element. */
|
|
50
43
|
export const place = (nodes) => (element) => element.replaceChildren(...nodes);
|
|
51
|
-
const later = new WeakMap();
|
|
52
|
-
/**
|
|
53
|
-
* A ui-sdk part's props, with its binding let go of after Svelte's teardown when its element has
|
|
54
|
-
* left the page. Spread them on the part's element. An element that stays, binding again, lets
|
|
55
|
-
* go at once, before it binds.
|
|
56
|
-
*/
|
|
57
|
-
export function unbindLater(props) {
|
|
58
|
-
const result = { ...props };
|
|
59
|
-
for (const key of Object.getOwnPropertySymbols(props)) {
|
|
60
|
-
const attach = props[key];
|
|
61
|
-
if (typeof attach !== 'function')
|
|
62
|
-
continue;
|
|
63
|
-
let deferred = later.get(attach);
|
|
64
|
-
if (!deferred) {
|
|
65
|
-
deferred = (element) => {
|
|
66
|
-
const release = attach(element);
|
|
67
|
-
if (typeof release !== 'function')
|
|
68
|
-
return release;
|
|
69
|
-
return () => (element.isConnected ? release() : queueMicrotask(() => release()));
|
|
70
|
-
};
|
|
71
|
-
later.set(attach, deferred);
|
|
72
|
-
}
|
|
73
|
-
result[key] = deferred;
|
|
74
|
-
}
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
@@ -24,3 +24,7 @@ export declare const tabStripTabMarker: Readonly<{
|
|
|
24
24
|
export declare const appShellStripMarker: Readonly<{
|
|
25
25
|
readonly marker: stylex.StyleXClassNameFor<"marker", symbol>;
|
|
26
26
|
}>;
|
|
27
|
+
/** Placed around an Input with content at its end, so the field's edge stays firm while the pointer is on that content. */
|
|
28
|
+
export declare const inputMarker: Readonly<{
|
|
29
|
+
readonly marker: stylex.StyleXClassNameFor<"marker", symbol>;
|
|
30
|
+
}>;
|
|
@@ -14,3 +14,5 @@ export const sidebarItemMarker = stylex.defineMarker();
|
|
|
14
14
|
export const tabStripTabMarker = stylex.defineMarker();
|
|
15
15
|
/** Placed on AppShell.Strip, so the header that holds it takes a band's colour and no line. */
|
|
16
16
|
export const appShellStripMarker = stylex.defineMarker();
|
|
17
|
+
/** Placed around an Input with content at its end, so the field's edge stays firm while the pointer is on that content. */
|
|
18
|
+
export const inputMarker = stylex.defineMarker();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Syntax highlighting for Narvi's Markdown, with Pierre's Highlights: a WebAssembly
|
|
3
|
-
* highlighter with
|
|
3
|
+
* highlighter with 190 languages that can tokenize code as it streams.
|
|
4
4
|
*
|
|
5
5
|
* import { highlight } from '@diegopluna/narvi/markdown/highlight';
|
|
6
6
|
* <Markdown value={text} plugins={[highlight()]} />
|
|
7
7
|
*
|
|
8
|
-
* Importing this module loads the highlighter (about
|
|
8
|
+
* Importing this module loads the highlighter (about 190 KB gzipped), so import it where
|
|
9
9
|
* Markdown with code is shown, or with a dynamic `import()` to keep it out of the first load.
|
|
10
10
|
*/
|
|
11
11
|
import { type Theme } from '@pierre/highlights';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Syntax highlighting for Narvi's Markdown, with Pierre's Highlights: a WebAssembly
|
|
3
|
-
* highlighter with
|
|
3
|
+
* highlighter with 190 languages that can tokenize code as it streams.
|
|
4
4
|
*
|
|
5
5
|
* import { highlight } from '@diegopluna/narvi/markdown/highlight';
|
|
6
6
|
* <Markdown value={text} plugins={[highlight()]} />
|
|
7
7
|
*
|
|
8
|
-
* Importing this module loads the highlighter (about
|
|
8
|
+
* Importing this module loads the highlighter (about 190 KB gzipped), so import it where
|
|
9
9
|
* Markdown with code is shown, or with a dynamic `import()` to keep it out of the first load.
|
|
10
10
|
*/
|
|
11
11
|
import { StreamTokenizer, codeToTokens, isSupportedLanguage } from '@pierre/highlights';
|
package/dist/markdown/html.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Document } from './ast.js';
|
|
1
|
+
import type { Document, Inline } from './ast.js';
|
|
2
2
|
export type HtmlOptions = {
|
|
3
3
|
/** Writes raw HTML as text instead of passing it through. Default `true` (pass through). */
|
|
4
4
|
rawHtml?: boolean | undefined;
|
|
@@ -11,4 +11,6 @@ export type HtmlOptions = {
|
|
|
11
11
|
safeLinks?: boolean | undefined;
|
|
12
12
|
};
|
|
13
13
|
export declare function escapeHtml(s: string): string;
|
|
14
|
+
/** Inline nodes as HTML, as `toHtml` writes them inside a block. */
|
|
15
|
+
export declare function inlinesToHtml(nodes: Inline[], options?: HtmlOptions): string;
|
|
14
16
|
export declare function toHtml(doc: Document, options?: HtmlOptions): string;
|
package/dist/markdown/html.js
CHANGED
|
@@ -279,6 +279,12 @@ class Writer {
|
|
|
279
279
|
this.write('</ol>\n</section>\n');
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
+
/** Inline nodes as HTML, as `toHtml` writes them inside a block. */
|
|
283
|
+
export function inlinesToHtml(nodes, options = {}) {
|
|
284
|
+
const writer = new Writer({ rawHtml: true, tagFilter: true, safeLinks: false, ...options });
|
|
285
|
+
writer.inlines(nodes);
|
|
286
|
+
return writer.out;
|
|
287
|
+
}
|
|
282
288
|
export function toHtml(doc, options = {}) {
|
|
283
289
|
const writer = new Writer({ rawHtml: true, tagFilter: true, safeLinks: false, ...options });
|
|
284
290
|
for (const f of doc.footnotes)
|
package/dist/markdown/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export type * from './ast.js';
|
|
8
8
|
export { MarkdownStream, parse, type ParseOptions } from './parse.js';
|
|
9
|
-
export { escapeHtml, toHtml, type HtmlOptions } from './html.js';
|
|
10
|
-
export { inlineText, tableToCsv, tableToMarkdown } from './table.js';
|
|
9
|
+
export { escapeHtml, inlinesToHtml, toHtml, type HtmlOptions } from './html.js';
|
|
10
|
+
export { displayWidth, inlineText, tableToCsv, tableToHtml, tableToMarkdown, tableToText } from './table.js';
|
|
11
11
|
export { defaultLinkPolicy, mapInlines, mapText, readUrl, withProps, type HighlightStream, type HighlightToken, type Highlighter, type LinkPolicy, type MarkdownPlugin, type NodeProps, type PluginComponent, type StaticPart, type StaticTools, type ResolvedLinkPolicy } from './plugin.js';
|
|
12
12
|
export { groupBlockHtml, groupInlineHtml, sanitizeHtml, type HtmlElement, type HtmlGroup, type HtmlInlineElement, type HtmlMarkdown, type HtmlNode, type HtmlText, type RenderBlock, type RenderInline, type UrlPolicy } from './sanitize.js';
|
package/dist/markdown/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { MarkdownStream, parse } from './parse.js';
|
|
2
|
-
export { escapeHtml, toHtml } from './html.js';
|
|
3
|
-
export { inlineText, tableToCsv, tableToMarkdown } from './table.js';
|
|
2
|
+
export { escapeHtml, inlinesToHtml, toHtml } from './html.js';
|
|
3
|
+
export { displayWidth, inlineText, tableToCsv, tableToHtml, tableToMarkdown, tableToText } from './table.js';
|
|
4
4
|
export { defaultLinkPolicy, mapInlines, mapText, readUrl, withProps } from './plugin.js';
|
|
5
5
|
export { groupBlockHtml, groupInlineHtml, sanitizeHtml } from './sanitize.js';
|
package/dist/markdown/table.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A table, written out again: as Markdown,
|
|
2
|
+
* A table, written out again: as Markdown, as CSV for a spreadsheet, as HTML for a rich-text
|
|
3
|
+
* editor, or as text whose columns line up.
|
|
3
4
|
*/
|
|
4
5
|
import type { Inline, Table } from './ast.js';
|
|
5
6
|
/** The text of inline nodes, without their formatting. A formula is its TeX. */
|
|
@@ -11,3 +12,21 @@ export declare function tableToMarkdown(table: Table): string;
|
|
|
11
12
|
* separator or a line ending, and kept from being read as formulas. `separator` is a comma by default; a tab makes TSV.
|
|
12
13
|
*/
|
|
13
14
|
export declare function tableToCsv(table: Table, separator?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The table as HTML, for a rich-text editor: a `<table>` with a head and a body, each cell's
|
|
17
|
+
* alignment as `align` and as `text-align`, and its emphasis, code and links kept. Raw HTML in
|
|
18
|
+
* a cell is written as text, and a link or image the default policy refuses is its words.
|
|
19
|
+
*/
|
|
20
|
+
export declare function tableToHtml(table: Table): string;
|
|
21
|
+
/**
|
|
22
|
+
* How many columns text takes in a monospace font, as a terminal draws it: two for a CJK
|
|
23
|
+
* character or an emoji, none for a combining mark or a zero-width space, one for the rest.
|
|
24
|
+
*/
|
|
25
|
+
export declare function displayWidth(text: string): number;
|
|
26
|
+
/**
|
|
27
|
+
* The table as text whose columns line up in a monospace font: for a terminal, a commit
|
|
28
|
+
* message or a chat that takes no formatting. Columns are two spaces apart, the head is
|
|
29
|
+
* underlined with dashes, and each column is aligned as the table says, counting wide
|
|
30
|
+
* characters as two columns. Lines carry no spaces at their end.
|
|
31
|
+
*/
|
|
32
|
+
export declare function tableToText(table: Table): string;
|