setup-cpp
Version:
Install all the tools required for building and testing C++/C projects.
1,649 lines • 145 kB
JavaScript
import { constants as Qu, createWriteStream as wu, createReadStream as Cu } from "node:fs";
import { readlink as Zu, readdir as Ju, lstat as et, open as Vu, chmod as ut, utimes as tt, symlink as rt, rm as ou, mkdir as Xe, writeFile as su } from "node:fs/promises";
import { join as Le, resolve as bu, dirname as yu, basename as nt } from "node:path";
import { Writable as at, Readable as it, pipeline as ot } from "node:stream";
import { pipeline as st } from "node:stream/promises";
import { promisify as lt } from "node:util";
import { spawn as Nu, spawnSync as Bu } from "node:child_process";
let X = /* @__PURE__ */ function(c) {
return c.DIRECTORY = "directory", c.FILE = "file", c.SYMLINK = "symlink", c.RESOURCE_FORK = "resource-fork", c;
}({});
const {
O_WRONLY: $u,
O_SYMLINK: We
} = Qu, ct = !!We, ft = !!We;
function Xu(c) {
return c.replace(/\\/g, "/").replace(/([^/])\/+$/, "$1");
}
function Ke(c) {
return Le(c, "..namedfork", "rsrc");
}
function pt(c) {
return c.isSymbolicLink() ? X.SYMLINK : c.isDirectory() ? X.DIRECTORY : c.isFile() ? X.FILE : null;
}
function ht(c) {
return c & 511;
}
async function Dt(c) {
const u = [];
let n = 0;
return await st(c, new at({
// eslint-disable-next-line jsdoc/require-jsdoc
write: (a, l, s) => {
u.push(a), n += a.length, s();
}
})), Buffer.concat(u, n);
}
async function mt(c, u) {
if (!ct)
return;
const n = await Vu(c, $u | We);
try {
await n.chmod(u);
} finally {
await n.close();
}
}
async function dt(c, u, n) {
await tt(c, u, n);
}
async function At(c, u, n) {
if (!ft)
return;
const a = await Vu(c, $u | We);
try {
await a.utimes(u, n);
} finally {
await a.close();
}
}
async function Et(c) {
return Zu(c, "buffer");
}
async function gt(c, u) {
await rt(u, c);
}
async function vt(c, u) {
await ut(c, u);
}
async function Tu(c) {
return (await Ju(c)).sort();
}
async function Gu(c) {
return et(c);
}
async function Ie(c) {
try {
return await Gu(c);
} catch (u) {
const {
code: n
} = u;
if (n === "ENOENT" || n === "ENOTDIR")
return null;
throw u;
}
}
async function wt(c, u, n = {}) {
const {
ignoreUnreadableDirectories: a
} = n, l = (await Tu(c)).reverse();
for (; l.length; ) {
const s = l.pop(), f = Le(c, s), m = await Gu(f), E = await u(s, m);
if (E === null)
break;
if (E === !1 || !m.isDirectory())
continue;
let A = [];
try {
A = await Tu(f);
} catch (b) {
if (!(b && a && b.code === "EACCES"))
throw b;
}
for (let b = A.length; b--; )
l.push(Le(s, A[b]));
}
}
const Su = lt(ot);
class ju {
/**
* Entry archive.
*/
/**
* Entry type.
*/
/**
* Entry path.
*/
/**
* Entry path, raw.
*/
/**
* Entry size.
*/
/**
* Entry size, compressed.
*/
/**
* Entry mode.
*/
/**
* Entry uid.
*/
/**
* Entry gid.
*/
/**
* Entry uname.
*/
/**
* Entry gname.
*/
/**
* Entry atime.
*/
/**
* Entry mtime.
*/
/**
* Read data.
*/
/**
* Read rsrc.
*/
/**
* Read symlink.
*/
/**
* Entry triggering.
*/
_triggering = !1;
/**
* Entry triggered.
*/
_triggered = !1;
/**
* Entry extracted.
*/
_extracted = !1;
/**
* Entry constructor.
*
* @param info Info object.
*/
constructor(u) {
this.archive = u.archive, this.type = u.type, this.pathRaw = u.pathRaw, this.path = Xu(u.pathRaw), this.size = u.size ?? null, this.sizeComp = u.sizeComp ?? null, this.mode = u.mode ?? null, this.uid = u.uid ?? null, this.gid = u.gid ?? null, this.uname = u.uname ?? null, this.gname = u.gname ?? null, this.atime = u.atime ?? null, this.mtime = u.mtime ?? null, this._readData = u.readData ?? null, this._readRsrc = u.readRsrc ?? null, this._readSymlink = u.readSymlink ?? null;
}
/**
* This entry path includes named volume.
*
* @returns Entry has volume name in path.
*/
get hasNamedVolume() {
return this.archive.hasNamedVolumes;
}
/**
* This entry volume name, or null.
*
* @returns Entry path volume name.
*/
get volumeName() {
if (this.hasNamedVolume) {
const {
path: u
} = this;
return u.slice(0, u.indexOf("/"));
}
return null;
}
/**
* This entry path without any possible volume name.
*
* @returns Entry path without the volume name.
*/
get volumePath() {
const {
path: u
} = this;
return this.hasNamedVolume ? u.slice(u.indexOf("/") + 1) : u;
}
/**
* Read entry as stream, or null if nothing to read.
* Consuming function will need to wait for stream to close.
*
* @returns Readable stream or null if nothing to read.
*/
async stream() {
return this._beginExtract(), this._stream();
}
/**
* Read entire entry into a Buffer.
*
* @returns Buffer or null if nothing to be read.
*/
async read() {
this._beginExtract();
const u = await this._stream();
return u ? Dt(u) : null;
}
/**
* Extract entry.
*
* @param path Extract path.
* @param options Extract options.
*/
async extract(u, n = {}) {
this._beginExtract(), await this._extract(u, n);
}
/**
* Trigger on itterator function.
*
* @param itter Itterator function.
* @returns Return value.
*/
async trigger(u) {
let n;
if (this._triggered)
throw new Error("Archive entry already triggered");
this._triggered = this._triggering = !0;
try {
n = await u(this);
} finally {
this._triggering = !1;
}
return n;
}
/**
* Run again after reading.
*
* @param path Extract path, relative.
* @param pathFull An optional full path to be used.
* @param options Extract options.
*/
async setAttributes(u, n = null, a = {}) {
const l = n === null ? u : n, {
ignorePermissions: s,
ignoreTimes: f
} = a, {
type: m,
mode: E,
atime: A,
mtime: b
} = this;
let N = !1;
switch (m) {
case X.FILE:
break;
case X.RESOURCE_FORK:
break;
case X.DIRECTORY:
break;
case X.SYMLINK: {
N = !0;
break;
}
default:
throw new Error(`Unsupported path type: ${m}`);
}
const O = A || b || null, P = b || A || null;
if (!s && E !== null) {
const ue = N ? mt : vt, Q = ht(E);
await ue(l, Q);
}
!f && O && P && await (N ? At : dt)(l, O, P);
}
/**
* Method to call before begining extraction.
* Throws error if extraction already started or entry not active.
*/
_beginExtract() {
if (!this._triggering)
throw new Error("Archive entry is not active");
if (this._extracted)
throw new Error("Archive entry can only be extracted once");
this._extracted = !0;
}
/**
* Create an extract error for path that exists.
*
* @param path Extract path.
* @returns Error object.
*/
_errorExtractPathExists(u) {
return new Error(`Extract path already exists: ${u}`);
}
/**
* Create an extract error for a resource fork not going to a file.
*
* @param path Extract path.
* @returns Error object.
*/
_errorNoResourceFork(u) {
return new Error(`Extract path for resource fork not a file: ${u}`);
}
/**
* Extract entry.
*
* @param path Extract path.
* @param options Extract options.
*/
async _extract(u, n) {
this.archive.afterReadSetAttributesRemove(u);
const {
type: a
} = this;
switch (a) {
case X.FILE: {
await this._extractFile(u, n);
break;
}
case X.RESOURCE_FORK: {
await this._extractResourceFork(u, n);
break;
}
case X.DIRECTORY: {
await this._extractDirectory(u, n);
break;
}
case X.SYMLINK: {
await this._extractSymlink(u, n);
break;
}
default:
throw new Error(`Unsupported path type: ${a}`);
}
}
/**
* Base function for extracting stream to a file.
*
* @param path Extract path.
* @param reader Reader function.
* @param options Extract options.
*/
async _extractStreamToFile(u, n, a) {
const {
replace: l
} = a;
if (await Ie(u))
if (l)
await ou(u, {
recursive: !0,
force: !0
});
else
throw this._errorExtractPathExists(u);
else
await Xe(yu(u), {
recursive: !0
});
await su(u, Buffer.alloc(0));
const f = await n();
f && await Su(f, wu(u)), await this.setAttributes(u, null, a);
}
/**
* Extract as a file.
*
* @param path Extract path.
* @param options Extract options.
*/
async _extractFile(u, n) {
const a = this._readData;
if (!a)
throw new Error("Internal error");
await this._extractStreamToFile(u, a, n);
}
/**
* Extract as resource fork to an existing file.
*
* @param path Extract path.
* @param options Extract options.
*/
async _extractResourceFork(u, n) {
const a = this._readRsrc;
if (!a)
throw new Error("Internal error");
if (n.resourceForkAsFile) {
await this._extractStreamToFile(u, a, n);
return;
}
const l = await Ie(u);
if (!l || !l.isFile())
throw this._errorNoResourceFork(u);
const s = Ke(u), f = await a();
f ? await Su(f, wu(s)) : await su(s, Buffer.alloc(0)), await this.setAttributes(u, null, n);
}
/**
* Extract as a directory.
*
* @param path Extract path.
* @param options Extract options.
*/
async _extractDirectory(u, n) {
const {
replace: a
} = n, l = await Ie(u);
if (l) {
if (!l.isDirectory())
if (a)
await ou(u, {
recursive: !0,
force: !0
}), await Xe(u, {
recursive: !0
});
else
throw this._errorExtractPathExists(u);
} else
await Xe(u, {
recursive: !0
});
this.archive.afterReadSetAttributes(u, this, {
...n
});
}
/**
* Extract as a symlink.
*
* @param path Extract path.
* @param options Extract options.
*/
async _extractSymlink(u, n) {
const a = this._readSymlink;
if (!a)
throw new Error("Internal error");
const {
replace: l,
symlinkAsFile: s
} = n;
if (await Ie(u))
if (l)
await ou(u, {
recursive: !0,
force: !0
});
else
throw this._errorExtractPathExists(u);
else
await Xe(yu(u), {
recursive: !0
});
const m = await a();
s ? await su(u, m) : await gt(u, m), await this.setAttributes(u, null, n);
}
/**
* Read as stream.
*
* @returns Readable stream.
*/
async _stream() {
const {
type: u
} = this;
switch (u) {
case X.FILE:
return this._streamFile();
case X.RESOURCE_FORK:
return this._streamResourceFork();
case X.DIRECTORY:
return this._streamDirectory();
case X.SYMLINK:
return this._streamSymlink();
default:
throw new Error(`Unsupported path type: ${u}`);
}
}
/**
* Read file as stream.
*
* @returns Readable stream.
*/
async _streamFile() {
const u = this._readData;
if (!u)
throw new Error("Internal error");
return u();
}
/**
* Read resource fork as stream.
*
* @returns Readable stream.
*/
async _streamResourceFork() {
const u = this._readRsrc;
if (!u)
throw new Error("Internal error");
return u();
}
/**
* Read directory null stream.
*
* @returns Null stream.
*/
async _streamDirectory() {
return null;
}
/**
* Read symlink as stream.
*
* @returns Readable stream.
*/
async _streamSymlink() {
const u = this._readSymlink;
if (!u)
throw new Error("Internal error");
const n = new it({
// eslint-disable-next-line jsdoc/require-jsdoc
read: () => {
u().then((a) => {
n.push(a), n.push(null);
}, (a) => {
n.emit("error", a);
});
}
});
return n;
}
}
class Ct {
/**
* List of file extensions, or null.
*/
static FILE_EXTENSIONS = null;
/**
* Archive has named volumes that each entry will be under.
*/
static HAS_NAMED_VOLUMES = !1;
/**
* Entry constructor.
*/
Entry = ju;
/**
* File path.
*/
/**
* Flag for currently reading.
*/
_reading = !1;
/**
* Map of entries to set attributes on after reading.
*/
_afterReadSetAttributes = null;
/**
* Archive constructor.
*
* @param path File path.
*/
constructor(u) {
this.path = u;
}
/**
* List of file extensions used by this format.
*
* @returns List of file extensions.
*/
get fileExtensions() {
return this.constructor.FILE_EXTENSIONS || null;
}
/**
* Archive has named volumes that each entry will be under.
*
* @returns Archive has named volumns.
*/
get hasNamedVolumes() {
return this.constructor.HAS_NAMED_VOLUMES;
}
/**
* Add an instance to set attributes after the read finishes.
*
* @param path Path string.
* @param entry Entry instance.
* @param options Extract options.
*/
afterReadSetAttributes(u, n, a = {}) {
const l = this._afterReadSetAttributes;
if (!l)
throw new Error("Archive after read callbacks can only be added while reading");
l.set(bu(u), {
path: u,
entry: n,
options: a
});
}
/**
* Remove an instance to set attributes after the read finishes.
*
* @param path Path string.
*/
afterReadSetAttributesRemove(u) {
const n = this._afterReadSetAttributes;
if (!n)
throw new Error("Archive after read callbacks can only be removed while reading");
n.delete(bu(u));
}
/**
* Read archive.
* If the itter callback returns false, reading ends.
* If the itter callback returns null, skip descent where available.
*
* @param itter Async callback for each archive entry.
*/
async read(u) {
if (this._reading)
throw new Error("Archive already being read");
this._reading = !0, this._afterReadSetAttributes = /* @__PURE__ */ new Map();
try {
await this._read(u), await this._afterReadSetAttributesTrigger();
} finally {
this._afterReadSetAttributes = null, this._reading = !1;
}
}
/**
* Run all after read set attributes.
*/
async _afterReadSetAttributesTrigger() {
const u = this._afterReadSetAttributes;
if (!u)
return;
const n = [];
for (const [a] of u)
n.push(a);
n.sort((a, l) => l.length - a.length);
for (const a of n) {
const l = u.get(a);
if (!l)
throw new Error("Internal error");
const {
entry: s,
path: f,
options: m
} = l;
await s.setAttributes(f, a, m);
}
}
/**
* Read archive, class implementation.
* If the itter callback returns false, reading ends.
* If the itter callback returns null, skip descent where available.
*
* @param itter Async callback for each archive entry.
*/
}
var qe = {}, ce = {}, ge = {}, Fu;
function Qe() {
if (Fu) return ge;
Fu = 1;
function c(s, f, m) {
if (m === void 0 && (m = Array.prototype), s && typeof m.find == "function")
return m.find.call(s, f);
for (var E = 0; E < s.length; E++)
if (Object.prototype.hasOwnProperty.call(s, E)) {
var A = s[E];
if (f.call(void 0, A, E, s))
return A;
}
}
function u(s, f) {
return f === void 0 && (f = Object), f && typeof f.freeze == "function" ? f.freeze(s) : s;
}
function n(s, f) {
if (s === null || typeof s != "object")
throw new TypeError("target is not an object");
for (var m in f)
Object.prototype.hasOwnProperty.call(f, m) && (s[m] = f[m]);
return s;
}
var a = u({
/**
* `text/html`, the only mime type that triggers treating an XML document as HTML.
*
* @see DOMParser.SupportedType.isHTML
* @see https://www.iana.org/assignments/media-types/text/html IANA MimeType registration
* @see https://en.wikipedia.org/wiki/HTML Wikipedia
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString MDN
* @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring WHATWG HTML Spec
*/
HTML: "text/html",
/**
* Helper method to check a mime type if it indicates an HTML document
*
* @param {string} [value]
* @returns {boolean}
*
* @see https://www.iana.org/assignments/media-types/text/html IANA MimeType registration
* @see https://en.wikipedia.org/wiki/HTML Wikipedia
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString MDN
* @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring */
isHTML: function(s) {
return s === a.HTML;
},
/**
* `application/xml`, the standard mime type for XML documents.
*
* @see https://www.iana.org/assignments/media-types/application/xml IANA MimeType registration
* @see https://tools.ietf.org/html/rfc7303#section-9.1 RFC 7303
* @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
*/
XML_APPLICATION: "application/xml",
/**
* `text/html`, an alias for `application/xml`.
*
* @see https://tools.ietf.org/html/rfc7303#section-9.2 RFC 7303
* @see https://www.iana.org/assignments/media-types/text/xml IANA MimeType registration
* @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
*/
XML_TEXT: "text/xml",
/**
* `application/xhtml+xml`, indicates an XML document that has the default HTML namespace,
* but is parsed as an XML document.
*
* @see https://www.iana.org/assignments/media-types/application/xhtml+xml IANA MimeType registration
* @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument WHATWG DOM Spec
* @see https://en.wikipedia.org/wiki/XHTML Wikipedia
*/
XML_XHTML_APPLICATION: "application/xhtml+xml",
/**
* `image/svg+xml`,
*
* @see https://www.iana.org/assignments/media-types/image/svg+xml IANA MimeType registration
* @see https://www.w3.org/TR/SVG11/ W3C SVG 1.1
* @see https://en.wikipedia.org/wiki/Scalable_Vector_Graphics Wikipedia
*/
XML_SVG_IMAGE: "image/svg+xml"
}), l = u({
/**
* The XHTML namespace.
*
* @see http://www.w3.org/1999/xhtml
*/
HTML: "http://www.w3.org/1999/xhtml",
/**
* Checks if `uri` equals `NAMESPACE.HTML`.
*
* @param {string} [uri]
*
* @see NAMESPACE.HTML
*/
isHTML: function(s) {
return s === l.HTML;
},
/**
* The SVG namespace.
*
* @see http://www.w3.org/2000/svg
*/
SVG: "http://www.w3.org/2000/svg",
/**
* The `xml:` namespace.
*
* @see http://www.w3.org/XML/1998/namespace
*/
XML: "http://www.w3.org/XML/1998/namespace",
/**
* The `xmlns:` namespace
*
* @see https://www.w3.org/2000/xmlns/
*/
XMLNS: "http://www.w3.org/2000/xmlns/"
});
return ge.assign = n, ge.find = c, ge.freeze = u, ge.MIME_TYPE = a, ge.NAMESPACE = l, ge;
}
var xu;
function zu() {
if (xu) return ce;
xu = 1;
var c = Qe(), u = c.find, n = c.NAMESPACE;
function a(e) {
return e !== "";
}
function l(e) {
return e ? e.split(/[\t\n\f\r ]+/).filter(a) : [];
}
function s(e, t) {
return e.hasOwnProperty(t) || (e[t] = !0), e;
}
function f(e) {
if (!e) return [];
var t = l(e);
return Object.keys(t.reduce(s, {}));
}
function m(e) {
return function(t) {
return e && e.indexOf(t) !== -1;
};
}
function E(e, t) {
for (var r in e)
Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
}
function A(e, t) {
var r = e.prototype;
if (!(r instanceof t)) {
let i = function() {
};
i.prototype = t.prototype, i = new i(), E(r, i), e.prototype = r = i;
}
r.constructor != e && (typeof e != "function" && console.error("unknown Class:" + e), r.constructor = e);
}
var b = {}, N = b.ELEMENT_NODE = 1, O = b.ATTRIBUTE_NODE = 2, P = b.TEXT_NODE = 3, ue = b.CDATA_SECTION_NODE = 4, Q = b.ENTITY_REFERENCE_NODE = 5, D = b.ENTITY_NODE = 6, R = b.PROCESSING_INSTRUCTION_NODE = 7, q = b.COMMENT_NODE = 8, _ = b.DOCUMENT_NODE = 9, V = b.DOCUMENT_TYPE_NODE = 10, M = b.DOCUMENT_FRAGMENT_NODE = 11, Y = b.NOTATION_NODE = 12, F = {}, L = {};
F.INDEX_SIZE_ERR = (L[1] = "Index size error", 1), F.DOMSTRING_SIZE_ERR = (L[2] = "DOMString size error", 2);
var o = F.HIERARCHY_REQUEST_ERR = (L[3] = "Hierarchy request error", 3);
F.WRONG_DOCUMENT_ERR = (L[4] = "Wrong document", 4), F.INVALID_CHARACTER_ERR = (L[5] = "Invalid character", 5), F.NO_DATA_ALLOWED_ERR = (L[6] = "No data allowed", 6), F.NO_MODIFICATION_ALLOWED_ERR = (L[7] = "No modification allowed", 7);
var h = F.NOT_FOUND_ERR = (L[8] = "Not found", 8);
F.NOT_SUPPORTED_ERR = (L[9] = "Not supported", 9);
var g = F.INUSE_ATTRIBUTE_ERR = (L[10] = "Attribute in use", 10);
F.INVALID_STATE_ERR = (L[11] = "Invalid state", 11), F.SYNTAX_ERR = (L[12] = "Syntax error", 12), F.INVALID_MODIFICATION_ERR = (L[13] = "Invalid modification", 13), F.NAMESPACE_ERR = (L[14] = "Invalid namespace", 14), F.INVALID_ACCESS_ERR = (L[15] = "Invalid access", 15);
function d(e, t) {
if (t instanceof Error)
var r = t;
else
r = this, Error.call(this, L[e]), this.message = L[e], Error.captureStackTrace && Error.captureStackTrace(this, d);
return r.code = e, t && (this.message = this.message + ": " + t), r;
}
d.prototype = Error.prototype, E(F, d);
function w() {
}
w.prototype = {
/**
* The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
* @standard level1
*/
length: 0,
/**
* Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
* @standard level1
* @param index unsigned long
* Index into the collection.
* @return Node
* The node at the indexth position in the NodeList, or null if that is not a valid index.
*/
item: function(e) {
return e >= 0 && e < this.length ? this[e] : null;
},
toString: function(e, t) {
for (var r = [], i = 0; i < this.length; i++)
Be(this[i], r, e, t);
return r.join("");
},
/**
* @private
* @param {function (Node):boolean} predicate
* @returns {Node[]}
*/
filter: function(e) {
return Array.prototype.filter.call(this, e);
},
/**
* @private
* @param {Node} item
* @returns {number}
*/
indexOf: function(e) {
return Array.prototype.indexOf.call(this, e);
}
};
function S(e, t) {
this._node = e, this._refresh = t, x(this);
}
function x(e) {
var t = e._node._inc || e._node.ownerDocument._inc;
if (e._inc !== t) {
var r = e._refresh(e._node);
if (Eu(e, "length", r.length), !e.$$length || r.length < e.$$length)
for (var i = r.length; i in e; i++)
Object.prototype.hasOwnProperty.call(e, i) && delete e[i];
E(r, e), e._inc = t;
}
}
S.prototype.item = function(e) {
return x(this), this[e] || null;
}, A(S, w);
function I() {
}
function y(e, t) {
for (var r = e.length; r--; )
if (e[r] === t)
return r;
}
function B(e, t, r, i) {
if (i ? t[y(t, i)] = r : t[t.length++] = r, e) {
r.ownerElement = e;
var p = e.ownerDocument;
p && (i && xe(p, e, i), j(p, e, r));
}
}
function T(e, t, r) {
var i = y(t, r);
if (i >= 0) {
for (var p = t.length - 1; i < p; )
t[i] = t[++i];
if (t.length = p, e) {
var C = e.ownerDocument;
C && (xe(C, e, r), r.ownerElement = null);
}
} else
throw new d(h, new Error(e.tagName + "@" + r));
}
I.prototype = {
length: 0,
item: w.prototype.item,
getNamedItem: function(e) {
for (var t = this.length; t--; ) {
var r = this[t];
if (r.nodeName == e)
return r;
}
},
setNamedItem: function(e) {
var t = e.ownerElement;
if (t && t != this._ownerElement)
throw new d(g);
var r = this.getNamedItem(e.nodeName);
return B(this._ownerElement, this, e, r), r;
},
/* returns Node */
setNamedItemNS: function(e) {
var t = e.ownerElement, r;
if (t && t != this._ownerElement)
throw new d(g);
return r = this.getNamedItemNS(e.namespaceURI, e.localName), B(this._ownerElement, this, e, r), r;
},
/* returns Node */
removeNamedItem: function(e) {
var t = this.getNamedItem(e);
return T(this._ownerElement, this, t), t;
},
// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
//for level2
removeNamedItemNS: function(e, t) {
var r = this.getNamedItemNS(e, t);
return T(this._ownerElement, this, r), r;
},
getNamedItemNS: function(e, t) {
for (var r = this.length; r--; ) {
var i = this[r];
if (i.localName == t && i.namespaceURI == e)
return i;
}
return null;
}
};
function $() {
}
$.prototype = {
/**
* The DOMImplementation.hasFeature() method returns a Boolean flag indicating if a given feature is supported.
* The different implementations fairly diverged in what kind of features were reported.
* The latest version of the spec settled to force this method to always return true, where the functionality was accurate and in use.
*
* @deprecated It is deprecated and modern browsers return true in all cases.
*
* @param {string} feature
* @param {string} [version]
* @returns {boolean} always true
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/hasFeature MDN
* @see https://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-5CED94D7 DOM Level 1 Core
* @see https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature DOM Living Standard
*/
hasFeature: function(e, t) {
return !0;
},
/**
* Creates an XML Document object of the specified type with its document element.
*
* __It behaves slightly different from the description in the living standard__:
* - There is no interface/class `XMLDocument`, it returns a `Document` instance.
* - `contentType`, `encoding`, `mode`, `origin`, `url` fields are currently not declared.
* - this implementation is not validating names or qualified names
* (when parsing XML strings, the SAX parser takes care of that)
*
* @param {string|null} namespaceURI
* @param {string} qualifiedName
* @param {DocumentType=null} doctype
* @returns {Document}
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocument MDN
* @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument DOM Level 2 Core (initial)
* @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument DOM Level 2 Core
*
* @see https://dom.spec.whatwg.org/#validate-and-extract DOM: Validate and extract
* @see https://www.w3.org/TR/xml/#NT-NameStartChar XML Spec: Names
* @see https://www.w3.org/TR/xml-names/#ns-qualnames XML Namespaces: Qualified names
*/
createDocument: function(e, t, r) {
var i = new G();
if (i.implementation = this, i.childNodes = new w(), i.doctype = r || null, r && i.appendChild(r), t) {
var p = i.createElementNS(e, t);
i.appendChild(p);
}
return i;
},
/**
* Returns a doctype, with the given `qualifiedName`, `publicId`, and `systemId`.
*
* __This behavior is slightly different from the in the specs__:
* - this implementation is not validating names or qualified names
* (when parsing XML strings, the SAX parser takes care of that)
*
* @param {string} qualifiedName
* @param {string} [publicId]
* @param {string} [systemId]
* @returns {DocumentType} which can either be used with `DOMImplementation.createDocument` upon document creation
* or can be put into the document via methods like `Node.insertBefore()` or `Node.replaceChild()`
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocumentType MDN
* @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocType DOM Level 2 Core
* @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype DOM Living Standard
*
* @see https://dom.spec.whatwg.org/#validate-and-extract DOM: Validate and extract
* @see https://www.w3.org/TR/xml/#NT-NameStartChar XML Spec: Names
* @see https://www.w3.org/TR/xml-names/#ns-qualnames XML Namespaces: Qualified names
*/
createDocumentType: function(e, t, r) {
var i = new Ve();
return i.name = e, i.nodeName = e, i.publicId = t || "", i.systemId = r || "", i;
}
};
function v() {
}
v.prototype = {
firstChild: null,
lastChild: null,
previousSibling: null,
nextSibling: null,
attributes: null,
parentNode: null,
childNodes: null,
ownerDocument: null,
nodeValue: null,
namespaceURI: null,
prefix: null,
localName: null,
// Modified in DOM Level 2:
insertBefore: function(e, t) {
return fe(this, e, t);
},
replaceChild: function(e, t) {
fe(this, e, t, Ue), t && this.removeChild(t);
},
removeChild: function(e) {
return Z(this, e);
},
appendChild: function(e) {
return this.insertBefore(e, null);
},
hasChildNodes: function() {
return this.firstChild != null;
},
cloneNode: function(e) {
return iu(this.ownerDocument || this, this, e);
},
// Modified in DOM Level 2:
normalize: function() {
for (var e = this.firstChild; e; ) {
var t = e.nextSibling;
t && t.nodeType == P && e.nodeType == P ? (this.removeChild(t), e.appendData(t.data)) : (e.normalize(), e = t);
}
},
// Introduced in DOM Level 2:
isSupported: function(e, t) {
return this.ownerDocument.implementation.hasFeature(e, t);
},
// Introduced in DOM Level 2:
hasAttributes: function() {
return this.attributes.length > 0;
},
/**
* Look up the prefix associated to the given namespace URI, starting from this node.
* **The default namespace declarations are ignored by this method.**
* See Namespace Prefix Lookup for details on the algorithm used by this method.
*
* _Note: The implementation seems to be incomplete when compared to the algorithm described in the specs._
*
* @param {string | null} namespaceURI
* @returns {string | null}
* @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespacePrefix
* @see https://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#lookupNamespacePrefixAlgo
* @see https://dom.spec.whatwg.org/#dom-node-lookupprefix
* @see https://github.com/xmldom/xmldom/issues/322
*/
lookupPrefix: function(e) {
for (var t = this; t; ) {
var r = t._nsMap;
if (r) {
for (var i in r)
if (Object.prototype.hasOwnProperty.call(r, i) && r[i] === e)
return i;
}
t = t.nodeType == O ? t.ownerDocument : t.parentNode;
}
return null;
},
// Introduced in DOM Level 3:
lookupNamespaceURI: function(e) {
for (var t = this; t; ) {
var r = t._nsMap;
if (r && Object.prototype.hasOwnProperty.call(r, e))
return r[e];
t = t.nodeType == O ? t.ownerDocument : t.parentNode;
}
return null;
},
// Introduced in DOM Level 3:
isDefaultNamespace: function(e) {
var t = this.lookupPrefix(e);
return t == null;
}
};
function J(e) {
return e == "<" && "<" || e == ">" && ">" || e == "&" && "&" || e == '"' && """ || "&#" + e.charCodeAt() + ";";
}
E(b, v), E(b, v.prototype);
function oe(e, t) {
if (t(e))
return !0;
if (e = e.firstChild)
do
if (oe(e, t))
return !0;
while (e = e.nextSibling);
}
function G() {
this.ownerDocument = this;
}
function j(e, t, r) {
e && e._inc++;
var i = r.namespaceURI;
i === n.XMLNS && (t._nsMap[r.prefix ? r.localName : ""] = r.value);
}
function xe(e, t, r, i) {
e && e._inc++;
var p = r.namespaceURI;
p === n.XMLNS && delete t._nsMap[r.prefix ? r.localName : ""];
}
function be(e, t, r) {
if (e && e._inc) {
e._inc++;
var i = t.childNodes;
if (r)
i[i.length++] = r;
else {
for (var p = t.firstChild, C = 0; p; )
i[C++] = p, p = p.nextSibling;
i.length = C, delete i[i.length];
}
}
}
function Z(e, t) {
var r = t.previousSibling, i = t.nextSibling;
return r ? r.nextSibling = i : e.firstChild = i, i ? i.previousSibling = r : e.lastChild = r, t.parentNode = null, t.previousSibling = null, t.nextSibling = null, be(e.ownerDocument, e), t;
}
function ne(e) {
return e && (e.nodeType === v.DOCUMENT_NODE || e.nodeType === v.DOCUMENT_FRAGMENT_NODE || e.nodeType === v.ELEMENT_NODE);
}
function _e(e) {
return e && (re(e) || ye(e) || te(e) || e.nodeType === v.DOCUMENT_FRAGMENT_NODE || e.nodeType === v.COMMENT_NODE || e.nodeType === v.PROCESSING_INSTRUCTION_NODE);
}
function te(e) {
return e && e.nodeType === v.DOCUMENT_TYPE_NODE;
}
function re(e) {
return e && e.nodeType === v.ELEMENT_NODE;
}
function ye(e) {
return e && e.nodeType === v.TEXT_NODE;
}
function K(e, t) {
var r = e.childNodes || [];
if (u(r, re) || te(t))
return !1;
var i = u(r, te);
return !(t && i && r.indexOf(i) > r.indexOf(t));
}
function Ne(e, t) {
var r = e.childNodes || [];
function i(C) {
return re(C) && C !== t;
}
if (u(r, i))
return !1;
var p = u(r, te);
return !(t && p && r.indexOf(p) > r.indexOf(t));
}
function z(e, t, r) {
if (!ne(e))
throw new d(o, "Unexpected parent node type " + e.nodeType);
if (r && r.parentNode !== e)
throw new d(h, "child not in parent");
if (
// 4. If `node` is not a DocumentFragment, DocumentType, Element, or CharacterData node, then throw a "HierarchyRequestError" DOMException.
!_e(t) || // 5. If either `node` is a Text node and `parent` is a document,
// the sax parser currently adds top level text nodes, this will be fixed in 0.9.0
// || (node.nodeType === Node.TEXT_NODE && parent.nodeType === Node.DOCUMENT_NODE)
// or `node` is a doctype and `parent` is not a document, then throw a "HierarchyRequestError" DOMException.
te(t) && e.nodeType !== v.DOCUMENT_NODE
)
throw new d(
o,
"Unexpected node type " + t.nodeType + " for parent node type " + e.nodeType
);
}
function Me(e, t, r) {
var i = e.childNodes || [], p = t.childNodes || [];
if (t.nodeType === v.DOCUMENT_FRAGMENT_NODE) {
var C = p.filter(re);
if (C.length > 1 || u(p, ye))
throw new d(o, "More than one element or text in fragment");
if (C.length === 1 && !K(e, r))
throw new d(o, "Element in fragment can not be inserted before doctype");
}
if (re(t) && !K(e, r))
throw new d(o, "Only one element can be added and only after doctype");
if (te(t)) {
if (u(i, te))
throw new d(o, "Only one doctype is allowed");
var U = u(i, re);
if (r && i.indexOf(U) < i.indexOf(r))
throw new d(o, "Doctype can only be inserted before an element");
if (!r && U)
throw new d(o, "Doctype can not be appended since element is present");
}
}
function Ue(e, t, r) {
var i = e.childNodes || [], p = t.childNodes || [];
if (t.nodeType === v.DOCUMENT_FRAGMENT_NODE) {
var C = p.filter(re);
if (C.length > 1 || u(p, ye))
throw new d(o, "More than one element or text in fragment");
if (C.length === 1 && !Ne(e, r))
throw new d(o, "Element in fragment can not be inserted before doctype");
}
if (re(t) && !Ne(e, r))
throw new d(o, "Only one element can be added and only after doctype");
if (te(t)) {
if (u(i, function(se) {
return te(se) && se !== r;
}))
throw new d(o, "Only one doctype is allowed");
var U = u(i, re);
if (r && i.indexOf(U) < i.indexOf(r))
throw new d(o, "Doctype can only be inserted before an element");
}
}
function fe(e, t, r, i) {
z(e, t, r), e.nodeType === v.DOCUMENT_NODE && (i || Me)(e, t, r);
var p = t.parentNode;
if (p && p.removeChild(t), t.nodeType === M) {
var C = t.firstChild;
if (C == null)
return t;
var U = t.lastChild;
} else
C = U = t;
var ee = r ? r.previousSibling : e.lastChild;
C.previousSibling = ee, U.nextSibling = r, ee ? ee.nextSibling = C : e.firstChild = C, r == null ? e.lastChild = U : r.previousSibling = U;
do
C.parentNode = e;
while (C !== U && (C = C.nextSibling));
return be(e.ownerDocument || e, e), t.nodeType == M && (t.firstChild = t.lastChild = null), t;
}
function Pe(e, t) {
return t.parentNode && t.parentNode.removeChild(t), t.parentNode = e, t.previousSibling = e.lastChild, t.nextSibling = null, t.previousSibling ? t.previousSibling.nextSibling = t : e.firstChild = t, e.lastChild = t, be(e.ownerDocument, e, t), t;
}
G.prototype = {
//implementation : null,
nodeName: "#document",
nodeType: _,
/**
* The DocumentType node of the document.
*
* @readonly
* @type DocumentType
*/
doctype: null,
documentElement: null,
_inc: 1,
insertBefore: function(e, t) {
if (e.nodeType == M) {
for (var r = e.firstChild; r; ) {
var i = r.nextSibling;
this.insertBefore(r, t), r = i;
}
return e;
}
return fe(this, e, t), e.ownerDocument = this, this.documentElement === null && e.nodeType === N && (this.documentElement = e), e;
},
removeChild: function(e) {
return this.documentElement == e && (this.documentElement = null), Z(this, e);
},
replaceChild: function(e, t) {
fe(this, e, t, Ue), e.ownerDocument = this, t && this.removeChild(t), re(e) && (this.documentElement = e);
},
// Introduced in DOM Level 2:
importNode: function(e, t) {
return Au(this, e, t);
},
// Introduced in DOM Level 2:
getElementById: function(e) {
var t = null;
return oe(this.documentElement, function(r) {
if (r.nodeType == N && r.getAttribute("id") == e)
return t = r, !0;
}), t;
},
/**
* The `getElementsByClassName` method of `Document` interface returns an array-like object
* of all child elements which have **all** of the given class name(s).
*
* Returns an empty list if `classeNames` is an empty string or only contains HTML white space characters.
*
*
* Warning: This is a live LiveNodeList.
* Changes in the DOM will reflect in the array as the changes occur.
* If an element selected by this array no longer qualifies for the selector,
* it will automatically be removed. Be aware of this for iteration purposes.
*
* @param {string} classNames is a string representing the class name(s) to match; multiple class names are separated by (ASCII-)whitespace
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
* @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
*/
getElementsByClassName: function(e) {
var t = f(e);
return new S(this, function(r) {
var i = [];
return t.length > 0 && oe(r.documentElement, function(p) {
if (p !== r && p.nodeType === N) {
var C = p.getAttribute("class");
if (C) {
var U = e === C;
if (!U) {
var ee = f(C);
U = t.every(m(ee));
}
U && i.push(p);
}
}
}), i;
});
},
//document factory method:
createElement: function(e) {
var t = new k();
t.ownerDocument = this, t.nodeName = e, t.tagName = e, t.localName = e, t.childNodes = new w();
var r = t.attributes = new I();
return r._ownerElement = t, t;
},
createDocumentFragment: function() {
var e = new $e();
return e.ownerDocument = this, e.childNodes = new w(), e;
},
createTextNode: function(e) {
var t = new eu();
return t.ownerDocument = this, t.appendData(e), t;
},
createComment: function(e) {
var t = new uu();
return t.ownerDocument = this, t.appendData(e), t;
},
createCDATASection: function(e) {
var t = new tu();
return t.ownerDocument = this, t.appendData(e), t;
},
createProcessingInstruction: function(e, t) {
var r = new nu();
return r.ownerDocument = this, r.tagName = r.nodeName = r.target = e, r.nodeValue = r.data = t, r;
},
createAttribute: function(e) {
var t = new H();
return t.ownerDocument = this, t.name = e, t.nodeName = e, t.localName = e, t.specified = !0, t;
},
createEntityReference: function(e) {
var t = new ru();
return t.ownerDocument = this, t.nodeName = e, t;
},
// Introduced in DOM Level 2:
createElementNS: function(e, t) {
var r = new k(), i = t.split(":"), p = r.attributes = new I();
return r.childNodes = new w(), r.ownerDocument = this, r.nodeName = t, r.tagName = t, r.namespaceURI = e, i.length == 2 ? (r.prefix = i[0], r.localName = i[1]) : r.localName = t, p._ownerElement = r, r;
},
// Introduced in DOM Level 2:
createAttributeNS: function(e, t) {
var r = new H(), i = t.split(":");
return r.ownerDocument = this, r.nodeName = t, r.name = t, r.namespaceURI = e, r.specified = !0, i.length == 2 ? (r.prefix = i[0], r.localName = i[1]) : r.localName = t, r;
}
}, A(G, v);
function k() {
this._nsMap = {};
}
k.prototype = {
nodeType: N,
hasAttribute: function(e) {
return this.getAttributeNode(e) != null;
},
getAttribute: function(e) {
var t = this.getAttributeNode(e);
return t && t.value || "";
},
getAttributeNode: function(e) {
return this.attributes.getNamedItem(e);
},
setAttribute: function(e, t) {
var r = this.ownerDocument.createAttribute(e);
r.value = r.nodeValue = "" + t, this.setAttributeNode(r);
},
removeAttribute: function(e) {
var t = this.getAttributeNode(e);
t && this.removeAttributeNode(t);
},
//four real opeartion method
appendChild: function(e) {
return e.nodeType === M ? this.insertBefore(e, null) : Pe(this, e);
},
setAttributeNode: function(e) {
return this.attributes.setNamedItem(e);
},
setAttributeNodeNS: function(e) {
return this.attributes.setNamedItemNS(e);
},
removeAttributeNode: function(e) {
return this.attributes.removeNamedItem(e.nodeName);
},
//get real attribute name,and remove it by removeAttributeNode
removeAttributeNS: function(e, t) {
var r = this.getAttributeNodeNS(e, t);
r && this.removeAttributeNode(r);
},
hasAttributeNS: function(e, t) {
return this.getAttributeNodeNS(e, t) != null;
},
getAttributeNS: function(e, t) {
var r = this.getAttributeNodeNS(e, t);
return r && r.value || "";
},
setAttributeNS: function(e, t, r) {
var i = this.ownerDocument.createAttributeNS(e, t);
i.value = i.nodeValue = "" + r, this.setAttributeNode(i);
},
getAttributeNodeNS: function(e, t) {
return this.attributes.getNamedItemNS(e, t);
},
getElementsByTagName: function(e) {
return new S(this, function(t) {
var r = [];
return oe(t, function(i) {
i !== t && i.nodeType == N && (e === "*" || i.tagName == e) && r.push(i);
}), r;
});
},
getElementsByTagNameNS: function(e, t) {
return new S(this, function(r) {
var i = [];
return oe(r, function(p) {
p !== r && p.nodeType === N && (e === "*" || p.namespaceURI === e) && (t === "*" || p.localName == t) && i.push(p);
}), i;
});
}
}, G.prototype.getElementsByTagName = k.prototype.getElementsByTagName, G.prototype.getElementsByTagNameNS = k.prototype.getElementsByTagNameNS, A(k, v);
function H() {
}
H.prototype.nodeType = O, A(H, v);
function De() {
}
De.prototype = {
data: "",
substringData: function(e, t) {
return this.data.substring(e, e + t);
},
appendData: function(e) {
e = this.data + e, this.nodeValue = this.data = e, this.length = e.length;
},
insertData: function(e, t) {
this.replaceData(e, 0, t);
},
appendChild: function(e) {
throw new Error(L[o]);
},
deleteData: function(e, t) {
this.replaceData(e, t, "");
},
replaceData: function(e, t, r) {
var i = this.data.substring(0, e), p = this.data.substring(e + t);
r = i + r + p, this.nodeValue = this.data = r, this.length = r.length;
}
}, A(De, v);
function eu() {
}
eu.prototype = {
nodeName: "#text",
nodeType: P,
splitText: function(e) {
var t = this.data, r = t.substring(e);
t = t.substring(0, e), this.data = this.nodeValue = t, this.length = t.length;
var i = this.ownerDocument.createTextNode(r);
return this.parentNode && this.parentNode.insertBefore(i, this.nextSibling), i;
}
}, A(eu, De);
function uu() {
}
uu.prototype = {
nodeName: "#comment",
nodeType: q
}, A(uu, De);
function tu() {
}
tu.prototype = {
nodeName: "#cdata-section",
nodeType: ue
}, A(tu, De);
function Ve() {
}
Ve.prototype.nodeType = V, A(Ve, v);
function pu() {
}
pu.prototype.nodeType = Y, A(pu, v);
function hu() {
}
hu.prototype.nodeType = D, A(hu, v);
function ru() {
}
ru.prototype.nodeType = Q, A(ru, v);
function $e() {
}
$e.prototype.nodeName = "#document-fragment", $e.prototype.nodeType = M, A($e, v);
function nu() {
}
nu.prototype.nodeType = R, A(nu, v);
function Du() {
}
Du.prototype.serializeToString = function(e, t, r) {
return mu.call(e, t, r);
}, v.prototype.toString = mu;
function mu(e, t) {
var r = [], i = this.nodeType == 9 && this.documentElement || this, p = i.prefix, C = i.namespaceURI;
if (C && p == null) {
var p = i.lookupPrefix(C);
if (p == null)
var U = [
{ namespace: C, prefix: null }
//{namespace:uri,prefix:''}
];
}
return Be(this, r, e, t, U), r.join("");
}
function du(e, t, r) {
var i = e.prefix || "", p = e.namespaceURI;
if (!p || i === "xml" && p === n.XML || p === n.XMLNS)
return !1;
for (var C = r.length; C--; ) {
var U = r[C];
if (U.prefix === i)
return U.namespace !== p;
}
return !0;
}
function au(e, t, r) {
e.push(" ", t, '="', r.replace(/[<>&"\t\n\r]/g, J), '"');
}
function Be(e, t, r, i, p) {
if (p || (p = []), i)
if (e = i(e), e) {
if (typeof e == "string") {
t.push(e);
return;
}
} else
return;
switch (e.nodeType) {
case N:
var C = e.attributes, U = C.length, W = e.firstChild, ee = e.tagName;
r = n.isHTML(e.namespaceURI) || r;
var se = ee;
if (!r && !e.prefix && e.namespaceURI) {
for (var pe, le = 0; le < C.length; le++)
if (C.item(le).name === "xmlns") {
pe = C.item(le).value;
break;
}
if (!pe)
for (var me = p.length - 1; me >= 0; me--) {
var de = p[me];
if (de.prefix === "" && de.namespace === e.namespaceURI) {
pe = de.namespace;
break;
}
}
if (pe !== e.namespaceURI)
for (var me = p.length - 1; me >= 0; me--) {
var de = p[me];
if (de.namespace === e.namespaceURI) {
de.prefix && (se = de.prefix + ":" + ee);
break;
}
}
}
t.push("<", se);
for (var Ae = 0; Ae < U; Ae++) {
var ae = C.item(Ae);
ae.prefix == "xmlns" ? p.push({ prefix: ae.localName, namespace: ae.value }) : ae.nodeName == "xmlns" && p.push({ prefix: "", namespace: ae.value });
}
for (var Ae = 0; Ae < U; Ae++) {
var ae = C.item(Ae);
if (du(ae, r, p)) {
var Ee = ae.prefix || "", Re = ae.namespaceURI;
au(t, Ee ? "xmlns:" + Ee : "xmlns", Re), p.push({ prefix: Ee, namespace: Re });
}
Be(ae, t, r, i, p);
}
if (ee === se && du(e, r, p)) {
var Ee = e.prefix || "", Re = e.namespaceURI;
au(t, Ee ? "xmlns:" + Ee : "xmlns", Re), p.push({ prefix: Ee, namespace: Re });
}
if (W || r && !/^(?:meta|link|img|br|hr|input)$/i.test(ee)) {
if (t.push(">"), r && /^script$/i.test(ee))
for (; W; )
W.data ? t.push(W.data) : Be(W, t, r, i, p.slice()), W = W.nextSibling;
else
for (; W; )
Be(W, t, r, i, p.slice()), W