@weborigami/origami 0.5.4 → 0.5.6

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 (131) hide show
  1. package/index.ts +0 -4
  2. package/main.js +2 -9
  3. package/package.json +4 -5
  4. package/src/cli/cli.js +10 -8
  5. package/src/common/documentObject.js +3 -3
  6. package/src/common/loadJsDom.js +13 -0
  7. package/src/common/utilities.d.ts +0 -2
  8. package/src/common/utilities.js +1 -55
  9. package/src/dev/ExplorableSiteTransform.js +2 -6
  10. package/src/dev/OriCommandTransform.js +25 -7
  11. package/src/dev/changes.js +10 -5
  12. package/src/dev/code.js +1 -6
  13. package/src/dev/copy.js +4 -8
  14. package/src/dev/crawler/audit.js +8 -8
  15. package/src/dev/crawler/crawl.js +3 -5
  16. package/src/dev/crawler/findPaths.js +9 -3
  17. package/src/dev/crawler/pathsInHtml.js +4 -3
  18. package/src/dev/debug.js +4 -7
  19. package/src/dev/dev.js +4 -2
  20. package/src/dev/explore.js +17 -39
  21. package/src/dev/help.js +0 -4
  22. package/src/dev/help.yaml +18 -14
  23. package/src/dev/log.js +1 -2
  24. package/src/dev/serve.js +5 -18
  25. package/src/dev/svg.js +5 -5
  26. package/src/dev/treeDot.js +5 -6
  27. package/src/dev/watch.js +8 -12
  28. package/src/initializeBuiltins.js +23 -0
  29. package/src/origami/csv.js +1 -5
  30. package/src/origami/document.js +2 -5
  31. package/src/origami/fetch.js +4 -8
  32. package/src/origami/htmlDom.js +3 -2
  33. package/src/origami/image/format.js +0 -5
  34. package/src/origami/image/resize.js +0 -3
  35. package/src/origami/indexPage.js +4 -4
  36. package/src/origami/inline.js +4 -10
  37. package/src/origami/json.js +2 -6
  38. package/src/origami/jsonKeys.js +4 -10
  39. package/src/origami/jsonParse.js +1 -1
  40. package/src/origami/mdHtml.js +5 -9
  41. package/src/origami/mdOutline.js +3 -3
  42. package/src/origami/once.js +3 -7
  43. package/src/origami/ori.js +21 -24
  44. package/src/origami/origami.js +1 -4
  45. package/src/origami/pack.js +0 -5
  46. package/src/origami/post.js +4 -3
  47. package/src/origami/rss.js +7 -8
  48. package/src/origami/sitemap.js +7 -9
  49. package/src/origami/static.js +7 -9
  50. package/src/origami/string.js +1 -14
  51. package/src/origami/unpack.js +0 -5
  52. package/src/origami/yaml.js +1 -5
  53. package/src/origami/yamlParse.js +1 -1
  54. package/src/server/constructResponse.js +3 -3
  55. package/src/server/server.js +8 -59
  56. package/src/builtinsProgram.js +0 -65
  57. package/src/builtinsShell.js +0 -18
  58. package/src/cli/getConfig.js +0 -11
  59. package/src/common/ConstantTree.js +0 -18
  60. package/src/common/constructHref.js +0 -20
  61. package/src/common/constructSiteTree.js +0 -34
  62. package/src/common/fetchAndHandleExtension.js +0 -27
  63. package/src/handlers/css.handler.js +0 -7
  64. package/src/handlers/csv.handler.js +0 -126
  65. package/src/handlers/handlerBuiltins.js +0 -27
  66. package/src/handlers/handlers.js +0 -33
  67. package/src/handlers/htm.handler.js +0 -2
  68. package/src/handlers/html.handler.js +0 -7
  69. package/src/handlers/jpeg.handler.js +0 -62
  70. package/src/handlers/jpg.handler.js +0 -2
  71. package/src/handlers/js.handler.js +0 -20
  72. package/src/handlers/json.handler.js +0 -27
  73. package/src/handlers/md.handler.js +0 -7
  74. package/src/handlers/mjs.handler.js +0 -2
  75. package/src/handlers/ori.handler.js +0 -55
  76. package/src/handlers/oridocument.handler.js +0 -78
  77. package/src/handlers/parseFrontMatter.js +0 -16
  78. package/src/handlers/processUnpackedContent.js +0 -35
  79. package/src/handlers/ts.handler.js +0 -1
  80. package/src/handlers/txt.handler.js +0 -91
  81. package/src/handlers/wasm.handler.js +0 -17
  82. package/src/handlers/xhtml.handler.js +0 -2
  83. package/src/handlers/yaml.handler.js +0 -36
  84. package/src/handlers/yml.handler.js +0 -2
  85. package/src/origami/config.js +0 -18
  86. package/src/origami/project.js +0 -111
  87. package/src/protocols/explore.js +0 -19
  88. package/src/protocols/files.js +0 -31
  89. package/src/protocols/http.js +0 -18
  90. package/src/protocols/https.js +0 -18
  91. package/src/protocols/httpstree.js +0 -19
  92. package/src/protocols/httptree.js +0 -19
  93. package/src/protocols/js.js +0 -13
  94. package/src/protocols/node.js +0 -13
  95. package/src/protocols/package.js +0 -70
  96. package/src/tree/addNextPrevious.js +0 -22
  97. package/src/tree/cache.js +0 -22
  98. package/src/tree/calendar.js +0 -1
  99. package/src/tree/clear.js +0 -19
  100. package/src/tree/concat.js +0 -17
  101. package/src/tree/constant.js +0 -1
  102. package/src/tree/deepMap.js +0 -32
  103. package/src/tree/deepMerge.js +0 -18
  104. package/src/tree/deepReverse.js +0 -23
  105. package/src/tree/deepTake.js +0 -26
  106. package/src/tree/deepValues.js +0 -22
  107. package/src/tree/defineds.js +0 -30
  108. package/src/tree/filter.js +0 -19
  109. package/src/tree/first.js +0 -19
  110. package/src/tree/fromFn.js +0 -29
  111. package/src/tree/globKeys.js +0 -19
  112. package/src/tree/group.js +0 -26
  113. package/src/tree/inners.js +0 -30
  114. package/src/tree/keys.js +0 -15
  115. package/src/tree/length.js +0 -15
  116. package/src/tree/map.d.ts +0 -11
  117. package/src/tree/map.js +0 -125
  118. package/src/tree/mask.js +0 -19
  119. package/src/tree/match.js +0 -79
  120. package/src/tree/merge.js +0 -41
  121. package/src/tree/paginate.js +0 -20
  122. package/src/tree/parent.js +0 -15
  123. package/src/tree/plain.js +0 -15
  124. package/src/tree/regExpKeys.js +0 -19
  125. package/src/tree/reverse.js +0 -17
  126. package/src/tree/setDeep.js +0 -49
  127. package/src/tree/shuffle.js +0 -57
  128. package/src/tree/sort.js +0 -52
  129. package/src/tree/take.js +0 -19
  130. package/src/tree/tree.js +0 -52
  131. package/src/tree/values.js +0 -15
