@seekalfred/primitives 0.6.0 → 0.7.3
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/README.md +214 -15
- package/dist/activity-heatmap/activity-heatmap.d.ts +92 -0
- package/dist/activity-heatmap/activity-heatmap.js +699 -0
- package/dist/activity-heatmap/activity-heatmap.js.map +1 -0
- package/dist/activity-heatmap/index.d.ts +2 -0
- package/dist/activity-heatmap/index.js +2 -0
- package/dist/alert/alert.d.ts +53 -4
- package/dist/alert/alert.js +100 -11
- package/dist/alert/alert.js.map +1 -1
- package/dist/alert/index.d.ts +2 -2
- package/dist/alert/index.js +2 -2
- package/dist/alert-dialog/alert-dialog.d.ts +58 -18
- package/dist/alert-dialog/alert-dialog.js +152 -9
- package/dist/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/alert-dialog/index.d.ts +2 -2
- package/dist/alert-dialog/index.js +2 -2
- package/dist/animated-counter/animated-counter.d.ts +38 -0
- package/dist/animated-counter/animated-counter.js +230 -0
- package/dist/animated-counter/animated-counter.js.map +1 -0
- package/dist/animated-counter/index.d.ts +2 -0
- package/dist/animated-counter/index.js +2 -0
- package/dist/announcement-bar/announcement-bar.d.ts +67 -0
- package/dist/announcement-bar/announcement-bar.js +364 -0
- package/dist/announcement-bar/announcement-bar.js.map +1 -0
- package/dist/announcement-bar/index.d.ts +2 -0
- package/dist/announcement-bar/index.js +2 -0
- package/dist/badge/badge.d.ts +1 -1
- package/dist/bar-chart/bar-chart.d.ts +51 -0
- package/dist/bar-chart/bar-chart.js +565 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/index.d.ts +2 -0
- package/dist/bar-chart/index.js +2 -0
- package/dist/breadcrumb/breadcrumb.d.ts +2 -2
- package/dist/breadcrumb/breadcrumb.js +12 -3
- package/dist/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/brush-chart/brush-chart.d.ts +64 -0
- package/dist/brush-chart/brush-chart.js +1056 -0
- package/dist/brush-chart/brush-chart.js.map +1 -0
- package/dist/brush-chart/index.d.ts +2 -0
- package/dist/brush-chart/index.js +2 -0
- package/dist/button/button.d.ts +1 -1
- package/dist/button/button.js +31 -21
- package/dist/button/button.js.map +1 -1
- package/dist/button-group/button-group.js +3 -4
- package/dist/button-group/button-group.js.map +1 -1
- package/dist/calendar/calendar.d.ts +1 -1
- package/dist/card/card.d.ts +22 -1
- package/dist/card/card.js +60 -7
- package/dist/card/card.js.map +1 -1
- package/dist/card-stack/card-stack.d.ts +54 -0
- package/dist/card-stack/card-stack.js +492 -0
- package/dist/card-stack/card-stack.js.map +1 -0
- package/dist/card-stack/index.d.ts +2 -0
- package/dist/card-stack/index.js +2 -0
- package/dist/carousel/carousel.d.ts +77 -0
- package/dist/carousel/carousel.js +415 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/carousel/index.d.ts +2 -0
- package/dist/carousel/index.js +2 -0
- package/dist/checkbox/checkbox.js +4 -4
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/chip-group/chip-group.d.ts +37 -0
- package/dist/chip-group/chip-group.js +148 -0
- package/dist/chip-group/chip-group.js.map +1 -0
- package/dist/chip-group/index.d.ts +2 -0
- package/dist/chip-group/index.js +2 -0
- package/dist/copy-button/copy-button.d.ts +18 -2
- package/dist/copy-button/copy-button.js +29 -8
- package/dist/copy-button/copy-button.js.map +1 -1
- package/dist/countdown/countdown.d.ts +45 -0
- package/dist/countdown/countdown.js +298 -0
- package/dist/countdown/countdown.js.map +1 -0
- package/dist/countdown/index.d.ts +2 -0
- package/dist/countdown/index.js +2 -0
- package/dist/date-picker/picker-parts.js +1 -1
- package/dist/date-picker/picker-parts.js.map +1 -1
- package/dist/dialog/dialog.js +1 -1
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/donut-chart/donut-chart.d.ts +86 -0
- package/dist/donut-chart/donut-chart.js +593 -0
- package/dist/donut-chart/donut-chart.js.map +1 -0
- package/dist/donut-chart/index.d.ts +2 -0
- package/dist/donut-chart/index.js +2 -0
- package/dist/empty-state/empty-state.d.ts +42 -10
- package/dist/empty-state/empty-state.js +44 -26
- package/dist/empty-state/empty-state.js.map +1 -1
- package/dist/empty-state/index.d.ts +2 -2
- package/dist/empty-state/index.js +2 -2
- package/dist/file-drop-zone/file-drop-zone.js +1 -1
- package/dist/file-drop-zone/file-drop-zone.js.map +1 -1
- package/dist/filter-bar/filter-bar.d.ts +50 -26
- package/dist/filter-bar/filter-bar.js +317 -157
- package/dist/filter-bar/filter-bar.js.map +1 -1
- package/dist/gauge/gauge.d.ts +45 -0
- package/dist/gauge/gauge.js +219 -0
- package/dist/gauge/gauge.js.map +1 -0
- package/dist/gauge/index.d.ts +2 -0
- package/dist/gauge/index.js +2 -0
- package/dist/in-view-title/in-view-title.d.ts +33 -0
- package/dist/in-view-title/in-view-title.js +119 -0
- package/dist/in-view-title/in-view-title.js.map +1 -0
- package/dist/in-view-title/index.d.ts +2 -0
- package/dist/in-view-title/index.js +2 -0
- package/dist/index.d.ts +53 -10
- package/dist/index.js +52 -12
- package/dist/input/input.js +4 -4
- package/dist/input/input.js.map +1 -1
- package/dist/lib/cn.js +11 -1
- package/dist/lib/cn.js.map +1 -1
- package/dist/lib/field-message.js +28 -10
- package/dist/lib/field-message.js.map +1 -1
- package/dist/lib/field-shell.js +10 -3
- package/dist/lib/field-shell.js.map +1 -1
- package/dist/lib/field-surface.js +31 -9
- package/dist/lib/field-surface.js.map +1 -1
- package/dist/lib/flag-emoji.js +50 -0
- package/dist/lib/flag-emoji.js.map +1 -0
- package/dist/lib/flip.js +11 -3
- package/dist/lib/flip.js.map +1 -1
- package/dist/lib/menu-highlight.js +64 -0
- package/dist/lib/menu-highlight.js.map +1 -0
- package/dist/lib/motion.js +9 -2
- package/dist/lib/motion.js.map +1 -1
- package/dist/lib/rolling-value.js +1 -1
- package/dist/lib/rolling-value.js.map +1 -1
- package/dist/lib/spring-tween.js +500 -0
- package/dist/lib/spring-tween.js.map +1 -0
- package/dist/lib/swap-text.js +3 -1
- package/dist/lib/swap-text.js.map +1 -1
- package/dist/lib/use-copy-feedback.js +17 -3
- package/dist/lib/use-copy-feedback.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -0
- package/dist/line-chart/index.js +2 -0
- package/dist/line-chart/line-chart.d.ts +116 -0
- package/dist/line-chart/line-chart.js +740 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/mention-input/index.d.ts +2 -0
- package/dist/mention-input/index.js +2 -0
- package/dist/mention-input/mention-input.d.ts +98 -0
- package/dist/mention-input/mention-input.js +576 -0
- package/dist/mention-input/mention-input.js.map +1 -0
- package/dist/menu/menu.d.ts +2 -0
- package/dist/menu/menu.js +23 -12
- package/dist/menu/menu.js.map +1 -1
- package/dist/money-input/index.d.ts +2 -0
- package/dist/money-input/index.js +2 -0
- package/dist/money-input/money-input.d.ts +86 -0
- package/dist/money-input/money-input.js +613 -0
- package/dist/money-input/money-input.js.map +1 -0
- package/dist/morph-select/index.d.ts +2 -0
- package/dist/morph-select/index.js +2 -0
- package/dist/morph-select/morph-select.d.ts +89 -0
- package/dist/morph-select/morph-select.js +712 -0
- package/dist/morph-select/morph-select.js.map +1 -0
- package/dist/multi-select/index.d.ts +2 -0
- package/dist/multi-select/index.js +2 -0
- package/dist/multi-select/multi-select.d.ts +77 -0
- package/dist/multi-select/multi-select.js +209 -0
- package/dist/multi-select/multi-select.js.map +1 -0
- package/dist/number-field/index.d.ts +2 -0
- package/dist/number-field/index.js +2 -0
- package/dist/number-field/number-field.d.ts +42 -0
- package/dist/number-field/number-field.js +199 -0
- package/dist/number-field/number-field.js.map +1 -0
- package/dist/onboarding-checklist/index.d.ts +2 -0
- package/dist/onboarding-checklist/index.js +2 -0
- package/dist/onboarding-checklist/onboarding-checklist.d.ts +55 -0
- package/dist/onboarding-checklist/onboarding-checklist.js +577 -0
- package/dist/onboarding-checklist/onboarding-checklist.js.map +1 -0
- package/dist/password-field/password-field.d.ts +16 -0
- package/dist/password-field/password-field.js +39 -10
- package/dist/password-field/password-field.js.map +1 -1
- package/dist/phone-input/index.d.ts +3 -0
- package/dist/phone-input/index.js +3 -0
- package/dist/phone-input/phone-countries.d.ts +29 -0
- package/dist/phone-input/phone-countries.js +170 -0
- package/dist/phone-input/phone-countries.js.map +1 -0
- package/dist/phone-input/phone-input.d.ts +66 -0
- package/dist/phone-input/phone-input.js +440 -0
- package/dist/phone-input/phone-input.js.map +1 -0
- package/dist/popover/index.d.ts +2 -2
- package/dist/popover/index.js +2 -2
- package/dist/popover/popover.d.ts +51 -2
- package/dist/popover/popover.js +59 -8
- package/dist/popover/popover.js.map +1 -1
- package/dist/progress/progress.d.ts +16 -2
- package/dist/progress/progress.js +16 -9
- package/dist/progress/progress.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -2
- package/dist/radio-group/index.js +2 -2
- package/dist/radio-group/radio-group.d.ts +33 -3
- package/dist/radio-group/radio-group.js +110 -10
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/reactions/index.d.ts +2 -0
- package/dist/reactions/index.js +2 -0
- package/dist/reactions/reactions.d.ts +50 -0
- package/dist/reactions/reactions.js +315 -0
- package/dist/reactions/reactions.js.map +1 -0
- package/dist/rich-text-editor/index.d.ts +3 -0
- package/dist/rich-text-editor/index.js +2 -0
- package/dist/rich-text-editor/rich-text-editor.d.ts +70 -0
- package/dist/rich-text-editor/rich-text-editor.js +909 -0
- package/dist/rich-text-editor/rich-text-editor.js.map +1 -0
- package/dist/rich-text-editor/rich-text-engine.d.ts +16 -0
- package/dist/rich-text-editor/rich-text-engine.js +366 -0
- package/dist/rich-text-editor/rich-text-engine.js.map +1 -0
- package/dist/rich-text-editor/rich-text-html.js +174 -0
- package/dist/rich-text-editor/rich-text-html.js.map +1 -0
- package/dist/rich-text-editor/rich-text-icons.js +43 -0
- package/dist/rich-text-editor/rich-text-icons.js.map +1 -0
- package/dist/ridgeline/index.d.ts +2 -0
- package/dist/ridgeline/index.js +2 -0
- package/dist/ridgeline/ridgeline.d.ts +55 -0
- package/dist/ridgeline/ridgeline.js +701 -0
- package/dist/ridgeline/ridgeline.js.map +1 -0
- package/dist/scroll-area/index.d.ts +2 -2
- package/dist/scroll-area/index.js +2 -2
- package/dist/scroll-area/scroll-area.d.ts +68 -31
- package/dist/scroll-area/scroll-area.js +212 -62
- package/dist/scroll-area/scroll-area.js.map +1 -1
- package/dist/scrub-input/evaluate.d.ts +14 -0
- package/dist/scrub-input/evaluate.js +72 -0
- package/dist/scrub-input/evaluate.js.map +1 -0
- package/dist/scrub-input/index.d.ts +3 -0
- package/dist/scrub-input/index.js +3 -0
- package/dist/scrub-input/scrub-input.d.ts +74 -0
- package/dist/scrub-input/scrub-input.js +486 -0
- package/dist/scrub-input/scrub-input.js.map +1 -0
- package/dist/search-field/search-field.d.ts +24 -2
- package/dist/search-field/search-field.js +24 -9
- package/dist/search-field/search-field.js.map +1 -1
- package/dist/select/select.d.ts +3 -1
- package/dist/select/select.js +28 -14
- package/dist/select/select.js.map +1 -1
- package/dist/separator/separator.d.ts +22 -10
- package/dist/separator/separator.js +33 -11
- package/dist/separator/separator.js.map +1 -1
- package/dist/sheet/sheet.js +2 -1
- package/dist/sheet/sheet.js.map +1 -1
- package/dist/shortcut-recorder/index.d.ts +3 -0
- package/dist/shortcut-recorder/index.js +3 -0
- package/dist/shortcut-recorder/shortcut-model.d.ts +27 -0
- package/dist/shortcut-recorder/shortcut-model.js +206 -0
- package/dist/shortcut-recorder/shortcut-model.js.map +1 -0
- package/dist/shortcut-recorder/shortcut-recorder.d.ts +93 -0
- package/dist/shortcut-recorder/shortcut-recorder.js +489 -0
- package/dist/shortcut-recorder/shortcut-recorder.js.map +1 -0
- package/dist/slider/index.d.ts +2 -2
- package/dist/slider/slider.d.ts +46 -14
- package/dist/slider/slider.js +151 -67
- package/dist/slider/slider.js.map +1 -1
- package/dist/slope-chart/index.d.ts +2 -0
- package/dist/slope-chart/index.js +2 -0
- package/dist/slope-chart/slope-chart.d.ts +54 -0
- package/dist/slope-chart/slope-chart.js +568 -0
- package/dist/slope-chart/slope-chart.js.map +1 -0
- package/dist/sparkline/index.d.ts +2 -0
- package/dist/sparkline/index.js +2 -0
- package/dist/sparkline/sparkline.d.ts +46 -0
- package/dist/sparkline/sparkline.js +390 -0
- package/dist/sparkline/sparkline.js.map +1 -0
- package/dist/split-bar/index.d.ts +2 -0
- package/dist/split-bar/index.js +2 -0
- package/dist/split-bar/split-bar.d.ts +62 -0
- package/dist/split-bar/split-bar.js +513 -0
- package/dist/split-bar/split-bar.js.map +1 -0
- package/dist/split-button/split-button.d.ts +1 -1
- package/dist/split-button/split-button.js +12 -11
- package/dist/split-button/split-button.js.map +1 -1
- package/dist/stat-card/index.d.ts +2 -2
- package/dist/stat-card/index.js +2 -2
- package/dist/stat-card/stat-card.d.ts +58 -5
- package/dist/stat-card/stat-card.js +144 -17
- package/dist/stat-card/stat-card.js.map +1 -1
- package/dist/stepper/index.d.ts +2 -0
- package/dist/stepper/index.js +2 -0
- package/dist/stepper/stepper.d.ts +51 -0
- package/dist/stepper/stepper.js +215 -0
- package/dist/stepper/stepper.js.map +1 -0
- package/dist/streamgraph/index.d.ts +2 -0
- package/dist/streamgraph/index.js +2 -0
- package/dist/streamgraph/streamgraph.d.ts +70 -0
- package/dist/streamgraph/streamgraph.js +613 -0
- package/dist/streamgraph/streamgraph.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/swipe-actions/index.d.ts +2 -0
- package/dist/swipe-actions/index.js +2 -0
- package/dist/swipe-actions/swipe-actions.d.ts +67 -0
- package/dist/swipe-actions/swipe-actions.js +552 -0
- package/dist/swipe-actions/swipe-actions.js.map +1 -0
- package/dist/switch/switch.js +2 -2
- package/dist/switch/switch.js.map +1 -1
- package/dist/table/index.d.ts +2 -2
- package/dist/table/index.js +2 -2
- package/dist/table/table.d.ts +55 -3
- package/dist/table/table.js +340 -165
- package/dist/table/table.js.map +1 -1
- package/dist/tabs/tabs.js +2 -2
- package/dist/tabs/tabs.js.map +1 -1
- package/dist/tag-input/index.d.ts +2 -0
- package/dist/tag-input/index.js +2 -0
- package/dist/tag-input/tag-input.d.ts +40 -0
- package/dist/tag-input/tag-input.js +269 -0
- package/dist/tag-input/tag-input.js.map +1 -0
- package/dist/text-morph/index.d.ts +2 -0
- package/dist/text-morph/index.js +2 -0
- package/dist/text-morph/text-morph.d.ts +23 -0
- package/dist/text-morph/text-morph.js +21 -0
- package/dist/text-morph/text-morph.js.map +1 -0
- package/dist/text-reveal/index.d.ts +2 -0
- package/dist/text-reveal/index.js +2 -0
- package/dist/text-reveal/text-reveal.d.ts +27 -0
- package/dist/text-reveal/text-reveal.js +51 -0
- package/dist/text-reveal/text-reveal.js.map +1 -0
- package/dist/text-shimmer/index.d.ts +2 -0
- package/dist/text-shimmer/index.js +2 -0
- package/dist/text-shimmer/text-shimmer.d.ts +29 -0
- package/dist/text-shimmer/text-shimmer.js +29 -0
- package/dist/text-shimmer/text-shimmer.js.map +1 -0
- package/dist/time-picker/time-picker.d.ts +36 -1
- package/dist/time-picker/time-picker.js +35 -7
- package/dist/time-picker/time-picker.js.map +1 -1
- package/dist/toast/index.d.ts +2 -2
- package/dist/toast/index.js +2 -2
- package/dist/toast/toast.d.ts +7 -1
- package/dist/toast/toast.js +82 -40
- package/dist/toast/toast.js.map +1 -1
- package/dist/tooltip/tooltip.d.ts +9 -2
- package/dist/tooltip/tooltip.js +7 -7
- package/dist/tooltip/tooltip.js.map +1 -1
- package/dist/treemap/index.d.ts +2 -0
- package/dist/treemap/index.js +2 -0
- package/dist/treemap/treemap.d.ts +53 -0
- package/dist/treemap/treemap.js +699 -0
- package/dist/treemap/treemap.js.map +1 -0
- package/dist/usage-meter/index.d.ts +2 -0
- package/dist/usage-meter/index.js +2 -0
- package/dist/usage-meter/usage-meter.d.ts +80 -0
- package/dist/usage-meter/usage-meter.js +458 -0
- package/dist/usage-meter/usage-meter.js.map +1 -0
- package/dist/waffle-chart/index.d.ts +2 -0
- package/dist/waffle-chart/index.js +2 -0
- package/dist/waffle-chart/waffle-chart.d.ts +57 -0
- package/dist/waffle-chart/waffle-chart.js +426 -0
- package/dist/waffle-chart/waffle-chart.js.map +1 -0
- package/package.json +165 -3
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
//#region src/rich-text-editor/rich-text-html.ts
|
|
2
|
+
const BLOCK_TAGS = /* @__PURE__ */ new Set([
|
|
3
|
+
"P",
|
|
4
|
+
"H1",
|
|
5
|
+
"H2",
|
|
6
|
+
"H3",
|
|
7
|
+
"LI",
|
|
8
|
+
"PRE",
|
|
9
|
+
"BLOCKQUOTE",
|
|
10
|
+
"DIV",
|
|
11
|
+
"UL",
|
|
12
|
+
"OL",
|
|
13
|
+
"HR"
|
|
14
|
+
]);
|
|
15
|
+
const INLINE_MAP = {
|
|
16
|
+
B: "strong",
|
|
17
|
+
STRONG: "strong",
|
|
18
|
+
I: "em",
|
|
19
|
+
EM: "em",
|
|
20
|
+
U: "u",
|
|
21
|
+
S: "s",
|
|
22
|
+
STRIKE: "s",
|
|
23
|
+
DEL: "s",
|
|
24
|
+
CODE: "code",
|
|
25
|
+
A: "a",
|
|
26
|
+
BR: "br"
|
|
27
|
+
};
|
|
28
|
+
const BLOCK_MAP = {
|
|
29
|
+
P: "p",
|
|
30
|
+
H1: "h1",
|
|
31
|
+
H2: "h2",
|
|
32
|
+
H3: "h3",
|
|
33
|
+
H4: "h3",
|
|
34
|
+
H5: "h3",
|
|
35
|
+
H6: "h3",
|
|
36
|
+
UL: "ul",
|
|
37
|
+
OL: "ol",
|
|
38
|
+
LI: "li",
|
|
39
|
+
BLOCKQUOTE: "blockquote",
|
|
40
|
+
PRE: "pre",
|
|
41
|
+
HR: "hr"
|
|
42
|
+
};
|
|
43
|
+
const DROP = /* @__PURE__ */ new Set([
|
|
44
|
+
"SCRIPT",
|
|
45
|
+
"STYLE",
|
|
46
|
+
"META",
|
|
47
|
+
"LINK",
|
|
48
|
+
"TITLE",
|
|
49
|
+
"TEMPLATE",
|
|
50
|
+
"IFRAME",
|
|
51
|
+
"OBJECT",
|
|
52
|
+
"EMBED",
|
|
53
|
+
"SVG",
|
|
54
|
+
"CANVAS",
|
|
55
|
+
"IMG",
|
|
56
|
+
"VIDEO",
|
|
57
|
+
"AUDIO",
|
|
58
|
+
"INPUT",
|
|
59
|
+
"BUTTON",
|
|
60
|
+
"SELECT",
|
|
61
|
+
"TEXTAREA",
|
|
62
|
+
"HEAD"
|
|
63
|
+
]);
|
|
64
|
+
/** Links the editor will keep: web, mail, phone, and in-page or site-relative addresses. Anything else (javascript:, data:) is dropped. */
|
|
65
|
+
const isSafeUrl = (url) => /^(https?:|mailto:|tel:|\/|#)/i.test(url.trim());
|
|
66
|
+
/** Adds a scheme to a bare domain so `example.com/docs` becomes a working link, and `mailto:` to an address. */
|
|
67
|
+
function normalizeUrl(input) {
|
|
68
|
+
const url = input.trim();
|
|
69
|
+
if (!url) return "";
|
|
70
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(url) || url.startsWith("/") || url.startsWith("#")) return url;
|
|
71
|
+
if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(url)) return `mailto:${url}`;
|
|
72
|
+
return `https://${url}`;
|
|
73
|
+
}
|
|
74
|
+
const isText = (node) => node.nodeType === Node.TEXT_NODE;
|
|
75
|
+
/** The text of a code block, with a line break where the source has a <br>. */
|
|
76
|
+
function codeText(element) {
|
|
77
|
+
let text = "";
|
|
78
|
+
element.childNodes.forEach((node) => {
|
|
79
|
+
if (isText(node)) text += node.data;
|
|
80
|
+
else if (node.nodeName === "BR") text += "\n";
|
|
81
|
+
else if (node.nodeType === Node.ELEMENT_NODE) text += codeText(node);
|
|
82
|
+
});
|
|
83
|
+
return text;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Keeps only the tags the editor understands and drops every attribute except safe link targets.
|
|
87
|
+
* Bold, italic, underline and strike spans from other editors become marks. Returns the cleaned
|
|
88
|
+
* document as a detached element.
|
|
89
|
+
*/
|
|
90
|
+
function sanitizeToDom(html) {
|
|
91
|
+
const source = new DOMParser().parseFromString(html, "text/html").body;
|
|
92
|
+
const out = document.createElement("div");
|
|
93
|
+
const convert = (from, into) => {
|
|
94
|
+
from.childNodes.forEach((child) => {
|
|
95
|
+
if (isText(child)) {
|
|
96
|
+
into.appendChild(document.createTextNode(child.data));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (child.nodeType !== Node.ELEMENT_NODE) return;
|
|
100
|
+
const element = child;
|
|
101
|
+
if (DROP.has(element.nodeName)) return;
|
|
102
|
+
const style = element.getAttribute("style") ?? "";
|
|
103
|
+
let tag = INLINE_MAP[element.nodeName] ?? BLOCK_MAP[element.nodeName];
|
|
104
|
+
if (element.nodeName === "B" && /font-weight:\s*(normal|[1-4]00)/.test(style)) tag = "";
|
|
105
|
+
if (element.nodeName === "SPAN") tag = /font-weight:\s*(bold|[6-9]00)/.test(style) ? "strong" : /font-style:\s*italic/.test(style) ? "em" : /text-decoration[^;]*underline/.test(style) ? "u" : /line-through/.test(style) ? "s" : "";
|
|
106
|
+
if (!tag) {
|
|
107
|
+
convert(element, into);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const next = document.createElement(tag);
|
|
111
|
+
if (tag === "a") {
|
|
112
|
+
const href = element.getAttribute("href") ?? "";
|
|
113
|
+
if (!isSafeUrl(href)) {
|
|
114
|
+
convert(element, into);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
next.setAttribute("href", href);
|
|
118
|
+
}
|
|
119
|
+
if (tag === "pre") next.textContent = codeText(element);
|
|
120
|
+
else if (tag !== "br" && tag !== "hr") convert(element, next);
|
|
121
|
+
into.appendChild(next);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
convert(source, out);
|
|
125
|
+
const fixed = document.createElement("div");
|
|
126
|
+
let run = null;
|
|
127
|
+
Array.from(out.childNodes).forEach((node) => {
|
|
128
|
+
if (node.nodeType === Node.ELEMENT_NODE && BLOCK_TAGS.has(node.nodeName)) {
|
|
129
|
+
run = null;
|
|
130
|
+
fixed.appendChild(node);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (isText(node) && !node.data.trim() && !run) return;
|
|
134
|
+
if (!run) {
|
|
135
|
+
run = document.createElement("p");
|
|
136
|
+
fixed.appendChild(run);
|
|
137
|
+
}
|
|
138
|
+
run.appendChild(node);
|
|
139
|
+
});
|
|
140
|
+
fixed.querySelectorAll("li > p").forEach((paragraph) => paragraph.replaceWith(...Array.from(paragraph.childNodes)));
|
|
141
|
+
[fixed, ...Array.from(fixed.querySelectorAll("ul, ol, blockquote, li"))].forEach((parent) => Array.from(parent.childNodes).forEach((node) => {
|
|
142
|
+
if (isText(node) && !node.data.trim() && (parent === fixed || parent.nodeName === "UL" || parent.nodeName === "OL" || node.previousSibling && BLOCK_TAGS.has(node.previousSibling.nodeName) || node.nextSibling && BLOCK_TAGS.has(node.nextSibling.nodeName))) node.remove();
|
|
143
|
+
}));
|
|
144
|
+
return fixed;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Canonical output for whatever HTML the engine exported: only the editor's tags, no attributes
|
|
148
|
+
* but link targets, nested lists inside the item they belong to, no trailing empty blocks.
|
|
149
|
+
*/
|
|
150
|
+
function canonicalDom(raw) {
|
|
151
|
+
const root = sanitizeToDom(raw);
|
|
152
|
+
root.querySelectorAll("li").forEach((item) => {
|
|
153
|
+
const list = item.firstElementChild;
|
|
154
|
+
const previous = item.previousElementSibling;
|
|
155
|
+
if (!!list && (list.nodeName === "UL" || list.nodeName === "OL") && Array.from(item.childNodes).every((node) => node === list || isText(node) && !node.data.trim()) && previous?.nodeName === "LI") {
|
|
156
|
+
previous.appendChild(list);
|
|
157
|
+
item.remove();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
root.querySelectorAll("strong strong, em em, u u, s s").forEach((inner) => {
|
|
161
|
+
if (inner.parentNode) inner.replaceWith(...Array.from(inner.childNodes));
|
|
162
|
+
});
|
|
163
|
+
const visible = (element) => !!element.textContent?.trim() || !!element.querySelector("hr");
|
|
164
|
+
while (root.lastElementChild && root.children.length > 1 && root.lastElementChild.nodeName !== "HR" && !visible(root.lastElementChild)) root.lastElementChild.remove();
|
|
165
|
+
return root;
|
|
166
|
+
}
|
|
167
|
+
/** Plain text of canonical HTML: one line per block. */
|
|
168
|
+
function plainText(root) {
|
|
169
|
+
return Array.from(root.querySelectorAll("p, h1, h2, h3, li, blockquote, pre")).filter((block) => !block.querySelector("p, li")).map((block) => (block.textContent ?? "").trim()).filter(Boolean).join("\n");
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { canonicalDom, isSafeUrl, normalizeUrl, plainText, sanitizeToDom };
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=rich-text-html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-text-html.js","names":[],"sources":["../../src/rich-text-editor/rich-text-html.ts"],"sourcesContent":["/*\n * The HTML the editor accepts and writes. Plain DOM work, no Lexical: a stored value is\n * engine-independent HTML in a small fixed vocabulary, so it survives a change of editor.\n */\n\nconst BLOCK_TAGS = new Set([\n \"P\",\n \"H1\",\n \"H2\",\n \"H3\",\n \"LI\",\n \"PRE\",\n \"BLOCKQUOTE\",\n \"DIV\",\n \"UL\",\n \"OL\",\n \"HR\",\n]);\nconst INLINE_MAP: Record<string, string> = {\n B: \"strong\",\n STRONG: \"strong\",\n I: \"em\",\n EM: \"em\",\n U: \"u\",\n S: \"s\",\n STRIKE: \"s\",\n DEL: \"s\",\n CODE: \"code\",\n A: \"a\",\n BR: \"br\",\n};\nconst BLOCK_MAP: Record<string, string> = {\n P: \"p\",\n H1: \"h1\",\n H2: \"h2\",\n H3: \"h3\",\n H4: \"h3\",\n H5: \"h3\",\n H6: \"h3\",\n UL: \"ul\",\n OL: \"ol\",\n LI: \"li\",\n BLOCKQUOTE: \"blockquote\",\n PRE: \"pre\",\n HR: \"hr\",\n};\nconst DROP = new Set([\n \"SCRIPT\",\n \"STYLE\",\n \"META\",\n \"LINK\",\n \"TITLE\",\n \"TEMPLATE\",\n \"IFRAME\",\n \"OBJECT\",\n \"EMBED\",\n \"SVG\",\n \"CANVAS\",\n \"IMG\",\n \"VIDEO\",\n \"AUDIO\",\n \"INPUT\",\n \"BUTTON\",\n \"SELECT\",\n \"TEXTAREA\",\n \"HEAD\",\n]);\n\n/** Links the editor will keep: web, mail, phone, and in-page or site-relative addresses. Anything else (javascript:, data:) is dropped. */\nexport const isSafeUrl = (url: string) => /^(https?:|mailto:|tel:|\\/|#)/i.test(url.trim());\n\n/** Adds a scheme to a bare domain so `example.com/docs` becomes a working link, and `mailto:` to an address. */\nexport function normalizeUrl(input: string) {\n const url = input.trim();\n if (!url) return \"\";\n if (/^[a-z][a-z\\d+.-]*:/i.test(url) || url.startsWith(\"/\") || url.startsWith(\"#\")) return url;\n if (/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(url)) return `mailto:${url}`;\n return `https://${url}`;\n}\n\nconst isText = (node: Node): node is Text => node.nodeType === Node.TEXT_NODE;\n\n/** The text of a code block, with a line break where the source has a <br>. */\nfunction codeText(element: Element) {\n let text = \"\";\n element.childNodes.forEach((node) => {\n if (isText(node)) text += node.data;\n else if (node.nodeName === \"BR\") text += \"\\n\";\n else if (node.nodeType === Node.ELEMENT_NODE) text += codeText(node as Element);\n });\n return text;\n}\n\n/**\n * Keeps only the tags the editor understands and drops every attribute except safe link targets.\n * Bold, italic, underline and strike spans from other editors become marks. Returns the cleaned\n * document as a detached element.\n */\nexport function sanitizeToDom(html: string): HTMLElement {\n const source = new DOMParser().parseFromString(html, \"text/html\").body;\n const out = document.createElement(\"div\");\n const convert = (from: Node, into: Node) => {\n from.childNodes.forEach((child) => {\n if (isText(child)) {\n into.appendChild(document.createTextNode(child.data));\n return;\n }\n if (child.nodeType !== Node.ELEMENT_NODE) return;\n const element = child as HTMLElement;\n if (DROP.has(element.nodeName)) return;\n const style = element.getAttribute(\"style\") ?? \"\";\n let tag = INLINE_MAP[element.nodeName] ?? BLOCK_MAP[element.nodeName];\n if (element.nodeName === \"B\" && /font-weight:\\s*(normal|[1-4]00)/.test(style)) tag = \"\";\n if (element.nodeName === \"SPAN\") {\n tag = /font-weight:\\s*(bold|[6-9]00)/.test(style)\n ? \"strong\"\n : /font-style:\\s*italic/.test(style)\n ? \"em\"\n : /text-decoration[^;]*underline/.test(style)\n ? \"u\"\n : /line-through/.test(style)\n ? \"s\"\n : \"\";\n }\n if (!tag) {\n convert(element, into);\n return;\n }\n const next = document.createElement(tag);\n if (tag === \"a\") {\n const href = element.getAttribute(\"href\") ?? \"\";\n if (!isSafeUrl(href)) {\n convert(element, into);\n return;\n }\n next.setAttribute(\"href\", href);\n }\n if (tag === \"pre\") next.textContent = codeText(element);\n else if (tag !== \"br\" && tag !== \"hr\") convert(element, next);\n into.appendChild(next);\n });\n };\n convert(source, out);\n\n // Inline runs at the top level become paragraphs; whitespace between blocks disappears.\n const fixed = document.createElement(\"div\");\n let run: HTMLElement | null = null;\n Array.from(out.childNodes).forEach((node) => {\n const block = node.nodeType === Node.ELEMENT_NODE && BLOCK_TAGS.has(node.nodeName);\n if (block) {\n run = null;\n fixed.appendChild(node);\n return;\n }\n if (isText(node) && !node.data.trim() && !run) return;\n if (!run) {\n run = document.createElement(\"p\");\n fixed.appendChild(run);\n }\n run.appendChild(node);\n });\n // A paragraph inside a list item is just the item's text.\n fixed\n .querySelectorAll(\"li > p\")\n .forEach((paragraph) => paragraph.replaceWith(...Array.from(paragraph.childNodes)));\n // Typed whitespace is kept, so only formatting whitespace between blocks and list items goes.\n [fixed, ...Array.from(fixed.querySelectorAll(\"ul, ol, blockquote, li\"))].forEach((parent) =>\n Array.from(parent.childNodes).forEach((node) => {\n if (\n isText(node) &&\n !node.data.trim() &&\n (parent === fixed ||\n parent.nodeName === \"UL\" ||\n parent.nodeName === \"OL\" ||\n (node.previousSibling && BLOCK_TAGS.has(node.previousSibling.nodeName)) ||\n (node.nextSibling && BLOCK_TAGS.has(node.nextSibling.nodeName)))\n )\n node.remove();\n }),\n );\n return fixed;\n}\n\n/** {@link sanitizeToDom} as a string. */\nexport const sanitizeHtml = (html: string) => sanitizeToDom(html).innerHTML;\n\n/**\n * Canonical output for whatever HTML the engine exported: only the editor's tags, no attributes\n * but link targets, nested lists inside the item they belong to, no trailing empty blocks.\n */\nexport function canonicalDom(raw: string): HTMLElement {\n const root = sanitizeToDom(raw);\n // An engine may write a sub-list as an item of its own; it belongs inside the item before it.\n root.querySelectorAll(\"li\").forEach((item) => {\n const list = item.firstElementChild;\n const previous = item.previousElementSibling;\n const wrapper =\n !!list &&\n (list.nodeName === \"UL\" || list.nodeName === \"OL\") &&\n Array.from(item.childNodes).every(\n (node) => node === list || (isText(node) && !node.data.trim()),\n );\n if (wrapper && previous?.nodeName === \"LI\") {\n previous.appendChild(list);\n item.remove();\n }\n });\n // An engine may wrap a mark in the same mark twice; once is enough.\n root.querySelectorAll(\"strong strong, em em, u u, s s\").forEach((inner) => {\n if (inner.parentNode) inner.replaceWith(...Array.from(inner.childNodes));\n });\n const visible = (element: Element) =>\n !!element.textContent?.trim() || !!element.querySelector(\"hr\");\n while (\n root.lastElementChild &&\n root.children.length > 1 &&\n root.lastElementChild.nodeName !== \"HR\" &&\n !visible(root.lastElementChild)\n ) {\n root.lastElementChild.remove();\n }\n return root;\n}\n\n/** Plain text of canonical HTML: one line per block. */\nexport function plainText(root: HTMLElement) {\n return Array.from(root.querySelectorAll(\"p, h1, h2, h3, li, blockquote, pre\"))\n .filter((block) => !block.querySelector(\"p, li\"))\n .map((block) => (block.textContent ?? \"\").trim())\n .filter(Boolean)\n .join(\"\\n\");\n}\n"],"mappings":";AAKA,MAAM,6BAAa,IAAI,IAAI;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,aAAqC;CACzC,GAAG;CACH,QAAQ;CACR,GAAG;CACH,IAAI;CACJ,G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C,QAAQ,cAAc,IAAI;CAC/D,OACE,KAAK,oBACL,KAAK,SAAS,SAAS,KACvB,KAAK,iBAAiB,aAAa,QACnC,CAAC,QAAQ,KAAK,gBAAgB,GAE9B,KAAK,iBAAiB,OAAO;CAE/B,OAAO;AACT;;AAGA,SAAgB,UAAU,MAAmB;CAC3C,OAAO,MAAM,KAAK,KAAK,iBAAiB,oCAAoC,CAAC,CAAC,CAC3E,QAAQ,UAAU,CAAC,MAAM,cAAc,OAAO,CAAC,CAAC,CAChD,KAAK,WAAW,MAAM,eAAe,GAAA,CAAI,KAAK,CAAC,CAAC,CAChD,OAAO,OAAO,CAAC,CACf,KAAK,IAAI;AACd"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
//#region src/rich-text-editor/rich-text-icons.tsx
|
|
3
|
+
function Icon({ children }) {
|
|
4
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
5
|
+
viewBox: "0 0 24 24",
|
|
6
|
+
fill: "none",
|
|
7
|
+
stroke: "currentColor",
|
|
8
|
+
strokeWidth: 1.75,
|
|
9
|
+
strokeLinecap: "round",
|
|
10
|
+
strokeLinejoin: "round",
|
|
11
|
+
"aria-hidden": "true",
|
|
12
|
+
className: "size-4",
|
|
13
|
+
children
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const BoldIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" }) });
|
|
17
|
+
const ItalicIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M19 4h-9M14 20H5M15 4 9 20" }) });
|
|
18
|
+
const UnderlineIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M6 4v6a6 6 0 0 0 12 0V4M4 20h16" }) });
|
|
19
|
+
const StrikeIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M16 4H9a3 3 0 0 0-2.83 4M14 12a4 4 0 0 1 0 8H6M4 12h16" }) });
|
|
20
|
+
const CodeIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "m16 18 6-6-6-6M8 6l-6 6 6 6" }) });
|
|
21
|
+
const LinkIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" }) });
|
|
22
|
+
const UnlinkIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "m18.84 12.25 1.72-1.71a5 5 0 0 0-7.07-7.07l-1.72 1.71M5.17 11.75l-1.71 1.71a5 5 0 0 0 7.07 7.07l1.71-1.71M8 2v3M2 8h3M16 19v3M19 16h3" }) });
|
|
23
|
+
const Heading1Icon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M4 12h8M4 18V6M12 18V6m5 6 3-2v8" }) });
|
|
24
|
+
const Heading2Icon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M4 12h8M4 18V6M12 18V6m9 12h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1" }) });
|
|
25
|
+
const Heading3Icon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M4 12h8M4 18V6M12 18V6m5.5 4.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2" }) });
|
|
26
|
+
const ListIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M3 6h.01M3 12h.01M3 18h.01M8 6h13M8 12h13M8 18h13" }) });
|
|
27
|
+
const ListOrderedIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M10 6h11M10 12h11M10 18h11M4 10h2M4 6h1v4M6 18H4c0-1 2-2 2-3s-1-1.5-2-1" }) });
|
|
28
|
+
const QuoteIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2zM5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }) });
|
|
29
|
+
const CodeBlockIcon = () => /* @__PURE__ */ jsxs(Icon, { children: [/* @__PURE__ */ jsx("path", { d: "m10 9-3 3 3 3M14 15l3-3-3-3" }), /* @__PURE__ */ jsx("rect", {
|
|
30
|
+
x: "3",
|
|
31
|
+
y: "3",
|
|
32
|
+
width: "18",
|
|
33
|
+
height: "18",
|
|
34
|
+
rx: "2"
|
|
35
|
+
})] });
|
|
36
|
+
const DividerIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M5 12h14" }) });
|
|
37
|
+
const ParagraphIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M13 4v16M17 4v16M19 4H9.5a4.5 4.5 0 0 0 0 9H13" }) });
|
|
38
|
+
const BackIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "m12 19-7-7 7-7M19 12H5" }) });
|
|
39
|
+
const CheckIcon = () => /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
|
|
40
|
+
//#endregion
|
|
41
|
+
export { BackIcon, BoldIcon, CheckIcon, CodeBlockIcon, CodeIcon, DividerIcon, Heading1Icon, Heading2Icon, Heading3Icon, ItalicIcon, LinkIcon, ListIcon, ListOrderedIcon, ParagraphIcon, QuoteIcon, StrikeIcon, UnderlineIcon, UnlinkIcon };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=rich-text-icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-text-icons.js","names":[],"sources":["../../src/rich-text-editor/rich-text-icons.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\n/*\n * The editor's icons: 24px strokes, drawn to read at 16px. Decorative (aria-hidden); every\n * control that holds one carries its own accessible name.\n */\nfunction Icon({ children }: { children: ReactNode }) {\n return (\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={1.75}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className=\"size-4\"\n >\n {children}\n </svg>\n );\n}\n\nexport const BoldIcon = () => (\n <Icon>\n <path d=\"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8\" />\n </Icon>\n);\nexport const ItalicIcon = () => (\n <Icon>\n <path d=\"M19 4h-9M14 20H5M15 4 9 20\" />\n </Icon>\n);\nexport const UnderlineIcon = () => (\n <Icon>\n <path d=\"M6 4v6a6 6 0 0 0 12 0V4M4 20h16\" />\n </Icon>\n);\nexport const StrikeIcon = () => (\n <Icon>\n <path d=\"M16 4H9a3 3 0 0 0-2.83 4M14 12a4 4 0 0 1 0 8H6M4 12h16\" />\n </Icon>\n);\nexport const CodeIcon = () => (\n <Icon>\n <path d=\"m16 18 6-6-6-6M8 6l-6 6 6 6\" />\n </Icon>\n);\nexport const LinkIcon = () => (\n <Icon>\n <path d=\"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71\" />\n </Icon>\n);\nexport const UnlinkIcon = () => (\n <Icon>\n <path d=\"m18.84 12.25 1.72-1.71a5 5 0 0 0-7.07-7.07l-1.72 1.71M5.17 11.75l-1.71 1.71a5 5 0 0 0 7.07 7.07l1.71-1.71M8 2v3M2 8h3M16 19v3M19 16h3\" />\n </Icon>\n);\nexport const Heading1Icon = () => (\n <Icon>\n <path d=\"M4 12h8M4 18V6M12 18V6m5 6 3-2v8\" />\n </Icon>\n);\nexport const Heading2Icon = () => (\n <Icon>\n <path d=\"M4 12h8M4 18V6M12 18V6m9 12h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1\" />\n </Icon>\n);\nexport const Heading3Icon = () => (\n <Icon>\n <path d=\"M4 12h8M4 18V6M12 18V6m5.5 4.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2\" />\n </Icon>\n);\nexport const ListIcon = () => (\n <Icon>\n <path d=\"M3 6h.01M3 12h.01M3 18h.01M8 6h13M8 12h13M8 18h13\" />\n </Icon>\n);\nexport const ListOrderedIcon = () => (\n <Icon>\n <path d=\"M10 6h11M10 12h11M10 18h11M4 10h2M4 6h1v4M6 18H4c0-1 2-2 2-3s-1-1.5-2-1\" />\n </Icon>\n);\nexport const QuoteIcon = () => (\n <Icon>\n <path d=\"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2zM5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z\" />\n </Icon>\n);\nexport const CodeBlockIcon = () => (\n <Icon>\n <path d=\"m10 9-3 3 3 3M14 15l3-3-3-3\" />\n <rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\" />\n </Icon>\n);\nexport const DividerIcon = () => (\n <Icon>\n <path d=\"M5 12h14\" />\n </Icon>\n);\nexport const ParagraphIcon = () => (\n <Icon>\n <path d=\"M13 4v16M17 4v16M19 4H9.5a4.5 4.5 0 0 0 0 9H13\" />\n </Icon>\n);\nexport const BackIcon = () => (\n <Icon>\n <path d=\"m12 19-7-7 7-7M19 12H5\" />\n </Icon>\n);\nexport const CheckIcon = () => (\n <Icon>\n <path d=\"M20 6 9 17l-5-5\" />\n </Icon>\n);\n"],"mappings":";;AAMA,SAAS,KAAK,EAAE,YAAqC;CACnD,OACE,oBAAC,OAAD;EACE,SAAQ;EACR,MAAK;EACL,QAAO;EACP,aAAa;EACb,eAAc;EACd,gBAAe;EACf,eAAY;EACZ,WAAU;EAET;CACE,CAAA;AAET;AAEA,MAAa,iBACX,oBAAC,MAAD,EAAA,UACE,oBAAC,QAAD,EAAM,GAAE,wEAAyE,CAAA,EAC7E,CAAA;AAER,MAAa,mBACX,oBAAC,MAAD,EAAA,UACE,oBAAC,QAAD,EAAM,GAAE,6BAA8B,CAAA,EAClC,CAAA;AAER,MAAa,sBACX,oBAAC,MAAD,EAAA,UACE,oBAAC,QAAD,EAAM,GAAE,kCAAmC,CAAA,EACvC,CAAA;AAER,MAAa,mBACX,oBAAC,MAAD,EAAA,UACE,oBAAC,QAAD,EAAM,GAAE,yDAA0D,CAAA,EAC9D,CAAA;AAER,MAAa,iBACX,oBAAC,MAAD,EAAA,UACE,oBAAC,QAAD,EAAM,GAAE,8BAA+B,CAAA,EACnC,CAAA;AAER,MAAa,iBACX,oBAAC,MAAD,EAAA,UACE,oBAAC,QAAD,EAAM,GAAE,0HAA2H,CAAA,EAC/H,CAAA;AAER,MAAa,mBACX,oBAAC,MAA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
//#region src/ridgeline/ridgeline.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Ridgeline: compare the shape of many distributions at once, such as daily
|
|
4
|
+
* temperatures by month or response times by region. Each series is one ridge, a
|
|
5
|
+
* smoothed density of its raw values, drawn top to bottom and overlapping the row
|
|
6
|
+
* behind it; the ridges share one value axis.
|
|
7
|
+
*
|
|
8
|
+
* The ridges roll in from the top row down once the chart is in view. New data
|
|
9
|
+
* morphs every ridge from the shape on screen, and the axis follows. Hovering,
|
|
10
|
+
* touching or the arrow keys lift one ridge above its neighbours with its middle
|
|
11
|
+
* half shaded and its median marked, step the others back, and show a tooltip with
|
|
12
|
+
* the median, the middle half and the range. Moving along the values shows how
|
|
13
|
+
* much of the series sits at or below that value. Each ridge is shaded by its
|
|
14
|
+
* median, from a light tint to the full first series colour, with the scale
|
|
15
|
+
* under the axis.
|
|
16
|
+
*
|
|
17
|
+
* Plain SVG written straight to the DOM by one small spring tween.
|
|
18
|
+
*/
|
|
19
|
+
export interface RidgelineSeries {
|
|
20
|
+
/** Stable identity. A ridge that survives a data change morphs into its new shape. */
|
|
21
|
+
id: string;
|
|
22
|
+
label: string;
|
|
23
|
+
/** Raw observations. The ridge is a smoothed density of these values. */
|
|
24
|
+
values: number[];
|
|
25
|
+
}
|
|
26
|
+
export interface RidgelineProps {
|
|
27
|
+
/** One ridge per series, drawn top to bottom. */
|
|
28
|
+
series: RidgelineSeries[];
|
|
29
|
+
/** What is measured, such as "Daily highs in Zurich". Names the chart for assistive technology. */
|
|
30
|
+
label: string;
|
|
31
|
+
/** Unit after each value, such as "°C". */
|
|
32
|
+
unit?: string;
|
|
33
|
+
formatValue?: (value: number) => string;
|
|
34
|
+
/** Value range of the axis. Defaults to the data with a little room on each side. */
|
|
35
|
+
domain?: [number, number];
|
|
36
|
+
/** How far a ridge may rise into the rows above, in row heights. @default 2.4 */
|
|
37
|
+
overlap?: number;
|
|
38
|
+
/** Height of one row in pixels. @default 30 */
|
|
39
|
+
rowHeight?: number;
|
|
40
|
+
/** Smoothing in value units. Defaults to Silverman's rule per series. */
|
|
41
|
+
bandwidth?: number;
|
|
42
|
+
/** Shades each ridge by its median, from a light tint to the full first series colour, and shows the scale under the axis. @default true */
|
|
43
|
+
tint?: boolean;
|
|
44
|
+
/** Controlled id of the lifted ridge. */
|
|
45
|
+
active?: string | null;
|
|
46
|
+
defaultActive?: string | null;
|
|
47
|
+
onActiveChange?: (id: string | null) => void;
|
|
48
|
+
/** @default "No data yet" */
|
|
49
|
+
emptyLabel?: string;
|
|
50
|
+
/** Extra classes for the root. Merged last. */
|
|
51
|
+
className?: string;
|
|
52
|
+
}
|
|
53
|
+
export declare const Ridgeline: import("react").ForwardRefExoticComponent<RidgelineProps & import("react").RefAttributes<HTMLElement>>;
|
|
54
|
+
//#endregion
|
|
55
|
+
//# sourceMappingURL=ridgeline.d.ts.map
|