pixi-tiled-utils
Version:
PIXI.js Tiled utilities
1,129 lines (1,126 loc) • 129 kB
JavaScript
/*! dustjs-linkedin - v2.7.5
* https://dustjs.com/
* Copyright (c) 2016 Aleksander Williams; Released under the MIT License */
!(function (a, b) {
"function" == typeof define && define.amd && define.amd.dust === !0
? define("dust.core", [], b)
: "object" == typeof exports
? (module.exports = b())
: (a.dust = b());
})(this, function () {
function getTemplate(a, b) {
return a
? "function" == typeof a && a.template
? a.template
: dust.isTemplateFn(a)
? a
: b !== !1
? dust.cache[a]
: void 0
: void 0;
}
function load(a, b, c) {
if (!a)
return b.setError(
new Error("No template or template name provided to render"),
);
var d = getTemplate(a, dust.config.cache);
return d
? d(b, Context.wrap(c, d.templateName))
: dust.onLoad
? b.map(function (b) {
function d(a, d) {
var f;
if (a) return b.setError(a);
if (
((f =
getTemplate(d, !1) ||
getTemplate(e, dust.config.cache)),
!f)
) {
if (!dust.compile)
return b.setError(
new Error("Dust compiler not available"),
);
f = dust.loadSource(dust.compile(d, e));
}
f(b, Context.wrap(c, f.templateName)).end();
}
var e = a;
3 === dust.onLoad.length
? dust.onLoad(e, c.options, d)
: dust.onLoad(e, d);
})
: b.setError(new Error("Template Not Found: " + a));
}
function Context(a, b, c, d, e) {
void 0 === a || a instanceof Stack || (a = new Stack(a)),
(this.stack = a),
(this.global = b),
(this.options = c),
(this.blocks = d),
(this.templateName = e),
(this._isContext = !0);
}
function getWithResolvedData(a, b, c) {
return function (d) {
return a.push(d)._get(b, c);
};
}
function Stack(a, b, c, d) {
(this.tail = b),
(this.isObject = a && "object" == typeof a),
(this.head = a),
(this.index = c),
(this.of = d);
}
function Stub(a) {
(this.head = new Chunk(this)), (this.callback = a), (this.out = "");
}
function Stream() {
this.head = new Chunk(this);
}
function Chunk(a, b, c) {
(this.root = a),
(this.next = b),
(this.data = []),
(this.flushable = !1),
(this.taps = c);
}
function Tap(a, b) {
(this.head = a), (this.tail = b);
}
var dust = { version: "2.7.5" },
NONE = "NONE",
ERROR = "ERROR",
WARN = "WARN",
INFO = "INFO",
DEBUG = "DEBUG",
EMPTY_FUNC = function () {};
(dust.config = { whitespace: !1, amd: !1, cjs: !1, cache: !0 }),
(dust._aliases = {
write: "w",
end: "e",
map: "m",
render: "r",
reference: "f",
section: "s",
exists: "x",
notexists: "nx",
block: "b",
partial: "p",
helper: "h",
}),
(function () {
var a,
b,
c = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, NONE: 4 };
"undefined" != typeof console && console.log
? ((a = console.log),
(b =
"function" == typeof a
? function () {
a.apply(console, arguments);
}
: function () {
a(
Array.prototype.slice
.apply(arguments)
.join(" "),
);
}))
: (b = EMPTY_FUNC),
(dust.log = function (a, d) {
(d = d || INFO),
c[d] >= c[dust.debugLevel] && b("[DUST:" + d + "]", a);
}),
(dust.debugLevel = NONE),
"undefined" != typeof process &&
process.env &&
/\bdust\b/.test(process.env.DEBUG) &&
(dust.debugLevel = DEBUG);
})(),
(dust.helpers = {}),
(dust.cache = {}),
(dust.register = function (a, b) {
a &&
((b.templateName = a),
dust.config.cache !== !1 && (dust.cache[a] = b));
}),
(dust.render = function (a, b, c) {
var d = new Stub(c).head;
try {
load(a, d, b).end();
} catch (e) {
d.setError(e);
}
}),
(dust.stream = function (a, b) {
var c = new Stream(),
d = c.head;
return (
dust.nextTick(function () {
try {
load(a, d, b).end();
} catch (c) {
d.setError(c);
}
}),
c
);
}),
(dust.loadSource = function (source) {
return eval(source);
}),
(dust.isArray = Array.isArray
? Array.isArray
: function (a) {
return "[object Array]" === Object.prototype.toString.call(a);
}),
(dust.nextTick = (function () {
return function (a) {
setTimeout(a, 0);
};
})()),
(dust.isEmpty = function (a) {
return 0 === a ? !1 : dust.isArray(a) && !a.length ? !0 : !a;
}),
(dust.isEmptyObject = function (a) {
var b;
if (null === a) return !1;
if (void 0 === a) return !1;
if (a.length > 0) return !1;
for (b in a)
if (Object.prototype.hasOwnProperty.call(a, b)) return !1;
return !0;
}),
(dust.isTemplateFn = function (a) {
return "function" == typeof a && a.__dustBody;
}),
(dust.isThenable = function (a) {
return a && "object" == typeof a && "function" == typeof a.then;
}),
(dust.isStreamable = function (a) {
return (
a && "function" == typeof a.on && "function" == typeof a.pipe
);
}),
(dust.filter = function (a, b, c, d) {
var e, f, g, h;
if (c)
for (e = 0, f = c.length; f > e; e++)
(g = c[e]),
g.length &&
((h = dust.filters[g]),
"s" === g
? (b = null)
: "function" == typeof h
? (a = h(a, d))
: dust.log("Invalid filter `" + g + "`", WARN));
return b && (a = dust.filters[b](a, d)), a;
}),
(dust.filters = {
h: function (a) {
return dust.escapeHtml(a);
},
j: function (a) {
return dust.escapeJs(a);
},
u: encodeURI,
uc: encodeURIComponent,
js: function (a) {
return dust.escapeJSON(a);
},
jp: function (a) {
return JSON
? JSON.parse(a)
: (dust.log(
"JSON is undefined; could not parse `" + a + "`",
WARN,
),
a);
},
}),
(dust.makeBase = dust.context = function (a, b) {
return new Context(void 0, a, b);
}),
(dust.isContext = function (a) {
return "object" == typeof a && a._isContext === !0;
}),
(Context.wrap = function (a, b) {
return dust.isContext(a) ? a : new Context(a, {}, {}, null, b);
}),
(Context.prototype.get = function (a, b) {
return (
"string" == typeof a &&
("." === a[0] && ((b = !0), (a = a.substr(1))),
(a = a.split("."))),
this._get(b, a)
);
}),
(Context.prototype._get = function (a, b) {
var c,
d,
e,
f,
g,
h = this.stack || {},
i = 1;
if (((d = b[0]), (e = b.length), a && 0 === e))
(f = h), (h = h.head);
else {
if (a) h && (h = h.head ? h.head[d] : void 0);
else {
for (
;
h &&
(!h.isObject ||
((f = h.head), (c = h.head[d]), void 0 === c));
)
h = h.tail;
h = void 0 !== c ? c : this.global && this.global[d];
}
for (; h && e > i; ) {
if (dust.isThenable(h))
return h.then(getWithResolvedData(this, a, b.slice(i)));
(f = h), (h = h[b[i]]), i++;
}
}
return "function" == typeof h
? ((g = function () {
try {
return h.apply(f, arguments);
} catch (a) {
throw (dust.log(a, ERROR), a);
}
}),
(g.__dustBody = !!h.__dustBody),
g)
: (void 0 === h &&
dust.log(
"Cannot find reference `{" +
b.join(".") +
"}` in template `" +
this.getTemplateName() +
"`",
INFO,
),
h);
}),
(Context.prototype.getPath = function (a, b) {
return this._get(a, b);
}),
(Context.prototype.push = function (a, b, c) {
return void 0 === a
? (dust.log(
"Not pushing an undefined variable onto the context",
INFO,
),
this)
: this.rebase(new Stack(a, this.stack, b, c));
}),
(Context.prototype.pop = function () {
var a = this.current();
return (this.stack = this.stack && this.stack.tail), a;
}),
(Context.prototype.rebase = function (a) {
return new Context(
a,
this.global,
this.options,
this.blocks,
this.getTemplateName(),
);
}),
(Context.prototype.clone = function () {
var a = this.rebase();
return (a.stack = this.stack), a;
}),
(Context.prototype.current = function () {
return this.stack && this.stack.head;
}),
(Context.prototype.getBlock = function (a) {
var b, c, d;
if (
("function" == typeof a &&
(a = a(new Chunk(), this).data.join("")),
(b = this.blocks),
!b)
)
return (
dust.log(
"No blocks for context `" +
a +
"` in template `" +
this.getTemplateName() +
"`",
DEBUG,
),
!1
);
for (c = b.length; c--; ) if ((d = b[c][a])) return d;
return (
dust.log(
"Malformed template `" +
this.getTemplateName() +
"` was missing one or more blocks.",
),
!1
);
}),
(Context.prototype.shiftBlocks = function (a) {
var b,
c = this.blocks;
return a
? ((b = c ? c.concat([a]) : [a]),
new Context(
this.stack,
this.global,
this.options,
b,
this.getTemplateName(),
))
: this;
}),
(Context.prototype.resolve = function (a) {
var b;
return "function" != typeof a
? a
: ((b = new Chunk().render(a, this)),
b instanceof Chunk ? b.data.join("") : b);
}),
(Context.prototype.getTemplateName = function () {
return this.templateName;
}),
(Stub.prototype.flush = function () {
for (var a = this.head; a; ) {
if (!a.flushable)
return a.error
? (this.callback(a.error),
dust.log(
"Rendering failed with error `" + a.error + "`",
ERROR,
),
void (this.flush = EMPTY_FUNC))
: void 0;
(this.out += a.data.join("")), (a = a.next), (this.head = a);
}
this.callback(null, this.out);
}),
(Stream.prototype.flush = function () {
for (var a = this.head; a; ) {
if (!a.flushable)
return a.error
? (this.emit("error", a.error),
this.emit("end"),
dust.log(
"Streaming failed with error `" + a.error + "`",
ERROR,
),
void (this.flush = EMPTY_FUNC))
: void 0;
this.emit("data", a.data.join("")),
(a = a.next),
(this.head = a);
}
this.emit("end");
}),
(Stream.prototype.emit = function (a, b) {
var c,
d,
e = this.events || {},
f = e[a] || [];
if (!f.length)
return (
dust.log(
"Stream broadcasting, but no listeners for `" + a + "`",
DEBUG,
),
!1
);
for (f = f.slice(0), c = 0, d = f.length; d > c; c++) f[c](b);
return !0;
}),
(Stream.prototype.on = function (a, b) {
var c = (this.events = this.events || {}),
d = (c[a] = c[a] || []);
return (
"function" != typeof b
? dust.log(
"No callback function provided for `" +
a +
"` event listener",
WARN,
)
: d.push(b),
this
);
}),
(Stream.prototype.pipe = function (a) {
if ("function" != typeof a.write || "function" != typeof a.end)
return (
dust.log("Incompatible stream passed to `pipe`", WARN), this
);
var b = !1;
return (
"function" == typeof a.emit && a.emit("pipe", this),
"function" == typeof a.on &&
a.on("error", function () {
b = !0;
}),
this.on("data", function (c) {
if (!b)
try {
a.write(c, "utf8");
} catch (d) {
dust.log(d, ERROR);
}
}).on("end", function () {
if (!b)
try {
a.end(), (b = !0);
} catch (c) {
dust.log(c, ERROR);
}
})
);
}),
(Chunk.prototype.write = function (a) {
var b = this.taps;
return b && (a = b.go(a)), this.data.push(a), this;
}),
(Chunk.prototype.end = function (a) {
return (
a && this.write(a),
(this.flushable = !0),
this.root.flush(),
this
);
}),
(Chunk.prototype.map = function (a) {
var b = new Chunk(this.root, this.next, this.taps),
c = new Chunk(this.root, b, this.taps);
(this.next = c), (this.flushable = !0);
try {
a(c);
} catch (d) {
dust.log(d, ERROR), c.setError(d);
}
return b;
}),
(Chunk.prototype.tap = function (a) {
var b = this.taps;
return (this.taps = b ? b.push(a) : new Tap(a)), this;
}),
(Chunk.prototype.untap = function () {
return (this.taps = this.taps.tail), this;
}),
(Chunk.prototype.render = function (a, b) {
return a(this, b);
}),
(Chunk.prototype.reference = function (a, b, c, d) {
return "function" == typeof a
? ((a = a.apply(b.current(), [
this,
b,
null,
{ auto: c, filters: d },
])),
a instanceof Chunk ? a : this.reference(a, b, c, d))
: dust.isThenable(a)
? this.await(a, b, null, c, d)
: dust.isStreamable(a)
? this.stream(a, b, null, c, d)
: dust.isEmpty(a)
? this
: this.write(dust.filter(a, c, d, b));
}),
(Chunk.prototype.section = function (a, b, c, d) {
var e,
f,
g,
h = c.block,
i = c["else"],
j = this;
if ("function" == typeof a && !dust.isTemplateFn(a)) {
try {
a = a.apply(b.current(), [this, b, c, d]);
} catch (k) {
return dust.log(k, ERROR), this.setError(k);
}
if (a instanceof Chunk) return a;
}
if (dust.isEmptyObject(c)) return j;
if ((dust.isEmptyObject(d) || (b = b.push(d)), dust.isArray(a))) {
if (h) {
if (((f = a.length), f > 0)) {
for (
g = (b.stack && b.stack.head) || {},
g.$len = f,
e = 0;
f > e;
e++
)
(g.$idx = e), (j = h(j, b.push(a[e], e, f)));
return (g.$idx = void 0), (g.$len = void 0), j;
}
if (i) return i(this, b);
}
} else {
if (dust.isThenable(a)) return this.await(a, b, c);
if (dust.isStreamable(a)) return this.stream(a, b, c);
if (a === !0) {
if (h) return h(this, b);
} else if (a || 0 === a) {
if (h) return h(this, b.push(a));
} else if (i) return i(this, b);
}
return (
dust.log(
"Section without corresponding key in template `" +
b.getTemplateName() +
"`",
DEBUG,
),
this
);
}),
(Chunk.prototype.exists = function (a, b, c) {
var d = c.block,
e = c["else"];
if (dust.isEmpty(a)) {
if (e) return e(this, b);
} else {
if (d) return d(this, b);
dust.log(
"No block for exists check in template `" +
b.getTemplateName() +
"`",
DEBUG,
);
}
return this;
}),
(Chunk.prototype.notexists = function (a, b, c) {
var d = c.block,
e = c["else"];
if (dust.isEmpty(a)) {
if (d) return d(this, b);
dust.log(
"No block for not-exists check in template `" +
b.getTemplateName() +
"`",
DEBUG,
);
} else if (e) return e(this, b);
return this;
}),
(Chunk.prototype.block = function (a, b, c) {
var d = a || c.block;
return d ? d(this, b) : this;
}),
(Chunk.prototype.partial = function (a, b, c, d) {
var e;
return (
void 0 === d && ((d = c), (c = b)),
dust.isEmptyObject(d) ||
((c = c.clone()), (e = c.pop()), (c = c.push(d).push(e))),
dust.isTemplateFn(a)
? this.capture(a, b, function (a, b) {
(c.templateName = a), load(a, b, c).end();
})
: ((c.templateName = a), load(a, this, c))
);
}),
(Chunk.prototype.helper = function (a, b, c, d, e) {
var f,
g = this,
h = d.filters;
if ((void 0 === e && (e = "h"), !dust.helpers[a]))
return dust.log("Helper `" + a + "` does not exist", WARN), g;
try {
return (
(f = dust.helpers[a](g, b, c, d)),
f instanceof Chunk
? f
: ("string" == typeof h && (h = h.split("|")),
dust.isEmptyObject(c)
? g.reference(f, b, e, h)
: g.section(f, b, c, d))
);
} catch (i) {
return (
dust.log(
"Error in helper `" + a + "`: " + i.message,
ERROR,
),
g.setError(i)
);
}
}),
(Chunk.prototype.await = function (a, b, c, d, e) {
return this.map(function (f) {
a.then(
function (a) {
(f = c ? f.section(a, b, c) : f.reference(a, b, d, e)),
f.end();
},
function (a) {
var d = c && c.error;
d
? f.render(d, b.push(a)).end()
: (dust.log(
"Unhandled promise rejection in `" +
b.getTemplateName() +
"`",
INFO,
),
f.end());
},
);
});
}),
(Chunk.prototype.stream = function (a, b, c, d, e) {
var f = c && c.block,
g = c && c.error;
return this.map(function (h) {
var i = !1;
a.on("data", function (a) {
i ||
(f
? (h = h.map(function (c) {
c.render(f, b.push(a)).end();
}))
: c || (h = h.reference(a, b, d, e)));
})
.on("error", function (a) {
i ||
(g
? h.render(g, b.push(a))
: dust.log(
"Unhandled stream error in `" +
b.getTemplateName() +
"`",
INFO,
),
i || ((i = !0), h.end()));
})
.on("end", function () {
i || ((i = !0), h.end());
});
});
}),
(Chunk.prototype.capture = function (a, b, c) {
return this.map(function (d) {
var e = new Stub(function (a, b) {
a ? d.setError(a) : c(b, d);
});
a(e.head, b).end();
});
}),
(Chunk.prototype.setError = function (a) {
return (this.error = a), this.root.flush(), this;
});
for (var f in Chunk.prototype)
dust._aliases[f] &&
(Chunk.prototype[dust._aliases[f]] = Chunk.prototype[f]);
(Tap.prototype.push = function (a) {
return new Tap(a, this);
}),
(Tap.prototype.go = function (a) {
for (var b = this; b; ) (a = b.head(a)), (b = b.tail);
return a;
});
var HCHARS = /[&<>"']/,
AMP = /&/g,
LT = /</g,
GT = />/g,
QUOT = /\"/g,
SQUOT = /\'/g;
dust.escapeHtml = function (a) {
return "string" == typeof a || (a && "function" == typeof a.toString)
? ("string" != typeof a && (a = a.toString()),
HCHARS.test(a)
? a
.replace(AMP, "&")
.replace(LT, "<")
.replace(GT, ">")
.replace(QUOT, """)
.replace(SQUOT, "'")
: a)
: a;
};
var BS = /\\/g,
FS = /\//g,
CR = /\r/g,
LS = /\u2028/g,
PS = /\u2029/g,
NL = /\n/g,
LF = /\f/g,
SQ = /'/g,
DQ = /"/g,
TB = /\t/g;
return (
(dust.escapeJs = function (a) {
return "string" == typeof a
? a
.replace(BS, "\\\\")
.replace(FS, "\\/")
.replace(DQ, '\\"')
.replace(SQ, "\\'")
.replace(CR, "\\r")
.replace(LS, "\\u2028")
.replace(PS, "\\u2029")
.replace(NL, "\\n")
.replace(LF, "\\f")
.replace(TB, "\\t")
: a;
}),
(dust.escapeJSON = function (a) {
return JSON
? JSON.stringify(a)
.replace(LS, "\\u2028")
.replace(PS, "\\u2029")
.replace(LT, "\\u003c")
: (dust.log(
"JSON is undefined; could not escape `" + a + "`",
WARN,
),
a);
}),
dust
);
}),
"function" == typeof define &&
define.amd &&
define.amd.dust === !0 &&
define(["require", "dust.core"], function (require, dust) {
return (
(dust.onLoad = function (a, b) {
require([a], function () {
b();
});
}),
dust
);
});
/*! dustjs-helpers - v1.7.4
* https://dustjs.com/
* Copyright (c) 2017 Aleksander Williams; Released under the MIT License */
!(function (a, b) {
"function" == typeof define && define.amd && define.amd.dust === !0
? define(["dust.core"], b)
: "object" == typeof exports
? ((module.exports = b(require("dustjs-linkedin"))),
(module.exports.registerWith = b))
: b(a.dust);
})(this, function (dust) {
function a(a, b, c) {
(c = c || "INFO"), (a = a ? "{@" + a + "}: " : ""), dust.log(a + b, c);
}
function b(b) {
k[b] ||
(a(
b,
"Deprecation warning: " +
b +
" is deprecated and will be removed in a future version of dustjs-helpers",
"WARN",
),
a(
null,
"For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#" +
b.replace(/\W+/g, ""),
"WARN",
),
(k[b] = !0));
}
function c(a) {
return (
a.stack.tail &&
a.stack.tail.head &&
"undefined" != typeof a.stack.tail.head.__select__
);
}
function d(a) {
return c(a) && a.get("__select__");
}
function e(a, b) {
var c,
d = a.stack.head,
e = a.rebase();
a.stack && a.stack.tail && (e.stack = a.stack.tail);
var f = {
isPending: !1,
isResolved: !1,
isDeferredComplete: !1,
deferreds: [],
};
for (c in b) f[c] = b[c];
return e.push({ __select__: f }).push(d, a.stack.index, a.stack.of);
}
function f(a) {
var b, c;
if (((a.isDeferredPending = !0), a.deferreds.length))
for (
a.isDeferredComplete = !0, b = 0, c = a.deferreds.length;
c > b;
b++
)
a.deferreds[b]();
a.isDeferredPending = !1;
}
function g(a, b) {
return "function" == typeof b
? b
.toString()
.replace(/(^\s+|\s+$)/gm, "")
.replace(/\n/gm, "")
.replace(/,\s*/gm, ", ")
.replace(/\)\{/gm, ") {")
: b;
}
function h(a, b) {
return function (c, d, e, f) {
return i(c, d, e, f, a, b);
};
}
function i(b, c, e, f, g, h) {
var i,
k,
l,
m,
n = e.block,
o = e["else"],
p = d(c) || {};
if (p.isResolved && !p.isDeferredPending) return b;
if (f.hasOwnProperty("key")) k = f.key;
else {
if (!p.hasOwnProperty("key"))
return a(g, "No key specified", "WARN"), b;
k = p.key;
}
return (
(m = f.type || p.type),
(k = j(c.resolve(k), m)),
(l = j(c.resolve(f.value), m)),
h(k, l)
? (p.isPending || ((i = !0), (p.isPending = !0)),
n && (b = b.render(n, c)),
i && (p.isResolved = !0))
: o && (b = b.render(o, c)),
b
);
}
function j(a, b) {
switch ((b && (b = b.toLowerCase()), b)) {
case "number":
return +a;
case "string":
return String(a);
case "boolean":
return (a = "false" === a ? !1 : a), Boolean(a);
case "date":
return new Date(a);
}
return a;
}
var k = {},
l = {
tap: function (a, c, d) {
return b("tap"), d.resolve(a);
},
sep: function (a, b, c) {
var d = c.block;
return b.stack.index === b.stack.of - 1 ? a : d ? d(a, b) : a;
},
first: function (a, b, c) {
return 0 === b.stack.index ? c.block(a, b) : a;
},
last: function (a, b, c) {
return b.stack.index === b.stack.of - 1 ? c.block(a, b) : a;
},
contextDump: function (b, c, d, e) {
var f,
h,
i = c.resolve(e.to),
j = c.resolve(e.key);
switch (j) {
case "full":
f = c.stack;
break;
default:
f = c.stack.head;
}
switch (((h = JSON.stringify(f, g, 2)), i)) {
case "console":
a("contextDump", h);
break;
default:
(h = h.replace(/</g, "\\u003c")), (b = b.write(h));
}
return b;
},
math: function (b, c, g, h) {
var i,
j = h.key,
k = h.method,
l = h.operand,
m = h.round;
if (!h.hasOwnProperty("key") || !h.method)
return (
a(
"math",
"`key` or `method` was not provided",
"ERROR",
),
b
);
switch (
((j = parseFloat(c.resolve(j))),
(l = parseFloat(c.resolve(l))),
k)
) {
case "mod":
0 === l && a("math", "Division by 0", "ERROR"),
(i = j % l);
break;
case "add":
i = j + l;
break;
case "subtract":
i = j - l;
break;
case "multiply":
i = j * l;
break;
case "divide":
0 === l && a("math", "Division by 0", "ERROR"),
(i = j / l);
break;
case "ceil":
case "floor":
case "round":
case "abs":
i = Math[k](j);
break;
case "toint":
i = parseInt(j, 10);
break;
default:
a(
"math",
"Method `" + k + "` is not supported",
"ERROR",
);
}
return (
"undefined" != typeof i &&
(m && (i = Math.round(i)),
g && g.block
? ((c = e(c, { key: i })),
(b = b.render(g.block, c)),
f(d(c)))
: (b = b.write(i))),
b
);
},
select: function (b, c, g, h) {
var i = g.block,
j = {};
return (
h.hasOwnProperty("key") && (j.key = c.resolve(h.key)),
h.hasOwnProperty("type") && (j.type = h.type),
i
? ((c = e(c, j)), (b = b.render(i, c)), f(d(c)))
: a("select", "Missing body block", "WARN"),
b
);
},
eq: h("eq", function (a, b) {
return a === b;
}),
ne: h("ne", function (a, b) {
return a !== b;
}),
lt: h("lt", function (a, b) {
return b > a;
}),
lte: h("lte", function (a, b) {
return b >= a;
}),
gt: h("gt", function (a, b) {
return a > b;
}),
gte: h("gte", function (a, b) {
return a >= b;
}),
any: function (b, c, e) {
var f = d(c);
return (
f
? f.isDeferredComplete
? a(
"any",
"Must not be nested inside {@any} or {@none} block",
"ERROR",
)
: (b = b.map(function (a) {
f.deferreds.push(function () {
f.isResolved &&
(a = a.render(e.block, c)),
a.end();
});
}))
: a(
"any",
"Must be used inside a {@select} block",
"ERROR",
),
b
);
},
none: function (b, c, e) {
var f = d(c);
return (
f
? f.isDeferredComplete
? a(
"none",
"Must not be nested inside {@any} or {@none} block",
"ERROR",
)
: (b = b.map(function (a) {
f.deferreds.push(function () {
f.isResolved ||
(a = a.render(e.block, c)),
a.end();
});
}))
: a(
"none",
"Must be used inside a {@select} block",
"ERROR",
),
b
);
},
size: function (a, b, c, d) {
var e,
f,
g = d.key;
if (((g = b.resolve(d.key)), g && g !== !0))
if (dust.isArray(g)) e = g.length;
else if (!isNaN(parseFloat(g)) && isFinite(g)) e = g;
else if ("object" == typeof g) {
e = 0;
for (f in g) g.hasOwnProperty(f) && e++;
} else e = (g + "").length;
else e = 0;
return a.write(e);
},
};
for (var m in l) dust.helpers[m] = l[m];
return dust;
});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.page=e()}(this,function(){"use strict";function t(t){return a(r(t))}var p=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},i=c,e=r,n=a,o=h,u=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^()])+)\\))?|\\(((?:\\\\.|[^()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function r(t){for(var e=[],n=0,i=0,o="";null!=(a=u.exec(t));){var r,a,s,h=a[0],c=a[1],p=a.index;o+=t.slice(i,p),i=p+h.length,c?o+=c[1]:(o&&(e.push(o),o=""),s=a[2],r=a[3],p=a[4],h=a[5],c=a[6],a=a[7],e.push({name:r||n++,prefix:s||"",delimiter:s=s||"/",optional:"?"===c||"*"===c,repeat:"+"===c||"*"===c,pattern:(p||h||(a?".*":"[^"+s+"]+?")).replace(/([=!:$\/()])/g,"\\$1")}))}return i<t.length&&(o+=t.substr(i)),o&&e.push(o),e}function a(h){for(var c=new Array(h.length),t=0;t<h.length;t++)"object"==typeof h[t]&&(c[t]=new RegExp("^"+h[t].pattern+"$"));return function(t){for(var e="",n=t||{},i=0;i<h.length;i++){var o=h[i];if("string"!=typeof o){var r,a=n[o.name];if(null==a){if(o.optional)continue;throw new TypeError('Expected "'+o.name+'" to be defined')}if(p(a)){if(!o.repeat)throw new TypeError('Expected "'+o.name+'" to not repeat, but received "'+a+'"');if(0===a.length){if(o.optional)continue;throw new TypeError('Expected "'+o.name+'" to not be empty')}for(var s=0;s<a.length;s++){if(r=encodeURIComponent(a[s]),!c[i].test(r))throw new TypeError('Expected all "'+o.name+'" to match "'+o.pattern+'", but received "'+r+'"');e+=(0===s?o.prefix:o.delimiter)+r}}else{if(r=encodeURIComponent(a),!c[i].test(r))throw new TypeError('Expected "'+o.name+'" to match "'+o.pattern+'", but received "'+r+'"');e+=o.prefix+r}}else e+=o}return e}}function d(t){return t.replace(/([.+*?=^!:${}()[\]|\/])/g,"\\$1")}function s(t,e){return t.keys=e,t}function l(t){return t.sensitive?"":"i"}function h(t,e){for(var n=(e=e||{}).strict,i=!1!==e.end,o="",r=t[t.length-1],r="string"==typeof r&&/\/$/.test(r),a=0;a<t.length;a++){var s,h,c=t[a];"string"==typeof c?o+=d(c):(s=d(c.prefix),h=c.pattern,c.repeat&&(h+="(?:"+s+h+")*"),o+=h=c.optional?s?"(?:"+s+"("+h+"))?":"("+h+")?":s+"("+h+")")}return n||(o=(r?o.slice(0,-2):o)+"(?:\\/(?=$))?"),o+=i?"$":n&&r?"":"(?=\\/|$)",new RegExp("^"+o,l(e))}function c(t,e,n){return p(e=e||[])?n=n||{}:(n=e,e=[]),t instanceof RegExp?function(t,e){var n=t.source.match(/\((?!\?)/g);if(n)for(var i=0;i<n.length;i++)e.push({name:i,prefix:null,delimiter:null,optional:!1,repeat:!1,pattern:null});return s(t,e)}(t,e):(p(t)?function(t,e,n){for(var i=[],o=0;o<t.length;o++)i.push(c(t[o],e,n).source);return s(new RegExp("(?:"+i.join("|")+")",l(n)),e)}:function(t,e,n){for(var i=r(t),n=h(i,n),o=0;o<i.length;o++)"string"!=typeof i[o]&&e.push(i[o]);return s(n,e)})(t,e,n)}i.parse=e,i.compile=t,i.tokensToFunction=n,i.tokensToRegExp=o;var f,g="undefined"!=typeof document,m="undefined"!=typeof window,w="undefined"!=typeof history,v="undefined"!=typeof process,y=g&&document.ontouchstart?"touchstart":"click",_=m&&!(!window.history.location&&!window.location);function b(){this.callbacks=[],this.exits=[],this.current="",this.len=0,this._decodeURLComponents=!0,this._base="",this._strict=!1,this._running=!1,this._hashbang=!1,this.clickHandler=this.clickHandler.bind(this),this._onpopstate=this._onpopstate.bind(this)}function x(t,e){if("function"==typeof t)return x.call(this,"*",t);if("function"==typeof e)for(var n=new R(t,null,this),i=1;i<arguments.length;++i)this.callbacks.push(n.middleware(arguments[i]));else"string"==typeof t?this["string"==typeof e?"redirect":"show"](t,e):this.start(t)}function E(t,e,n){var i=this.page=n||x,o=i._window,r=i._hashbang,a=t.replace(document.baseURI.split("/").filter(t=>t.length).pop()+"/",""),s=i._getBase(),n=(a="/"===a[0]&&0!==a.indexOf(s)?s+(r?"#!":"")+a:a).indexOf("?");this.canonicalPath=t;s=new RegExp("^"+s.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1"));this.path=a.replace(s,"")||"/",r&&(this.path=this.path.replace("#!","")||"/"),this.title=g&&o.document.title,this.state=e||{},this.state.path=a,this.querystring=~n?i._decodeURLEncodedURIComponent(a.slice(n+1)):"",this.pathname=i._decodeURLEncodedURIComponent(~n?a.slice(0,n):a),this.params={},this.hash="",r||~this.path.indexOf("#")&&(r=this.path.split("#"),this.path=this.pathname=r[0],this.hash=i._decodeURLEncodedURIComponent(r[1])||"",this.querystring=this.querystring.split("#")[0])}function R(t,e,n){this.page=n||k;e=e||{};e.strict=e.strict||n._strict,this.path="*"===t?"(.*)":t,this.method="GET",this.regexp=i(this.path,this.keys=[],e)}b.prototype.configure=function(t){t=t||{};this._window=t.window||m&&window,this._decodeURLComponents=!1!==t.decodeURLComponents,this._popstate=!1!==t.popstate&&m,this._click=!1!==t.click&&g,this._hashbang=!!t.hashbang;t=this._window;this._popstate?t.addEventListener("popstate",this._onpopstate,!1):m&&t.removeEventListener("popstate",this._onpopstate,!1),this._click?t.document.addEventListener(y,this.clickHandler,!1):g&&t.document.removeEventListener(y,this.clickHandler,!1),this._hashbang&&m&&!w?t.addEventListener("hashchange",this._onpopstate,!1):m&&t.removeEventListener("hashchange",this._onpopstate,!1)},b.prototype.base=function(t){if(0===arguments.length)return this._base;this._base=t},b.prototype._getBase=function(){var t=this._base;if(t)return t;var e=m&&this._window&&this._window.location;return t=m&&this._hashbang&&e&&"file:"===e.protocol?e.pathname:t},b.prototype.strict=function(t){if(0===arguments.length)return this._strict;this._strict=t},b.prototype.start=function(t){var e,t=t||{};this.configure(t),!1!==t.dispatch&&(this._running=!0,_&&(e=this._window.location,e=this._hashbang&&~e.hash.indexOf("#!")?e.hash.substr(2)+e.search:this._hashbang?e.search+e.hash:e.pathname+e.search+e.hash),this.replace(e,null,!0,t.dispatch))},b.prototype.stop=function(){var t;this._running&&(this.current="",this.len=0,this._running=!1,t=this._window,this._click&&t.document.removeEventListener(y,this.clickHandler,!1),m&&t.removeEventListener("popstate",this._onpopstate,!1),m&&t.removeEventListener("hashchange",this._onpopstate,!1))},b.prototype.show=function(t,e,n,i){t=new E(t,e,this),e=this.prevContext;return this.prevContext=t,this.current=t.path,!1!==n&&this.dispatch(t,e),!1!==t.handled&&!1!==i&&t.pushState(),t},b.prototype.back=function(t,e){var n,i=this;0<this.len?(n=this._window,w&&n.history.back(),this.len--):t?setTimeout(function(){i.show(t,e)}):setTimeout(function(){i.show(i._getBase(),e)})},b.prototype.redirect=function(t,e){var n=this;"string"==typeof t&&"string"==typeof e&&x.call(this,t,function(t){setTimeout(function(){n.replace(e)},0)}),"string"==typeof t&&void 0===e&&setTimeout(function(){n.replace(t)},0)},b.prototype.replace=function(t,e,n,i){t=new E(t,e,this),e=this.prevContext;return this.prevContext=t,this.current=t.path,t.init=n,t.save(),!1!==i&&this.dispatch(t,e),t},b.prototype.dispatch=function(e,n){var i=0,o=0,r=this;function a(){var t=r.callbacks[i++];if(e.path===r.current)return t?void t(e,a):function(t){var e;t.handled||(e=this._window,(this._hashbang?_&&this._getBase()+e.location.hash.replace("#!",""):_&&e.location.pathname+e.location.search)!==t.canonicalPath&&(this.stop(),t.handled=!1,_&&(e.location.href=t.canonicalPath)))}.call(r,e);e.handled=!1}(n?function t(){var e=r.exits[o++];if(!e)return a();e(n,t)}:a)()},b.prototype.exit=function(t,e){if("function"==typeof t)return this.exit("*",t);for(var n=new R(t,null,this),i=1;i<arguments.length;++i)this.exits.push(n.middleware(arguments[i]))},b.prototype.clickHandler=function(t){if(1===this._which(t)&&!(t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented)){var e,n,i,o=t.target,r=t.path||(t.composedPath?t.composedPath():null);if(r)for(var a=0;a<r.length;a++)if(r[a].nodeName&&"A"===r[a].nodeName.toUpperCase()&&r[a].href){o=r[a];break}for(;o&&"A"!==o.nodeName.toUpperCase();)o=o.parentNode;o&&"A"===o.nodeName.toUpperCase()&&(i="object"==typeof o.href&&"SVGAnimatedString"===o.href.constructor.name,o.hasAttribute("download")||"external"===o.getAttribute("rel")||(n=o.getAttribute("href"),!this._hashbang&&this._samePath(o)&&(o.hash||"#"===n)||n&&-1<n.indexOf("mailto:")||(i?o.target.baseVal:o.target)||(i||this.sameOrigin(o.href))&&(e="/"!==(e=i?o.href.baseVal:o.pathname+o.search+(o.hash||""))[0]?"/"+e:e,n=e=v&&e.match(/^\/[a-zA-Z]:\//)?e.replace(/^\/[a-zA-Z]:\//,"/"):e,i=this._getBase(),0===e.indexOf(i)&&(e=e.substr(i.length)),this._hashbang&&(e=e.replace("#!","")),(!i||n!==e||_&&"file:"===this._window.location.protocol)&&(t.preventDefault(),this.show(n)))))}},b.prototype._onpopstate=(f=!1,m?(g&&"complete"===document.readyState?f=!0:window.addEventListener("load",function(){setTimeout(function(){f=!0},0)}),function(t){var e;f&&(t.state?(e=t.state.path,this.replace(e,t.state)):_&&(t=this._window.location,this.show(t.pathname+t.search+t.hash,void 0,void 0,!1)))}):function(){}),b.prototype._which=function(t){return null==(t=t||m&&this._window.event).which?t.button:t.which},b.prototype._toURL=function(t){var e=this._window;if("function"==typeof URL&&_)return new URL(t,e.location.toString());if(g){e=e.document.createElement("a");return e.href=t,e}},b.prototype.sameOrigin=function(t){if(!t||!_)return!1;var e=this._toURL(t),t=this._window.location;return t.protocol===e.protocol&&t.hostname===e.hostname&&t.port===e.port},b.prototype._samePath=function(t){if(!_)return!1;var e=this._window.location;return t.pathname===e.pathname&&t.search===e.search},b.prototype._decodeURLEncodedURIComponent=function(t){return"string"==typeof t&&this._decodeURLComponents?decodeURIComponent(t.replace(/\+/g," ")):t},E.prototype.pushState=function(){var t=this.page,e=t._window,n=t._hashbang;t.len++,w&&e.history.pushState(this.state,this.title,n&&"/"!==this.path?"#!"+this.path:this.canonicalPath)},E.prototype.save=function(){var t=this.page;w&&"file:"!==t._window.location.protocol&&t._window.history.replaceState(this.state,this.title,t._hashbang&&"/"!==this.path?"#!"+this.path:this.canonicalPath)},R.prototype.middleware=function(n){var i=this;return function(t,e){if(i.match(t.path,t.params))return n(t,e);e()}},R.prototype.match=function(t,e){var n=this.keys,i=t.indexOf("?"),t=~i?t.slice(0,i):t,o=this.regexp.exec(decodeURIComponent(t));if(!o)return!1;for(var r=1,a=o.length;r<a;++r){v