⌈⌋ ⎇ branch:  Bitrhythm


Hex Artifact Content

Artifact 4b6245ca922fdaf60af6d465f61c646da143c7626c6bd78130284681a81be836:


0000: 69 6d 70 6f 72 74 20 73 74 79 6c 65 4d 61 6e 61  import styleMana
0010: 67 65 72 20 66 72 6f 6d 20 27 2e 2f 73 74 79 6c  ger from './styl
0020: 65 4d 61 6e 61 67 65 72 27 0a 69 6d 70 6f 72 74  eManager'.import
0030: 20 69 73 53 74 72 69 6e 67 20 66 72 6f 6d 20 27   isString from '
0040: 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c  ./../common/util
0050: 2f 63 68 65 63 6b 73 2f 69 73 2d 73 74 72 69 6e  /checks/is-strin
0060: 67 27 0a 69 6d 70 6f 72 74 20 69 73 55 6e 64 65  g'.import isUnde
0070: 66 69 6e 65 64 20 66 72 6f 6d 20 27 2e 2f 2e 2e  fined from './..
0080: 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 63 68 65  /common/util/che
0090: 63 6b 73 2f 69 73 2d 75 6e 64 65 66 69 6e 65 64  cks/is-undefined
00a0: 27 0a 69 6d 70 6f 72 74 20 69 73 4f 62 6a 65 63  '.import isObjec
00b0: 74 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d  t from './../com
00c0: 6d 6f 6e 2f 75 74 69 6c 2f 63 68 65 63 6b 73 2f  mon/util/checks/
00d0: 69 73 2d 6f 62 6a 65 63 74 27 0a 69 6d 70 6f 72  is-object'.impor
00e0: 74 20 69 73 46 75 6e 63 74 69 6f 6e 20 66 72 6f  t isFunction fro
00f0: 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75  m './../common/u
0100: 74 69 6c 2f 63 68 65 63 6b 73 2f 69 73 2d 66 75  til/checks/is-fu
0110: 6e 63 74 69 6f 6e 27 0a 69 6d 70 6f 72 74 20 73  nction'.import s
0120: 65 74 41 74 74 72 69 62 75 74 65 20 66 72 6f 6d  etAttribute from
0130: 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74   './../common/ut
0140: 69 6c 2f 64 6f 6d 2f 73 65 74 2d 61 74 74 72 69  il/dom/set-attri
0150: 62 75 74 65 27 0a 69 6d 70 6f 72 74 20 67 65 74  bute'.import get
0160: 41 74 74 72 69 62 75 74 65 20 66 72 6f 6d 20 27  Attribute from '
0170: 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c  ./../common/util
0180: 2f 64 6f 6d 2f 67 65 74 2d 61 74 74 72 69 62 75  /dom/get-attribu
0190: 74 65 27 0a 69 6d 70 6f 72 74 20 24 24 20 66 72  te'.import $$ fr
01a0: 6f 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f  om './../common/
01b0: 75 74 69 6c 2f 64 6f 6d 2f 24 24 27 0a 69 6d 70  util/dom/$$'.imp
01c0: 6f 72 74 20 65 61 63 68 20 66 72 6f 6d 20 27 2e  ort each from '.
01d0: 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f  /../common/util/
01e0: 6d 69 73 63 2f 65 61 63 68 27 0a 69 6d 70 6f 72  misc/each'.impor
01f0: 74 20 65 78 74 65 6e 64 20 66 72 6f 6d 20 27 2e  t extend from '.
0200: 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f  /../common/util/
0210: 6d 69 73 63 2f 65 78 74 65 6e 64 27 0a 69 6d 70  misc/extend'.imp
0220: 6f 72 74 20 6d 6f 75 6e 74 54 6f 20 66 72 6f 6d  ort mountTo from
0230: 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74   './../common/ut
0240: 69 6c 2f 74 61 67 73 2f 6d 6f 75 6e 74 27 0a 69  il/tags/mount'.i
0250: 6d 70 6f 72 74 20 71 75 65 72 79 20 66 72 6f 6d  mport query from
0260: 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74   './../common/ut
0270: 69 6c 2f 74 61 67 73 2f 71 75 65 72 79 27 0a 0a  il/tags/query'..
0280: 69 6d 70 6f 72 74 20 7b 0a 20 20 5f 5f 54 41 47  import {.  __TAG
0290: 5f 49 4d 50 4c 2c 0a 20 20 5f 5f 54 41 47 53 5f  _IMPL,.  __TAGS_
02a0: 43 41 43 48 45 2c 0a 20 20 47 4c 4f 42 41 4c 5f  CACHE,.  GLOBAL_
02b0: 4d 49 58 49 4e 2c 0a 20 20 49 53 5f 44 49 52 45  MIXIN,.  IS_DIRE
02c0: 43 54 49 56 45 0a 7d 20 66 72 6f 6d 20 27 2e 2f  CTIVE.} from './
02d0: 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 67 6c 6f 62 61 6c  ../common/global
02e0: 2d 76 61 72 69 61 62 6c 65 73 27 0a 0a 2f 2a 2a  -variables'../**
02f0: 0a 20 2a 20 41 6e 6f 74 68 65 72 20 77 61 79 20  . * Another way 
0300: 74 6f 20 63 72 65 61 74 65 20 61 20 72 69 6f 74  to create a riot
0310: 20 74 61 67 20 61 20 62 69 74 20 6d 6f 72 65 20   tag a bit more 
0320: 65 73 36 20 66 72 69 65 6e 64 6c 79 0a 20 2a 20  es6 friendly. * 
0330: 40 70 61 72 61 6d 20 7b 20 48 54 4d 4c 45 6c 65  @param { HTMLEle
0340: 6d 65 6e 74 20 7d 20 65 6c 20 2d 20 74 61 67 20  ment } el - tag 
0350: 44 4f 4d 20 73 65 6c 65 63 74 6f 72 20 6f 72 20  DOM selector or 
0360: 44 4f 4d 20 6e 6f 64 65 2f 73 0a 20 2a 20 40 70  DOM node/s. * @p
0370: 61 72 61 6d 20 7b 20 4f 62 6a 65 63 74 20 7d 20  aram { Object } 
0380: 6f 70 74 73 20 2d 20 74 61 67 20 6c 6f 67 69 63  opts - tag logic
0390: 0a 20 2a 20 40 72 65 74 75 72 6e 73 20 7b 20 54  . * @returns { T
03a0: 61 67 20 7d 20 6e 65 77 20 72 69 6f 74 20 74 61  ag } new riot ta
03b0: 67 20 69 6e 73 74 61 6e 63 65 0a 20 2a 2f 0a 65  g instance. */.e
03c0: 78 70 6f 72 74 20 66 75 6e 63 74 69 6f 6e 20 54  xport function T
03d0: 61 67 28 65 6c 2c 20 6f 70 74 73 29 20 7b 0a 20  ag(el, opts) {. 
03e0: 20 2f 2f 20 67 65 74 20 74 68 65 20 74 61 67 20   // get the tag 
03f0: 70 72 6f 70 65 72 74 69 65 73 20 66 72 6f 6d 20  properties from 
0400: 74 68 65 20 63 6c 61 73 73 20 63 6f 6e 73 74 72  the class constr
0410: 75 63 74 6f 72 0a 20 20 63 6f 6e 73 74 20 7b 6e  uctor.  const {n
0420: 61 6d 65 2c 20 74 6d 70 6c 2c 20 63 73 73 2c 20  ame, tmpl, css, 
0430: 61 74 74 72 73 2c 20 6f 6e 43 72 65 61 74 65 7d  attrs, onCreate}
0440: 20 3d 20 74 68 69 73 0a 20 20 2f 2f 20 72 65 67   = this.  // reg
0450: 69 73 74 65 72 20 61 20 6e 65 77 20 74 61 67 20  ister a new tag 
0460: 61 6e 64 20 63 61 63 68 65 20 74 68 65 20 63 6c  and cache the cl
0470: 61 73 73 20 70 72 6f 74 6f 74 79 70 65 0a 20 20  ass prototype.  
0480: 69 66 20 28 21 5f 5f 54 41 47 5f 49 4d 50 4c 5b  if (!__TAG_IMPL[
0490: 6e 61 6d 65 5d 29 20 7b 0a 20 20 20 20 74 61 67  name]) {.    tag
04a0: 28 6e 61 6d 65 2c 20 74 6d 70 6c 2c 20 63 73 73  (name, tmpl, css
04b0: 2c 20 61 74 74 72 73 2c 20 6f 6e 43 72 65 61 74  , attrs, onCreat
04c0: 65 29 0a 20 20 20 20 2f 2f 20 63 61 63 68 65 20  e).    // cache 
04d0: 74 68 65 20 63 6c 61 73 73 20 63 6f 6e 73 74 72  the class constr
04e0: 75 63 74 6f 72 0a 20 20 20 20 5f 5f 54 41 47 5f  uctor.    __TAG_
04f0: 49 4d 50 4c 5b 6e 61 6d 65 5d 2e 63 6c 61 73 73  IMPL[name].class
0500: 20 3d 20 74 68 69 73 2e 63 6f 6e 73 74 72 75 63   = this.construc
0510: 74 6f 72 0a 20 20 7d 0a 0a 20 20 2f 2f 20 6d 6f  tor.  }..  // mo
0520: 75 6e 74 20 74 68 65 20 74 61 67 20 75 73 69 6e  unt the tag usin
0530: 67 20 74 68 65 20 63 6c 61 73 73 20 69 6e 73 74  g the class inst
0540: 61 6e 63 65 0a 20 20 6d 6f 75 6e 74 54 6f 28 65  ance.  mountTo(e
0550: 6c 2c 20 6e 61 6d 65 2c 20 6f 70 74 73 2c 20 74  l, name, opts, t
0560: 68 69 73 29 0a 20 20 2f 2f 20 69 6e 6a 65 63 74  his).  // inject
0570: 20 74 68 65 20 63 6f 6d 70 6f 6e 65 6e 74 20 63   the component c
0580: 73 73 0a 20 20 69 66 20 28 63 73 73 29 20 73 74  ss.  if (css) st
0590: 79 6c 65 4d 61 6e 61 67 65 72 2e 69 6e 6a 65 63  yleManager.injec
05a0: 74 28 29 0a 0a 20 20 72 65 74 75 72 6e 20 74 68  t()..  return th
05b0: 69 73 0a 7d 0a 0a 2f 2a 2a 0a 20 2a 20 43 72 65  is.}../**. * Cre
05c0: 61 74 65 20 61 20 6e 65 77 20 72 69 6f 74 20 74  ate a new riot t
05d0: 61 67 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f  ag implementatio
05e0: 6e 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 20  n. * @param   { 
05f0: 53 74 72 69 6e 67 20 7d 20 20 20 6e 61 6d 65 20  String }   name 
0600: 2d 20 6e 61 6d 65 2f 69 64 20 6f 66 20 74 68 65  - name/id of the
0610: 20 6e 65 77 20 72 69 6f 74 20 74 61 67 0a 20 2a   new riot tag. *
0620: 20 40 70 61 72 61 6d 20 20 20 7b 20 53 74 72 69   @param   { Stri
0630: 6e 67 20 7d 20 20 20 74 6d 70 6c 20 2d 20 74 61  ng }   tmpl - ta
0640: 67 20 74 65 6d 70 6c 61 74 65 0a 20 2a 20 40 70  g template. * @p
0650: 61 72 61 6d 20 20 20 7b 20 53 74 72 69 6e 67 20  aram   { String 
0660: 7d 20 20 20 63 73 73 20 2d 20 63 75 73 74 6f 6d  }   css - custom
0670: 20 74 61 67 20 63 73 73 0a 20 2a 20 40 70 61 72   tag css. * @par
0680: 61 6d 20 20 20 7b 20 53 74 72 69 6e 67 20 7d 20  am   { String } 
0690: 20 20 61 74 74 72 73 20 2d 20 72 6f 6f 74 20 74    attrs - root t
06a0: 61 67 20 61 74 74 72 69 62 75 74 65 73 0a 20 2a  ag attributes. *
06b0: 20 40 70 61 72 61 6d 20 20 20 7b 20 46 75 6e 63   @param   { Func
06c0: 74 69 6f 6e 20 7d 20 66 6e 20 2d 20 75 73 65 72  tion } fn - user
06d0: 20 66 75 6e 63 74 69 6f 6e 0a 20 2a 20 40 72 65   function. * @re
06e0: 74 75 72 6e 73 20 7b 20 53 74 72 69 6e 67 20 7d  turns { String }
06f0: 20 6e 61 6d 65 2f 69 64 20 6f 66 20 74 68 65 20   name/id of the 
0700: 74 61 67 20 6a 75 73 74 20 63 72 65 61 74 65 64  tag just created
0710: 0a 20 2a 2f 0a 65 78 70 6f 72 74 20 66 75 6e 63  . */.export func
0720: 74 69 6f 6e 20 74 61 67 28 6e 61 6d 65 2c 20 74  tion tag(name, t
0730: 6d 70 6c 2c 20 63 73 73 2c 20 61 74 74 72 73 2c  mpl, css, attrs,
0740: 20 66 6e 29 20 7b 0a 20 20 69 66 20 28 69 73 46   fn) {.  if (isF
0750: 75 6e 63 74 69 6f 6e 28 61 74 74 72 73 29 29 20  unction(attrs)) 
0760: 7b 0a 20 20 20 20 66 6e 20 3d 20 61 74 74 72 73  {.    fn = attrs
0770: 0a 0a 20 20 20 20 69 66 20 28 2f 5e 5b 5c 77 2d  ..    if (/^[\w-
0780: 5d 2b 5c 73 3f 3d 2f 2e 74 65 73 74 28 63 73 73  ]+\s?=/.test(css
0790: 29 29 20 7b 0a 20 20 20 20 20 20 61 74 74 72 73  )) {.      attrs
07a0: 20 3d 20 63 73 73 0a 20 20 20 20 20 20 63 73 73   = css.      css
07b0: 20 3d 20 27 27 0a 20 20 20 20 7d 20 65 6c 73 65   = ''.    } else
07c0: 0a 20 20 20 20 20 20 61 74 74 72 73 20 3d 20 27  .      attrs = '
07d0: 27 0a 20 20 7d 0a 0a 20 20 69 66 20 28 63 73 73  '.  }..  if (css
07e0: 29 20 7b 0a 20 20 20 20 69 66 20 28 69 73 46 75  ) {.    if (isFu
07f0: 6e 63 74 69 6f 6e 28 63 73 73 29 29 0a 20 20 20  nction(css)).   
0800: 20 20 20 66 6e 20 3d 20 63 73 73 0a 20 20 20 20     fn = css.    
0810: 65 6c 73 65 0a 20 20 20 20 20 20 73 74 79 6c 65  else.      style
0820: 4d 61 6e 61 67 65 72 2e 61 64 64 28 63 73 73 2c  Manager.add(css,
0830: 20 6e 61 6d 65 29 0a 20 20 7d 0a 0a 20 20 6e 61   name).  }..  na
0840: 6d 65 20 3d 20 6e 61 6d 65 2e 74 6f 4c 6f 77 65  me = name.toLowe
0850: 72 43 61 73 65 28 29 0a 20 20 5f 5f 54 41 47 5f  rCase().  __TAG_
0860: 49 4d 50 4c 5b 6e 61 6d 65 5d 20 3d 20 7b 20 6e  IMPL[name] = { n
0870: 61 6d 65 2c 20 74 6d 70 6c 2c 20 61 74 74 72 73  ame, tmpl, attrs
0880: 2c 20 66 6e 20 7d 0a 0a 20 20 72 65 74 75 72 6e  , fn }..  return
0890: 20 6e 61 6d 65 0a 7d 0a 0a 2f 2a 2a 0a 20 2a 20   name.}../**. * 
08a0: 43 72 65 61 74 65 20 61 20 6e 65 77 20 72 69 6f  Create a new rio
08b0: 74 20 74 61 67 20 69 6d 70 6c 65 6d 65 6e 74 61  t tag implementa
08c0: 74 69 6f 6e 20 28 66 6f 72 20 75 73 65 20 62 79  tion (for use by
08d0: 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 29 0a 20   the compiler). 
08e0: 2a 20 40 70 61 72 61 6d 20 20 20 7b 20 53 74 72  * @param   { Str
08f0: 69 6e 67 20 7d 20 20 20 6e 61 6d 65 20 2d 20 6e  ing }   name - n
0900: 61 6d 65 2f 69 64 20 6f 66 20 74 68 65 20 6e 65  ame/id of the ne
0910: 77 20 72 69 6f 74 20 74 61 67 0a 20 2a 20 40 70  w riot tag. * @p
0920: 61 72 61 6d 20 20 20 7b 20 53 74 72 69 6e 67 20  aram   { String 
0930: 7d 20 20 20 74 6d 70 6c 20 2d 20 74 61 67 20 74  }   tmpl - tag t
0940: 65 6d 70 6c 61 74 65 0a 20 2a 20 40 70 61 72 61  emplate. * @para
0950: 6d 20 20 20 7b 20 53 74 72 69 6e 67 20 7d 20 20  m   { String }  
0960: 20 63 73 73 20 2d 20 63 75 73 74 6f 6d 20 74 61   css - custom ta
0970: 67 20 63 73 73 0a 20 2a 20 40 70 61 72 61 6d 20  g css. * @param 
0980: 20 20 7b 20 53 74 72 69 6e 67 20 7d 20 20 20 61    { String }   a
0990: 74 74 72 73 20 2d 20 72 6f 6f 74 20 74 61 67 20  ttrs - root tag 
09a0: 61 74 74 72 69 62 75 74 65 73 0a 20 2a 20 40 70  attributes. * @p
09b0: 61 72 61 6d 20 20 20 7b 20 46 75 6e 63 74 69 6f  aram   { Functio
09c0: 6e 20 7d 20 66 6e 20 2d 20 75 73 65 72 20 66 75  n } fn - user fu
09d0: 6e 63 74 69 6f 6e 0a 20 2a 20 40 72 65 74 75 72  nction. * @retur
09e0: 6e 73 20 7b 20 53 74 72 69 6e 67 20 7d 20 6e 61  ns { String } na
09f0: 6d 65 2f 69 64 20 6f 66 20 74 68 65 20 74 61 67  me/id of the tag
0a00: 20 6a 75 73 74 20 63 72 65 61 74 65 64 0a 20 2a   just created. *
0a10: 2f 0a 65 78 70 6f 72 74 20 66 75 6e 63 74 69 6f  /.export functio
0a20: 6e 20 74 61 67 32 28 6e 61 6d 65 2c 20 74 6d 70  n tag2(name, tmp
0a30: 6c 2c 20 63 73 73 2c 20 61 74 74 72 73 2c 20 66  l, css, attrs, f
0a40: 6e 29 20 7b 0a 20 20 69 66 20 28 63 73 73 29 20  n) {.  if (css) 
0a50: 73 74 79 6c 65 4d 61 6e 61 67 65 72 2e 61 64 64  styleManager.add
0a60: 28 63 73 73 2c 20 6e 61 6d 65 29 0a 0a 20 20 5f  (css, name)..  _
0a70: 5f 54 41 47 5f 49 4d 50 4c 5b 6e 61 6d 65 5d 20  _TAG_IMPL[name] 
0a80: 3d 20 7b 20 6e 61 6d 65 2c 20 74 6d 70 6c 2c 20  = { name, tmpl, 
0a90: 61 74 74 72 73 2c 20 66 6e 20 7d 0a 0a 20 20 72  attrs, fn }..  r
0aa0: 65 74 75 72 6e 20 6e 61 6d 65 0a 7d 0a 0a 2f 2a  eturn name.}../*
0ab0: 2a 0a 20 2a 20 4d 6f 75 6e 74 20 61 20 74 61 67  *. * Mount a tag
0ac0: 20 75 73 69 6e 67 20 61 20 73 70 65 63 69 66 69   using a specifi
0ad0: 63 20 74 61 67 20 69 6d 70 6c 65 6d 65 6e 74 61  c tag implementa
0ae0: 74 69 6f 6e 0a 20 2a 20 40 70 61 72 61 6d 20 20  tion. * @param  
0af0: 20 7b 20 2a 20 7d 20 73 65 6c 65 63 74 6f 72 20   { * } selector 
0b00: 2d 20 74 61 67 20 44 4f 4d 20 73 65 6c 65 63 74  - tag DOM select
0b10: 6f 72 20 6f 72 20 44 4f 4d 20 6e 6f 64 65 2f 73  or or DOM node/s
0b20: 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 20 53  . * @param   { S
0b30: 74 72 69 6e 67 20 7d 20 74 61 67 4e 61 6d 65 20  tring } tagName 
0b40: 2d 20 74 61 67 20 69 6d 70 6c 65 6d 65 6e 74 61  - tag implementa
0b50: 74 69 6f 6e 20 6e 61 6d 65 0a 20 2a 20 40 70 61  tion name. * @pa
0b60: 72 61 6d 20 20 20 7b 20 4f 62 6a 65 63 74 20 7d  ram   { Object }
0b70: 20 6f 70 74 73 20 2d 20 74 61 67 20 6c 6f 67 69   opts - tag logi
0b80: 63 0a 20 2a 20 40 72 65 74 75 72 6e 73 20 7b 20  c. * @returns { 
0b90: 41 72 72 61 79 20 7d 20 6e 65 77 20 74 61 67 73  Array } new tags
0ba0: 20 69 6e 73 74 61 6e 63 65 73 0a 20 2a 2f 0a 65   instances. */.e
0bb0: 78 70 6f 72 74 20 66 75 6e 63 74 69 6f 6e 20 6d  xport function m
0bc0: 6f 75 6e 74 28 73 65 6c 65 63 74 6f 72 2c 20 74  ount(selector, t
0bd0: 61 67 4e 61 6d 65 2c 20 6f 70 74 73 29 20 7b 0a  agName, opts) {.
0be0: 20 20 63 6f 6e 73 74 20 74 61 67 73 20 3d 20 5b    const tags = [
0bf0: 5d 0a 20 20 6c 65 74 20 65 6c 65 6d 2c 20 61 6c  ].  let elem, al
0c00: 6c 54 61 67 73 0a 0a 20 20 66 75 6e 63 74 69 6f  lTags..  functio
0c10: 6e 20 70 75 73 68 54 61 67 73 54 6f 28 72 6f 6f  n pushTagsTo(roo
0c20: 74 29 20 7b 0a 20 20 20 20 69 66 20 28 72 6f 6f  t) {.    if (roo
0c30: 74 2e 74 61 67 4e 61 6d 65 29 20 7b 0a 20 20 20  t.tagName) {.   
0c40: 20 20 20 6c 65 74 20 72 69 6f 74 54 61 67 20 3d     let riotTag =
0c50: 20 67 65 74 41 74 74 72 69 62 75 74 65 28 72 6f   getAttribute(ro
0c60: 6f 74 2c 20 49 53 5f 44 49 52 45 43 54 49 56 45  ot, IS_DIRECTIVE
0c70: 29 2c 20 74 61 67 0a 0a 20 20 20 20 20 20 2f 2f  ), tag..      //
0c80: 20 68 61 76 65 20 74 61 67 4e 61 6d 65 3f 20 66   have tagName? f
0c90: 6f 72 63 65 20 72 69 6f 74 2d 74 61 67 20 74 6f  orce riot-tag to
0ca0: 20 62 65 20 74 68 65 20 73 61 6d 65 0a 20 20 20   be the same.   
0cb0: 20 20 20 69 66 20 28 74 61 67 4e 61 6d 65 20 26     if (tagName &
0cc0: 26 20 72 69 6f 74 54 61 67 20 21 3d 3d 20 74 61  & riotTag !== ta
0cd0: 67 4e 61 6d 65 29 20 7b 0a 20 20 20 20 20 20 20  gName) {.       
0ce0: 20 72 69 6f 74 54 61 67 20 3d 20 74 61 67 4e 61   riotTag = tagNa
0cf0: 6d 65 0a 20 20 20 20 20 20 20 20 73 65 74 41 74  me.        setAt
0d00: 74 72 69 62 75 74 65 28 72 6f 6f 74 2c 20 49 53  tribute(root, IS
0d10: 5f 44 49 52 45 43 54 49 56 45 2c 20 74 61 67 4e  _DIRECTIVE, tagN
0d20: 61 6d 65 29 0a 20 20 20 20 20 20 7d 0a 0a 20 20  ame).      }..  
0d30: 20 20 20 20 74 61 67 20 3d 20 6d 6f 75 6e 74 54      tag = mountT
0d40: 6f 28 0a 20 20 20 20 20 20 20 20 72 6f 6f 74 2c  o(.        root,
0d50: 0a 20 20 20 20 20 20 20 20 72 69 6f 74 54 61 67  .        riotTag
0d60: 20 7c 7c 20 72 6f 6f 74 2e 74 61 67 4e 61 6d 65   || root.tagName
0d70: 2e 74 6f 4c 6f 77 65 72 43 61 73 65 28 29 2c 0a  .toLowerCase(),.
0d80: 20 20 20 20 20 20 20 20 69 73 46 75 6e 63 74 69          isFuncti
0d90: 6f 6e 28 6f 70 74 73 29 20 3f 20 6f 70 74 73 28  on(opts) ? opts(
0da0: 29 20 3a 20 6f 70 74 73 0a 20 20 20 20 20 20 29  ) : opts.      )
0db0: 0a 0a 20 20 20 20 20 20 69 66 20 28 74 61 67 29  ..      if (tag)
0dc0: 0a 20 20 20 20 20 20 20 20 74 61 67 73 2e 70 75  .        tags.pu
0dd0: 73 68 28 74 61 67 29 0a 20 20 20 20 7d 20 65 6c  sh(tag).    } el
0de0: 73 65 20 69 66 20 28 72 6f 6f 74 2e 6c 65 6e 67  se if (root.leng
0df0: 74 68 29 0a 20 20 20 20 20 20 65 61 63 68 28 72  th).      each(r
0e00: 6f 6f 74 2c 20 70 75 73 68 54 61 67 73 54 6f 29  oot, pushTagsTo)
0e10: 20 2f 2f 20 61 73 73 75 6d 65 20 6e 6f 64 65 4c   // assume nodeL
0e20: 69 73 74 0a 20 20 7d 0a 0a 20 20 2f 2f 20 69 6e  ist.  }..  // in
0e30: 6a 65 63 74 20 73 74 79 6c 65 73 20 69 6e 74 6f  ject styles into
0e40: 20 44 4f 4d 0a 20 20 73 74 79 6c 65 4d 61 6e 61   DOM.  styleMana
0e50: 67 65 72 2e 69 6e 6a 65 63 74 28 29 0a 0a 20 20  ger.inject()..  
0e60: 69 66 20 28 69 73 4f 62 6a 65 63 74 28 74 61 67  if (isObject(tag
0e70: 4e 61 6d 65 29 20 7c 7c 20 69 73 46 75 6e 63 74  Name) || isFunct
0e80: 69 6f 6e 28 74 61 67 4e 61 6d 65 29 29 20 7b 0a  ion(tagName)) {.
0e90: 20 20 20 20 6f 70 74 73 20 3d 20 74 61 67 4e 61      opts = tagNa
0ea0: 6d 65 0a 20 20 20 20 74 61 67 4e 61 6d 65 20 3d  me.    tagName =
0eb0: 20 30 0a 20 20 7d 0a 0a 20 20 2f 2f 20 63 72 61   0.  }..  // cra
0ec0: 77 6c 20 74 68 65 20 44 4f 4d 20 74 6f 20 66 69  wl the DOM to fi
0ed0: 6e 64 20 74 68 65 20 74 61 67 0a 20 20 69 66 20  nd the tag.  if 
0ee0: 28 69 73 53 74 72 69 6e 67 28 73 65 6c 65 63 74  (isString(select
0ef0: 6f 72 29 29 20 7b 0a 20 20 20 20 73 65 6c 65 63  or)) {.    selec
0f00: 74 6f 72 20 3d 20 73 65 6c 65 63 74 6f 72 20 3d  tor = selector =
0f10: 3d 3d 20 27 2a 27 20 3f 0a 20 20 20 20 20 20 2f  == '*' ?.      /
0f20: 2f 20 73 65 6c 65 63 74 20 61 6c 6c 20 72 65 67  / select all reg
0f30: 69 73 74 65 72 65 64 20 74 61 67 73 0a 20 20 20  istered tags.   
0f40: 20 20 20 2f 2f 20 26 20 74 61 67 73 20 66 6f 75     // & tags fou
0f50: 6e 64 20 77 69 74 68 20 74 68 65 20 72 69 6f 74  nd with the riot
0f60: 2d 74 61 67 20 61 74 74 72 69 62 75 74 65 20 73  -tag attribute s
0f70: 65 74 0a 20 20 20 20 20 20 61 6c 6c 54 61 67 73  et.      allTags
0f80: 20 3d 20 71 75 65 72 79 28 29 20 3a 0a 20 20 20   = query() :.   
0f90: 20 20 20 2f 2f 20 6f 72 20 6a 75 73 74 20 74 68     // or just th
0fa0: 65 20 6f 6e 65 73 20 6e 61 6d 65 64 20 6c 69 6b  e ones named lik
0fb0: 65 20 74 68 65 20 73 65 6c 65 63 74 6f 72 0a 20  e the selector. 
0fc0: 20 20 20 20 20 73 65 6c 65 63 74 6f 72 20 2b 20       selector + 
0fd0: 71 75 65 72 79 28 73 65 6c 65 63 74 6f 72 2e 73  query(selector.s
0fe0: 70 6c 69 74 28 2f 2c 20 2a 2f 29 29 0a 0a 20 20  plit(/, */))..  
0ff0: 20 20 2f 2f 20 6d 61 6b 65 20 73 75 72 65 20 74    // make sure t
1000: 6f 20 70 61 73 73 20 61 6c 77 61 79 73 20 61 20  o pass always a 
1010: 73 65 6c 65 63 74 6f 72 0a 20 20 20 20 2f 2f 20  selector.    // 
1020: 74 6f 20 74 68 65 20 71 75 65 72 79 53 65 6c 65  to the querySele
1030: 63 74 6f 72 41 6c 6c 20 66 75 6e 63 74 69 6f 6e  ctorAll function
1040: 0a 20 20 20 20 65 6c 65 6d 20 3d 20 73 65 6c 65  .    elem = sele
1050: 63 74 6f 72 20 3f 20 24 24 28 73 65 6c 65 63 74  ctor ? $$(select
1060: 6f 72 29 20 3a 20 5b 5d 0a 20 20 7d 0a 20 20 65  or) : [].  }.  e
1070: 6c 73 65 0a 20 20 20 20 2f 2f 20 70 72 6f 62 61  lse.    // proba
1080: 62 6c 79 20 79 6f 75 20 68 61 76 65 20 70 61 73  bly you have pas
1090: 73 65 64 20 61 6c 72 65 61 64 79 20 61 20 74 61  sed already a ta
10a0: 67 20 6f 72 20 61 20 4e 6f 64 65 4c 69 73 74 0a  g or a NodeList.
10b0: 20 20 20 20 65 6c 65 6d 20 3d 20 73 65 6c 65 63      elem = selec
10c0: 74 6f 72 0a 0a 20 20 2f 2f 20 73 65 6c 65 63 74  tor..  // select
10d0: 20 61 6c 6c 20 74 68 65 20 72 65 67 69 73 74 65   all the registe
10e0: 72 65 64 20 61 6e 64 20 6d 6f 75 6e 74 20 74 68  red and mount th
10f0: 65 6d 20 69 6e 73 69 64 65 20 74 68 65 69 72 20  em inside their 
1100: 72 6f 6f 74 20 65 6c 65 6d 65 6e 74 73 0a 20 20  root elements.  
1110: 69 66 20 28 74 61 67 4e 61 6d 65 20 3d 3d 3d 20  if (tagName === 
1120: 27 2a 27 29 20 7b 0a 20 20 20 20 2f 2f 20 67 65  '*') {.    // ge
1130: 74 20 61 6c 6c 20 63 75 73 74 6f 6d 20 74 61 67  t all custom tag
1140: 73 0a 20 20 20 20 74 61 67 4e 61 6d 65 20 3d 20  s.    tagName = 
1150: 61 6c 6c 54 61 67 73 20 7c 7c 20 71 75 65 72 79  allTags || query
1160: 28 29 0a 20 20 20 20 2f 2f 20 69 66 20 74 68 65  ().    // if the
1170: 20 72 6f 6f 74 20 65 6c 73 20 69 74 27 73 20 6a   root els it's j
1180: 75 73 74 20 61 20 73 69 6e 67 6c 65 20 74 61 67  ust a single tag
1190: 0a 20 20 20 20 69 66 20 28 65 6c 65 6d 2e 74 61  .    if (elem.ta
11a0: 67 4e 61 6d 65 29 0a 20 20 20 20 20 20 65 6c 65  gName).      ele
11b0: 6d 20 3d 20 24 24 28 74 61 67 4e 61 6d 65 2c 20  m = $$(tagName, 
11c0: 65 6c 65 6d 29 0a 20 20 20 20 65 6c 73 65 20 7b  elem).    else {
11d0: 0a 20 20 20 20 20 20 2f 2f 20 73 65 6c 65 63 74  .      // select
11e0: 20 61 6c 6c 20 74 68 65 20 63 68 69 6c 64 72 65   all the childre
11f0: 6e 20 66 6f 72 20 61 6c 6c 20 74 68 65 20 64 69  n for all the di
1200: 66 66 65 72 65 6e 74 20 72 6f 6f 74 20 65 6c 65  fferent root ele
1210: 6d 65 6e 74 73 0a 20 20 20 20 20 20 76 61 72 20  ments.      var 
1220: 6e 6f 64 65 4c 69 73 74 20 3d 20 5b 5d 0a 0a 20  nodeList = [].. 
1230: 20 20 20 20 20 65 61 63 68 28 65 6c 65 6d 2c 20       each(elem, 
1240: 5f 65 6c 20 3d 3e 20 6e 6f 64 65 4c 69 73 74 2e  _el => nodeList.
1250: 70 75 73 68 28 24 24 28 74 61 67 4e 61 6d 65 2c  push($$(tagName,
1260: 20 5f 65 6c 29 29 29 0a 0a 20 20 20 20 20 20 65   _el)))..      e
1270: 6c 65 6d 20 3d 20 6e 6f 64 65 4c 69 73 74 0a 20  lem = nodeList. 
1280: 20 20 20 7d 0a 20 20 20 20 2f 2f 20 67 65 74 20     }.    // get 
1290: 72 69 64 20 6f 66 20 74 68 65 20 74 61 67 4e 61  rid of the tagNa
12a0: 6d 65 0a 20 20 20 20 74 61 67 4e 61 6d 65 20 3d  me.    tagName =
12b0: 20 30 0a 20 20 7d 0a 0a 20 20 70 75 73 68 54 61   0.  }..  pushTa
12c0: 67 73 54 6f 28 65 6c 65 6d 29 0a 0a 20 20 72 65  gsTo(elem)..  re
12d0: 74 75 72 6e 20 74 61 67 73 0a 7d 0a 0a 2f 2f 20  turn tags.}..// 
12e0: 43 72 65 61 74 65 20 61 20 6d 69 78 69 6e 20 74  Create a mixin t
12f0: 68 61 74 20 63 6f 75 6c 64 20 62 65 20 67 6c 6f  hat could be glo
1300: 62 61 6c 6c 79 20 73 68 61 72 65 64 20 61 63 72  bally shared acr
1310: 6f 73 73 20 61 6c 6c 20 74 68 65 20 74 61 67 73  oss all the tags
1320: 0a 63 6f 6e 73 74 20 6d 69 78 69 6e 73 20 3d 20  .const mixins = 
1330: 7b 7d 0a 63 6f 6e 73 74 20 67 6c 6f 62 61 6c 73  {}.const globals
1340: 20 3d 20 6d 69 78 69 6e 73 5b 47 4c 4f 42 41 4c   = mixins[GLOBAL
1350: 5f 4d 49 58 49 4e 5d 20 3d 20 7b 7d 0a 6c 65 74  _MIXIN] = {}.let
1360: 20 6d 69 78 69 6e 73 5f 69 64 20 3d 20 30 0a 0a   mixins_id = 0..
1370: 2f 2a 2a 0a 20 2a 20 43 72 65 61 74 65 2f 52 65  /**. * Create/Re
1380: 74 75 72 6e 20 61 20 6d 69 78 69 6e 20 62 79 20  turn a mixin by 
1390: 69 74 73 20 6e 61 6d 65 0a 20 2a 20 40 70 61 72  its name. * @par
13a0: 61 6d 20 20 20 7b 20 53 74 72 69 6e 67 20 7d 20  am   { String } 
13b0: 20 6e 61 6d 65 20 2d 20 6d 69 78 69 6e 20 6e 61   name - mixin na
13c0: 6d 65 20 28 67 6c 6f 62 61 6c 20 6d 69 78 69 6e  me (global mixin
13d0: 20 69 66 20 6f 62 6a 65 63 74 29 0a 20 2a 20 40   if object). * @
13e0: 70 61 72 61 6d 20 20 20 7b 20 4f 62 6a 65 63 74  param   { Object
13f0: 20 7d 20 20 6d 69 78 20 2d 20 6d 69 78 69 6e 20   }  mix - mixin 
1400: 6c 6f 67 69 63 0a 20 2a 20 40 70 61 72 61 6d 20  logic. * @param 
1410: 20 20 7b 20 42 6f 6f 6c 65 61 6e 20 7d 20 67 20    { Boolean } g 
1420: 2d 20 69 73 20 67 6c 6f 62 61 6c 3f 0a 20 2a 20  - is global?. * 
1430: 40 72 65 74 75 72 6e 73 20 7b 20 4f 62 6a 65 63  @returns { Objec
1440: 74 20 7d 20 20 74 68 65 20 6d 69 78 69 6e 20 6c  t }  the mixin l
1450: 6f 67 69 63 0a 20 2a 2f 0a 65 78 70 6f 72 74 20  ogic. */.export 
1460: 66 75 6e 63 74 69 6f 6e 20 6d 69 78 69 6e 28 6e  function mixin(n
1470: 61 6d 65 2c 20 6d 69 78 2c 20 67 29 20 7b 0a 20  ame, mix, g) {. 
1480: 20 2f 2f 20 55 6e 6e 61 6d 65 64 20 67 6c 6f 62   // Unnamed glob
1490: 61 6c 0a 20 20 69 66 20 28 69 73 4f 62 6a 65 63  al.  if (isObjec
14a0: 74 28 6e 61 6d 65 29 29 20 7b 0a 20 20 20 20 6d  t(name)) {.    m
14b0: 69 78 69 6e 28 60 5f 5f 24 7b 6d 69 78 69 6e 73  ixin(`__${mixins
14c0: 5f 69 64 2b 2b 7d 5f 5f 60 2c 20 6e 61 6d 65 2c  _id++}__`, name,
14d0: 20 74 72 75 65 29 0a 20 20 20 20 72 65 74 75 72   true).    retur
14e0: 6e 0a 20 20 7d 0a 0a 20 20 63 6f 6e 73 74 20 73  n.  }..  const s
14f0: 74 6f 72 65 20 3d 20 67 20 3f 20 67 6c 6f 62 61  tore = g ? globa
1500: 6c 73 20 3a 20 6d 69 78 69 6e 73 0a 0a 20 20 2f  ls : mixins..  /
1510: 2f 20 47 65 74 74 65 72 0a 20 20 69 66 20 28 21  / Getter.  if (!
1520: 6d 69 78 29 20 7b 0a 20 20 20 20 69 66 20 28 69  mix) {.    if (i
1530: 73 55 6e 64 65 66 69 6e 65 64 28 73 74 6f 72 65  sUndefined(store
1540: 5b 6e 61 6d 65 5d 29 29 0a 20 20 20 20 20 20 74  [name])).      t
1550: 68 72 6f 77 20 6e 65 77 20 45 72 72 6f 72 28 60  hrow new Error(`
1560: 55 6e 72 65 67 69 73 74 65 72 65 64 20 6d 69 78  Unregistered mix
1570: 69 6e 3a 20 24 7b 20 6e 61 6d 65 20 7d 60 29 0a  in: ${ name }`).
1580: 0a 20 20 20 20 72 65 74 75 72 6e 20 73 74 6f 72  .    return stor
1590: 65 5b 6e 61 6d 65 5d 0a 20 20 7d 0a 0a 20 20 2f  e[name].  }..  /
15a0: 2f 20 53 65 74 74 65 72 0a 20 20 73 74 6f 72 65  / Setter.  store
15b0: 5b 6e 61 6d 65 5d 20 3d 20 69 73 46 75 6e 63 74  [name] = isFunct
15c0: 69 6f 6e 28 6d 69 78 29 20 3f 0a 20 20 20 20 65  ion(mix) ?.    e
15d0: 78 74 65 6e 64 28 6d 69 78 2e 70 72 6f 74 6f 74  xtend(mix.protot
15e0: 79 70 65 2c 20 73 74 6f 72 65 5b 6e 61 6d 65 5d  ype, store[name]
15f0: 20 7c 7c 20 7b 7d 29 20 26 26 20 6d 69 78 20 3a   || {}) && mix :
1600: 0a 20 20 20 20 65 78 74 65 6e 64 28 73 74 6f 72  .    extend(stor
1610: 65 5b 6e 61 6d 65 5d 20 7c 7c 20 7b 7d 2c 20 6d  e[name] || {}, m
1620: 69 78 29 0a 7d 0a 0a 2f 2a 2a 0a 20 2a 20 55 70  ix).}../**. * Up
1630: 64 61 74 65 20 61 6c 6c 20 74 68 65 20 74 61 67  date all the tag
1640: 73 20 69 6e 73 74 61 6e 63 65 73 20 63 72 65 61  s instances crea
1650: 74 65 64 0a 20 2a 20 40 72 65 74 75 72 6e 73 20  ted. * @returns 
1660: 7b 20 41 72 72 61 79 20 7d 20 61 6c 6c 20 74 68  { Array } all th
1670: 65 20 74 61 67 73 20 69 6e 73 74 61 6e 63 65 73  e tags instances
1680: 0a 20 2a 2f 0a 65 78 70 6f 72 74 20 66 75 6e 63  . */.export func
1690: 74 69 6f 6e 20 75 70 64 61 74 65 28 29 20 7b 0a  tion update() {.
16a0: 20 20 72 65 74 75 72 6e 20 65 61 63 68 28 5f 5f    return each(__
16b0: 54 41 47 53 5f 43 41 43 48 45 2c 20 74 61 67 20  TAGS_CACHE, tag 
16c0: 3d 3e 20 74 61 67 2e 75 70 64 61 74 65 28 29 29  => tag.update())
16d0: 0a 7d 0a 0a 65 78 70 6f 72 74 20 66 75 6e 63 74  .}..export funct
16e0: 69 6f 6e 20 75 6e 72 65 67 69 73 74 65 72 28 6e  ion unregister(n
16f0: 61 6d 65 29 20 7b 0a 20 20 73 74 79 6c 65 4d 61  ame) {.  styleMa
1700: 6e 61 67 65 72 2e 72 65 6d 6f 76 65 28 6e 61 6d  nager.remove(nam
1710: 65 29 0a 20 20 72 65 74 75 72 6e 20 64 65 6c 65  e).  return dele
1720: 74 65 20 5f 5f 54 41 47 5f 49 4d 50 4c 5b 6e 61  te __TAG_IMPL[na
1730: 6d 65 5d 0a 7d 0a 0a 65 78 70 6f 72 74 20 63 6f  me].}..export co
1740: 6e 73 74 20 76 65 72 73 69 6f 6e 20 3d 20 27 57  nst version = 'W
1750: 49 50 27 0a                                      IP'.