@weborigami/origami 0.2.7 → 0.2.8
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/package.json +4 -4
- package/src/builtins.js +0 -4
- package/src/handlers/oridocument.handler.js +12 -1
- package/src/tree/map.js +1 -34
- package/src/tree/mapFn.js +1 -34
- package/src/tree/parseExtensions.js +43 -0
- package/src/deprecated.js +0 -140
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"typescript": "5.7.2"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@weborigami/async-tree": "0.2.
|
|
21
|
-
"@weborigami/language": "0.2.
|
|
22
|
-
"@weborigami/types": "0.2.
|
|
20
|
+
"@weborigami/async-tree": "0.2.8",
|
|
21
|
+
"@weborigami/language": "0.2.8",
|
|
22
|
+
"@weborigami/types": "0.2.8",
|
|
23
23
|
"exif-parser": "0.1.12",
|
|
24
24
|
"graphviz-wasm": "3.0.2",
|
|
25
25
|
"highlight.js": "11.11.0",
|
package/src/builtins.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as calc from "./calc/calc.js";
|
|
2
|
-
import deprecated from "./deprecated.js";
|
|
3
2
|
import * as dev from "./dev/dev.js";
|
|
4
3
|
import * as handlers from "./handlers/handlers.js";
|
|
5
4
|
import help from "./help/help.js";
|
|
@@ -46,9 +45,6 @@ export default {
|
|
|
46
45
|
|
|
47
46
|
// Some builtins need to be exposed at top level
|
|
48
47
|
...handlers.default,
|
|
49
|
-
|
|
50
|
-
// Deprecated builtins
|
|
51
|
-
...deprecated,
|
|
52
48
|
};
|
|
53
49
|
|
|
54
50
|
// Handle cases where a builtin name conflicts with a JS reserved word
|
|
@@ -40,6 +40,7 @@ export default {
|
|
|
40
40
|
let text;
|
|
41
41
|
let frontData = null;
|
|
42
42
|
let frontSource = null;
|
|
43
|
+
let offset = 0;
|
|
43
44
|
let extendedParent = parent;
|
|
44
45
|
const parsed = parseFrontMatter(unpacked);
|
|
45
46
|
if (!parsed) {
|
|
@@ -58,11 +59,21 @@ export default {
|
|
|
58
59
|
extendedParent = new ObjectTree(frontData);
|
|
59
60
|
extendedParent.parent = parent;
|
|
60
61
|
}
|
|
62
|
+
|
|
63
|
+
// Determine how many lines the source code is offset by (if any) to
|
|
64
|
+
// account for front matter, plus 2 lines for `---` separators
|
|
65
|
+
offset = (frontText.match(/\r?\n/g) ?? []).length + 2;
|
|
66
|
+
|
|
61
67
|
text = body;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
// Construct an object to represent the source code
|
|
65
|
-
const bodySource = {
|
|
71
|
+
const bodySource = {
|
|
72
|
+
name: key,
|
|
73
|
+
offset,
|
|
74
|
+
text,
|
|
75
|
+
url,
|
|
76
|
+
};
|
|
66
77
|
|
|
67
78
|
// Compile the source as an Origami template document
|
|
68
79
|
const scopeCaching = frontSource ? false : true;
|
package/src/tree/map.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from "@weborigami/async-tree";
|
|
8
8
|
import getTreeArgument from "../common/getTreeArgument.js";
|
|
9
9
|
import { toFunction } from "../common/utilities.js";
|
|
10
|
+
import parseExtensions from "./parseExtensions.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Map a hierarchical tree of keys and values to a new tree of keys and values.
|
|
@@ -142,37 +143,3 @@ function extendKeyFn(keyFn) {
|
|
|
142
143
|
return resultKey;
|
|
143
144
|
};
|
|
144
145
|
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Given a string specifying an extension or a mapping of one extension to another,
|
|
148
|
-
* return the source and result extensions.
|
|
149
|
-
*
|
|
150
|
-
* Syntax:
|
|
151
|
-
* foo
|
|
152
|
-
* foo→bar Unicode Rightwards Arrow
|
|
153
|
-
* foo->bar hyphen and greater-than sign
|
|
154
|
-
*
|
|
155
|
-
* @param {string} specifier
|
|
156
|
-
*/
|
|
157
|
-
function parseExtensions(specifier) {
|
|
158
|
-
const lowercase = specifier?.toLowerCase() ?? "";
|
|
159
|
-
const extensionRegex =
|
|
160
|
-
/^((?<sourceExtension>\.?\S*)\s*(→|->)\s*(?<resultExtension>\.?\S*))|(?<extension>\.?\S*)$/;
|
|
161
|
-
const match = lowercase.match(extensionRegex);
|
|
162
|
-
if (!match) {
|
|
163
|
-
// Shouldn't happen because the regex is exhaustive.
|
|
164
|
-
throw new Error(`map: Invalid extension specifier "${specifier}".`);
|
|
165
|
-
}
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
const { extension, resultExtension, sourceExtension } = match.groups;
|
|
168
|
-
if (extension) {
|
|
169
|
-
// foo
|
|
170
|
-
return {
|
|
171
|
-
resultExtension: extension,
|
|
172
|
-
sourceExtension: extension,
|
|
173
|
-
};
|
|
174
|
-
} else {
|
|
175
|
-
// foo→bar
|
|
176
|
-
return { resultExtension, sourceExtension };
|
|
177
|
-
}
|
|
178
|
-
}
|
package/src/tree/mapFn.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@weborigami/async-tree";
|
|
7
7
|
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
8
8
|
import { toFunction } from "../common/utilities.js";
|
|
9
|
+
import parseExtensions from "./parseExtensions.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Return a function that transforms a tree of keys and values to a new tree of
|
|
@@ -123,37 +124,3 @@ export default function mapFnBuiltin(operation) {
|
|
|
123
124
|
return mapped;
|
|
124
125
|
};
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Given a string specifying an extension or a mapping of one extension to another,
|
|
129
|
-
* return the source and result extensions.
|
|
130
|
-
*
|
|
131
|
-
* Syntax:
|
|
132
|
-
* foo
|
|
133
|
-
* foo→bar Unicode Rightwards Arrow
|
|
134
|
-
* foo->bar hyphen and greater-than sign
|
|
135
|
-
*
|
|
136
|
-
* @param {string} specifier
|
|
137
|
-
*/
|
|
138
|
-
function parseExtensions(specifier) {
|
|
139
|
-
const lowercase = specifier?.toLowerCase() ?? "";
|
|
140
|
-
const extensionRegex =
|
|
141
|
-
/^(\.?(?<sourceExtension>\S*)\s*(→|->)\s*\.?(?<resultExtension>\S*))|(\.?(?<extension>\S*))$/;
|
|
142
|
-
const match = lowercase.match(extensionRegex);
|
|
143
|
-
if (!match) {
|
|
144
|
-
// Shouldn't happen because the regex is exhaustive.
|
|
145
|
-
throw new Error(`@mapFn: Invalid extension specifier "${specifier}".`);
|
|
146
|
-
}
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
const { extension, resultExtension, sourceExtension } = match.groups;
|
|
149
|
-
if (sourceExtension || resultExtension) {
|
|
150
|
-
// foo→bar
|
|
151
|
-
return { resultExtension, sourceExtension };
|
|
152
|
-
} else {
|
|
153
|
-
// foo
|
|
154
|
-
return {
|
|
155
|
-
resultExtension: specifier,
|
|
156
|
-
sourceExtension: specifier,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a string specifying an extension or a mapping of one extension to another,
|
|
3
|
+
* return the source and result extensions.
|
|
4
|
+
*
|
|
5
|
+
* Syntax:
|
|
6
|
+
* .foo source and result extension are the same
|
|
7
|
+
* .foo→.bar Unicode Rightwards Arrow
|
|
8
|
+
* .foo→ Unicode Rightwards Arrow, no result extension
|
|
9
|
+
* .foo->.bar hyphen and greater-than sign
|
|
10
|
+
*
|
|
11
|
+
* @param {string} specifier
|
|
12
|
+
*/
|
|
13
|
+
export default function parseExtensions(specifier) {
|
|
14
|
+
const lowercase = specifier?.toLowerCase() ?? "";
|
|
15
|
+
const extensionRegex =
|
|
16
|
+
/^((?<sourceExtension>\/|\.\S*)?\s*(→|->)\s*(?<resultExtension>\/|\.\S*)?)|(?<extension>\/|\.\S*)$/;
|
|
17
|
+
const match = lowercase.match(extensionRegex);
|
|
18
|
+
if (!match) {
|
|
19
|
+
throw new Error(`Invalid file extension specifier "${specifier}".`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
let { extension, resultExtension, sourceExtension } = match.groups;
|
|
24
|
+
if (extension) {
|
|
25
|
+
// foo
|
|
26
|
+
return {
|
|
27
|
+
resultExtension: extension,
|
|
28
|
+
sourceExtension: extension,
|
|
29
|
+
};
|
|
30
|
+
} else {
|
|
31
|
+
// foo→bar
|
|
32
|
+
|
|
33
|
+
if (resultExtension === undefined && sourceExtension === undefined) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`A file extension mapping must indicate a source or result extension: "${specifier}".`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
resultExtension ??= "";
|
|
40
|
+
sourceExtension ??= "";
|
|
41
|
+
return { resultExtension, sourceExtension };
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/deprecated.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Tree } from "@weborigami/async-tree";
|
|
2
|
-
import * as calc from "./calc/calc.js";
|
|
3
|
-
import * as dev from "./dev/dev.js";
|
|
4
|
-
import * as image from "./image/image.js";
|
|
5
|
-
import js from "./js.js";
|
|
6
|
-
import node from "./node.js";
|
|
7
|
-
import * as origami from "./origami/origami.js";
|
|
8
|
-
import files from "./protocols/files.js";
|
|
9
|
-
import * as site from "./site/site.js";
|
|
10
|
-
import * as text from "./text/text.js";
|
|
11
|
-
import * as tree from "./tree/tree.js";
|
|
12
|
-
|
|
13
|
-
const warningsDisplayedForKeys = new Set();
|
|
14
|
-
|
|
15
|
-
export function command(namespace, newKey, oldKey, fn) {
|
|
16
|
-
const wrappedFn = function (...args) {
|
|
17
|
-
const keys = newKey
|
|
18
|
-
? `"${namespace}${newKey}" or just "${newKey}"`
|
|
19
|
-
: `"${namespace}"`;
|
|
20
|
-
if (!warningsDisplayedForKeys.has(oldKey)) {
|
|
21
|
-
console.warn(
|
|
22
|
-
`ori: Warning: "${oldKey}" is deprecated. Use ${keys} instead.`
|
|
23
|
-
);
|
|
24
|
-
warningsDisplayedForKeys.add(oldKey);
|
|
25
|
-
}
|
|
26
|
-
return fn instanceof Function
|
|
27
|
-
? // @ts-ignore
|
|
28
|
-
fn.call(this, ...args)
|
|
29
|
-
: Tree.traverseOrThrow(fn, ...args);
|
|
30
|
-
};
|
|
31
|
-
if (fn.key) {
|
|
32
|
-
wrappedFn.key = fn.key;
|
|
33
|
-
}
|
|
34
|
-
if (fn.inverseKey) {
|
|
35
|
-
wrappedFn.inverseKey = fn.inverseKey;
|
|
36
|
-
}
|
|
37
|
-
return wrappedFn;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function commands(namespace, object) {
|
|
41
|
-
const deprecatedEntries = Object.entries(object).map(([key, fn]) => [
|
|
42
|
-
`@${fn.key ?? key}`,
|
|
43
|
-
command(namespace, fn.key ?? key, `@${fn.key ?? key}`, fn),
|
|
44
|
-
]);
|
|
45
|
-
return Object.fromEntries(deprecatedEntries);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default {
|
|
49
|
-
...commands("calc:", calc),
|
|
50
|
-
...commands("dev:", dev),
|
|
51
|
-
"@false": command("js:", "false", "@false", js.false),
|
|
52
|
-
"@fetch": command("js:", "fetch", "@fetch", js.fetch),
|
|
53
|
-
"@files": command("files:", null, "@files/", files),
|
|
54
|
-
"@image": command("image:", null, "@image/", image),
|
|
55
|
-
"@js": command("js:", null, "@js/", js),
|
|
56
|
-
"@math": command("calc:", null, "@math/", calc),
|
|
57
|
-
"@mdHtml": command("text:", "mdHtml", "@mdHtml", text.mdHtml),
|
|
58
|
-
"@node": command("node:", null, "@node/", node),
|
|
59
|
-
...commands("origami:", origami),
|
|
60
|
-
...commands("site:", site),
|
|
61
|
-
...commands("text:", text),
|
|
62
|
-
...commands("tree:", tree),
|
|
63
|
-
"@tree": command("tree:", null, "@tree/", Tree),
|
|
64
|
-
"@true": command("js:", "true", "@true", js.true),
|
|
65
|
-
|
|
66
|
-
// Renamed commands
|
|
67
|
-
"@clean": command("tree:", "clear", "@clean", tree.clear),
|
|
68
|
-
|
|
69
|
-
// Deprecated commands
|
|
70
|
-
"@deepTakeFn": command(
|
|
71
|
-
"tree:",
|
|
72
|
-
"deepTake",
|
|
73
|
-
"@deepTakeFn",
|
|
74
|
-
(options) =>
|
|
75
|
-
/** @this {any} */
|
|
76
|
-
function (treelike) {
|
|
77
|
-
return tree.deepTake.call(this, treelike, options);
|
|
78
|
-
}
|
|
79
|
-
),
|
|
80
|
-
"@deepMapFn": command(
|
|
81
|
-
"tree:",
|
|
82
|
-
"deepMap",
|
|
83
|
-
"@deepMapFn",
|
|
84
|
-
(options) =>
|
|
85
|
-
/** @this {any} */
|
|
86
|
-
function (treelike) {
|
|
87
|
-
return tree.deepMap.call(this, treelike, options);
|
|
88
|
-
}
|
|
89
|
-
),
|
|
90
|
-
"@groupFn": command(
|
|
91
|
-
"tree:",
|
|
92
|
-
"group",
|
|
93
|
-
"@groupFn",
|
|
94
|
-
(options) =>
|
|
95
|
-
/** @this {any} */
|
|
96
|
-
function (treelike) {
|
|
97
|
-
return tree.group.call(this, treelike, options);
|
|
98
|
-
}
|
|
99
|
-
),
|
|
100
|
-
"@mapFn": command(
|
|
101
|
-
"tree:",
|
|
102
|
-
"map",
|
|
103
|
-
"@mapFn",
|
|
104
|
-
(options) =>
|
|
105
|
-
/** @this {any} */
|
|
106
|
-
function (treelike) {
|
|
107
|
-
return tree.map.call(this, treelike, options);
|
|
108
|
-
}
|
|
109
|
-
),
|
|
110
|
-
"@paginateFn": command(
|
|
111
|
-
"tree:",
|
|
112
|
-
"paginate",
|
|
113
|
-
"@paginateFn",
|
|
114
|
-
(options) =>
|
|
115
|
-
/** @this {any} */
|
|
116
|
-
function (treelike) {
|
|
117
|
-
return tree.paginate.call(this, treelike, options);
|
|
118
|
-
}
|
|
119
|
-
),
|
|
120
|
-
"@sortFn": command(
|
|
121
|
-
"tree:",
|
|
122
|
-
"sort",
|
|
123
|
-
"@sortFn",
|
|
124
|
-
(options) =>
|
|
125
|
-
/** @this {any} */
|
|
126
|
-
function (treelike) {
|
|
127
|
-
return tree.sort.call(this, treelike, options);
|
|
128
|
-
}
|
|
129
|
-
),
|
|
130
|
-
"@takeFn": command(
|
|
131
|
-
"tree:",
|
|
132
|
-
"take",
|
|
133
|
-
"@takeFn",
|
|
134
|
-
(options) =>
|
|
135
|
-
/** @this {any} */
|
|
136
|
-
function (treelike) {
|
|
137
|
-
return tree.take.call(this, treelike, options);
|
|
138
|
-
}
|
|
139
|
-
),
|
|
140
|
-
};
|