@marvalt/wparser 0.1.23 → 0.1.24
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/dist/index.cjs +844 -804
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +46 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +844 -805
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts +2 -2
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/registry/enhancedRegistry.d.ts +2 -2
- package/dist/registry/enhancedRegistry.d.ts.map +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +19 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
|
|
3
3
|
type AuthMode = 'cloudflare_proxy' | 'direct' | string;
|
|
4
|
+
/**
|
|
5
|
+
* Maps WordPress theme color names to app-specific CSS classes
|
|
6
|
+
* WordPress controls which color is applied, app controls what it means
|
|
7
|
+
*
|
|
8
|
+
* @param wpColorName - WordPress theme color name (e.g., 'accent-5', 'base', 'contrast')
|
|
9
|
+
* @returns CSS class string (e.g., 'bg-gray-100') or null if no mapping
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const colorMapper: ColorMapper = (wpColorName) => {
|
|
14
|
+
* const colorMap: Record<string, string> = {
|
|
15
|
+
* 'accent-5': 'bg-gray-100',
|
|
16
|
+
* 'base': 'bg-white',
|
|
17
|
+
* 'contrast': 'bg-gray-900',
|
|
18
|
+
* };
|
|
19
|
+
* return wpColorName ? colorMap[wpColorName] || null : null;
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
type ColorMapper = (wpColorName: string | undefined | null) => string | null;
|
|
4
24
|
interface WordPressFeaturedMedia {
|
|
5
25
|
source_url?: string;
|
|
6
26
|
alt_text?: string;
|
|
@@ -29,6 +49,7 @@ interface WordPressPageMinimal {
|
|
|
29
49
|
interface RenderContext {
|
|
30
50
|
registry: ComponentRegistry;
|
|
31
51
|
page?: WordPressPageMinimal;
|
|
52
|
+
colorMapper?: ColorMapper;
|
|
32
53
|
}
|
|
33
54
|
interface BlockRendererProps {
|
|
34
55
|
block: WordPressBlock;
|
|
@@ -47,6 +68,8 @@ interface ComponentRegistry {
|
|
|
47
68
|
shortcodes: Record<string, ShortcodeRenderer>;
|
|
48
69
|
/** Fallback renderer for unknown blocks */
|
|
49
70
|
fallback: BlockRenderer;
|
|
71
|
+
/** Optional color mapper for converting WordPress theme colors to CSS classes */
|
|
72
|
+
colorMapper?: ColorMapper;
|
|
50
73
|
}
|
|
51
74
|
/**
|
|
52
75
|
* Pattern matching for blocks - allows matching blocks by name and attributes
|
|
@@ -99,7 +122,7 @@ interface RenderOptions {
|
|
|
99
122
|
}
|
|
100
123
|
declare function renderNodes(blocks: WordPressBlock[], registry: ComponentRegistry, options?: RenderOptions, page?: WordPressPageMinimal): React$1.ReactNode;
|
|
101
124
|
|
|
102
|
-
declare function createDefaultRegistry(): ComponentRegistry;
|
|
125
|
+
declare function createDefaultRegistry(colorMapper?: ColorMapper): ComponentRegistry;
|
|
103
126
|
|
|
104
127
|
/**
|
|
105
128
|
* Create an enhanced registry that supports pattern-based component mapping
|
|
@@ -129,7 +152,7 @@ declare function createDefaultRegistry(): ComponentRegistry;
|
|
|
129
152
|
* const registry = createEnhancedRegistry(mappings);
|
|
130
153
|
* ```
|
|
131
154
|
*/
|
|
132
|
-
declare function createEnhancedRegistry(mappings?: ComponentMapping[], baseRegistry?: ComponentRegistry): EnhancedRegistry;
|
|
155
|
+
declare function createEnhancedRegistry(mappings?: ComponentMapping[], baseRegistry?: ComponentRegistry, colorMapper?: ColorMapper): EnhancedRegistry;
|
|
133
156
|
|
|
134
157
|
interface WPContentProps {
|
|
135
158
|
blocks: WordPressBlock[];
|
|
@@ -413,6 +436,25 @@ declare function parseContentPosition(contentPosition: string | undefined): {
|
|
|
413
436
|
* Extract video iframe HTML from innerBlocks (finds HTML block with iframe)
|
|
414
437
|
*/
|
|
415
438
|
declare function extractVideoIframeFromInnerBlocks(block: WordPressBlock): string | null;
|
|
439
|
+
/**
|
|
440
|
+
* Extract and map background color from block attributes
|
|
441
|
+
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
442
|
+
*
|
|
443
|
+
* WordPress controls which color is applied (via backgroundColor attribute),
|
|
444
|
+
* app controls what it means (via colorMapper function)
|
|
445
|
+
*
|
|
446
|
+
* @param block - WordPress block to extract background color from
|
|
447
|
+
* @param context - Render context containing optional colorMapper
|
|
448
|
+
* @returns CSS class string (e.g., 'bg-gray-100') or null if no mapping
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* // In WordPress, group block has: backgroundColor: "accent-5"
|
|
453
|
+
* // In app, colorMapper maps: "accent-5" → "bg-gray-100"
|
|
454
|
+
* // Result: extractBackgroundColor returns "bg-gray-100"
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
declare function extractBackgroundColor(block: WordPressBlock, context: RenderContext): string | null;
|
|
416
458
|
|
|
417
459
|
interface ImageConversionOptions {
|
|
418
460
|
/** Convert to Cloudflare variant if URL is already Cloudflare */
|
|
@@ -465,5 +507,5 @@ interface SectionWrapperProps {
|
|
|
465
507
|
*/
|
|
466
508
|
declare const SectionWrapper: React$1.FC<SectionWrapperProps>;
|
|
467
509
|
|
|
468
|
-
export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
469
|
-
export type { AuthMode, BlockPattern, BlockRenderer, BlockRendererProps, CloudflareVariantOptions, ComponentMapping, ComponentRegistry, EnhancedRegistry, ImageConversionOptions, ParseOptions, ParsedShortcode, RenderContext, RenderOptions, SectionWrapperProps, ShortcodeAttributes, ShortcodeRenderer, WPContentProps, WPNode, WPPageProps, WordPressBlock, WordPressEmbedded, WordPressFeaturedMedia, WordPressPageMinimal, WordPressTitleField };
|
|
510
|
+
export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
511
|
+
export type { AuthMode, BlockPattern, BlockRenderer, BlockRendererProps, CloudflareVariantOptions, ColorMapper, ComponentMapping, ComponentRegistry, EnhancedRegistry, ImageConversionOptions, ParseOptions, ParsedShortcode, RenderContext, RenderOptions, SectionWrapperProps, ShortcodeAttributes, ShortcodeRenderer, WPContentProps, WPNode, WPPageProps, WordPressBlock, WordPressEmbedded, WordPressFeaturedMedia, WordPressPageMinimal, WordPressTitleField };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClH,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClH,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC"}
|