@weborigami/origami 0.2.8 → 0.2.9
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 +9 -9
- package/src/image/resize.js +4 -2
- package/src/origami/regexMatch.js +6 -2
- package/src/site/index.js +4 -2
- package/src/tree/parseExtensions.js +1 -0
- package/src/tree/shuffle.js +33 -4
- package/src/image/resizeFn.js +0 -17
- package/src/origami/regexMatchFn.js +0 -9
- package/src/tree/ShuffleTransform.js +0 -29
- package/src/tree/mapFn.js +0 -126
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
"main": "./main.js",
|
|
14
14
|
"types": "./index.ts",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@types/node": "22.
|
|
17
|
-
"typescript": "5.
|
|
16
|
+
"@types/node": "22.13.5",
|
|
17
|
+
"typescript": "5.8.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.9",
|
|
21
|
+
"@weborigami/language": "0.2.9",
|
|
22
|
+
"@weborigami/types": "0.2.9",
|
|
23
23
|
"exif-parser": "0.1.12",
|
|
24
24
|
"graphviz-wasm": "3.0.2",
|
|
25
|
-
"highlight.js": "11.11.
|
|
26
|
-
"marked": "15.0.
|
|
25
|
+
"highlight.js": "11.11.1",
|
|
26
|
+
"marked": "15.0.7",
|
|
27
27
|
"marked-gfm-heading-id": "4.1.1",
|
|
28
28
|
"marked-highlight": "2.2.1",
|
|
29
29
|
"marked-smartypants": "1.1.9",
|
|
30
30
|
"sharp": "0.33.5",
|
|
31
|
-
"yaml": "2.
|
|
31
|
+
"yaml": "2.7.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"test": "node --test --test-reporter=spec",
|
package/src/image/resize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import sharp from "sharp";
|
|
1
2
|
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
2
|
-
import imageResizeFn from "./resizeFn.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Resize an image.
|
|
@@ -10,5 +10,7 @@ import imageResizeFn from "./resizeFn.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export default async function resize(input, options) {
|
|
12
12
|
assertTreeIsDefined(this, "image:resize");
|
|
13
|
-
return
|
|
13
|
+
return input instanceof Uint8Array || input instanceof ArrayBuffer
|
|
14
|
+
? sharp(input).rotate().resize(options).toBuffer()
|
|
15
|
+
: undefined;
|
|
14
16
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const parsers = {};
|
|
2
2
|
|
|
3
3
|
export default function regexMatch(text, regex) {
|
|
4
|
-
|
|
4
|
+
if (!parsers[regex]) {
|
|
5
|
+
const regexp = new RegExp(regex);
|
|
6
|
+
parsers[regex] = (input) => input.match(regexp)?.groups;
|
|
7
|
+
}
|
|
8
|
+
return parsers[regex](text);
|
|
5
9
|
}
|
package/src/site/index.js
CHANGED
|
@@ -8,8 +8,9 @@ import { getDescriptor } from "../common/utilities.js";
|
|
|
8
8
|
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
9
9
|
* @this {AsyncTree|null}
|
|
10
10
|
* @param {Treelike} [treelike]
|
|
11
|
+
* @param {string} [basePath]
|
|
11
12
|
*/
|
|
12
|
-
export default async function index(treelike) {
|
|
13
|
+
export default async function index(treelike, basePath) {
|
|
13
14
|
const tree = await getTreeArgument(this, arguments, treelike, "site:index");
|
|
14
15
|
const keys = Array.from(await tree.keys());
|
|
15
16
|
|
|
@@ -21,8 +22,9 @@ export default async function index(treelike) {
|
|
|
21
22
|
const links = [];
|
|
22
23
|
for (const key of filtered) {
|
|
23
24
|
const keyText = String(key);
|
|
25
|
+
const path = basePath ? [basePath, keyText].join("/") : keyText;
|
|
24
26
|
// Simple key.
|
|
25
|
-
const link = ` <li><a href="${
|
|
27
|
+
const link = ` <li><a href="${path}">${keyText}</a></li>`;
|
|
26
28
|
links.push(link);
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* .foo source and result extension are the same
|
|
7
7
|
* .foo→.bar Unicode Rightwards Arrow
|
|
8
8
|
* .foo→ Unicode Rightwards Arrow, no result extension
|
|
9
|
+
* →.bar Unicode Rightwards Arrow, no source extension
|
|
9
10
|
* .foo->.bar hyphen and greater-than sign
|
|
10
11
|
*
|
|
11
12
|
* @param {string} specifier
|
package/src/tree/shuffle.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import getTreeArgument from "../common/getTreeArgument.js";
|
|
2
|
-
import { transformObject } from "../common/utilities.js";
|
|
3
|
-
import { default as ShuffleTransform, shuffle } from "./ShuffleTransform.js";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Return a new tree with the original's keys shuffled
|
|
@@ -10,8 +8,9 @@ import { default as ShuffleTransform, shuffle } from "./ShuffleTransform.js";
|
|
|
10
8
|
*
|
|
11
9
|
* @this {AsyncTree|null}
|
|
12
10
|
* @param {Treelike} [treelike]
|
|
11
|
+
* @param {boolean} [reshuffle]
|
|
13
12
|
*/
|
|
14
|
-
export default async function shuffleTree(treelike) {
|
|
13
|
+
export default async function shuffleTree(treelike, reshuffle = false) {
|
|
15
14
|
// Special case: If the treelike is an array, shuffle it directly. Otherwise
|
|
16
15
|
// we'll end up shuffling the array's indexes, and if this is directly
|
|
17
16
|
// displayed by the ori CLI, this will end up creating a plain object. Even
|
|
@@ -23,6 +22,36 @@ export default async function shuffleTree(treelike) {
|
|
|
23
22
|
shuffle(array);
|
|
24
23
|
return array;
|
|
25
24
|
}
|
|
25
|
+
|
|
26
26
|
const tree = await getTreeArgument(this, arguments, treelike, "tree:shuffle");
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
let keys;
|
|
29
|
+
return {
|
|
30
|
+
async get(key) {
|
|
31
|
+
return tree.get(key);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
async keys() {
|
|
35
|
+
if (!keys || reshuffle) {
|
|
36
|
+
keys = Array.from(await tree.keys());
|
|
37
|
+
shuffle(keys);
|
|
38
|
+
}
|
|
39
|
+
return keys;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Shuffle an array.
|
|
46
|
+
*
|
|
47
|
+
* Performs a Fisher-Yates shuffle. From http://sedition.com/perl/javascript-fy.html
|
|
48
|
+
*/
|
|
49
|
+
export function shuffle(array) {
|
|
50
|
+
let i = array.length;
|
|
51
|
+
while (--i >= 0) {
|
|
52
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
53
|
+
const temp = array[i];
|
|
54
|
+
array[i] = array[j];
|
|
55
|
+
array[j] = temp;
|
|
56
|
+
}
|
|
28
57
|
}
|
package/src/image/resizeFn.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import sharp from "sharp";
|
|
2
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Return a function that resizes an image.
|
|
6
|
-
*
|
|
7
|
-
* @this {import("@weborigami/types").AsyncTree|null}
|
|
8
|
-
* @param {import("sharp").ResizeOptions} options
|
|
9
|
-
*/
|
|
10
|
-
export default function imageResizeFn(options) {
|
|
11
|
-
assertTreeIsDefined(this, "image/resizeFn");
|
|
12
|
-
// Include `rotate()` to auto-rotate according to EXIF data.
|
|
13
|
-
return (buffer) =>
|
|
14
|
-
buffer instanceof Uint8Array || buffer instanceof ArrayBuffer
|
|
15
|
-
? sharp(buffer).rotate().resize(options).toBuffer()
|
|
16
|
-
: undefined;
|
|
17
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
3
|
-
* @typedef {import("../../index.ts").Constructor<AsyncTree>} AsyncTreeConstructor
|
|
4
|
-
* @param {AsyncTreeConstructor} Base
|
|
5
|
-
*/
|
|
6
|
-
export default function ShuffleTransform(Base) {
|
|
7
|
-
return class Shuffle extends Base {
|
|
8
|
-
async keys() {
|
|
9
|
-
const keys = Array.from(await super.keys());
|
|
10
|
-
shuffle(keys);
|
|
11
|
-
return keys;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
* Shuffle an array.
|
|
18
|
-
*
|
|
19
|
-
* Performs a Fisher-Yates shuffle. From http://sedition.com/perl/javascript-fy.html
|
|
20
|
-
*/
|
|
21
|
-
export function shuffle(array) {
|
|
22
|
-
let i = array.length;
|
|
23
|
-
while (--i >= 0) {
|
|
24
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
25
|
-
const temp = array[i];
|
|
26
|
-
array[i] = array[j];
|
|
27
|
-
array[j] = temp;
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/tree/mapFn.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cachedKeyFunctions,
|
|
3
|
-
isPlainObject,
|
|
4
|
-
keyFunctionsForExtensions,
|
|
5
|
-
map,
|
|
6
|
-
} from "@weborigami/async-tree";
|
|
7
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
8
|
-
import { toFunction } from "../common/utilities.js";
|
|
9
|
-
import parseExtensions from "./parseExtensions.js";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Return a function that transforms a tree of keys and values to a new tree of
|
|
13
|
-
* keys and values.
|
|
14
|
-
*
|
|
15
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
16
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
17
|
-
* @typedef {import("@weborigami/async-tree").ValueKeyFn} ValueKeyFn
|
|
18
|
-
* @typedef {import("./map.js").TreeMapOptions} TreeMapOptions
|
|
19
|
-
*
|
|
20
|
-
* @this {AsyncTree|null}
|
|
21
|
-
* @param {ValueKeyFn|TreeMapOptions} operation
|
|
22
|
-
*/
|
|
23
|
-
export default function mapFnBuiltin(operation) {
|
|
24
|
-
assertTreeIsDefined(this, "map");
|
|
25
|
-
const tree = this;
|
|
26
|
-
|
|
27
|
-
// Identify whether the map instructions take the form of a value function or
|
|
28
|
-
// a dictionary of options.
|
|
29
|
-
/** @type {TreeMapOptions} */
|
|
30
|
-
let options;
|
|
31
|
-
/** @type {ValueKeyFn|undefined} */
|
|
32
|
-
let valueFn;
|
|
33
|
-
if (isPlainObject(operation)) {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
options = operation;
|
|
36
|
-
if (`value` in options && !options.value) {
|
|
37
|
-
throw new TypeError(`@mapFn: The value function is not defined.`);
|
|
38
|
-
}
|
|
39
|
-
valueFn = options?.value;
|
|
40
|
-
} else if (
|
|
41
|
-
typeof operation === "function" ||
|
|
42
|
-
typeof (/** @type {any} */ (operation)?.unpack) === "function"
|
|
43
|
-
) {
|
|
44
|
-
valueFn = operation;
|
|
45
|
-
options = {};
|
|
46
|
-
} else {
|
|
47
|
-
throw new TypeError(
|
|
48
|
-
`@mapFn: You must specify a value function or options dictionary as the first parameter.`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const { deep, extension, needsSourceValue } = options;
|
|
53
|
-
const description = options.description ?? `@mapFn ${extension ?? ""}`;
|
|
54
|
-
const keyFn = options.key;
|
|
55
|
-
const inverseKeyFn = options.inverseKey;
|
|
56
|
-
|
|
57
|
-
if (extension && (keyFn || inverseKeyFn)) {
|
|
58
|
-
throw new TypeError(
|
|
59
|
-
`@mapFn: You can't specify extensions and also a key or inverseKey function`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let extendedValueFn;
|
|
64
|
-
if (valueFn) {
|
|
65
|
-
const resolvedValueFn = toFunction(valueFn);
|
|
66
|
-
// Have the value function run in this tree.
|
|
67
|
-
extendedValueFn = resolvedValueFn.bind(tree);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Extend the key functions to run in this tree.
|
|
71
|
-
let extendedKeyFn;
|
|
72
|
-
let extendedInverseKeyFn;
|
|
73
|
-
if (extension) {
|
|
74
|
-
let { resultExtension, sourceExtension } = parseExtensions(extension);
|
|
75
|
-
const keyFns = keyFunctionsForExtensions({
|
|
76
|
-
resultExtension,
|
|
77
|
-
sourceExtension,
|
|
78
|
-
});
|
|
79
|
-
extendedKeyFn = keyFns.key;
|
|
80
|
-
extendedInverseKeyFn = keyFns.inverseKey;
|
|
81
|
-
} else if (keyFn) {
|
|
82
|
-
const resolvedKeyFn = toFunction(keyFn);
|
|
83
|
-
async function scopedKeyFn(sourceKey, sourceTree) {
|
|
84
|
-
const sourceValue = await sourceTree.get(sourceKey);
|
|
85
|
-
// The key function will be given the source tree, but will run with the
|
|
86
|
-
// scope of this tree.
|
|
87
|
-
const resultKey = await resolvedKeyFn.call(
|
|
88
|
-
tree,
|
|
89
|
-
sourceValue,
|
|
90
|
-
sourceKey,
|
|
91
|
-
sourceTree
|
|
92
|
-
);
|
|
93
|
-
return resultKey;
|
|
94
|
-
}
|
|
95
|
-
const keyFns = cachedKeyFunctions(scopedKeyFn, deep);
|
|
96
|
-
extendedKeyFn = keyFns.key;
|
|
97
|
-
extendedInverseKeyFn = keyFns.inverseKey;
|
|
98
|
-
} else {
|
|
99
|
-
// Use sidecar keyFn/inverseKey functions if the valueFn defines them.
|
|
100
|
-
extendedKeyFn = /** @type {any} */ (valueFn)?.key;
|
|
101
|
-
extendedInverseKeyFn = /** @type {any} */ (valueFn)?.inverseKey;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// const fn = mapFn({
|
|
105
|
-
// deep,
|
|
106
|
-
// description,
|
|
107
|
-
// inverseKey: extendedInverseKeyFn,
|
|
108
|
-
// key: extendedKeyFn,
|
|
109
|
-
// needsSourceValue,
|
|
110
|
-
// value: extendedValueFn,
|
|
111
|
-
// });
|
|
112
|
-
const temp = {
|
|
113
|
-
deep,
|
|
114
|
-
description,
|
|
115
|
-
inverseKey: extendedInverseKeyFn,
|
|
116
|
-
key: extendedKeyFn,
|
|
117
|
-
needsSourceValue,
|
|
118
|
-
value: extendedValueFn,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return (treelike) => {
|
|
122
|
-
const mapped = map(treelike, temp);
|
|
123
|
-
mapped.parent = tree;
|
|
124
|
-
return mapped;
|
|
125
|
-
};
|
|
126
|
-
}
|