@liiift-studio/sanity-font-manager 2.3.2 → 2.3.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liiift-studio/sanity-font-manager",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "Sanity Studio plugin — full font management suite with batch upload, format conversion, metadata extraction, CSS generation, collection/pair generation, and script variant support. Supports Sanity v3, v4, and v5.",
5
5
  "license": "MIT",
6
6
  "author": "Liiift Studio",
@@ -34,6 +34,7 @@
34
34
  "src/components",
35
35
  "src/hooks",
36
36
  "src/utils",
37
+ "src/schema",
37
38
  "src/index.js"
38
39
  ],
39
40
  "scripts": {
@@ -0,0 +1,87 @@
1
+ // Detects and sets active OpenType features on a typeface document from the first linked font's metadata
2
+
3
+ import { useState } from 'react';
4
+ import { set, useFormValue } from 'sanity';
5
+ import { Stack, Button, Text } from '@sanity/ui';
6
+ import { useSanityClient } from '../hooks/useSanityClient';
7
+
8
+ /**
9
+ * Reads the first linked font's opentypeFeatures data and checks which configured
10
+ * feature keys are supported. Patches the field with the detected features array.
11
+ */
12
+ export const SetOTF = (props) => {
13
+ const { onChange, value = {} } = props;
14
+ const client = useSanityClient();
15
+ const stylesObject = useFormValue(['styles']);
16
+ const [message, setMessage] = useState('');
17
+
18
+ /** Fetches the first font document and matches its OpenType features against the configured keys. */
19
+ const detect = async () => {
20
+ if (!stylesObject?.fonts?.length) {
21
+ setMessage('Error: No fonts found in styles. Please add at least one font first.');
22
+ setTimeout(() => setMessage(''), 5000);
23
+ return;
24
+ }
25
+
26
+ const fontRef = stylesObject.fonts[0]?._ref;
27
+ if (!fontRef) {
28
+ setMessage('Error: Invalid font reference in styles.');
29
+ setTimeout(() => setMessage(''), 5000);
30
+ return;
31
+ }
32
+
33
+ try {
34
+ const font = await client.fetch('*[_type == "font" && _id == $id][0]', { id: fontRef });
35
+
36
+ if (!font) {
37
+ setMessage('Error: Could not find the referenced font.');
38
+ setTimeout(() => setMessage(''), 5000);
39
+ return;
40
+ }
41
+
42
+ if (!font.opentypeFeatures?.chars) {
43
+ setMessage(`Error: No OpenType feature data found in "${font.title || 'this font'}". Generate font data first.`);
44
+ setTimeout(() => setMessage(''), 5000);
45
+ return;
46
+ }
47
+
48
+ const features = [];
49
+ Object.keys(value).forEach(key => {
50
+ if (key !== 'features' && value[key]?.feature) {
51
+ const requiredFeatures = value[key].feature.split(' ');
52
+ const approved = requiredFeatures.every(v => font.opentypeFeatures.chars.includes(v));
53
+ if (approved) features.push(key);
54
+ }
55
+ });
56
+
57
+ onChange(set({ ...value, features }));
58
+ setMessage(`Features detected: ${features.length ? features.join(', ') : 'none'}.`);
59
+ setTimeout(() => setMessage(''), 5000);
60
+ } catch (err) {
61
+ setMessage('Error detecting features. Check the console for details.');
62
+ console.error('SetOTF detect error:', err);
63
+ }
64
+ };
65
+
66
+ return (
67
+ <Stack className="openType">
68
+ {value?.features?.length > 0 && (
69
+ <Text muted size={1} style={{ marginBottom: '0.5rem' }}>
70
+ Number of features: {value.features.length}
71
+ </Text>
72
+ )}
73
+ {!!stylesObject?.fonts?.length && (
74
+ <Button
75
+ text="Detect OTF"
76
+ mode="ghost"
77
+ onClick={detect}
78
+ style={{ borderRadius: '0 3px 0 0', marginBottom: '1rem' }}
79
+ />
80
+ )}
81
+ {!!message && (
82
+ <Text muted size={1}><br />{message}<br /><br /></Text>
83
+ )}
84
+ {props.renderDefault(props)}
85
+ </Stack>
86
+ );
87
+ };
@@ -0,0 +1,16 @@
1
+ // Displays the total count of static and variable font styles linked to a typeface document
2
+
3
+ import React from 'react';
4
+ import { Text } from '@sanity/ui';
5
+ import { useFormValue } from 'sanity';
6
+
7
+ /** Reads styles.fonts and styles.variableFont arrays and displays the combined count. */
8
+ export const StyleCountInput = (props) => {
9
+ const styles = useFormValue(['styles', 'fonts']) || [];
10
+ const vfStyles = useFormValue(['styles', 'variableFont']) || [];
11
+ const count = styles.length + vfStyles.length;
12
+
13
+ return (
14
+ <Text size={1}>{count}</Text>
15
+ );
16
+ };
package/src/index.js CHANGED
@@ -15,6 +15,8 @@ export { KeyValueInput } from './components/KeyValueInput.jsx';
15
15
  export { KeyValueReferenceInput } from './components/KeyValueReferenceInput.jsx';
16
16
  export { VariableInstanceReferencesInput } from './components/VariableInstanceReferencesInput.jsx';
17
17
  export { PrimaryCollectionGeneratorTypeface } from './components/PrimaryCollectionGeneratorTypeface.jsx';
18
+ export { SetOTF } from './components/SetOTF.jsx';
19
+ export { StyleCountInput } from './components/StyleCountInput.jsx';
18
20
 
19
21
  // Hooks
20
22
  export { useSanityClient } from './hooks/useSanityClient.js';
@@ -51,6 +53,10 @@ export { renameFontDocuments } from './utils/regenerateFontData.js';
51
53
  export { updateFontPrices } from './utils/updateFontPrices.js';
52
54
  export { sanitizeForSanityId } from './utils/sanitizeForSanityId.js';
53
55
 
56
+ // Schema field definitions
57
+ export { openTypeField } from './schema/openTypeField.js';
58
+ export { styleCountField } from './schema/styleCountField.js';
59
+
54
60
  // Keyword utilities
55
61
  export {
56
62
  generateStyleKeywords,