jtlt 0.3.0 → 0.5.0

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.
Files changed (59) hide show
  1. package/CHANGES.md +18 -0
  2. package/README.md +46 -78
  3. package/demo/codemirror.esm.js +28242 -0
  4. package/demo/codemirror.js +94 -0
  5. package/demo/index.css +11 -0
  6. package/demo/index.html +11 -14
  7. package/demo/index.js +210 -26
  8. package/demo/vendor/fontoxpath/dist/fontoxpath.esm.js +600 -0
  9. package/demo/vendor/jamilih/dist/jml.mjs +2341 -0
  10. package/demo/vendor/jhtml/src/SAJJ/SAJJ.ObjectArrayDelegator.js +356 -0
  11. package/demo/vendor/jhtml/src/SAJJ/SAJJ.Stringifier.js +186 -0
  12. package/demo/vendor/jhtml/src/SAJJ/SAJJ.js +746 -0
  13. package/demo/vendor/jhtml/src/SAJJ/testing/SAJJ.html +33 -0
  14. package/demo/vendor/jhtml/src/SAJJ/testing/SAJJ.testing.js +25 -0
  15. package/demo/vendor/jhtml/src/jhtml-browser.js +5 -0
  16. package/demo/vendor/jhtml/src/jhtml-node.cts +3 -0
  17. package/demo/vendor/jhtml/src/jhtml-node.js +8 -0
  18. package/demo/vendor/jhtml/src/jhtml-node.mts +1 -0
  19. package/demo/vendor/jhtml/src/jhtml.cts +3 -0
  20. package/demo/vendor/jhtml/src/jhtml.js +602 -0
  21. package/demo/vendor/jhtml/src/jhtml.mts +1 -0
  22. package/demo/vendor/jsonpath-plus/dist/index-browser-esm.js +2158 -0
  23. package/demo/vendor/prsc/dist/prsc.esm.js +2 -0
  24. package/demo/vendor/simple-get-json/dist/index-es.js +151 -0
  25. package/demo/vendor/whynot/dist/whynot.esm.js +2 -0
  26. package/demo/vendor/xspattern/dist/xspattern.esm.js +2 -0
  27. package/dist/AbstractJoiningTransformer.d.ts +27 -0
  28. package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
  29. package/dist/DOMJoiningTransformer.d.ts +60 -8
  30. package/dist/DOMJoiningTransformer.d.ts.map +1 -1
  31. package/dist/JSONJoiningTransformer.d.ts +8 -9
  32. package/dist/JSONJoiningTransformer.d.ts.map +1 -1
  33. package/dist/JSONPathTransformer.d.ts.map +1 -1
  34. package/dist/JSONPathTransformerContext.d.ts +223 -4
  35. package/dist/JSONPathTransformerContext.d.ts.map +1 -1
  36. package/dist/StringJoiningTransformer.d.ts +7 -7
  37. package/dist/StringJoiningTransformer.d.ts.map +1 -1
  38. package/dist/XPathTransformer.d.ts +2 -2
  39. package/dist/XPathTransformer.d.ts.map +1 -1
  40. package/dist/XPathTransformerContext.d.ts +161 -8
  41. package/dist/XPathTransformerContext.d.ts.map +1 -1
  42. package/dist/index.d.ts +4 -4
  43. package/dist/index.d.ts.map +1 -1
  44. package/docs/API.expanded.md +5 -3
  45. package/docs/API.md +1 -1
  46. package/docs/TO-DO.md +62 -36
  47. package/eslint.config.js +3 -1
  48. package/package.json +28 -4
  49. package/rollup.config.js +13 -0
  50. package/src/AbstractJoiningTransformer.js +42 -0
  51. package/src/DOMJoiningTransformer.js +115 -23
  52. package/src/JSONJoiningTransformer.js +50 -26
  53. package/src/JSONPathTransformer.js +2 -0
  54. package/src/JSONPathTransformerContext.js +936 -5
  55. package/src/StringJoiningTransformer.js +25 -21
  56. package/src/XPathTransformer.js +3 -1
  57. package/src/XPathTransformerContext.js +884 -15
  58. package/src/index.js +16 -7
  59. package/tsconfig.json +5 -2
@@ -36,7 +36,7 @@ function _makeDatasetAttribute (n0) {
36
36
  * plus special helpers: dataset (object) and $a (ordered attribute array).
37
37
  * @typedef {Record<string, unknown> & {
38
38
  * dataset?: Record<string, string>,
39
- * $a?: Array<[string, string]>
39
+ * $a?: [string, string][]
40
40
  * }} ElementAttributes
41
41
  */
42
42
 
@@ -329,20 +329,6 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
329
329
  return this;
330
330
  }
331
331
 
