⌈⌋ ⎇ branch:  Bitrhythm


Hex Artifact Content

Artifact fa32d3847de4ee689cc19793cba7b3b1c030c376ce78acb820ec62ebe12e1e94:


0000: 69 6d 70 6f 72 74 20 7b 0a 20 20 54 5f 53 54 52  import {.  T_STR
0010: 49 4e 47 2c 0a 20 20 54 5f 4f 42 4a 45 43 54 2c  ING,.  T_OBJECT,
0020: 0a 20 20 5f 5f 54 41 47 5f 49 4d 50 4c 2c 0a 20  .  __TAG_IMPL,. 
0030: 20 43 4f 4e 44 49 54 49 4f 4e 41 4c 5f 44 49 52   CONDITIONAL_DIR
0040: 45 43 54 49 56 45 2c 0a 20 20 4c 4f 4f 50 5f 44  ECTIVE,.  LOOP_D
0050: 49 52 45 43 54 49 56 45 2c 0a 20 20 4c 4f 4f 50  IRECTIVE,.  LOOP
0060: 5f 4e 4f 5f 52 45 4f 52 44 45 52 5f 44 49 52 45  _NO_REORDER_DIRE
0070: 43 54 49 56 45 2c 0a 20 20 4b 45 59 5f 44 49 52  CTIVE,.  KEY_DIR
0080: 45 43 54 49 56 45 0a 7d 20 66 72 6f 6d 20 27 2e  ECTIVE.} from '.
0090: 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 67 6c 6f 62 61  /../common/globa
00a0: 6c 2d 76 61 72 69 61 62 6c 65 73 27 0a 0a 69 6d  l-variables'..im
00b0: 70 6f 72 74 20 69 73 53 74 72 69 6e 67 20 66 72  port isString fr
00c0: 6f 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f  om './../common/
00d0: 75 74 69 6c 2f 63 68 65 63 6b 73 2f 69 73 2d 73  util/checks/is-s
00e0: 74 72 69 6e 67 27 0a 69 6d 70 6f 72 74 20 69 73  tring'.import is
00f0: 41 72 72 61 79 20 66 72 6f 6d 20 27 2e 2f 2e 2e  Array from './..
0100: 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 63 68 65  /common/util/che
0110: 63 6b 73 2f 69 73 2d 61 72 72 61 79 27 0a 69 6d  cks/is-array'.im
0120: 70 6f 72 74 20 72 65 6d 6f 76 65 41 74 74 72 69  port removeAttri
0130: 62 75 74 65 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f  bute from './../
0140: 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 64 6f 6d 2f  common/util/dom/
0150: 72 65 6d 6f 76 65 2d 61 74 74 72 69 62 75 74 65  remove-attribute
0160: 27 0a 69 6d 70 6f 72 74 20 67 65 74 41 74 74 72  '.import getAttr
0170: 69 62 75 74 65 20 66 72 6f 6d 20 27 2e 2f 2e 2e  ibute from './..
0180: 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 64 6f 6d  /common/util/dom
0190: 2f 67 65 74 2d 61 74 74 72 69 62 75 74 65 27 0a  /get-attribute'.
01a0: 69 6d 70 6f 72 74 20 63 72 65 61 74 65 50 6c 61  import createPla
01b0: 63 65 68 6f 6c 64 65 72 20 66 72 6f 6d 20 27 2e  ceholder from '.
01c0: 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f  /../common/util/
01d0: 64 6f 6d 2f 63 72 65 61 74 65 2d 70 6c 61 63 65  dom/create-place
01e0: 68 6f 6c 64 65 72 27 0a 69 6d 70 6f 72 74 20 73  holder'.import s
01f0: 61 66 65 49 6e 73 65 72 74 20 66 72 6f 6d 20 27  afeInsert from '
0200: 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c  ./../common/util
0210: 2f 64 6f 6d 2f 73 61 66 65 2d 69 6e 73 65 72 74  /dom/safe-insert
0220: 27 0a 69 6d 70 6f 72 74 20 63 72 65 61 74 65 46  '.import createF
0230: 72 61 67 6d 65 6e 74 20 66 72 6f 6d 20 27 2e 2f  ragment from './
0240: 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 64  ../common/util/d
0250: 6f 6d 2f 63 72 65 61 74 65 2d 66 72 61 67 6d 65  om/create-fragme
0260: 6e 74 27 0a 0a 69 6d 70 6f 72 74 20 65 61 63 68  nt'..import each
0270: 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d   from './../comm
0280: 6f 6e 2f 75 74 69 6c 2f 6d 69 73 63 2f 65 61 63  on/util/misc/eac
0290: 68 27 0a 69 6d 70 6f 72 74 20 63 6f 6e 74 61 69  h'.import contai
02a0: 6e 73 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 63 6f  ns from './../co
02b0: 6d 6d 6f 6e 2f 75 74 69 6c 2f 6d 69 73 63 2f 63  mmon/util/misc/c
02c0: 6f 6e 74 61 69 6e 73 27 0a 69 6d 70 6f 72 74 20  ontains'.import 
02d0: 63 72 65 61 74 65 20 66 72 6f 6d 20 27 2e 2f 2e  create from './.
02e0: 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 6d 69  ./common/util/mi
02f0: 73 63 2f 6f 62 6a 65 63 74 2d 63 72 65 61 74 65  sc/object-create
0300: 27 0a 69 6d 70 6f 72 74 20 65 78 74 65 6e 64 20  '.import extend 
0310: 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f  from './../commo
0320: 6e 2f 75 74 69 6c 2f 6d 69 73 63 2f 65 78 74 65  n/util/misc/exte
0330: 6e 64 27 0a 0a 69 6d 70 6f 72 74 20 6d 6f 76 65  nd'..import move
0340: 43 68 69 6c 64 20 66 72 6f 6d 20 27 2e 2f 2e 2e  Child from './..
0350: 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 74 61 67  /common/util/tag
0360: 73 2f 6d 6f 76 65 2d 63 68 69 6c 64 27 0a 69 6d  s/move-child'.im
0370: 70 6f 72 74 20 67 65 74 54 61 67 20 66 72 6f 6d  port getTag from
0380: 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74   './../common/ut
0390: 69 6c 2f 74 61 67 73 2f 67 65 74 27 0a 69 6d 70  il/tags/get'.imp
03a0: 6f 72 74 20 67 65 74 54 61 67 4e 61 6d 65 20 66  ort getTagName f
03b0: 72 6f 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e  rom './../common
03c0: 2f 75 74 69 6c 2f 74 61 67 73 2f 67 65 74 2d 6e  /util/tags/get-n
03d0: 61 6d 65 27 0a 69 6d 70 6f 72 74 20 61 72 72 61  ame'.import arra
03e0: 79 69 73 68 41 64 64 20 66 72 6f 6d 20 27 2e 2f  yishAdd from './
03f0: 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 74  ../common/util/t
0400: 61 67 73 2f 61 72 72 61 79 69 73 68 2d 61 64 64  ags/arrayish-add
0410: 27 0a 69 6d 70 6f 72 74 20 61 72 72 61 79 69 73  '.import arrayis
0420: 68 52 65 6d 6f 76 65 20 66 72 6f 6d 20 27 2e 2f  hRemove from './
0430: 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 74  ../common/util/t
0440: 61 67 73 2f 61 72 72 61 79 69 73 68 2d 72 65 6d  ags/arrayish-rem
0450: 6f 76 65 27 0a 69 6d 70 6f 72 74 20 6d 61 6b 65  ove'.import make
0460: 56 69 72 74 75 61 6c 20 66 72 6f 6d 20 27 2e 2f  Virtual from './
0470: 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 74  ../common/util/t
0480: 61 67 73 2f 6d 61 6b 65 2d 76 69 72 74 75 61 6c  ags/make-virtual
0490: 27 0a 69 6d 70 6f 72 74 20 6d 6f 76 65 56 69 72  '.import moveVir
04a0: 74 75 61 6c 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f  tual from './../
04b0: 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 74 61 67 73  common/util/tags
04c0: 2f 6d 6f 76 65 2d 76 69 72 74 75 61 6c 27 0a 0a  /move-virtual'..
04d0: 69 6d 70 6f 72 74 20 63 72 65 61 74 65 54 61 67  import createTag
04e0: 20 66 72 6f 6d 20 27 2e 2f 74 61 67 27 0a 69 6d   from './tag'.im
04f0: 70 6f 72 74 20 7b 20 74 6d 70 6c 20 7d 20 66 72  port { tmpl } fr
0500: 6f 6d 20 27 72 69 6f 74 2d 74 6d 70 6c 27 0a 0a  om 'riot-tmpl'..
0510: 0a 2f 2a 2a 0a 20 2a 20 43 6f 6e 76 65 72 74 20  ./**. * Convert 
0520: 74 68 65 20 69 74 65 6d 20 6c 6f 6f 70 65 64 20  the item looped 
0530: 69 6e 74 6f 20 61 6e 20 6f 62 6a 65 63 74 20 75  into an object u
0540: 73 65 64 20 74 6f 20 65 78 74 65 6e 64 20 74 68  sed to extend th
0550: 65 20 63 68 69 6c 64 20 74 61 67 20 70 72 6f 70  e child tag prop
0560: 65 72 74 69 65 73 0a 20 2a 20 40 70 61 72 61 6d  erties. * @param
0570: 20 20 20 7b 20 4f 62 6a 65 63 74 20 7d 20 65 78     { Object } ex
0580: 70 72 20 2d 20 6f 62 6a 65 63 74 20 63 6f 6e 74  pr - object cont
0590: 61 69 6e 69 6e 67 20 74 68 65 20 6b 65 79 73 20  aining the keys 
05a0: 75 73 65 64 20 74 6f 20 65 78 74 65 6e 64 20 74  used to extend t
05b0: 68 65 20 63 68 69 6c 64 72 65 6e 20 74 61 67 73  he children tags
05c0: 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 20 2a  . * @param   { *
05d0: 20 7d 20 6b 65 79 20 2d 20 76 61 6c 75 65 20 74   } key - value t
05e0: 6f 20 61 73 73 69 67 6e 20 74 6f 20 74 68 65 20  o assign to the 
05f0: 6e 65 77 20 6f 62 6a 65 63 74 20 72 65 74 75 72  new object retur
0600: 6e 65 64 0a 20 2a 20 40 70 61 72 61 6d 20 20 20  ned. * @param   
0610: 7b 20 2a 20 7d 20 76 61 6c 20 2d 20 76 61 6c 75  { * } val - valu
0620: 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65  e containing the
0630: 20 70 6f 73 69 74 69 6f 6e 20 6f 66 20 74 68 65   position of the
0640: 20 69 74 65 6d 20 69 6e 20 74 68 65 20 61 72 72   item in the arr
0650: 61 79 0a 20 2a 20 40 72 65 74 75 72 6e 73 20 7b  ay. * @returns {
0660: 20 4f 62 6a 65 63 74 20 7d 20 2d 20 6e 65 77 20   Object } - new 
0670: 6f 62 6a 65 63 74 20 63 6f 6e 74 61 69 6e 69 6e  object containin
0680: 67 20 74 68 65 20 76 61 6c 75 65 73 20 6f 66 20  g the values of 
0690: 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 69 74 65  the original ite
06a0: 6d 0a 20 2a 0a 20 2a 20 54 68 65 20 76 61 72 69  m. *. * The vari
06b0: 61 62 6c 65 73 20 27 6b 65 79 27 20 61 6e 64 20  ables 'key' and 
06c0: 27 76 61 6c 27 20 61 72 65 20 61 72 62 69 74 72  'val' are arbitr
06d0: 61 72 79 2e 0a 20 2a 20 54 68 65 79 20 64 65 70  ary.. * They dep
06e0: 65 6e 64 20 6f 6e 20 74 68 65 20 63 6f 6c 6c 65  end on the colle
06f0: 63 74 69 6f 6e 20 74 79 70 65 20 6c 6f 6f 70 65  ction type loope
0700: 64 20 28 41 72 72 61 79 2c 20 4f 62 6a 65 63 74  d (Array, Object
0710: 29 0a 20 2a 20 61 6e 64 20 6f 6e 20 74 68 65 20  ). * and on the 
0720: 65 78 70 72 65 73 73 69 6f 6e 20 75 73 65 64 20  expression used 
0730: 6f 6e 20 74 68 65 20 65 61 63 68 20 74 61 67 0a  on the each tag.
0740: 20 2a 0a 20 2a 2f 0a 66 75 6e 63 74 69 6f 6e 20   *. */.function 
0750: 6d 6b 69 74 65 6d 28 65 78 70 72 2c 20 6b 65 79  mkitem(expr, key
0760: 2c 20 76 61 6c 29 20 7b 0a 20 20 63 6f 6e 73 74  , val) {.  const
0770: 20 69 74 65 6d 20 3d 20 7b 7d 0a 20 20 69 74 65   item = {}.  ite
0780: 6d 5b 65 78 70 72 2e 6b 65 79 5d 20 3d 20 6b 65  m[expr.key] = ke
0790: 79 0a 20 20 69 66 20 28 65 78 70 72 2e 70 6f 73  y.  if (expr.pos
07a0: 29 20 69 74 65 6d 5b 65 78 70 72 2e 70 6f 73 5d  ) item[expr.pos]
07b0: 20 3d 20 76 61 6c 0a 20 20 72 65 74 75 72 6e 20   = val.  return 
07c0: 69 74 65 6d 0a 7d 0a 0a 2f 2a 2a 0a 20 2a 20 55  item.}../**. * U
07d0: 6e 6d 6f 75 6e 74 20 74 68 65 20 72 65 64 75 6e  nmount the redun
07e0: 64 61 6e 74 20 74 61 67 73 0a 20 2a 20 40 70 61  dant tags. * @pa
07f0: 72 61 6d 20 20 20 7b 20 41 72 72 61 79 20 7d 20  ram   { Array } 
0800: 69 74 65 6d 73 20 2d 20 61 72 72 61 79 20 63 6f  items - array co
0810: 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 63 75 72  ntaining the cur
0820: 72 65 6e 74 20 69 74 65 6d 73 20 74 6f 20 6c 6f  rent items to lo
0830: 6f 70 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b  op. * @param   {
0840: 20 41 72 72 61 79 20 7d 20 74 61 67 73 20 2d 20   Array } tags - 
0850: 61 72 72 61 79 20 63 6f 6e 74 61 69 6e 69 6e 67  array containing
0860: 20 61 6c 6c 20 74 68 65 20 63 68 69 6c 64 72 65   all the childre
0870: 6e 20 74 61 67 73 0a 20 2a 2f 0a 66 75 6e 63 74  n tags. */.funct
0880: 69 6f 6e 20 75 6e 6d 6f 75 6e 74 52 65 64 75 6e  ion unmountRedun
0890: 64 61 6e 74 28 69 74 65 6d 73 2c 20 74 61 67 73  dant(items, tags
08a0: 2c 20 66 69 6c 74 65 72 65 64 49 74 65 6d 73 43  , filteredItemsC
08b0: 6f 75 6e 74 29 20 7b 0a 20 20 6c 65 74 20 69 20  ount) {.  let i 
08c0: 3d 20 74 61 67 73 2e 6c 65 6e 67 74 68 0a 20 20  = tags.length.  
08d0: 63 6f 6e 73 74 20 6a 20 3d 20 69 74 65 6d 73 2e  const j = items.
08e0: 6c 65 6e 67 74 68 20 2d 20 66 69 6c 74 65 72 65  length - filtere
08f0: 64 49 74 65 6d 73 43 6f 75 6e 74 0a 0a 20 20 77  dItemsCount..  w
0900: 68 69 6c 65 20 28 69 20 3e 20 6a 29 20 7b 0a 20  hile (i > j) {. 
0910: 20 20 20 69 2d 2d 0a 20 20 20 20 72 65 6d 6f 76     i--.    remov
0920: 65 2e 61 70 70 6c 79 28 74 61 67 73 5b 69 5d 2c  e.apply(tags[i],
0930: 20 5b 74 61 67 73 2c 20 69 5d 29 0a 20 20 7d 0a   [tags, i]).  }.
0940: 7d 0a 0a 0a 2f 2a 2a 0a 20 2a 20 52 65 6d 6f 76  }.../**. * Remov
0950: 65 20 61 20 63 68 69 6c 64 20 74 61 67 0a 20 2a  e a child tag. *
0960: 20 40 74 68 69 73 20 54 61 67 0a 20 2a 20 40 70   @this Tag. * @p
0970: 61 72 61 6d 20 20 20 7b 20 41 72 72 61 79 20 7d  aram   { Array }
0980: 20 74 61 67 73 20 2d 20 74 61 67 73 20 63 6f 6c   tags - tags col
0990: 6c 65 63 74 69 6f 6e 0a 20 2a 20 40 70 61 72 61  lection. * @para
09a0: 6d 20 20 20 7b 20 4e 75 6d 62 65 72 20 7d 20 69  m   { Number } i
09b0: 20 2d 20 69 6e 64 65 78 20 6f 66 20 74 68 65 20   - index of the 
09c0: 74 61 67 20 74 6f 20 72 65 6d 6f 76 65 0a 20 2a  tag to remove. *
09d0: 2f 0a 66 75 6e 63 74 69 6f 6e 20 72 65 6d 6f 76  /.function remov
09e0: 65 28 74 61 67 73 2c 20 69 29 20 7b 0a 20 20 74  e(tags, i) {.  t
09f0: 61 67 73 2e 73 70 6c 69 63 65 28 69 2c 20 31 29  ags.splice(i, 1)
0a00: 0a 20 20 74 68 69 73 2e 75 6e 6d 6f 75 6e 74 28  .  this.unmount(
0a10: 29 0a 20 20 61 72 72 61 79 69 73 68 52 65 6d 6f  ).  arrayishRemo
0a20: 76 65 28 74 68 69 73 2e 70 61 72 65 6e 74 2c 20  ve(this.parent, 
0a30: 74 68 69 73 2c 20 74 68 69 73 2e 5f 5f 2e 74 61  this, this.__.ta
0a40: 67 4e 61 6d 65 2c 20 74 72 75 65 29 0a 7d 0a 0a  gName, true).}..
0a50: 2f 2a 2a 0a 20 2a 20 4d 6f 76 65 20 74 68 65 20  /**. * Move the 
0a60: 6e 65 73 74 65 64 20 63 75 73 74 6f 6d 20 74 61  nested custom ta
0a70: 67 73 20 69 6e 20 6e 6f 6e 20 63 75 73 74 6f 6d  gs in non custom
0a80: 20 6c 6f 6f 70 20 74 61 67 73 0a 20 2a 20 40 74   loop tags. * @t
0a90: 68 69 73 20 54 61 67 0a 20 2a 20 40 70 61 72 61  his Tag. * @para
0aa0: 6d 20 20 20 7b 20 4e 75 6d 62 65 72 20 7d 20 69  m   { Number } i
0ab0: 20 2d 20 63 75 72 72 65 6e 74 20 70 6f 73 69 74   - current posit
0ac0: 69 6f 6e 20 6f 66 20 74 68 65 20 6c 6f 6f 70 20  ion of the loop 
0ad0: 74 61 67 0a 20 2a 2f 0a 66 75 6e 63 74 69 6f 6e  tag. */.function
0ae0: 20 6d 6f 76 65 4e 65 73 74 65 64 54 61 67 73 28   moveNestedTags(
0af0: 69 29 20 7b 0a 20 20 65 61 63 68 28 4f 62 6a 65  i) {.  each(Obje
0b00: 63 74 2e 6b 65 79 73 28 74 68 69 73 2e 74 61 67  ct.keys(this.tag
0b10: 73 29 2c 20 28 74 61 67 4e 61 6d 65 29 20 3d 3e  s), (tagName) =>
0b20: 20 7b 0a 20 20 20 20 6d 6f 76 65 43 68 69 6c 64   {.    moveChild
0b30: 2e 61 70 70 6c 79 28 74 68 69 73 2e 74 61 67 73  .apply(this.tags
0b40: 5b 74 61 67 4e 61 6d 65 5d 2c 20 5b 74 61 67 4e  [tagName], [tagN
0b50: 61 6d 65 2c 20 69 5d 29 0a 20 20 7d 29 0a 7d 0a  ame, i]).  }).}.
0b60: 0a 2f 2a 2a 0a 20 2a 20 4d 6f 76 65 20 61 20 63  ./**. * Move a c
0b70: 68 69 6c 64 20 74 61 67 0a 20 2a 20 40 74 68 69  hild tag. * @thi
0b80: 73 20 54 61 67 0a 20 2a 20 40 70 61 72 61 6d 20  s Tag. * @param 
0b90: 20 20 7b 20 48 54 4d 4c 45 6c 65 6d 65 6e 74 20    { HTMLElement 
0ba0: 7d 20 72 6f 6f 74 20 2d 20 64 6f 6d 20 6e 6f 64  } root - dom nod
0bb0: 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 61 6c 6c  e containing all
0bc0: 20 74 68 65 20 6c 6f 6f 70 20 63 68 69 6c 64 72   the loop childr
0bd0: 65 6e 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b  en. * @param   {
0be0: 20 54 61 67 20 7d 20 6e 65 78 74 54 61 67 20 2d   Tag } nextTag -
0bf0: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65   instance of the
0c00: 20 6e 65 78 74 20 74 61 67 20 70 72 65 63 65 64   next tag preced
0c10: 69 6e 67 20 74 68 65 20 6f 6e 65 20 77 65 20 77  ing the one we w
0c20: 61 6e 74 20 74 6f 20 6d 6f 76 65 0a 20 2a 20 40  ant to move. * @
0c30: 70 61 72 61 6d 20 20 20 7b 20 42 6f 6f 6c 65 61  param   { Boolea
0c40: 6e 20 7d 20 69 73 56 69 72 74 75 61 6c 20 2d 20  n } isVirtual - 
0c50: 69 73 20 69 74 20 61 20 76 69 72 74 75 61 6c 20  is it a virtual 
0c60: 74 61 67 3f 0a 20 2a 2f 0a 66 75 6e 63 74 69 6f  tag?. */.functio
0c70: 6e 20 6d 6f 76 65 28 72 6f 6f 74 2c 20 6e 65 78  n move(root, nex
0c80: 74 54 61 67 2c 20 69 73 56 69 72 74 75 61 6c 29  tTag, isVirtual)
0c90: 20 7b 0a 20 20 69 66 20 28 69 73 56 69 72 74 75   {.  if (isVirtu
0ca0: 61 6c 29 0a 20 20 20 20 6d 6f 76 65 56 69 72 74  al).    moveVirt
0cb0: 75 61 6c 2e 61 70 70 6c 79 28 74 68 69 73 2c 20  ual.apply(this, 
0cc0: 5b 72 6f 6f 74 2c 20 6e 65 78 74 54 61 67 5d 29  [root, nextTag])
0cd0: 0a 20 20 65 6c 73 65 0a 20 20 20 20 73 61 66 65  .  else.    safe
0ce0: 49 6e 73 65 72 74 28 72 6f 6f 74 2c 20 74 68 69  Insert(root, thi
0cf0: 73 2e 72 6f 6f 74 2c 20 6e 65 78 74 54 61 67 2e  s.root, nextTag.
0d00: 72 6f 6f 74 29 0a 7d 0a 0a 2f 2a 2a 0a 20 2a 20  root).}../**. * 
0d10: 49 6e 73 65 72 74 20 61 6e 64 20 6d 6f 75 6e 74  Insert and mount
0d20: 20 61 20 63 68 69 6c 64 20 74 61 67 0a 20 2a 20   a child tag. * 
0d30: 40 74 68 69 73 20 54 61 67 0a 20 2a 20 40 70 61  @this Tag. * @pa
0d40: 72 61 6d 20 20 20 7b 20 48 54 4d 4c 45 6c 65 6d  ram   { HTMLElem
0d50: 65 6e 74 20 7d 20 72 6f 6f 74 20 2d 20 64 6f 6d  ent } root - dom
0d60: 20 6e 6f 64 65 20 63 6f 6e 74 61 69 6e 69 6e 67   node containing
0d70: 20 61 6c 6c 20 74 68 65 20 6c 6f 6f 70 20 63 68   all the loop ch
0d80: 69 6c 64 72 65 6e 0a 20 2a 20 40 70 61 72 61 6d  ildren. * @param
0d90: 20 20 20 7b 20 54 61 67 20 7d 20 6e 65 78 74 54     { Tag } nextT
0da0: 61 67 20 2d 20 69 6e 73 74 61 6e 63 65 20 6f 66  ag - instance of
0db0: 20 74 68 65 20 6e 65 78 74 20 74 61 67 20 70 72   the next tag pr
0dc0: 65 63 65 64 69 6e 67 20 74 68 65 20 6f 6e 65 20  eceding the one 
0dd0: 77 65 20 77 61 6e 74 20 74 6f 20 69 6e 73 65 72  we want to inser
0de0: 74 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 20  t. * @param   { 
0df0: 42 6f 6f 6c 65 61 6e 20 7d 20 69 73 56 69 72 74  Boolean } isVirt
0e00: 75 61 6c 20 2d 20 69 73 20 69 74 20 61 20 76 69  ual - is it a vi
0e10: 72 74 75 61 6c 20 74 61 67 3f 0a 20 2a 2f 0a 66  rtual tag?. */.f
0e20: 75 6e 63 74 69 6f 6e 20 69 6e 73 65 72 74 28 72  unction insert(r
0e30: 6f 6f 74 2c 20 6e 65 78 74 54 61 67 2c 20 69 73  oot, nextTag, is
0e40: 56 69 72 74 75 61 6c 29 20 7b 0a 20 20 69 66 20  Virtual) {.  if 
0e50: 28 69 73 56 69 72 74 75 61 6c 29 0a 20 20 20 20  (isVirtual).    
0e60: 6d 61 6b 65 56 69 72 74 75 61 6c 2e 61 70 70 6c  makeVirtual.appl
0e70: 79 28 74 68 69 73 2c 20 5b 72 6f 6f 74 2c 20 6e  y(this, [root, n
0e80: 65 78 74 54 61 67 5d 29 0a 20 20 65 6c 73 65 0a  extTag]).  else.
0e90: 20 20 20 20 73 61 66 65 49 6e 73 65 72 74 28 72      safeInsert(r
0ea0: 6f 6f 74 2c 20 74 68 69 73 2e 72 6f 6f 74 2c 20  oot, this.root, 
0eb0: 6e 65 78 74 54 61 67 2e 72 6f 6f 74 29 0a 7d 0a  nextTag.root).}.
0ec0: 0a 2f 2a 2a 0a 20 2a 20 41 70 70 65 6e 64 20 61  ./**. * Append a
0ed0: 20 6e 65 77 20 74 61 67 20 69 6e 74 6f 20 74 68   new tag into th
0ee0: 65 20 44 4f 4d 0a 20 2a 20 40 74 68 69 73 20 54  e DOM. * @this T
0ef0: 61 67 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b  ag. * @param   {
0f00: 20 48 54 4d 4c 45 6c 65 6d 65 6e 74 20 7d 20 72   HTMLElement } r
0f10: 6f 6f 74 20 2d 20 64 6f 6d 20 6e 6f 64 65 20 63  oot - dom node c
0f20: 6f 6e 74 61 69 6e 69 6e 67 20 61 6c 6c 20 74 68  ontaining all th
0f30: 65 20 6c 6f 6f 70 20 63 68 69 6c 64 72 65 6e 0a  e loop children.
0f40: 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 20 42 6f   * @param   { Bo
0f50: 6f 6c 65 61 6e 20 7d 20 69 73 56 69 72 74 75 61  olean } isVirtua
0f60: 6c 20 2d 20 69 73 20 69 74 20 61 20 76 69 72 74  l - is it a virt
0f70: 75 61 6c 20 74 61 67 3f 0a 20 2a 2f 0a 66 75 6e  ual tag?. */.fun
0f80: 63 74 69 6f 6e 20 61 70 70 65 6e 64 28 72 6f 6f  ction append(roo
0f90: 74 2c 20 69 73 56 69 72 74 75 61 6c 29 20 7b 0a  t, isVirtual) {.
0fa0: 20 20 69 66 20 28 69 73 56 69 72 74 75 61 6c 29    if (isVirtual)
0fb0: 0a 20 20 20 20 6d 61 6b 65 56 69 72 74 75 61 6c  .    makeVirtual
0fc0: 2e 63 61 6c 6c 28 74 68 69 73 2c 20 72 6f 6f 74  .call(this, root
0fd0: 29 0a 20 20 65 6c 73 65 0a 20 20 20 20 72 6f 6f  ).  else.    roo
0fe0: 74 2e 61 70 70 65 6e 64 43 68 69 6c 64 28 74 68  t.appendChild(th
0ff0: 69 73 2e 72 6f 6f 74 29 0a 7d 0a 0a 2f 2a 2a 0a  is.root).}../**.
1000: 20 2a 20 52 65 74 75 72 6e 20 74 68 65 20 76 61   * Return the va
1010: 6c 75 65 20 77 65 20 77 61 6e 74 20 74 6f 20 75  lue we want to u
1020: 73 65 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65  se to lookup the
1030: 20 70 6f 73 74 69 6f 6e 20 6f 66 20 6f 75 72 20   postion of our 
1040: 69 74 65 6d 73 20 69 6e 20 74 68 65 20 63 6f 6c  items in the col
1050: 6c 65 63 74 69 6f 6e 0a 20 2a 20 40 70 61 72 61  lection. * @para
1060: 6d 20 20 20 7b 20 53 74 72 69 6e 67 20 7d 20 20  m   { String }  
1070: 6b 65 79 41 74 74 72 20 20 20 20 20 20 20 20 20  keyAttr         
1080: 2d 20 6c 6f 6f 6b 75 70 20 73 74 72 69 6e 67 20  - lookup string 
1090: 6f 72 20 65 78 70 72 65 73 73 69 6f 6e 0a 20 2a  or expression. *
10a0: 20 40 70 61 72 61 6d 20 20 20 7b 20 2a 20 7d 20   @param   { * } 
10b0: 20 20 20 20 20 20 6f 72 69 67 69 6e 61 6c 49 74        originalIt
10c0: 65 6d 20 20 20 20 2d 20 6f 72 69 67 69 6e 61 6c  em    - original
10d0: 20 69 74 65 6d 20 66 72 6f 6d 20 74 68 65 20 63   item from the c
10e0: 6f 6c 6c 65 63 74 69 6f 6e 0a 20 2a 20 40 70 61  ollection. * @pa
10f0: 72 61 6d 20 20 20 7b 20 4f 62 6a 65 63 74 20 7d  ram   { Object }
1100: 20 20 6b 65 79 65 64 49 74 65 6d 20 20 20 20 20    keyedItem     
1110: 20 20 2d 20 6f 62 6a 65 63 74 20 63 72 65 61 74    - object creat
1120: 65 64 20 62 79 20 72 69 6f 74 20 76 69 61 20 7b  ed by riot via {
1130: 20 69 74 65 6d 2c 20 69 20 69 6e 20 63 6f 6c 6c   item, i in coll
1140: 65 63 74 69 6f 6e 20 7d 0a 20 2a 20 40 70 61 72  ection }. * @par
1150: 61 6d 20 20 20 7b 20 42 6f 6f 6c 65 61 6e 20 7d  am   { Boolean }
1160: 20 68 61 73 4b 65 79 41 74 74 72 45 78 70 72 20   hasKeyAttrExpr 
1170: 20 2d 20 66 6c 61 67 20 74 6f 20 63 68 65 63 6b   - flag to check
1180: 20 77 68 65 74 68 65 72 20 74 68 65 20 6b 65 79   whether the key
1190: 20 69 73 20 61 6e 20 65 78 70 72 65 73 73 69 6f   is an expressio
11a0: 6e 0a 20 2a 20 40 72 65 74 75 72 6e 73 20 7b 20  n. * @returns { 
11b0: 2a 20 7d 20 76 61 6c 75 65 20 74 68 61 74 20 77  * } value that w
11c0: 65 20 77 69 6c 6c 20 75 73 65 20 74 6f 20 66 69  e will use to fi
11d0: 67 75 72 65 20 6f 75 74 20 74 68 65 20 69 74 65  gure out the ite
11e0: 6d 20 70 6f 73 69 74 69 6f 6e 20 76 69 61 20 63  m position via c
11f0: 6f 6c 6c 65 63 74 69 6f 6e 2e 69 6e 64 65 78 4f  ollection.indexO
1200: 66 0a 20 2a 2f 0a 66 75 6e 63 74 69 6f 6e 20 67  f. */.function g
1210: 65 74 49 74 65 6d 49 64 28 6b 65 79 41 74 74 72  etItemId(keyAttr
1220: 2c 20 6f 72 69 67 69 6e 61 6c 49 74 65 6d 2c 20  , originalItem, 
1230: 6b 65 79 65 64 49 74 65 6d 2c 20 68 61 73 4b 65  keyedItem, hasKe
1240: 79 41 74 74 72 45 78 70 72 29 20 7b 0a 20 20 69  yAttrExpr) {.  i
1250: 66 20 28 6b 65 79 41 74 74 72 29 20 7b 0a 20 20  f (keyAttr) {.  
1260: 20 20 72 65 74 75 72 6e 20 68 61 73 4b 65 79 41    return hasKeyA
1270: 74 74 72 45 78 70 72 20 3f 20 20 74 6d 70 6c 28  ttrExpr ?  tmpl(
1280: 6b 65 79 41 74 74 72 2c 20 6b 65 79 65 64 49 74  keyAttr, keyedIt
1290: 65 6d 29 20 3a 20 20 6f 72 69 67 69 6e 61 6c 49  em) :  originalI
12a0: 74 65 6d 5b 6b 65 79 41 74 74 72 5d 0a 20 20 7d  tem[keyAttr].  }
12b0: 0a 0a 20 20 72 65 74 75 72 6e 20 6f 72 69 67 69  ..  return origi
12c0: 6e 61 6c 49 74 65 6d 0a 7d 0a 0a 2f 2a 2a 0a 20  nalItem.}../**. 
12d0: 2a 20 4d 61 6e 61 67 65 20 74 61 67 73 20 68 61  * Manage tags ha
12e0: 76 69 6e 67 20 74 68 65 20 27 65 61 63 68 27 0a  ving the 'each'.
12f0: 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 20 48 54   * @param   { HT
1300: 4d 4c 45 6c 65 6d 65 6e 74 20 7d 20 64 6f 6d 20  MLElement } dom 
1310: 2d 20 44 4f 4d 20 6e 6f 64 65 20 77 65 20 6e 65  - DOM node we ne
1320: 65 64 20 74 6f 20 6c 6f 6f 70 0a 20 2a 20 40 70  ed to loop. * @p
1330: 61 72 61 6d 20 20 20 7b 20 54 61 67 20 7d 20 70  aram   { Tag } p
1340: 61 72 65 6e 74 20 2d 20 70 61 72 65 6e 74 20 74  arent - parent t
1350: 61 67 20 69 6e 73 74 61 6e 63 65 20 77 68 65 72  ag instance wher
1360: 65 20 74 68 65 20 64 6f 6d 20 6e 6f 64 65 20 69  e the dom node i
1370: 73 20 63 6f 6e 74 61 69 6e 65 64 0a 20 2a 20 40  s contained. * @
1380: 70 61 72 61 6d 20 20 20 7b 20 53 74 72 69 6e 67  param   { String
1390: 20 7d 20 65 78 70 72 20 2d 20 73 74 72 69 6e 67   } expr - string
13a0: 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 74 68   contained in th
13b0: 65 20 27 65 61 63 68 27 20 61 74 74 72 69 62 75  e 'each' attribu
13c0: 74 65 0a 20 2a 20 40 72 65 74 75 72 6e 73 20 7b  te. * @returns {
13d0: 20 4f 62 6a 65 63 74 20 7d 20 65 78 70 72 65 73   Object } expres
13e0: 73 69 6f 6e 20 6f 62 6a 65 63 74 20 66 6f 72 20  sion object for 
13f0: 74 68 69 73 20 65 61 63 68 20 6c 6f 6f 70 0a 20  this each loop. 
1400: 2a 2f 0a 65 78 70 6f 72 74 20 64 65 66 61 75 6c  */.export defaul
1410: 74 20 66 75 6e 63 74 69 6f 6e 20 5f 65 61 63 68  t function _each
1420: 28 64 6f 6d 2c 20 70 61 72 65 6e 74 2c 20 65 78  (dom, parent, ex
1430: 70 72 29 20 7b 0a 20 20 63 6f 6e 73 74 20 6d 75  pr) {.  const mu
1440: 73 74 52 65 6f 72 64 65 72 20 3d 20 74 79 70 65  stReorder = type
1450: 6f 66 20 67 65 74 41 74 74 72 69 62 75 74 65 28  of getAttribute(
1460: 64 6f 6d 2c 20 4c 4f 4f 50 5f 4e 4f 5f 52 45 4f  dom, LOOP_NO_REO
1470: 52 44 45 52 5f 44 49 52 45 43 54 49 56 45 29 20  RDER_DIRECTIVE) 
1480: 21 3d 3d 20 54 5f 53 54 52 49 4e 47 20 7c 7c 20  !== T_STRING || 
1490: 72 65 6d 6f 76 65 41 74 74 72 69 62 75 74 65 28  removeAttribute(
14a0: 64 6f 6d 2c 20 4c 4f 4f 50 5f 4e 4f 5f 52 45 4f  dom, LOOP_NO_REO
14b0: 52 44 45 52 5f 44 49 52 45 43 54 49 56 45 29 0a  RDER_DIRECTIVE).
14c0: 20 20 63 6f 6e 73 74 20 6b 65 79 41 74 74 72 20    const keyAttr 
14d0: 3d 20 67 65 74 41 74 74 72 69 62 75 74 65 28 64  = getAttribute(d
14e0: 6f 6d 2c 20 4b 45 59 5f 44 49 52 45 43 54 49 56  om, KEY_DIRECTIV
14f0: 45 29 0a 20 20 63 6f 6e 73 74 20 68 61 73 4b 65  E).  const hasKe
1500: 79 41 74 74 72 45 78 70 72 20 3d 20 6b 65 79 41  yAttrExpr = keyA
1510: 74 74 72 20 3f 20 74 6d 70 6c 2e 68 61 73 45 78  ttr ? tmpl.hasEx
1520: 70 72 28 6b 65 79 41 74 74 72 29 20 3a 20 66 61  pr(keyAttr) : fa
1530: 6c 73 65 0a 20 20 63 6f 6e 73 74 20 74 61 67 4e  lse.  const tagN
1540: 61 6d 65 20 3d 20 67 65 74 54 61 67 4e 61 6d 65  ame = getTagName
1550: 28 64 6f 6d 29 0a 20 20 63 6f 6e 73 74 20 69 6d  (dom).  const im
1560: 70 6c 20 3d 20 5f 5f 54 41 47 5f 49 4d 50 4c 5b  pl = __TAG_IMPL[
1570: 74 61 67 4e 61 6d 65 5d 0a 20 20 63 6f 6e 73 74  tagName].  const
1580: 20 70 61 72 65 6e 74 4e 6f 64 65 20 3d 20 64 6f   parentNode = do
1590: 6d 2e 70 61 72 65 6e 74 4e 6f 64 65 0a 20 20 63  m.parentNode.  c
15a0: 6f 6e 73 74 20 70 6c 61 63 65 68 6f 6c 64 65 72  onst placeholder
15b0: 20 3d 20 63 72 65 61 74 65 50 6c 61 63 65 68 6f   = createPlaceho
15c0: 6c 64 65 72 28 29 0a 20 20 63 6f 6e 73 74 20 63  lder().  const c
15d0: 68 69 6c 64 20 3d 20 67 65 74 54 61 67 28 64 6f  hild = getTag(do
15e0: 6d 29 0a 20 20 63 6f 6e 73 74 20 69 66 45 78 70  m).  const ifExp
15f0: 72 20 3d 20 67 65 74 41 74 74 72 69 62 75 74 65  r = getAttribute
1600: 28 64 6f 6d 2c 20 43 4f 4e 44 49 54 49 4f 4e 41  (dom, CONDITIONA
1610: 4c 5f 44 49 52 45 43 54 49 56 45 29 0a 20 20 63  L_DIRECTIVE).  c
1620: 6f 6e 73 74 20 74 61 67 73 20 3d 20 5b 5d 0a 20  onst tags = []. 
1630: 20 63 6f 6e 73 74 20 69 73 4c 6f 6f 70 20 3d 20   const isLoop = 
1640: 74 72 75 65 0a 20 20 63 6f 6e 73 74 20 69 6e 6e  true.  const inn
1650: 65 72 48 54 4d 4c 20 3d 20 64 6f 6d 2e 69 6e 6e  erHTML = dom.inn
1660: 65 72 48 54 4d 4c 0a 20 20 63 6f 6e 73 74 20 69  erHTML.  const i
1670: 73 41 6e 6f 6e 79 6d 6f 75 73 20 3d 20 21 5f 5f  sAnonymous = !__
1680: 54 41 47 5f 49 4d 50 4c 5b 74 61 67 4e 61 6d 65  TAG_IMPL[tagName
1690: 5d 0a 20 20 63 6f 6e 73 74 20 69 73 56 69 72 74  ].  const isVirt
16a0: 75 61 6c 20 3d 20 64 6f 6d 2e 74 61 67 4e 61 6d  ual = dom.tagNam
16b0: 65 20 3d 3d 3d 20 27 56 49 52 54 55 41 4c 27 0a  e === 'VIRTUAL'.
16c0: 20 20 6c 65 74 20 6f 6c 64 49 74 65 6d 73 20 3d    let oldItems =
16d0: 20 5b 5d 0a 0a 20 20 2f 2f 20 72 65 6d 6f 76 65   []..  // remove
16e0: 20 74 68 65 20 65 61 63 68 20 70 72 6f 70 65 72   the each proper
16f0: 74 79 20 66 72 6f 6d 20 74 68 65 20 6f 72 69 67  ty from the orig
1700: 69 6e 61 6c 20 74 61 67 0a 20 20 72 65 6d 6f 76  inal tag.  remov
1710: 65 41 74 74 72 69 62 75 74 65 28 64 6f 6d 2c 20  eAttribute(dom, 
1720: 4c 4f 4f 50 5f 44 49 52 45 43 54 49 56 45 29 0a  LOOP_DIRECTIVE).
1730: 20 20 72 65 6d 6f 76 65 41 74 74 72 69 62 75 74    removeAttribut
1740: 65 28 64 6f 6d 2c 20 4b 45 59 5f 44 49 52 45 43  e(dom, KEY_DIREC
1750: 54 49 56 45 29 0a 0a 20 20 2f 2f 20 70 61 72 73  TIVE)..  // pars
1760: 65 20 74 68 65 20 65 61 63 68 20 65 78 70 72 65  e the each expre
1770: 73 73 69 6f 6e 0a 20 20 65 78 70 72 20 3d 20 74  ssion.  expr = t
1780: 6d 70 6c 2e 6c 6f 6f 70 4b 65 79 73 28 65 78 70  mpl.loopKeys(exp
1790: 72 29 0a 20 20 65 78 70 72 2e 69 73 4c 6f 6f 70  r).  expr.isLoop
17a0: 20 3d 20 74 72 75 65 0a 0a 20 20 69 66 20 28 69   = true..  if (i
17b0: 66 45 78 70 72 29 20 72 65 6d 6f 76 65 41 74 74  fExpr) removeAtt
17c0: 72 69 62 75 74 65 28 64 6f 6d 2c 20 43 4f 4e 44  ribute(dom, COND
17d0: 49 54 49 4f 4e 41 4c 5f 44 49 52 45 43 54 49 56  ITIONAL_DIRECTIV
17e0: 45 29 0a 0a 20 20 2f 2f 20 69 6e 73 65 72 74 20  E)..  // insert 
17f0: 61 20 6d 61 72 6b 65 64 20 77 68 65 72 65 20 74  a marked where t
1800: 68 65 20 6c 6f 6f 70 20 74 61 67 73 20 77 69 6c  he loop tags wil
1810: 6c 20 62 65 20 69 6e 6a 65 63 74 65 64 0a 20 20  l be injected.  
1820: 70 61 72 65 6e 74 4e 6f 64 65 2e 69 6e 73 65 72  parentNode.inser
1830: 74 42 65 66 6f 72 65 28 70 6c 61 63 65 68 6f 6c  tBefore(placehol
1840: 64 65 72 2c 20 64 6f 6d 29 0a 20 20 70 61 72 65  der, dom).  pare
1850: 6e 74 4e 6f 64 65 2e 72 65 6d 6f 76 65 43 68 69  ntNode.removeChi
1860: 6c 64 28 64 6f 6d 29 0a 0a 20 20 65 78 70 72 2e  ld(dom)..  expr.
1870: 75 70 64 61 74 65 20 3d 20 66 75 6e 63 74 69 6f  update = functio
1880: 6e 20 75 70 64 61 74 65 45 61 63 68 28 29 20 7b  n updateEach() {
1890: 0a 20 20 20 20 2f 2f 20 67 65 74 20 74 68 65 20  .    // get the 
18a0: 6e 65 77 20 69 74 65 6d 73 20 63 6f 6c 6c 65 63  new items collec
18b0: 74 69 6f 6e 0a 20 20 20 20 65 78 70 72 2e 76 61  tion.    expr.va
18c0: 6c 75 65 20 3d 20 74 6d 70 6c 28 65 78 70 72 2e  lue = tmpl(expr.
18d0: 76 61 6c 2c 20 70 61 72 65 6e 74 29 0a 0a 20 20  val, parent)..  
18e0: 20 20 6c 65 74 20 69 74 65 6d 73 20 3d 20 65 78    let items = ex
18f0: 70 72 2e 76 61 6c 75 65 0a 20 20 20 20 63 6f 6e  pr.value.    con
1900: 73 74 20 66 72 61 67 20 3d 20 63 72 65 61 74 65  st frag = create
1910: 46 72 61 67 6d 65 6e 74 28 29 0a 20 20 20 20 63  Fragment().    c
1920: 6f 6e 73 74 20 69 73 4f 62 6a 65 63 74 20 3d 20  onst isObject = 
1930: 21 69 73 41 72 72 61 79 28 69 74 65 6d 73 29 20  !isArray(items) 
1940: 26 26 20 21 69 73 53 74 72 69 6e 67 28 69 74 65  && !isString(ite
1950: 6d 73 29 0a 20 20 20 20 63 6f 6e 73 74 20 72 6f  ms).    const ro
1960: 6f 74 20 3d 20 70 6c 61 63 65 68 6f 6c 64 65 72  ot = placeholder
1970: 2e 70 61 72 65 6e 74 4e 6f 64 65 0a 20 20 20 20  .parentNode.    
1980: 63 6f 6e 73 74 20 74 6d 70 49 74 65 6d 73 20 3d  const tmpItems =
1990: 20 5b 5d 0a 20 20 20 20 63 6f 6e 73 74 20 68 61   [].    const ha
19a0: 73 4b 65 79 73 20 3d 20 69 73 4f 62 6a 65 63 74  sKeys = isObject
19b0: 20 26 26 20 21 21 69 74 65 6d 73 0a 0a 20 20 20   && !!items..   
19c0: 20 2f 2f 20 69 66 20 74 68 69 73 20 44 4f 4d 20   // if this DOM 
19d0: 77 61 73 20 72 65 6d 6f 76 65 64 20 74 68 65 20  was removed the 
19e0: 75 70 64 61 74 65 20 68 65 72 65 20 69 73 20 75  update here is u
19f0: 73 65 6c 65 73 73 0a 20 20 20 20 2f 2f 20 74 68  seless.    // th
1a00: 69 73 20 63 6f 6e 64 69 74 69 6f 6e 20 66 69 78  is condition fix
1a10: 65 73 20 61 6c 73 6f 20 61 20 77 65 69 72 64 20  es also a weird 
1a20: 61 73 79 6e 63 20 69 73 73 75 65 20 6f 6e 20 49  async issue on I
1a30: 45 20 69 6e 20 6f 75 72 20 75 6e 69 74 20 74 65  E in our unit te
1a40: 73 74 0a 20 20 20 20 69 66 20 28 21 72 6f 6f 74  st.    if (!root
1a50: 29 20 72 65 74 75 72 6e 0a 0a 20 20 20 20 2f 2f  ) return..    //
1a60: 20 6f 62 6a 65 63 74 20 6c 6f 6f 70 2e 20 61 6e   object loop. an
1a70: 79 20 63 68 61 6e 67 65 73 20 63 61 75 73 65 20  y changes cause 
1a80: 66 75 6c 6c 20 72 65 64 72 61 77 0a 20 20 20 20  full redraw.    
1a90: 69 66 20 28 69 73 4f 62 6a 65 63 74 29 20 7b 0a  if (isObject) {.
1aa0: 20 20 20 20 20 20 69 74 65 6d 73 20 3d 20 69 74        items = it
1ab0: 65 6d 73 20 3f 20 4f 62 6a 65 63 74 2e 6b 65 79  ems ? Object.key
1ac0: 73 28 69 74 65 6d 73 29 2e 6d 61 70 28 6b 65 79  s(items).map(key
1ad0: 20 3d 3e 20 6d 6b 69 74 65 6d 28 65 78 70 72 2c   => mkitem(expr,
1ae0: 20 69 74 65 6d 73 5b 6b 65 79 5d 2c 20 6b 65 79   items[key], key
1af0: 29 29 20 3a 20 5b 5d 0a 20 20 20 20 7d 0a 0a 20  )) : [].    }.. 
1b00: 20 20 20 2f 2f 20 73 74 6f 72 65 20 74 68 65 20     // store the 
1b10: 61 6d 6f 75 6e 74 20 6f 66 20 66 69 6c 74 65 72  amount of filter
1b20: 65 64 20 69 74 65 6d 73 0a 20 20 20 20 6c 65 74  ed items.    let
1b30: 20 66 69 6c 74 65 72 65 64 49 74 65 6d 73 43 6f   filteredItemsCo
1b40: 75 6e 74 20 3d 20 30 0a 0a 20 20 20 20 2f 2f 20  unt = 0..    // 
1b50: 6c 6f 6f 70 20 61 6c 6c 20 74 68 65 20 6e 65 77  loop all the new
1b60: 20 69 74 65 6d 73 0a 20 20 20 20 65 61 63 68 28   items.    each(
1b70: 69 74 65 6d 73 2c 20 28 5f 69 74 65 6d 2c 20 69  items, (_item, i
1b80: 6e 64 65 78 29 20 3d 3e 20 7b 0a 20 20 20 20 20  ndex) => {.     
1b90: 20 63 6f 6e 73 74 20 69 20 3d 20 69 6e 64 65 78   const i = index
1ba0: 20 2d 20 66 69 6c 74 65 72 65 64 49 74 65 6d 73   - filteredItems
1bb0: 43 6f 75 6e 74 0a 20 20 20 20 20 20 63 6f 6e 73  Count.      cons
1bc0: 74 20 69 74 65 6d 20 3d 20 21 68 61 73 4b 65 79  t item = !hasKey
1bd0: 73 20 26 26 20 65 78 70 72 2e 6b 65 79 20 3f 20  s && expr.key ? 
1be0: 6d 6b 69 74 65 6d 28 65 78 70 72 2c 20 5f 69 74  mkitem(expr, _it
1bf0: 65 6d 2c 20 69 6e 64 65 78 29 20 3a 20 5f 69 74  em, index) : _it
1c00: 65 6d 0a 0a 20 20 20 20 20 20 2f 2f 20 73 6b 69  em..      // ski
1c10: 70 20 74 68 69 73 20 69 74 65 6d 20 62 65 63 61  p this item beca
1c20: 75 73 65 20 69 74 20 6d 75 73 74 20 62 65 20 66  use it must be f
1c30: 69 6c 74 65 72 65 64 0a 20 20 20 20 20 20 69 66  iltered.      if
1c40: 20 28 69 66 45 78 70 72 20 26 26 20 21 74 6d 70   (ifExpr && !tmp
1c50: 6c 28 69 66 45 78 70 72 2c 20 65 78 74 65 6e 64  l(ifExpr, extend
1c60: 28 63 72 65 61 74 65 28 70 61 72 65 6e 74 29 2c  (create(parent),
1c70: 20 69 74 65 6d 29 29 29 20 7b 0a 20 20 20 20 20   item))) {.     
1c80: 20 20 20 66 69 6c 74 65 72 65 64 49 74 65 6d 73     filteredItems
1c90: 43 6f 75 6e 74 20 2b 2b 0a 20 20 20 20 20 20 20  Count ++.       
1ca0: 20 72 65 74 75 72 6e 0a 20 20 20 20 20 20 7d 0a   return.      }.
1cb0: 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 69 74 65  .      const ite
1cc0: 6d 49 64 20 3d 20 67 65 74 49 74 65 6d 49 64 28  mId = getItemId(
1cd0: 6b 65 79 41 74 74 72 2c 20 5f 69 74 65 6d 2c 20  keyAttr, _item, 
1ce0: 69 74 65 6d 2c 20 68 61 73 4b 65 79 41 74 74 72  item, hasKeyAttr
1cf0: 45 78 70 72 29 0a 20 20 20 20 20 20 2f 2f 20 72  Expr).      // r
1d00: 65 6f 72 64 65 72 20 6f 6e 6c 79 20 69 66 20 74  eorder only if t
1d10: 68 65 20 69 74 65 6d 73 20 61 72 65 20 6e 6f 74  he items are not
1d20: 20 6f 62 6a 65 63 74 73 0a 20 20 20 20 20 20 2f   objects.      /
1d30: 2f 20 6f 72 20 61 20 6b 65 79 20 61 74 74 72 69  / or a key attri
1d40: 62 75 74 65 20 68 61 73 20 62 65 65 6e 20 70 72  bute has been pr
1d50: 6f 76 69 64 65 64 0a 20 20 20 20 20 20 63 6f 6e  ovided.      con
1d60: 73 74 20 64 6f 52 65 6f 72 64 65 72 20 3d 20 21  st doReorder = !
1d70: 69 73 4f 62 6a 65 63 74 20 26 26 20 6d 75 73 74  isObject && must
1d80: 52 65 6f 72 64 65 72 20 26 26 20 74 79 70 65 6f  Reorder && typeo
1d90: 66 20 5f 69 74 65 6d 20 3d 3d 3d 20 54 5f 4f 42  f _item === T_OB
1da0: 4a 45 43 54 20 7c 7c 20 6b 65 79 41 74 74 72 0a  JECT || keyAttr.
1db0: 20 20 20 20 20 20 63 6f 6e 73 74 20 6f 6c 64 50        const oldP
1dc0: 6f 73 20 3d 20 6f 6c 64 49 74 65 6d 73 2e 69 6e  os = oldItems.in
1dd0: 64 65 78 4f 66 28 69 74 65 6d 49 64 29 0a 20 20  dexOf(itemId).  
1de0: 20 20 20 20 63 6f 6e 73 74 20 69 73 4e 65 77 20      const isNew 
1df0: 3d 20 6f 6c 64 50 6f 73 20 3d 3d 3d 20 2d 31 0a  = oldPos === -1.
1e00: 20 20 20 20 20 20 63 6f 6e 73 74 20 70 6f 73 20        const pos 
1e10: 3d 20 21 69 73 4e 65 77 20 26 26 20 64 6f 52 65  = !isNew && doRe
1e20: 6f 72 64 65 72 20 3f 20 6f 6c 64 50 6f 73 20 3a  order ? oldPos :
1e30: 20 69 0a 20 20 20 20 20 20 2f 2f 20 64 6f 65 73   i.      // does
1e40: 20 61 20 74 61 67 20 65 78 69 73 74 20 69 6e 20   a tag exist in 
1e50: 74 68 69 73 20 70 6f 73 69 74 69 6f 6e 3f 0a 20  this position?. 
1e60: 20 20 20 20 20 6c 65 74 20 74 61 67 20 3d 20 74       let tag = t
1e70: 61 67 73 5b 70 6f 73 5d 0a 20 20 20 20 20 20 63  ags[pos].      c
1e80: 6f 6e 73 74 20 6d 75 73 74 41 70 70 65 6e 64 20  onst mustAppend 
1e90: 3d 20 69 20 3e 3d 20 6f 6c 64 49 74 65 6d 73 2e  = i >= oldItems.
1ea0: 6c 65 6e 67 74 68 0a 20 20 20 20 20 20 63 6f 6e  length.      con
1eb0: 73 74 20 6d 75 73 74 43 72 65 61 74 65 20 3d 20  st mustCreate = 
1ec0: 64 6f 52 65 6f 72 64 65 72 20 26 26 20 69 73 4e  doReorder && isN
1ed0: 65 77 20 7c 7c 20 21 64 6f 52 65 6f 72 64 65 72  ew || !doReorder
1ee0: 20 26 26 20 21 74 61 67 20 7c 7c 20 21 74 61 67   && !tag || !tag
1ef0: 73 5b 69 5d 0a 0a 20 20 20 20 20 20 2f 2f 20 6e  s[i]..      // n
1f00: 65 77 20 74 61 67 0a 20 20 20 20 20 20 69 66 20  ew tag.      if 
1f10: 28 6d 75 73 74 43 72 65 61 74 65 29 20 7b 0a 20  (mustCreate) {. 
1f20: 20 20 20 20 20 20 20 74 61 67 20 3d 20 63 72 65         tag = cre
1f30: 61 74 65 54 61 67 28 69 6d 70 6c 2c 20 7b 0a 20  ateTag(impl, {. 
1f40: 20 20 20 20 20 20 20 20 20 70 61 72 65 6e 74 2c           parent,
1f50: 0a 20 20 20 20 20 20 20 20 20 20 69 73 4c 6f 6f  .          isLoo
1f60: 70 2c 0a 20 20 20 20 20 20 20 20 20 20 69 73 41  p,.          isA
1f70: 6e 6f 6e 79 6d 6f 75 73 2c 0a 20 20 20 20 20 20  nonymous,.      
1f80: 20 20 20 20 74 61 67 4e 61 6d 65 2c 0a 20 20 20      tagName,.   
1f90: 20 20 20 20 20 20 20 72 6f 6f 74 3a 20 64 6f 6d         root: dom
1fa0: 2e 63 6c 6f 6e 65 4e 6f 64 65 28 69 73 41 6e 6f  .cloneNode(isAno
1fb0: 6e 79 6d 6f 75 73 29 2c 0a 20 20 20 20 20 20 20  nymous),.       
1fc0: 20 20 20 69 74 65 6d 2c 0a 20 20 20 20 20 20 20     item,.       
1fd0: 20 20 20 69 6e 64 65 78 3a 20 69 2c 0a 20 20 20     index: i,.   
1fe0: 20 20 20 20 20 7d 2c 20 69 6e 6e 65 72 48 54 4d       }, innerHTM
1ff0: 4c 29 0a 0a 20 20 20 20 20 20 20 20 2f 2f 20 6d  L)..        // m
2000: 6f 75 6e 74 20 74 68 65 20 74 61 67 0a 20 20 20  ount the tag.   
2010: 20 20 20 20 20 74 61 67 2e 6d 6f 75 6e 74 28 29       tag.mount()
2020: 0a 0a 20 20 20 20 20 20 20 20 69 66 20 28 6d 75  ..        if (mu
2030: 73 74 41 70 70 65 6e 64 29 0a 20 20 20 20 20 20  stAppend).      
2040: 20 20 20 20 61 70 70 65 6e 64 2e 61 70 70 6c 79      append.apply
2050: 28 74 61 67 2c 20 5b 66 72 61 67 20 7c 7c 20 72  (tag, [frag || r
2060: 6f 6f 74 2c 20 69 73 56 69 72 74 75 61 6c 5d 29  oot, isVirtual])
2070: 0a 20 20 20 20 20 20 20 20 65 6c 73 65 0a 20 20  .        else.  
2080: 20 20 20 20 20 20 20 20 69 6e 73 65 72 74 2e 61          insert.a
2090: 70 70 6c 79 28 74 61 67 2c 20 5b 72 6f 6f 74 2c  pply(tag, [root,
20a0: 20 74 61 67 73 5b 69 5d 2c 20 69 73 56 69 72 74   tags[i], isVirt
20b0: 75 61 6c 5d 29 0a 0a 20 20 20 20 20 20 20 20 69  ual])..        i
20c0: 66 20 28 21 6d 75 73 74 41 70 70 65 6e 64 29 20  f (!mustAppend) 
20d0: 6f 6c 64 49 74 65 6d 73 2e 73 70 6c 69 63 65 28  oldItems.splice(
20e0: 69 2c 20 30 2c 20 69 74 65 6d 29 0a 20 20 20 20  i, 0, item).    
20f0: 20 20 20 20 74 61 67 73 2e 73 70 6c 69 63 65 28      tags.splice(
2100: 69 2c 20 30 2c 20 74 61 67 29 0a 20 20 20 20 20  i, 0, tag).     
2110: 20 20 20 69 66 20 28 63 68 69 6c 64 29 20 61 72     if (child) ar
2120: 72 61 79 69 73 68 41 64 64 28 70 61 72 65 6e 74  rayishAdd(parent
2130: 2e 74 61 67 73 2c 20 74 61 67 4e 61 6d 65 2c 20  .tags, tagName, 
2140: 74 61 67 2c 20 74 72 75 65 29 0a 20 20 20 20 20  tag, true).     
2150: 20 7d 20 65 6c 73 65 20 69 66 20 28 70 6f 73 20   } else if (pos 
2160: 21 3d 3d 20 69 20 26 26 20 64 6f 52 65 6f 72 64  !== i && doReord
2170: 65 72 29 20 7b 0a 20 20 20 20 20 20 20 20 2f 2f  er) {.        //
2180: 20 6d 6f 76 65 0a 20 20 20 20 20 20 20 20 69 66   move.        if
2190: 20 28 6b 65 79 41 74 74 72 20 7c 7c 20 63 6f 6e   (keyAttr || con
21a0: 74 61 69 6e 73 28 69 74 65 6d 73 2c 20 6f 6c 64  tains(items, old
21b0: 49 74 65 6d 73 5b 70 6f 73 5d 29 29 20 7b 0a 20  Items[pos])) {. 
21c0: 20 20 20 20 20 20 20 20 20 6d 6f 76 65 2e 61 70           move.ap
21d0: 70 6c 79 28 74 61 67 2c 20 5b 72 6f 6f 74 2c 20  ply(tag, [root, 
21e0: 74 61 67 73 5b 69 5d 2c 20 69 73 56 69 72 74 75  tags[i], isVirtu
21f0: 61 6c 5d 29 0a 20 20 20 20 20 20 20 20 20 20 2f  al]).          /
2200: 2f 20 6d 6f 76 65 20 74 68 65 20 6f 6c 64 20 74  / move the old t
2210: 61 67 20 69 6e 73 74 61 6e 63 65 0a 20 20 20 20  ag instance.    
2220: 20 20 20 20 20 20 74 61 67 73 2e 73 70 6c 69 63        tags.splic
2230: 65 28 69 2c 20 30 2c 20 74 61 67 73 2e 73 70 6c  e(i, 0, tags.spl
2240: 69 63 65 28 70 6f 73 2c 20 31 29 5b 30 5d 29 0a  ice(pos, 1)[0]).
2250: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 6d 6f 76            // mov
2260: 65 20 74 68 65 20 6f 6c 64 20 69 74 65 6d 0a 20  e the old item. 
2270: 20 20 20 20 20 20 20 20 20 6f 6c 64 49 74 65 6d           oldItem
2280: 73 2e 73 70 6c 69 63 65 28 69 2c 20 30 2c 20 6f  s.splice(i, 0, o
2290: 6c 64 49 74 65 6d 73 2e 73 70 6c 69 63 65 28 70  ldItems.splice(p
22a0: 6f 73 2c 20 31 29 5b 30 5d 29 0a 20 20 20 20 20  os, 1)[0]).     
22b0: 20 20 20 7d 0a 0a 20 20 20 20 20 20 20 20 2f 2f     }..        //
22c0: 20 75 70 64 61 74 65 20 74 68 65 20 70 6f 73 69   update the posi
22d0: 74 69 6f 6e 20 61 74 74 72 69 62 75 74 65 20 69  tion attribute i
22e0: 66 20 69 74 20 65 78 69 73 74 73 0a 20 20 20 20  f it exists.    
22f0: 20 20 20 20 69 66 20 28 65 78 70 72 2e 70 6f 73      if (expr.pos
2300: 29 20 74 61 67 5b 65 78 70 72 2e 70 6f 73 5d 20  ) tag[expr.pos] 
2310: 3d 20 69 0a 0a 20 20 20 20 20 20 20 20 2f 2f 20  = i..        // 
2320: 69 66 20 74 68 65 20 6c 6f 6f 70 20 74 61 67 73  if the loop tags
2330: 20 61 72 65 20 6e 6f 74 20 63 75 73 74 6f 6d 0a   are not custom.
2340: 20 20 20 20 20 20 20 20 2f 2f 20 77 65 20 6e 65          // we ne
2350: 65 64 20 74 6f 20 6d 6f 76 65 20 61 6c 6c 20 74  ed to move all t
2360: 68 65 69 72 20 63 75 73 74 6f 6d 20 74 61 67 73  heir custom tags
2370: 20 69 6e 74 6f 20 74 68 65 20 72 69 67 68 74 20   into the right 
2380: 70 6f 73 69 74 69 6f 6e 0a 20 20 20 20 20 20 20  position.       
2390: 20 69 66 20 28 21 63 68 69 6c 64 20 26 26 20 74   if (!child && t
23a0: 61 67 2e 74 61 67 73 29 20 6d 6f 76 65 4e 65 73  ag.tags) moveNes
23b0: 74 65 64 54 61 67 73 2e 63 61 6c 6c 28 74 61 67  tedTags.call(tag
23c0: 2c 20 69 29 0a 20 20 20 20 20 20 7d 0a 0a 20 20  , i).      }..  
23d0: 20 20 20 20 2f 2f 20 63 61 63 68 65 20 74 68 65      // cache the
23e0: 20 6f 72 69 67 69 6e 61 6c 20 69 74 65 6d 20 74   original item t
23f0: 6f 20 75 73 65 20 69 74 20 69 6e 20 74 68 65 20  o use it in the 
2400: 65 76 65 6e 74 73 20 62 6f 75 6e 64 20 74 6f 20  events bound to 
2410: 74 68 69 73 20 6e 6f 64 65 0a 20 20 20 20 20 20  this node.      
2420: 2f 2f 20 61 6e 64 20 69 74 73 20 63 68 69 6c 64  // and its child
2430: 72 65 6e 0a 20 20 20 20 20 20 65 78 74 65 6e 64  ren.      extend
2440: 28 74 61 67 2e 5f 5f 2c 20 7b 0a 20 20 20 20 20  (tag.__, {.     
2450: 20 20 20 69 74 65 6d 2c 0a 20 20 20 20 20 20 20     item,.       
2460: 20 69 6e 64 65 78 3a 20 69 2c 0a 20 20 20 20 20   index: i,.     
2470: 20 20 20 70 61 72 65 6e 74 0a 20 20 20 20 20 20     parent.      
2480: 7d 29 0a 0a 20 20 20 20 20 20 74 6d 70 49 74 65  })..      tmpIte
2490: 6d 73 5b 69 5d 20 3d 20 69 74 65 6d 49 64 0a 0a  ms[i] = itemId..
24a0: 20 20 20 20 20 20 69 66 20 28 21 6d 75 73 74 43        if (!mustC
24b0: 72 65 61 74 65 29 20 74 61 67 2e 75 70 64 61 74  reate) tag.updat
24c0: 65 28 69 74 65 6d 29 0a 20 20 20 20 7d 29 0a 0a  e(item).    })..
24d0: 20 20 20 20 2f 2f 20 72 65 6d 6f 76 65 20 74 68      // remove th
24e0: 65 20 72 65 64 75 6e 64 61 6e 74 20 74 61 67 73  e redundant tags
24f0: 0a 20 20 20 20 75 6e 6d 6f 75 6e 74 52 65 64 75  .    unmountRedu
2500: 6e 64 61 6e 74 28 69 74 65 6d 73 2c 20 74 61 67  ndant(items, tag
2510: 73 2c 20 66 69 6c 74 65 72 65 64 49 74 65 6d 73  s, filteredItems
2520: 43 6f 75 6e 74 29 0a 0a 20 20 20 20 2f 2f 20 63  Count)..    // c
2530: 6c 6f 6e 65 20 74 68 65 20 69 74 65 6d 73 20 61  lone the items a
2540: 72 72 61 79 0a 20 20 20 20 6f 6c 64 49 74 65 6d  rray.    oldItem
2550: 73 20 3d 20 74 6d 70 49 74 65 6d 73 2e 73 6c 69  s = tmpItems.sli
2560: 63 65 28 29 0a 0a 20 20 20 20 72 6f 6f 74 2e 69  ce()..    root.i
2570: 6e 73 65 72 74 42 65 66 6f 72 65 28 66 72 61 67  nsertBefore(frag
2580: 2c 20 70 6c 61 63 65 68 6f 6c 64 65 72 29 0a 20  , placeholder). 
2590: 20 7d 0a 0a 20 20 65 78 70 72 2e 75 6e 6d 6f 75   }..  expr.unmou
25a0: 6e 74 20 3d 20 28 29 20 3d 3e 20 7b 0a 20 20 20  nt = () => {.   
25b0: 20 65 61 63 68 28 74 61 67 73 2c 20 74 20 3d 3e   each(tags, t =>
25c0: 20 7b 20 74 2e 75 6e 6d 6f 75 6e 74 28 29 20 7d   { t.unmount() }
25d0: 29 0a 20 20 7d 0a 0a 20 20 72 65 74 75 72 6e 20  ).  }..  return 
25e0: 65 78 70 72 0a 7d                                expr.}