@duskmoon-dev/el-markdown-input 1.5.4 → 1.5.6

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.
@@ -61,7 +61,7 @@ var init_sanitize_schema = __esm(() => {
61
61
  import_rehype_sanitize = require("rehype-sanitize");
62
62
  sanitizeSchema = deepMergeSchemas(import_rehype_sanitize.defaultSchema, {
63
63
  attributes: {
64
- span: ["className", "style"],
64
+ span: ["className", "style", "ariaHidden"],
65
65
  code: ["className"],
66
66
  input: ["type", "checked", "disabled"],
67
67
  math: ["xmlns", "display"],
@@ -108,12 +108,57 @@ __export(exports_render, {
108
108
  renderMermaidBlocks: () => renderMermaidBlocks,
109
109
  renderMarkdown: () => renderMarkdown
110
110
  });
111
+ function renderFrontMatter() {
112
+ return (tree) => {
113
+ if (tree.type === "root" && tree.children) {
114
+ tree.children = tree.children.map((node) => node.type === "yaml" ? { type: "code", lang: "yaml", value: node.value } : node);
115
+ }
116
+ };
117
+ }
118
+ function isSupportedColor(value) {
119
+ if (/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(value))
120
+ return true;
121
+ const rgb = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(value);
122
+ if (rgb)
123
+ return rgb.slice(1).every((channel) => Number(channel) <= 255);
124
+ const hsl = /^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/.exec(value);
125
+ return Boolean(hsl && Number(hsl[1]) <= 360 && Number(hsl[2]) <= 100 && Number(hsl[3]) <= 100);
126
+ }
127
+ function addColorChips() {
128
+ return (tree) => {
129
+ appendColorChips(tree);
130
+ };
131
+ }
132
+ function appendColorChips(node) {
133
+ if (!node.children)
134
+ return;
135
+ for (const child of node.children) {
136
+ const text = child.children?.length === 1 ? child.children[0] : undefined;
137
+ const color = node.tagName !== "pre" && child.type === "element" && child.tagName === "code" && text?.type === "text" ? text.value : undefined;
138
+ if (color && isSupportedColor(color)) {
139
+ child.children?.push({
140
+ type: "element",
141
+ tagName: "span",
142
+ properties: {
143
+ className: ["color-chip"],
144
+ style: `--color-chip: ${color}`,
145
+ ariaHidden: "true"
146
+ },
147
+ children: []
148
+ });
149
+ } else {
150
+ appendColorChips(child);
151
+ }
152
+ }
153
+ }
111
154
  async function buildProcessor() {
112
155
  const [
113
156
  { unified },
114
157
  { default: remarkParse },
158
+ { default: remarkFrontmatter },
115
159
  { default: remarkGfm },
116
160
  { default: remarkMath },
161
+ { default: remarkBreaks },
117
162
  { default: remarkRehype },
118
163
  { default: rehypeKatex },
119
164
  { default: rehypePrismPlus },
@@ -122,15 +167,17 @@ async function buildProcessor() {
122
167
  ] = await Promise.all([
123
168
  import("unified"),
124
169
  import("remark-parse"),
170
+ import("remark-frontmatter"),
125
171
  import("remark-gfm"),
126
172
  import("remark-math"),
173
+ import("remark-breaks"),
127
174
  import("remark-rehype"),
128
175
  import("rehype-katex"),
129
176
  import("rehype-prism-plus"),
130
177
  import("rehype-sanitize"),
131
178
  import("rehype-stringify")
132
179
  ]);
133
- return unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkRehype, { allowDangerousHtml: false }).use(rehypeKatex).use(rehypePrismPlus, { ignoreMissing: true }).use(rehypeSanitize, sanitizeSchema).use(rehypeStringify);
180
+ return unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(renderFrontMatter).use(remarkGfm).use(remarkMath).use(remarkBreaks).use(remarkRehype, { allowDangerousHtml: false }).use(rehypeKatex).use(rehypePrismPlus, { ignoreMissing: true }).use(addColorChips).use(rehypeSanitize, sanitizeSchema).use(rehypeStringify);
134
181
  }
135
182
  function getProcessor() {
136
183
  if (!processorPromise) {
@@ -418,6 +465,17 @@ var elementStyles = import_el_base.css`
418
465
  flex-shrink: 0;
419
466
  }
420
467
 
468
+ .preview-body .color-chip {
469
+ display: inline-block;
470
+ width: 0.75em;
471
+ height: 0.75em;
472
+ margin-left: 0.35em;
473
+ vertical-align: -0.05em;
474
+ background-color: var(--color-chip);
475
+ border: 1px solid var(--md-border);
476
+ border-radius: 0.2em;
477
+ }
478
+
421
479
  /* ── Preview skeleton (shown while render pipeline loads) ──────────── */
422
480
  .preview-skeleton {
423
481
  display: flex;
@@ -1148,6 +1206,16 @@ class ElDmMarkdownInput extends import_el_base2.BaseElement {
1148
1206
  this.#internals = this.attachInternals();
1149
1207
  this.attachStyles([elementStyles, markdownBodySheet]);
1150
1208
  }
1209
+ #resolveValue(fallback = "") {
1210
+ const value = this.value;
1211
+ if (typeof value === "string") {
1212
+ return value;
1213
+ }
1214
+ if (Array.isArray(value) && value.every((part) => typeof part === "string" || typeof part === "number")) {
1215
+ return value.join("");
1216
+ }
1217
+ return this.getAttribute("value") ?? fallback;
1218
+ }
1151
1219
  connectedCallback() {
1152
1220
  super.connectedCallback();
1153
1221
  }
@@ -1164,7 +1232,7 @@ class ElDmMarkdownInput extends import_el_base2.BaseElement {
1164
1232
  this.#cacheDOMRefs();
1165
1233
  this.#attachEventHandlers();
1166
1234
  this.#initHighlight();
1167
- const initVal = this.value ?? "";
1235
+ const initVal = this.#resolveValue();
1168
1236
  if (this.#textarea) {
1169
1237
  this.#textarea.value = initVal;
1170
1238
  this.#syncFormValue();
@@ -1188,7 +1256,7 @@ class ElDmMarkdownInput extends import_el_base2.BaseElement {
1188
1256
  if (attachBtn) {
1189
1257
  attachBtn.disabled = ta.disabled || ta.readOnly;
1190
1258
  }
1191
- const propVal = this.value ?? "";
1259
+ const propVal = this.#resolveValue(ta.value);
1192
1260
  if (propVal !== ta.value) {
1193
1261
  ta.value = propVal;
1194
1262
  this.#syncFormValue();
@@ -1901,5 +1969,5 @@ if (!customElements.get("el-dm-markdown-input")) {
1901
1969
  customElements.define("el-dm-markdown-input", ElDmMarkdownInput);
1902
1970
  }
1903
1971
 
1904
- //# debugId=FAB471DFCCCB51A064756E2164756E21
1972
+ //# debugId=D0AA0C616627E36464756E2164756E21
1905
1973
  //# sourceMappingURL=register.js.map