@smallpen/local-package 0.1.0-alpha.3 → 0.1.0-alpha.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/assets/fonts/SourceSansPro-OFL.txt +46 -0
- package/assets/fonts/WorkSans-OFL.txt +46 -0
- package/package.json +2 -2
- package/src/draft-import.mjs +1 -11
- package/src/font-convert.mjs +23 -1
- package/src/fs-utils.mjs +95 -0
- package/src/index.mjs +18 -3
- package/src/initialize.mjs +363 -136
- package/src/kiwi-runtime.mjs +38 -36
- package/src/library-network.mjs +189 -0
- package/src/local-package-backend.mjs +215 -24
- package/src/local-package.mjs +589 -177
- package/src/local-workspace-session.mjs +278 -96
- package/src/migrate-themes.mjs +116 -0
- package/src/remote-library.mjs +167 -28
- package/src/render.mjs +1351 -510
- package/src/webp-decode.mjs +32 -0
- package/src/workspace.mjs +178 -17
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Applies to: SourceSansPro-Regular.ttf, SourceSansPro-Semibold.ttf, SourceSansPro-Bold.ttf
|
|
2
|
+
|
|
3
|
+
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
|
|
4
|
+
|
|
5
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
6
|
+
|
|
7
|
+
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
|
8
|
+
|
|
9
|
+
-----------------------------------------------------------
|
|
10
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
11
|
+
-----------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
PREAMBLE
|
|
14
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
|
15
|
+
|
|
16
|
+
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
|
17
|
+
|
|
18
|
+
DEFINITIONS
|
|
19
|
+
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
|
20
|
+
|
|
21
|
+
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
|
|
22
|
+
|
|
23
|
+
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
|
24
|
+
|
|
25
|
+
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
|
26
|
+
|
|
27
|
+
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
|
28
|
+
|
|
29
|
+
PERMISSION & CONDITIONS
|
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
|
31
|
+
|
|
32
|
+
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
|
33
|
+
|
|
34
|
+
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
|
35
|
+
|
|
36
|
+
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
|
37
|
+
|
|
38
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
|
39
|
+
|
|
40
|
+
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
|
41
|
+
|
|
42
|
+
TERMINATION
|
|
43
|
+
This license becomes null and void if any of the above conditions are not met.
|
|
44
|
+
|
|
45
|
+
DISCLAIMER
|
|
46
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Applies to: WorkSans-Regular.ttf
|
|
2
|
+
|
|
3
|
+
Copyright 2019 The Work Sans Project Authors (https://github.com/weiweihuanghuang/Work-Sans)
|
|
4
|
+
|
|
5
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
6
|
+
This license is copied below, and is also available with a FAQ at:
|
|
7
|
+
https://openfontlicense.org
|
|
8
|
+
|
|
9
|
+
-----------------------------------------------------------
|
|
10
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
11
|
+
-----------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
PREAMBLE
|
|
14
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
|
15
|
+
|
|
16
|
+
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
|
17
|
+
|
|
18
|
+
DEFINITIONS
|
|
19
|
+
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
|
20
|
+
|
|
21
|
+
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
|
|
22
|
+
|
|
23
|
+
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
|
24
|
+
|
|
25
|
+
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
|
26
|
+
|
|
27
|
+
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
|
28
|
+
|
|
29
|
+
PERMISSION & CONDITIONS
|
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
|
31
|
+
|
|
32
|
+
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
|
33
|
+
|
|
34
|
+
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
|
35
|
+
|
|
36
|
+
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
|
37
|
+
|
|
38
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
|
39
|
+
|
|
40
|
+
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
|
41
|
+
|
|
42
|
+
TERMINATION
|
|
43
|
+
This license becomes null and void if any of the above conditions are not met.
|
|
44
|
+
|
|
45
|
+
DISCLAIMER
|
|
46
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smallpen/local-package",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@jsquash/webp": "1.5.0",
|
|
15
|
-
"@smallpen/core": "0.1.0-alpha.
|
|
15
|
+
"@smallpen/core": "0.1.0-alpha.8",
|
|
16
16
|
"opentype.js": "2.0.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
package/src/draft-import.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import {
|
|
3
|
-
lstat,
|
|
4
3
|
mkdir,
|
|
5
4
|
mkdtemp,
|
|
6
5
|
rename,
|
|
@@ -21,6 +20,7 @@ import {
|
|
|
21
20
|
SmallPenError,
|
|
22
21
|
} from "@smallpen/core";
|
|
23
22
|
|
|
23
|
+
import { pathExists } from "./fs-utils.mjs";
|
|
24
24
|
import {
|
|
25
25
|
ByteBuffer,
|
|
26
26
|
compileSchema,
|
|
@@ -170,16 +170,6 @@ function inspectSvg(bytes) {
|
|
|
170
170
|
return { height, width };
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
async function pathExists(path) {
|
|
174
|
-
try {
|
|
175
|
-
await lstat(path);
|
|
176
|
-
return true;
|
|
177
|
-
} catch (error) {
|
|
178
|
-
if (error?.code === "ENOENT") return false;
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
173
|
export async function writeDraftPackage(outputValue, values) {
|
|
184
174
|
const output = resolve(outputValue);
|
|
185
175
|
if (!output.endsWith(".smallpen")) {
|
package/src/font-convert.mjs
CHANGED
|
@@ -20,7 +20,9 @@ function matches(bytes, signature) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function inspectFont(bytes, mimeType) {
|
|
23
|
-
const signature = FONT_SIGNATURES
|
|
23
|
+
const signature = Object.hasOwn(FONT_SIGNATURES, mimeType)
|
|
24
|
+
? FONT_SIGNATURES[mimeType]
|
|
25
|
+
: undefined;
|
|
24
26
|
if (!signature || !matches(bytes, signature)) {
|
|
25
27
|
failFont(
|
|
26
28
|
"invalid_font_blob",
|
|
@@ -108,6 +110,26 @@ export function sfntToWoff(bytes, mimeType) {
|
|
|
108
110
|
return output;
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
// Penpot names a Font Variant without a stored name from its weight and
|
|
114
|
+
// style (app.common.media/font-display-variant), e.g. "Bold Italic".
|
|
115
|
+
const FONT_WEIGHT_NAMES = {
|
|
116
|
+
100: "Hairline",
|
|
117
|
+
200: "Extra Light",
|
|
118
|
+
300: "Light",
|
|
119
|
+
400: "Regular",
|
|
120
|
+
500: "Medium",
|
|
121
|
+
600: "Semi Bold",
|
|
122
|
+
700: "Bold",
|
|
123
|
+
800: "Extra Bold",
|
|
124
|
+
900: "Black",
|
|
125
|
+
950: "Extra Black",
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export function fontVariantName(weight, style) {
|
|
129
|
+
const base = FONT_WEIGHT_NAMES[Number(weight)] ?? String(weight);
|
|
130
|
+
return style === "italic" ? `${base} Italic` : base;
|
|
131
|
+
}
|
|
132
|
+
|
|
111
133
|
export function prepareFontFiles(input) {
|
|
112
134
|
const files = {};
|
|
113
135
|
for (const [mimeType, bytes] of Object.entries(input)) {
|
package/src/fs-utils.mjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { lstat, open } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, relative } from "node:path";
|
|
4
|
+
|
|
5
|
+
export function isWithinRoot(rootPath, candidatePath) {
|
|
6
|
+
const child = relative(rootPath, candidatePath);
|
|
7
|
+
return child === "" || (!child.startsWith("..") && !isAbsolute(child));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function pathExists(path) {
|
|
11
|
+
try {
|
|
12
|
+
await lstat(path);
|
|
13
|
+
return true;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (error?.code === "ENOENT") return false;
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Reads a file only when it is a regular file. A FIFO or device in a Package
|
|
21
|
+
// (an archive can carry one) would otherwise block the read, the write lock
|
|
22
|
+
// and a thread-pool thread forever. Opening without blocking and checking the
|
|
23
|
+
// opened handle leaves no gap between the check and the read.
|
|
24
|
+
//
|
|
25
|
+
// With `maxBytes`, a file larger than the limit fails with code EFILETOOBIG
|
|
26
|
+
// (and `size`/`maxBytes` on the error) instead of being buffered whole; the
|
|
27
|
+
// read itself is bounded too, so a file growing after the size check cannot
|
|
28
|
+
// pass the limit either.
|
|
29
|
+
export async function readRegularFile(path, encoding, { maxBytes } = {}) {
|
|
30
|
+
const handle = await open(path, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
|
|
31
|
+
try {
|
|
32
|
+
const info = await handle.stat();
|
|
33
|
+
if (!info.isFile()) {
|
|
34
|
+
const error = new Error(`Not a regular file: ${path}`);
|
|
35
|
+
error.code = "ENOTREGULAR";
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
if (maxBytes === undefined) return await handle.readFile(encoding);
|
|
39
|
+
const tooBig = (size) =>
|
|
40
|
+
Object.assign(new Error(`File exceeds ${maxBytes} bytes: ${path}`), {
|
|
41
|
+
code: "EFILETOOBIG",
|
|
42
|
+
maxBytes,
|
|
43
|
+
size,
|
|
44
|
+
});
|
|
45
|
+
if (info.size > maxBytes) throw tooBig(info.size);
|
|
46
|
+
const chunks = [];
|
|
47
|
+
let length = 0;
|
|
48
|
+
while (length <= maxBytes) {
|
|
49
|
+
const chunk = Buffer.alloc(Math.min(Math.max(info.size - length, 0), maxBytes - length) + 1);
|
|
50
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, length);
|
|
51
|
+
if (bytesRead === 0) break;
|
|
52
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
53
|
+
length += bytesRead;
|
|
54
|
+
}
|
|
55
|
+
if (length > maxBytes) throw tooBig(length);
|
|
56
|
+
const bytes = Buffer.concat(chunks, length);
|
|
57
|
+
return encoding ? bytes.toString(encoding) : bytes;
|
|
58
|
+
} finally {
|
|
59
|
+
await handle.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Writes a new file and flushes it to stable storage before returning. The
|
|
64
|
+
// file must not exist yet: commits never truncate an inode in place because
|
|
65
|
+
// unchanged candidate files are hard links shared with the live Package.
|
|
66
|
+
export async function writeFileDurable(path, data, encoding) {
|
|
67
|
+
const handle = await open(path, "wx");
|
|
68
|
+
try {
|
|
69
|
+
await handle.writeFile(data, encoding);
|
|
70
|
+
await handle.sync();
|
|
71
|
+
} finally {
|
|
72
|
+
await handle.close();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Flushes directory entries (creates, renames, unlinks). Some platforms and
|
|
77
|
+
// file systems (notably Windows) cannot open or sync a directory; durability
|
|
78
|
+
// there relies on the file-level syncs alone.
|
|
79
|
+
export async function syncDirectory(path) {
|
|
80
|
+
let handle;
|
|
81
|
+
try {
|
|
82
|
+
handle = await open(path, "r");
|
|
83
|
+
await handle.sync();
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (
|
|
86
|
+
!["EISDIR", "EPERM", "EACCES", "EINVAL", "ENOTSUP", "EBADF"].includes(
|
|
87
|
+
error?.code,
|
|
88
|
+
)
|
|
89
|
+
) {
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
} finally {
|
|
93
|
+
await handle?.close();
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/index.mjs
CHANGED
|
@@ -3,18 +3,31 @@ export {
|
|
|
3
3
|
LocalWorkspaceSession,
|
|
4
4
|
reconcilePackageViewState,
|
|
5
5
|
} from "./local-workspace-session.mjs";
|
|
6
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
localLibraryLocator,
|
|
8
|
+
openWorkspace,
|
|
9
|
+
resolveWorkspace,
|
|
10
|
+
} from "./workspace.mjs";
|
|
7
11
|
export {
|
|
8
12
|
defaultLibraryCacheRoot,
|
|
9
13
|
openRemoteLibrary,
|
|
10
14
|
} from "./remote-library.mjs";
|
|
11
|
-
export {
|
|
15
|
+
export {
|
|
16
|
+
createEvidence,
|
|
17
|
+
measureProjectionText,
|
|
18
|
+
renderProjection,
|
|
19
|
+
} from "./render.mjs";
|
|
12
20
|
export {
|
|
13
21
|
decodeFigmaClipboard,
|
|
14
22
|
importDraft,
|
|
15
23
|
writeDraftPackage,
|
|
16
24
|
} from "./draft-import.mjs";
|
|
17
|
-
export {
|
|
25
|
+
export {
|
|
26
|
+
createBlankPackage,
|
|
27
|
+
initializeBlankWorkspace,
|
|
28
|
+
initializeWorkspace,
|
|
29
|
+
} from "./initialize.mjs";
|
|
30
|
+
export { migrateThemesByCopy } from "./migrate-themes.mjs";
|
|
18
31
|
export {
|
|
19
32
|
applyOperationBatch,
|
|
20
33
|
deleteFontFamily,
|
|
@@ -22,12 +35,14 @@ export {
|
|
|
22
35
|
importFontVariant,
|
|
23
36
|
importMedia,
|
|
24
37
|
openPackage,
|
|
38
|
+
readBatchHistory,
|
|
25
39
|
removeMedia,
|
|
26
40
|
replayRecordedBatch,
|
|
27
41
|
updateFontFamily,
|
|
28
42
|
} from "./local-package.mjs";
|
|
29
43
|
export { detectMediaType, inspectMedia } from "./media-inspect.mjs";
|
|
30
44
|
export {
|
|
45
|
+
fontVariantName,
|
|
31
46
|
inspectFont,
|
|
32
47
|
prepareFontFiles,
|
|
33
48
|
sfntToWoff,
|