package/src/dev/help.yaml CHANGED
@@ -175,12 +175,12 @@ Tree:
175
175
  cache:
176
176
  args: (tree, [cache])
177
177
  description: Caches values from the tree
178
+ calendar:
179
+ args: (options)
180
+ description: Return a tree structure for years/months/days
178
181
  clear:
179
182
  args: (tree)
180
183
  description: Remove all values from the tree
181
- concat:
182
- args: (...objs)
183
- description: Concatenate text and/or trees of text
184
184
  constant:
185
185
  args: (value)
186
186
  description: Return a deep tree with a single constant value
@@ -202,9 +202,9 @@ Tree:
202
202
  deepValues:
203
203
  args: (tree)
204
204
  description: The in-order leaf values of the tree
205
- defineds:
206
- args: (tree)
207
- description: Only the defined values of the tree
205
+ delete:
206
+ args: (tree, key)
207
+ description: Delete the value for the key from tree
208
208
  entries:
209
209
  args: (tree)
210
210
  description: The tree's [key, value] pairs
@@ -220,19 +220,17 @@ Tree:
220
220
  from:
221
221
  args: (object, options)
222
222
  description: Create a tree from an object
223
- fromFn:
224
- args: (fn, [keys])
225
- description: A tree defined by a value function
226
223
  globKeys:
