@weborigami/origami 0.0.46 → 0.0.47
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/exports/buildExports.js +2 -2
- package/exports/exports.js +16 -16
- package/package.json +11 -13
- package/src/builtins/@config.js +12 -5
- package/src/builtins/@crawl.js +3 -3
- package/src/builtins/@debug.js +9 -2
- package/src/builtins/@document.js +3 -5
- package/src/builtins/@fnTree.js +5 -2
- package/src/builtins/@inline.js +18 -25
- package/src/builtins/@inners.js +1 -3
- package/src/builtins/@invoke.js +2 -1
- package/src/builtins/@json.js +0 -3
- package/src/builtins/@keysJson.js +1 -4
- package/src/builtins/@mdHtml.js +8 -8
- package/src/builtins/@project.js +22 -14
- package/src/builtins/@shuffle.js +1 -6
- package/src/builtins/@sitemap.js +2 -2
- package/src/builtins/@sort.js +1 -4
- package/src/builtins/@static.js +1 -3
- package/src/builtins/@tree.js +1 -4
- package/src/builtins/@yaml.js +0 -3
- package/src/builtins/css_handler.js +7 -0
- package/src/builtins/htm_handler.js +2 -0
- package/src/builtins/html_handler.js +7 -0
- package/src/builtins/jpeg_handler.js +58 -0
- package/src/builtins/jpg_handler.js +2 -0
- package/src/builtins/js_handler.js +20 -0
- package/src/builtins/json_handler.js +19 -0
- package/src/builtins/md_handler.js +7 -0
- package/src/builtins/mjs_handler.js +2 -0
- package/src/builtins/ori_handler.js +48 -0
- package/src/builtins/txt_handler.js +78 -0
- package/src/builtins/wasm_handler.js +17 -0
- package/src/builtins/xhtml_handler.js +2 -0
- package/src/builtins/yaml_handler.js +29 -0
- package/src/builtins/yml_handler.js +2 -0
- package/src/common/ExplorableSiteTransform.js +5 -1
- package/src/common/addValueKeyToScope.js +3 -2
- package/src/common/documentObject.js +33 -0
- package/src/common/serialize.d.ts +1 -0
- package/src/common/serialize.js +68 -27
- package/src/common/utilities.js +9 -7
- package/src/misc/getTreeArgument.js +12 -2
- package/src/server/constructResponse.js +18 -5
- package/src/server/server.js +5 -4
- package/src/builtins/@loaders/css.js +0 -2
- package/src/builtins/@loaders/htm.js +0 -2
- package/src/builtins/@loaders/html.js +0 -2
- package/src/builtins/@loaders/jpeg.js +0 -55
- package/src/builtins/@loaders/jpg.js +0 -2
- package/src/builtins/@loaders/js.js +0 -14
- package/src/builtins/@loaders/json.js +0 -14
- package/src/builtins/@loaders/md.js +0 -2
- package/src/builtins/@loaders/mjs.js +0 -2
- package/src/builtins/@loaders/ori.js +0 -45
- package/src/builtins/@loaders/txt.js +0 -37
- package/src/builtins/@loaders/wasm.js +0 -11
- package/src/builtins/@loaders/xhtml.js +0 -2
- package/src/builtins/@loaders/yaml.js +0 -23
- package/src/builtins/@loaders/yml.js +0 -2
- package/src/common/TextDocument.js +0 -58
|
@@ -1,55 +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
|
-
* Load Exif data from a JPEG file.
|
|
14
|
-
*
|
|
15
|
-
* @type {import("@weborigami/language").FileUnpackFunction}
|
|
16
|
-
*/
|
|
17
|
-
export default async function unpackJpeg(buffer, options) {
|
|
18
|
-
const parser = exifParser.create(buffer);
|
|
19
|
-
parser.enableTagNames(true);
|
|
20
|
-
parser.enableSimpleValues(true);
|
|
21
|
-
const parsed = await parser.parse();
|
|
22
|
-
|
|
23
|
-
// The exif-parser `enableSimpleValues` option should convert dates to
|
|
24
|
-
// JavaScript Date objects, but that doesn't seem to work. Ensure dates are
|
|
25
|
-
// Date objects.
|
|
26
|
-
const exif = parsed.tags;
|
|
27
|
-
for (const tag of exifDateTags) {
|
|
28
|
-
if (typeof exif[tag] === "number") {
|
|
29
|
-
exif[tag] = new Date(exif[tag] * 1000);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const result = {
|
|
34
|
-
height: parsed.imageSize.height,
|
|
35
|
-
width: parsed.imageSize.width,
|
|
36
|
-
exif,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// Promote some Exif properties to the top level.
|
|
40
|
-
const tagsToPromote = {
|
|
41
|
-
ImageDescription: "caption",
|
|
42
|
-
ModifyDate: "modified",
|
|
43
|
-
Orientation: "orientation",
|
|
44
|
-
};
|
|
45
|
-
for (const [tag, key] of Object.entries(tagsToPromote)) {
|
|
46
|
-
if (exif[tag] !== undefined) {
|
|
47
|
-
result[key] = exif[tag];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Add aspect ratio for use with `aspect-ratio` CSS.
|
|
52
|
-
result.aspectRatio = result.width / result.height;
|
|
53
|
-
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import processUnpackedContent from "../../common/processUnpackedContent.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Load a .js file as module's default export or exports.
|
|
5
|
-
*
|
|
6
|
-
* @type {import("@weborigami/language").FileUnpackFunction}
|
|
7
|
-
*/
|
|
8
|
-
export default async function unpackModule(input, options = {}) {
|
|
9
|
-
const { key, parent } = options;
|
|
10
|
-
if (parent && "import" in parent) {
|
|
11
|
-
const content = await /** @type {any} */ (parent).import?.(key);
|
|
12
|
-
return processUnpackedContent(content, parent);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as utilities from "../../common/utilities.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Load a file as JSON.
|
|
5
|
-
*
|
|
6
|
-
* @type {import("@weborigami/language").FileUnpackFunction}
|
|
7
|
-
*/
|
|
8
|
-
export default function unpackJson(input) {
|
|
9
|
-
const json = utilities.toString(input);
|
|
10
|
-
if (!json) {
|
|
11
|
-
throw new Error("Tried to parse something as JSON but it wasn't text.");
|
|
12
|
-
}
|
|
13
|
-
return JSON.parse(json);
|
|
14
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Scope, compile, symbols } from "@weborigami/language";
|
|
2
|
-
import processUnpackedContent from "../../common/processUnpackedContent.js";
|
|
3
|
-
import * as utilities from "../../common/utilities.js";
|
|
4
|
-
import builtins from "../@builtins.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Load and evaluate an Origami expression from a file.
|
|
8
|
-
*
|
|
9
|
-
* @type {import("@weborigami/language").FileUnpackFunction}
|
|
10
|
-
*/
|
|
11
|
-
export default async function unpackOrigamiExpression(
|
|
12
|
-
inputDocument,
|
|
13
|
-
options = {}
|
|
14
|
-
) {
|
|
15
|
-
const attachedData = options.attachedData;
|
|
16
|
-
const parent =
|
|
17
|
-
options.parent ??
|
|
18
|
-
/** @type {any} */ (inputDocument).parent ??
|
|
19
|
-
/** @type {any} */ (inputDocument)[symbols.parent];
|
|
20
|
-
|
|
21
|
-
// Construct an object to represent the source code.
|
|
22
|
-
const sourceName = options.key;
|
|
23
|
-
let url;
|
|
24
|
-
if (sourceName && parent?.url) {
|
|
25
|
-
let parentHref = parent.url.href;
|
|
26
|
-
if (!parentHref.endsWith("/")) {
|
|
27
|
-
parentHref += "/";
|
|
28
|
-
}
|
|
29
|
-
url = new URL(sourceName, parentHref);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const source = {
|
|
33
|
-
text: utilities.toString(inputDocument),
|
|
34
|
-
name: options.key,
|
|
35
|
-
url,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Compile the source code as an Origami expression and evaluate it.
|
|
39
|
-
const compiler = options.compiler ?? compile.expression;
|
|
40
|
-
const fn = compiler(source);
|
|
41
|
-
const parentScope = parent ? Scope.getScope(parent) : builtins;
|
|
42
|
-
let content = await fn.call(parentScope);
|
|
43
|
-
|
|
44
|
-
return processUnpackedContent(content, parent, attachedData);
|
|
45
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import TextDocument from "../../common/TextDocument.js";
|
|
2
|
-
import { evaluateYaml } from "../../common/serialize.js";
|
|
3
|
-
import * as utilities from "../../common/utilities.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Load a file as text document with possible front matter.
|
|
7
|
-
*
|
|
8
|
-
* This process will parse out any YAML or JSON front matter and attach it to
|
|
9
|
-
* the document as data. The first line of the text must be "---", followed by a
|
|
10
|
-
* block of JSON or YAML, followed by another line of "---". Any lines following
|
|
11
|
-
* will be treated as the document text.
|
|
12
|
-
*
|
|
13
|
-
* Any Origami expressions in the front matter will be evaluated and the results
|
|
14
|
-
* incorporated into the document data.
|
|
15
|
-
*
|
|
16
|
-
* @type {import("@weborigami/language").FileUnpackFunction}
|
|
17
|
-
*/
|
|
18
|
-
export default async function unpackText(input, options = {}) {
|
|
19
|
-
const parent = options.parent ?? null;
|
|
20
|
-
const text = utilities.toString(input);
|
|
21
|
-
if (!text) {
|
|
22
|
-
throw new Error("Tried to treat something as text but it wasn't text.");
|
|
23
|
-
}
|
|
24
|
-
const regex =
|
|
25
|
-
/^(---\r?\n(?<frontText>[\s\S]*?\r?\n)---\r?\n)(?<body>[\s\S]*$)/;
|
|
26
|
-
const match = regex.exec(text);
|
|
27
|
-
|
|
28
|
-
const body = match?.groups?.body ?? text;
|
|
29
|
-
|
|
30
|
-
const frontData = match?.groups
|
|
31
|
-
? await evaluateYaml(match.groups.frontText, parent)
|
|
32
|
-
: null;
|
|
33
|
-
|
|
34
|
-
const object = Object.assign({}, frontData, { "@text": body });
|
|
35
|
-
|
|
36
|
-
return new TextDocument(object, options.parent);
|
|
37
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import processUnpackedContent from "../../common/processUnpackedContent.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Load a WebAssembly module and return its exports.
|
|
5
|
-
*
|
|
6
|
-
* @type {import("@weborigami/language").FileUnpackFunction}
|
|
7
|
-
*/
|
|
8
|
-
export default async function unpackWasm(buffer, options = {}) {
|
|
9
|
-
const wasmModule = await WebAssembly.instantiate(buffer);
|
|
10
|
-
return processUnpackedContent(wasmModule.instance.exports, options.parent);
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as YAMLModule from "yaml";
|
|
2
|
-
import processUnpackedContent from "../../common/processUnpackedContent.js";
|
|
3
|
-
import { evaluateYaml } from "../../common/serialize.js";
|
|
4
|
-
import * as utilities from "../../common/utilities.js";
|
|
5
|
-
|
|
6
|
-
// See notes at serialize.js
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const YAML = YAMLModule.default ?? YAMLModule.YAML;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Load a file as YAML.
|
|
12
|
-
*
|
|
13
|
-
* @type {import("@weborigami/language").FileUnpackFunction}
|
|
14
|
-
*/
|
|
15
|
-
export default async function unpackYaml(input, options = {}) {
|
|
16
|
-
const parent = options.parent ?? null;
|
|
17
|
-
const yaml = utilities.toString(input);
|
|
18
|
-
if (!yaml) {
|
|
19
|
-
throw new Error("Tried to parse something as YAML but it wasn't text.");
|
|
20
|
-
}
|
|
21
|
-
const data = await evaluateYaml(yaml, options.parent);
|
|
22
|
-
return processUnpackedContent(data, parent);
|
|
23
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { isStringLike } from "@weborigami/async-tree";
|
|
2
|
-
import { symbols } from "@weborigami/language";
|
|
3
|
-
import { toYaml } from "./serialize.js";
|
|
4
|
-
import * as utilities from "./utilities.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A text document is any object with a `@text` property and a `toString()`
|
|
8
|
-
* method that returns that text. This class is a helper for constructing such
|
|
9
|
-
* text documents.
|
|
10
|
-
*/
|
|
11
|
-
export default class TextDocument {
|
|
12
|
-
/**
|
|
13
|
-
* The `input` parameter can be anything that can be converted to a string.
|
|
14
|
-
* The optional `data` parameter can be any object; if the object is a plain
|
|
15
|
-
* object, its properties will be copied to the new document; otherwise, that
|
|
16
|
-
* parameter is ignored.
|
|
17
|
-
*
|
|
18
|
-
* @typedef {import("@weborigami/types").AsyncTree|null} AsyncTree
|
|
19
|
-
*
|
|
20
|
-
* @param {any} [data]
|
|
21
|
-
* @param {AsyncTree} [parent]
|
|
22
|
-
*/
|
|
23
|
-
constructor(data, parent) {
|
|
24
|
-
Object.assign(this, data);
|
|
25
|
-
if (parent) {
|
|
26
|
-
this[symbols.parent] = parent;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static from(input, parent) {
|
|
31
|
-
if (input["@text"]) {
|
|
32
|
-
return input;
|
|
33
|
-
} else if (isStringLike(input)) {
|
|
34
|
-
const text = utilities.toString(input);
|
|
35
|
-
return new TextDocument({ "@text": text }, parent);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Render the text and data as a document with YAML front matter.
|
|
41
|
-
*/
|
|
42
|
-
async pack() {
|
|
43
|
-
const text = this["@text"];
|
|
44
|
-
/** @type {any} */
|
|
45
|
-
const dataWithoutText = Object.assign({}, this);
|
|
46
|
-
delete dataWithoutText["@text"];
|
|
47
|
-
if (Object.keys(dataWithoutText).length > 0) {
|
|
48
|
-
const frontMatter = (await toYaml(dataWithoutText)).trimEnd();
|
|
49
|
-
return `---\n${frontMatter}\n---\n${text}`;
|
|
50
|
-
} else {
|
|
51
|
-
return text;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
toString() {
|
|
56
|
-
return this["@text"];
|
|
57
|
-
}
|
|
58
|
-
}
|