laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
304 lines (303 loc) • 9.17 kB
JavaScript
"use client";
import { stringify as w } from "../../comma-separated-tokens/index.js";
import { ok as u } from "../../devlop/lib/default.js";
import { svg as m, html as C } from "../../property-information/index.js";
import { stringify as N } from "../../space-separated-tokens/index.js";
import S from "../../../_virtual/index4.js";
import { whitespace as j } from "../../hast-util-whitespace/lib/index.js";
import { name as x } from "../../estree-util-is-identifier-name/lib/index.js";
import { VFileMessage as h } from "../../vfile-message/lib/index.js";
import { find as A } from "../../property-information/lib/find.js";
import { hastToReact as T } from "../../property-information/lib/hast-to-react.js";
import { pointStart as F } from "../../unist-util-position/lib/index.js";
const f = {}.hasOwnProperty, P = /* @__PURE__ */ new Map(), J = /[A-Z]/g, I = /* @__PURE__ */ new Set(["table", "tbody", "thead", "tfoot", "tr"]), L = /* @__PURE__ */ new Set(["td", "th"]), g = "https://github.com/syntax-tree/hast-util-to-jsx-runtime";
function ae(t, e) {
if (!e || e.Fragment === void 0)
throw new TypeError("Expected `Fragment` in options");
const r = e.filePath || void 0;
let n;
if (e.development) {
if (typeof e.jsxDEV != "function")
throw new TypeError(
"Expected `jsxDEV` in options when `development: true`"
);
n = R(r, e.jsxDEV);
} else {
if (typeof e.jsx != "function")
throw new TypeError("Expected `jsx` in production options");
if (typeof e.jsxs != "function")
throw new TypeError("Expected `jsxs` in production options");
n = B(r, e.jsx, e.jsxs);
}
const s = {
Fragment: e.Fragment,
ancestors: [],
components: e.components || {},
create: n,
elementAttributeNameCase: e.elementAttributeNameCase || "react",
evaluater: e.createEvaluater ? e.createEvaluater() : void 0,
filePath: r,
ignoreInvalidStyle: e.ignoreInvalidStyle || !1,
passKeys: e.passKeys !== !1,
passNode: e.passNode || !1,
schema: e.space === "svg" ? m : C,
stylePropertyNameCase: e.stylePropertyNameCase || "dom",
tableCellAlignToStyle: e.tableCellAlignToStyle !== !1
}, i = E(s, t, void 0);
return i && typeof i != "string" ? i : s.create(
t,
s.Fragment,
{ children: i || void 0 },
void 0
);
}
function E(t, e, r) {
if (e.type === "element")
return M(t, e, r);
if (e.type === "mdxFlowExpression" || e.type === "mdxTextExpression")
return D(t, e);
if (e.type === "mdxJsxFlowElement" || e.type === "mdxJsxTextElement")
return K(t, e, r);
if (e.type === "mdxjsEsm")
return V(t, e);
if (e.type === "root")
return O(t, e, r);
if (e.type === "text")
return _(t, e);
}
function M(t, e, r) {
const n = t.schema;
let s = n;
e.tagName.toLowerCase() === "svg" && n.space === "html" && (s = m, t.schema = s), t.ancestors.push(e);
const i = b(t, e.tagName, !1), a = z(t, e);
let o = d(t, e);
return I.has(e.tagName) && (o = o.filter(function(l) {
return typeof l == "string" ? !j(l) : !0;
})), v(t, a, i, e), y(a, o), t.ancestors.pop(), t.schema = n, t.create(e, i, a, r);
}
function D(t, e) {
if (e.data && e.data.estree && t.evaluater) {
const n = e.data.estree.body[0];
return u(n.type === "ExpressionStatement"), /** @type {Child | undefined} */
t.evaluater.evaluateExpression(n.expression);
}
p(t, e.position);
}
function V(t, e) {
if (e.data && e.data.estree && t.evaluater)
return (
/** @type {Child | undefined} */
t.evaluater.evaluateProgram(e.data.estree)
);
p(t, e.position);
}
function K(t, e, r) {
const n = t.schema;
let s = n;
e.name === "svg" && n.space === "html" && (s = m, t.schema = s), t.ancestors.push(e);
const i = e.name === null ? t.Fragment : b(t, e.name, !0), a = X(t, e), o = d(t, e);
return v(t, a, i, e), y(a, o), t.ancestors.pop(), t.schema = n, t.create(e, i, a, r);
}
function O(t, e, r) {
const n = {};
return y(n, d(t, e)), t.create(e, t.Fragment, n, r);
}
function _(t, e) {
return e.value;
}
function v(t, e, r, n) {
typeof r != "string" && r !== t.Fragment && t.passNode && (e.node = n);
}
function y(t, e) {
if (e.length > 0) {
const r = e.length > 1 ? e : e[0];
r && (t.children = r);
}
}
function B(t, e, r) {
return n;
function n(s, i, a, o) {
const c = Array.isArray(a.children) ? r : e;
return o ? c(i, a, o) : c(i, a);
}
}
function R(t, e) {
return r;
function r(n, s, i, a) {
const o = Array.isArray(i.children), l = F(n);
return e(
s,
i,
a,
o,
{
columnNumber: l ? l.column - 1 : void 0,
fileName: t,
lineNumber: l ? l.line : void 0
},
void 0
);
}
}
function z(t, e) {
const r = {};
let n, s;
for (s in e.properties)
if (s !== "children" && f.call(e.properties, s)) {
const i = Z(t, s, e.properties[s]);
if (i) {
const [a, o] = i;
t.tableCellAlignToStyle && a === "align" && typeof o == "string" && L.has(e.tagName) ? n = o : r[a] = o;
}
}
if (n) {
const i = (
/** @type {Style} */
r.style || (r.style = {})
);
i[t.stylePropertyNameCase === "css" ? "text-align" : "textAlign"] = n;
}
return r;
}
function X(t, e) {
const r = {};
for (const n of e.attributes)
if (n.type === "mdxJsxExpressionAttribute")
if (n.data && n.data.estree && t.evaluater) {
const i = n.data.estree.body[0];
u(i.type === "ExpressionStatement");
const a = i.expression;
u(a.type === "ObjectExpression");
const o = a.properties[0];
u(o.type === "SpreadElement"), Object.assign(
r,
t.evaluater.evaluateExpression(o.argument)
);
} else
p(t, e.position);
else {
const s = n.name;
let i;
if (n.value && typeof n.value == "object")
if (n.value.data && n.value.data.estree && t.evaluater) {
const o = n.value.data.estree.body[0];
u(o.type === "ExpressionStatement"), i = t.evaluater.evaluateExpression(o.expression);
} else
p(t, e.position);
else
i = n.value === null ? !0 : n.value;
r[s] = /** @type {Props[keyof Props]} */
i;
}
return r;
}
function d(t, e) {
const r = [];
let n = -1;
const s = t.passKeys ? /* @__PURE__ */ new Map() : P;
for (; ++n < e.children.length; ) {
const i = e.children[n];
let a;
if (t.passKeys) {
const l = i.type === "element" ? i.tagName : i.type === "mdxJsxFlowElement" || i.type === "mdxJsxTextElement" ? i.name : void 0;
if (l) {
const c = s.get(l) || 0;
a = l + "-" + c, s.set(l, c + 1);
}
}
const o = E(t, i, a);
o !== void 0 && r.push(o);
}
return r;
}
function Z(t, e, r) {
const n = A(t.schema, e);
if (!(r == null || typeof r == "number" && Number.isNaN(r))) {
if (Array.isArray(r) && (r = n.commaSeparated ? w(r) : N(r)), n.property === "style") {
let s = typeof r == "object" ? r : k(t, String(r));
return t.stylePropertyNameCase === "css" && (s = q(s)), ["style", s];
}
return [
t.elementAttributeNameCase === "react" && n.space ? T[n.property] || n.property : n.attribute,
r
];
}
}
function k(t, e) {
try {
return S(e, { reactCompat: !0 });
} catch (r) {
if (t.ignoreInvalidStyle)
return {};
const n = (
/** @type {Error} */
r
), s = new h("Cannot parse `style` attribute", {
ancestors: t.ancestors,
cause: n,
ruleId: "style",
source: "hast-util-to-jsx-runtime"
});
throw s.file = t.filePath || void 0, s.url = g + "#cannot-parse-style-attribute", s;
}
}
function b(t, e, r) {
let n;
if (!r)
n = { type: "Literal", value: e };
else if (e.includes(".")) {
const s = e.split(".");
let i = -1, a;
for (; ++i < s.length; ) {
const o = x(s[i]) ? { type: "Identifier", name: s[i] } : { type: "Literal", value: s[i] };
a = a ? {
type: "MemberExpression",
object: a,
property: o,
computed: !!(i && o.type === "Literal"),
optional: !1
} : o;
}
n = a;
} else
n = x(e) && !/^[a-z]/.test(e) ? { type: "Identifier", name: e } : { type: "Literal", value: e };
if (n.type === "Literal") {
const s = (
/** @type {string | number} */
n.value
);
return f.call(t.components, s) ? t.components[s] : s;
}
if (t.evaluater)
return t.evaluater.evaluateExpression(n);
p(t);
}
function p(t, e) {
const r = new h(
"Cannot handle MDX estrees without `createEvaluater`",
{
ancestors: t.ancestors,
place: e,
ruleId: "mdx-estree",
source: "hast-util-to-jsx-runtime"
}
);
throw r.file = t.filePath || void 0, r.url = g + "#cannot-handle-mdx-estrees-without-createevaluater", r;
}
function q(t) {
const e = {};
let r;
for (r in t)
f.call(t, r) && (e[G(r)] = t[r]);
return e;
}
function G(t) {
let e = t.replace(J, H);
return e.slice(0, 3) === "ms-" && (e = "-" + e), e;
}
function H(t) {
return "-" + t.toLowerCase();
}
export {
ae as toJsxRuntime
};