@liiift-studio/sanity-font-manager 2.3.19 → 2.5.0
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/README.md +437 -437
- package/dist/UploadModal-6LIX7XOK.js +6 -0
- package/dist/UploadModal-NME2W53V.mjs +6 -0
- package/dist/chunk-646WCBRR.mjs +7276 -0
- package/dist/chunk-FH4QKHOH.js +7276 -0
- package/dist/index.js +747 -1675
- package/dist/index.mjs +400 -1237
- package/package.json +85 -85
- package/src/components/BatchUploadFonts.jsx +653 -639
- package/src/components/BulkActions.jsx +99 -0
- package/src/components/ExistingDocumentResolver.jsx +152 -0
- package/src/components/FontReviewCard.jsx +415 -0
- package/src/components/FontScriptUploaderComponent.jsx +463 -463
- package/src/components/GenerateCollectionsPairsComponent.jsx +259 -259
- package/src/components/KeyValueInput.jsx +95 -95
- package/src/components/KeyValueReferenceInput.jsx +254 -254
- package/src/components/NestedObjectArraySelector.jsx +146 -146
- package/src/components/PriceInput.jsx +26 -26
- package/src/components/PrimaryCollectionGeneratorTypeface.jsx +116 -116
- package/src/components/RegenerateSubfamiliesComponent.jsx +185 -185
- package/src/components/SetOTF.jsx +87 -87
- package/src/components/SingleUploaderTool.jsx +672 -673
- package/src/components/StatusDisplay.jsx +26 -26
- package/src/components/StyleCountInput.jsx +16 -16
- package/src/components/UpdateScriptsComponent.jsx +76 -76
- package/src/components/UploadButton.jsx +43 -43
- package/src/components/UploadModal.jsx +268 -0
- package/src/components/UploadScriptsComponent.jsx +539 -537
- package/src/components/UploadStep1Settings.jsx +272 -0
- package/src/components/UploadStep2Review.jsx +472 -0
- package/src/components/UploadStep3Execute.jsx +234 -0
- package/src/components/UploadSummary.jsx +196 -0
- package/src/components/VariableInstanceReferencesInput.jsx +190 -190
- package/src/hooks/useNestedObjects.js +92 -92
- package/src/hooks/useSanityClient.js +9 -9
- package/src/index.js +115 -70
- package/src/schema/openTypeField.js +1945 -1945
- package/src/schema/styleCountField.js +12 -12
- package/src/schema/stylesField.js +268 -268
- package/src/schema/stylisticSetField.js +301 -301
- package/src/utils/buildUploadPlan.js +325 -0
- package/src/utils/executeUploadPlan.js +437 -0
- package/src/utils/executionReducer.js +56 -0
- package/src/utils/fontHelpers.js +267 -0
- package/src/utils/generateCssFile.js +207 -205
- package/src/utils/generateFontData.js +98 -145
- package/src/utils/generateFontFile.js +38 -38
- package/src/utils/generateKeywords.js +185 -185
- package/src/utils/generateSubset.js +45 -45
- package/src/utils/getEmptyFontKit.js +101 -99
- package/src/utils/parseFont.js +55 -0
- package/src/utils/parseVariableFontInstances.js +211 -211
- package/src/utils/planReducer.js +517 -0
- package/src/utils/planTypes.js +183 -0
- package/src/utils/processFontFiles.js +529 -477
- package/src/utils/regenerateFontData.js +146 -146
- package/src/utils/resolveExistingFont.js +87 -0
- package/src/utils/sanitizeForSanityId.js +65 -65
- package/src/utils/updateFontPrices.js +94 -94
- package/src/utils/updateTypefaceDocument.js +149 -160
- package/src/utils/uploadFontFiles.js +405 -316
- package/src/utils/utils.js +24 -24
|
@@ -1,99 +1,101 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
reader
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
// Parses font files and returns name/subfamily metadata groupings without writing to Sanity
|
|
2
|
+
|
|
3
|
+
import { parseFont } from './parseFont';
|
|
4
|
+
import { getNameString, getVariationAxes } from './fontHelpers';
|
|
5
|
+
import slugify from 'slugify';
|
|
6
|
+
|
|
7
|
+
/** Reads font files and returns name/subfamily metadata without writing to Sanity */
|
|
8
|
+
export async function getEmptyFontKit({ title, files, weightKeywordList, italicKeywordList }) {
|
|
9
|
+
|
|
10
|
+
let fontNames = {};
|
|
11
|
+
let subfamilies = {};
|
|
12
|
+
|
|
13
|
+
for (var i = 0; i < files.length; i++) {
|
|
14
|
+
|
|
15
|
+
const file = files[i];
|
|
16
|
+
const fontBuffer = await readFontFile(file);
|
|
17
|
+
const font = await parseFont(fontBuffer, file.name);
|
|
18
|
+
|
|
19
|
+
let weightName = getNameString(font, 17) || getNameString(font, 2) || '';
|
|
20
|
+
|
|
21
|
+
const axes = getVariationAxes(font);
|
|
22
|
+
let variableFont = axes !== null;
|
|
23
|
+
const familyName = getNameString(font, 1);
|
|
24
|
+
const fullName = getNameString(font, 4);
|
|
25
|
+
let subfamilyName = familyName.toLowerCase().trim().replace(title.toLowerCase().trim(), '').trim();
|
|
26
|
+
let fontTitle = fullName.toLowerCase().trim();
|
|
27
|
+
|
|
28
|
+
weightKeywordList.forEach(keyword => {
|
|
29
|
+
const kw = keyword.toLowerCase().trim();
|
|
30
|
+
|
|
31
|
+
if (fontTitle.includes(kw)) {
|
|
32
|
+
fontTitle = fontTitle.replace(kw, '');
|
|
33
|
+
}
|
|
34
|
+
if (subfamilyName.includes(kw)) {
|
|
35
|
+
subfamilyName = subfamilyName.replace(kw, '');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
italicKeywordList.forEach(keyword => {
|
|
40
|
+
const kw = keyword.toLowerCase().trim();
|
|
41
|
+
|
|
42
|
+
if (subfamilyName.includes(kw)) {
|
|
43
|
+
subfamilyName = subfamilyName.replace(kw, '');
|
|
44
|
+
}
|
|
45
|
+
if (fontTitle.includes(kw)) {
|
|
46
|
+
fontTitle = fontTitle.replace(kw, '');
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
fontTitle = fontTitle.trim().split(' ').map(word => word[0].toUpperCase() + word.slice(1)).join(' ');
|
|
51
|
+
|
|
52
|
+
subfamilyName = subfamilyName.trim();
|
|
53
|
+
subfamilyName = (subfamilyName == '') ? 'Regular' : subfamilyName.split(' ').map(word => word[0].toUpperCase() + word.slice(1)).join(' ');
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
let id = slugify(fontTitle.toLowerCase().trim());
|
|
57
|
+
if (variableFont && !id.endsWith('-vf')) {
|
|
58
|
+
id = id + '-vf';
|
|
59
|
+
fontTitle = fontTitle + ' VF';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// add subfamily to list
|
|
63
|
+
if (!subfamilies[id]) {
|
|
64
|
+
subfamilies[id] = [subfamilyName];
|
|
65
|
+
} else if (subfamilies[id].indexOf(subfamilyName) == -1) {
|
|
66
|
+
subfamilies[id] = [...subfamilies[id], subfamilyName];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!fontNames[id]) {
|
|
70
|
+
fontNames[id] = [{
|
|
71
|
+
file: file.name,
|
|
72
|
+
fullName: fullName,
|
|
73
|
+
familyName: familyName,
|
|
74
|
+
subFamily: subfamilyName,
|
|
75
|
+
}];
|
|
76
|
+
} else if (fontNames[id].indexOf(file.name) == -1) {
|
|
77
|
+
fontNames[id].push({
|
|
78
|
+
file: file.name,
|
|
79
|
+
fullName: fullName,
|
|
80
|
+
familyName: familyName,
|
|
81
|
+
subFamily: subfamilyName,
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log('Font names:', fontNames);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Reads a font file and returns its content as an ArrayBuffer */
|
|
90
|
+
const readFontFile = (file) => {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const reader = new FileReader();
|
|
93
|
+
|
|
94
|
+
reader.onload = (event) => {
|
|
95
|
+
resolve(event.target.result);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
reader.onerror = (error) => { reject(error); };
|
|
99
|
+
reader.readAsArrayBuffer(file);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Async font parser — wraps lib-font event model in a Promise with decompressor bootstrap
|
|
2
|
+
|
|
3
|
+
import pako from 'pako';
|
|
4
|
+
|
|
5
|
+
// Set decompressor globals BEFORE lib-font is imported.
|
|
6
|
+
// lib-font reads globalThis.pako and globalThis.unbrotli at module evaluation time
|
|
7
|
+
// (top of woff.js / woff2.js), not at parse time. These must be set before lib-font
|
|
8
|
+
// is first evaluated, so we use dynamic import() below to guarantee ordering.
|
|
9
|
+
globalThis.pako = pako;
|
|
10
|
+
|
|
11
|
+
// unbrotli is a UMD that sets globalThis.unbrotli as a side effect on evaluation.
|
|
12
|
+
// We vendor it from lib-font/lib/unbrotli.js because the subpath is not in
|
|
13
|
+
// lib-font's exports map (ERR_PACKAGE_PATH_NOT_EXPORTED).
|
|
14
|
+
import '../vendor/unbrotli.js';
|
|
15
|
+
|
|
16
|
+
// Lazy-loaded lib-font Font constructor — resolved on first parseFont() call.
|
|
17
|
+
// Using dynamic import() guarantees globalThis.pako and globalThis.unbrotli are
|
|
18
|
+
// set before lib-font evaluates, which static imports cannot guarantee in ESM.
|
|
19
|
+
let _Font = null;
|
|
20
|
+
|
|
21
|
+
/** Returns the lib-font Font constructor, loading it on first call */
|
|
22
|
+
async function getFont() {
|
|
23
|
+
if (!_Font) {
|
|
24
|
+
const mod = await import('lib-font');
|
|
25
|
+
_Font = mod.Font;
|
|
26
|
+
}
|
|
27
|
+
return _Font;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Maximum font file size accepted for parsing (50 MB) */
|
|
31
|
+
const MAX_FONT_FILE_SIZE = 50 * 1024 * 1024;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Parse a font file from an ArrayBuffer.
|
|
35
|
+
* Returns a lib-font Font object with all tables accessible via font.opentype.tables.*.
|
|
36
|
+
*
|
|
37
|
+
* @param {ArrayBuffer} buffer - Raw font file bytes
|
|
38
|
+
* @param {string} filename - Original filename (used for format detection by lib-font)
|
|
39
|
+
* @returns {Promise<import('lib-font').Font>} Parsed lib-font Font object
|
|
40
|
+
* @throws {Error} If the file exceeds MAX_FONT_FILE_SIZE or parsing fails
|
|
41
|
+
*/
|
|
42
|
+
export async function parseFont(buffer, filename) {
|
|
43
|
+
if (buffer.byteLength > MAX_FONT_FILE_SIZE) {
|
|
44
|
+
throw new Error(`Font file exceeds ${MAX_FONT_FILE_SIZE / 1024 / 1024}MB limit: ${filename} (${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB)`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const Font = await getFont();
|
|
48
|
+
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
const font = new Font('font', { skipStyleSheet: true });
|
|
51
|
+
font.onload = (evt) => resolve(evt.detail.font);
|
|
52
|
+
font.onerror = (evt) => reject(new Error(evt.detail?.message || `Failed to parse ${filename}`));
|
|
53
|
+
font.fromDataBuffer(buffer, filename);
|
|
54
|
+
});
|
|
55
|
+
}
|