UNPKG

laif-ds

Version:

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

147 lines (146 loc) 4.08 kB
"use client"; import { ok as x } from "../../devlop/lib/default.js"; import { svg as h, html as T } from "../../property-information/index.js"; import { webNamespaces as b } from "../../web-namespaces/index.js"; import { s as L, h as w } from "../../hastscript/lib/index.js"; import { find as C } from "../../property-information/lib/find.js"; import { location as N } from "../../vfile-location/lib/index.js"; const v = {}.hasOwnProperty, k = Object.prototype; function U(t, n) { const e = n || {}; return m( { file: e.file || void 0, location: !1, schema: e.space === "svg" ? h : T, verbose: e.verbose || !1 }, t ); } function m(t, n) { let e; switch (n.nodeName) { case "#comment": { const o = ( /** @type {DefaultTreeAdapterMap['commentNode']} */ n ); return e = { type: "comment", value: o.data }, l(t, o, e), e; } case "#document": case "#document-fragment": { const o = ( /** @type {DefaultTreeAdapterMap['document'] | DefaultTreeAdapterMap['documentFragment']} */ n ), c = "mode" in o ? o.mode === "quirks" || o.mode === "limited-quirks" : !1; if (e = { type: "root", children: y(t, n.childNodes), data: { quirksMode: c } }, t.file && t.location) { const a = String(t.file), s = N(a), i = s.toPoint(0), r = s.toPoint(a.length); e.position = { start: i, end: r }; } return e; } case "#documentType": { const o = ( /** @type {DefaultTreeAdapterMap['documentType']} */ n ); return e = { type: "doctype" }, l(t, o, e), e; } case "#text": { const o = ( /** @type {DefaultTreeAdapterMap['textNode']} */ n ); return e = { type: "text", value: o.value }, l(t, o, e), e; } // Element. default: return e = O( t, /** @type {DefaultTreeAdapterMap['element']} */ n ), e; } } function y(t, n) { let e = -1; const o = []; for (; ++e < n.length; ) { const c = ( /** @type {RootContent} */ m(t, n[e]) ); o.push(c); } return o; } function O(t, n) { const e = t.schema; t.schema = n.namespaceURI === b.svg ? h : T; let o = -1; const c = {}; for (; ++o < n.attrs.length; ) { const i = n.attrs[o], r = (i.prefix ? i.prefix + ":" : "") + i.name; v.call(k, r) || (c[r] = i.value); } const s = (t.schema.space === "svg" ? L : w)(n.tagName, c, y(t, n.childNodes)); if (l(t, n, s), s.tagName === "template") { const i = ( /** @type {DefaultTreeAdapterMap['template']} */ n ), r = i.sourceCodeLocation, f = r && r.startTag && u(r.startTag), p = r && r.endTag && u(r.endTag), d = ( /** @type {Root} */ m(t, i.content) ); f && p && t.file && (d.position = { start: f.end, end: p.start }), s.content = d; } return t.schema = e, s; } function l(t, n, e) { if ("sourceCodeLocation" in n && n.sourceCodeLocation && t.file) { const o = P(t, e, n.sourceCodeLocation); o && (t.location = !0, e.position = o); } } function P(t, n, e) { const o = u(e); if (n.type === "element") { const c = n.children[n.children.length - 1]; if (o && !e.endTag && c && c.position && c.position.end && (o.end = Object.assign({}, c.position.end)), t.verbose) { const a = {}; let s; if (e.attrs) for (s in e.attrs) v.call(e.attrs, s) && (a[C(t.schema, s).property] = u( e.attrs[s] )); x(e.startTag); const i = u(e.startTag), r = e.endTag ? u(e.endTag) : void 0, f = { opening: i }; r && (f.closing = r), f.properties = a, n.data = { position: f }; } } return o; } function u(t) { const n = g({ line: t.startLine, column: t.startCol, offset: t.startOffset }), e = g({ line: t.endLine, column: t.endCol, offset: t.endOffset }); return n || e ? { start: n, end: e } : void 0; } function g(t) { return t.line && t.column ? t : void 0; } export { U as fromParse5 };