valyrian.js 7.2.2 → 7.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/hooks/index.ts"],"names":[],"mappings":"AAQA,oBAAY,IAAI,GAAG,GAAG,CAAC;AAEvB,MAAM,WAAW,cAAc;IAE7B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAElC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAE/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAEhC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAE/B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;CACnC;AAED,MAAM,WAAW,UAAU;IAEzB,CAAC,cAAc,EAAE,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CAC3D;AAED,eAAO,MAAM,UAAU,YAiEG,CAAC;AAS3B,eAAO,MAAM,QAAQ,YA7EyB,GAAG,EAAE,KAAK,GAgGtD,CAAC;AAGH,eAAO,MAAM,SAAS,YAnGwB,GAAG,EAAE,KAAK,GAuJtD,CAAC;AAEH,eAAO,MAAM,MAAM,YAzJ2B,GAAG,EAAE,KAAK,GAgKtD,CAAC;AAEH,eAAO,MAAM,WAAW,YAlKsB,GAAG,EAAE,KAAK,GAgLtD,CAAC;AAEH,eAAO,MAAM,OAAO,YAlL0B,GAAG,EAAE,KAAK,GAkMtD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/hooks/index.ts"],"names":[],"mappings":"AAQA,oBAAY,IAAI,GAAG,GAAG,CAAC;AAEvB,MAAM,WAAW,cAAc;IAE7B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAElC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAE/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAEhC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAE/B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;CACnC;AAED,MAAM,WAAW,UAAU;IAEzB,CAAC,cAAc,EAAE,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CAC3D;AAED,eAAO,MAAM,UAAU,YAiEG,CAAC;AAS3B,eAAO,MAAM,QAAQ,YA7EyB,GAAG,EAAE,KAAK,GAqGtD,CAAC;AAGH,eAAO,MAAM,SAAS,YAxGwB,GAAG,EAAE,KAAK,GA4JtD,CAAC;AAEH,eAAO,MAAM,MAAM,YA9J2B,GAAG,EAAE,KAAK,GAqKtD,CAAC;AAEH,eAAO,MAAM,WAAW,YAvKsB,GAAG,EAAE,KAAK,GAqLtD,CAAC;AAEH,eAAO,MAAM,OAAO,YAvL0B,GAAG,EAAE,KAAK,GAuMtD,CAAC"}
@@ -88,6 +88,9 @@ var useState = createHook({
88
88
  get.toJSON = get.valueOf = get;
89
89
  get.toString = () => `${value}`;
90
90
  function set(newValue) {
91
+ if (import_valyrian.current.event) {
92
+ import_valyrian.current.event.preventDefault();
93
+ }
91
94
  if (value !== newValue) {
92
95
  value = newValue;
93
96
  get.value = newValue;
@@ -60,6 +60,9 @@ var useState = createHook({
60
60
  get.toJSON = get.valueOf = get;
61
61
  get.toString = () => `${value}`;
62
62
  function set(newValue) {
63
+ if (current.event) {
64
+ current.event.preventDefault();
65
+ }
63
66
  if (value !== newValue) {
64
67
  value = newValue;
65
68
  get.value = newValue;
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ export interface Current {
49
49
  component: Component | POJOComponent | null;
50
50
  vnode: VnodeWithDom | null;
51
51
  oldVnode?: VnodeWithDom | null;
52
+ event: Event | null;
52
53
  }
53
54
  export interface V {
54
55
  (tagOrComponent: string | Component | POJOComponent, props: VnodeProperties | null, ...children: Children): VnodeInterface | VnodeComponentInterface;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAG9B,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEtB,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CACtC;AAID,MAAM,WAAW,UAAW,SAAQ,OAAO;IACzC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAID,MAAM,WAAW,cAAc;IAI7B,KAAK,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC;IAE1G,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CAAC;IAExC,KAAK,EAAE,eAAe,CAAC;IAEvB,QAAQ,EAAE,QAAQ,CAAC;IAEnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CACtC;AAGD,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,GAAG,EAAE,UAAU,CAAC;CACjB;AAID,MAAM,WAAW,SAAS;IAIxB,CAA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Y,GAAG,IAAI,CAM5G;AAUD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CA6BtF;AAKD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CA8N3E;AAGD,wBAAgB,MAAM,IAAI,IAAI,GAAG,MAAM,CA+BtC;AAQD,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CA6BtF;AAGD,wBAAgB,OAAO,kBA4BtB;AAED,wBAAgB,KAAK,CAAC,GAAG,KAAA,EAAE,SAAS,KAAA,iBA8BnC;AAID,eAAO,MAAM,CAAC,EAAE,CAGf,CAAC"}
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ function domToVnode(dom) {
68
68
  for (let i = 0, l = dom.childNodes.length; i < l; i++) {
69
69
  let childDom = dom.childNodes[i];
70
70
  if (childDom.nodeType === 3) {
71
- let vnode2 = new Vnode(textTag, {}, []);
71
+ let vnode2 = new Vnode(textTag, {}, [childDom.nodeValue]);
72
72
  vnode2.dom = childDom;
73
73
  children.push(vnode2);
74
74
  continue;
@@ -97,7 +97,8 @@ var isMounted = false;
97
97
  var current = {
98
98
  vnode: null,
99
99
  oldVnode: null,
100
- component: null
100
+ component: null,
101
+ event: null
101
102
  };
102
103
  var reservedProps = {
103
104
  key: true,
@@ -142,6 +143,7 @@ function callSet(set) {
142
143
  }
143
144
  var eventListenerNames = {};
144
145
  function eventListener(e) {
146
+ current.event = e;
145
147
  let dom = e.target;
146
148
  let name = `v-on${e.type}`;
147
149
  while (dom) {
@@ -154,6 +156,7 @@ function eventListener(e) {
154
156
  }
155
157
  dom = dom.parentNode;
156
158
  }
159
+ current.event = null;
157
160
  }
158
161
  var hideDirective = (test) => (bool, vnode, oldnode) => {
159
162
  let value = test ? bool : !bool;
@@ -308,12 +311,11 @@ function directive(name, directive2) {
308
311
  }
309
312
  function sharedSetAttribute(name, value, newVnode, oldVnode) {
310
313
  if (typeof value === "function") {
311
- let lowercaseName = name.toLowerCase();
312
- if (lowercaseName in eventListenerNames === false) {
313
- mainVnode.dom.addEventListener(lowercaseName.slice(2), eventListener);
314
- eventListenerNames[lowercaseName] = true;
314
+ if (name in eventListenerNames === false) {
315
+ mainVnode.dom.addEventListener(name.slice(2), eventListener);
316
+ eventListenerNames[name] = true;
315
317
  }
316
- newVnode.dom[`v-${lowercaseName}`] = value;
318
+ newVnode.dom[`v-${name}`] = value;
317
319
  return;
318
320
  }
319
321
  if (name in newVnode.dom && newVnode.isSVG === false) {
@@ -360,6 +362,10 @@ function updateAttributes(newVnode, oldVnode) {
360
362
  }
361
363
  }
362
364
  function patch(newVnode, oldVnode) {
365
+ if (newVnode.children.length === 0) {
366
+ newVnode.dom.textContent = "";
367
+ return;
368
+ }
363
369
  let newTree = newVnode.children;
364
370
  let oldTree = oldVnode?.children || [];
365
371
  let oldTreeLength = oldTree.length;
@@ -411,19 +417,18 @@ function patch(newVnode, oldVnode) {
411
417
  current.oldVnode = oldVnode;
412
418
  for (let i = 0; i < newTree.length; i++) {
413
419
  let newChild = newTree[i];
414
- if (newChild instanceof Vnode && newChild.tag !== textTag) {
415
- if (typeof newChild.tag === "string") {
416
- continue;
420
+ if (newChild instanceof Vnode) {
421
+ if (typeof newChild.tag !== "string") {
422
+ current.component = newChild.tag;
423
+ newTree.splice(
424
+ i--,
425
+ 1,
426
+ ("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
427
+ newChild.props,
428
+ ...newChild.children
429
+ )
430
+ );
417
431
  }
418
- current.component = newChild.tag;
419
- newTree.splice(
420
- i--,
421
- 1,
422
- ("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
423
- newChild.props,
424
- ...newChild.children
425
- )
426
- );
427
432
  continue;
428
433
  }
429
434
  if (Array.isArray(newChild)) {
@@ -434,55 +439,51 @@ function patch(newVnode, oldVnode) {
434
439
  newTree.splice(i--, 1);
435
440
  continue;
436
441
  }
437
- if (newChild instanceof Vnode) {
438
- newChild.children[0] = newChild.dom.textContent;
439
- continue;
440
- }
441
- newChild = newTree[i] = new Vnode(textTag, {}, [newChild]);
442
+ newTree[i] = new Vnode(textTag, {}, [newChild]);
442
443
  }
443
444
  for (let i = 0; i < newTree.length; i++) {
444
445
  let newChild = newTree[i];
445
446
  if (newChild.tag === textTag) {
446
- if (i < oldTreeLength) {
447
- let oldChild = oldTree[i];
448
- if (oldChild.tag === textTag) {
449
- newChild.dom = oldChild.dom;
450
- if (newChild.children[0] != oldChild.dom.textContent) {
451
- oldChild.dom.textContent = newChild.children[0];
452
- }
453
- continue;
454
- }
447
+ if (i >= oldTreeLength) {
455
448
  newChild.dom = document.createTextNode(newChild.children[0]);
456
- newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
449
+ newVnode.dom.appendChild(newChild.dom);
457
450
  continue;
458
451
  }
459
- newChild.dom = document.createTextNode(newChild.children[0]);
460
- newVnode.dom.appendChild(newChild.dom);
452
+ let oldChild2 = oldTree[i];
453
+ if (oldChild2.tag !== textTag) {
454
+ newChild.dom = document.createTextNode(newChild.children[0]);
455
+ newVnode.dom.replaceChild(newChild.dom, oldChild2.dom);
456
+ continue;
457
+ }
458
+ newChild.dom = oldChild2.dom;
459
+ if (newChild.children[0] != oldChild2.dom.textContent) {
460
+ oldChild2.dom.textContent = newChild.children[0];
461
+ }
461
462
  continue;
462
463
  }
463
464
  newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
464
- if (i < oldTreeLength) {
465
- let oldChild = oldTree[i];
466
- if (newChild.tag === oldChild.tag) {
467
- newChild.dom = oldChild.dom;
468
- if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
469
- newChild.children = oldChild.children;
470
- continue;
471
- }
472
- updateAttributes(newChild, oldChild);
473
- patch(newChild, oldChild);
474
- continue;
475
- }
465
+ if (i >= oldTreeLength) {
466
+ newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
467
+ updateAttributes(newChild);
468
+ newVnode.dom.appendChild(newChild.dom);
469
+ patch(newChild);
470
+ continue;
471
+ }
472
+ let oldChild = oldTree[i];
473
+ if (newChild.tag !== oldChild.tag) {
476
474
  newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
477
475
  updateAttributes(newChild);
478
476
  newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
479
477
  patch(newChild);
480
478
  continue;
481
479
  }
482
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
483
- updateAttributes(newChild);
484
- newVnode.dom.appendChild(newChild.dom);
485
- patch(newChild);
480
+ newChild.dom = oldChild.dom;
481
+ if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
482
+ newChild.children = oldChild.children;
483
+ continue;
484
+ }
485
+ updateAttributes(newChild, oldChild);
486
+ patch(newChild, oldChild);
486
487
  }
487
488
  for (let i = newTree.length; i < oldTreeLength; i++) {
488
489
  newVnode.dom.removeChild(oldTree[i].dom);
@@ -512,6 +513,8 @@ function updateVnode(vnode, oldVnode) {
512
513
  oldVnode.tag = vnode.tag;
513
514
  oldVnode.props = { ...vnode.props };
514
515
  oldVnode.children = [...vnode.children];
516
+ oldVnode.dom = vnode.dom;
517
+ oldVnode.isSVG = vnode.isSVG;
515
518
  callSet(isMounted ? onUpdateSet : onMountSet);
516
519
  isMounted = true;
517
520
  current.vnode = null;
package/dist/index.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var e="#text",t=Boolean("undefined"!=typeof process&&process.versions&&process.versions.node);function o(e,t=!1){return t?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e)}var n=function(e,t,o){this.tag=e,this.props=t,this.children=o};function l(e){return e&&("function"==typeof e||"object"==typeof e&&"view"in e)}var i=e=>e instanceof n,d=e=>i(e)&&l(e.tag);function r(t){let o=[];for(let l=0,i=t.childNodes.length;l<i;l++){let i=t.childNodes[l];if(3!==i.nodeType)1===i.nodeType&&o.push(r(i));else{let t=new n(e,{},[]);t.dom=i,o.push(t)}}let l={};for(let e=0,o=t.attributes.length;e<o;e++){let o=t.attributes[e];l[o.nodeName]=o.nodeValue}let i=new n(t.tagName.toLowerCase(),l,o);return i.dom=t,i}function p(e){let t=o("div");return t.innerHTML=e.trim(),[].map.call(t.childNodes,e=>r(e))}var s=null,a=null,c=!1,u={vnode:null,oldVnode:null,component:null},m={key:!0,state:!0,"v-keep":!0,"v-if":!0,"v-unless":!0,"v-for":!0,"v-show":!0,"v-class":!0,"v-html":!0,"v-model":!0,"v-create":!0,"v-update":!0,"v-cleanup":!0},f=new Set,v=new Set,h=new Set,g=new Set;function y(e){f.add(e)}function w(e){for(let t of e)t();e.clear()}var k={};function V(e){let t=e.target,o=`v-on${e.type}`;for(;t;){if(t[o])return t[o](e,t),void(e.defaultPrevented||A());t=t.parentNode}}var C=e=>(t,o,n)=>{if(e?t:!t){let e=document.createTextNode("");return n&&n.dom&&n.dom.parentNode&&n.dom.parentNode.replaceChild(e,n.dom),o.tag="#text",o.children=[],o.props={},o.dom=e,!1}},N={"v-if":C(!1),"v-unless":C(!0),"v-for":(e,t)=>{let o=[],n=t.children[0];for(let t=0,l=e.length;t<l;t++)o.push(n(e[t],t));t.children=o},"v-show":(e,t)=>{t.dom.style.display=e?"":"none"},"v-class":(e,t)=>{for(let o in e)t.dom.classList.toggle(o,e[o])},"v-html":(e,t)=>{t.children=[p(e)]},"v-model":([e,t,o],n,l)=>{let i,d=o=>e[t]=o.target.value;if("input"===n.tag)switch(o=o||"oninput",n.props.type){case"checkbox":Array.isArray(e[t])?(d=o=>{let n=o.target.value,l=e[t].indexOf(n);-1===l?e[t].push(n):e[t].splice(l,1)},i=-1!==e[t].indexOf(n.dom.value)):"value"in n.props?(d=()=>{e[t]===n.props.value?e[t]=null:e[t]=n.props.value},i=e[t]===n.props.value):(d=()=>e[t]=!e[t],i=e[t]),x("checked",i,n);break;case"radio":x("checked",e[t]===n.dom.value,n);break;default:x("value",e[t],n)}else"select"===n.tag?(o=o||"onclick",n.props.multiple?(d=o=>{let n=o.target.value;if(o.ctrlKey){let o=e[t].indexOf(n);-1===o?e[t].push(n):e[t].splice(o,1)}else e[t].splice(0,e[t].length),e[t].push(n)},n.children.forEach(o=>{if("option"===o.tag){let n="value"in o.props?o.props.value:o.children.join("").trim();o.props.selected=-1!==e[t].indexOf(n)}})):n.children.forEach(o=>{if("option"===o.tag){let n="value"in o.props?o.props.value:o.children.join("").trim();o.props.selected=n===e[t]}})):"textarea"===n.tag&&(o=o||"oninput",n.children=[e[t]]);let r=n.props[o];x(o,e=>{d(e),r&&r(e)},n,l)},"v-create":(e,t,o)=>{if(!o){let o=e(t);"function"==typeof o&&y(o)}},"v-update":(e,t,o)=>{if(o){let n=e(t,o);"function"==typeof n&&y(n)}},"v-cleanup":(e,t,o)=>{y(()=>e(t,o))}};function x(e,t,o,n){if("function"==typeof t){let n=e.toLowerCase();return n in k==!1&&(a.dom.addEventListener(n.slice(2),V),k[n]=!0),void(o.dom[`v-${n}`]=t)}e in o.dom&&!1===o.isSVG?o.dom[e]!=t&&(o.dom[e]=t):n&&t===n.props[e]||(!1===t?o.dom.removeAttribute(e):o.dom.setAttribute(e,t))}function S(e,t){if(t)for(let o in t.props)o in e.props==!1&&o in k==!1&&o in m==!1&&(o in e.dom&&!1===e.isSVG?e.dom[o]=null:e.dom.removeAttribute(o));for(let o in e.props)if(o in m){if(o in N&&!1===N[o](e.props[o],e,t))break}else x(o,e.props[o],e,t)}function b(t,l){let i=t.children,d=l?.children||[],r=d.length;if(r&&i[0]instanceof n&&"key"in i[0].props&&"key"in d[0].props){let e=i.length,n={};for(let e=0;e<r;e++)n[d[e].props.key]=e;let l={};for(let t=0;t<e;t++)l[i[t].props.key]=t;for(let l=0;l<e;l++){let e=i[l],r=d[n[e.props.key]],p=!0;r?(e.dom=r.dom,"v-keep"in e.props&&e.props["v-keep"]===r.props["v-keep"]?(e.children=r.children,p=!1):S(e,r)):(e.dom=o(e.tag,e.isSVG),S(e)),t.dom.childNodes[l]?t.dom.childNodes[l]!==e.dom&&t.dom.replaceChild(e.dom,t.dom.childNodes[l]):t.dom.appendChild(e.dom),p&&b(e,r)}for(let t=e;t<r;t++)l[d[t].props.key]||d[t].dom.parentNode&&d[t].dom.parentNode.removeChild(d[t].dom)}else if(0!==i.length){u.vnode=t,u.oldVnode=l;for(let t=0;t<i.length;t++){let o=i[t];if(o instanceof n&&o.tag!==e){if("string"==typeof o.tag)continue;u.component=o.tag,i.splice(t--,1,("view"in o.tag?o.tag.view.bind(o.tag):o.tag.bind(o.tag))(o.props,...o.children))}else Array.isArray(o)?i.splice(t--,1,...o):null!=o?o instanceof n?o.children[0]=o.dom.textContent:o=i[t]=new n(e,{},[o]):i.splice(t--,1)}for(let n=0;n<i.length;n++){let l=i[n];if(l.tag!==e)if(l.isSVG=t.isSVG||"svg"===l.tag,n<r){let e=d[n];if(l.tag===e.tag){if(l.dom=e.dom,"v-keep"in l.props&&l.props["v-keep"]===e.props["v-keep"]){l.children=e.children;continue}S(l,e),b(l,e);continue}l.dom=o(l.tag,l.isSVG),S(l),t.dom.replaceChild(l.dom,e.dom),b(l)}else l.dom=o(l.tag,l.isSVG),S(l),t.dom.appendChild(l.dom),b(l);else{if(n<r){let o=d[n];if(o.tag===e){l.dom=o.dom,l.children[0]!=o.dom.textContent&&(o.dom.textContent=l.children[0]);continue}l.dom=document.createTextNode(l.children[0]),t.dom.replaceChild(l.dom,o.dom);continue}l.dom=document.createTextNode(l.children[0]),t.dom.appendChild(l.dom)}}for(let e=i.length;e<r;e++)t.dom.removeChild(d[e].dom)}else t.dom.textContent=""}function A(){if(a){w(f);let e=a;if((a=new n(e.tag,e.props,[s])).dom=e.dom,a.isSVG=e.isSVG,b(a,e),w(c?h:v),c=!0,u.vnode=null,u.oldVnode=null,u.component=null,t)return a.dom.innerHTML}}function G(){if(a){s=new n(()=>null,{},[]);let e=A();w(g);for(let e in k)a.dom.removeEventListener(e.slice(2).toLowerCase(),V),Reflect.deleteProperty(k,e);return s=null,a=null,c=!1,u.vnode=null,u.oldVnode=null,u.component=null,e}}var L=(e,t={},...o)=>new n(e,t||{},o);L.fragment=(e,...t)=>t;var T={Vnode:n,createDomElement:o,current:u,directive:function(e,t){let o=`v-${e}`;N[o]=t,m[o]=!0},directives:N,isComponent:l,isNodeJs:t,isVnode:i,isVnodeComponent:d,mount:function(e,i){let p="string"==typeof e?t?o(e,"svg"===e):document.querySelectorAll(e)[0]:e,c=d(i)?i:l(i)?new n(i,{},[]):new n(()=>i,{},[]);return s&&s.tag!==c.tag&&G(),s=c,a=r(p),A()},onCleanup:y,onMount:function(e){c||v.add(e)},onUnmount:function(e){c||g.add(e)},onUpdate:function(e){h.add(e)},patch:b,reservedProps:m,setAttribute:function(e,t,o,n){e in m||(o.props[e]=t,x(e,t,o,n))},trust:p,unmount:G,update:A,updateAttributes:S,updateVnode:function(e,o){if(w(f),b(e,o),o.tag=e.tag,o.props={...e.props},o.children=[...e.children],w(c?h:v),c=!0,u.vnode=null,u.oldVnode=null,u.component=null,t)return e.dom.innerHTML},v:L};"undefined"!=typeof module?module.exports=T:self.Valyrian=T})();//# sourceMappingURL=index.min.js.map
1
+ (()=>{var e="#text",t=Boolean("undefined"!=typeof process&&process.versions&&process.versions.node);function n(e,t=!1){return t?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e)}var o=function(e,t,n){this.tag=e,this.props=t,this.children=n};function l(e){return e&&("function"==typeof e||"object"==typeof e&&"view"in e)}var d=e=>e instanceof o,i=e=>d(e)&&l(e.tag);function r(t){let n=[];for(let l=0,d=t.childNodes.length;l<d;l++){let d=t.childNodes[l];if(3!==d.nodeType)1===d.nodeType&&n.push(r(d));else{let t=new o(e,{},[d.nodeValue]);t.dom=d,n.push(t)}}let l={};for(let e=0,n=t.attributes.length;e<n;e++){let n=t.attributes[e];l[n.nodeName]=n.nodeValue}let d=new o(t.tagName.toLowerCase(),l,n);return d.dom=t,d}function p(e){let t=n("div");return t.innerHTML=e.trim(),[].map.call(t.childNodes,e=>r(e))}var s=null,a=null,c=!1,u={vnode:null,oldVnode:null,component:null,event:null},m={key:!0,state:!0,"v-keep":!0,"v-if":!0,"v-unless":!0,"v-for":!0,"v-show":!0,"v-class":!0,"v-html":!0,"v-model":!0,"v-create":!0,"v-update":!0,"v-cleanup":!0},f=new Set,v=new Set,h=new Set,g=new Set;function y(e){f.add(e)}function w(e){for(let t of e)t();e.clear()}var V={};function k(e){u.event=e;let t=e.target,n=`v-on${e.type}`;for(;t;){if(t[n])return t[n](e,t),void(e.defaultPrevented||G());t=t.parentNode}u.event=null}var C=e=>(t,n,o)=>{if(e?t:!t){let e=document.createTextNode("");return o&&o.dom&&o.dom.parentNode&&o.dom.parentNode.replaceChild(e,o.dom),n.tag="#text",n.children=[],n.props={},n.dom=e,!1}},N={"v-if":C(!1),"v-unless":C(!0),"v-for":(e,t)=>{let n=[],o=t.children[0];for(let t=0,l=e.length;t<l;t++)n.push(o(e[t],t));t.children=n},"v-show":(e,t)=>{t.dom.style.display=e?"":"none"},"v-class":(e,t)=>{for(let n in e)t.dom.classList.toggle(n,e[n])},"v-html":(e,t)=>{t.children=[p(e)]},"v-model":([e,t,n],o,l)=>{let d,i=n=>e[t]=n.target.value;if("input"===o.tag)switch(n=n||"oninput",o.props.type){case"checkbox":Array.isArray(e[t])?(i=n=>{let o=n.target.value,l=e[t].indexOf(o);-1===l?e[t].push(o):e[t].splice(l,1)},d=-1!==e[t].indexOf(o.dom.value)):"value"in o.props?(i=()=>{e[t]===o.props.value?e[t]=null:e[t]=o.props.value},d=e[t]===o.props.value):(i=()=>e[t]=!e[t],d=e[t]),S("checked",d,o);break;case"radio":S("checked",e[t]===o.dom.value,o);break;default:S("value",e[t],o)}else"select"===o.tag?(n=n||"onclick",o.props.multiple?(i=n=>{let o=n.target.value;if(n.ctrlKey){let n=e[t].indexOf(o);-1===n?e[t].push(o):e[t].splice(n,1)}else e[t].splice(0,e[t].length),e[t].push(o)},o.children.forEach(n=>{if("option"===n.tag){let o="value"in n.props?n.props.value:n.children.join("").trim();n.props.selected=-1!==e[t].indexOf(o)}})):o.children.forEach(n=>{if("option"===n.tag){let o="value"in n.props?n.props.value:n.children.join("").trim();n.props.selected=o===e[t]}})):"textarea"===o.tag&&(n=n||"oninput",o.children=[e[t]]);let r=o.props[n];S(n,e=>{i(e),r&&r(e)},o,l)},"v-create":(e,t,n)=>{if(!n){let n=e(t);"function"==typeof n&&y(n)}},"v-update":(e,t,n)=>{if(n){let o=e(t,n);"function"==typeof o&&y(o)}},"v-cleanup":(e,t,n)=>{y(()=>e(t,n))}};function S(e,t,n,o){if("function"==typeof t)return e in V==!1&&(a.dom.addEventListener(e.slice(2),k),V[e]=!0),void(n.dom[`v-${e}`]=t);e in n.dom&&!1===n.isSVG?n.dom[e]!=t&&(n.dom[e]=t):o&&t===o.props[e]||(!1===t?n.dom.removeAttribute(e):n.dom.setAttribute(e,t))}function x(e,t){if(t)for(let n in t.props)n in e.props==!1&&n in V==!1&&n in m==!1&&(n in e.dom&&!1===e.isSVG?e.dom[n]=null:e.dom.removeAttribute(n));for(let n in e.props)if(n in m){if(n in N&&!1===N[n](e.props[n],e,t))break}else S(n,e.props[n],e,t)}function b(t,l){if(0===t.children.length)return void(t.dom.textContent="");let d=t.children,i=l?.children||[],r=i.length;if(r&&d[0]instanceof o&&"key"in d[0].props&&"key"in i[0].props){let e=d.length,o={};for(let e=0;e<r;e++)o[i[e].props.key]=e;let l={};for(let t=0;t<e;t++)l[d[t].props.key]=t;for(let l=0;l<e;l++){let e=d[l],r=i[o[e.props.key]],p=!0;r?(e.dom=r.dom,"v-keep"in e.props&&e.props["v-keep"]===r.props["v-keep"]?(e.children=r.children,p=!1):x(e,r)):(e.dom=n(e.tag,e.isSVG),x(e)),t.dom.childNodes[l]?t.dom.childNodes[l]!==e.dom&&t.dom.replaceChild(e.dom,t.dom.childNodes[l]):t.dom.appendChild(e.dom),p&&b(e,r)}for(let t=e;t<r;t++)l[i[t].props.key]||i[t].dom.parentNode&&i[t].dom.parentNode.removeChild(i[t].dom)}else if(0!==d.length){u.vnode=t,u.oldVnode=l;for(let t=0;t<d.length;t++){let n=d[t];n instanceof o?"string"!=typeof n.tag&&(u.component=n.tag,d.splice(t--,1,("view"in n.tag?n.tag.view.bind(n.tag):n.tag.bind(n.tag))(n.props,...n.children))):Array.isArray(n)?d.splice(t--,1,...n):null!=n?d[t]=new o(e,{},[n]):d.splice(t--,1)}for(let o=0;o<d.length;o++){let l=d[o];if(l.tag===e){if(o>=r){l.dom=document.createTextNode(l.children[0]),t.dom.appendChild(l.dom);continue}let n=i[o];if(n.tag!==e){l.dom=document.createTextNode(l.children[0]),t.dom.replaceChild(l.dom,n.dom);continue}l.dom=n.dom,l.children[0]!=n.dom.textContent&&(n.dom.textContent=l.children[0]);continue}if(l.isSVG=t.isSVG||"svg"===l.tag,o>=r){l.dom=n(l.tag,l.isSVG),x(l),t.dom.appendChild(l.dom),b(l);continue}let p=i[o];l.tag===p.tag?(l.dom=p.dom,"v-keep"in l.props&&l.props["v-keep"]===p.props["v-keep"]?l.children=p.children:(x(l,p),b(l,p))):(l.dom=n(l.tag,l.isSVG),x(l),t.dom.replaceChild(l.dom,p.dom),b(l))}for(let e=d.length;e<r;e++)t.dom.removeChild(i[e].dom)}else t.dom.textContent=""}function G(){if(a){w(f);let e=a;if((a=new o(e.tag,e.props,[s])).dom=e.dom,a.isSVG=e.isSVG,b(a,e),w(c?h:v),c=!0,u.vnode=null,u.oldVnode=null,u.component=null,t)return a.dom.innerHTML}}function A(){if(a){s=new o(()=>null,{},[]);let e=G();w(g);for(let e in V)a.dom.removeEventListener(e.slice(2).toLowerCase(),k),Reflect.deleteProperty(V,e);return s=null,a=null,c=!1,u.vnode=null,u.oldVnode=null,u.component=null,e}}var L=(e,t={},...n)=>new o(e,t||{},n);L.fragment=(e,...t)=>t;var T={Vnode:o,createDomElement:n,current:u,directive:function(e,t){let n=`v-${e}`;N[n]=t,m[n]=!0},directives:N,isComponent:l,isNodeJs:t,isVnode:d,isVnodeComponent:i,mount:function(e,d){let p="string"==typeof e?t?n(e,"svg"===e):document.querySelectorAll(e)[0]:e,c=i(d)?d:l(d)?new o(d,{},[]):new o(()=>d,{},[]);return s&&s.tag!==c.tag&&A(),s=c,a=r(p),G()},onCleanup:y,onMount:function(e){c||v.add(e)},onUnmount:function(e){c||g.add(e)},onUpdate:function(e){h.add(e)},patch:b,reservedProps:m,setAttribute:function(e,t,n,o){e in m||(n.props[e]=t,S(e,t,n,o))},trust:p,unmount:A,update:G,updateAttributes:x,updateVnode:function(e,n){if(w(f),b(e,n),n.tag=e.tag,n.props={...e.props},n.children=[...e.children],n.dom=e.dom,n.isSVG=e.isSVG,w(c?h:v),c=!0,u.vnode=null,u.oldVnode=null,u.component=null,t)return e.dom.innerHTML},v:L};"undefined"!=typeof module?module.exports=T:self.Valyrian=T})();//# sourceMappingURL=index.min.js.map