]*)['"]\s*>([\S\s]*?)<\/yield\s*>/ig;
var reYieldDest = /|>([\S\s]*?)<\/yield\s*>)/ig;
var rootEls = { tr: 'tbody', th: 'tr', td: 'tr', col: 'colgroup' };
var tblTags = IE_VERSION && IE_VERSION < 10 ? RE_SPECIAL_TAGS : RE_SPECIAL_TAGS_NO_OPTION;
var GENERIC = 'div';
var SVG = 'svg';
/*
Creates the root element for table or select child elements:
tr/th/td/thead/tfoot/tbody/caption/col/colgroup/option/optgroup
*/
function specialTags(el, tmpl, tagName) {
var
select = tagName[0] === 'o',
parent = select ? 'select>' : 'table>';
// trim() is important here, this ensures we don't have artifacts,
// so we can check if we have only one element inside the parent
el.innerHTML = '<' + parent + tmpl.trim() + '' + parent;
parent = el.firstChild;
// returns the immediate parent if tr/th/td/col is the only element, if not
// returns the whole tree, as this can include additional elements
/* istanbul ignore next */
if (select) {
parent.selectedIndex = -1; // for IE9, compatible w/current riot behavior
} else {
// avoids insertion of cointainer inside container (ex: tbody inside tbody)
var tname = rootEls[tagName];
if (tname && parent.childElementCount === 1) { parent = $(tname, parent); }
}
return parent
}
/*
Replace the yield tag from any tag template with the innerHTML of the
original tag in the page
*/
function replaceYield(tmpl, html) {
// do nothing if no yield
if (!reHasYield.test(tmpl)) { return tmpl }
// be careful with #1343 - string on the source having `$1`
var src = {};
html = html && html.replace(reYieldSrc, function (_, ref, text) {
src[ref] = src[ref] || text; // preserve first definition
return ''
}).trim();
return tmpl
.replace(reYieldDest, function (_, ref, def) { // yield with from - to attrs
return src[ref] || def || ''
})
.replace(reYieldAll, function (_, def) { // yield without any "from"
return html || def || ''
})
}
/**
* Creates a DOM element to wrap the given content. Normally an `DIV`, but can be
* also a `TABLE`, `SELECT`, `TBODY`, `TR`, or `COLGROUP` element.
*
* @param { String } tmpl - The template coming from the custom tag definition
* @param { String } html - HTML content that comes from the DOM element where you
* will mount the tag, mostly the original tag in the page
* @param { Boolean } isSvg - true if the root node is an svg
* @returns { HTMLElement } DOM element with _tmpl_ merged through `YIELD` with the _html_.
*/
function mkdom(tmpl, html, isSvg$$1) {
var match = tmpl && tmpl.match(/^\s*<([-\w]+)/);
var tagName = match && match[1].toLowerCase();
var el = mkEl(isSvg$$1 ? SVG : GENERIC);
// replace all the yield tags with the tag inner html
tmpl = replaceYield(tmpl, html);
/* istanbul ignore next */
if (tblTags.test(tagName))
{ el = specialTags(el, tmpl, tagName); }
else
{ setInnerHTML(el, tmpl, isSvg$$1); }
return el
}
/**
* Another way to create a riot tag a bit more es6 friendly
* @param { HTMLElement } el - tag DOM selector or DOM node/s
* @param { Object } opts - tag logic
* @returns { Tag } new riot tag instance
*/
function Tag$1(el, opts) {
// get the tag properties from the class constructor
var ref = this;
var name = ref.name;
var tmpl = ref.tmpl;
var css = ref.css;
var attrs = ref.attrs;
var onCreate = ref.onCreate;
// register a new tag and cache the class prototype
if (!__TAG_IMPL[name]) {
tag$1(name, tmpl, css, attrs, onCreate);
// cache the class constructor
__TAG_IMPL[name].class = this.constructor;
}
// mount the tag using the class instance
mountTo(el, name, opts, this);
// inject the component css
if (css) { styleManager.inject(); }
return this
}
/**
* Create a new riot tag implementation
* @param { String } name - name/id of the new riot tag
* @param { String } tmpl - tag template
* @param { String } css - custom tag css
* @param { String } attrs - root tag attributes
* @param { Function } fn - user function
* @returns { String } name/id of the tag just created
*/
function tag$1(name, tmpl, css, attrs, fn) {
if (isFunction(attrs)) {
fn = attrs;
if (/^[\w-]+\s?=/.test(css)) {
attrs = css;
css = '';
} else
{ attrs = ''; }
}
if (css) {
if (isFunction(css))
{ fn = css; }
else
{ styleManager.add(css); }
}
name = name.toLowerCase();
__TAG_IMPL[name] = { name: name, tmpl: tmpl, attrs: attrs, fn: fn };
return name
}
/**
* Create a new riot tag implementation (for use by the compiler)
* @param { String } name - name/id of the new riot tag
* @param { String } tmpl - tag template
* @param { String } css - custom tag css
* @param { String } attrs - root tag attributes
* @param { Function } fn - user function
* @returns { String } name/id of the tag just created
*/
function tag2$1(name, tmpl, css, attrs, fn) {
if (css) { styleManager.add(css, name); }
__TAG_IMPL[name] = { name: name, tmpl: tmpl, attrs: attrs, fn: fn };
return name
}
/**
* Mount a tag using a specific tag implementation
* @param { * } selector - tag DOM selector or DOM node/s
* @param { String } tagName - tag implementation name
* @param { Object } opts - tag logic
* @returns { Array } new tags instances
*/
function mount$2(selector, tagName, opts) {
var tags = [];
var elem, allTags;
function pushTagsTo(root) {
if (root.tagName) {
var riotTag = getAttr(root, IS_DIRECTIVE), tag;
// have tagName? force riot-tag to be the same
if (tagName && riotTag !== tagName) {
riotTag = tagName;
setAttr(root, IS_DIRECTIVE, tagName);
}
tag = mountTo(root, riotTag || root.tagName.toLowerCase(), opts);
if (tag)
{ tags.push(tag); }
} else if (root.length)
{ each(root, pushTagsTo); } // assume nodeList
}
// inject styles into DOM
styleManager.inject();
if (isObject(tagName)) {
opts = tagName;
tagName = 0;
}
// crawl the DOM to find the tag
if (isString(selector)) {
selector = selector === '*' ?
// select all registered tags
// & tags found with the riot-tag attribute set
allTags = selectTags() :
// or just the ones named like the selector
selector + selectTags(selector.split(/, */));
// make sure to pass always a selector
// to the querySelectorAll function
elem = selector ? $$(selector) : [];
}
else
// probably you have passed already a tag or a NodeList
{ elem = selector; }
// select all the registered and mount them inside their root elements
if (tagName === '*') {
// get all custom tags
tagName = allTags || selectTags();
// if the root els it's just a single tag
if (elem.tagName)
{ elem = $$(tagName, elem); }
else {
// select all the children for all the different root elements
var nodeList = [];
each(elem, function (_el) { return nodeList.push($$(tagName, _el)); });
elem = nodeList;
}
// get rid of the tagName
tagName = 0;
}
pushTagsTo(elem);
return tags
}
// Create a mixin that could be globally shared across all the tags
var mixins = {};
var globals = mixins[GLOBAL_MIXIN] = {};
var mixins_id = 0;
/**
* Create/Return a mixin by its name
* @param { String } name - mixin name (global mixin if object)
* @param { Object } mix - mixin logic
* @param { Boolean } g - is global?
* @returns { Object } the mixin logic
*/
function mixin$1(name, mix, g) {
// Unnamed global
if (isObject(name)) {
mixin$1(("__" + (mixins_id++) + "__"), name, true);
return
}
var store = g ? globals : mixins;
// Getter
if (!mix) {
if (isUndefined(store[name]))
{ throw new Error(("Unregistered mixin: " + name)) }
return store[name]
}
// Setter
store[name] = isFunction(mix) ?
extend(mix.prototype, store[name] || {}) && mix :
extend(store[name] || {}, mix);
}
/**
* Update all the tags instances created
* @returns { Array } all the tags instances
*/
function update$1() {
return each(__TAGS_CACHE, function (tag) { return tag.update(); })
}
function unregister$1(name) {
__TAG_IMPL[name] = null;
}
var version$1 = 'v3.8.1';
var core = Object.freeze({
Tag: Tag$1,
tag: tag$1,
tag2: tag2$1,
mount: mount$2,
mixin: mixin$1,
update: update$1,
unregister: unregister$1,
version: version$1
});
/**
* We need to update opts for this tag. That requires updating the expressions
* in any attributes on the tag, and then copying the result onto opts.
* @this Tag
* @param {Boolean} isLoop - is it a loop tag?
* @param { Tag } parent - parent tag node
* @param { Boolean } isAnonymous - is it a tag without any impl? (a tag not registered)
* @param { Object } opts - tag options
* @param { Array } instAttrs - tag attributes array
*/
function updateOpts(isLoop, parent, isAnonymous, opts, instAttrs) {
// isAnonymous `each` tags treat `dom` and `root` differently. In this case
// (and only this case) we don't need to do updateOpts, because the regular parse
// will update those attrs. Plus, isAnonymous tags don't need opts anyway
if (isLoop && isAnonymous) { return }
var ctx = isLoop ? inheritParentProps.call(this) : parent || this;
each(instAttrs, function (attr) {
if (attr.expr) { updateExpression.call(ctx, attr.expr); }
// normalize the attribute names
opts[toCamel(attr.name).replace(ATTRS_PREFIX, '')] = attr.expr ? attr.expr.value : attr.value;
});
}
/**
* Manage the mount state of a tag triggering also the observable events
* @this Tag
* @param { Boolean } value - ..of the isMounted flag
*/
function setMountState(value) {
var ref = this.__;
var isAnonymous = ref.isAnonymous;
defineProperty(this, 'isMounted', value);
if (!isAnonymous) {
if (value) { this.trigger('mount'); }
else {
this.trigger('unmount');
this.off('*');
this.__.wasCreated = false;
}
}
}
/**
* Tag creation factory function
* @constructor
* @param { Object } impl - it contains the tag template, and logic
* @param { Object } conf - tag options
* @param { String } innerHTML - html that eventually we need to inject in the tag
*/
function createTag(impl, conf, innerHTML) {
if ( impl === void 0 ) impl = {};
if ( conf === void 0 ) conf = {};
var tag = conf.context || {};
var opts = extend({}, conf.opts);
var parent = conf.parent;
var isLoop = conf.isLoop;
var isAnonymous = !!conf.isAnonymous;
var skipAnonymous = settings$1.skipAnonymousTags && isAnonymous;
var item = conf.item;
// available only for the looped nodes
var index = conf.index;
// All attributes on the Tag when it's first parsed
var instAttrs = [];
// expressions on this type of Tag
var implAttrs = [];
var expressions = [];
var root = conf.root;
var tagName = conf.tagName || getTagName(root);
var isVirtual = tagName === 'virtual';
var isInline = !isVirtual && !impl.tmpl;
var dom;
// make this tag observable
if (!skipAnonymous) { observable$1(tag); }
// only call unmount if we have a valid __TAG_IMPL (has name property)
if (impl.name && root._tag) { root._tag.unmount(true); }
// not yet mounted
defineProperty(tag, 'isMounted', false);
defineProperty(tag, '__', {
isAnonymous: isAnonymous,
instAttrs: instAttrs,
innerHTML: innerHTML,
tagName: tagName,
index: index,
isLoop: isLoop,
isInline: isInline,
// tags having event listeners
// it would be better to use weak maps here but we can not introduce breaking changes now
listeners: [],
// these vars will be needed only for the virtual tags
virts: [],
wasCreated: false,
tail: null,
head: null,
parent: null,
item: null
});
// create a unique id to this tag
// it could be handy to use it also to improve the virtual dom rendering speed
defineProperty(tag, '_riot_id', uid()); // base 1 allows test !t._riot_id
defineProperty(tag, 'root', root);
extend(tag, { opts: opts }, item);
// protect the "tags" and "refs" property from being overridden
defineProperty(tag, 'parent', parent || null);
defineProperty(tag, 'tags', {});
defineProperty(tag, 'refs', {});
if (isInline || isLoop && isAnonymous) {
dom = root;
} else {
if (!isVirtual) { root.innerHTML = ''; }
dom = mkdom(impl.tmpl, innerHTML, isSvg(root));
}
/**
* Update the tag expressions and options
* @param { * } data - data we want to use to extend the tag properties
* @returns { Tag } the current tag instance
*/
defineProperty(tag, 'update', function tagUpdate(data) {
var nextOpts = {};
var canTrigger = tag.isMounted && !skipAnonymous;
// inherit properties from the parent tag
if (isAnonymous && parent) { extend(tag, parent); }
extend(tag, data);
updateOpts.apply(tag, [isLoop, parent, isAnonymous, nextOpts, instAttrs]);
if (
canTrigger &&
tag.isMounted &&
isFunction(tag.shouldUpdate) && !tag.shouldUpdate(data, nextOpts)
) {
return tag
}
extend(opts, nextOpts);
if (canTrigger) { tag.trigger('update', data); }
updateAllExpressions.call(tag, expressions);
if (canTrigger) { tag.trigger('updated'); }
return tag
});
/**
* Add a mixin to this tag
* @returns { Tag } the current tag instance
*/
defineProperty(tag, 'mixin', function tagMixin() {
each(arguments, function (mix) {
var instance;
var obj;
var props = [];
// properties blacklisted and will not be bound to the tag instance
var propsBlacklist = ['init', '__proto__'];
mix = isString(mix) ? mixin$1(mix) : mix;
// check if the mixin is a function
if (isFunction(mix)) {
// create the new mixin instance
instance = new mix();
} else { instance = mix; }
var proto = Object.getPrototypeOf(instance);
// build multilevel prototype inheritance chain property list
do { props = props.concat(Object.getOwnPropertyNames(obj || instance)); }
while (obj = Object.getPrototypeOf(obj || instance))
// loop the keys in the function prototype or the all object keys
each(props, function (key) {
// bind methods to tag
// allow mixins to override other properties/parent mixins
if (!contains(propsBlacklist, key)) {
// check for getters/setters
var descriptor = getPropDescriptor(instance, key) || getPropDescriptor(proto, key);
var hasGetterSetter = descriptor && (descriptor.get || descriptor.set);
// apply method only if it does not already exist on the instance
if (!tag.hasOwnProperty(key) && hasGetterSetter) {
Object.defineProperty(tag, key, descriptor);
} else {
tag[key] = isFunction(instance[key]) ?
instance[key].bind(tag) :
instance[key];
}
}
});
// init method will be called automatically
if (instance.init)
{ instance.init.bind(tag)(opts); }
});
return tag
});
/**
* Mount the current tag instance
* @returns { Tag } the current tag instance
*/
defineProperty(tag, 'mount', function tagMount() {
root._tag = tag; // keep a reference to the tag just created
// Read all the attrs on this instance. This give us the info we need for updateOpts
parseAttributes.apply(parent, [root, root.attributes, function (attr, expr) {
if (!isAnonymous && RefExpr.isPrototypeOf(expr)) { expr.tag = tag; }
attr.expr = expr;
instAttrs.push(attr);
}]);
// update the root adding custom attributes coming from the compiler
walkAttrs(impl.attrs, function (k, v) { implAttrs.push({name: k, value: v}); });
parseAttributes.apply(tag, [root, implAttrs, function (attr, expr) {
if (expr) { expressions.push(expr); }
else { setAttr(root, attr.name, attr.value); }
}]);
// initialiation
updateOpts.apply(tag, [isLoop, parent, isAnonymous, opts, instAttrs]);
// add global mixins
var globalMixin = mixin$1(GLOBAL_MIXIN);
if (globalMixin && !skipAnonymous) {
for (var i in globalMixin) {
if (globalMixin.hasOwnProperty(i)) {
tag.mixin(globalMixin[i]);
}
}
}
if (impl.fn) { impl.fn.call(tag, opts); }
if (!skipAnonymous) { tag.trigger('before-mount'); }
// parse layout after init. fn may calculate args for nested custom tags
each(parseExpressions.apply(tag, [dom, isAnonymous]), function (e) { return expressions.push(e); });
tag.update(item);
if (!isAnonymous && !isInline) {
while (dom.firstChild) { root.appendChild(dom.firstChild); }
}
defineProperty(tag, 'root', root);
// if we need to wait that the parent "mount" or "updated" event gets triggered
if (!skipAnonymous && tag.parent) {
var p = getImmediateCustomParentTag(tag.parent);
p.one(!p.isMounted ? 'mount' : 'updated', function () {
setMountState.call(tag, true);
});
} else {
// otherwise it's not a child tag we can trigger its mount event
setMountState.call(tag, true);
}
tag.__.wasCreated = true;
return tag
});
/**
* Unmount the tag instance
* @param { Boolean } mustKeepRoot - if it's true the root node will not be removed
* @returns { Tag } the current tag instance
*/
defineProperty(tag, 'unmount', function tagUnmount(mustKeepRoot) {
var el = tag.root;
var p = el.parentNode;
var tagIndex = __TAGS_CACHE.indexOf(tag);
if (!skipAnonymous) { tag.trigger('before-unmount'); }
// clear all attributes coming from the mounted tag
walkAttrs(impl.attrs, function (name) {
if (startsWith(name, ATTRS_PREFIX))
{ name = name.slice(ATTRS_PREFIX.length); }
remAttr(root, name);
});
// remove all the event listeners
tag.__.listeners.forEach(function (dom) {
Object.keys(dom[RIOT_EVENTS_KEY]).forEach(function (eventName) {
dom.removeEventListener(eventName, dom[RIOT_EVENTS_KEY][eventName]);
});
});
// remove tag instance from the global tags cache collection
if (tagIndex !== -1) { __TAGS_CACHE.splice(tagIndex, 1); }
// clean up the parent tags object
if (parent && !isAnonymous) {
var ptag = getImmediateCustomParentTag(parent);
if (isVirtual) {
Object
.keys(tag.tags)
.forEach(function (tagName) { return arrayishRemove(ptag.tags, tagName, tag.tags[tagName]); });
} else {
arrayishRemove(ptag.tags, tagName, tag);
}
}
// unmount all the virtual directives
if (tag.__.virts) {
each(tag.__.virts, function (v) {
if (v.parentNode) { v.parentNode.removeChild(v); }
});
}
// allow expressions to unmount themselves
unmountAll(expressions);
each(instAttrs, function (a) { return a.expr && a.expr.unmount && a.expr.unmount(); });
// clear the tag html if it's necessary
if (mustKeepRoot) { setInnerHTML(el, ''); }
// otherwise detach the root tag from the DOM
else if (p) { p.removeChild(el); }
// custom internal unmount function to avoid relying on the observable
if (tag.__.onUnmount) { tag.__.onUnmount(); }
// weird fix for a weird edge case #2409 and #2436
// some users might use your software not as you've expected
// so I need to add these dirty hacks to mitigate unexpected issues
if (!tag.isMounted) { setMountState.call(tag, true); }
setMountState.call(tag, false);
delete tag.root._tag;
return tag
});
return tag
}
/**
* Detect the tag implementation by a DOM node
* @param { Object } dom - DOM node we need to parse to get its tag implementation
* @returns { Object } it returns an object containing the implementation of a custom tag (template and boot function)
*/
function getTag(dom) {
return dom.tagName && __TAG_IMPL[getAttr(dom, IS_DIRECTIVE) ||
getAttr(dom, IS_DIRECTIVE) || dom.tagName.toLowerCase()]
}
/**
* Move the position of a custom tag in its parent tag
* @this Tag
* @param { String } tagName - key where the tag was stored
* @param { Number } newPos - index where the new tag will be stored
*/
function moveChildTag(tagName, newPos) {
var parent = this.parent;
var tags;
// no parent no move
if (!parent) { return }
tags = parent.tags[tagName];
if (isArray(tags))
{ tags.splice(newPos, 0, tags.splice(tags.indexOf(this), 1)[0]); }
else { arrayishAdd(parent.tags, tagName, this); }
}
/**
* Create a new child tag including it correctly into its parent
* @param { Object } child - child tag implementation
* @param { Object } opts - tag options containing the DOM node where the tag will be mounted
* @param { String } innerHTML - inner html of the child node
* @param { Object } parent - instance of the parent tag including the child custom tag
* @returns { Object } instance of the new child tag just created
*/
function initChildTag(child, opts, innerHTML, parent) {
var tag = createTag(child, opts, innerHTML);
var tagName = opts.tagName || getTagName(opts.root, true);
var ptag = getImmediateCustomParentTag(parent);
// fix for the parent attribute in the looped elements
defineProperty(tag, 'parent', ptag);
// store the real parent tag
// in some cases this could be different from the custom parent tag
// for example in nested loops
tag.__.parent = parent;
// add this tag to the custom parent tag
arrayishAdd(ptag.tags, tagName, tag);
// and also to the real parent tag
if (ptag !== parent)
{ arrayishAdd(parent.tags, tagName, tag); }
return tag
}
/**
* Loop backward all the parents tree to detect the first custom parent tag
* @param { Object } tag - a Tag instance
* @returns { Object } the instance of the first custom parent tag found
*/
function getImmediateCustomParentTag(tag) {
var ptag = tag;
while (ptag.__.isAnonymous) {
if (!ptag.parent) { break }
ptag = ptag.parent;
}
return ptag
}
/**
* Trigger the unmount method on all the expressions
* @param { Array } expressions - DOM expressions
*/
function unmountAll(expressions) {
each(expressions, function (expr) {
if (expr.unmount) { expr.unmount(true); }
else if (expr.tagName) { expr.tag.unmount(true); }
else if (expr.unmount) { expr.unmount(); }
});
}
/**
* Get the tag name of any DOM node
* @param { Object } dom - DOM node we want to parse
* @param { Boolean } skipDataIs - hack to ignore the data-is attribute when attaching to parent
* @returns { String } name to identify this dom node in riot
*/
function getTagName(dom, skipDataIs) {
var child = getTag(dom);
var namedTag = !skipDataIs && getAttr(dom, IS_DIRECTIVE);
return namedTag && !tmpl.hasExpr(namedTag) ?
namedTag : child ? child.name : dom.tagName.toLowerCase()
}
/**
* Set the property of an object for a given key. If something already
* exists there, then it becomes an array containing both the old and new value.
* @param { Object } obj - object on which to set the property
* @param { String } key - property name
* @param { Object } value - the value of the property to be set
* @param { Boolean } ensureArray - ensure that the property remains an array
* @param { Number } index - add the new item in a certain array position
*/
function arrayishAdd(obj, key, value, ensureArray, index) {
var dest = obj[key];
var isArr = isArray(dest);
var hasIndex = !isUndefined(index);
if (dest && dest === value) { return }
// if the key was never set, set it once
if (!dest && ensureArray) { obj[key] = [value]; }
else if (!dest) { obj[key] = value; }
// if it was an array and not yet set
else {
if (isArr) {
var oldIndex = dest.indexOf(value);
// this item never changed its position
if (oldIndex === index) { return }
// remove the item from its old position
if (oldIndex !== -1) { dest.splice(oldIndex, 1); }
// move or add the item
if (hasIndex) {
dest.splice(index, 0, value);
} else {
dest.push(value);
}
} else { obj[key] = [dest, value]; }
}
}
/**
* Removes an item from an object at a given key. If the key points to an array,
* then the item is just removed from the array.
* @param { Object } obj - object on which to remove the property
* @param { String } key - property name
* @param { Object } value - the value of the property to be removed
* @param { Boolean } ensureArray - ensure that the property remains an array
*/
function arrayishRemove(obj, key, value, ensureArray) {
if (isArray(obj[key])) {
var index = obj[key].indexOf(value);
if (index !== -1) { obj[key].splice(index, 1); }
if (!obj[key].length) { delete obj[key]; }
else if (obj[key].length === 1 && !ensureArray) { obj[key] = obj[key][0]; }
} else if (obj[key] === value)
{ delete obj[key]; } // otherwise just delete the key
}
/**
* Mount a tag creating new Tag instance
* @param { Object } root - dom node where the tag will be mounted
* @param { String } tagName - name of the riot tag we want to mount
* @param { Object } opts - options to pass to the Tag instance
* @param { Object } ctx - optional context that will be used to extend an existing class ( used in riot.Tag )
* @returns { Tag } a new Tag instance
*/
function mountTo(root, tagName, opts, ctx) {
var impl = __TAG_IMPL[tagName];
var implClass = __TAG_IMPL[tagName].class;
var context = ctx || (implClass ? Object.create(implClass.prototype) : {});
// cache the inner HTML to fix #855
var innerHTML = root._innerHTML = root._innerHTML || root.innerHTML;
var conf = extend({ root: root, opts: opts, context: context }, { parent: opts ? opts.parent : null });
var tag;
if (impl && root) { tag = createTag(impl, conf, innerHTML); }
if (tag && tag.mount) {
tag.mount(true);
// add this tag to the virtualDom variable
if (!contains(__TAGS_CACHE, tag)) { __TAGS_CACHE.push(tag); }
}
return tag
}
/**
* makes a tag virtual and replaces a reference in the dom
* @this Tag
* @param { tag } the tag to make virtual
* @param { ref } the dom reference location
*/
function makeReplaceVirtual(tag, ref) {
var frag = createFrag();
makeVirtual.call(tag, frag);
ref.parentNode.replaceChild(frag, ref);
}
/**
* Adds the elements for a virtual tag
* @this Tag
* @param { Node } src - the node that will do the inserting or appending
* @param { Tag } target - only if inserting, insert before this tag's first child
*/
function makeVirtual(src, target) {
var this$1 = this;
var head = createDOMPlaceholder();
var tail = createDOMPlaceholder();
var frag = createFrag();
var sib;
var el;
this.root.insertBefore(head, this.root.firstChild);
this.root.appendChild(tail);
this.__.head = el = head;
this.__.tail = tail;
while (el) {
sib = el.nextSibling;
frag.appendChild(el);
this$1.__.virts.push(el); // hold for unmounting
el = sib;
}
if (target)
{ src.insertBefore(frag, target.__.head); }
else
{ src.appendChild(frag); }
}
/**
* Return a temporary context containing also the parent properties
* @this Tag
* @param { Tag } - temporary tag context containing all the parent properties
*/
function inheritParentProps() {
if (this.parent) { return extend(Object.create(this), this.parent) }
return this
}
/**
* Move virtual tag and all child nodes
* @this Tag
* @param { Node } src - the node that will do the inserting
* @param { Tag } target - insert before this tag's first child
*/
function moveVirtual(src, target) {
var this$1 = this;
var el = this.__.head;
var sib;
var frag = createFrag();
while (el) {
sib = el.nextSibling;
frag.appendChild(el);
el = sib;
if (el === this$1.__.tail) {
frag.appendChild(el);
src.insertBefore(frag, target.__.head);
break
}
}
}
/**
* Get selectors for tags
* @param { Array } tags - tag names to select
* @returns { String } selector
*/
function selectTags(tags) {
// select all tags
if (!tags) {
var keys = Object.keys(__TAG_IMPL);
return keys + selectTags(keys)
}
return tags
.filter(function (t) { return !/[^-\w]/.test(t); })
.reduce(function (list, t) {
var name = t.trim().toLowerCase();
return list + ",[" + IS_DIRECTIVE + "=\"" + name + "\"]"
}, '')
}
var tags = Object.freeze({
getTag: getTag,
moveChildTag: moveChildTag,
initChildTag: initChildTag,
getImmediateCustomParentTag: getImmediateCustomParentTag,
unmountAll: unmountAll,
getTagName: getTagName,
arrayishAdd: arrayishAdd,
arrayishRemove: arrayishRemove,
mountTo: mountTo,
makeReplaceVirtual: makeReplaceVirtual,
makeVirtual: makeVirtual,
inheritParentProps: inheritParentProps,
moveVirtual: moveVirtual,
selectTags: selectTags
});
/**
* Riot public api
*/
var settings = settings$1;
var util = {
tmpl: tmpl,
brackets: brackets,
styleManager: styleManager,
vdom: __TAGS_CACHE,
styleNode: styleManager.styleNode,
// export the riot internal utils as well
dom: dom,
check: check,
misc: misc,
tags: tags
};
// export the core props/methods
var Tag = Tag$1;
var tag = tag$1;
var tag2 = tag2$1;
var mount$1 = mount$2;
var mixin = mixin$1;
var update = update$1;
var unregister = unregister$1;
var version = version$1;
var observable = observable$1;
var riot$1 = extend({}, core, {
observable: observable$1,
settings: settings,
util: util,
});
var riot$2 = Object.freeze({
settings: settings,
util: util,
Tag: Tag,
tag: tag,
tag2: tag2,
mount: mount$1,
mixin: mixin,
update: update,
unregister: unregister,
version: version,
observable: observable,
default: riot$1
});
/**
* Compiler for riot custom tags
* @version v3.4.0
*/
// istanbul ignore next
function safeRegex (re) {
var arguments$1 = arguments;
var src = re.source;
var opt = re.global ? 'g' : '';
if (re.ignoreCase) { opt += 'i'; }
if (re.multiline) { opt += 'm'; }
for (var i = 1; i < arguments.length; i++) {
src = src.replace('@', '\\' + arguments$1[i]);
}
return new RegExp(src, opt)
}
/**
* @module parsers
*/
var parsers$1 = (function (win) {
var _p = {};
function _r (name) {
var parser = win[name];
if (parser) { return parser }
throw new Error('Parser "' + name + '" not loaded.')
}
function _req (name) {
var parts = name.split('.');
if (parts.length !== 2) { throw new Error('Bad format for parsers._req') }
var parser = _p[parts[0]][parts[1]];
if (parser) { return parser }
throw new Error('Parser "' + name + '" not found.')
}
function extend (obj, props) {
if (props) {
for (var prop in props) {
/* istanbul ignore next */
if (props.hasOwnProperty(prop)) {
obj[prop] = props[prop];
}
}
}
return obj
}
function renderPug (compilerName, html, opts, url) {
opts = extend({
pretty: true,
filename: url,
doctype: 'html'
}, opts);
return _r(compilerName).render(html, opts)
}
_p.html = {
jade: function (html, opts, url) {
/* eslint-disable */
console.log('DEPRECATION WARNING: jade was renamed "pug" - The jade parser will be removed in riot@3.0.0!');
/* eslint-enable */
return renderPug('jade', html, opts, url)
},
pug: function (html, opts, url) {
return renderPug('pug', html, opts, url)
}
};
_p.css = {
less: function (tag, css, opts, url) {
var ret;
opts = extend({
sync: true,
syncImport: true,
filename: url
}, opts);
_r('less').render(css, opts, function (err, result) {
// istanbul ignore next
if (err) { throw err }
ret = result.css;
});
return ret
}
};
_p.js = {
es6: function (js, opts, url) { // eslint-disable-line no-unused-vars
return _r('Babel').transform( // eslint-disable-line
js,
extend({
plugins: [
['transform-es2015-template-literals', { loose: true }],
'transform-es2015-literals',
'transform-es2015-function-name',
'transform-es2015-arrow-functions',
'transform-es2015-block-scoped-functions',
['transform-es2015-classes', { loose: true }],
'transform-es2015-object-super',
'transform-es2015-shorthand-properties',
'transform-es2015-duplicate-keys',
['transform-es2015-computed-properties', { loose: true }],
['transform-es2015-for-of', { loose: true }],
'transform-es2015-sticky-regex',
'transform-es2015-unicode-regex',
'check-es2015-constants',
['transform-es2015-spread', { loose: true }],
'transform-es2015-parameters',
['transform-es2015-destructuring', { loose: true }],
'transform-es2015-block-scoping',
'transform-es2015-typeof-symbol',
['transform-es2015-modules-commonjs', { allowTopLevelThis: true }],
['transform-regenerator', { async: false, asyncGenerators: false }]
]
},
opts
)).code
},
buble: function (js, opts, url) {
opts = extend({
source: url,
modules: false
}, opts);
return _r('buble').transform(js, opts).code
},
coffee: function (js, opts) {
return _r('CoffeeScript').compile(js, extend({ bare: true }, opts))
},
livescript: function (js, opts) {
return _r('livescript').compile(js, extend({ bare: true, header: false }, opts))
},
typescript: function (js, opts) {
return _r('typescript')(js, opts)
},
none: function (js) {
return js
}
};
_p.js.javascript = _p.js.none;
_p.js.coffeescript = _p.js.coffee;
_p._req = _req;
_p.utils = {
extend: extend
};
return _p
})(window || global);
var S_SQ_STR = /'[^'\n\r\\]*(?:\\(?:\r\n?|[\S\s])[^'\n\r\\]*)*'/.source;
var S_R_SRC1 = [
/\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//.source,
'//.*',
S_SQ_STR,
S_SQ_STR.replace(/'/g, '"'),
'([/`])'
].join('|');
var S_R_SRC2 = (S_R_SRC1.slice(0, -2)) + "{}])";
function skipES6str (code, start, stack) {
var re = /[`$\\]/g;
re.lastIndex = start;
while (re.exec(code)) {
var end = re.lastIndex;
var c = code[end - 1];
if (c === '`') {
return end
}
if (c === '$' && code[end] === '{') {
stack.push('`', '}');
return end + 1
}
re.lastIndex++;
}
throw new Error('Unclosed ES6 template')
}
function jsSplitter (code, start) {
var re1 = new RegExp(S_R_SRC1, 'g');
var re2;
var skipRegex = brackets.skipRegex;
var offset = start | 0;
var result = [[]];
var stack = [];
var re = re1;
var lastPos = re.lastIndex = offset;
var str, ch, idx, end, match;
while ((match = re.exec(code))) {
idx = match.index;
end = re.lastIndex;
str = '';
ch = match[1];
if (ch) {
if (ch === '{') {
stack.push('}');
} else if (ch === '}') {
if (stack.pop() !== ch) {
throw new Error("Unexpected '}'")
} else if (stack[stack.length - 1] === '`') {
ch = stack.pop();
}
} else if (ch === '/') {
end = skipRegex(code, idx);
if (end > idx + 1) {
str = code.slice(idx, end);
}
}
if (ch === '`') {
end = skipES6str(code, end, stack);
str = code.slice(idx, end);
if (stack.length) {
re = re2 || (re2 = new RegExp(S_R_SRC2, 'g'));
} else {
re = re1;
}
}
} else {
str = match[0];
if (str[0] === '/') {
str = str[1] === '*' ? ' ' : '';
code = code.slice(offset, idx) + str + code.slice(end);
end = idx + str.length;
str = '';
} else if (str.length === 2) {
str = '';
}
}
if (str) {
result[0].push(code.slice(lastPos, idx));
result.push(str);
lastPos = end;
}
re.lastIndex = end;
}
result[0].push(code.slice(lastPos));
return result
}
/**
* @module compiler
*/
var extend$1 = parsers$1.utils.extend;
/* eslint-enable */
var S_LINESTR = /"[^"\n\\]*(?:\\[\S\s][^"\n\\]*)*"|'[^'\n\\]*(?:\\[\S\s][^'\n\\]*)*'/.source;
var S_STRINGS = brackets.R_STRINGS.source;
var HTML_ATTRS = / *([-\w:\xA0-\xFF]+) ?(?:= ?('[^']*'|"[^"]*"|\S+))?/g;
var HTML_COMMS = RegExp(//.source + '|' + S_LINESTR, 'g');
var HTML_TAGS = /<(-?[A-Za-z][-\w\xA0-\xFF]*)(?:\s+([^"'/>]*(?:(?:"[^"]*"|'[^']*'|\/[^>])[^'"/>]*)*)|\s*)(\/?)>/g;
var HTML_PACK = />[ \t]+<(-?[A-Za-z]|\/[-A-Za-z])/g;
var RIOT_ATTRS = ['style', 'src', 'd', 'value'];
var VOID_TAGS = /^(?:input|img|br|wbr|hr|area|base|col|embed|keygen|link|meta|param|source|track)$/;
var PRE_TAGS = /]*|"[^"]*")*)?>([\S\s]+?)<\/pre\s*>/gi;
var SPEC_TYPES = /^"(?:number|date(?:time)?|time|month|email|color)\b/i;
var IMPORT_STATEMENT = /^\s*import(?!\w)(?:(?:\s|[^\s'"])*)['|"].*\n?/gm;
var TRIM_TRAIL = /[ \t]+$/gm;
var RE_HASEXPR = safeRegex(/@#\d/, 'x01');
var RE_REPEXPR = safeRegex(/@#(\d+)/g, 'x01');
var CH_IDEXPR = '\x01#';
var CH_DQCODE = '\u2057';
var DQ = '"';
var SQ = "'";
function cleanSource (src) {
var
mm,
re = HTML_COMMS;
if (src.indexOf('\r') !== 1) {
src = src.replace(/\r\n?/g, '\n');
}
re.lastIndex = 0;
while ((mm = re.exec(src))) {
if (mm[0][0] === '<') {
src = RegExp.leftContext + RegExp.rightContext;
re.lastIndex = mm[3] + 1;
}
}
return src
}
function parseAttribs (str, pcex) {
var
list = [],
match,
type, vexp;
HTML_ATTRS.lastIndex = 0;
str = str.replace(/\s+/g, ' ');
while ((match = HTML_ATTRS.exec(str))) {
var
k = match[1].toLowerCase(),
v = match[2];
if (!v) {
list.push(k);
} else {
if (v[0] !== DQ) {
v = DQ + (v[0] === SQ ? v.slice(1, -1) : v) + DQ;
}
if (k === 'type' && SPEC_TYPES.test(v)) {
type = v;
} else {
if (RE_HASEXPR.test(v)) {
if (k === 'value') { vexp = 1; }
if (RIOT_ATTRS.indexOf(k) !== -1) { k = 'riot-' + k; }
}
list.push(k + '=' + v);
}
}
}
if (type) {
if (vexp) { type = DQ + pcex._bp[0] + SQ + type.slice(1, -1) + SQ + pcex._bp[1] + DQ; }
list.push('type=' + type);
}
return list.join(' ')
}
function splitHtml (html, opts, pcex) {
var _bp = pcex._bp;
if (html && _bp[4].test(html)) {
var
jsfn = opts.expr && (opts.parser || opts.type) ? _compileJS : 0,
list = brackets.split(html, 0, _bp),
expr;
for (var i = 1; i < list.length; i += 2) {
expr = list[i];
if (expr[0] === '^') {
expr = expr.slice(1);
} else if (jsfn) {
expr = jsfn(expr, opts).trim();
if (expr.slice(-1) === ';') { expr = expr.slice(0, -1); }
}
list[i] = CH_IDEXPR + (pcex.push(expr) - 1) + _bp[1];
}
html = list.join('');
}
return html
}
function restoreExpr (html, pcex) {
if (pcex.length) {
html = html.replace(RE_REPEXPR, function (_, d) {
return pcex._bp[0] + pcex[d].trim().replace(/[\r\n]+/g, ' ').replace(/"/g, CH_DQCODE)
});
}
return html
}
function _compileHTML (html, opts, pcex) {
if (!/\S/.test(html)) { return '' }
html = splitHtml(html, opts, pcex)
.replace(HTML_TAGS, function (_, name, attr, ends) {
name = name.toLowerCase();
ends = ends && !VOID_TAGS.test(name) ? '>' + name : '';
if (attr) { name += ' ' + parseAttribs(attr, pcex); }
return '<' + name + ends + '>'
});
if (!opts.whitespace) {
var p = [];
if (/]/.test(html)) {
html = html.replace(PRE_TAGS, function (q) {
p.push(q);
return '\u0002'
});
}
html = html.trim().replace(/\s+/g, ' ');
if (p.length) { html = html.replace(/\u0002/g, function () { return p.shift() }); }
}
if (opts.compact) { html = html.replace(HTML_PACK, '><$1'); }
return restoreExpr(html, pcex).replace(TRIM_TRAIL, '')
}
function compileHTML (html, opts, pcex) {
if (Array.isArray(opts)) {
pcex = opts;
opts = {};
} else {
if (!pcex) { pcex = []; }
if (!opts) { opts = {}; }
}
pcex._bp = brackets.array(opts.brackets);
return _compileHTML(cleanSource(html), opts, pcex)
}
var JS_ES6SIGN = /^[ \t]*(((?:async|\*)\s*)?([$_A-Za-z][$\w]*))\s*\([^()]*\)\s*{/m;
function riotjs (js) {
var
parts = [],
match,
toes5,
pos,
method,
prefix,
name,
RE = RegExp;
var src = jsSplitter(js);
js = src.shift().join('<%>');
while ((match = js.match(JS_ES6SIGN))) {
parts.push(RE.leftContext);
js = RE.rightContext;
pos = skipBody(js);
method = match[1];
prefix = match[2] || '';
name = match[3];
toes5 = !/^(?:if|while|for|switch|catch|function)$/.test(name);
if (toes5) {
name = match[0].replace(method, 'this.' + name + ' =' + prefix + ' function');
} else {
name = match[0];
}
parts.push(name, js.slice(0, pos));
js = js.slice(pos);
if (toes5 && !/^\s*.\s*bind\b/.test(js)) { parts.push('.bind(this)'); }
}
if (parts.length) {
js = parts.join('') + js;
}
if (src.length) {
js = js.replace(/<%>/g, function () {
return src.shift()
});
}
return js
function skipBody (s) {
var r = /[{}]/g;
var i = 1;
while (i && r.exec(s)) {
if (s[r.lastIndex - 1] === '{') { ++i; }
else { --i; }
}
return i ? s.length : r.lastIndex
}
}
function _compileJS (js, opts, type, parserOpts, url) {
if (!/\S/.test(js)) { return '' }
if (!type) { type = opts.type; }
var parser = opts.parser || type && parsers$1._req('js.' + type, true) || riotjs;
return parser(js, parserOpts, url).replace(/\r\n?/g, '\n').replace(TRIM_TRAIL, '')
}
function compileJS (js, opts, type, userOpts) {
if (typeof opts === 'string') {
userOpts = type;
type = opts;
opts = {};
}
if (type && typeof type === 'object') {
userOpts = type;
type = '';
}
if (!userOpts) { userOpts = {}; }
return _compileJS(js, opts || {}, type, userOpts.parserOptions, userOpts.url)
}
var CSS_SELECTOR = RegExp('([{}]|^)[; ]*((?:[^@ ;{}][^{}]*)?[^@ ;{}:] ?)(?={)|' + S_LINESTR, 'g');
function scopedCSS (tag, css) {
var scope = ':scope';
return css.replace(CSS_SELECTOR, function (m, p1, p2) {
if (!p2) { return m }
p2 = p2.replace(/[^,]+/g, function (sel) {
var s = sel.trim();
if (s.indexOf(tag) === 0) {
return sel
}
if (!s || s === 'from' || s === 'to' || s.slice(-1) === '%') {
return sel
}
if (s.indexOf(scope) < 0) {
s = tag + ' ' + s + ',[data-is="' + tag + '"] ' + s;
} else {
s = s.replace(scope, tag) + ',' +
s.replace(scope, '[data-is="' + tag + '"]');
}
return s
});
return p1 ? p1 + ' ' + p2 : p2
})
}
function _compileCSS (css, tag, type, opts) {
opts = opts || {};
if (type) {
if (type !== 'css') {
var parser = parsers$1._req('css.' + type, true);
css = parser(tag, css, opts.parserOpts || {}, opts.url);
}
}
css = css.replace(brackets.R_MLCOMMS, '').replace(/\s+/g, ' ').trim();
if (tag) { css = scopedCSS(tag, css); }
return css
}
function compileCSS (css, type, opts) {
if (type && typeof type === 'object') {
opts = type;
type = '';
} else if (!opts) { opts = {}; }
return _compileCSS(css, opts.tagName, type, opts)
}
var TYPE_ATTR = /\stype\s*=\s*(?:(['"])(.+?)\1|(\S+))/i;
var MISC_ATTR = '\\s*=\\s*(' + S_STRINGS + '|{[^}]+}|\\S+)';
var END_TAGS = /\/>\n|^<(?:\/?-?[A-Za-z][-\w\xA0-\xFF]*\s*|-?[A-Za-z][-\w\xA0-\xFF]*\s+[-\w:\xA0-\xFF][\S\s]*?)>\n/;
function _q (s, r) {
if (!s) { return "''" }
s = SQ + s.replace(/\\/g, '\\\\').replace(/'/g, "\\'") + SQ;
return r && s.indexOf('\n') !== -1 ? s.replace(/\n/g, '\\n') : s
}
function mktag (name, html, css, attr, js, imports, opts) {
var
c = opts.debug ? ',\n ' : ', ',
s = '});';
if (js && js.slice(-1) !== '\n') { s = '\n' + s; }
return imports + 'riot.tag2(\'' + name + SQ +
c + _q(html, 1) +
c + _q(css) +
c + _q(attr) + ', function(opts) {\n' + js + s
}
function splitBlocks (str) {
if (/<[-\w]/.test(str)) {
var
m,
k = str.lastIndexOf('<'),
n = str.length;
while (k !== -1) {
m = str.slice(k, n).match(END_TAGS);
if (m) {
k += m.index + m[0].length;
m = str.slice(0, k);
if (m.slice(-5) === '<-/>\n') { m = m.slice(0, -5); }
return [m, str.slice(k)]
}
n = k;
k = str.lastIndexOf('<', k - 1);
}
}
return ['', str]
}
function getType (attribs) {
if (attribs) {
var match = attribs.match(TYPE_ATTR);
match = match && (match[2] || match[3]);
if (match) {
return match.replace('text/', '')
}
}
return ''
}
function getAttrib (attribs, name) {
if (attribs) {
var match = attribs.match(RegExp('\\s' + name + MISC_ATTR, 'i'));
match = match && match[1];
if (match) {
return (/^['"]/).test(match) ? match.slice(1, -1) : match
}
}
return ''
}
function unescapeHTML (str) {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, '\'')
}
function getParserOptions (attribs) {
var opts = unescapeHTML(getAttrib(attribs, 'options'));
return opts ? JSON.parse(opts) : null
}
function getCode (code, opts, attribs, base) {
var
type = getType(attribs),
src = getAttrib(attribs, 'src'),
jsParserOptions = extend$1({}, opts.parserOptions.js);
if (src) { return false }
return _compileJS(
code,
opts,
type,
extend$1(jsParserOptions, getParserOptions(attribs)),
base
)
}
function cssCode (code, opts, attribs, url, tag) {
var
parserStyleOptions = extend$1({}, opts.parserOptions.style),
extraOpts = {
parserOpts: extend$1(parserStyleOptions, getParserOptions(attribs)),
url: url
};
return _compileCSS(code, tag, getType(attribs) || opts.style, extraOpts)
}
function compileTemplate (html, url, lang, opts) {
var parser = parsers$1._req('html.' + lang, true);
return parser(html, opts, url)
}
var CUST_TAG = RegExp(/^([ \t]*)<(-?[A-Za-z][-\w\xA0-\xFF]*)(?:\s+([^'"/>]+(?:(?:@|\/[^>])[^'"/>]*)*)|\s*)?(?:\/>|>[ \t]*\n?([\S\s]*)^\1<\/\2\s*>|>(.*)<\/\2\s*>)/
.source.replace('@', S_STRINGS), 'gim');
var SCRIPTS = /