UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

104 lines (103 loc) 4.3 kB
"use client"; import { unreachable as k } from "../../devlop/lib/default.js"; import { jsxs as b, jsx as O, Fragment as P } from "react/jsx-runtime"; import "react"; import { unified as v } from "../../unified/lib/index.js"; import E from "../../remark-parse/lib/index.js"; import T from "../../remark-rehype/lib/index.js"; import { VFile as x } from "../../vfile/lib/index.js"; import { visit as N } from "../../unist-util-visit/lib/index.js"; import { toJsxRuntime as R } from "../../hast-util-to-jsx-runtime/lib/index.js"; import { urlAttributes as a } from "../../html-url-attributes/lib/index.js"; const j = "https://github.com/remarkjs/react-markdown/blob/main/changelog.md", f = [], u = { allowDangerousHtml: !0 }, H = /^(https?|ircs?|mailto|xmpp)$/i, S = [ { from: "astPlugins", id: "remove-buggy-html-in-markdown-parser" }, { from: "allowDangerousHtml", id: "remove-buggy-html-in-markdown-parser" }, { from: "allowNode", id: "replace-allownode-allowedtypes-and-disallowedtypes", to: "allowElement" }, { from: "allowedTypes", id: "replace-allownode-allowedtypes-and-disallowedtypes", to: "allowedElements" }, { from: "className", id: "remove-classname" }, { from: "disallowedTypes", id: "replace-allownode-allowedtypes-and-disallowedtypes", to: "disallowedElements" }, { from: "escapeHtml", id: "remove-buggy-html-in-markdown-parser" }, { from: "includeElementIndex", id: "#remove-includeelementindex" }, { from: "includeNodeIndex", id: "change-includenodeindex-to-includeelementindex" }, { from: "linkTarget", id: "remove-linktarget" }, { from: "plugins", id: "change-plugins-to-remarkplugins", to: "remarkPlugins" }, { from: "rawSourcePos", id: "#remove-rawsourcepos" }, { from: "renderers", id: "change-renderers-to-components", to: "components" }, { from: "source", id: "change-source-to-children", to: "children" }, { from: "sourcePos", id: "#remove-sourcepos" }, { from: "transformImageUri", id: "#add-urltransform", to: "urlTransform" }, { from: "transformLinkUri", id: "#add-urltransform", to: "urlTransform" } ]; function C(r) { const e = D(r), t = I(r); return U(e.runSync(e.parse(t), t), r); } function D(r) { const e = r.rehypePlugins || f, t = r.remarkPlugins || f, n = r.remarkRehypeOptions ? { ...r.remarkRehypeOptions, ...u } : u; return v().use(E).use(t).use(T, n).use(e); } function I(r) { const e = r.children || "", t = new x(); return typeof e == "string" && (t.value = e), t; } function U(r, e) { const t = e.allowedElements, n = e.allowElement, i = e.components, c = e.disallowedElements, p = e.skipHtml, w = e.unwrapDisallowed, g = e.urlTransform || F; for (const o of S) Object.hasOwn(e, o.from) && k( "Unexpected `" + o.from + "` prop, " + (o.to ? "use `" + o.to + "` instead" : "remove it") + " (see <" + j + "#" + o.id + "> for more info)" ); return N(r, h), R(r, { Fragment: P, components: i, ignoreInvalidStyle: !0, jsx: O, jsxs: b, passKeys: !0, passNode: !0 }); function h(o, l, m) { if (o.type === "raw" && m && typeof l == "number") return p ? m.children.splice(l, 1) : m.children[l] = { type: "text", value: o.value }, l; if (o.type === "element") { let s; for (s in a) if (Object.hasOwn(a, s) && Object.hasOwn(o.properties, s)) { const y = o.properties[s], d = a[s]; (d === null || d.includes(o.tagName)) && (o.properties[s] = g(String(y || ""), s, o)); } } if (o.type === "element") { let s = t ? !t.includes(o.tagName) : c ? c.includes(o.tagName) : !1; if (!s && n && typeof l == "number" && (s = !n(o, l, m)), s && m && typeof l == "number") return w && o.children ? m.children.splice(l, 1, ...o.children) : m.children.splice(l, 1), l; } } } function F(r) { const e = r.indexOf(":"), t = r.indexOf("?"), n = r.indexOf("#"), i = r.indexOf("/"); return ( // If there is no protocol, it’s relative. e === -1 || // If the first colon is after a `?`, `#`, or `/`, it’s not a protocol. i !== -1 && e > i || t !== -1 && e > t || n !== -1 && e > n || // It is a protocol, it should be allowed. H.test(r.slice(0, e)) ? r : "" ); } export { C as Markdown, F as defaultUrlTransform };