@weborigami/origami 0.3.2 → 0.3.3-jse.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.
- package/main.js +0 -1
- package/package.json +4 -4
- package/src/builtins.js +0 -2
- package/src/builtinsNew.js +84 -0
- package/src/common/documentObject.js +7 -0
- package/src/handlers/handlers.js +5 -0
- package/src/handlers/jse.handler.js +16 -0
- package/src/handlers/jseModeParent.js +30 -0
- package/src/handlers/jsedocument.handler.js +16 -0
- package/src/handlers/ori.handler.js +2 -1
- package/src/handlers/oridocument.handler.js +2 -1
- package/src/handlers/txt.handler.js +9 -1
- package/src/internal.js +4 -0
- package/src/js.js +52 -11
- package/src/calc/calc.js +0 -81
package/main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3-jse.1",
|
|
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.
|
|
20
|
+
"@weborigami/async-tree": "0.3.3-jse.1",
|
|
21
21
|
"@weborigami/json-feed-to-rss": "1.0.0",
|
|
22
|
-
"@weborigami/language": "0.3.
|
|
23
|
-
"@weborigami/types": "0.3.
|
|
22
|
+
"@weborigami/language": "0.3.3-jse.1",
|
|
23
|
+
"@weborigami/types": "0.3.3-jse.1",
|
|
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,4 +1,3 @@
|
|
|
1
|
-
import * as calc from "./calc/calc.js";
|
|
2
1
|
import * as dev from "./dev/dev.js";
|
|
3
2
|
import * as handlers from "./handlers/handlers.js";
|
|
4
3
|
import help from "./help/help.js";
|
|
@@ -22,7 +21,6 @@ import * as tree from "./tree/tree.js";
|
|
|
22
21
|
|
|
23
22
|
/** @type {any} */
|
|
24
23
|
export default {
|
|
25
|
-
"calc:": adjustReservedWords(calc),
|
|
26
24
|
"dev:": dev,
|
|
27
25
|
"explore:": explore,
|
|
28
26
|
"files:": files,
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
});
|
|
@@ -37,6 +37,13 @@ export default async function documentObject(input, data) {
|
|
|
37
37
|
// };
|
|
38
38
|
// const result = Object.create(base);
|
|
39
39
|
const result = {};
|
|
40
|
+
// TODO: Deprecate @text
|
|
40
41
|
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
|
+
});
|
|
41
48
|
return result;
|
|
42
49
|
}
|
package/src/handlers/handlers.js
CHANGED
|
@@ -11,6 +11,8 @@ 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";
|
|
14
16
|
import jsonHandler from "./json.handler.js";
|
|
15
17
|
import mdHandler from "./md.handler.js";
|
|
16
18
|
import mjsHandler from "./mjs.handler.js";
|
|
@@ -27,6 +29,9 @@ export default {
|
|
|
27
29
|
"jpeg.handler": jpegHandler,
|
|
28
30
|
"jpg.handler": jpgHandler,
|
|
29
31
|
"js.handler": jsHandler,
|
|
32
|
+
"jse.handler": jseHandler,
|
|
33
|
+
"jsep.handler": jseHandler,
|
|
34
|
+
"jsedocument.handler": jseDocumentHandler,
|
|
30
35
|
"json.handler": jsonHandler,
|
|
31
36
|
"md.handler": mdHandler,
|
|
32
37
|
"mjs.handler": mjsHandler,
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -34,7 +34,8 @@ 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
|
|
37
|
+
const mode = options.mode ?? "shell";
|
|
38
|
+
const fn = compiler(source, { mode });
|
|
38
39
|
const target = parent ?? builtinsTree;
|
|
39
40
|
let content = await fn.call(target);
|
|
40
41
|
|
|
@@ -35,7 +35,8 @@ export default {
|
|
|
35
35
|
text,
|
|
36
36
|
url,
|
|
37
37
|
};
|
|
38
|
-
const
|
|
38
|
+
const mode = options.mode ?? "shell";
|
|
39
|
+
const defineFn = compile.templateDocument(source, { mode });
|
|
39
40
|
|
|
40
41
|
// Invoke the definition to get back the template function
|
|
41
42
|
const result = await defineFn.call(parent);
|
|
@@ -39,7 +39,8 @@ export default {
|
|
|
39
39
|
throw new TypeError("The input to pack must be a JavaScript object.");
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
// TODO: Deprecate @text
|
|
43
|
+
const text = object._body ?? object["@text"] ?? "";
|
|
43
44
|
|
|
44
45
|
/** @type {any} */
|
|
45
46
|
const dataWithoutText = Object.assign({}, object);
|
|
@@ -72,7 +73,14 @@ export default {
|
|
|
72
73
|
} else {
|
|
73
74
|
frontData = parseYaml(frontText);
|
|
74
75
|
}
|
|
76
|
+
// TODO: Deprecate @text
|
|
75
77
|
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
|
+
});
|
|
76
84
|
} else {
|
|
77
85
|
// Plain text
|
|
78
86
|
unpacked = new String(text);
|
package/src/internal.js
CHANGED
|
@@ -15,6 +15,10 @@ 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
|
+
|
|
18
22
|
export { default as processUnpackedContent } from "./common/processUnpackedContent.js";
|
|
19
23
|
|
|
20
24
|
export { default as wasmHandler } from "./handlers/wasm.handler.js";
|
package/src/js.js
CHANGED
|
@@ -1,38 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
*/
|
|
6
9
|
export default {
|
|
10
|
+
AggregateError,
|
|
7
11
|
Array,
|
|
12
|
+
ArrayBuffer,
|
|
13
|
+
Atomics,
|
|
8
14
|
BigInt,
|
|
15
|
+
BigInt64Array,
|
|
16
|
+
BigUint64Array,
|
|
9
17
|
Boolean,
|
|
18
|
+
DataView,
|
|
10
19
|
Date,
|
|
11
20
|
Error,
|
|
21
|
+
EvalError,
|
|
22
|
+
FinalizationRegistry,
|
|
23
|
+
Float32Array,
|
|
24
|
+
Float64Array,
|
|
25
|
+
Function,
|
|
12
26
|
Infinity,
|
|
27
|
+
Int16Array,
|
|
28
|
+
Int32Array,
|
|
29
|
+
Int8Array,
|
|
13
30
|
Intl,
|
|
31
|
+
// @ts-ignore Iterator does exist despite what TypeScript thinks
|
|
32
|
+
Iterator,
|
|
14
33
|
JSON,
|
|
15
34
|
Map,
|
|
16
35
|
Math,
|
|
17
36
|
NaN,
|
|
18
37
|
Number,
|
|
19
38
|
Object,
|
|
39
|
+
Promise,
|
|
40
|
+
Proxy,
|
|
41
|
+
RangeError,
|
|
42
|
+
ReferenceError,
|
|
43
|
+
Reflect,
|
|
20
44
|
RegExp,
|
|
21
|
-
Response,
|
|
22
45
|
Set,
|
|
46
|
+
SharedArrayBuffer,
|
|
23
47
|
String,
|
|
24
48
|
Symbol,
|
|
49
|
+
SyntaxError,
|
|
50
|
+
TypeError,
|
|
51
|
+
URIError,
|
|
52
|
+
Uint16Array,
|
|
53
|
+
Uint32Array,
|
|
54
|
+
Uint8Array,
|
|
55
|
+
Uint8ClampedArray,
|
|
56
|
+
WeakMap,
|
|
57
|
+
WeakRef,
|
|
58
|
+
WeakSet,
|
|
25
59
|
decodeURI,
|
|
26
60
|
decodeURIComponent,
|
|
27
61
|
encodeURI,
|
|
28
62
|
encodeURIComponent,
|
|
29
|
-
|
|
30
|
-
|
|
63
|
+
eval,
|
|
64
|
+
false: false, // treat like a global
|
|
65
|
+
fetch: fetchWrapper, // special case
|
|
66
|
+
globalThis,
|
|
31
67
|
isFinite,
|
|
32
68
|
isNaN,
|
|
33
|
-
null: null,
|
|
69
|
+
null: null, // treat like a global
|
|
34
70
|
parseFloat,
|
|
35
71
|
parseInt,
|
|
36
|
-
true: true,
|
|
37
|
-
undefined
|
|
72
|
+
true: true, // treat like a global
|
|
73
|
+
undefined,
|
|
38
74
|
};
|
|
75
|
+
|
|
76
|
+
async function fetchWrapper(resource, options) {
|
|
77
|
+
const response = await fetch(resource, options);
|
|
78
|
+
return response.ok ? await response.arrayBuffer() : undefined;
|
|
79
|
+
}
|
package/src/calc/calc.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
}
|