227
224
  args: (patterns)
228
225
  description: A tree whose keys can include glob wildcard patterns
229
- group:
226
+ groupBy:
230
227
  args: (tree, fn)
231
228
  description: A new tree with values grouped by the function
232
229
  has:
233
230
  args: (tree, key)
234
231
  description: True if key exists in tree
235
232
  indent:
233
+ args: "`…`"
236
234
  description: Tagged template literal for normalizing indentation
237
235
  inners:
238
236
  args: (tree)
@@ -261,8 +259,11 @@ Tree:
261
259
  map:
262
260
  args: (tree, options)
263
261
  description: Create a new tree by mapping keys and/or values
262
+ mapExtension:
263
+ args: (tree, ext, options)
264
+ description: Map extensions and values
264
265
  mapReduce:
265
- args: (tree, valueFn, reduceFn)
266
+ args: (tree, mapFn, reduceFn)
266
267
  description: Map values and reduce them
267
268
  mask:
268
269
  args: (source, mask)
@@ -288,9 +289,6 @@ Tree:
288
289
  regExpKeys:
289
290
  args: (tree)
290
291
  description: A tree whose keys are regular expression strings
291
- remove:
292
- args: (tree, key)
293
- description: Remove the value for the key from tree
294
292
  reverse:
295
293
  args: (tree)
296
294
  description: Reverse the order of the tree's keys
@@ -309,6 +307,9 @@ Tree:
309
307
  take:
310
308
  args: (tree, n)
311
309
  description: The first n values in the tree
310
+ text:
311
+ args: "`…`"
312
+ description: Tagged template literal for rendering trees
312
313
  traverse:
313
314
  args: (tree, ...keys)
314
315
  description: Return the value at the path of keys
@@ -321,3 +322,6 @@ Tree:
321
322
  values:
322
323
  args: (tree)
323
324
  description: The tree's values
325
+ withKeys:
326
+ args: (tree, keys)
327
+ description: Use the given keys for the tree
package/src/dev/log.js CHANGED
@@ -4,12 +4,11 @@ import yaml from "../origami/yaml.js";
4
4
  * Log the first argument to the console as a side effect and return the second
5
5
  * argument. If no second argument is provided, return the first argument.
6
6
  *
7
- * @this {import("@weborigami/types").AsyncTree|null}
8
7
  * @param {any} object
9
8
  * @param {any} [result]
10
9
  */
