@anoki/fse-ui
Version:
FSE UI components library
345 lines (344 loc) • 23.8 kB
JavaScript
import { __exports as m } from "./index.es717.js";
import { __require as g } from "./index.es714.js";
var p;
function A() {
return p ? m : (p = 1, (function(c) {
Object.defineProperty(c, "__esModule", { value: !0 }), c.QuoteType = void 0;
var h = /* @__PURE__ */ g(), s;
(function(t) {
t[t.Tab = 9] = "Tab", t[t.NewLine = 10] = "NewLine", t[t.FormFeed = 12] = "FormFeed", t[t.CarriageReturn = 13] = "CarriageReturn", t[t.Space = 32] = "Space", t[t.ExclamationMark = 33] = "ExclamationMark", t[t.Number = 35] = "Number", t[t.Amp = 38] = "Amp", t[t.SingleQuote = 39] = "SingleQuote", t[t.DoubleQuote = 34] = "DoubleQuote", t[t.Dash = 45] = "Dash", t[t.Slash = 47] = "Slash", t[t.Zero = 48] = "Zero", t[t.Nine = 57] = "Nine", t[t.Semi = 59] = "Semi", t[t.Lt = 60] = "Lt", t[t.Eq = 61] = "Eq", t[t.Gt = 62] = "Gt", t[t.Questionmark = 63] = "Questionmark", t[t.UpperA = 65] = "UpperA", t[t.LowerA = 97] = "LowerA", t[t.UpperF = 70] = "UpperF", t[t.LowerF = 102] = "LowerF", t[t.UpperZ = 90] = "UpperZ", t[t.LowerZ = 122] = "LowerZ", t[t.LowerX = 120] = "LowerX", t[t.OpeningSquareBracket = 91] = "OpeningSquareBracket";
})(s || (s = {}));
var i;
(function(t) {
t[t.Text = 1] = "Text", t[t.BeforeTagName = 2] = "BeforeTagName", t[t.InTagName = 3] = "InTagName", t[t.InSelfClosingTag = 4] = "InSelfClosingTag", t[t.BeforeClosingTagName = 5] = "BeforeClosingTagName", t[t.InClosingTagName = 6] = "InClosingTagName", t[t.AfterClosingTagName = 7] = "AfterClosingTagName", t[t.BeforeAttributeName = 8] = "BeforeAttributeName", t[t.InAttributeName = 9] = "InAttributeName", t[t.AfterAttributeName = 10] = "AfterAttributeName", t[t.BeforeAttributeValue = 11] = "BeforeAttributeValue", t[t.InAttributeValueDq = 12] = "InAttributeValueDq", t[t.InAttributeValueSq = 13] = "InAttributeValueSq", t[t.InAttributeValueNq = 14] = "InAttributeValueNq", t[t.BeforeDeclaration = 15] = "BeforeDeclaration", t[t.InDeclaration = 16] = "InDeclaration", t[t.InProcessingInstruction = 17] = "InProcessingInstruction", t[t.BeforeComment = 18] = "BeforeComment", t[t.CDATASequence = 19] = "CDATASequence", t[t.InSpecialComment = 20] = "InSpecialComment", t[t.InCommentLike = 21] = "InCommentLike", t[t.BeforeSpecialS = 22] = "BeforeSpecialS", t[t.SpecialStartSequence = 23] = "SpecialStartSequence", t[t.InSpecialTag = 24] = "InSpecialTag", t[t.BeforeEntity = 25] = "BeforeEntity", t[t.BeforeNumericEntity = 26] = "BeforeNumericEntity", t[t.InNamedEntity = 27] = "InNamedEntity", t[t.InNumericEntity = 28] = "InNumericEntity", t[t.InHexEntity = 29] = "InHexEntity";
})(i || (i = {}));
function o(t) {
return t === s.Space || t === s.NewLine || t === s.Tab || t === s.FormFeed || t === s.CarriageReturn;
}
function l(t) {
return t === s.Slash || t === s.Gt || o(t);
}
function x(t) {
return t >= s.Zero && t <= s.Nine;
}
function d(t) {
return t >= s.LowerA && t <= s.LowerZ || t >= s.UpperA && t <= s.UpperZ;
}
function I(t) {
return t >= s.UpperA && t <= s.UpperF || t >= s.LowerA && t <= s.LowerF;
}
var u;
(function(t) {
t[t.NoValue = 0] = "NoValue", t[t.Unquoted = 1] = "Unquoted", t[t.Single = 2] = "Single", t[t.Double = 3] = "Double";
})(u = c.QuoteType || (c.QuoteType = {}));
var a = {
Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
CdataEnd: new Uint8Array([93, 93, 62]),
CommentEnd: new Uint8Array([45, 45, 62]),
ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101])
// `</title`
}, y = (
/** @class */
(function() {
function t(e, n) {
var r = e.xmlMode, f = r === void 0 ? !1 : r, b = e.decodeEntities, S = b === void 0 ? !0 : b;
this.cbs = n, this.state = i.Text, this.buffer = "", this.sectionStart = 0, this.index = 0, this.baseState = i.Text, this.isSpecial = !1, this.running = !0, this.offset = 0, this.currentSequence = void 0, this.sequenceIndex = 0, this.trieIndex = 0, this.trieCurrent = 0, this.entityResult = 0, this.entityExcess = 0, this.xmlMode = f, this.decodeEntities = S, this.entityTrie = f ? h.xmlDecodeTree : h.htmlDecodeTree;
}
return t.prototype.reset = function() {
this.state = i.Text, this.buffer = "", this.sectionStart = 0, this.index = 0, this.baseState = i.Text, this.currentSequence = void 0, this.running = !0, this.offset = 0;
}, t.prototype.write = function(e) {
this.offset += this.buffer.length, this.buffer = e, this.parse();
}, t.prototype.end = function() {
this.running && this.finish();
}, t.prototype.pause = function() {
this.running = !1;
}, t.prototype.resume = function() {
this.running = !0, this.index < this.buffer.length + this.offset && this.parse();
}, t.prototype.getIndex = function() {
return this.index;
}, t.prototype.getSectionStart = function() {
return this.sectionStart;
}, t.prototype.stateText = function(e) {
e === s.Lt || !this.decodeEntities && this.fastForwardTo(s.Lt) ? (this.index > this.sectionStart && this.cbs.ontext(this.sectionStart, this.index), this.state = i.BeforeTagName, this.sectionStart = this.index) : this.decodeEntities && e === s.Amp && (this.state = i.BeforeEntity);
}, t.prototype.stateSpecialStartSequence = function(e) {
var n = this.sequenceIndex === this.currentSequence.length, r = n ? (
// If we are at the end of the sequence, make sure the tag name has ended
l(e)
) : (
// Otherwise, do a case-insensitive comparison
(e | 32) === this.currentSequence[this.sequenceIndex]
);
if (!r)
this.isSpecial = !1;
else if (!n) {
this.sequenceIndex++;
return;
}
this.sequenceIndex = 0, this.state = i.InTagName, this.stateInTagName(e);
}, t.prototype.stateInSpecialTag = function(e) {
if (this.sequenceIndex === this.currentSequence.length) {
if (e === s.Gt || o(e)) {
var n = this.index - this.currentSequence.length;
if (this.sectionStart < n) {
var r = this.index;
this.index = n, this.cbs.ontext(this.sectionStart, n), this.index = r;
}
this.isSpecial = !1, this.sectionStart = n + 2, this.stateInClosingTagName(e);
return;
}
this.sequenceIndex = 0;
}
(e | 32) === this.currentSequence[this.sequenceIndex] ? this.sequenceIndex += 1 : this.sequenceIndex === 0 ? this.currentSequence === a.TitleEnd ? this.decodeEntities && e === s.Amp && (this.state = i.BeforeEntity) : this.fastForwardTo(s.Lt) && (this.sequenceIndex = 1) : this.sequenceIndex = +(e === s.Lt);
}, t.prototype.stateCDATASequence = function(e) {
e === a.Cdata[this.sequenceIndex] ? ++this.sequenceIndex === a.Cdata.length && (this.state = i.InCommentLike, this.currentSequence = a.CdataEnd, this.sequenceIndex = 0, this.sectionStart = this.index + 1) : (this.sequenceIndex = 0, this.state = i.InDeclaration, this.stateInDeclaration(e));
}, t.prototype.fastForwardTo = function(e) {
for (; ++this.index < this.buffer.length + this.offset; )
if (this.buffer.charCodeAt(this.index - this.offset) === e)
return !0;
return this.index = this.buffer.length + this.offset - 1, !1;
}, t.prototype.stateInCommentLike = function(e) {
e === this.currentSequence[this.sequenceIndex] ? ++this.sequenceIndex === this.currentSequence.length && (this.currentSequence === a.CdataEnd ? this.cbs.oncdata(this.sectionStart, this.index, 2) : this.cbs.oncomment(this.sectionStart, this.index, 2), this.sequenceIndex = 0, this.sectionStart = this.index + 1, this.state = i.Text) : this.sequenceIndex === 0 ? this.fastForwardTo(this.currentSequence[0]) && (this.sequenceIndex = 1) : e !== this.currentSequence[this.sequenceIndex - 1] && (this.sequenceIndex = 0);
}, t.prototype.isTagStartChar = function(e) {
return this.xmlMode ? !l(e) : d(e);
}, t.prototype.startSpecial = function(e, n) {
this.isSpecial = !0, this.currentSequence = e, this.sequenceIndex = n, this.state = i.SpecialStartSequence;
}, t.prototype.stateBeforeTagName = function(e) {
if (e === s.ExclamationMark)
this.state = i.BeforeDeclaration, this.sectionStart = this.index + 1;
else if (e === s.Questionmark)
this.state = i.InProcessingInstruction, this.sectionStart = this.index + 1;
else if (this.isTagStartChar(e)) {
var n = e | 32;
this.sectionStart = this.index, !this.xmlMode && n === a.TitleEnd[2] ? this.startSpecial(a.TitleEnd, 3) : this.state = !this.xmlMode && n === a.ScriptEnd[2] ? i.BeforeSpecialS : i.InTagName;
} else e === s.Slash ? this.state = i.BeforeClosingTagName : (this.state = i.Text, this.stateText(e));
}, t.prototype.stateInTagName = function(e) {
l(e) && (this.cbs.onopentagname(this.sectionStart, this.index), this.sectionStart = -1, this.state = i.BeforeAttributeName, this.stateBeforeAttributeName(e));
}, t.prototype.stateBeforeClosingTagName = function(e) {
o(e) || (e === s.Gt ? this.state = i.Text : (this.state = this.isTagStartChar(e) ? i.InClosingTagName : i.InSpecialComment, this.sectionStart = this.index));
}, t.prototype.stateInClosingTagName = function(e) {
(e === s.Gt || o(e)) && (this.cbs.onclosetag(this.sectionStart, this.index), this.sectionStart = -1, this.state = i.AfterClosingTagName, this.stateAfterClosingTagName(e));
}, t.prototype.stateAfterClosingTagName = function(e) {
(e === s.Gt || this.fastForwardTo(s.Gt)) && (this.state = i.Text, this.baseState = i.Text, this.sectionStart = this.index + 1);
}, t.prototype.stateBeforeAttributeName = function(e) {
e === s.Gt ? (this.cbs.onopentagend(this.index), this.isSpecial ? (this.state = i.InSpecialTag, this.sequenceIndex = 0) : this.state = i.Text, this.baseState = this.state, this.sectionStart = this.index + 1) : e === s.Slash ? this.state = i.InSelfClosingTag : o(e) || (this.state = i.InAttributeName, this.sectionStart = this.index);
}, t.prototype.stateInSelfClosingTag = function(e) {
e === s.Gt ? (this.cbs.onselfclosingtag(this.index), this.state = i.Text, this.baseState = i.Text, this.sectionStart = this.index + 1, this.isSpecial = !1) : o(e) || (this.state = i.BeforeAttributeName, this.stateBeforeAttributeName(e));
}, t.prototype.stateInAttributeName = function(e) {
(e === s.Eq || l(e)) && (this.cbs.onattribname(this.sectionStart, this.index), this.sectionStart = -1, this.state = i.AfterAttributeName, this.stateAfterAttributeName(e));
}, t.prototype.stateAfterAttributeName = function(e) {
e === s.Eq ? this.state = i.BeforeAttributeValue : e === s.Slash || e === s.Gt ? (this.cbs.onattribend(u.NoValue, this.index), this.state = i.BeforeAttributeName, this.stateBeforeAttributeName(e)) : o(e) || (this.cbs.onattribend(u.NoValue, this.index), this.state = i.InAttributeName, this.sectionStart = this.index);
}, t.prototype.stateBeforeAttributeValue = function(e) {
e === s.DoubleQuote ? (this.state = i.InAttributeValueDq, this.sectionStart = this.index + 1) : e === s.SingleQuote ? (this.state = i.InAttributeValueSq, this.sectionStart = this.index + 1) : o(e) || (this.sectionStart = this.index, this.state = i.InAttributeValueNq, this.stateInAttributeValueNoQuotes(e));
}, t.prototype.handleInAttributeValue = function(e, n) {
e === n || !this.decodeEntities && this.fastForwardTo(n) ? (this.cbs.onattribdata(this.sectionStart, this.index), this.sectionStart = -1, this.cbs.onattribend(n === s.DoubleQuote ? u.Double : u.Single, this.index), this.state = i.BeforeAttributeName) : this.decodeEntities && e === s.Amp && (this.baseState = this.state, this.state = i.BeforeEntity);
}, t.prototype.stateInAttributeValueDoubleQuotes = function(e) {
this.handleInAttributeValue(e, s.DoubleQuote);
}, t.prototype.stateInAttributeValueSingleQuotes = function(e) {
this.handleInAttributeValue(e, s.SingleQuote);
}, t.prototype.stateInAttributeValueNoQuotes = function(e) {
o(e) || e === s.Gt ? (this.cbs.onattribdata(this.sectionStart, this.index), this.sectionStart = -1, this.cbs.onattribend(u.Unquoted, this.index), this.state = i.BeforeAttributeName, this.stateBeforeAttributeName(e)) : this.decodeEntities && e === s.Amp && (this.baseState = this.state, this.state = i.BeforeEntity);
}, t.prototype.stateBeforeDeclaration = function(e) {
e === s.OpeningSquareBracket ? (this.state = i.CDATASequence, this.sequenceIndex = 0) : this.state = e === s.Dash ? i.BeforeComment : i.InDeclaration;
}, t.prototype.stateInDeclaration = function(e) {
(e === s.Gt || this.fastForwardTo(s.Gt)) && (this.cbs.ondeclaration(this.sectionStart, this.index), this.state = i.Text, this.sectionStart = this.index + 1);
}, t.prototype.stateInProcessingInstruction = function(e) {
(e === s.Gt || this.fastForwardTo(s.Gt)) && (this.cbs.onprocessinginstruction(this.sectionStart, this.index), this.state = i.Text, this.sectionStart = this.index + 1);
}, t.prototype.stateBeforeComment = function(e) {
e === s.Dash ? (this.state = i.InCommentLike, this.currentSequence = a.CommentEnd, this.sequenceIndex = 2, this.sectionStart = this.index + 1) : this.state = i.InDeclaration;
}, t.prototype.stateInSpecialComment = function(e) {
(e === s.Gt || this.fastForwardTo(s.Gt)) && (this.cbs.oncomment(this.sectionStart, this.index, 0), this.state = i.Text, this.sectionStart = this.index + 1);
}, t.prototype.stateBeforeSpecialS = function(e) {
var n = e | 32;
n === a.ScriptEnd[3] ? this.startSpecial(a.ScriptEnd, 4) : n === a.StyleEnd[3] ? this.startSpecial(a.StyleEnd, 4) : (this.state = i.InTagName, this.stateInTagName(e));
}, t.prototype.stateBeforeEntity = function(e) {
this.entityExcess = 1, this.entityResult = 0, e === s.Number ? this.state = i.BeforeNumericEntity : e === s.Amp || (this.trieIndex = 0, this.trieCurrent = this.entityTrie[0], this.state = i.InNamedEntity, this.stateInNamedEntity(e));
}, t.prototype.stateInNamedEntity = function(e) {
if (this.entityExcess += 1, this.trieIndex = (0, h.determineBranch)(this.entityTrie, this.trieCurrent, this.trieIndex + 1, e), this.trieIndex < 0) {
this.emitNamedEntity(), this.index--;
return;
}
this.trieCurrent = this.entityTrie[this.trieIndex];
var n = this.trieCurrent & h.BinTrieFlags.VALUE_LENGTH;
if (n) {
var r = (n >> 14) - 1;
if (!this.allowLegacyEntity() && e !== s.Semi)
this.trieIndex += r;
else {
var f = this.index - this.entityExcess + 1;
f > this.sectionStart && this.emitPartial(this.sectionStart, f), this.entityResult = this.trieIndex, this.trieIndex += r, this.entityExcess = 0, this.sectionStart = this.index + 1, r === 0 && this.emitNamedEntity();
}
}
}, t.prototype.emitNamedEntity = function() {
if (this.state = this.baseState, this.entityResult !== 0) {
var e = (this.entityTrie[this.entityResult] & h.BinTrieFlags.VALUE_LENGTH) >> 14;
switch (e) {
case 1: {
this.emitCodePoint(this.entityTrie[this.entityResult] & ~h.BinTrieFlags.VALUE_LENGTH);
break;
}
case 2: {
this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
break;
}
case 3:
this.emitCodePoint(this.entityTrie[this.entityResult + 1]), this.emitCodePoint(this.entityTrie[this.entityResult + 2]);
}
}
}, t.prototype.stateBeforeNumericEntity = function(e) {
(e | 32) === s.LowerX ? (this.entityExcess++, this.state = i.InHexEntity) : (this.state = i.InNumericEntity, this.stateInNumericEntity(e));
}, t.prototype.emitNumericEntity = function(e) {
var n = this.index - this.entityExcess - 1, r = n + 2 + +(this.state === i.InHexEntity);
r !== this.index && (n > this.sectionStart && this.emitPartial(this.sectionStart, n), this.sectionStart = this.index + Number(e), this.emitCodePoint((0, h.replaceCodePoint)(this.entityResult))), this.state = this.baseState;
}, t.prototype.stateInNumericEntity = function(e) {
e === s.Semi ? this.emitNumericEntity(!0) : x(e) ? (this.entityResult = this.entityResult * 10 + (e - s.Zero), this.entityExcess++) : (this.allowLegacyEntity() ? this.emitNumericEntity(!1) : this.state = this.baseState, this.index--);
}, t.prototype.stateInHexEntity = function(e) {
e === s.Semi ? this.emitNumericEntity(!0) : x(e) ? (this.entityResult = this.entityResult * 16 + (e - s.Zero), this.entityExcess++) : I(e) ? (this.entityResult = this.entityResult * 16 + ((e | 32) - s.LowerA + 10), this.entityExcess++) : (this.allowLegacyEntity() ? this.emitNumericEntity(!1) : this.state = this.baseState, this.index--);
}, t.prototype.allowLegacyEntity = function() {
return !this.xmlMode && (this.baseState === i.Text || this.baseState === i.InSpecialTag);
}, t.prototype.cleanup = function() {
this.running && this.sectionStart !== this.index && (this.state === i.Text || this.state === i.InSpecialTag && this.sequenceIndex === 0 ? (this.cbs.ontext(this.sectionStart, this.index), this.sectionStart = this.index) : (this.state === i.InAttributeValueDq || this.state === i.InAttributeValueSq || this.state === i.InAttributeValueNq) && (this.cbs.onattribdata(this.sectionStart, this.index), this.sectionStart = this.index));
}, t.prototype.shouldContinue = function() {
return this.index < this.buffer.length + this.offset && this.running;
}, t.prototype.parse = function() {
for (; this.shouldContinue(); ) {
var e = this.buffer.charCodeAt(this.index - this.offset);
switch (this.state) {
case i.Text: {
this.stateText(e);
break;
}
case i.SpecialStartSequence: {
this.stateSpecialStartSequence(e);
break;
}
case i.InSpecialTag: {
this.stateInSpecialTag(e);
break;
}
case i.CDATASequence: {
this.stateCDATASequence(e);
break;
}
case i.InAttributeValueDq: {
this.stateInAttributeValueDoubleQuotes(e);
break;
}
case i.InAttributeName: {
this.stateInAttributeName(e);
break;
}
case i.InCommentLike: {
this.stateInCommentLike(e);
break;
}
case i.InSpecialComment: {
this.stateInSpecialComment(e);
break;
}
case i.BeforeAttributeName: {
this.stateBeforeAttributeName(e);
break;
}
case i.InTagName: {
this.stateInTagName(e);
break;
}
case i.InClosingTagName: {
this.stateInClosingTagName(e);
break;
}
case i.BeforeTagName: {
this.stateBeforeTagName(e);
break;
}
case i.AfterAttributeName: {
this.stateAfterAttributeName(e);
break;
}
case i.InAttributeValueSq: {
this.stateInAttributeValueSingleQuotes(e);
break;
}
case i.BeforeAttributeValue: {
this.stateBeforeAttributeValue(e);
break;
}
case i.BeforeClosingTagName: {
this.stateBeforeClosingTagName(e);
break;
}
case i.AfterClosingTagName: {
this.stateAfterClosingTagName(e);
break;
}
case i.BeforeSpecialS: {
this.stateBeforeSpecialS(e);
break;
}
case i.InAttributeValueNq: {
this.stateInAttributeValueNoQuotes(e);
break;
}
case i.InSelfClosingTag: {
this.stateInSelfClosingTag(e);
break;
}
case i.InDeclaration: {
this.stateInDeclaration(e);
break;
}
case i.BeforeDeclaration: {
this.stateBeforeDeclaration(e);
break;
}
case i.BeforeComment: {
this.stateBeforeComment(e);
break;
}
case i.InProcessingInstruction: {
this.stateInProcessingInstruction(e);
break;
}
case i.InNamedEntity: {
this.stateInNamedEntity(e);
break;
}
case i.BeforeEntity: {
this.stateBeforeEntity(e);
break;
}
case i.InHexEntity: {
this.stateInHexEntity(e);
break;
}
case i.InNumericEntity: {
this.stateInNumericEntity(e);
break;
}
default:
this.stateBeforeNumericEntity(e);
}
this.index++;
}
this.cleanup();
}, t.prototype.finish = function() {
this.state === i.InNamedEntity && this.emitNamedEntity(), this.sectionStart < this.index && this.handleTrailingData(), this.cbs.onend();
}, t.prototype.handleTrailingData = function() {
var e = this.buffer.length + this.offset;
this.state === i.InCommentLike ? this.currentSequence === a.CdataEnd ? this.cbs.oncdata(this.sectionStart, e, 0) : this.cbs.oncomment(this.sectionStart, e, 0) : this.state === i.InNumericEntity && this.allowLegacyEntity() ? this.emitNumericEntity(!1) : this.state === i.InHexEntity && this.allowLegacyEntity() ? this.emitNumericEntity(!1) : this.state === i.InTagName || this.state === i.BeforeAttributeName || this.state === i.BeforeAttributeValue || this.state === i.AfterAttributeName || this.state === i.InAttributeName || this.state === i.InAttributeValueSq || this.state === i.InAttributeValueDq || this.state === i.InAttributeValueNq || this.state === i.InClosingTagName || this.cbs.ontext(this.sectionStart, e);
}, t.prototype.emitPartial = function(e, n) {
this.baseState !== i.Text && this.baseState !== i.InSpecialTag ? this.cbs.onattribdata(e, n) : this.cbs.ontext(e, n);
}, t.prototype.emitCodePoint = function(e) {
this.baseState !== i.Text && this.baseState !== i.InSpecialTag ? this.cbs.onattribentity(e) : this.cbs.ontextentity(e);
}, t;
})()
);
c.default = y;
})(m), m);
}
export {
A as __require
};
//# sourceMappingURL=index.es680.js.map