332
- /**
333
- * @param {import('./StringJoiningTransformer.js').OutputConfig} cfg
334
- * @returns {JSONJoiningTransformer}
335
- */
336
- output (cfg) {
337
- // We wait until first element is set in `element()` to add
338
- // XML declaration and DOCTYPE as latter depends on root element
339
- this._outputConfig = cfg;
340
-
341
- // Use for file extension if making downloadable?
342
- this.mediaType = cfg.mediaType;
343
- return this;
344
- }
345
-
346
332
  /**
347
333
  * Build a Jamilih-style element JSON array and append to current container.
348
334
  * Result form: ['tag', {attr: 'val'}, child1, child2, ...]
@@ -401,23 +387,35 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
401
387
  for (const k in ds) {
402
388
  if (Object.hasOwn(ds, k)) {
403
389
  const dashed = k.replaceAll(camelCase, _makeDatasetAttribute);
404
- attsObj['data-' + dashed] = ds[k];
390
+ attsObj['data-' + dashed] = this._replaceCharacterMaps(ds[k]);
405
391
  }
406
392
  }
407
393
  delete attsObj.dataset;
408
394
  }
409
395
  if (Array.isArray(attsObj.$a)) {
410
- (/** @type {unknown[][]} */ (attsObj.$a)).forEach((pair) => {
396
+ attsObj.$a.forEach((pair) => {
411
397
  if (Array.isArray(pair) && pair.length > 1) {
412
- attsObj[String(pair[0])] = pair[1];
398
+ attsObj[String(pair[0])] = this._replaceCharacterMaps(pair[1]);
413
399
  }
414
400
  });
415
401
  delete attsObj.$a;
416
402
  }
417
403
 
404
+ // Apply character maps to all regular attribute values
405
+ for (const key in attsObj) {
406
+ if (Object.hasOwn(attsObj, key) && typeof attsObj[key] === 'string') {
407
+ attsObj[key] = this._replaceCharacterMaps(attsObj[key]);
408
+ }
409
+ }
410
+
418
411
  // If children provided as array, copy (may be primitives or nested JML)
419
412
  if (Array.isArray(childNodes) && childNodes.length) {
420
- jmlChildren.push(...childNodes);
413
+ jmlChildren.push(...childNodes.map((childNode) => {
414
+ if (typeof childNode === 'string') {
415
+ return this._replaceCharacterMaps(childNode);
416
+ }
417
+ return childNode;
418
+ }));
421
419
  }
422
420
 
423
421
  // Callback-driven building (attribute/text/nested element mutate stack)
@@ -435,9 +433,10 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
435
433
  /** @type {any[]} */
436
434
  const jmlEl = [elementName];
437
435
  if (Object.keys(attsObj).length) {
438
- jmlEl.push(attsObj);
436
+ jmlEl.push(attsObj, jmlChildren);
437
+ } else {
438
+ jmlEl.push(jmlChildren);
439
439
  }
440
- jmlEl.push(...jmlChildren);
441
440
 
442
441
  if (isRoot) {
443
442
  // todo: indent, cdataSectionElements
@@ -490,6 +489,29 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
490
489
  return this;
491
490
  }
492
491
 
492
+ /**
493
+ * @param {string} prefix
494
+ * @param {string} namespaceURI
495
+ * @returns {JSONJoiningTransformer}
496
+ */
497
+ namespace (prefix, namespaceURI) {
498
+ if (!this._elementStack.length) {
499
+ // No-op outside an element() callback (JSON joiner semantics)
500
+ return this;
501
+ }
502
+ const top = /** @type {ElementInfo} */ (this._elementStack.at(-1));
503
+ const {attsObj} = top;
504
+
505
+ if (!attsObj.xmlns) {
506
+ attsObj.xmlns = {};
507
+ }
508
+
509
+ /** @type {Record<string, string>} */
510
+ (attsObj.xmlns)[prefix] = this._replaceCharacterMaps(namespaceURI);
511
+
512
+ return this;
513
+ }
514
+
493
515
  /**
494
516
  * Adds/updates an attribute for the most recently open element built via
495
517
  * a callback-driven element(). When not in an element callback context,
@@ -513,20 +535,22 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
513
535
  for (const k in datasetObj) {
514
536
  if (Object.hasOwn(datasetObj, k)) {
515
537
  const dashed = k.replaceAll(camelCase, _makeDatasetAttribute);
516
- attsObj['data-' + dashed] = datasetObj[k];
538
+ attsObj['data-' + dashed] = this._replaceCharacterMaps(
539
+ /** @type {string} */ (datasetObj[k])
540
+ );
517
541
  }
518
542
  }
519
543
  return this;
520
544
  }
521
545
  if (name === '$a' && Array.isArray(val)) {
522
- (/** @type {unknown[][]} */ (val)).forEach((pair) => {
546
+ val.forEach((pair) => {
523
547
  if (Array.isArray(pair) && pair.length > 1) {
524
- attsObj[String(pair[0])] = pair[1];
548
+ attsObj[String(pair[0])] = this._replaceCharacterMaps(pair[1]);
525
549
  }
526
550
  });
527
551
  return this;
528
552
  }
529
- attsObj[name] = val;
553
+ attsObj[name] = this._replaceCharacterMaps(/** @type {string} */ (val));
530
554
  return this;
531
555
  }
532
556
 
@@ -578,7 +602,7 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
578
602
  if (this._elementStack.length) {
579
603
  const top = /** @type {ElementInfo} */ (this._elementStack.at(-1));
580
604
  const {jmlChildren} = top;
581
- jmlChildren.push(['!', txt]);
605
+ jmlChildren.push(this._replaceCharacterMaps(txt));
582
606
  return this;
583
607
  }
584
608
  // No-op outside element context in JSON joiner
@@ -70,6 +70,8 @@ class JSONPathTransformer {
70
70
  if (len > 1) {
71
71
  this._triggerEqualPriorityError();
72
72
  }
73
+ // Set up parameter context for valueOf() access in root template
74
+ jte._params = {0: jte._contextObj};
73
75
  const ret = /** @type {import('./index.js').JSONPathTemplateObject<T>} */ (
74
76
  templateObj
75
77
  ).template.call(jte, undefined, {mode});