11
10
  export default async function log(result, object = result) {
12
- let text = object !== undefined ? await yaml.call(this, object) : "undefined";
11
+ let text = object !== undefined ? await yaml(object) : "undefined";
13
12
  text = text?.trim();
14
13
  console.log(text);
15
14
  return result;
package/src/dev/serve.js CHANGED
@@ -1,13 +1,10 @@
1
- import { Tree } from "@weborigami/async-tree";
1
+ import { getTreeArgument } from "@weborigami/async-tree";
2
2
  import http from "node:http";
3
3
  import { createServer } from "node:net";
4
4
  import process from "node:process";
5
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
6
5
  import { isTransformApplied, transformObject } from "../common/utilities.js";
7
6
  import { requestListener } from "../server/server.js";
8
- import debug from "./debug.js";
9
7
  import ExplorableSiteTransform from "./ExplorableSiteTransform.js";
10
- import watch from "./watch.js";
11
8
 
12
9
  const defaultPort = 5000;
13
10
 
@@ -19,22 +16,12 @@ const defaultPort = 5000;
19
16
  *
20
17
  * @param {Treelike} treelike
21
18
  * @param {number} [port]
22
- * @this {AsyncTree|null}
23
19
  */
24
20
  export default async function serve(treelike, port) {
25
- assertTreeIsDefined(this, "serve");
26
- let tree;
27
- if (treelike) {
28
- tree = Tree.from(treelike, { parent: this });
29
- if (!isTransformApplied(ExplorableSiteTransform, tree)) {
30
- tree = transformObject(ExplorableSiteTransform, tree);
31
- }
32
- } else if (arguments.length === 0) {
33
- // By default, watch the default tree and add default pages.
34
- const withDefaults = await debug.call(this);
35
- tree = await watch.call(this, withDefaults);
36
- } else {
37
- throw new Error("serve: no tree was provided to serve");
21
+ let tree = await getTreeArgument(treelike, "serve");
22
+
23
+ if (!isTransformApplied(ExplorableSiteTransform, tree)) {
24
+ tree = transformObject(ExplorableSiteTransform, tree);
38
25
  }
39
26
 
40
27
  if (port === undefined) {
package/src/dev/svg.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { getTreeArgument } from "@weborigami/async-tree";
1
2
  import graphviz from "graphviz-wasm";
2
- import getTreeArgument from "../common/getTreeArgument.js";
3
+
3
4
  import dot from "./treeDot.js";
4
5
 
5
6
  let graphvizLoaded = false;
@@ -11,8 +12,7 @@ let graphvizLoaded = false;
11
12
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
12
13
  * @typedef {import("@weborigami/async-tree").PlainObject} PlainObject
13
14
  *
14
- * @this {AsyncTree|null}
15
- * @param {Treelike} [treelike]
15
+ * @param {Treelike} treelike
16
16
  * @param {PlainObject} [options]
17
17
  */
18
18
  export default async function svg(treelike, options = {}) {
@@ -20,8 +20,8 @@ export default async function svg(treelike, options = {}) {
20
20
  await graphviz.loadWASM();
21
21
  graphvizLoaded = true;
22
22
  }
23
- const tree = await getTreeArgument(this, arguments, treelike, "svg", true);
24
- const dotText = await dot.call(this, tree, options);
23
+ const tree = await getTreeArgument(treelike, "svg", { deep: true });
24
+ const dotText = await dot(tree, options);
25
25
  if (dotText === undefined) {
26
26
  return undefined;
27
27
  }
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  Tree,
3
+ getTreeArgument,
3
4
  isPlainObject,
4
- isStringLike,
5
+ isStringlike,
5
6
  toString,
6
7
  trailingSlash,
7
8
  } from "@weborigami/async-tree";
@@ -11,16 +12,14 @@ import { getDescriptor } from "../common/utilities.js";
11
12
  /**
12
13
  * Render a tree in DOT format.
13
14
  *
14
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
15
15
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
16
16
  * @typedef {import("@weborigami/async-tree").PlainObject} PlainObject
17
17
  *
18
- * @this {AsyncTree|null}
19
- * @param {Treelike} [treelike]
18
+ * @param {Treelike} treelike
20
19
  * @param {PlainObject} [options]
21
20
  */
22
21
  export default async function dot(treelike, options = {}) {
23
- const tree = Tree.from(treelike, { deep: true });
22
+ const tree = await getTreeArgument(treelike, "treeDot", { deep: true });
24
23
  const rootLabel = getDescriptor(tree) ?? "";
25
24
  const treeArcs = await statements(tree, "", rootLabel, options);
26
25
  return `digraph g {
@@ -74,7 +73,7 @@ async function statements(tree, nodePath, nodeLabel, options) {
74
73
  const subStatements = await statements(subtree, destPath, null, options);
75
74
  result = result.concat(subStatements);
76
75
  } else {
77
- const label = isStringLike(value)
76
+ const label = isStringlike(value)
78
77
  ? toString(value)
79
78
  : value !== undefined
80
79
  ? await serialize.toYaml(value)
package/src/dev/watch.js CHANGED
@@ -1,22 +1,19 @@
1
- import { Tree } from "@weborigami/async-tree";
1
+ import { constant, getTreeArgument, Tree } from "@weborigami/async-tree";
2
2
  import { formatError, moduleCache } from "@weborigami/language";
3
- import ConstantTree from "../common/ConstantTree.js";
4
- import getTreeArgument from "../common/getTreeArgument.js";
5
3
 
6
4
  /**
7
5
  * Let a tree (e.g., of files) respond to changes.
8
6
  *
9
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
7
+ * @typedef {import("@weborigami/async-tree").Invocable} Invocable
10
8
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
11
- * @typedef {import("../../index.ts").Invocable} Invocable
9
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
12
10
  *
13
- * @this {AsyncTree|null}
14
- * @param {Treelike} [treelike]
11
+ * @param {Treelike} treelike
15
12
  * @param {Invocable} [fn]
13
+ * @returns {Promise<AsyncTree>}
16
14
  */
17
15
  export default async function watch(treelike, fn) {
18
- /** @type {any} */
19
- const container = await getTreeArgument(this, arguments, treelike, "watch");
16
+ const container = await getTreeArgument(treelike, "watch");
20
17
 
21
18
  // Watch the indicated tree.
22
19
  await /** @type {any} */ (container).watch?.();
@@ -35,7 +32,7 @@ export default async function watch(treelike, fn) {
35
32
  const handle = Object.create(tree);
36
33
 
37
34
  // Reevaluate the function whenever the tree changes.
38
- container.addEventListener?.("change", async () => {
35
+ /** @type {any} */ (container).addEventListener?.("change", async () => {
39
36
  const tree = await evaluateTree(container, fn);
40
37
  moduleCache.resetTimestamp();
41
38
  updateIndirectPointer(handle, tree);
@@ -61,8 +58,7 @@ async function evaluateTree(parent, fn) {
61
58
  message = `Warning: watch expression did not return a tree`;
62
59
  }
63
60
  console.warn(message);
64
- tree = new ConstantTree(message);
65
- tree.parent = parent;
61
+ tree = constant(message);
66
62
  return tree;
67
63
  }
68
64
 
@@ -0,0 +1,23 @@
1
+ import { builtins } from "@weborigami/language";
2
+ import * as dev from "./dev/dev.js";
3
+ import help from "./dev/help.js";
4
+ import * as origami from "./origami/origami.js";
5
+
6
+ let initialized = false;
7
+
8
+ /**
9
+ * Pass the Origami builtins to the compiler.
10
+ */
11
+ export default function initializeBuiltins() {
12
+ if (!initialized) {
13
+ const origamiBuiltins = {
14
+ Dev: dev,
15
+ Origami: origami,
16
+ "help:": help,
17
+ };
18
+
19
+ Object.assign(builtins, origamiBuiltins);
20
+ }
21
+
22
+ initialized = true;
23
+ }
@@ -1,5 +1,4 @@
1
1
  import { isUnpackable, toPlainValue } from "@weborigami/async-tree";
2
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
3
2
 
4
3
  /**
5
4
  * Render the object as text in CSV format.
@@ -7,12 +6,9 @@ import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
7
6
  * The object should a treelike object such as an array. The output will include
8
7
  * a header row with field names taken from the first item in the tree/array.
9
8
  *
10
- * @this {import("@weborigami/types").AsyncTree|null}
11
- * @param {any} [object]
9
+ * @param {any} object
12
10
  */
13
11
  export default async function csv(object) {
14
- assertTreeIsDefined(this, "csv");
15
- object = object ?? this;
16
12
  if (object === undefined) {
17
13
  return undefined;
18
14
  }
@@ -1,15 +1,12 @@
1
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
1
  import documentObject from "../common/documentObject.js";
3
2
 
4
3
  /**
5
4
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
6
- * @typedef {import("@weborigami/async-tree").StringLike} StringLike
5
+ * @typedef {import("@weborigami/async-tree").Stringlike} Stringlike
7
6
  *
8
- * @this {AsyncTree|null}
9
- * @param {StringLike} text
7
+ * @param {Stringlike} text
10
8
  * @param {any} [data]
11
9
  */
12
10
  export default async function documentBuiltin(text, data) {
13
- assertTreeIsDefined(this, "document");
14
11
  return documentObject(text, data);
15
12
  }
@@ -1,7 +1,8 @@
1
- import { getHandlers, handleExtension } from "@weborigami/language";
1
+ import { handleExtension } from "@weborigami/language";
2
2
 
3
3
  /**
4
- * @this {import("@weborigami/types").AsyncTree|null|undefined}
4
+ * Extend the JavaScript `fetch` function to implicity return an ArrayBuffer
5
+ * with an unpack() method if the resource has a known file extension.
5
6
  */
6
7
  export default async function fetchBuiltin(resource, options) {
7
8
  const response = await fetch(resource, options);
@@ -10,13 +11,8 @@ export default async function fetchBuiltin(resource, options) {
10
11
  }
11
12
 
12
13
  const value = await response.arrayBuffer();
13
- if (!this) {
14
- // Can't get extension handlers
15
- return value;
16
- }
17
14
 
18
- const handlers = getHandlers(this);
19
15
  const url = new URL(resource);
20
16
  const key = url.pathname;
21
- return handleExtension(this, value, key, handlers);
17
+ return handleExtension(value, key);
22
18
  }
@@ -1,6 +1,7 @@
1
- import { JSDOM } from "jsdom";
1
+ import loadJsDom from "../common/loadJsDom.js";
2
2
 
3
- export default function htmlDom(html) {
3
+ export default async function htmlDom(html) {
4
+ const { JSDOM } = await loadJsDom();
4
5
  const dom = JSDOM.fragment(html);
5
6
  return dom;
6
7
  }
@@ -1,19 +1,14 @@
1
1
  import sharp from "sharp";
2
- import assertTreeIsDefined from "../../common/assertTreeIsDefined.js";
3
2
 
4
3
  /**
5
4
  * Return the image in a different format.
6
5
  *
7
- * @this {import("@weborigami/types").AsyncTree|null}
8
- *
9
- * @this {import("@weborigami/types").AsyncTree|null}
10
6
  * @param {import("@weborigami/async-tree").Packed} input
11
7
  * @param {keyof import("sharp").FormatEnum|import("sharp").AvailableFormatInfo}
12
8
  * format
13
9
  * @param {any} options
14
10
  */
15
11
  export default async function imageFormat(input, format, options) {
16
- assertTreeIsDefined(this, "format");
17
12
  return input instanceof Uint8Array || input instanceof ArrayBuffer
18
13
  ? sharp(input).toFormat(format, options).toBuffer()
19
14
  : undefined;
@@ -1,15 +1,12 @@
1
1
  import sharp from "sharp";
2
- import assertTreeIsDefined from "../../common/assertTreeIsDefined.js";
3
2
 
4
3
  /**
5
4
  * Resize an image.
6
5
  *
7
- * @this {import("@weborigami/types").AsyncTree|null}
8
6
  * @param {import("@weborigami/async-tree").Packed} input
9
7
  * @param {import("sharp").ResizeOptions} options
10
8
  */
11
9
  export default async function resize(input, options) {
12
- assertTreeIsDefined(this, "resize");
13
10
  return input instanceof Uint8Array || input instanceof ArrayBuffer
14
11
  ? sharp(input).rotate().resize(options).toBuffer()
15
12
  : undefined;
@@ -1,4 +1,4 @@
1
- import getTreeArgument from "../common/getTreeArgument.js";
1
+ import { getTreeArgument } from "@weborigami/async-tree";
2
2
  import { getDescriptor } from "../common/utilities.js";
3
3
 
4
4
  /**
@@ -6,12 +6,12 @@ import { getDescriptor } from "../common/utilities.js";
6
6
  *
7
7
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
8
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
9
- * @this {AsyncTree|null}
10
- * @param {Treelike} [treelike]
9
+ *
10
+ * @param {Treelike} treelike
11
11
  * @param {string} [basePath]
12
12
  */
13
13
  export default async function indexPage(treelike, basePath) {
14
- const tree = await getTreeArgument(this, arguments, treelike, "indexPage");
14
+ const tree = await getTreeArgument(treelike, "svg");
15
15
  const keys = Array.from(await tree.keys());
16
16
 
17
17
  // Skip system-ish files that start with a period. Also skip `index.html`.
@@ -1,21 +1,16 @@
1
1
  import { isUnpackable, symbols, toString } from "@weborigami/async-tree";
2
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
+ import { oridocument_handler } from "@weborigami/language/src/handlers/handlers.js";
3
3
  import documentObject from "../common/documentObject.js";
4
- import { oridocumentHandler } from "../handlers/handlers.js";
5
4
 
6
5
  /**
7
6
  * Inline any Origami expressions found inside ${...} placeholders in the input
8
7
  * text.
9
8
  *
10
9
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
11
- * @typedef {import("@weborigami/async-tree").StringLike} StringLike
12
10
  *
13
- * @this {AsyncTree|null}
14
- * @param {StringLike & {_body?: StringLike}} input
11
+ * @param {any} input
15
12
  */
16
13
  export default async function inline(input) {
17
- assertTreeIsDefined(this, "inline");
18
-
19
14
  // Get the input text and any attached front matter.
20
15
  if (isUnpackable(input)) {
21
16
  input = await input.unpack();
@@ -28,8 +23,7 @@ export default async function inline(input) {
28
23
 
29
24
  const parent =
30
25
  /** @type {any} */ (input).parent ??
31
- /** @type {any} */ (input)[symbols.parent] ??
32
- this;
26
+ /** @type {any} */ (input)[symbols.parent];
33
27
 
34
28
  let front;
35
29
  if (inputIsDocument) {
@@ -42,7 +36,7 @@ export default async function inline(input) {
42
36
  }
43
37
 
44
38
  // @ts-ignore
45
- let result = await oridocumentHandler.unpack(origami, {
39
+ let result = await oridocument_handler.unpack(origami, {
46
40
  front,
47
41
  parent,
48
42
  });
@@ -1,22 +1,18 @@
1
- /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
1
  import { isUnpackable, toPlainValue } from "@weborigami/async-tree";
3
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
4
2
 
5
3
  /**
6
4
  * Render the given object in JSON format.
7
5
  *
8
- * @this {AsyncTree|null}
6
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
7
+ *
9
8
  * @param {any} [obj]
10
9
  */
11
10
  export default async function json(obj) {
12
- assertTreeIsDefined(this, "json");
13
- // A fragment of the logic from getTreeArgument.js
14
11
  if (arguments.length > 0 && obj === undefined) {
15
12
  throw new Error(
16
13
  "An Origami function was called with an initial argument, but its value is undefined."
17
14
  );
18
15
  }
19
- obj = obj ?? this;
20
16
  if (obj === undefined) {
21
17
  return undefined;
22
18
  }
@@ -1,22 +1,16 @@
1
- import { Tree, jsonKeys } from "@weborigami/async-tree";
2
- import getTreeArgument from "../common/getTreeArgument.js";
1
+ import { Tree, getTreeArgument, jsonKeys } from "@weborigami/async-tree";
3
2
 
4
3
  /**
5
4
  * Expose .keys.json for a tree.
6
5
  *
7
6
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
7
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
9
- * @this {AsyncTree|null}
8
+ *
10
9
  * @param {Treelike} treelike
10
+ * @returns {Promise<AsyncTree>}
11
11
  */
12
12
  export default async function jsonKeysBuiltin(treelike) {
13
- const tree = await getTreeArgument(
14
- this,
15
- arguments,
16
- treelike,
17
- "jsonKeys",
18
- true
19
- );
13
+ const tree = await getTreeArgument(treelike, "jsonKeys");
20
14
  return jsonKeysTree(tree);
21
15
  }
22
16
 
@@ -1,4 +1,4 @@
1
- import { toString } from "../common/utilities.js";
1
+ import { toString } from "@weborigami/async-tree";
2
2
 
3
3
  export default async function jsonParse(input) {
4
4
  const text = toString(input);
@@ -1,11 +1,10 @@
1
- import { extension, isUnpackable } from "@weborigami/async-tree";
1
+ import { extension, isUnpackable, toString } from "@weborigami/async-tree";
2
2
  import highlight from "highlight.js";
3
3
  import { Marked } from "marked";
4
4
  import { gfmHeadingId as markedGfmHeadingId } from "marked-gfm-heading-id";
5
5
  import { markedHighlight } from "marked-highlight";
6
6
  import { markedSmartypants } from "marked-smartypants";
7
7
  import documentObject from "../common/documentObject.js";
8
- import { toString } from "../common/utilities.js";
9
8
  import origamiHighlightDefinition from "./origamiHighlightDefinition.js";
10
9
 
11
10
  highlight.registerLanguage("ori", origamiHighlightDefinition);
@@ -32,11 +31,7 @@ marked.use(
32
31
  /**
33
32
  * Transform markdown to HTML.
34
33
  *
35
- * @typedef {import("@weborigami/async-tree").StringLike} StringLike
36
- * @typedef {import("@weborigami/async-tree").Unpackable<StringLike>} UnpackableStringlike
37
- *
38
- * @this {import("@weborigami/types").AsyncTree|null|void}
39
- * @param {StringLike|UnpackableStringlike} input
34
+ * @param {any} input
40
35
  */
41
36
  export default async function mdHtml(input) {
42
37
  if (input == null) {
@@ -48,7 +43,7 @@ export default async function mdHtml(input) {
48
43
  input = await input.unpack();
49
44
  }
50
45
  const inputIsDocument = typeof input === "object" && "_body" in input;
51
- const markdown = toString(input);
46
+ const markdown = inputIsDocument ? input._body : toString(input);
52
47
  if (markdown === null) {
53
48
  throw new Error("mdHtml: The provided input couldn't be treated as text.");
54
49
  }
@@ -56,5 +51,6 @@ export default async function mdHtml(input) {
56
51
  return inputIsDocument ? documentObject(html, input) : html;
57
52
  }
58
53
 
59
- mdHtml.key = (sourceKey) => extension.replace(sourceKey, ".md", ".html");
54
+ mdHtml.key = (sourceValue, sourceKey) =>
55
+ extension.replace(sourceKey, ".md", ".html");
60
56
  mdHtml.inverseKey = (resultKey) => extension.replace(resultKey, ".html", ".md");
@@ -1,12 +1,12 @@
1
- import { isUnpackable } from "@weborigami/async-tree";
1
+ import { isUnpackable, toString } from "@weborigami/async-tree";
2
2
  import { Marked } from "marked";
3
- import { toString } from "../common/utilities.js";
4
3
 
5
4
  export default async function mdOutline(input) {
6
5
  if (isUnpackable(input)) {
7
6
  input = await input.unpack();
8
7
  }
9
- const markdown = toString(input);
8
+ const inputIsDocument = typeof input === "object" && "_body" in input;
9
+ const markdown = inputIsDocument ? input._body : toString(input);
10
10
  if (markdown === null) {
11
11
  throw new Error("mdHtml: The provided input couldn't be treated as text.");
12
12
  }
@@ -1,5 +1,3 @@
1
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
-
3
1
  const fnPromiseMap = new Map();
4
2
  const codePromiseMap = new Map();
5
3
 
@@ -7,18 +5,16 @@ const codePromiseMap = new Map();
7
5
  * Evaluate the given function only once and cache the result.
8
6
  *
9
7
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
10
- * @this {AsyncTree|null}
8
+ *
11
9
  * @param {Function} fn
12
10
  */
13
11
  export default async function once(fn) {
14
- assertTreeIsDefined(this, "once");
15
-
16
12
  const code = /** @type {any} */ (fn).code;
17
13
  if (code) {
18
14
  // Origami function, cache by code
19
15
  if (!codePromiseMap.has(code)) {
20
16
  // Don't wait for promise to resolve
21
- const promise = fn.call(this);
17
+ const promise = fn();
22
18
  codePromiseMap.set(code, promise);
23
19
  }
24
20
  return codePromiseMap.get(code);
@@ -27,7 +23,7 @@ export default async function once(fn) {
27
23
  // Regular function, cache by function
28
24
  if (!fnPromiseMap.has(fn)) {
29
25
  // Don't wait for promise to resolve
30
- const promise = fn.call(this);
26
+ const promise = fn();
31
27
  fnPromiseMap.set(fn, promise);
32
28
  }
33
29
  return fnPromiseMap.get(fn);