@anoki/fse-ui
Version:
FSE UI components library
141 lines (140 loc) • 4.96 kB
JavaScript
import { __require as R } from "./index.es707.js";
import g from "./index.es705.js";
import { __require as _ } from "./index.es688.js";
import { __require as P } from "./index.es706.js";
var L, q;
function $() {
if (q) return L;
q = 1;
let { nanoid: y } = /* @__PURE__ */ R(), { isAbsolute: C, resolve: S } = g, { SourceMapConsumer: O, SourceMapGenerator: T } = g, { fileURLToPath: b, pathToFileURL: d } = g, v = _(), A = P(), x = g, I = Symbol("lineToIndexCache"), M = !!(O && T), w = !!(S && C);
function F(a) {
if (a[I]) return a[I];
let i = a.css.split(`
`), e = new Array(i.length), t = 0;
for (let r = 0, o = i.length; r < o; r++)
e[r] = t, t += i[r].length + 1;
return a[I] = e, e;
}
class p {
get from() {
return this.file || this.id;
}
constructor(i, e = {}) {
if (i === null || typeof i > "u" || typeof i == "object" && !i.toString)
throw new Error(`PostCSS received ${i} instead of CSS string`);
if (this.css = i.toString(), this.css[0] === "\uFEFF" || this.css[0] === "" ? (this.hasBOM = !0, this.css = this.css.slice(1)) : this.hasBOM = !1, this.document = this.css, e.document && (this.document = e.document.toString()), e.from && (!w || /^\w+:\/\//.test(e.from) || C(e.from) ? this.file = e.from : this.file = S(e.from)), w && M) {
let t = new A(this.css, e);
if (t.text) {
this.map = t;
let r = t.consumer().file;
!this.file && r && (this.file = this.mapResolve(r));
}
}
this.file || (this.id = "<input css " + y(6) + ">"), this.map && (this.map.file = this.from);
}
error(i, e, t, r = {}) {
let o, n, f, s, u;
if (e && typeof e == "object") {
let h = e, m = t;
if (typeof h.offset == "number") {
s = h.offset;
let c = this.fromOffset(s);
e = c.line, t = c.col;
} else
e = h.line, t = h.column, s = this.fromLineAndColumn(e, t);
if (typeof m.offset == "number") {
f = m.offset;
let c = this.fromOffset(f);
n = c.line, o = c.col;
} else
n = m.line, o = m.column, f = this.fromLineAndColumn(m.line, m.column);
} else if (t)
s = this.fromLineAndColumn(e, t);
else {
s = e;
let h = this.fromOffset(s);
e = h.line, t = h.col;
}
let l = this.origin(e, t, n, o);
return l ? u = new v(
i,
l.endLine === void 0 ? l.line : { column: l.column, line: l.line },
l.endLine === void 0 ? l.column : { column: l.endColumn, line: l.endLine },
l.source,
l.file,
r.plugin
) : u = new v(
i,
n === void 0 ? e : { column: t, line: e },
n === void 0 ? t : { column: o, line: n },
this.css,
this.file,
r.plugin
), u.input = { column: t, endColumn: o, endLine: n, endOffset: f, line: e, offset: s, source: this.css }, this.file && (d && (u.input.url = d(this.file).toString()), u.input.file = this.file), u;
}
fromLineAndColumn(i, e) {
return F(this)[i - 1] + e - 1;
}
fromOffset(i) {
let e = F(this), t = e[e.length - 1], r = 0;
if (i >= t)
r = e.length - 1;
else {
let o = e.length - 2, n;
for (; r < o; )
if (n = r + (o - r >> 1), i < e[n])
o = n - 1;
else if (i >= e[n + 1])
r = n + 1;
else {
r = n;
break;
}
}
return {
col: i - e[r] + 1,
line: r + 1
};
}
mapResolve(i) {
return /^\w+:\/\//.test(i) ? i : S(this.map.consumer().sourceRoot || this.map.root || ".", i);
}
origin(i, e, t, r) {
if (!this.map) return !1;
let o = this.map.consumer(), n = o.originalPositionFor({ column: e, line: i });
if (!n.source) return !1;
let f;
typeof t == "number" && (f = o.originalPositionFor({ column: r, line: t }));
let s;
C(n.source) ? s = d(n.source) : s = new URL(
n.source,
this.map.consumer().sourceRoot || d(this.map.mapFile)
);
let u = {
column: n.column,
endColumn: f && f.column,
endLine: f && f.line,
line: n.line,
url: s.toString()
};
if (s.protocol === "file:")
if (b)
u.file = b(s);
else
throw new Error("file: protocol is not available in this PostCSS build");
let l = o.sourceContentFor(n.source);
return l && (u.source = l), u;
}
toJSON() {
let i = {};
for (let e of ["hasBOM", "css", "file", "id"])
this[e] != null && (i[e] = this[e]);
return this.map && (i.map = { ...this.map }, i.map.consumerCache && (i.map.consumerCache = void 0)), i;
}
}
return L = p, p.default = p, x && x.registerInput && x.registerInput(p), L;
}
export {
$ as __require
};
//# sourceMappingURL=index.es692.js.map