@forgewp/compiler 0.4.3 → 0.4.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 +59 -0
- package/bin/add.js +20 -14
- package/bin/cli.js +145 -70
- package/bin/doctor.js +21 -12
- package/bin/export.js +69 -20
- package/bin/fresh.js +5 -0
- package/bin/i18n-extract.js +3 -10
- package/bin/i18n-translate.js +15 -24
- package/bin/make-block.js +13 -0
- package/bin/make-editable.js +166 -0
- package/bin/make-form.js +131 -0
- package/bin/make-loop.js +40 -43
- package/bin/make-mail.js +27 -0
- package/bin/make-post-type.js +57 -29
- package/bin/make-sandbox.js +62 -11
- package/bin/make-section.js +221 -0
- package/bin/make-shell.js +375 -0
- package/bin/repair.js +14 -26
- package/bin/seed.js +119 -0
- package/bin/sync-routes.js +107 -85
- package/lib/adapters/html-adapter.js +5 -0
- package/lib/adapters/stub-adapter.js +4 -0
- package/lib/add-component.js +153 -92
- package/lib/asset-loader.js +313 -3
- package/lib/assets/asset-graph.js +432 -0
- package/lib/assets/asset-pipeline.js +125 -0
- package/lib/assets/diagnostics-report.js +345 -0
- package/lib/assets/external-fetcher.js +173 -0
- package/lib/assets/font-orchestrator.js +348 -0
- package/lib/assets/font-usage-scanner.js +242 -0
- package/lib/assets/image-optimizer.js +229 -0
- package/lib/assets/index.js +51 -0
- package/lib/assets/preload-generator.js +70 -0
- package/lib/assets/public-url.js +153 -0
- package/lib/block-authoring-help.js +11 -0
- package/lib/blocks/ast-parser.js +67 -0
- package/lib/blocks/discover-blocks.js +146 -0
- package/lib/blocks/editor-scope.js +733 -0
- package/lib/blocks/editor-transpiler.js +1229 -0
- package/lib/blocks/index.js +2838 -0
- package/lib/blocks/php-transpiler.js +4928 -0
- package/lib/blocks/scanner.js +1487 -0
- package/lib/blocks/shared-utils.js +290 -0
- package/lib/blocks/source-sanitize.js +1449 -0
- package/lib/blueprints.js +31 -91
- package/lib/build-assets.js +38 -33
- package/lib/collect-page-template-routes.js +102 -0
- package/lib/collect-static-routes.js +175 -0
- package/lib/diagnostics.js +58 -33
- package/lib/export-theme.js +84 -5
- package/lib/extract-template-content.js +90 -0
- package/lib/forms-preview.js +42 -0
- package/lib/functions/cpt-routing.js +69 -0
- package/lib/functions/forms.js +2461 -0
- package/lib/functions/hydration-enqueuer.js +400 -0
- package/lib/functions/index.js +1623 -0
- package/lib/functions/load-menus.js +112 -0
- package/lib/functions/load-translations.js +148 -0
- package/lib/functions/rest-endpoints.js +2923 -0
- package/lib/functions/routing.js +765 -0
- package/lib/functions/seed-mock-data.js +392 -0
- package/lib/functions/seed-products.js +481 -0
- package/lib/functions/settings-page.js +273 -0
- package/lib/functions/theme-setup.js +494 -0
- package/lib/generate-theme.js +1916 -339
- package/lib/hydration/editable-schemas.js +332 -0
- package/lib/hydration/enter-hidden-initial.js +65 -0
- package/lib/hydration/form-schemas.js +227 -0
- package/lib/hydration/index.js +12 -0
- package/lib/hydration/is-interactive.js +951 -0
- package/lib/hydration/island-split.js +1231 -0
- package/lib/hydration/islands-scanner.js +599 -0
- package/lib/hydration/resolve-island-chunk.js +103 -0
- package/lib/hydration/resolve-island-component.js +52 -0
- package/lib/hydration/rollup-inputs.js +81 -0
- package/lib/hydration/root-class-extractor.js +220 -0
- package/lib/hydration/scan-app-providers.js +154 -0
- package/lib/hydration/static-lint.js +382 -0
- package/lib/hydration/transform.js +257 -0
- package/lib/hydration/uses-block-area.js +49 -0
- package/lib/hydration/utils.js +119 -0
- package/lib/i18n/translation-cache.js +141 -0
- package/lib/icon-registry.js +72 -0
- package/lib/index.d.ts +287 -8
- package/lib/index.js +2 -1
- package/lib/load-config.js +338 -242
- package/lib/mail-templates.js +37 -0
- package/lib/markup-processor.js +388 -102
- package/lib/node-runtime.js +7 -0
- package/lib/page-config-plugin.js +64 -20
- package/lib/php-builders.js +383 -44
- package/lib/react-adapter.js +983 -235
- package/lib/registration-metadata.js +11 -0
- package/lib/render-theme.mts +1410 -616
- package/lib/route-layout.js +76 -0
- package/lib/template-discovery.js +58 -0
- package/lib/theme-compatibility.js +32 -0
- package/lib/validate-export.js +2 -2
- package/lib/validate.js +27 -5
- package/lib/virtual-plugin.js +319 -0
- package/lib/walkthrough.md +26 -0
- package/package.json +16 -5
- package/templates/auth/cms/email-logs.json +9 -0
- package/templates/auth/cms/menus.json +11 -0
- package/templates/auth/cms/mock-data.json +123 -0
- package/templates/auth/cms/roles.json +7 -0
- package/templates/auth/cms/sessions.json +1 -0
- package/templates/auth/cms/site-settings.json +28 -0
- package/templates/auth/cms/translations.json +4 -0
- package/templates/auth/cms/users.json +46 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +10 -2
- package/templates/auth/components/login-form-wrapper.tsx +118 -21
- package/templates/auth/components/reset-password-form-wrapper.tsx +10 -2
- package/templates/auth/components/signup-form-wrapper.tsx +2 -2
- package/templates/auth/components/verify-email-view-wrapper.tsx +5 -5
- package/templates/auth/pages/DashboardPage.tsx +1 -4
- package/templates/auth/pages/ForgotPasswordPage.tsx +1 -4
- package/templates/auth/pages/LoginPage.tsx +1 -4
- package/templates/auth/pages/ResetPasswordPage.tsx +1 -4
- package/templates/auth/pages/SignUpPage.tsx +1 -4
- package/templates/auth/pages/VerifyEmailPage.tsx +1 -4
- package/templates/auth/ui/button.tsx +57 -0
- package/templates/auth/ui/card.tsx +76 -0
- package/templates/auth/ui/field.tsx +242 -0
- package/templates/auth/ui/input.tsx +22 -0
- package/templates/auth/ui/label.tsx +24 -0
- package/templates/auth/ui/separator.tsx +31 -0
- package/templates/menus.json +12 -10
- package/templates/users.json +8 -4
- package/templates/wordpress.tsx +690 -245
- package/lib/block-compiler.js +0 -552
- package/lib/functions-builder.js +0 -2970
- package/lib/hydration-scanner.js +0 -833
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { readFileSync, existsSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ts } from "./is-interactive.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolves imported component path using aliases or relative paths.
|
|
7
|
+
*/
|
|
8
|
+
export function resolveImportPath(dir, importPath, themeRoot) {
|
|
9
|
+
let absolutePath;
|
|
10
|
+
if (importPath.startsWith("@/")) {
|
|
11
|
+
absolutePath = path.resolve(themeRoot, "src", importPath.substring(2));
|
|
12
|
+
} else {
|
|
13
|
+
absolutePath = path.resolve(dir, importPath);
|
|
14
|
+
}
|
|
15
|
+
const extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
16
|
+
if (existsSync(absolutePath) && statSync(absolutePath).isFile()) {
|
|
17
|
+
return absolutePath;
|
|
18
|
+
}
|
|
19
|
+
for (const ext of extensions) {
|
|
20
|
+
const p = absolutePath + ext;
|
|
21
|
+
if (existsSync(p)) return p;
|
|
22
|
+
|
|
23
|
+
const indexP = path.join(absolutePath, "index" + ext);
|
|
24
|
+
if (existsSync(indexP)) return indexP;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Statically checks recursively if a component file uses auth hooks.
|
|
31
|
+
*/
|
|
32
|
+
export function doesComponentUseAuthHooks(filePath, visited = new Set()) {
|
|
33
|
+
if (!existsSync(filePath) || visited.has(filePath)) return false;
|
|
34
|
+
visited.add(filePath);
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const content = readFileSync(filePath, "utf8");
|
|
38
|
+
const hasHookMention = content.includes("useWpUser") || content.includes("useWpAuth") || content.includes("useWpCapability");
|
|
39
|
+
if (hasHookMention) {
|
|
40
|
+
if (!ts) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const sourceFile = ts.createSourceFile(
|
|
44
|
+
filePath,
|
|
45
|
+
content,
|
|
46
|
+
ts.ScriptTarget.Latest,
|
|
47
|
+
true,
|
|
48
|
+
ts.ScriptKind.TSX
|
|
49
|
+
);
|
|
50
|
+
let usesAuth = false;
|
|
51
|
+
function checkNode(node) {
|
|
52
|
+
if (usesAuth) return;
|
|
53
|
+
if (node.kind === ts.SyntaxKind.CallExpression) {
|
|
54
|
+
const expression = node.expression;
|
|
55
|
+
if (expression.kind === ts.SyntaxKind.Identifier) {
|
|
56
|
+
const name = expression.text;
|
|
57
|
+
if (["useWpUser", "useWpAuth", "useWpCapability"].includes(name)) {
|
|
58
|
+
usesAuth = true;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
ts.forEachChild(node, checkNode);
|
|
64
|
+
}
|
|
65
|
+
ts.forEachChild(sourceFile, checkNode);
|
|
66
|
+
if (usesAuth) return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Check imports recursively
|
|
70
|
+
const themeRoot = filePath.includes("/src/")
|
|
71
|
+
? filePath.substring(0, filePath.indexOf("/src/"))
|
|
72
|
+
: process.cwd();
|
|
73
|
+
|
|
74
|
+
if (!ts) {
|
|
75
|
+
const importRegex = /import\s+([A-Za-z0-9_$,\s{}]+)\s+from\s+['"]([^'"]+)['"]/g;
|
|
76
|
+
let match;
|
|
77
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
78
|
+
const importPath = match[2];
|
|
79
|
+
if (importPath.startsWith(".") || importPath.startsWith("@/")) {
|
|
80
|
+
const resolvedPath = resolveImportPath(path.dirname(filePath), importPath, themeRoot);
|
|
81
|
+
if (resolvedPath && doesComponentUseAuthHooks(resolvedPath, visited)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const sourceFile = ts.createSourceFile(
|
|
90
|
+
filePath,
|
|
91
|
+
content,
|
|
92
|
+
ts.ScriptTarget.Latest,
|
|
93
|
+
true,
|
|
94
|
+
ts.ScriptKind.TSX
|
|
95
|
+
);
|
|
96
|
+
let recursiveAuth = false;
|
|
97
|
+
function checkImports(node) {
|
|
98
|
+
if (recursiveAuth) return;
|
|
99
|
+
if (node.kind === ts.SyntaxKind.ImportDeclaration) {
|
|
100
|
+
const moduleSpecifier = node.moduleSpecifier;
|
|
101
|
+
if (moduleSpecifier.kind === ts.SyntaxKind.StringLiteral) {
|
|
102
|
+
const importPath = moduleSpecifier.text;
|
|
103
|
+
if (importPath.startsWith(".") || importPath.startsWith("@/")) {
|
|
104
|
+
const resolvedPath = resolveImportPath(path.dirname(filePath), importPath, themeRoot);
|
|
105
|
+
if (resolvedPath && doesComponentUseAuthHooks(resolvedPath, visited)) {
|
|
106
|
+
recursiveAuth = true;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
ts.forEachChild(node, checkImports);
|
|
113
|
+
}
|
|
114
|
+
ts.forEachChild(sourceFile, checkImports);
|
|
115
|
+
return recursiveAuth;
|
|
116
|
+
} catch (err) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
/** Optional build-time response cache. Catalog values always take precedence. */
|
|
6
|
+
export function createTranslationCache(
|
|
7
|
+
themeRoot,
|
|
8
|
+
cachePath,
|
|
9
|
+
providerName,
|
|
10
|
+
providerConfig = {}
|
|
11
|
+
) {
|
|
12
|
+
if (cachePath === undefined) return null;
|
|
13
|
+
if (typeof cachePath !== 'string' || !cachePath.trim()) {
|
|
14
|
+
throw new Error('i18n.cache must be a nonempty project-relative JSON path');
|
|
15
|
+
}
|
|
16
|
+
const root = path.resolve(themeRoot);
|
|
17
|
+
const file = path.resolve(root, cachePath);
|
|
18
|
+
const relative = path.relative(root, file);
|
|
19
|
+
if (
|
|
20
|
+
path.isAbsolute(cachePath) ||
|
|
21
|
+
relative.startsWith('..' + path.sep) ||
|
|
22
|
+
relative === '..' ||
|
|
23
|
+
!relative ||
|
|
24
|
+
path.extname(file).toLowerCase() !== '.json'
|
|
25
|
+
) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
'i18n.cache must point to a JSON file inside the theme project'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (
|
|
31
|
+
['cms/translations.json', 'package.json'].includes(
|
|
32
|
+
relative.replaceAll('\\', '/').toLowerCase()
|
|
33
|
+
)
|
|
34
|
+
) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'i18n.cache must be separate from the translation catalog and package.json'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
let entries = {};
|
|
40
|
+
if (fs.existsSync(file)) {
|
|
41
|
+
let data;
|
|
42
|
+
try {
|
|
43
|
+
data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
44
|
+
} catch {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Invalid translation cache at ${file}; remove it or choose a new cache path`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (
|
|
50
|
+
data?.version !== 1 ||
|
|
51
|
+
!data.entries ||
|
|
52
|
+
typeof data.entries !== 'object' ||
|
|
53
|
+
Array.isArray(data.entries) ||
|
|
54
|
+
Object.entries(data.entries).some(
|
|
55
|
+
([key, value]) =>
|
|
56
|
+
!/^[a-f0-9]{64}$/.test(key) ||
|
|
57
|
+
typeof value !== 'string' ||
|
|
58
|
+
!value.trim()
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Invalid translation cache at ${file}; remove it or choose a new cache path`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
entries = data.entries;
|
|
66
|
+
}
|
|
67
|
+
const keyFor = (text, source, target) =>
|
|
68
|
+
createHash('sha256')
|
|
69
|
+
.update(
|
|
70
|
+
JSON.stringify([
|
|
71
|
+
providerName,
|
|
72
|
+
providerConfig.endpoint || '',
|
|
73
|
+
source,
|
|
74
|
+
target,
|
|
75
|
+
text,
|
|
76
|
+
])
|
|
77
|
+
)
|
|
78
|
+
.digest('hex');
|
|
79
|
+
let dirty = false;
|
|
80
|
+
return {
|
|
81
|
+
get(text, source, target) {
|
|
82
|
+
return entries[keyFor(text, source, target)];
|
|
83
|
+
},
|
|
84
|
+
set(text, source, target, value) {
|
|
85
|
+
if (typeof value !== 'string' || !value.trim()) return;
|
|
86
|
+
const key = keyFor(text, source, target);
|
|
87
|
+
if (entries[key] !== value) {
|
|
88
|
+
entries[key] = value;
|
|
89
|
+
dirty = true;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
save() {
|
|
93
|
+
if (!dirty) return;
|
|
94
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
95
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
96
|
+
try {
|
|
97
|
+
fs.writeFileSync(
|
|
98
|
+
temporary,
|
|
99
|
+
JSON.stringify({ version: 1, entries }, null, 2) + '\n',
|
|
100
|
+
{ flag: 'wx' }
|
|
101
|
+
);
|
|
102
|
+
fs.renameSync(temporary, file);
|
|
103
|
+
dirty = false;
|
|
104
|
+
} finally {
|
|
105
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Translate only blank catalog entries, caching successful remote responses. */
|
|
112
|
+
export async function translateMissingEntries(
|
|
113
|
+
localeMap,
|
|
114
|
+
source,
|
|
115
|
+
target,
|
|
116
|
+
provider,
|
|
117
|
+
cache
|
|
118
|
+
) {
|
|
119
|
+
const missing = Object.keys(localeMap).filter((key) => !localeMap[key]);
|
|
120
|
+
const pending = [];
|
|
121
|
+
let restored = 0;
|
|
122
|
+
for (const text of missing) {
|
|
123
|
+
const cached = cache?.get(text, source, target);
|
|
124
|
+
if (cached !== undefined) {
|
|
125
|
+
localeMap[text] = cached;
|
|
126
|
+
restored++;
|
|
127
|
+
} else pending.push(text);
|
|
128
|
+
}
|
|
129
|
+
if (!pending.length) return { restored, translated: 0 };
|
|
130
|
+
const response = await provider.translate(pending, source, target);
|
|
131
|
+
let translated = 0;
|
|
132
|
+
for (const text of pending) {
|
|
133
|
+
const value = response?.[text];
|
|
134
|
+
if (typeof value !== 'string' || !value.trim()) continue;
|
|
135
|
+
localeMap[text] = value;
|
|
136
|
+
cache?.set(text, source, target, value);
|
|
137
|
+
translated++;
|
|
138
|
+
}
|
|
139
|
+
cache?.save();
|
|
140
|
+
return { restored, translated };
|
|
141
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated ForgeWP icon registry (Lucide-compatible slugs → inline SVG).
|
|
3
|
+
* Used by PHP forgewp_render_theme_icon, block editor picker, and WpIcon resolve.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** @type {Record<string, string>} */
|
|
7
|
+
export const FORGEWP_ICON_SVGS = {
|
|
8
|
+
award:
|
|
9
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-award"><path d="m15.477 12.89 1.515 8.526a.5.5 0 0 1-.81.47l-3.58-2.687a1 1 0 0 0-1.197 0l-3.586 2.686a.5.5 0 0 1-.81-.469l1.514-8.526"></path><circle cx="12" cy="8" r="6"></circle></svg>',
|
|
10
|
+
shield:
|
|
11
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-shield"><path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"></path></svg>',
|
|
12
|
+
globe:
|
|
13
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-globe"><circle cx="12" cy="12" r="10"></circle><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"></path><path d="M2 12h20"></path></svg>',
|
|
14
|
+
users:
|
|
15
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-users"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M22 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>',
|
|
16
|
+
star:
|
|
17
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-star"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>',
|
|
18
|
+
heart:
|
|
19
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-heart"><path d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z"></path></svg>',
|
|
20
|
+
check:
|
|
21
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check"><path d="M20 6 9 17l-5-5"></path></svg>',
|
|
22
|
+
'map-pin':
|
|
23
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-map-pin"><path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"></path><circle cx="12" cy="10" r="3"></circle></svg>',
|
|
24
|
+
'book-open':
|
|
25
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-book-open"><path d="M12 7v14"></path><path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"></path></svg>',
|
|
26
|
+
'arrow-right':
|
|
27
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-right"><path d="M5 12h14"></path><path d="m12 5 7 7-7 7"></path></svg>',
|
|
28
|
+
hotel:
|
|
29
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-hotel"><path d="M10 22v-6.57"></path><path d="M12 11h.01"></path><path d="M12 7h.01"></path><path d="M14 15.43V22"></path><path d="M15 16a5 5 0 0 0-6 0"></path><path d="M16 11h.01"></path><path d="M16 7h.01"></path><path d="M8 11h.01"></path><path d="M8 7h.01"></path><rect x="4" y="2" width="16" height="20" rx="2"></rect></svg>',
|
|
30
|
+
sparkles:
|
|
31
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-sparkles"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"></path><path d="M20 3v4"></path><path d="M22 5h-4"></path><path d="M4 17v2"></path><path d="M5 18H3"></path></svg>',
|
|
32
|
+
mail:
|
|
33
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mail"><rect width="20" height="16" x="2" y="4" rx="2"></rect><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"></path></svg>',
|
|
34
|
+
phone:
|
|
35
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-phone"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"></path></svg>',
|
|
36
|
+
'check-circle':
|
|
37
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-check"><circle cx="12" cy="12" r="10"></circle><path d="m9 12 2 2 4-4"></path></svg>',
|
|
38
|
+
leaf:
|
|
39
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-leaf"><path d="M11 20A7 7 0 0 1 9.8 6.1C15.5 5 17 4.48 19 2c1 2 2 4.18 2 8 0 5.5-4.78 10-10 10Z"></path><path d="M2 21c0-3 1.85-5.36 5.08-6C9.5 14.52 12 13 13 12"></path></svg>',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const FORGEWP_DEFAULT_ICON_SLUGS = Object.keys(FORGEWP_ICON_SVGS);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Apply class to an SVG root tag (or return as-is).
|
|
46
|
+
*/
|
|
47
|
+
export function applyIconClass(svg, className) {
|
|
48
|
+
if (!svg) return '';
|
|
49
|
+
if (!className) return svg;
|
|
50
|
+
if (/\sclass="/.test(svg)) {
|
|
51
|
+
return svg.replace(/\sclass="([^"]*)"/, (_, existing) => ` class="${existing} ${className}"`);
|
|
52
|
+
}
|
|
53
|
+
return svg.replace('<svg ', `<svg class="${className}" `);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* PHP array literal for forgewp_render_theme_icon body.
|
|
58
|
+
*/
|
|
59
|
+
export function buildPhpIconSvgMapLiteral() {
|
|
60
|
+
const lines = Object.entries(FORGEWP_ICON_SVGS).map(([slug, svg]) => {
|
|
61
|
+
const escaped = svg.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
62
|
+
return ` '${slug}' => '${escaped}',`;
|
|
63
|
+
});
|
|
64
|
+
return lines.join('\n');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* JSON object for window.forgeWpIconRegistry in the block editor.
|
|
69
|
+
*/
|
|
70
|
+
export function buildEditorIconRegistry() {
|
|
71
|
+
return { ...FORGEWP_ICON_SVGS };
|
|
72
|
+
}
|