@weborigami/origami 0.3.3-jse.2 → 0.3.3

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.
package/main.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./src/calc/calc.js";
1
2
  export { default as documentObject } from "./src/common/documentObject.js";
2
3
  export { toString } from "./src/common/utilities.js";
3
4
  export * from "./src/dev/dev.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/origami",
3
- "version": "0.3.3-jse.2",
3
+ "version": "0.3.3",
4
4
  "description": "Web Origami language, CLI, framework, and server",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,10 +17,10 @@
17
17
  "typescript": "5.8.2"
18
18
  },
19
19
  "dependencies": {
20
- "@weborigami/async-tree": "0.3.3-jse.2",
20
+ "@weborigami/async-tree": "0.3.3",
21
21
  "@weborigami/json-feed-to-rss": "1.0.0",
22
- "@weborigami/language": "0.3.3-jse.2",
23
- "@weborigami/types": "0.3.3-jse.2",
22
+ "@weborigami/language": "0.3.3",
23
+ "@weborigami/types": "0.3.3",
24
24
  "css-tree": "3.1.0",
25
25
  "exif-parser": "0.1.12",
26
26
  "graphviz-wasm": "3.0.2",
package/src/builtins.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as calc from "./calc/calc.js";
1
2
  import * as dev from "./dev/dev.js";
2
3
  import * as handlers from "./handlers/handlers.js";
3
4
  import help from "./help/help.js";
@@ -21,6 +22,7 @@ import * as tree from "./tree/tree.js";
21
22
 
22
23
  /** @type {any} */
23
24
  export default {
25
+ "calc:": adjustReservedWords(calc),
24
26
  "dev:": dev,
25
27
  "explore:": explore,
26
28
  "files:": files,
@@ -0,0 +1,81 @@
1
+ import { Tree } from "@weborigami/async-tree";
2
+ import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
3
+
4
+ export function add(...args) {
5
+ console.warn(`Warning: "add" is deprecated. Use the "+" operator instead.`);
6
+ const numbers = args.map((arg) => Number(arg));
7
+ return numbers.reduce((acc, val) => acc + val, 0);
8
+ }
9
+
10
+ export function and(...args) {
11
+ console.warn(`Warning: "and" is deprecated. Use the "&&" operator instead.`);
12
+ return args.every((arg) => arg);
13
+ }
14
+
15
+ export function divide(a, b) {
16
+ console.warn(
17
+ `Warning: "divide" is deprecated. Use the "/" operator instead.`
18
+ );
19
+ return Number(a) / Number(b);
20
+ }
21
+
22
+ export function equals(a, b) {
23
+ console.warn(
24
+ `Warning: "equals" is deprecated. Use the "===" operator instead.`
25
+ );
26
+ return a === b;
27
+ }
28
+
29
+ /**
30
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
31
+ *
32
+ * @this {AsyncTree|null}
33
+ * @param {any} value
34
+ * @param {any} trueResult
35
+ * @param {any} [falseResult]
36
+ */
37
+ export async function ifBuiltin(value, trueResult, falseResult) {
38
+ console.warn(
39
+ `Warning: "if" is deprecated. Use the conditional "a ? b : c" operator instead.`
40
+ );
41
+
42
+ assertTreeIsDefined(this, "calc:if");
43
+ let condition = await value;
44
+ if (Tree.isAsyncTree(condition)) {
45
+ const keys = Array.from(await condition.keys());
46
+ condition = keys.length > 0;
47
+ }
48
+
49
+ // 0 is true, null/undefined/false is false
50
+ let result = condition || condition === 0 ? trueResult : falseResult;
51
+ if (typeof result === "function") {
52
+ result = await result.call(this);
53
+ }
54
+ return result;
55
+ }
56
+ ifBuiltin.key = "if";
57
+
58
+ export function multiply(...args) {
59
+ console.warn(
60
+ `Warning: "multiply" is deprecated. Use the "*" operator instead.`
61
+ );
62
+ const numbers = args.map((arg) => Number(arg));
63
+ return numbers.reduce((acc, val) => acc * val, 1);
64
+ }
65
+
66
+ export function not(value) {
67
+ console.warn(`Warning: "not" is deprecated. Use the "!" operator instead.`);
68
+ return !value;
69
+ }
70
+
71
+ export function or(...args) {
72
+ console.warn(`Warning: "or" is deprecated. Use the "||" operator instead.`);
73
+ return args.find((arg) => arg);
74
+ }
75
+
76
+ export function subtract(a, b) {
77
+ console.warn(
78
+ `Warning: "subtract" is deprecated. Use the "-" operator instead.`
79
+ );
80
+ return Number(a) - Number(b);
81
+ }
@@ -37,13 +37,6 @@ export default async function documentObject(input, data) {
37
37
  // };
38
38
  // const result = Object.create(base);
39
39
  const result = {};
40
- // TODO: Deprecate @text
41
40
  Object.assign(result, inputData, data, { "@text": text });
42
- Object.defineProperty(result, "_body", {
43
- configurable: true,
44
- value: text,
45
- enumerable: false, // TODO: Make enumerable
46
- writable: true,
47
- });
48
41
  return result;
49
42
  }
@@ -130,7 +130,7 @@ async function processPath(tree, path, baseUrl) {
130
130
 
131
131
  // Traverse tree to get value.
132
132
  let value;
133
- let normalizedKeys = [];
133
+ let normalizedKeys;
134
134
  let normalizedPath;
135
135
  try {
136
136
  value = await Tree.traverse(tree, ...keys);
@@ -5,9 +5,7 @@ import { addHref } from "./utilities.js";
5
5
 
6
6
  export default function pathsInHtml(html) {
7
7
  const paths = {
8
- /** @type {string[]} */
9
8
  crawlablePaths: [],
10
- /** @type {string[]} */
11
9
  resourcePaths: [],
12
10
  };
13
11
 
@@ -11,8 +11,6 @@ import htmHandler from "./htm.handler.js";
11
11
  import htmlHandler from "./html.handler.js";
12
12
  import jpegHandler from "./jpeg.handler.js";
13
13
  import jpgHandler from "./jpg.handler.js";
14
- import jseHandler from "./jse.handler.js";
15
- import jseDocumentHandler from "./jsedocument.handler.js";
16
14
  import jsonHandler from "./json.handler.js";
17
15
  import mdHandler from "./md.handler.js";
18
16
  import mjsHandler from "./mjs.handler.js";
@@ -29,9 +27,6 @@ export default {
29
27
  "jpeg.handler": jpegHandler,
30
28
  "jpg.handler": jpgHandler,
31
29
  "js.handler": jsHandler,
32
- "jse.handler": jseHandler,
33
- "jsep.handler": jseHandler,
34
- "jsedocument.handler": jseDocumentHandler,
35
30
  "json.handler": jsonHandler,
36
31
  "md.handler": mdHandler,
37
32
  "mjs.handler": mjsHandler,
@@ -34,8 +34,7 @@ export default {
34
34
 
35
35
  // Compile the source code as an Origami program and evaluate it.
36
36
  const compiler = options.compiler ?? compile.program;
37
- const mode = options.mode ?? "shell";
38
- const fn = compiler(source, { mode });
37
+ const fn = compiler(source);
39
38
  const target = parent ?? builtinsTree;
40
39
  let content = await fn.call(target);
41
40
 
@@ -35,8 +35,7 @@ export default {
35
35
  text,
36
36
  url,
37
37
  };
38
- const mode = options.mode ?? "shell";
39
- const defineFn = compile.templateDocument(source, { mode });
38
+ const defineFn = compile.templateDocument(source);
40
39
 
41
40
  // Invoke the definition to get back the template function
42
41
  const result = await defineFn.call(parent);
@@ -39,8 +39,7 @@ export default {
39
39
  throw new TypeError("The input to pack must be a JavaScript object.");
40
40
  }
41
41
 
42
- // TODO: Deprecate @text
43
- const text = object._body ?? object["@text"] ?? "";
42
+ const text = object["@text"] ?? "";
44
43
 
45
44
  /** @type {any} */
46
45
  const dataWithoutText = Object.assign({}, object);
@@ -73,14 +72,7 @@ export default {
73
72
  } else {
74
73
  frontData = parseYaml(frontText);
75
74
  }
76
- // TODO: Deprecate @text
77
75
  unpacked = Object.assign({}, frontData, { "@text": body });
78
- Object.defineProperty(unpacked, "_body", {
79
- configurable: true,
80
- value: text,
81
- enumerable: false, // TODO: Make enumerable
82
- writable: true,
83
- });
84
76
  } else {
85
77
  // Plain text
86
78
  unpacked = new String(text);
package/src/internal.js CHANGED
@@ -15,10 +15,6 @@ export { default as oriHandler } from "./handlers/ori.handler.js";
15
15
 
16
16
  export { default as oridocumentHandler } from "./handlers/oridocument.handler.js";
17
17
 
18
- export { default as jseHandler } from "./handlers/jse.handler.js";
19
-
20
- export { default as jsedocumentHandler } from "./handlers/jsedocument.handler.js";
21
-
22
18
  export { default as processUnpackedContent } from "./common/processUnpackedContent.js";
23
19
 
24
20
  export { default as wasmHandler } from "./handlers/wasm.handler.js";
package/src/js.js CHANGED
@@ -1,79 +1,38 @@
1
- /**
2
- * The complete set of support JavaScript globals and global-like values.
3
- *
4
- * See
5
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects.
6
- * That page lists some things like `TypedArrays` which are not globals so are
7
- * omitted here.
8
- */
1
+ async function fetchWrapper(resource, options) {
2
+ const response = await fetch(resource, options);
3
+ return response.ok ? await response.arrayBuffer() : undefined;
4
+ }
5
+
9
6
  export default {
10
- AggregateError,
11
7
  Array,
12
- ArrayBuffer,
13
- Atomics,
14
8
  BigInt,
15
- BigInt64Array,
16
- BigUint64Array,
17
9
  Boolean,
18
- DataView,
19
10
  Date,
20
11
  Error,
21
- EvalError,
22
- FinalizationRegistry,
23
- Float32Array,
24
- Float64Array,
25
- Function,
26
12
  Infinity,
27
- Int16Array,
28
- Int32Array,
29
- Int8Array,
30
13
  Intl,
31
- // @ts-ignore Iterator does exist despite what TypeScript thinks
32
- Iterator,
33
14
  JSON,
34
15
  Map,
35
16
  Math,
36
17
  NaN,
37
18
  Number,
38
19
  Object,
39
- Promise,
40
- Proxy,
41
- RangeError,
42
- ReferenceError,
43
- Reflect,
44
20
  RegExp,
21
+ Response,
45
22
  Set,
46
- SharedArrayBuffer,
47
23
  String,
48
24
  Symbol,
49
- SyntaxError,
50
- TypeError,
51
- URIError,
52
- Uint16Array,
53
- Uint32Array,
54
- Uint8Array,
55
- Uint8ClampedArray,
56
- WeakMap,
57
- WeakRef,
58
- WeakSet,
59
25
  decodeURI,
60
26
  decodeURIComponent,
61
27
  encodeURI,
62
28
  encodeURIComponent,
63
- eval,
64
- false: false, // treat like a global
65
- fetch: fetchWrapper, // special case
66
- globalThis,
29
+ false: false,
30
+ fetch: fetchWrapper,
67
31
  isFinite,
68
32
  isNaN,
69
- null: null, // treat like a global
33
+ null: null,
70
34
  parseFloat,
71
35
  parseInt,
72
- true: true, // treat like a global
73
- undefined,
36
+ true: true,
37
+ undefined: undefined,
74
38
  };
75
-
76
- async function fetchWrapper(resource, options) {
77
- const response = await fetch(resource, options);
78
- return response.ok ? await response.arrayBuffer() : undefined;
79
- }
@@ -1,84 +0,0 @@
1
- import {
2
- ObjectTree,
3
- trailingSlash,
4
- text as treeText,
5
- } from "@weborigami/async-tree";
6
- import * as dev from "./dev/dev.js";
7
- import * as handlers from "./handlers/handlers.js";
8
- import help from "./help/help.js";
9
- import * as image from "./image/image.js";
10
- import js from "./js.js";
11
- import node from "./node.js";
12
- import * as origami from "./origami/origami.js";
13
- import explore from "./protocols/explore.js";
14
- import files from "./protocols/files.js";
15
- import http from "./protocols/http.js";
16
- import https from "./protocols/https.js";
17
- import httpstree from "./protocols/httpstree.js";
18
- import httptree from "./protocols/httptree.js";
19
- import inherited from "./protocols/inherited.js";
20
- import instantiate from "./protocols/new.js";
21
- import packageNamespace from "./protocols/package.js";
22
- import scope from "./protocols/scope.js";
23
- import * as site from "./site/site.js";
24
- import * as text from "./text/text.js";
25
- import * as tree from "./tree/tree.js";
26
-
27
- // See notes in builtinsTree.js
28
- class BuiltinsTree {
29
- constructor(object) {
30
- this.object = object;
31
- }
32
-
33
- async get(key) {
34
- const normalizedKey = trailingSlash.remove(key);
35
- return this.object[normalizedKey];
36
- }
37
-
38
- async keys() {
39
- return Object.keys(this.object);
40
- }
41
- }
42
-
43
- const Tree = new BuiltinsTree({
44
- ...tree,
45
- indent: text.indent,
46
- json: origami.json,
47
- text: treeText,
48
- });
49
-
50
- const Origami = new BuiltinsTree({
51
- ...dev,
52
- ...origami,
53
- ...site,
54
- ...text,
55
- });
56
-
57
- const Image = new BuiltinsTree({
58
- ...image,
59
- });
60
-
61
- /** @type {any} */
62
- export default new ObjectTree({
63
- "explore:": explore,
64
- "files:": files,
65
- "help:": help,
66
- "http:": http,
67
- "https:": https,
68
- "httpstree:": httpstree,
69
- "httptree:": httptree,
70
- "inherited:": inherited,
71
- "new:": instantiate,
72
- "node:": node,
73
- "package:": packageNamespace,
74
- "scope:": scope,
75
-
76
- ...js,
77
-
78
- Tree,
79
- Origami,
80
- Image,
81
-
82
- // Some builtins need to be exposed at top level
83
- ...handlers.default,
84
- });
@@ -1,16 +0,0 @@
1
- import { oriHandler } from "../internal.js";
2
- import getParent from "./getParent.js";
3
- import jseModeParent from "./jseModeParent.js";
4
-
5
- export default {
6
- ...oriHandler,
7
-
8
- async unpack(packed, options = {}) {
9
- const parent = getParent(packed, options);
10
- return oriHandler.unpack(packed, {
11
- ...options,
12
- mode: "jse",
13
- parent: await jseModeParent(parent),
14
- });
15
- },
16
- };
@@ -1,30 +0,0 @@
1
- import { FileTree, ObjectTree } from "@weborigami/async-tree";
2
-
3
- let builtinsNew;
4
-
5
- // Adapt the existing parent chain to use the new builtins
6
- export default async function jseModeParent(parent) {
7
- builtinsNew ??= (await import("../builtinsNew.js")).default;
8
- return cloneParent(parent);
9
- }
10
-
11
- function cloneParent(parent) {
12
- let clone;
13
- // We expect the parent to be a FileTree (or a subclass), ObjectTree (or a
14
- // subclass), or builtins.
15
- if (!parent) {
16
- return null;
17
- } else if (parent instanceof FileTree) {
18
- clone = Reflect.construct(parent.constructor, [parent.path]);
19
- } else if (parent instanceof ObjectTree) {
20
- clone = Reflect.construct(parent.constructor, [parent.object]);
21
- } else if (!parent.parent) {
22
- // Builtins
23
- clone = builtinsNew;
24
- } else {
25
- // Maybe a map? Skip it and hope for the best.
26
- return cloneParent(parent.parent);
27
- }
28
- clone.parent = cloneParent(parent.parent);
29
- return clone;
30
- }
@@ -1,16 +0,0 @@
1
- import { oridocumentHandler } from "../internal.js";
2
- import getParent from "./getParent.js";
3
- import jseModeParent from "./jseModeParent.js";
4
-
5
- export default {
6
- ...oridocumentHandler,
7
-
8
- async unpack(packed, options = {}) {
9
- const parent = getParent(packed, options);
10
- return oridocumentHandler.unpack(packed, {
11
- ...options,
12
- mode: "jse",
13
- parent: await jseModeParent(parent),
14
- });
15
- },
16
- };