-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0
/** @jsx h */
import type * as Hast from "../../../deps/esm.sh/hast/types.ts";
import { h } from "../../../deps/esm.sh/hastscript/mod.ts";
import {
type Handlers,
type State,
} from "../../../deps/esm.sh/mdast-util-to-hast/mod.ts";
import {
type CalloutType,
type OfmCallout,
parseOfmCalloutNode,
} from "../../../content_parser/obsidian_markdown/mdast_util_ofm_callout.ts";
import { buildClasses, css, join } from "../css.ts";
import * as icons from "../icons/lucide.tsx";
const c = buildClasses("fm-co", [
"root",
"title",
"titleText",
"body",
"icon",
"bg",
"chevron",
]);
export const calloutStyles = join(
icons.lucideIconStyles,
css`
.${c.root} {
--_macana-callout-overlay: hsl(0deg 0% 0% / 0.03);
--_macana-callout-color: var(--callout-color-info, var(--obsidian-color-fallback));
position: relative;
margin: 0;
margin-top: calc(var(--baseline) * 1rem);
padding: 0;
line-height: calc(var(--baseline) * 1rem);
max-width: 100%;
font-size: 1rem;
border: 1px solid var(--_macana-callout-color);
border-radius: 4px;
}
.${c.root}[data-type="todo"] {
--_macana-callout-color: var(--callout-color-todo);
}
.${c.root}[data-type="tip"] {
--_macana-callout-color: var(--callout-color-tip);
}
.${c.root}[data-type="success"] {
--_macana-callout-color: var(--callout-color-success);
}
.${c.root}[data-type="question"] {
--_macana-callout-color: var(--callout-color-question);
}
.${c.root}[data-type="warning"] {
--_macana-callout-color: var(--callout-color-warning);
}
.${c.root}[data-type="failure"] {
--_macana-callout-color: var(--callout-color-failure);
}
.${c.root}[data-type="danger"] {
--_macana-callout-color: var(--callout-color-danger);
}
.${c.root}[data-type="bug"] {
--_macana-callout-color: var(--callout-color-bug);
}
.${c.root}[data-type="example"] {
--_macana-callout-color: var(--callout-color-example);
}
.${c.root}[data-type="quote"] {
--_macana-callout-color: var(--callout-color-quote);
}
.${c.bg} {
position: absolute;
inset: 0;
background-color: var(--_macana-callout-color);
pointer-events: none;
opacity: 0.02;
}
@media (prefers-color-scheme: dark) {
.${c.root} {
--_macana-callout-overlay: hsl(0deg 0% 100% / 0.1);
}
.${c.bg} {
opacity: 0.05;
}
}
.${c.title} {
font-size: 1.1rem;
display: flex;
justify-content: flex-start;
align-items: center;
gap: 0.25em;
padding: calc(var(--baseline) * 0.5rem) 8px;
border-bottom: 1px solid var(--_macana-callout-overlay);
margin: 0;
font-weight: 700;
}
summary.${c.title} {
cursor: pointer;
}
summary.${c.title}:hover {
background-color: var(--_macana-callout-overlay);
}
details:not([open]) > summary.${c.title} {
border-bottom-color: transparent;
}
.${c.icon} {
color: var(--_macana-callout-color);
}
.${c.titleText} {
line-height: calc(var(--baseline) * 1rem);
}
.${c.chevron} {
transition: transform 0.15s ease-out;
}
details:not([open]) .${c.chevron} {
transform: rotate(-90deg);
}
.${c.body} {
font-size: 1rem;
padding: calc(var(--baseline) * 0.5rem) 12px;
}
.${c.body} > :first-child {
margin-block-start: 0;
}
`,
);
let counter = 0;
export function calloutHandlers(): Handlers {
return {
// @ts-expect-error: unist-related libraries heavily relies on ambient module declarations,
// which Deno does not support. APIs also don't accept type parameters.
ofmCallout(state: State, node: OfmCallout): Hast.Nodes {
const { title, body, type } = parseOfmCalloutNode(state, node);
const titleId = "__macana-callout__" + (counter++).toString(16);
const containerProps = {
class: c.root,
"aria-labelledby": titleId,
"data-type": type,
};
if (!node.isFoldable) {
return (
<aside
{...containerProps}
>
<div class={c.bg} />
<p class={c.title} id={titleId}>
{icon(type, c.icon)}
<span class={c.titleText}>{title}</span>
</p>
<div class={c.body}>{body}</div>
</aside>
);
}
return (
<aside {...containerProps}>
<div class={c.bg} />
<details open={node.defaultExpanded ? "" : undefined}>
<summary class={c.title} id={titleId}>
{icon(type, c.icon)}
<span class={c.titleText}>{title}</span>
{icons.chevronDown({
className: c.chevron,
"aria-hidden": "true",
})}
</summary>
<div class={c.body}>{body}</div>
</details>
</aside>
);
},
};
}
function icon(type: CalloutType, className?: string) {
switch (type) {
case "abstract":
return icons.clipboardList({
className,
role: "img",
"aria-label": "Clipboard icon",
});
case "info":
return icons.info({
className,
role: "img",
"aria-label": "Info icon",
});
case "todo":
return icons.circleCheck({
className,
role: "img",
"aria-label": "Check icon",
});
case "tip":
return icons.flame({
className,
role: "img",
"aria-label": "Flame icon",
});
case "success":
return icons.check({
className,
role: "img",
"aria-label": "Check icon",
});
case "question":
return icons.circleHelp({
className,
role: "img",
"aria-label": "Question icon",
});
case "warning":
return icons.triangleAlert({
className,
role: "img",
"aria-label": "Warning icon",
});
case "failure":
return icons.x({
className,
role: "img",
"aria-label": "Cross icon",
});
case "danger":
return icons.zap({
className,
role: "img",
"aria-label": "Lightning icon",
});
case "bug":
return icons.bug({
className,
role: "img",
"aria-label": "Bug icon",
});
case "example":
return icons.list({
className,
role: "img",
"aria-label": "List icon",
});
case "quote":
return icons.quote({
className,
role: "img",
"aria-label": "Quote icon",
});
case "note":
default:
return icons.pencil({
className,
role: "img",
"aria-label": "Pencil icon",
});
}
}