jaxs 0.2.1 → 0.3.1

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.
@@ -581,7 +581,6 @@ function hmrAccept(bundle /*: ParcelRequire */ , id /*: string */ ) {
581
581
  },{}],"bAfYR":[function(require,module,exports) {
582
582
  var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
583
583
  parcelHelpers.defineInteropFlag(exports);
584
- parcelHelpers.export(exports, "views", ()=>views);
585
584
  parcelHelpers.export(exports, "render", ()=>render);
586
585
  parcelHelpers.export(exports, "navigation", ()=>exports_navigation);
587
586
  parcelHelpers.export(exports, "jsx", ()=>jsx_default);
@@ -655,11 +654,12 @@ var normalizeValueForKey = (object, key, defaultValue = "")=>{
655
654
  return object[key];
656
655
  };
657
656
  // src/rendering/dom/svg.ts
657
+ var namespace = "http://www.w3.org/2000/svg";
658
658
  var isSvgTag = (tagType)=>tagType === "svg";
659
+ var isSvg = (element)=>element.namespaceURI === namespace;
659
660
  var createSvgNode = (type, attributes, renderKit)=>{
660
661
  const document = renderKit && renderKit.document || window.document;
661
- const xmlns = "http://www.w3.org/2000/svg";
662
- const node = document.createElementNS(xmlns, type, xmlns);
662
+ const node = document.createElementNS(namespace, type);
663
663
  for(const key in attributes){
664
664
  if (key === "__self" || key === "xmlns") continue;
665
665
  node.setAttributeNS(null, key, attributes[key]);
@@ -709,20 +709,20 @@ var isTextNode = (child)=>{
709
709
  var textNode = (content)=>{
710
710
  return new TextTemplate(content);
711
711
  };
712
- var withSvgFlag = (isSvg)=>(template)=>{
713
- template && (template.isSvg = template.isSvg || isSvg);
712
+ var withSvgFlag = (isSvg2)=>(template)=>{
713
+ template && (template.isSvg = template.isSvg || isSvg2);
714
714
  return template;
715
715
  };
716
716
  class Children {
717
717
  collection;
718
718
  parentElement;
719
719
  isSvg;
720
- constructor(jsxChildren, isSvg = false){
720
+ constructor(jsxChildren, isSvg2 = false){
721
721
  this.collection = ensureArray(jsxChildren);
722
722
  this.collection = this.collection.map(replaceTextNodes);
723
723
  this.collection = this.collection.flat();
724
- this.collection = this.collection.map(withSvgFlag(isSvg));
725
- this.isSvg = isSvg;
724
+ this.collection = this.collection.map(withSvgFlag(isSvg2));
725
+ this.isSvg = isSvg2;
726
726
  }
727
727
  render(renderKit, parentElement) {
728
728
  this.parentElement = parentElement;
@@ -746,14 +746,13 @@ class Tag {
746
746
  attributes;
747
747
  children;
748
748
  isSvg;
749
- constructor(tagType, combinedAttributes, children2, isSvg = false){
749
+ constructor(tagType, combinedAttributes, children2, isSvg2 = false){
750
750
  this.type = tagType;
751
751
  const { events, attributes } = separateAttrsAndEvents(combinedAttributes);
752
752
  this.events = events;
753
753
  this.attributes = attributes;
754
- this.isSvg = isSvg || isSvgTag(this.type);
754
+ this.isSvg = isSvg2 || isSvgTag(this.type);
755
755
  this.children = new Children(children2, this.isSvg);
756
- console.log(this.type, this.isSvg);
757
756
  }
758
757
  render(renderKit) {
759
758
  const dom = this.generateDom(renderKit);
@@ -764,13 +763,8 @@ class Tag {
764
763
  ];
765
764
  }
766
765
  generateDom(renderKit) {
767
- if (this.isSvg) {
768
- console.log("rendering", this.type, "as svg");
769
- return this.generateSvnDom(renderKit);
770
- } else {
771
- console.log("rendering", this.type, "as normal node");
772
- return this.generateHtmlDom(renderKit);
773
- }
766
+ if (this.isSvg) return this.generateSvnDom(renderKit);
767
+ else return this.generateHtmlDom(renderKit);
774
768
  }
775
769
  generateHtmlDom(renderKit) {
776
770
  const node = createDecoratedNode(this.type, this.attributes, this.events, renderKit);
@@ -1137,7 +1131,7 @@ var createIdMap = (list)=>{
1137
1131
  return map;
1138
1132
  };
1139
1133
  // src/rendering/change/instructions/attributes.ts
1140
- var compileForAttributes = (source, target)=>{
1134
+ var compileForAttributes = (source, target, isSvg2 = false)=>{
1141
1135
  const instructions = [];
1142
1136
  const sourceAttributes = source.attributes;
1143
1137
  const sourceLength = sourceAttributes.length;
@@ -1159,11 +1153,13 @@ var compileForAttributes = (source, target)=>{
1159
1153
  }
1160
1154
  }
1161
1155
  if (!matchingAttribute) instructions.push(removeAttribute(source, target, {
1162
- name: sourceAttribute.name
1156
+ name: sourceAttribute.name,
1157
+ isSvg: isSvg2
1163
1158
  }));
1164
1159
  else if (sourceAttribute.value !== matchingAttribute.value) instructions.push(updateAttribute(source, target, {
1165
1160
  name: sourceAttribute.name,
1166
- value: matchingAttribute.value
1161
+ value: matchingAttribute.value,
1162
+ isSvg: isSvg2
1167
1163
  }));
1168
1164
  }
1169
1165
  for(index = 0; index < targetLength; index++){
@@ -1180,7 +1176,8 @@ var compileForAttributes = (source, target)=>{
1180
1176
  }
1181
1177
  if (!matchingAttribute) instructions.push(addAttribute(source, target, {
1182
1178
  name: targetAttribute.name,
1183
- value: targetAttribute.value
1179
+ value: targetAttribute.value,
1180
+ isSvg: isSvg2
1184
1181
  }));
1185
1182
  }
1186
1183
  return instructions;
@@ -1222,6 +1219,9 @@ var compileForElement = (source, target)=>{
1222
1219
  const valueInstructions = compileForInputValue(source, target);
1223
1220
  return attributeInstructions.concat(eventInstructions).concat(valueInstructions);
1224
1221
  };
1222
+ var compileForSvg = (source, target)=>{
1223
+ return compileForAttributes(source, target, true);
1224
+ };
1225
1225
  var compileForInputValue = (sourceElement, targetElement)=>{
1226
1226
  const instructions = [];
1227
1227
  if (sourceElement.tagName !== "INPUT") return instructions;
@@ -1248,7 +1248,13 @@ var NodeTypes;
1248
1248
  })(NodeTypes || (NodeTypes = {}));
1249
1249
  var compileForNodeGenerator = (compileForCollection)=>(source, target)=>{
1250
1250
  let instructions = [];
1251
- if (source.nodeType === NodeTypes.ElementNode) {
1251
+ if (source.nodeType === NodeTypes.ElementNode && isSvg(source)) {
1252
+ const sourceElement = source;
1253
+ const targetElement = target;
1254
+ const baseInstructions = compileForSvg(sourceElement, targetElement);
1255
+ const childrenInstructions = compileForCollection(sourceElement.childNodes, targetElement.childNodes, sourceElement);
1256
+ instructions = baseInstructions.concat(childrenInstructions);
1257
+ } else if (source.nodeType === NodeTypes.ElementNode) {
1252
1258
  const sourceElement = source;
1253
1259
  const targetElement = target;
1254
1260
  const baseInstructions = compileForElement(sourceElement, targetElement);
@@ -1257,8 +1263,6 @@ var compileForNodeGenerator = (compileForCollection)=>(source, target)=>{
1257
1263
  } else if (source.nodeType === NodeTypes.TextNode) instructions = compileForText(source, target);
1258
1264
  return instructions;
1259
1265
  };
1260
- // src/debugging.js
1261
- var debug = (...message)=>{};
1262
1266
  // src/rendering/change/instructions/children.ts
1263
1267
  var compileChildren = (sourceList, targetList, parent)=>{
1264
1268
  const baseInstructions = [];
@@ -1270,55 +1274,37 @@ var compileChildren = (sourceList, targetList, parent)=>{
1270
1274
  for(; index < length; index++){
1271
1275
  const source = sourceList[index];
1272
1276
  const target = targetList[index];
1273
- debug("\n", "loop index", index, source && source.__jsx, target && target.__jsx);
1274
1277
  if (target && targetMap.check(target)) {
1275
- debug("target", target.__jsx, "index", index);
1276
1278
  const matchingSource = sourceMap.pullMatch(target);
1277
1279
  targetMap.clear(target);
1278
1280
  if (matchingSource.element) {
1279
- debug("matching source found for target");
1280
- if (matchingSource.index !== index) {
1281
- debug("moving source", matchingSource.element.__jsx, index);
1282
- baseInstructions.push(insertNode(matchingSource.element, {
1283
- parent,
1284
- index
1285
- }));
1286
- }
1287
- debug("updating to match target", matchingSource.element.__jsx, matchingSource.element.classList, target.__jsx, target.classList);
1281
+ if (matchingSource.index !== index) baseInstructions.push(insertNode(matchingSource.element, {
1282
+ parent,
1283
+ index
1284
+ }));
1288
1285
  nodesPairsToDiff.push({
1289
1286
  source: matchingSource.element,
1290
1287
  target
1291
1288
  });
1292
1289
  } else if (source) {
1293
- debug("NO matching source for target but source in slot", source.__jsx);
1294
- if (targetMap.check(source)) {
1295
- debug("adding", target.__jsx, "at", index);
1296
- baseInstructions.push(insertNode(target, {
1297
- parent,
1298
- index
1299
- }));
1300
- } else {
1301
- debug("replacing", source.__jsx, target.__jsx, "at", index);
1302
- sourceMap.clear(source);
1303
- baseInstructions.push(replaceNode(source, target));
1304
- }
1305
- } else {
1306
- debug("adding target to end", target.__jsx);
1307
- baseInstructions.push(insertNode(target, {
1290
+ if (targetMap.check(source)) baseInstructions.push(insertNode(target, {
1308
1291
  parent,
1309
1292
  index
1310
1293
  }));
1311
- }
1294
+ else {
1295
+ sourceMap.clear(source);
1296
+ baseInstructions.push(replaceNode(source, target));
1297
+ }
1298
+ } else baseInstructions.push(insertNode(target, {
1299
+ parent,
1300
+ index
1301
+ }));
1312
1302
  } else if (source) {
1313
1303
  const matchingSource = sourceMap.pullMatch(source);
1314
- if (matchingSource.element) {
1315
- debug("removing", source.__jsx);
1316
- baseInstructions.push(removeNode(source));
1317
- }
1304
+ if (matchingSource.element) baseInstructions.push(removeNode(source));
1318
1305
  }
1319
1306
  }
1320
1307
  sourceMap.remaining().forEach(({ element: element2 })=>{
1321
- debug("removing", element2.__jsx);
1322
1308
  baseInstructions.push(removeNode(element2));
1323
1309
  });
1324
1310
  const nodeInstructions = nodesPairsToDiff.reduce((collection, { source, target })=>{
@@ -1340,7 +1326,6 @@ var compileForNode = compileForNodeGenerator(compileChildren);
1340
1326
  // src/rendering/change.ts
1341
1327
  var change = (source, target, parent)=>{
1342
1328
  const instructions = compileChildren(source, target, parent);
1343
- debug("instructions", instructions.map((instruction)=>instruction.type));
1344
1329
  instructions.forEach((instruction)=>{
1345
1330
  performInstruction(instruction);
1346
1331
  });
@@ -1357,7 +1342,6 @@ var changeText2 = (instruction)=>{
1357
1342
  var removeNode2 = (instruction)=>{
1358
1343
  const { source } = instruction;
1359
1344
  source.remove();
1360
- debug("removeNode called on", source.nodeName);
1361
1345
  };
1362
1346
  var insertNode2 = (instruction)=>{
1363
1347
  const { target, data } = instruction;
@@ -1369,18 +1353,18 @@ var insertNode2 = (instruction)=>{
1369
1353
  var replaceNode2 = (instruction)=>{
1370
1354
  const { source, target } = instruction;
1371
1355
  source.replaceWith(target);
1372
- debug("replaceNode called on", source.nodeName, "with", target.nodeName);
1373
- debug("parent", source.parentElement);
1374
1356
  };
1375
1357
  var removeAttribute2 = (instruction)=>{
1376
1358
  const { source, data } = instruction;
1377
- const { name } = data;
1378
- source.removeAttribute(name);
1359
+ const { name, isSvg: isSvg2 } = data;
1360
+ if (isSvg2) source.removeAttributeNS(null, name);
1361
+ else source.removeAttribute(name);
1379
1362
  };
1380
1363
  var addAttribute2 = (instruction)=>{
1381
1364
  const { source, data } = instruction;
1382
- const { name, value } = data;
1383
- source.setAttribute(name, value);
1365
+ const { name, value, isSvg: isSvg2 } = data;
1366
+ if (isSvg2) source.setAttributeNS(null, name, value);
1367
+ else source.setAttribute(name, value);
1384
1368
  };
1385
1369
  var updateAttribute2 = (instruction)=>{
1386
1370
  addAttribute2(instruction);
@@ -1424,10 +1408,11 @@ var performers = {
1424
1408
  [ChangeInstructions.changeValue]: changeValue2
1425
1409
  };
1426
1410
  // src/rendering/templates/bound.js
1411
+ var passThroughViewModel = (state2)=>state2;
1427
1412
  class Bound {
1428
1413
  constructor(TemplateClass, viewModel, subscriptions, attributes2){
1429
1414
  this.TemplateClass = TemplateClass;
1430
- this.viewModel = viewModel;
1415
+ this.viewModel = viewModel || passThroughViewModel;
1431
1416
  this.attributes = attributes2 || {};
1432
1417
  this.subscriptions = subscriptions;
1433
1418
  this.dom = [];
@@ -1644,44 +1629,6 @@ __export(exports_navigation, {
1644
1629
  return setupHistory;
1645
1630
  }
1646
1631
  });
1647
- // src/views/conditionals.jsx
1648
- var exports_conditionals = {};
1649
- __export(exports_conditionals, {
1650
- Unless: ()=>{
1651
- return Unless;
1652
- },
1653
- IfElse: ()=>{
1654
- return IfElse;
1655
- },
1656
- If: ()=>{
1657
- return If;
1658
- }
1659
- });
1660
- var If = ({ condition, children: children3 })=>{
1661
- if (!condition) return;
1662
- return jsx_default(jsx_default.fragment, null, children3);
1663
- };
1664
- var Unless = ({ condition, children: children3 })=>{
1665
- if (condition) return;
1666
- return jsx_default(jsx_default.fragment, null, children3);
1667
- };
1668
- var IfElse = ({ condition, children: children3 })=>{
1669
- const [first, ...rest] = children3;
1670
- if (condition) return jsx_default(jsx_default.fragment, null, first);
1671
- return jsx_default(jsx_default.fragment, null, rest);
1672
- };
1673
- // src/views/link.jsx
1674
- var Link = ({ children: children3, ...props })=>{
1675
- return jsx_default("a", {
1676
- ...props,
1677
- onClick: "goToHref"
1678
- }, children3);
1679
- };
1680
- // src/views.js
1681
- var views = {
1682
- ...exports_conditionals,
1683
- Link
1684
- };
1685
1632
 
1686
1633
  },{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"gkKU3":[function(require,module,exports) {
1687
1634
  exports.interopDefault = function(a) {