@forgewp/compiler 0.1.8 → 0.1.9

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/lib/blueprints.js CHANGED
@@ -1,497 +1,501 @@
1
- /**
2
- * System File Blueprints — ForgeWP Compiler
3
- *
4
- * These are fallback templates used by the compiler's self-healing preflight check.
5
- * If a developer accidentally deletes a system-critical library file,
6
- * the compiler will automatically recreate it to prevent compilation and runtime errors.
7
- */
8
-
9
- export const SYSTEM_BLUEPRINTS = {
10
- "wordpress/mock-data.json": `{
11
- "post": [
12
- {
13
- "id": 1,
14
- "title": "Welcome to ForgeWP: The Headless Revolution",
15
- "excerpt": "Discover how ForgeWP bridges standard WordPress themes with blistering fast React architectures.",
16
- "content": "<p>This is the first mock post. In local dev, you can modify <code>wordpress/mock-data.json</code> to test layout content changes.</p>",
17
- "date": "May 10, 2026",
18
- "author": "Antigravity",
19
- "featuredImage": "https://picsum.photos/seed/forgewp/1200/630",
20
- "customFields": {}
21
- },
22
- {
23
- "id": 2,
24
- "title": "Unlocking Brutalist Web Design Aesthetics",
25
- "excerpt": "A deep dive into high-contrast grids, sharp corners, and premium flat shadows in modern interfaces.",
26
- "content": "<p>This is the second mock post. Style these grids using beautiful Tailwind utilities.</p>",
27
- "date": "May 12, 2026",
28
- "author": "DeepMind Partner",
29
- "featuredImage": "https://picsum.photos/seed/brutalist/1200/630",
30
- "customFields": {}
31
- }
32
- ],
33
- "project": [
34
- {
35
- "id": 1,
36
- "title": "ForgeWP Scaffolding Platform",
37
- "excerpt": "Building a custom compiler framework to transpile React elements into standard PHP themes.",
38
- "content": "<p>Detailed description of the ForgeWP compiler pipeline project.</p>",
39
- "date": "May 15, 2026",
40
- "author": "Lead Architect",
41
- "featuredImage": "https://picsum.photos/seed/platform/1200/630",
42
- "customFields": {
43
- "client_name": "El Dorado",
44
- "project_budget": "$45,000"
45
- }
46
- },
47
- {
48
- "id": 2,
49
- "title": "Brutalist Starter Theme",
50
- "excerpt": "A clean, responsive, and robust high-contrast interface leveraging Tailwind CSS v4.",
51
- "content": "<p>A brutalist theme showcasing raw black borders and vivid accent colors.</p>",
52
- "date": "May 16, 2026",
53
- "author": "Theme Engineer",
54
- "featuredImage": "https://picsum.photos/seed/starter/1200/630",
55
- "customFields": {
56
- "client_name": "ForgeWP Community",
57
- "project_budget": "Open Source"
58
- }
59
- }
60
- ]
61
- }`,
62
-
63
- "src/lib/wordpress.tsx": `/**
64
- * ForgeWP WordPress Data Hooks
65
- *
66
- * These hooks provide mock data during local development (Vite dev server).
67
- * When the theme is exported, the ForgeWP compiler replaces every token
68
- * with the equivalent WordPress PHP function call.
69
- */
70
- import React, { createContext, useContext } from "react";
71
-
72
- // @ts-ignore
73
- import mockData from "../../wordpress/mock-data.json";
74
-
75
- const IS_DEV =
76
- typeof import.meta !== "undefined" &&
77
- // @ts-ignore
78
- import.meta.env?.DEV === true;
79
-
80
- // React context to support database-like query loops during local development
81
- const WpPostContext = createContext<any>(null);
82
-
83
- // ── Post content ─────────────────────────────────────────────────────────────
84
-
85
- export function useWpTitle() {
86
- if (IS_DEV) {
87
- const post = useContext(WpPostContext);
88
- return post?.title || "Sample WordPress Post Title";
89
- }
90
- return "__FORGEWP_THE_TITLE__";
91
- }
92
-
93
- export function useWpContent() {
94
- if (IS_DEV) {
95
- const post = useContext(WpPostContext);
96
- return post?.content || "<p>This is sample post content rendered locally so you can design your theme. In WordPress, this is replaced by the actual content from the Gutenberg editor — including blocks, shortcodes, and embeds.</p>";
97
- }
98
- return "__FORGEWP_THE_CONTENT__";
99
- }
100
-
101
- export function useWpExcerpt() {
102
- if (IS_DEV) {
103
- const post = useContext(WpPostContext);
104
- return post?.excerpt || "A short excerpt that gives readers a quick preview of what to expect in the full post.";
105
- }
106
- return "__FORGEWP_THE_EXCERPT__";
107
- }
108
-
109
- export function useWpPermalink() {
110
- if (IS_DEV) {
111
- const post = useContext(WpPostContext);
112
- return post ? \`/post/\${post.id}\` : "/post";
113
- }
114
- return "__FORGEWP_THE_PERMALINK__";
115
- }
116
-
117
- // ── Post meta ─────────────────────────────────────────────────────────────────
118
-
119
- export function useWpDate() {
120
- if (IS_DEV) {
121
- const post = useContext(WpPostContext);
122
- return post?.date || new Date().toLocaleDateString("en-US", {
123
- year: "numeric",
124
- month: "long",
125
- day: "numeric",
126
- });
127
- }
128
- return "__FORGEWP_THE_DATE__";
129
- }
130
-
131
- export function useWpAuthor() {
132
- if (IS_DEV) {
133
- const post = useContext(WpPostContext);
134
- return post?.author || "Jane Doe";
135
- }
136
- return "__FORGEWP_THE_AUTHOR__";
137
- }
138
-
139
- export function useWpFeaturedImage() {
140
- if (IS_DEV) {
141
- const post = useContext(WpPostContext);
142
- return post?.featuredImage || "https://picsum.photos/seed/forgewp/1200/630";
143
- }
144
- return "__FORGEWP_THE_POST_THUMBNAIL_URL__";
145
- }
146
-
147
- export function useWpCategories() {
148
- if (IS_DEV) {
149
- return '<a href="#">Technology</a>, <a href="#">Design</a>';
150
- }
151
- return "__FORGEWP_THE_CATEGORY_LIST__";
152
- }
153
-
154
- export function useWpArchiveTitle() {
155
- if (IS_DEV) return "Category: Technology";
156
- return "__FORGEWP_THE_ARCHIVE_TITLE__";
157
- }
158
-
159
- // ── Loop ──────────────────────────────────────────────────────────────────────
160
-
161
- export function WpLoop({ children }: { children: React.ReactNode }) {
162
- if (IS_DEV) {
163
- const posts = mockData?.post || [
164
- { id: 1, title: "Mock Post 1" },
165
- { id: 2, title: "Mock Post 2" },
166
- { id: 3, title: "Mock Post 3" }
167
- ];
168
-
169
- return (
170
- <>
171
- {posts.map((post: any) => (
172
- <WpPostContext.Provider key={post.id} value={post}>
173
- {children}
174
- </WpPostContext.Provider>
175
- ))}
176
- </>
177
- );
178
- }
179
-
180
- return (
181
- <>
182
- {/* @ts-ignore */}
183
- <forgewp-loop-start />
184
- {children}
185
- {/* @ts-ignore */}
186
- <forgewp-loop-end />
187
- </>
188
- );
189
- }
190
-
191
- // ── Custom Field Mapping (ACF / Meta Fields) ──────────────────────────────────
192
-
193
- export function useWpCustomField(fieldName: string, defaultValue: string = ""): string {
194
- if (IS_DEV) {
195
- const post = useContext(WpPostContext);
196
- if (post && post.customFields && typeof post.customFields[fieldName] !== "undefined") {
197
- return post.customFields[fieldName];
198
- }
199
- return defaultValue || "[Mock custom field: " + fieldName + "]";
200
- }
201
- return "__FORGEWP_CUSTOM_FIELD__" + fieldName + "__";
202
- }
203
-
204
- // ── Navigation Menu Component ──────────────────────────────────────────────────
205
-
206
- export interface WpMenuProps {
207
- location?: string;
208
- className?: string;
209
- linkClassName?: string;
210
- }
211
-
212
- export function WpMenu({ location = "primary", className = "", linkClassName = "" }: WpMenuProps) {
213
- if (IS_DEV) {
214
- const mockItems = [
215
- { title: "Home", url: "/" },
216
- { title: "Blog", url: "/post" },
217
- { title: "Archive", url: "/archive" },
218
- ];
219
- return (
220
- <nav className={className}>
221
- {mockItems.map((item, idx) => (
222
- <a key={idx} href={item.url} className={linkClassName}>
223
- {item.title}
224
- </a>
225
- ))}
226
- </nav>
227
- );
228
- }
229
-
230
- return (
231
- // @ts-ignore
232
- <forgewp-menu location={location} className={className} linkClassName={linkClassName} />
233
- );
234
- }
235
-
236
- // ── Custom Query Loop Component ───────────────────────────────────────────────
237
-
238
- export interface WpQueryLoopProps {
239
- postType?: string;
240
- postsPerPage?: number;
241
- categoryName?: string;
242
- children: React.ReactNode;
243
- }
244
-
245
- export function WpQueryLoop({
246
- postType = "post",
247
- postsPerPage = 3,
248
- categoryName = "",
249
- children
250
- }: WpQueryLoopProps) {
251
- if (IS_DEV) {
252
- const allPosts = (mockData as any)?.[postType] || [];
253
- const posts = allPosts.slice(0, postsPerPage);
254
-
255
- if (posts.length === 0) {
256
- const fallbacks = Array.from({ length: postsPerPage }).map((_, i) => ({
257
- id: i + 1,
258
- title: \`Mock \${postType} \${i + 1}\`,
259
- }));
260
- return (
261
- <>
262
- {fallbacks.map((post: any) => (
263
- <WpPostContext.Provider key={post.id} value={post}>
264
- {children}
265
- </WpPostContext.Provider>
266
- ))}
267
- </>
268
- );
269
- }
270
-
271
- return (
272
- <>
273
- {posts.map((post: any) => (
274
- <WpPostContext.Provider key={post.id} value={post}>
275
- {children}
276
- </WpPostContext.Provider>
277
- ))}
278
- </>
279
- );
280
- }
281
-
282
- return (
283
- <>
284
- {/* @ts-ignore */}
285
- <forgewp-query-loop-start postType={postType} postsPerPage={postsPerPage} categoryName={categoryName} />
286
- {children}
287
- {/* @ts-ignore */}
288
- <forgewp-query-loop-end />
289
- </>
290
- );
291
- }
292
-
293
- // ── Shortcodes Component ────────────────────────────────────────────────────────
294
-
295
- export interface WpShortcodeProps {
296
- code: string;
297
- }
298
-
299
- export function WpShortcode({ code }: WpShortcodeProps) {
300
- if (IS_DEV) {
301
- return (
302
- <div className="p-4 bg-zinc-100 border-2 border-dashed border-zinc-400 font-mono text-xs text-zinc-600 rounded-none my-4">
303
- <span className="font-bold text-zinc-800">WordPress Shortcode Preview:</span> {code}
304
- </div>
305
- );
306
- }
307
-
308
- return (
309
- // @ts-ignore
310
- <forgewp-shortcode code={code} />
311
- );
312
- }
313
- `,
314
-
315
- "src/lib/SEO.tsx": `import * as ReactHelmetAsync from "react-helmet-async";
316
- import { useWpTitle } from "./wordpress";
317
-
318
- // Support both ESM and CommonJS exports of react-helmet-async across Vite and TSX compiler
319
- const Helmet = (ReactHelmetAsync.Helmet || (ReactHelmetAsync as any)["default"]?.Helmet || ReactHelmetAsync) as any;
320
-
321
- /**
322
- * ForgeWP SEO — Internal system file. Do not delete.
323
- *
324
- * Use this component in \`src/app/layout.tsx\` to set global SEO defaults,
325
- * and in individual page files to override them per-page.
326
- *
327
- * The ForgeWP compiler reads the props you pass here and injects them
328
- * directly into the WordPress theme's <head> as native meta tags.
329
- *
330
- * @see https://forgewp.dev/docs/seo
331
- */
332
-
333
- export interface SEOProps {
334
- /** Page title — defaults to the WordPress post title via useWpTitle() */
335
- title?: string;
336
- /** Meta description for search engines and social cards */
337
- description?: string;
338
- /** Comma-separated keywords */
339
- keywords?: string;
340
- /** Open Graph title (falls back to title if omitted) */
341
- ogTitle?: string;
342
- /** Open Graph description (falls back to description if omitted) */
343
- ogDescription?: string;
344
- /** Absolute URL to the Open Graph image */
345
- ogImage?: string;
346
- /** Open Graph type — "website" for homepages, "article" for posts */
347
- ogType?: string;
348
- /** Twitter card type */
349
- twitterCard?: string;
350
- /** Twitter creator handle, e.g. "@username" */
351
- twitterCreator?: string;
352
- /** Canonical URL — tells search engines the preferred version of this page */
353
- canonical?: string;
354
- /** Set to true to prevent this page from being indexed by search engines */
355
- noIndex?: boolean;
356
- }
357
-
358
- /**
359
- * \`<SEO>\` — ForgeWP SEO manager.
360
- *
361
- * Drop this into your **layout.tsx** to set site-wide defaults.
362
- * Then drop it into any **page file** to override for that specific template.
363
- *
364
- * @example
365
- * // layout.tsx — global defaults (the compiler reads these for all pages)
366
- * <SEO
367
- * description="Your site tagline or description."
368
- * keywords="WordPress, React, Tailwind"
369
- * ogImage="https://yoursite.com/og-default.png"
370
- * />
371
- *
372
- * @example
373
- * // single.tsx — per-page override (article-specific metadata)
374
- * <SEO
375
- * ogType="article"
376
- * ogImage="https://yoursite.com/og-post.png"
377
- * twitterCreator="@yourhandle"
378
- * />
379
- */
380
- export function SEO({
381
- title,
382
- description = "A WordPress theme built with ForgeWP — React & Tailwind CSS.",
383
- keywords = "WordPress, React, Tailwind CSS, ForgeWP",
384
- ogTitle,
385
- ogDescription,
386
- ogImage,
387
- ogType = "website",
388
- twitterCard = "summary_large_image",
389
- twitterCreator,
390
- canonical,
391
- noIndex = false,
392
- }: SEOProps) {
393
- const wpTitle = useWpTitle();
394
- const resolvedTitle = title ?? wpTitle;
395
-
396
- return (
397
- <Helmet>
398
- {/* ── Primary ── */}
399
- <title>{resolvedTitle}</title>
400
- <meta name="description" content={description} />
401
- {keywords && <meta name="keywords" content={keywords} />}
402
- {noIndex && <meta name="robots" content="noindex, nofollow" />}
403
- {canonical && <link rel="canonical" href={canonical} />}
404
-
405
- {/* ── Open Graph ── */}
406
- <meta property="og:type" content={ogType} />
407
- <meta property="og:title" content={ogTitle ?? resolvedTitle} />
408
- <meta property="og:description" content={ogDescription ?? description} />
409
- {ogImage && <meta property="og:image" content={ogImage} />}
410
-
411
- {/* ── Twitter ── */}
412
- <meta name="twitter:card" content={twitterCard} />
413
- <meta name="twitter:title" content={ogTitle ?? resolvedTitle} />
414
- <meta name="twitter:description" content={ogDescription ?? description} />
415
- {ogImage && <meta name="twitter:image" content={ogImage} />}
416
- {twitterCreator && <meta name="twitter:creator" content={twitterCreator} />}
417
- </Helmet>
418
- );
419
- }
420
- `,
421
-
422
- "src/lib/PresetsStyle.tsx": `import wpConfig from "../../wp.config";
423
-
424
- const IS_DEV =
425
- typeof import.meta !== "undefined" &&
426
- // @ts-ignore
427
- import.meta.env?.DEV === true;
428
-
429
- /**
430
- * PresetsStyle component — Internal system component.
431
- *
432
- * Dynamically injects WordPress-preset CSS Custom Properties and enqueues Google Fonts
433
- * during local Vite development, keeping your styles perfectly in sync with WordPress.
434
- * In production builds, this returns only the registry-aesthetic design tokens (like --radius)
435
- * to keep shadcn components and theme variables responsive to your config.
436
- */
437
- export function PresetsStyle() {
438
- const themeStyle = wpConfig.style || "forgewp";
439
-
440
- // Production build: only inject custom registry-aesthetic design properties
441
- if (!IS_DEV) {
442
- const prodCss = \`
443
- :root {
444
- --radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
445
- --radius-sm: calc(var(--radius) - 4px);
446
- --radius-md: calc(var(--radius) - 2px);
447
- --radius-lg: var(--radius);
448
- --border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
449
- --border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
450
- --shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
451
- }
452
- \`;
453
- return <style dangerouslySetInnerHTML={{ __html: prodCss }} />;
454
- }
455
-
456
- // Local development fallbacks for WordPress CSS presets
457
- const colors = wpConfig.settings?.color?.palette || [];
458
- const fontSizes = wpConfig.settings?.typography?.fontSizes || [];
459
- const fontFamilies = wpConfig.settings?.typography?.fontFamilies || [];
460
- const layout = wpConfig.settings?.layout || {};
461
- const googleFonts = wpConfig.settings?.typography?.googleFonts || [];
462
-
463
- // Parse and build Google Fonts href for dev injection
464
- const fontsHtml = googleFonts.length > 0
465
- ? \`<link rel="preconnect" href="https://fonts.googleapis.com">
466
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
467
- <link href="https://fonts.googleapis.com/css2?family=\&{googleFonts.map(f => encodeURIComponent(f)).join("&family=")}&display=swap" rel="stylesheet">\`
468
- : "";
469
-
470
- const devCss = \`
471
- :root {
472
- \${colors.map((c) => "--wp--preset--color--" + c.slug + ": " + c.color + ";").join("\\n ")}
473
- \${fontSizes.map((f) => "--wp--preset--font-size--" + f.slug + ": " + f.size + ";").join("\\n ")}
474
- \${fontFamilies.map((f) => "--wp--preset--font-family--" + f.slug + ": " + f.fontFamily + ";").join("\\n ")}
475
- \${layout.contentSize ? "--wp--style--global--content-size: " + layout.contentSize + ";" : ""}
476
- \${layout.wideSize ? "--wp--style--global--wide-size: " + layout.wideSize + ";" : ""}
477
-
478
- /* Registry Aesthetic Mode Custom Properties */
479
- --radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
480
- --radius-sm: calc(var(--radius) - 4px);
481
- --radius-md: calc(var(--radius) - 2px);
482
- --radius-lg: var(--radius);
483
- --border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
484
- --border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
485
- --shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
486
- }
487
- \`;
488
-
489
- return (
490
- <>
491
- {fontsHtml && <span dangerouslySetInnerHTML={{ __html: fontsHtml }} />}
492
- <style dangerouslySetInnerHTML={{ __html: devCss }} />
493
- </>
494
- );
495
- }
496
- `
497
- };
1
+ /**
2
+ * System File Blueprints — ForgeWP Compiler
3
+ *
4
+ * These are fallback templates used by the compiler's self-healing preflight check.
5
+ * If a developer accidentally deletes a system-critical library file,
6
+ * the compiler will automatically recreate it to prevent compilation and runtime errors.
7
+ */
8
+
9
+ export const SYSTEM_BLUEPRINTS = {
10
+ "wordpress/menus.json": `{
11
+ "_comment": "⚡ ForgeWP Navigation Menus — Edit this file to add/remove links in local dev. Run 'pnpm forgewp sync:routes' to auto-scaffold corresponding React pages!",
12
+ "primary": [
13
+ { "title": "Home", "url": "/" },
14
+ { "title": "New", "url": "/new" },
15
+ { "title": "Men", "url": "/men" },
16
+ { "title": "Women", "url": "/women" }
17
+ ],
18
+ "utility": [
19
+ { "title": "Help", "url": "/help" },
20
+ { "title": "Sign In", "url": "/login" }
21
+ ]
22
+ }`,
23
+
24
+ "wordpress/mock-data.json": `{
25
+ "post": [
26
+ {
27
+ "id": 1,
28
+ "title": "Welcome to ForgeWP: The Headless Revolution",
29
+ "excerpt": "Discover how ForgeWP bridges standard WordPress themes with blistering fast React architectures.",
30
+ "content": "<p>This is the first mock post. In local dev, you can modify <code>wordpress/mock-data.json</code> to test layout content changes.</p>",
31
+ "date": "May 10, 2026",
32
+ "author": "Antigravity",
33
+ "featuredImage": "https://picsum.photos/seed/forgewp/1200/630",
34
+ "customFields": {}
35
+ },
36
+ {
37
+ "id": 2,
38
+ "title": "Unlocking Brutalist Web Design Aesthetics",
39
+ "excerpt": "A deep dive into high-contrast grids, sharp corners, and premium flat shadows in modern interfaces.",
40
+ "content": "<p>This is the second mock post. Style these grids using beautiful Tailwind utilities.</p>",
41
+ "date": "May 12, 2026",
42
+ "author": "DeepMind Partner",
43
+ "featuredImage": "https://picsum.photos/seed/brutalist/1200/630",
44
+ "customFields": {}
45
+ }
46
+ ],
47
+ "project": [
48
+ {
49
+ "id": 1,
50
+ "title": "ForgeWP Scaffolding Platform",
51
+ "excerpt": "Building a custom compiler framework to transpile React elements into standard PHP themes.",
52
+ "content": "<p>Detailed description of the ForgeWP compiler pipeline project.</p>",
53
+ "date": "May 15, 2026",
54
+ "author": "Lead Architect",
55
+ "featuredImage": "https://picsum.photos/seed/platform/1200/630",
56
+ "customFields": {
57
+ "client_name": "El Dorado",
58
+ "project_budget": "$45,000"
59
+ }
60
+ },
61
+ {
62
+ "id": 2,
63
+ "title": "Brutalist Starter Theme",
64
+ "excerpt": "A clean, responsive, and robust high-contrast interface leveraging Tailwind CSS v4.",
65
+ "content": "<p>A brutalist theme showcasing raw black borders and vivid accent colors.</p>",
66
+ "date": "May 16, 2026",
67
+ "author": "Theme Engineer",
68
+ "featuredImage": "https://picsum.photos/seed/starter/1200/630",
69
+ "customFields": {
70
+ "client_name": "ForgeWP Community",
71
+ "project_budget": "Open Source"
72
+ }
73
+ }
74
+ ]
75
+ }`,
76
+
77
+ "src/.forgewp/forgewp-config.ts": `export interface ColorPreset {
78
+ name: string;
79
+ slug: string;
80
+ color: string;
81
+ }
82
+
83
+ export interface FontSizePreset {
84
+ name: string;
85
+ slug: string;
86
+ size: string;
87
+ }
88
+
89
+ export interface FontFamilyPreset {
90
+ name: string;
91
+ slug: string;
92
+ fontFamily: string;
93
+ }
94
+
95
+ export interface ForgeWPThemeConfig {
96
+ name: string;
97
+ slug: string;
98
+ version: string;
99
+ description: string;
100
+ textDomain: string;
101
+ /** Design aesthetic style — "forgewp" (sharp edges, high-contrast) or "shadcn" (smooth rounded modern) */
102
+ style?: "forgewp" | "shadcn";
103
+ // Design Tokens (Phase 5)
104
+ settings?: {
105
+ layout?: {
106
+ contentSize?: string;
107
+ wideSize?: string;
108
+ };
109
+ color?: {
110
+ palette?: ColorPreset[];
111
+ custom?: boolean;
112
+ };
113
+ typography?: {
114
+ fontSizes?: FontSizePreset[];
115
+ fontFamilies?: FontFamilyPreset[];
116
+ googleFonts?: string[];
117
+ };
118
+ };
119
+ }
120
+ `,
121
+
122
+ "src/.forgewp/wordpress.tsx": `/**
123
+ * ForgeWP WordPress Data Hooks
124
+ *
125
+ * These hooks provide mock data during local development (Vite dev server).
126
+ * When the theme is exported, the ForgeWP compiler replaces every token
127
+ * with the equivalent WordPress PHP function call.
128
+ */
129
+ import React from "react";
130
+
131
+ // @ts-ignore
132
+ import mockData from "../../wordpress/mock-data.json";
133
+ // @ts-ignore
134
+ import menusData from "../../wordpress/menus.json";
135
+
136
+ import {
137
+ WpQueryLoop as _WpQueryLoop,
138
+ WpMenu as _WpMenu,
139
+ WpShortcode,
140
+ useWpTitle as _useWpTitle,
141
+ useWpContent as _useWpContent,
142
+ useWpExcerpt as _useWpExcerpt,
143
+ useWpPermalink as _useWpPermalink,
144
+ useWpDate as _useWpDate,
145
+ useWpAuthor as _useWpAuthor,
146
+ useWpFeaturedImage as _useWpFeaturedImage,
147
+ useWpCustomField as _useWpCustomField,
148
+ } from "@forgewp/react";
149
+ import type { WpQueryLoopProps, WpMenuProps } from "@forgewp/react";
150
+
151
+ const IS_DEV =
152
+ typeof import.meta !== "undefined" &&
153
+ // @ts-ignore
154
+ import.meta.env?.DEV === true;
155
+
156
+ // ── Re-export pure hooks with compiler token fallbacks ────────────────────────
157
+ // In dev: @forgewp/react hook returns the mock value from WpPostContext.
158
+ // In prod: compiler replaces the call with the PHP equivalent below.
159
+
160
+ export function useWpTitle(): string {
161
+ if (IS_DEV) return _useWpTitle();
162
+ return "__FORGEWP_THE_TITLE__";
163
+ }
164
+ export function useWpContent(): string {
165
+ if (IS_DEV) return _useWpContent();
166
+ return "__FORGEWP_THE_CONTENT__";
167
+ }
168
+ export function useWpExcerpt(): string {
169
+ if (IS_DEV) return _useWpExcerpt();
170
+ return "__FORGEWP_THE_EXCERPT__";
171
+ }
172
+ export function useWpPermalink(): string {
173
+ if (IS_DEV) return _useWpPermalink();
174
+ return "__FORGEWP_THE_PERMALINK__";
175
+ }
176
+ export function useWpDate(): string {
177
+ if (IS_DEV) return _useWpDate();
178
+ return "__FORGEWP_THE_DATE__";
179
+ }
180
+ export function useWpAuthor(): string {
181
+ if (IS_DEV) return _useWpAuthor();
182
+ return "__FORGEWP_THE_AUTHOR__";
183
+ }
184
+ export function useWpFeaturedImage(): string {
185
+ if (IS_DEV) return _useWpFeaturedImage();
186
+ return "__FORGEWP_THE_POST_THUMBNAIL_URL__";
187
+ }
188
+ export function useWpCustomField(fieldName: string, defaultValue = ""): string {
189
+ if (IS_DEV) return _useWpCustomField(fieldName, defaultValue);
190
+ return "__FORGEWP_CUSTOM_FIELD__" + fieldName + "__";
191
+ }
192
+
193
+ export function useWpCategories(): string {
194
+ if (IS_DEV) return '<a href="#">Technology</a>, <a href="#">Design</a>';
195
+ return "__FORGEWP_THE_CATEGORY_LIST__";
196
+ }
197
+ export function useWpArchiveTitle(): string {
198
+ if (IS_DEV) return "Category: Technology";
199
+ return "__FORGEWP_THE_ARCHIVE_TITLE__";
200
+ }
201
+
202
+ // ── WpQueryLoop — data bridge wraps @forgewp/react with mock data ─────────────
203
+
204
+ export function WpQueryLoop({
205
+ postType = "post",
206
+ postsPerPage = 3,
207
+ categoryName = "",
208
+ children,
209
+ }: WpQueryLoopProps) {
210
+ if (IS_DEV) {
211
+ const posts = (mockData as any)?.[postType] || [];
212
+ return (
213
+ <_WpQueryLoop posts={posts} postType={postType} postsPerPage={postsPerPage} categoryName={categoryName}>
214
+ {children}
215
+ </_WpQueryLoop>
216
+ );
217
+ }
218
+
219
+ // Production: compiler transforms these custom elements into WordPress loop PHP
220
+ return (
221
+ <>
222
+ {/* @ts-ignore */}
223
+ <forgewp-query-loop-start postType={postType} postsPerPage={postsPerPage} categoryName={categoryName} />
224
+ {children}
225
+ {/* @ts-ignore */}
226
+ <forgewp-query-loop-end />
227
+ </>
228
+ );
229
+ }
230
+
231
+ // ── WpLoop — simple all-posts loop (no postType arg) ─────────────────────────
232
+
233
+ export function WpLoop({ children }: { children: React.ReactNode }) {
234
+ if (IS_DEV) {
235
+ const posts = (mockData as any)?.post || [];
236
+ return (
237
+ <_WpQueryLoop posts={posts}>
238
+ {children}
239
+ </_WpQueryLoop>
240
+ );
241
+ }
242
+ return (
243
+ <>
244
+ {/* @ts-ignore */}
245
+ <forgewp-loop-start />
246
+ {children}
247
+ {/* @ts-ignore */}
248
+ <forgewp-loop-end />
249
+ </>
250
+ );
251
+ }
252
+
253
+ // ── WpMenu — data bridge wraps @forgewp/react with menus.json ────────────────
254
+
255
+ export function WpMenu({ location = "primary", className = "", linkClassName = "" }: WpMenuProps) {
256
+ if (IS_DEV) {
257
+ const items =
258
+ (menusData as any)?.[location] ||
259
+ (mockData as any).menu?.[location] ||
260
+ [{ title: "Home", url: "/" }, { title: "Blog", url: "/post" }];
261
+ return <_WpMenu items={items} location={location} className={className} linkClassName={linkClassName} />;
262
+ }
263
+
264
+ // Production: compiler transforms this into wp_nav_menu()
265
+ return (
266
+ // @ts-ignore
267
+ <forgewp-menu location={location} className={className} linkClassName={linkClassName} />
268
+ );
269
+ }
270
+
271
+ // ── WpShortcode — pass-through, no data bridging needed ──────────────────────
272
+ export { WpShortcode };
273
+
274
+ // ── Compiler custom element JSX declarations ──────────────────────────────────
275
+
276
+ declare global {
277
+ namespace React {
278
+ namespace JSX {
279
+ interface IntrinsicElements {
280
+ "forgewp-menu": React.DetailedHTMLProps<
281
+ React.HTMLAttributes<HTMLElement> & {
282
+ location?: "primary" | "footer" | "sidebar";
283
+ linkClassName?: string;
284
+ },
285
+ HTMLElement
286
+ >;
287
+ "forgewp-query-loop-start": React.DetailedHTMLProps<
288
+ React.HTMLAttributes<HTMLElement> & {
289
+ postType?: string;
290
+ postsPerPage?: number;
291
+ categoryName?: string;
292
+ },
293
+ HTMLElement
294
+ >;
295
+ "forgewp-query-loop-end": React.DetailedHTMLProps<
296
+ React.HTMLAttributes<HTMLElement>,
297
+ HTMLElement
298
+ >;
299
+ "forgewp-loop-start": React.DetailedHTMLProps<
300
+ React.HTMLAttributes<HTMLElement>,
301
+ HTMLElement
302
+ >;
303
+ "forgewp-loop-end": React.DetailedHTMLProps<
304
+ React.HTMLAttributes<HTMLElement>,
305
+ HTMLElement
306
+ >;
307
+ "forgewp-shortcode": React.DetailedHTMLProps<
308
+ React.HTMLAttributes<HTMLElement> & {
309
+ code?: string;
310
+ },
311
+ HTMLElement
312
+ >;
313
+ }
314
+ }
315
+ }
316
+ }
317
+ `,
318
+
319
+ "src/.forgewp/SEO.tsx": `import * as ReactHelmetAsync from "react-helmet-async";
320
+ import { useWpTitle } from "./wordpress";
321
+
322
+ // Support both ESM and CommonJS exports of react-helmet-async across Vite and TSX compiler
323
+ const Helmet = (ReactHelmetAsync.Helmet || (ReactHelmetAsync as any)["default"]?.Helmet || ReactHelmetAsync) as any;
324
+
325
+ /**
326
+ * ForgeWP SEO — Internal system file. Do not delete.
327
+ *
328
+ * Use this component in \`src/app/layout.tsx\` to set global SEO defaults,
329
+ * and in individual page files to override them per-page.
330
+ *
331
+ * The ForgeWP compiler reads the props you pass here and injects them
332
+ * directly into the WordPress theme's <head> as native meta tags.
333
+ *
334
+ * @see https://forgewp.dev/docs/seo
335
+ */
336
+
337
+ export interface SEOProps {
338
+ /** Page title — defaults to the WordPress post title via useWpTitle() */
339
+ title?: string;
340
+ /** Meta description for search engines and social cards */
341
+ description?: string;
342
+ /** Comma-separated keywords */
343
+ keywords?: string;
344
+ /** Open Graph title (falls back to title if omitted) */
345
+ ogTitle?: string;
346
+ /** Open Graph description (falls back to description if omitted) */
347
+ ogDescription?: string;
348
+ /** Absolute URL to the Open Graph image */
349
+ ogImage?: string;
350
+ /** Open Graph type — "website" for homepages, "article" for posts */
351
+ ogType?: string;
352
+ /** Twitter card type */
353
+ twitterCard?: string;
354
+ /** Twitter creator handle, e.g. "@username" */
355
+ twitterCreator?: string;
356
+ /** Canonical URL — tells search engines the preferred version of this page */
357
+ canonical?: string;
358
+ /** Set to true to prevent this page from being indexed by search engines */
359
+ noIndex?: boolean;
360
+ }
361
+
362
+ /**
363
+ * \`<SEO>\` — ForgeWP SEO manager.
364
+ *
365
+ * Drop this into your **layout.tsx** to set site-wide defaults.
366
+ * Then drop it into any **page file** to override for that specific template.
367
+ *
368
+ * @example
369
+ * // layout.tsx — global defaults (the compiler reads these for all pages)
370
+ * <SEO
371
+ * description="Your site tagline or description."
372
+ * keywords="WordPress, React, Tailwind"
373
+ * ogImage="https://yoursite.com/og-default.png"
374
+ * />
375
+ *
376
+ * @example
377
+ * // single.tsx — per-page override (article-specific metadata)
378
+ * <SEO
379
+ * ogType="article"
380
+ * ogImage="https://yoursite.com/og-post.png"
381
+ * twitterCreator="@yourhandle"
382
+ * />
383
+ */
384
+ export function SEO({
385
+ title,
386
+ description = "A WordPress theme built with ForgeWP — React & Tailwind CSS.",
387
+ keywords = "WordPress, React, Tailwind CSS, ForgeWP",
388
+ ogTitle,
389
+ ogDescription,
390
+ ogImage,
391
+ ogType = "website",
392
+ twitterCard = "summary_large_image",
393
+ twitterCreator,
394
+ canonical,
395
+ noIndex = false,
396
+ }: SEOProps) {
397
+ const wpTitle = useWpTitle();
398
+ const resolvedTitle = title ?? wpTitle;
399
+
400
+ return (
401
+ <Helmet>
402
+ {/* ── Primary ── */}
403
+ <title>{resolvedTitle}</title>
404
+ <meta name="description" content={description} />
405
+ {keywords && <meta name="keywords" content={keywords} />}
406
+ {noIndex && <meta name="robots" content="noindex, nofollow" />}
407
+ {canonical && <link rel="canonical" href={canonical} />}
408
+
409
+ {/* ── Open Graph ── */}
410
+ <meta property="og:type" content={ogType} />
411
+ <meta property="og:title" content={ogTitle ?? resolvedTitle} />
412
+ <meta property="og:description" content={ogDescription ?? description} />
413
+ {ogImage && <meta property="og:image" content={ogImage} />}
414
+
415
+ {/* ── Twitter ── */}
416
+ <meta name="twitter:card" content={twitterCard} />
417
+ <meta name="twitter:title" content={ogTitle ?? resolvedTitle} />
418
+ <meta name="twitter:description" content={ogDescription ?? description} />
419
+ {ogImage && <meta name="twitter:image" content={ogImage} />}
420
+ {twitterCreator && <meta name="twitter:creator" content={twitterCreator} />}
421
+ </Helmet>
422
+ );
423
+ }
424
+ `,
425
+
426
+ "src/.forgewp/PresetsStyle.tsx": `import wpConfig from "../../wp.config";
427
+
428
+ const IS_DEV =
429
+ typeof import.meta !== "undefined" &&
430
+ // @ts-ignore
431
+ import.meta.env?.DEV === true;
432
+
433
+ /**
434
+ * PresetsStyle component — Internal system component.
435
+ *
436
+ * Dynamically injects WordPress-preset CSS Custom Properties and enqueues Google Fonts
437
+ * during local Vite development, keeping your styles perfectly in sync with WordPress.
438
+ * In production builds, this returns only the registry-aesthetic design tokens (like --radius)
439
+ * to keep shadcn components and theme variables responsive to your config.
440
+ */
441
+ export function PresetsStyle() {
442
+ const themeStyle = wpConfig.style || "forgewp";
443
+
444
+ // Production build: only inject custom registry-aesthetic design properties
445
+ if (!IS_DEV) {
446
+ const prodCss = \`
447
+ :root {
448
+ --radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
449
+ --radius-sm: calc(var(--radius) - 4px);
450
+ --radius-md: calc(var(--radius) - 2px);
451
+ --radius-lg: var(--radius);
452
+ --border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
453
+ --border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
454
+ --shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
455
+ }
456
+ \`;
457
+ return <style dangerouslySetInnerHTML={{ __html: prodCss }} />;
458
+ }
459
+
460
+ // Local development fallbacks for WordPress CSS presets
461
+ const colors = wpConfig.settings?.color?.palette || [];
462
+ const fontSizes = wpConfig.settings?.typography?.fontSizes || [];
463
+ const fontFamilies = wpConfig.settings?.typography?.fontFamilies || [];
464
+ const layout = wpConfig.settings?.layout || {};
465
+ const googleFonts = wpConfig.settings?.typography?.googleFonts || [];
466
+
467
+ // Parse and build Google Fonts href for dev injection
468
+ const fontsHtml = googleFonts.length > 0
469
+ ? \`<link rel="preconnect" href="https://fonts.googleapis.com">
470
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
471
+ <link href="https://fonts.googleapis.com/css2?family=\&{googleFonts.map(f => encodeURIComponent(f)).join("&family=")}&display=swap" rel="stylesheet">\`
472
+ : "";
473
+
474
+ const devCss = \`
475
+ :root {
476
+ \${colors.map((c) => "--wp--preset--color--" + c.slug + ": " + c.color + ";").join("\\n ")}
477
+ \${fontSizes.map((f) => "--wp--preset--font-size--" + f.slug + ": " + f.size + ";").join("\\n ")}
478
+ \${fontFamilies.map((f) => "--wp--preset--font-family--" + f.slug + ": " + f.fontFamily + ";").join("\\n ")}
479
+ \${layout.contentSize ? "--wp--style--global--content-size: " + layout.contentSize + ";" : ""}
480
+ \${layout.wideSize ? "--wp--style--global--wide-size: " + layout.wideSize + ";" : ""}
481
+
482
+ /* Registry Aesthetic Mode Custom Properties */
483
+ --radius: \${themeStyle === "forgewp" ? "0px" : "0.5rem"};
484
+ --radius-sm: calc(var(--radius) - 4px);
485
+ --radius-md: calc(var(--radius) - 2px);
486
+ --radius-lg: var(--radius);
487
+ --border-width: \${themeStyle === "forgewp" ? "2px" : "1px"};
488
+ --border-color: \${themeStyle === "forgewp" ? "#09090b" : "#e4e4e7"};
489
+ --shadow-offset: \${themeStyle === "forgewp" ? "4px" : "0px"};
490
+ }
491
+ \`;
492
+
493
+ return (
494
+ <>
495
+ {fontsHtml && <span dangerouslySetInnerHTML={{ __html: fontsHtml }} />}
496
+ <style dangerouslySetInnerHTML={{ __html: devCss }} />
497
+ </>
498
+ );
499
+ }
500
+ `
501
+ };