@weborigami/origami 0.5.5 → 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.
- package/main.js +2 -26
- package/package.json +4 -5
- package/src/cli/cli.js +10 -8
- package/src/common/documentObject.js +1 -1
- package/src/common/utilities.d.ts +0 -1
- package/src/common/utilities.js +1 -19
- package/src/dev/ExplorableSiteTransform.js +2 -2
- package/src/dev/OriCommandTransform.js +25 -7
- package/src/dev/explore.js +17 -40
- package/src/dev/help.yaml +4 -1
- package/src/dev/log.js +1 -1
- package/src/dev/svg.js +5 -5
- package/src/initializeBuiltins.js +23 -0
- package/src/origami/fetch.js +4 -8
- package/src/origami/indexPage.js +4 -4
- package/src/origami/inline.js +3 -4
- package/src/origami/jsonParse.js +1 -1
- package/src/origami/mdHtml.js +3 -7
- package/src/origami/mdOutline.js +3 -3
- package/src/origami/ori.js +16 -24
- package/src/origami/origami.js +0 -2
- package/src/origami/sitemap.js +2 -2
- package/src/origami/static.js +2 -2
- package/src/origami/string.js +1 -10
- package/src/origami/yaml.js +1 -5
- package/src/origami/yamlParse.js +1 -1
- package/src/server/constructResponse.js +1 -1
- package/src/server/server.js +6 -26
- package/src/builtinsProgram.js +0 -56
- package/src/builtinsShell.js +0 -18
- package/src/cli/getConfig.js +0 -11
- package/src/common/constructHref.js +0 -20
- package/src/common/constructSiteTree.js +0 -34
- package/src/common/fetchAndHandleExtension.js +0 -27
- package/src/handlers/css.handler.js +0 -7
- package/src/handlers/csv.handler.js +0 -129
- package/src/handlers/handlerBuiltins.js +0 -27
- package/src/handlers/handlers.js +0 -33
- package/src/handlers/htm.handler.js +0 -2
- package/src/handlers/html.handler.js +0 -7
- package/src/handlers/jpeg.handler.js +0 -62
- package/src/handlers/jpg.handler.js +0 -2
- package/src/handlers/js.handler.js +0 -20
- package/src/handlers/json.handler.js +0 -27
- package/src/handlers/md.handler.js +0 -7
- package/src/handlers/mjs.handler.js +0 -2
- package/src/handlers/ori.handler.js +0 -55
- package/src/handlers/oridocument.handler.js +0 -78
- package/src/handlers/parseFrontMatter.js +0 -16
- package/src/handlers/processUnpackedContent.js +0 -35
- package/src/handlers/ts.handler.js +0 -1
- package/src/handlers/txt.handler.js +0 -91
- package/src/handlers/wasm.handler.js +0 -17
- package/src/handlers/xhtml.handler.js +0 -2
- package/src/handlers/yaml.handler.js +0 -36
- package/src/handlers/yml.handler.js +0 -2
- package/src/origami/config.js +0 -18
- package/src/origami/project.js +0 -111
- package/src/protocols/explore.js +0 -17
- package/src/protocols/files.js +0 -31
- package/src/protocols/http.js +0 -18
- package/src/protocols/https.js +0 -18
- package/src/protocols/httpstree.js +0 -17
- package/src/protocols/httptree.js +0 -17
- package/src/protocols/node.js +0 -13
- package/src/protocols/package.js +0 -70
package/src/origami/yaml.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
/** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
|
|
2
2
|
import { isUnpackable, toPlainValue } from "@weborigami/async-tree";
|
|
3
3
|
import YAML from "yaml";
|
|
4
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Render the object as text in YAML format.
|
|
8
7
|
*
|
|
9
|
-
* @this {AsyncTree|null}
|
|
10
8
|
* @param {any} [obj]
|
|
11
9
|
*/
|
|
12
|
-
export default async function
|
|
13
|
-
assertTreeIsDefined(this, "yaml");
|
|
10
|
+
export default async function yamlBuiltin(obj) {
|
|
14
11
|
// A fragment of the logic from getTreeArgument.js
|
|
15
12
|
if (arguments.length > 0 && obj === undefined) {
|
|
16
13
|
throw new Error(
|
|
17
14
|
"An Origami function was called with an initial argument, but its value is undefined."
|
|
18
15
|
);
|
|
19
16
|
}
|
|
20
|
-
obj = obj ?? this;
|
|
21
17
|
if (obj === undefined) {
|
|
22
18
|
return undefined;
|
|
23
19
|
}
|
package/src/origami/yamlParse.js
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
isPlainObject,
|
|
5
5
|
isStringlike,
|
|
6
6
|
SiteTree,
|
|
7
|
+
toString,
|
|
7
8
|
Tree,
|
|
8
9
|
} from "@weborigami/async-tree";
|
|
9
10
|
import * as serialize from "../common/serialize.js";
|
|
10
|
-
import { toString } from "../common/utilities.js";
|
|
11
11
|
import { mediaTypeForExtension } from "./mediaTypes.js";
|
|
12
12
|
|
|
13
13
|
/**
|
package/src/server/server.js
CHANGED
|
@@ -81,35 +81,15 @@ export async function handleRequest(request, response, tree) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
function keysFromUrl(url) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const parts = url.pathname.split(/\/!/);
|
|
87
|
-
|
|
88
|
-
// Split everything before the first command by slashes and decode those.
|
|
89
|
-
let path = parts.shift();
|
|
90
|
-
if (parts.length > 0) {
|
|
91
|
-
// HACK: Add back trailing slash that was removed by split
|
|
92
|
-
path += "/";
|
|
93
|
-
}
|
|
94
|
-
const pathKeys = keysFromPath(path).map((key) => decodeURIComponent(key));
|
|
95
|
-
if (parts.length > 0 && pathKeys.at(-1) === "") {
|
|
96
|
-
// HACK part 2: Remove empty string that was added for trailing slash
|
|
97
|
-
pathKeys.pop();
|
|
98
|
-
}
|
|
84
|
+
const encodedKeys = keysFromPath(url.pathname);
|
|
85
|
+
const keys = encodedKeys.map((key) => decodeURIComponent(key));
|
|
99
86
|
|
|
100
|
-
// If
|
|
101
|
-
//
|
|
102
|
-
if (
|
|
103
|
-
|
|
87
|
+
// If the path ends with a trailing slash, the final key will be an empty
|
|
88
|
+
// string. Change that to "index.html".
|
|
89
|
+
if (keys.at(-1) === "") {
|
|
90
|
+
keys[keys.length - 1] = "index.html";
|
|
104
91
|
}
|
|
105
92
|
|
|
106
|
-
// Decode the text of the commands, prefix spaces with a backslash, and add
|
|
107
|
-
// back the `!` character.
|
|
108
|
-
const commandKeys = parts.map(
|
|
109
|
-
(command) => `!${decodeURIComponent(command).replace(/ /g, "\\ ")}`
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const keys = [...pathKeys, ...commandKeys];
|
|
113
93
|
return keys;
|
|
114
94
|
}
|
|
115
95
|
|
package/src/builtinsProgram.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Tree } from "@weborigami/async-tree";
|
|
2
|
-
import { jsGlobals } from "@weborigami/language";
|
|
3
|
-
import * as dev from "./dev/dev.js";
|
|
4
|
-
import help from "./dev/help.js";
|
|
5
|
-
import handlerBuiltins from "./handlers/handlerBuiltins.js";
|
|
6
|
-
import * as origami from "./origami/origami.js";
|
|
7
|
-
import explore from "./protocols/explore.js";
|
|
8
|
-
import files from "./protocols/files.js";
|
|
9
|
-
import http from "./protocols/http.js";
|
|
10
|
-
import https from "./protocols/https.js";
|
|
11
|
-
import httpstree from "./protocols/httpstree.js";
|
|
12
|
-
import httptree from "./protocols/httptree.js";
|
|
13
|
-
import node from "./protocols/node.js";
|
|
14
|
-
import packageNamespace from "./protocols/package.js";
|
|
15
|
-
|
|
16
|
-
let builtins;
|
|
17
|
-
|
|
18
|
-
export default function builtinsProgram() {
|
|
19
|
-
if (!builtins) {
|
|
20
|
-
const Protocol = {
|
|
21
|
-
explore,
|
|
22
|
-
files,
|
|
23
|
-
http,
|
|
24
|
-
https,
|
|
25
|
-
httpstree,
|
|
26
|
-
httptree,
|
|
27
|
-
node,
|
|
28
|
-
package: packageNamespace,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/** @type {any} */
|
|
32
|
-
builtins = {
|
|
33
|
-
...jsGlobals,
|
|
34
|
-
|
|
35
|
-
"explore:": explore,
|
|
36
|
-
"files:": files,
|
|
37
|
-
"help:": help,
|
|
38
|
-
"http:": http,
|
|
39
|
-
"https:": https,
|
|
40
|
-
"httpstree:": httpstree,
|
|
41
|
-
"httptree:": httptree,
|
|
42
|
-
"node:": node,
|
|
43
|
-
"package:": packageNamespace,
|
|
44
|
-
|
|
45
|
-
Dev: dev,
|
|
46
|
-
Tree,
|
|
47
|
-
Origami: origami,
|
|
48
|
-
Protocol,
|
|
49
|
-
|
|
50
|
-
// Handlers need to be exposed at top level
|
|
51
|
-
...handlerBuiltins(),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return builtins;
|
|
56
|
-
}
|
package/src/builtinsShell.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import builtinsProgram from "./builtinsProgram.js";
|
|
2
|
-
import * as dev from "./dev/dev.js";
|
|
3
|
-
|
|
4
|
-
let builtins;
|
|
5
|
-
|
|
6
|
-
export default function builtinsShell() {
|
|
7
|
-
if (!builtins) {
|
|
8
|
-
builtins = {
|
|
9
|
-
// All program builtins
|
|
10
|
-
...builtinsProgram(),
|
|
11
|
-
|
|
12
|
-
// Dev builtins exposed at the top level in shell
|
|
13
|
-
...dev,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return builtins;
|
|
18
|
-
}
|
package/src/cli/getConfig.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { pathFromKeys } from "@weborigami/async-tree";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Given a protocol, a host, and a list of keys, construct an href.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} protocol
|
|
7
|
-
* @param {string} host
|
|
8
|
-
* @param {string[]} keys
|
|
9
|
-
*/
|
|
10
|
-
export default function constructHref(protocol, host, ...keys) {
|
|
11
|
-
const path = pathFromKeys(keys);
|
|
12
|
-
let href = [host, path].join("/");
|
|
13
|
-
if (!href.startsWith(protocol)) {
|
|
14
|
-
if (!href.startsWith("//")) {
|
|
15
|
-
href = `//${href}`;
|
|
16
|
-
}
|
|
17
|
-
href = `${protocol}${href}`;
|
|
18
|
-
}
|
|
19
|
-
return href;
|
|
20
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { trailingSlash } from "@weborigami/async-tree";
|
|
2
|
-
import { HandleExtensionsTransform } from "@weborigami/language";
|
|
3
|
-
import constructHref from "./constructHref.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Given a protocol, a host, and a list of keys, construct an href.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
*
|
|
10
|
-
* @param {string} protocol
|
|
11
|
-
* @param {import("../../index.ts").Constructor<AsyncTree>} treeClass
|
|
12
|
-
* @param {AsyncTree|null} parent
|
|
13
|
-
* @param {string} host
|
|
14
|
-
* @param {string[]} keys
|
|
15
|
-
*/
|
|
16
|
-
export default function constructSiteTree(
|
|
17
|
-
protocol,
|
|
18
|
-
treeClass,
|
|
19
|
-
parent,
|
|
20
|
-
host,
|
|
21
|
-
...keys
|
|
22
|
-
) {
|
|
23
|
-
// If the last key doesn't end in a slash, remove it for now.
|
|
24
|
-
let lastKey;
|
|
25
|
-
if (keys.length > 0 && keys.at(-1) && !trailingSlash.has(keys.at(-1))) {
|
|
26
|
-
lastKey = keys.pop();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const href = constructHref(protocol, host, ...keys);
|
|
30
|
-
let result = new (HandleExtensionsTransform(treeClass))(href);
|
|
31
|
-
result.parent = parent;
|
|
32
|
-
|
|
33
|
-
return lastKey ? result.get(lastKey) : result;
|
|
34
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { getHandlers, handleExtension } from "@weborigami/language";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Fetch the resource at the given href.
|
|
5
|
-
*
|
|
6
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
7
|
-
*
|
|
8
|
-
* @this {AsyncTree|null}
|
|
9
|
-
* @param {string} href
|
|
10
|
-
*/
|
|
11
|
-
export default async function fetchAndHandleExtension(href) {
|
|
12
|
-
const response = await fetch(href);
|
|
13
|
-
if (!response.ok) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
let buffer = await response.arrayBuffer();
|
|
17
|
-
|
|
18
|
-
// Attach any loader defined for the file type.
|
|
19
|
-
const url = new URL(href);
|
|
20
|
-
const filename = url.pathname.split("/").pop();
|
|
21
|
-
if (this && filename) {
|
|
22
|
-
const handlers = getHandlers(this);
|
|
23
|
-
buffer = await handleExtension(this, buffer, filename, handlers);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return buffer;
|
|
27
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { symbols, toString } from "@weborigami/async-tree";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
mediaType: "text/csv",
|
|
5
|
-
|
|
6
|
-
unpack(packed, options = {}) {
|
|
7
|
-
const parent = options.parent ?? null;
|
|
8
|
-
const text = toString(packed);
|
|
9
|
-
if (text === null) {
|
|
10
|
-
throw new TypeError("CSV handler can only unpack text");
|
|
11
|
-
}
|
|
12
|
-
const data = csvParse(text);
|
|
13
|
-
// Define `parent` as non-enumerable property
|
|
14
|
-
Object.defineProperty(data, symbols.parent, {
|
|
15
|
-
configurable: true,
|
|
16
|
-
enumerable: false,
|
|
17
|
-
value: parent,
|
|
18
|
-
writable: true,
|
|
19
|
-
});
|
|
20
|
-
return data;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Parse text as CSV following RFC 4180
|
|
26
|
-
*
|
|
27
|
-
* This assumes the presence of a header row, and accepts both CRLF and LF line
|
|
28
|
-
* endings.
|
|
29
|
-
*
|
|
30
|
-
* @param {string} text
|
|
31
|
-
* @returns {any[]}
|
|
32
|
-
*/
|
|
33
|
-
function csvParse(text) {
|
|
34
|
-
const rows = [];
|
|
35
|
-
let currentRow = [];
|
|
36
|
-
let currentField = "";
|
|
37
|
-
|
|
38
|
-
const pushField = () => {
|
|
39
|
-
// Push the completed field and reset for the next field.
|
|
40
|
-
currentRow.push(currentField);
|
|
41
|
-
currentField = "";
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const pushRow = () => {
|
|
45
|
-
// Push the row if there is at least one field (accounts for potential trailing newline)
|
|
46
|
-
rows.push(currentRow);
|
|
47
|
-
currentRow = [];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Main state machine
|
|
51
|
-
let i = 0;
|
|
52
|
-
let inQuotes = false;
|
|
53
|
-
while (i < text.length) {
|
|
54
|
-
const char = text[i];
|
|
55
|
-
|
|
56
|
-
if (inQuotes) {
|
|
57
|
-
// In a quoted field
|
|
58
|
-
if (char === '"') {
|
|
59
|
-
// Check if next character is also a quote
|
|
60
|
-
if (i + 1 < text.length && text[i + 1] === '"') {
|
|
61
|
-
// Append a literal double quote and skip the next character
|
|
62
|
-
currentField += '"';
|
|
63
|
-
i += 2;
|
|
64
|
-
continue;
|
|
65
|
-
} else {
|
|
66
|
-
// End of the quoted field
|
|
67
|
-
inQuotes = false;
|
|
68
|
-
i++;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
// All other characters within quotes are taken literally.
|
|
73
|
-
currentField += char;
|
|
74
|
-
i++;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
} else if (char === '"') {
|
|
78
|
-
// Start of a quoted field
|
|
79
|
-
inQuotes = true;
|
|
80
|
-
i++;
|
|
81
|
-
continue;
|
|
82
|
-
} else if (char === ",") {
|
|
83
|
-
// End of field
|
|
84
|
-
pushField();
|
|
85
|
-
i++;
|
|
86
|
-
continue;
|
|
87
|
-
} else if (char === "\n" || (char === "\r" && text[i + 1] === "\n")) {
|
|
88
|
-
// End of row: push the last field, then row.
|
|
89
|
-
pushField();
|
|
90
|
-
pushRow();
|
|
91
|
-
if (char === "\r" && text[i + 1] === "\n") {
|
|
92
|
-
i++; // Handle CRLF line endings
|
|
93
|
-
}
|
|
94
|
-
i++;
|
|
95
|
-
continue;
|
|
96
|
-
} else {
|
|
97
|
-
// Regular character
|
|
98
|
-
currentField += char;
|
|
99
|
-
i++;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Handle any remaining data after the loop.
|
|
105
|
-
// This will capture the last field/row if the text did not end with a newline.
|
|
106
|
-
if (inQuotes) {
|
|
107
|
-
// Mismatched quotes: you might choose to throw an error or handle it gracefully.
|
|
108
|
-
throw new Error("CSV parsing error: unmatched quote in the input.");
|
|
109
|
-
}
|
|
110
|
-
if (currentField !== "" || text.at(-1) === ",") {
|
|
111
|
-
pushField();
|
|
112
|
-
}
|
|
113
|
-
if (currentRow.length > 0) {
|
|
114
|
-
pushRow();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// The first row is assumed to be the header.
|
|
118
|
-
if (rows.length === 0) {
|
|
119
|
-
return [];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const header = rows.shift();
|
|
123
|
-
|
|
124
|
-
const data = rows.map((row) =>
|
|
125
|
-
Object.fromEntries(row.map((value, index) => [header[index], value]))
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
return data;
|
|
129
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as handlers from "./handlers.js";
|
|
2
|
-
|
|
3
|
-
export default function handlerBuiltins() {
|
|
4
|
-
return {
|
|
5
|
-
"css.handler": handlers.cssHandler,
|
|
6
|
-
"csv.handler": handlers.csvHandler,
|
|
7
|
-
"htm.handler": handlers.htmHandler,
|
|
8
|
-
"html.handler": handlers.htmlHandler,
|
|
9
|
-
"jpeg.handler": handlers.jpegHandler,
|
|
10
|
-
"jpg.handler": handlers.jpgHandler,
|
|
11
|
-
"js.handler": handlers.jsHandler,
|
|
12
|
-
// TODO: Remove deprecated JSE extensions
|
|
13
|
-
"jse.handler": handlers.oriHandler,
|
|
14
|
-
"jsedocument.handler": handlers.oridocumentHandler,
|
|
15
|
-
"json.handler": handlers.jsonHandler,
|
|
16
|
-
"md.handler": handlers.mdHandler,
|
|
17
|
-
"mjs.handler": handlers.mjsHandler,
|
|
18
|
-
"ori.handler": handlers.oriHandler,
|
|
19
|
-
"oridocument.handler": handlers.oridocumentHandler,
|
|
20
|
-
"ts.handler": handlers.tsHandler,
|
|
21
|
-
"txt.handler": handlers.txtHandler,
|
|
22
|
-
"wasm.handler": handlers.wasmHandler,
|
|
23
|
-
"xhtml.handler": handlers.xhtmlHandler,
|
|
24
|
-
"yaml.handler": handlers.yamlHandler,
|
|
25
|
-
"yml.handler": handlers.ymlHandler,
|
|
26
|
-
};
|
|
27
|
-
}
|
package/src/handlers/handlers.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// This library includes a number of modules with circular dependencies. This
|
|
3
|
-
// module exists to explicitly set the loading order for those modules. To
|
|
4
|
-
// enforce use of this loading order, other modules should only load the modules
|
|
5
|
-
// below via this module.
|
|
6
|
-
//
|
|
7
|
-
// About this pattern:
|
|
8
|
-
// https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de
|
|
9
|
-
//
|
|
10
|
-
// Note: to avoid having VS Code auto-sort the imports, keep lines between them.
|
|
11
|
-
|
|
12
|
-
export { default as jsHandler } from "./js.handler.js";
|
|
13
|
-
export { default as tsHandler } from "./ts.handler.js";
|
|
14
|
-
|
|
15
|
-
export { default as oriHandler } from "./ori.handler.js";
|
|
16
|
-
|
|
17
|
-
export { default as oridocumentHandler } from "./oridocument.handler.js";
|
|
18
|
-
|
|
19
|
-
export { default as txtHandler } from "./txt.handler.js";
|
|
20
|
-
|
|
21
|
-
export { default as cssHandler } from "./css.handler.js";
|
|
22
|
-
export { default as csvHandler } from "./csv.handler.js";
|
|
23
|
-
export { default as htmHandler } from "./htm.handler.js";
|
|
24
|
-
export { default as htmlHandler } from "./html.handler.js";
|
|
25
|
-
export { default as jpegHandler } from "./jpeg.handler.js";
|
|
26
|
-
export { default as jpgHandler } from "./jpg.handler.js";
|
|
27
|
-
export { default as jsonHandler } from "./json.handler.js";
|
|
28
|
-
export { default as mdHandler } from "./md.handler.js";
|
|
29
|
-
export { default as mjsHandler } from "./mjs.handler.js";
|
|
30
|
-
export { default as wasmHandler } from "./wasm.handler.js";
|
|
31
|
-
export { default as xhtmlHandler } from "./xhtml.handler.js";
|
|
32
|
-
export { default as yamlHandler } from "./yaml.handler.js";
|
|
33
|
-
export { default as ymlHandler } from "./yml.handler.js";
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import exifParser from "exif-parser";
|
|
2
|
-
|
|
3
|
-
const exifDateTags = [
|
|
4
|
-
"ModifyDate",
|
|
5
|
-
"MDPrepDate",
|
|
6
|
-
"DateTimeOriginal",
|
|
7
|
-
"CreateDate",
|
|
8
|
-
"PreviewDateTime",
|
|
9
|
-
"GPSDateStamp",
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A JPEG file with possible Exif metadata
|
|
14
|
-
*/
|
|
15
|
-
export default {
|
|
16
|
-
mediaType: "image/jpeg",
|
|
17
|
-
|
|
18
|
-
/** @type {import("@weborigami/async-tree").UnpackFunction} */
|
|
19
|
-
async unpack(packed, options) {
|
|
20
|
-
if (packed instanceof Uint8Array) {
|
|
21
|
-
// Downgrade to old Node Buffer for exif-parser.
|
|
22
|
-
packed = Buffer.from(packed);
|
|
23
|
-
}
|
|
24
|
-
const parser = exifParser.create(packed);
|
|
25
|
-
parser.enableTagNames(true);
|
|
26
|
-
parser.enableSimpleValues(true);
|
|
27
|
-
const parsed = await parser.parse();
|
|
28
|
-
|
|
29
|
-
// The exif-parser `enableSimpleValues` option should convert dates to
|
|
30
|
-
// JavaScript Date objects, but that doesn't seem to work. Ensure dates are
|
|
31
|
-
// Date objects.
|
|
32
|
-
const exif = parsed.tags;
|
|
33
|
-
for (const tag of exifDateTags) {
|
|
34
|
-
if (typeof exif[tag] === "number") {
|
|
35
|
-
exif[tag] = new Date(exif[tag] * 1000);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const result = {
|
|
40
|
-
height: parsed.imageSize.height,
|
|
41
|
-
width: parsed.imageSize.width,
|
|
42
|
-
exif,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// Promote some Exif properties to the top level.
|
|
46
|
-
const tagsToPromote = {
|
|
47
|
-
ImageDescription: "caption",
|
|
48
|
-
ModifyDate: "modified",
|
|
49
|
-
Orientation: "orientation",
|
|
50
|
-
};
|
|
51
|
-
for (const [tag, key] of Object.entries(tagsToPromote)) {
|
|
52
|
-
if (exif[tag] !== undefined) {
|
|
53
|
-
result[key] = exif[tag];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Add aspect ratio for use with `aspect-ratio` CSS.
|
|
58
|
-
result.aspectRatio = result.width / result.height;
|
|
59
|
-
|
|
60
|
-
return result;
|
|
61
|
-
},
|
|
62
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import processUnpackedContent from "./processUnpackedContent.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A JavaScript file
|
|
5
|
-
*
|
|
6
|
-
* Unpacking a JavaScript file returns its default export, or its set of exports
|
|
7
|
-
* if there is more than one.
|
|
8
|
-
*/
|
|
9
|
-
export default {
|
|
10
|
-
mediaType: "application/javascript",
|
|
11
|
-
|
|
12
|
-
/** @type {import("@weborigami/async-tree").UnpackFunction} */
|
|
13
|
-
async unpack(packed, options = {}) {
|
|
14
|
-
const { key, parent } = options;
|
|
15
|
-
if (parent && "import" in parent) {
|
|
16
|
-
const content = await /** @type {any} */ (parent).import?.(key);
|
|
17
|
-
return processUnpackedContent(content, parent);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { symbols } from "@weborigami/async-tree";
|
|
2
|
-
import * as utilities from "../common/utilities.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A JSON file
|
|
6
|
-
*
|
|
7
|
-
* Unpacking a JSON file returns the parsed data.
|
|
8
|
-
*/
|
|
9
|
-
export default {
|
|
10
|
-
mediaType: "application/json",
|
|
11
|
-
|
|
12
|
-
/** @type {import("@weborigami/async-tree").UnpackFunction} */
|
|
13
|
-
unpack(packed) {
|
|
14
|
-
const json = utilities.toString(packed);
|
|
15
|
-
if (!json) {
|
|
16
|
-
throw new Error("Tried to parse something as JSON but it wasn't text.");
|
|
17
|
-
}
|
|
18
|
-
const data = JSON.parse(json);
|
|
19
|
-
if (data && typeof data === "object" && Object.isExtensible(data)) {
|
|
20
|
-
Object.defineProperty(data, symbols.deep, {
|
|
21
|
-
enumerable: false,
|
|
22
|
-
value: true,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return data;
|
|
26
|
-
},
|
|
27
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { getParent } from "@weborigami/async-tree";
|
|
2
|
-
import { compile } from "@weborigami/language";
|
|
3
|
-
import builtinsProgram from "../builtinsProgram.js";
|
|
4
|
-
import getConfig from "../cli/getConfig.js";
|
|
5
|
-
import * as utilities from "../common/utilities.js";
|
|
6
|
-
import processUnpackedContent from "./processUnpackedContent.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* An Origami expression file
|
|
10
|
-
*
|
|
11
|
-
* Unpacking an Origami file returns the result of evaluating the expression.
|
|
12
|
-
*/
|
|
13
|
-
export default {
|
|
14
|
-
mediaType: "text/plain",
|
|
15
|
-
|
|
16
|
-
/** @type {import("@weborigami/async-tree").UnpackFunction} */
|
|
17
|
-
async unpack(packed, options = {}) {
|
|
18
|
-
const parent = getParent(packed, options);
|
|
19
|
-
|
|
20
|
-
// Construct an object to represent the source code.
|
|
21
|
-
const sourceName = options.key;
|
|
22
|
-
let url;
|
|
23
|
-
if (sourceName && /** @type {any} */ (parent)?.url) {
|
|
24
|
-
let parentHref = /** @type {any} */ (parent).url.href;
|
|
25
|
-
if (!parentHref.endsWith("/")) {
|
|
26
|
-
parentHref += "/";
|
|
27
|
-
}
|
|
28
|
-
url = new URL(sourceName, parentHref);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const source = {
|
|
32
|
-
text: utilities.toString(packed),
|
|
33
|
-
name: options.key,
|
|
34
|
-
url,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Compile the source code as an Origami program and evaluate it.
|
|
38
|
-
const compiler = options.compiler ?? compile.program;
|
|
39
|
-
|
|
40
|
-
const config = getConfig(parent) ?? {};
|
|
41
|
-
const globals = {
|
|
42
|
-
...(options.globals ?? builtinsProgram()),
|
|
43
|
-
...config,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const fn = compiler(source, {
|
|
47
|
-
globals,
|
|
48
|
-
mode: "program",
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
let result = await fn.call(parent);
|
|
52
|
-
|
|
53
|
-
return processUnpackedContent(result, parent);
|
|
54
|
-
},
|
|
55
|
-
};
|