import { ATTRS, NS, TAG_ID, getTagID } from "./html.js";
var MIME_TYPES = {
	TEXT_HTML: "text/html",
	APPLICATION_XML: "application/xhtml+xml"
}, DEFINITION_URL_ATTR = "definitionurl", ADJUSTED_DEFINITION_URL_ATTR = "definitionURL", SVG_ATTRS_ADJUSTMENT_MAP = new Map((/* @__PURE__ */ "attributeName.attributeType.baseFrequency.baseProfile.calcMode.clipPathUnits.diffuseConstant.edgeMode.filterUnits.glyphRef.gradientTransform.gradientUnits.kernelMatrix.kernelUnitLength.keyPoints.keySplines.keyTimes.lengthAdjust.limitingConeAngle.markerHeight.markerUnits.markerWidth.maskContentUnits.maskUnits.numOctaves.pathLength.patternContentUnits.patternTransform.patternUnits.pointsAtX.pointsAtY.pointsAtZ.preserveAlpha.preserveAspectRatio.primitiveUnits.refX.refY.repeatCount.repeatDur.requiredExtensions.requiredFeatures.specularConstant.specularExponent.spreadMethod.startOffset.stdDeviation.stitchTiles.surfaceScale.systemLanguage.tableValues.targetX.targetY.textLength.viewBox.viewTarget.xChannelSelector.yChannelSelector.zoomAndPan".split(".")).map((e) => [e.toLowerCase(), e])), XML_ATTRS_ADJUSTMENT_MAP = new Map([
	["xlink:actuate", {
		prefix: "xlink",
		name: "actuate",
		namespace: NS.XLINK
	}],
	["xlink:arcrole", {
		prefix: "xlink",
		name: "arcrole",
		namespace: NS.XLINK
	}],
	["xlink:href", {
		prefix: "xlink",
		name: "href",
		namespace: NS.XLINK
	}],
	["xlink:role", {
		prefix: "xlink",
		name: "role",
		namespace: NS.XLINK
	}],
	["xlink:show", {
		prefix: "xlink",
		name: "show",
		namespace: NS.XLINK
	}],
	["xlink:title", {
		prefix: "xlink",
		name: "title",
		namespace: NS.XLINK
	}],
	["xlink:type", {
		prefix: "xlink",
		name: "type",
		namespace: NS.XLINK
	}],
	["xml:lang", {
		prefix: "xml",
		name: "lang",
		namespace: NS.XML
	}],
	["xml:space", {
		prefix: "xml",
		name: "space",
		namespace: NS.XML
	}],
	["xmlns", {
		prefix: "",
		name: "xmlns",
		namespace: NS.XMLNS
	}],
	["xmlns:xlink", {
		prefix: "xmlns",
		name: "xlink",
		namespace: NS.XMLNS
	}]
]);
const SVG_TAG_NAMES_ADJUSTMENT_MAP = new Map((/* @__PURE__ */ "altGlyph.altGlyphDef.altGlyphItem.animateColor.animateMotion.animateTransform.clipPath.feBlend.feColorMatrix.feComponentTransfer.feComposite.feConvolveMatrix.feDiffuseLighting.feDisplacementMap.feDistantLight.feFlood.feFuncA.feFuncB.feFuncG.feFuncR.feGaussianBlur.feImage.feMerge.feMergeNode.feMorphology.feOffset.fePointLight.feSpecularLighting.feSpotLight.feTile.feTurbulence.foreignObject.glyphRef.linearGradient.radialGradient.textPath".split(".")).map((e) => [e.toLowerCase(), e]));
var EXITS_FOREIGN_CONTENT = new Set([
	TAG_ID.B,
	TAG_ID.BIG,
	TAG_ID.BLOCKQUOTE,
	TAG_ID.BODY,
	TAG_ID.BR,
	TAG_ID.CENTER,
	TAG_ID.CODE,
	TAG_ID.DD,
	TAG_ID.DIV,
	TAG_ID.DL,
	TAG_ID.DT,
	TAG_ID.EM,
	TAG_ID.EMBED,
	TAG_ID.H1,
	TAG_ID.H2,
	TAG_ID.H3,
	TAG_ID.H4,
	TAG_ID.H5,
	TAG_ID.H6,
	TAG_ID.HEAD,
	TAG_ID.HR,
	TAG_ID.I,
	TAG_ID.IMG,
	TAG_ID.LI,
	TAG_ID.LISTING,
	TAG_ID.MENU,
	TAG_ID.META,
	TAG_ID.NOBR,
	TAG_ID.OL,
	TAG_ID.P,
	TAG_ID.PRE,
	TAG_ID.RUBY,
	TAG_ID.S,
	TAG_ID.SMALL,
	TAG_ID.SPAN,
	TAG_ID.STRONG,
	TAG_ID.STRIKE,
	TAG_ID.SUB,
	TAG_ID.SUP,
	TAG_ID.TABLE,
	TAG_ID.TT,
	TAG_ID.U,
	TAG_ID.UL,
	TAG_ID.VAR
]);
function causesExit(p) {
	let h = p.tagID;
	return h === TAG_ID.FONT && p.attrs.some(({ name: p }) => p === ATTRS.COLOR || p === ATTRS.SIZE || p === ATTRS.FACE) || EXITS_FOREIGN_CONTENT.has(h);
}
function adjustTokenMathMLAttrs(e) {
	for (let p = 0; p < e.attrs.length; p++) if (e.attrs[p].name === DEFINITION_URL_ATTR) {
		e.attrs[p].name = ADJUSTED_DEFINITION_URL_ATTR;
		break;
	}
}
function adjustTokenSVGAttrs(e) {
	for (let p = 0; p < e.attrs.length; p++) {
		let m = SVG_ATTRS_ADJUSTMENT_MAP.get(e.attrs[p].name);
		m != null && (e.attrs[p].name = m);
	}
}
function adjustTokenXMLAttrs(e) {
	for (let p = 0; p < e.attrs.length; p++) {
		let m = XML_ATTRS_ADJUSTMENT_MAP.get(e.attrs[p].name);
		m && (e.attrs[p].prefix = m.prefix, e.attrs[p].name = m.name, e.attrs[p].namespace = m.namespace);
	}
}
function adjustTokenSVGTagName(e) {
	let p = SVG_TAG_NAMES_ADJUSTMENT_MAP.get(e.tagName);
	p != null && (e.tagName = p, e.tagID = getTagID(e.tagName));
}
function isMathMLTextIntegrationPoint(e, h) {
	return h === NS.MATHML && (e === TAG_ID.MI || e === TAG_ID.MO || e === TAG_ID.MN || e === TAG_ID.MS || e === TAG_ID.MTEXT);
}
function isHtmlIntegrationPoint(h, _, v) {
	if (_ === NS.MATHML && h === TAG_ID.ANNOTATION_XML) {
		for (let p = 0; p < v.length; p++) if (v[p].name === ATTRS.ENCODING) {
			let e = v[p].value.toLowerCase();
			return e === MIME_TYPES.TEXT_HTML || e === MIME_TYPES.APPLICATION_XML;
		}
	}
	return _ === NS.SVG && (h === TAG_ID.FOREIGN_OBJECT || h === TAG_ID.DESC || h === TAG_ID.TITLE);
}
function isIntegrationPoint(e, m, h, g) {
	return (!g || g === NS.HTML) && isHtmlIntegrationPoint(e, m, h) || (!g || g === NS.MATHML) && isMathMLTextIntegrationPoint(e, m);
}
export { adjustTokenMathMLAttrs, adjustTokenSVGAttrs, adjustTokenSVGTagName, adjustTokenXMLAttrs, causesExit, isIntegrationPoint };
