@10up/block-renderer-preferences 0.1.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/README.md ADDED
@@ -0,0 +1,328 @@
1
+ # @10up/block-renderer-preferences
2
+
3
+ Load and manage user preferences for AI block generation. Preferences guide AI assistants on preferred blocks, styles, and patterns.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @10up/block-renderer-preferences
9
+ # or
10
+ pnpm add @10up/block-renderer-preferences
11
+ ```
12
+
13
+ ## Overview
14
+
15
+ This package:
16
+
17
+ 1. **Loads preferences** - From `block-preferences.json` or `.blockrc.json`
18
+ 2. **Validates with Zod** - Ensures preference files are correctly formatted
19
+ 3. **Formats for AI prompts** - Converts preferences to AI-friendly text
20
+ 4. **Provides defaults** - Sensible defaults when no file exists
21
+
22
+ ## Usage
23
+
24
+ ### Load Preferences
25
+
26
+ Automatically find and load preferences from a directory:
27
+
28
+ ```typescript
29
+ import { loadPreferences } from '@10up/block-renderer-preferences';
30
+
31
+ const prefs = loadPreferences('/path/to/project');
32
+ // Searches for:
33
+ // - /path/to/project/block-preferences.json
34
+ // - /path/to/project/.blockrc.json
35
+ // - /path/to/project/.block-renderer/preferences.json
36
+
37
+ if (prefs) {
38
+ console.log(prefs.preferredBlocks);
39
+ console.log(prefs.avoidBlocks);
40
+ console.log(prefs.styleGuide);
41
+ }
42
+ ```
43
+
44
+ ### Load from Specific File
45
+
46
+ ```typescript
47
+ import { loadPreferencesFromFile } from '@10up/block-renderer-preferences';
48
+
49
+ const prefs = loadPreferencesFromFile('/path/to/custom-prefs.json');
50
+ ```
51
+
52
+ ### Find Preferences File
53
+
54
+ ```typescript
55
+ import { findPreferencesFile } from '@10up/block-renderer-preferences';
56
+
57
+ const filePath = findPreferencesFile('/path/to/project');
58
+ // Returns path to preferences file or null if not found
59
+ ```
60
+
61
+ ### Create Default Preferences
62
+
63
+ ```typescript
64
+ import { createDefaultPreferences } from '@10up/block-renderer-preferences';
65
+
66
+ const defaults = createDefaultPreferences();
67
+ // Returns sensible default configuration
68
+ ```
69
+
70
+ ### Merge Preferences
71
+
72
+ Combine multiple preference sources:
73
+
74
+ ```typescript
75
+ import { mergePreferences, createDefaultPreferences } from '@10up/block-renderer-preferences';
76
+
77
+ const defaults = createDefaultPreferences();
78
+ const userPrefs = loadPreferencesFromFile('/path/to/prefs.json');
79
+ const merged = mergePreferences(defaults, userPrefs);
80
+ ```
81
+
82
+ ### Format for AI Prompts
83
+
84
+ ```typescript
85
+ import { formatPreferencesForPrompt } from '@10up/block-renderer-preferences';
86
+
87
+ const promptSection = formatPreferencesForPrompt(prefs);
88
+ // Returns formatted markdown for AI system prompt
89
+ ```
90
+
91
+ ## Preferences Schema
92
+
93
+ ### BlockPreferencesConfig
94
+
95
+ The main configuration object:
96
+
97
+ ```typescript
98
+ interface BlockPreferencesConfig {
99
+ // Block preferences
100
+ blocks?: BlocksPreferences;
101
+
102
+ // Layout preferences
103
+ layout?: LayoutPreferences;
104
+
105
+ // Typography preferences
106
+ typography?: TypographyPreferences;
107
+
108
+ // Color preferences
109
+ colors?: ColorPreferences;
110
+
111
+ // Spacing preferences
112
+ spacing?: SpacingPreferences;
113
+
114
+ // Image preferences
115
+ images?: ImagePreferences;
116
+
117
+ // Style guide
118
+ styleGuide?: StyleGuide;
119
+
120
+ // Brand guidelines
121
+ brand?: BrandGuideline;
122
+ }
123
+ ```
124
+
125
+ ### BlocksPreferences
126
+
127
+ ```typescript
128
+ interface BlocksPreferences {
129
+ /** Blocks to prefer when multiple options exist */
130
+ preferred?: string[];
131
+ /** Blocks to avoid using */
132
+ avoid?: string[];
133
+ /** Default block for text content */
134
+ defaultText?: string;
135
+ /** Default container block */
136
+ defaultContainer?: string;
137
+ }
138
+ ```
139
+
140
+ ### LayoutPreferences
141
+
142
+ ```typescript
143
+ interface LayoutPreferences {
144
+ /** Default layout type for groups */
145
+ defaultType?: 'constrained' | 'flex' | 'flow' | 'grid';
146
+ /** Maximum content width */
147
+ maxWidth?: string;
148
+ /** Default alignment */
149
+ defaultAlign?: 'left' | 'center' | 'right' | 'wide' | 'full';
150
+ }
151
+ ```
152
+
153
+ ### TypographyPreferences
154
+
155
+ ```typescript
156
+ interface TypographyPreferences {
157
+ /** Use semantic heading levels */
158
+ useSemanticHeadings?: boolean;
159
+ /** Maximum heading level to use */
160
+ maxHeadingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
161
+ /** Default font size */
162
+ defaultFontSize?: string;
163
+ }
164
+ ```
165
+
166
+ ### ColorPreferences
167
+
168
+ ```typescript
169
+ interface ColorPreferences {
170
+ /** Preferred color tokens to use */
171
+ preferred?: string[];
172
+ /** Colors to avoid */
173
+ avoid?: string[];
174
+ /** Default background color */
175
+ defaultBackground?: string;
176
+ /** Default text color */
177
+ defaultText?: string;
178
+ }
179
+ ```
180
+
181
+ ### SpacingPreferences
182
+
183
+ ```typescript
184
+ interface SpacingPreferences {
185
+ /** Default spacing token */
186
+ default?: string;
187
+ /** Preferred spacing scale */
188
+ scale?: string[];
189
+ }
190
+ ```
191
+
192
+ ### ImagePreferences
193
+
194
+ ```typescript
195
+ interface ImagePreferences {
196
+ /** Preferred image sizes */
197
+ preferredSizes?: string[];
198
+ /** Default aspect ratio */
199
+ defaultAspectRatio?: string;
200
+ /** Always include alt text */
201
+ requireAlt?: boolean;
202
+ }
203
+ ```
204
+
205
+ ### StyleGuide
206
+
207
+ ```typescript
208
+ interface StyleGuide {
209
+ /** Custom style rules */
210
+ rules?: string[];
211
+ /** Preferred patterns by category */
212
+ patternsByCategory?: Record<string, string[]>;
213
+ /** Patterns to avoid */
214
+ avoidPatterns?: string[];
215
+ }
216
+ ```
217
+
218
+ ### BrandGuideline
219
+
220
+ ```typescript
221
+ interface BrandGuideline {
222
+ /** Brand name */
223
+ name?: string;
224
+ /** Brand description */
225
+ description?: string;
226
+ /** Voice and tone guidelines */
227
+ voiceTone?: string[];
228
+ }
229
+ ```
230
+
231
+ ## Example Configuration
232
+
233
+ ```json
234
+ {
235
+ "blocks": {
236
+ "preferred": ["core/group", "core/columns"],
237
+ "avoid": ["core/freeform", "core/html"],
238
+ "defaultText": "core/paragraph",
239
+ "defaultContainer": "core/group"
240
+ },
241
+ "layout": {
242
+ "defaultType": "constrained",
243
+ "defaultAlign": "wide"
244
+ },
245
+ "typography": {
246
+ "useSemanticHeadings": true,
247
+ "maxHeadingLevel": 4
248
+ },
249
+ "colors": {
250
+ "preferred": ["primary", "secondary", "base", "contrast"],
251
+ "avoid": ["error", "warning"]
252
+ },
253
+ "spacing": {
254
+ "default": "50",
255
+ "scale": ["30", "40", "50", "60", "70"]
256
+ },
257
+ "images": {
258
+ "preferredSizes": ["large", "full"],
259
+ "requireAlt": true
260
+ },
261
+ "styleGuide": {
262
+ "rules": [
263
+ "Always use constrained layout for content groups",
264
+ "Prefer flex layout for button containers",
265
+ "Use consistent spacing throughout sections"
266
+ ],
267
+ "patternsByCategory": {
268
+ "hero": ["theme/hero-centered", "theme/hero-split"]
269
+ },
270
+ "avoidPatterns": ["theme/deprecated-banner"]
271
+ },
272
+ "brand": {
273
+ "name": "Acme Corp",
274
+ "voiceTone": [
275
+ "Professional but approachable",
276
+ "Clear and concise",
277
+ "Helpful and supportive"
278
+ ]
279
+ }
280
+ }
281
+ ```
282
+
283
+ ## Complete Exports
284
+
285
+ ### Functions
286
+
287
+ | Function | Description |
288
+ |----------|-------------|
289
+ | `loadPreferences(directory)` | Auto-detect and load preferences |
290
+ | `loadPreferencesFromFile(filePath)` | Load from specific file |
291
+ | `findPreferencesFile(directory)` | Find preferences file path |
292
+ | `createDefaultPreferences()` | Create default configuration |
293
+ | `mergePreferences(base, override)` | Merge preference objects |
294
+ | `formatPreferencesForPrompt(prefs)` | Format for AI prompt |
295
+
296
+ ### Types
297
+
298
+ | Type | Description |
299
+ |------|-------------|
300
+ | `BlockPreferencesConfig` | Main configuration type |
301
+ | `BlocksPreferences` | Block selection preferences |
302
+ | `LayoutPreferences` | Layout preferences |
303
+ | `TypographyPreferences` | Typography preferences |
304
+ | `ColorPreferences` | Color preferences |
305
+ | `SpacingPreferences` | Spacing preferences |
306
+ | `ImagePreferences` | Image preferences |
307
+ | `StyleGuide` | Style guide rules |
308
+ | `BrandGuideline` | Brand guidelines |
309
+ | `Preferences` | Alias for BlockPreferencesConfig |
310
+
311
+ ### Zod Schemas
312
+
313
+ | Schema | Description |
314
+ |--------|-------------|
315
+ | `blockPreferencesConfigSchema` | Main config schema |
316
+ | `blockPreferencesSchema` | Block preferences schema |
317
+ | `layoutPreferencesSchema` | Layout preferences schema |
318
+ | `typographyPreferencesSchema` | Typography preferences schema |
319
+ | `colorPreferencesSchema` | Color preferences schema |
320
+ | `spacingPreferencesSchema` | Spacing preferences schema |
321
+ | `imagePreferencesSchema` | Image preferences schema |
322
+ | `styleGuideSchema` | Style guide schema |
323
+ | `brandGuidelineSchema` | Brand guideline schema |
324
+ | `preferencesSchema` | Alias for main schema |
325
+
326
+ ## License
327
+
328
+ MIT
@@ -0,0 +1,6 @@
1
+ import type { BlockPreferencesConfig } from './schema.js';
2
+ /**
3
+ * Formats preferences as a markdown string for AI prompts.
4
+ */
5
+ export declare function formatPreferencesForPrompt(config: BlockPreferencesConfig): string;
6
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAwBjF"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Formats preferences as a markdown string for AI prompts.
3
+ */
4
+ export function formatPreferencesForPrompt(config) {
5
+ const sections = [];
6
+ // Format main preferences
7
+ if (config.preferences) {
8
+ sections.push(formatMainPreferences(config.preferences));
9
+ }
10
+ // Format style guide rules
11
+ if (config.styleGuide?.rules && config.styleGuide.rules.length > 0) {
12
+ sections.push(formatStyleGuideRules(config.styleGuide.rules));
13
+ }
14
+ // Format style guide examples
15
+ if (config.styleGuide?.examples && Object.keys(config.styleGuide.examples).length > 0) {
16
+ sections.push(formatStyleGuideExamples(config.styleGuide.examples));
17
+ }
18
+ // Format brand guidelines
19
+ if (config.brandGuidelines && Object.keys(config.brandGuidelines).length > 0) {
20
+ sections.push(formatBrandGuidelines(config.brandGuidelines));
21
+ }
22
+ return sections.filter(s => s.length > 0).join('\n\n');
23
+ }
24
+ /**
25
+ * Formats main preferences section.
26
+ */
27
+ function formatMainPreferences(preferences) {
28
+ const lines = ['## User Preferences'];
29
+ // Layout preferences
30
+ if (preferences.layout) {
31
+ lines.push('\n**Layout:**');
32
+ if (preferences.layout.preferGrid !== undefined) {
33
+ lines.push(`- ${preferences.layout.preferGrid ? 'Prefer' : 'Avoid'} CSS Grid layouts`);
34
+ }
35
+ if (preferences.layout.defaultContainerBlock) {
36
+ lines.push(`- Default container: ${preferences.layout.defaultContainerBlock}`);
37
+ }
38
+ if (preferences.layout.defaultAlignment) {
39
+ lines.push(`- Default alignment: ${preferences.layout.defaultAlignment}`);
40
+ }
41
+ if (preferences.layout.preferConstrained !== undefined) {
42
+ lines.push(`- ${preferences.layout.preferConstrained ? 'Use' : 'Avoid'} constrained layout`);
43
+ }
44
+ }
45
+ // Block preferences
46
+ if (preferences.blocks) {
47
+ lines.push('\n**Blocks:**');
48
+ if (preferences.blocks.preferButtonsOverLinks !== undefined) {
49
+ lines.push(`- ${preferences.blocks.preferButtonsOverLinks ? 'Prefer' : 'Avoid'} buttons over links for CTAs`);
50
+ }
51
+ if (preferences.blocks.preferPatternWhenAvailable !== undefined) {
52
+ lines.push(`- ${preferences.blocks.preferPatternWhenAvailable ? 'Use' : "Don't use"} patterns when available`);
53
+ }
54
+ if (preferences.blocks.avoidBlocks && preferences.blocks.avoidBlocks.length > 0) {
55
+ lines.push(`- Avoid: ${preferences.blocks.avoidBlocks.join(', ')}`);
56
+ }
57
+ if (preferences.blocks.preferBlocks) {
58
+ for (const [use, block] of Object.entries(preferences.blocks.preferBlocks)) {
59
+ lines.push(`- For ${use}: use ${block}`);
60
+ }
61
+ }
62
+ }
63
+ // Typography preferences
64
+ if (preferences.typography) {
65
+ lines.push('\n**Typography:**');
66
+ if (preferences.typography.defaultHeadingLevel !== undefined) {
67
+ lines.push(`- Default heading level: h${preferences.typography.defaultHeadingLevel}`);
68
+ }
69
+ if (preferences.typography.preferredFontSizes && preferences.typography.preferredFontSizes.length > 0) {
70
+ lines.push(`- Preferred font sizes: ${preferences.typography.preferredFontSizes.join(', ')}`);
71
+ }
72
+ if (preferences.typography.useDropCap !== undefined) {
73
+ lines.push(`- Drop cap: ${preferences.typography.useDropCap ? 'enabled' : 'disabled'}`);
74
+ }
75
+ }
76
+ // Color preferences
77
+ if (preferences.colors) {
78
+ lines.push('\n**Colors:**');
79
+ if (preferences.colors.preferPresetColors !== undefined) {
80
+ lines.push(`- ${preferences.colors.preferPresetColors ? 'Use' : 'Allow custom'} preset colors`);
81
+ }
82
+ if (preferences.colors.defaultBackgroundColor) {
83
+ lines.push(`- Default background: ${preferences.colors.defaultBackgroundColor}`);
84
+ }
85
+ if (preferences.colors.defaultTextColor) {
86
+ lines.push(`- Default text color: ${preferences.colors.defaultTextColor}`);
87
+ }
88
+ }
89
+ // Spacing preferences
90
+ if (preferences.spacing) {
91
+ lines.push('\n**Spacing:**');
92
+ if (preferences.spacing.defaultBlockGap) {
93
+ lines.push(`- Default block gap: ${preferences.spacing.defaultBlockGap}`);
94
+ }
95
+ if (preferences.spacing.preferMarginOverPadding !== undefined) {
96
+ lines.push(`- Prefer ${preferences.spacing.preferMarginOverPadding ? 'margin' : 'padding'}`);
97
+ }
98
+ }
99
+ // Image preferences
100
+ if (preferences.images) {
101
+ lines.push('\n**Images:**');
102
+ if (preferences.images.defaultSizeSlug) {
103
+ lines.push(`- Default size: ${preferences.images.defaultSizeSlug}`);
104
+ }
105
+ if (preferences.images.preferFigureCaption !== undefined) {
106
+ lines.push(`- Figure caption: ${preferences.images.preferFigureCaption ? 'include' : 'optional'}`);
107
+ }
108
+ }
109
+ return lines.join('\n');
110
+ }
111
+ /**
112
+ * Formats style guide rules section.
113
+ */
114
+ function formatStyleGuideRules(rules) {
115
+ const lines = ['## Style Guide Rules', ''];
116
+ for (const rule of rules) {
117
+ lines.push(`- ${rule}`);
118
+ }
119
+ return lines.join('\n');
120
+ }
121
+ /**
122
+ * Formats style guide examples section.
123
+ */
124
+ function formatStyleGuideExamples(examples) {
125
+ const lines = ['## Design Examples', ''];
126
+ for (const [name, description] of Object.entries(examples)) {
127
+ lines.push(`- **${name}**: ${description}`);
128
+ }
129
+ return lines.join('\n');
130
+ }
131
+ /**
132
+ * Formats brand guidelines section.
133
+ */
134
+ function formatBrandGuidelines(guidelines) {
135
+ const lines = ['## Brand Guidelines', '', 'When creating these elements, use these configurations:'];
136
+ for (const [name, config] of Object.entries(guidelines)) {
137
+ lines.push(`- **${name}**: ${config.block} with ${JSON.stringify(config.props)}`);
138
+ }
139
+ return lines.join('\n');
140
+ }
141
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAA8B;IACvE,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,0BAA0B;IAC1B,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,2BAA2B;IAC3B,IAAI,MAAM,CAAC,UAAU,EAAE,KAAK,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnE,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,UAAU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EAAE,CAAC,CAAC;IACpF,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { layoutPreferencesSchema, blockPreferencesSchema, typographyPreferencesSchema, colorPreferencesSchema, spacingPreferencesSchema, imagePreferencesSchema, preferencesSchema, styleGuideSchema, brandGuidelineSchema, blockPreferencesConfigSchema, } from './schema.js';
2
+ export type { LayoutPreferences, BlocksPreferences, TypographyPreferences, ColorPreferences, SpacingPreferences, ImagePreferences, Preferences, StyleGuide, BrandGuideline, BlockPreferencesConfig, } from './schema.js';
3
+ export { findPreferencesFile, loadPreferencesFromFile, loadPreferences, mergePreferences, createDefaultPreferences, } from './loader.js';
4
+ export { formatPreferencesForPrompt, } from './formatter.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,cAAc,EACd,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Schema and types
2
+ export { layoutPreferencesSchema, blockPreferencesSchema, typographyPreferencesSchema, colorPreferencesSchema, spacingPreferencesSchema, imagePreferencesSchema, preferencesSchema, styleGuideSchema, brandGuidelineSchema, blockPreferencesConfigSchema, } from './schema.js';
3
+ // Loader
4
+ export { findPreferencesFile, loadPreferencesFromFile, loadPreferences, mergePreferences, createDefaultPreferences, } from './loader.js';
5
+ // Formatter
6
+ export { formatPreferencesForPrompt, } from './formatter.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAerB,SAAS;AACT,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,YAAY;AACZ,OAAO,EACL,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type BlockPreferencesConfig } from './schema.js';
2
+ /**
3
+ * Finds a preferences file in the given directory.
4
+ */
5
+ export declare function findPreferencesFile(directory: string): string | null;
6
+ /**
7
+ * Loads preferences from a specific file path.
8
+ */
9
+ export declare function loadPreferencesFromFile(filePath: string): BlockPreferencesConfig;
10
+ /**
11
+ * Loads preferences from a directory (auto-discovers file).
12
+ */
13
+ export declare function loadPreferences(directory: string): BlockPreferencesConfig | null;
14
+ /**
15
+ * Merges multiple preference configs together.
16
+ * Later configs override earlier ones.
17
+ */
18
+ export declare function mergePreferences(...configs: (BlockPreferencesConfig | null | undefined)[]): BlockPreferencesConfig;
19
+ /**
20
+ * Creates a default preferences config.
21
+ */
22
+ export declare function createDefaultPreferences(): BlockPreferencesConfig;
23
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAWxF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQpE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,sBAAsB,CAehF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,sBAAsB,GAAG,IAAI,CAQhF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,OAAO,EAAE,CAAC,sBAAsB,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GACxD,sBAAsB,CAsCxB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,sBAAsB,CAsBjE"}
package/dist/loader.js ADDED
@@ -0,0 +1,113 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { blockPreferencesConfigSchema } from './schema.js';
4
+ /**
5
+ * Known preference file names
6
+ */
7
+ const PREFERENCE_FILE_NAMES = [
8
+ 'block-preferences.json',
9
+ '.blockrc.json',
10
+ '.blockrc',
11
+ ];
12
+ /**
13
+ * Finds a preferences file in the given directory.
14
+ */
15
+ export function findPreferencesFile(directory) {
16
+ for (const fileName of PREFERENCE_FILE_NAMES) {
17
+ const filePath = path.join(directory, fileName);
18
+ if (fs.existsSync(filePath)) {
19
+ return filePath;
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+ /**
25
+ * Loads preferences from a specific file path.
26
+ */
27
+ export function loadPreferencesFromFile(filePath) {
28
+ const content = fs.readFileSync(filePath, 'utf-8');
29
+ const data = JSON.parse(content);
30
+ // Validate against schema
31
+ const result = blockPreferencesConfigSchema.safeParse(data);
32
+ if (!result.success) {
33
+ const errors = result.error.issues.map(issue => `${issue.path.join('.')}: ${issue.message}`);
34
+ throw new Error(`Invalid preferences file: ${errors.join(', ')}`);
35
+ }
36
+ return result.data;
37
+ }
38
+ /**
39
+ * Loads preferences from a directory (auto-discovers file).
40
+ */
41
+ export function loadPreferences(directory) {
42
+ const filePath = findPreferencesFile(directory);
43
+ if (!filePath) {
44
+ return null;
45
+ }
46
+ return loadPreferencesFromFile(filePath);
47
+ }
48
+ /**
49
+ * Merges multiple preference configs together.
50
+ * Later configs override earlier ones.
51
+ */
52
+ export function mergePreferences(...configs) {
53
+ const result = {};
54
+ for (const config of configs) {
55
+ if (!config)
56
+ continue;
57
+ // Merge preferences
58
+ if (config.preferences) {
59
+ result.preferences = {
60
+ ...result.preferences,
61
+ ...config.preferences,
62
+ };
63
+ }
64
+ // Merge style guide
65
+ if (config.styleGuide) {
66
+ result.styleGuide = {
67
+ rules: [
68
+ ...(result.styleGuide?.rules || []),
69
+ ...(config.styleGuide.rules || []),
70
+ ],
71
+ examples: {
72
+ ...result.styleGuide?.examples,
73
+ ...config.styleGuide.examples,
74
+ },
75
+ };
76
+ }
77
+ // Merge brand guidelines
78
+ if (config.brandGuidelines) {
79
+ result.brandGuidelines = {
80
+ ...result.brandGuidelines,
81
+ ...config.brandGuidelines,
82
+ };
83
+ }
84
+ }
85
+ return result;
86
+ }
87
+ /**
88
+ * Creates a default preferences config.
89
+ */
90
+ export function createDefaultPreferences() {
91
+ return {
92
+ preferences: {
93
+ layout: {
94
+ defaultContainerBlock: 'core/group',
95
+ defaultAlignment: 'none',
96
+ preferConstrained: true,
97
+ },
98
+ blocks: {
99
+ preferColumnsOverGrid: true,
100
+ preferButtonsOverLinks: true,
101
+ avoidBlocks: ['core/freeform', 'core/html'],
102
+ },
103
+ typography: {
104
+ defaultHeadingLevel: 2,
105
+ useDropCap: false,
106
+ },
107
+ colors: {
108
+ preferPresetColors: true,
109
+ },
110
+ },
111
+ };
112
+ }
113
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","source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