@anoki/fse-ui
Version:
FSE UI components library
261 lines (260 loc) • 8.09 kB
JavaScript
import { __require as g } from "./index.es688.js";
import { __require as O } from "./index.es710.js";
import { __require as S } from "./index.es701.js";
import { __require as I } from "./index.es703.js";
var d, m;
function _() {
if (m) return d;
m = 1;
let p = g(), y = O(), x = S(), { isClean: a, my: w } = I();
function c(u, e) {
let t = new u.constructor();
for (let n in u) {
if (!Object.prototype.hasOwnProperty.call(u, n) || n === "proxyCache") continue;
let i = u[n], r = typeof i;
n === "parent" && r === "object" ? e && (t[n] = e) : n === "source" ? t[n] = i : Array.isArray(i) ? t[n] = i.map((s) => c(s, t)) : (r === "object" && i !== null && (i = c(i)), t[n] = i);
}
return t;
}
function l(u, e) {
if (e && typeof e.offset < "u")
return e.offset;
let t = 1, n = 1, i = 0;
for (let r = 0; r < u.length; r++) {
if (n === e.line && t === e.column) {
i = r;
break;
}
u[r] === `
` ? (t = 1, n += 1) : t += 1;
}
return i;
}
class h {
get proxyOf() {
return this;
}
constructor(e = {}) {
this.raws = {}, this[a] = !1, this[w] = !0;
for (let t in e)
if (t === "nodes") {
this.nodes = [];
for (let n of e[t])
typeof n.clone == "function" ? this.append(n.clone()) : this.append(n);
} else
this[t] = e[t];
}
addToError(e) {
if (e.postcssNode = this, e.stack && this.source && /\n\s{4}at /.test(e.stack)) {
let t = this.source;
e.stack = e.stack.replace(
/\n\s{4}at /,
`$&${t.input.from}:${t.start.line}:${t.start.column}$&`
);
}
return e;
}
after(e) {
return this.parent.insertAfter(this, e), this;
}
assign(e = {}) {
for (let t in e)
this[t] = e[t];
return this;
}
before(e) {
return this.parent.insertBefore(this, e), this;
}
cleanRaws(e) {
delete this.raws.before, delete this.raws.after, e || delete this.raws.between;
}
clone(e = {}) {
let t = c(this);
for (let n in e)
t[n] = e[n];
return t;
}
cloneAfter(e = {}) {
let t = this.clone(e);
return this.parent.insertAfter(this, t), t;
}
cloneBefore(e = {}) {
let t = this.clone(e);
return this.parent.insertBefore(this, t), t;
}
error(e, t = {}) {
if (this.source) {
let { end: n, start: i } = this.rangeBy(t);
return this.source.input.error(
e,
{ column: i.column, line: i.line },
{ column: n.column, line: n.line },
t
);
}
return new p(e);
}
getProxyProcessor() {
return {
get(e, t) {
return t === "proxyOf" ? e : t === "root" ? () => e.root().toProxy() : e[t];
},
set(e, t, n) {
return e[t] === n || (e[t] = n, (t === "prop" || t === "value" || t === "name" || t === "params" || t === "important" || /* c8 ignore next */
t === "text") && e.markDirty()), !0;
}
};
}
/* c8 ignore next 3 */
markClean() {
this[a] = !0;
}
markDirty() {
if (this[a]) {
this[a] = !1;
let e = this;
for (; e = e.parent; )
e[a] = !1;
}
}
next() {
if (!this.parent) return;
let e = this.parent.index(this);
return this.parent.nodes[e + 1];
}
positionBy(e = {}) {
let t = this.source.start;
if (e.index)
t = this.positionInside(e.index);
else if (e.word) {
let n = "document" in this.source.input ? this.source.input.document : this.source.input.css, r = n.slice(
l(n, this.source.start),
l(n, this.source.end)
).indexOf(e.word);
r !== -1 && (t = this.positionInside(r));
}
return t;
}
positionInside(e) {
let t = this.source.start.column, n = this.source.start.line, i = "document" in this.source.input ? this.source.input.document : this.source.input.css, r = l(i, this.source.start), s = r + e;
for (let o = r; o < s; o++)
i[o] === `
` ? (t = 1, n += 1) : t += 1;
return { column: t, line: n, offset: s };
}
prev() {
if (!this.parent) return;
let e = this.parent.index(this);
return this.parent.nodes[e - 1];
}
rangeBy(e = {}) {
let t = "document" in this.source.input ? this.source.input.document : this.source.input.css, n = {
column: this.source.start.column,
line: this.source.start.line,
offset: l(t, this.source.start)
}, i = this.source.end ? {
column: this.source.end.column + 1,
line: this.source.end.line,
offset: typeof this.source.end.offset == "number" ? (
// `source.end.offset` is exclusive, so we don't need to add 1
this.source.end.offset
) : (
// Since line/column in this.source.end is inclusive,
// the `sourceOffset(... , this.source.end)` returns an inclusive offset.
// So, we add 1 to convert it to exclusive.
l(t, this.source.end) + 1
)
} : {
column: n.column + 1,
line: n.line,
offset: n.offset + 1
};
if (e.word) {
let s = t.slice(
l(t, this.source.start),
l(t, this.source.end)
).indexOf(e.word);
s !== -1 && (n = this.positionInside(s), i = this.positionInside(s + e.word.length));
} else
e.start ? n = {
column: e.start.column,
line: e.start.line,
offset: l(t, e.start)
} : e.index && (n = this.positionInside(e.index)), e.end ? i = {
column: e.end.column,
line: e.end.line,
offset: l(t, e.end)
} : typeof e.endIndex == "number" ? i = this.positionInside(e.endIndex) : e.index && (i = this.positionInside(e.index + 1));
return (i.line < n.line || i.line === n.line && i.column <= n.column) && (i = {
column: n.column + 1,
line: n.line,
offset: n.offset + 1
}), { end: i, start: n };
}
raw(e, t) {
return new y().raw(this, e, t);
}
remove() {
return this.parent && this.parent.removeChild(this), this.parent = void 0, this;
}
replaceWith(...e) {
if (this.parent) {
let t = this, n = !1;
for (let i of e)
i === this ? n = !0 : n ? (this.parent.insertAfter(t, i), t = i) : this.parent.insertBefore(t, i);
n || this.remove();
}
return this;
}
root() {
let e = this;
for (; e.parent && e.parent.type !== "document"; )
e = e.parent;
return e;
}
toJSON(e, t) {
let n = {}, i = t == null;
t = t || /* @__PURE__ */ new Map();
let r = 0;
for (let s in this) {
if (!Object.prototype.hasOwnProperty.call(this, s) || s === "parent" || s === "proxyCache") continue;
let o = this[s];
if (Array.isArray(o))
n[s] = o.map((f) => typeof f == "object" && f.toJSON ? f.toJSON(null, t) : f);
else if (typeof o == "object" && o.toJSON)
n[s] = o.toJSON(null, t);
else if (s === "source") {
if (o == null) continue;
let f = t.get(o.input);
f == null && (f = r, t.set(o.input, r), r++), n[s] = {
end: o.end,
inputId: f,
start: o.start
};
} else
n[s] = o;
}
return i && (n.inputs = [...t.keys()].map((s) => s.toJSON())), n;
}
toProxy() {
return this.proxyCache || (this.proxyCache = new Proxy(this, this.getProxyProcessor())), this.proxyCache;
}
toString(e = x) {
e.stringify && (e = e.stringify);
let t = "";
return e(this, (n) => {
t += n;
}), t;
}
warn(e, t, n = {}) {
let i = { node: this };
for (let r in n) i[r] = n[r];
return e.warn(t, i);
}
}
return d = h, h.default = h, d;
}
export {
_ as __require
};
//# sourceMappingURL=index.es695.js.map