@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
package/lib/markup-processor.js
CHANGED
|
@@ -3,9 +3,23 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {string} html Raw HTML markup
|
|
5
5
|
* @param {string} textDomain Text domain for translations
|
|
6
|
+
* @param {Set<string>|null} richTextKeys Field keys actually declared richText() in an
|
|
7
|
+
* editable schema — the authoritative source for whether a meta value should be run
|
|
8
|
+
* through wpautop(). Without this, richness was guessed from the key name (e.g. any
|
|
9
|
+
* key containing "subtitle"), which wrongly wpautop-wraps a plain text() field once
|
|
10
|
+
* it has real content, double-nesting <p> tags inside the JSX's own <p> wrapper and
|
|
11
|
+
* silently dropping its styling (the browser auto-closes the outer <p> at the nested
|
|
12
|
+
* one). The empty-value/default case bypassed wpautop entirely, so this only ever
|
|
13
|
+
* surfaced once an editor actually filled in the field.
|
|
14
|
+
* @param {import('./assets/asset-graph.js').AssetGraph|null} assetGraph
|
|
6
15
|
* @returns {string} Transpiled HTML containing PHP tags
|
|
7
16
|
*/
|
|
8
|
-
export function processMarkup(
|
|
17
|
+
export function processMarkup(
|
|
18
|
+
html,
|
|
19
|
+
textDomain = 'theme',
|
|
20
|
+
richTextKeys = null,
|
|
21
|
+
assetGraph = null,
|
|
22
|
+
) {
|
|
9
23
|
if (!html) return '';
|
|
10
24
|
// Fix nav links — # → <?php echo esc_url( home_url( '/' ) ); ?>
|
|
11
25
|
// We use a placeholder and replace it in the PHP file generation if needed,
|
|
@@ -18,12 +32,12 @@ export function processMarkup(html, textDomain = 'theme') {
|
|
|
18
32
|
// Map React root link (href="/") to dynamic localized WordPress home URL
|
|
19
33
|
processed = processed.replace(
|
|
20
34
|
/href=(["'])\/\1/g,
|
|
21
|
-
|
|
35
|
+
"href=\"<?php echo esc_url( function_exists( 'pll_home_url' ) ? pll_home_url( function_exists( 'pll_current_language' ) ? pll_current_language() : '' ) : home_url( '/' ) ); ?>\"",
|
|
22
36
|
);
|
|
23
37
|
|
|
24
38
|
processed = processed.replace(
|
|
25
39
|
/__FORGEWP_THE_TITLE__/g,
|
|
26
|
-
|
|
40
|
+
"<?php echo html_entity_decode( get_the_title(), ENT_QUOTES | ENT_HTML5, 'UTF-8' ); ?>",
|
|
27
41
|
);
|
|
28
42
|
|
|
29
43
|
processed = processed.replace(
|
|
@@ -31,6 +45,11 @@ export function processMarkup(html, textDomain = 'theme') {
|
|
|
31
45
|
'<?php the_content(); ?>',
|
|
32
46
|
);
|
|
33
47
|
|
|
48
|
+
processed = processed.replace(
|
|
49
|
+
/<forgewp-block-area\b[^>]*>\s*<\/forgewp-block-area>/gi,
|
|
50
|
+
'<?php the_content(); ?>',
|
|
51
|
+
);
|
|
52
|
+
|
|
34
53
|
processed = processed.replace(
|
|
35
54
|
/__FORGEWP_THE_PERMALINK__/g,
|
|
36
55
|
'<?php the_permalink(); ?>',
|
|
@@ -90,6 +109,74 @@ export function processMarkup(html, textDomain = 'theme') {
|
|
|
90
109
|
|
|
91
110
|
processed = processed.replace(/<\/forgewp-loop-end>/g, '');
|
|
92
111
|
|
|
112
|
+
// ── Dynamic WpIcon Custom SVGs ──
|
|
113
|
+
processed = processed.replace(
|
|
114
|
+
/<forgewp-icon-placeholder\s+([^>]*)\/?>/g,
|
|
115
|
+
(match, attrsStr) => {
|
|
116
|
+
const getAttr = (name) => {
|
|
117
|
+
const regex = new RegExp(
|
|
118
|
+
`(?:${name}|${name.toLowerCase()})=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
|
|
119
|
+
'i',
|
|
120
|
+
);
|
|
121
|
+
const m = attrsStr.match(regex);
|
|
122
|
+
return m ? m[1] || m[2] || m[3] || '' : '';
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const nameAttr = getAttr('name');
|
|
126
|
+
const provider = getAttr('provider') || 'lucide';
|
|
127
|
+
const className = getAttr('class') || getAttr('className') || '';
|
|
128
|
+
|
|
129
|
+
const fieldMatch = nameAttr.match(
|
|
130
|
+
/__FORGEWP_REPEATER_FIELD_([a-zA-Z0-9_-]+)__/,
|
|
131
|
+
);
|
|
132
|
+
if (fieldMatch) {
|
|
133
|
+
const fieldName = fieldMatch[1];
|
|
134
|
+
return `<?php forgewp_render_theme_icon($row['${fieldName}'], '${className}', '${provider}'); ?>`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const metaMatch = nameAttr.match(
|
|
138
|
+
/__(?:FORGEWP|forgewp)_META_([a-zA-Z0-9_-]+)(?:_POST_(front|[0-9]+))?_DEFAULT_(.*?)__/i,
|
|
139
|
+
);
|
|
140
|
+
if (metaMatch) {
|
|
141
|
+
const key = metaMatch[1];
|
|
142
|
+
const postId = metaMatch[2];
|
|
143
|
+
const defaultValEncoded = metaMatch[3];
|
|
144
|
+
const decoded = decodeURIComponent(defaultValEncoded);
|
|
145
|
+
const escapedDecoded = decoded.replace(/'/g, "\\'");
|
|
146
|
+
const cleanDecoded = escapedDecoded.replace(
|
|
147
|
+
/__FORGEWP_I18N_([^_](?:[^_]|_(?!_))*?)__/gi,
|
|
148
|
+
(m, text) => {
|
|
149
|
+
const cleanText = text
|
|
150
|
+
.replace(/'/g, "'")
|
|
151
|
+
.replace(/"/g, '"')
|
|
152
|
+
.replace(/&/g, '&')
|
|
153
|
+
.replace(/'/g, "\\'");
|
|
154
|
+
return `' . __('${cleanText}', '${textDomain}') . '`;
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
const phpPostId =
|
|
158
|
+
postId && postId.toLowerCase() === 'front'
|
|
159
|
+
? 'forgewp_resolve_front_page_id()'
|
|
160
|
+
: postId
|
|
161
|
+
? postId
|
|
162
|
+
: 'null';
|
|
163
|
+
return `<?php forgewp_render_theme_icon(forgewp_get_meta_value('${key}', '${cleanDecoded}', false, ${phpPostId}), '${className}', '${provider}'); ?>`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (nameAttr.startsWith('<?php') && nameAttr.endsWith('?>')) {
|
|
167
|
+
const phpCode = nameAttr
|
|
168
|
+
.replace(/^<\?php\s*(?:echo\s+)?/, '')
|
|
169
|
+
.replace(/\s*\?>$/, '')
|
|
170
|
+
.trim()
|
|
171
|
+
.replace(/;$/, '');
|
|
172
|
+
return `<?php forgewp_render_theme_icon(${phpCode}, '${className}', '${provider}'); ?>`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return `<?php forgewp_render_theme_icon('${nameAttr}', '${className}', '${provider}'); ?>`;
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
processed = processed.replace(/<\/forgewp-icon-placeholder>/g, '');
|
|
179
|
+
|
|
93
180
|
// ── Custom Meta Fields (ACF / metadata support) ──
|
|
94
181
|
processed = processed.replace(
|
|
95
182
|
/__FORGEWP_CUSTOM_FIELD__([a-zA-Z0-9_-]+)__/g,
|
|
@@ -97,12 +184,12 @@ export function processMarkup(html, textDomain = 'theme') {
|
|
|
97
184
|
);
|
|
98
185
|
|
|
99
186
|
processed = processed.replace(
|
|
100
|
-
/__FORGEWP_META_([a-zA-Z0-9_-]+)_DEFAULT_(.*?)__/
|
|
101
|
-
(match, key, defaultValEncoded) => {
|
|
187
|
+
/__FORGEWP_META_([a-zA-Z0-9_-]+)(?:_POST_(front|[0-9]+))?_DEFAULT_(.*?)__/gi,
|
|
188
|
+
(match, key, postId, defaultValEncoded) => {
|
|
102
189
|
const decoded = decodeURIComponent(defaultValEncoded);
|
|
103
190
|
const escapedDecoded = decoded.replace(/'/g, "\\'");
|
|
104
191
|
const cleanDecoded = escapedDecoded.replace(
|
|
105
|
-
/__FORGEWP_I18N_([^_](?:[^_]|_(?!_))*?)__/
|
|
192
|
+
/__FORGEWP_I18N_([^_](?:[^_]|_(?!_))*?)__/gi,
|
|
106
193
|
(m, text) => {
|
|
107
194
|
const cleanText = text
|
|
108
195
|
.replace(/'/g, "'")
|
|
@@ -110,11 +197,21 @@ export function processMarkup(html, textDomain = 'theme') {
|
|
|
110
197
|
.replace(/&/g, '&')
|
|
111
198
|
.replace(/'/g, "\\'");
|
|
112
199
|
return `' . __('${cleanText}', '${textDomain}') . '`;
|
|
113
|
-
}
|
|
200
|
+
},
|
|
114
201
|
);
|
|
115
|
-
const isRichText =
|
|
116
|
-
|
|
117
|
-
|
|
202
|
+
const isRichText =
|
|
203
|
+
(richTextKeys instanceof Set ? richTextKeys.has(key) : false) ||
|
|
204
|
+
decoded.includes('<p>') ||
|
|
205
|
+
decoded.includes('</p>') ||
|
|
206
|
+
decoded.includes('<br');
|
|
207
|
+
const phpPostId =
|
|
208
|
+
postId && postId.toLowerCase() === 'front'
|
|
209
|
+
? 'forgewp_resolve_front_page_id()'
|
|
210
|
+
: postId
|
|
211
|
+
? postId
|
|
212
|
+
: 'null';
|
|
213
|
+
return `<?php echo forgewp_get_meta_value( '${key}', '${cleanDecoded}', ${isRichText ? 'true' : 'false'}, ${phpPostId} ); ?>`;
|
|
214
|
+
},
|
|
118
215
|
);
|
|
119
216
|
|
|
120
217
|
// ── Dynamic Custom Menus ──
|
|
@@ -166,15 +263,20 @@ export function processMarkup(html, textDomain = 'theme') {
|
|
|
166
263
|
return m ? m[1] || m[2] || m[3] || '' : '';
|
|
167
264
|
};
|
|
168
265
|
|
|
169
|
-
const className
|
|
170
|
-
const linkClass
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
266
|
+
const className = getAttr('class') || getAttr('className') || '';
|
|
267
|
+
const linkClass =
|
|
268
|
+
getAttr('linkClassName') || getAttr('linkclassname') || '';
|
|
269
|
+
const showFlags = getAttr('showFlags') === '1';
|
|
270
|
+
const showNames = getAttr('showNames') === '1';
|
|
271
|
+
const showCodes = getAttr('showCodes') !== '0'; // default true
|
|
272
|
+
|
|
273
|
+
const flagsPart = showFlags
|
|
274
|
+
? "echo '<img src=\"' . esc_url($pll_l['flag']) . '\" alt=\"' . esc_attr($pll_l['name']) . '\" />';"
|
|
275
|
+
: '';
|
|
276
|
+
const codesPart = showCodes
|
|
277
|
+
? "echo esc_html(strtoupper($pll_l['slug']));"
|
|
278
|
+
: '';
|
|
279
|
+
const namesPart = showNames ? "echo ' ' . esc_html($pll_l['name']);" : '';
|
|
178
280
|
|
|
179
281
|
return `<?php
|
|
180
282
|
if (function_exists('pll_the_languages')) {
|
|
@@ -256,12 +358,15 @@ if (function_exists('pll_the_languages')) {
|
|
|
256
358
|
getAttr('postsPerPage') || getAttr('postsperpage') || '10';
|
|
257
359
|
const categoryName =
|
|
258
360
|
getAttr('categoryName') || getAttr('categoryname') || '';
|
|
361
|
+
const postId = getAttr('postId') || getAttr('postid') || '';
|
|
259
362
|
const orderby = getAttr('orderby') || '';
|
|
260
363
|
const order = getAttr('order') || '';
|
|
261
364
|
const metaKey = getAttr('metaKey') || getAttr('metakey') || '';
|
|
262
365
|
const metaValue = getAttr('metaValue') || getAttr('metavalue') || '';
|
|
263
|
-
const metaCompare =
|
|
264
|
-
|
|
366
|
+
const metaCompare =
|
|
367
|
+
getAttr('metaCompare') || getAttr('metacompare') || '=';
|
|
368
|
+
const taxTaxonomy =
|
|
369
|
+
getAttr('taxTaxonomy') || getAttr('taxtaxonomy') || '';
|
|
265
370
|
const taxTerms = getAttr('taxTerms') || getAttr('taxterms') || '';
|
|
266
371
|
const postIn = getAttr('postIn') || getAttr('postin') || '';
|
|
267
372
|
|
|
@@ -284,7 +389,7 @@ if (function_exists('pll_the_languages')) {
|
|
|
284
389
|
}
|
|
285
390
|
|
|
286
391
|
let phpArgs = ` 'post_type' => '${postType}',\n 'posts_per_page' => ${postsPerPage},`;
|
|
287
|
-
|
|
392
|
+
|
|
288
393
|
if (orderby !== '') {
|
|
289
394
|
phpArgs += `\n 'orderby' => '${orderby}',`;
|
|
290
395
|
}
|
|
@@ -294,7 +399,10 @@ if (function_exists('pll_the_languages')) {
|
|
|
294
399
|
if (categoryName !== '') {
|
|
295
400
|
phpArgs += `\n 'category_name' => '${categoryName}',`;
|
|
296
401
|
}
|
|
297
|
-
|
|
402
|
+
if (/^\d+$/.test(postId)) {
|
|
403
|
+
phpArgs += `\n 'p' => ${postId},`;
|
|
404
|
+
}
|
|
405
|
+
|
|
298
406
|
if (metaKey !== '') {
|
|
299
407
|
let valExpr = `'${metaValue}'`;
|
|
300
408
|
if (metaValue === 'CURRENT_POST_ID') {
|
|
@@ -302,7 +410,7 @@ if (function_exists('pll_the_languages')) {
|
|
|
302
410
|
} else if (metaValue === ',CURRENT_POST_ID,') {
|
|
303
411
|
valExpr = "',' . get_the_ID() . ','";
|
|
304
412
|
}
|
|
305
|
-
|
|
413
|
+
|
|
306
414
|
phpArgs += `\n 'meta_query' => array(
|
|
307
415
|
array(
|
|
308
416
|
'key' => '${metaKey}',
|
|
@@ -311,7 +419,7 @@ if (function_exists('pll_the_languages')) {
|
|
|
311
419
|
)
|
|
312
420
|
),`;
|
|
313
421
|
}
|
|
314
|
-
|
|
422
|
+
|
|
315
423
|
if (taxTaxonomy !== '') {
|
|
316
424
|
phpArgs += `\n 'tax_query' => array(
|
|
317
425
|
array(
|
|
@@ -355,30 +463,134 @@ ${phpArgs}
|
|
|
355
463
|
|
|
356
464
|
const id = getAttr('id');
|
|
357
465
|
const field = getAttr('field');
|
|
466
|
+
const src = getAttr('src');
|
|
358
467
|
const size = getAttr('size') || 'full';
|
|
359
|
-
const className = getAttr('class-name');
|
|
468
|
+
const className = getAttr('class-name') || getAttr('class');
|
|
360
469
|
const alt = getAttr('alt');
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
470
|
+
const width = getAttr('width');
|
|
471
|
+
const height = getAttr('height');
|
|
472
|
+
const priority = getAttr('priority') === 'true';
|
|
473
|
+
const loading = getAttr('loading') || (priority ? 'eager' : 'lazy');
|
|
474
|
+
const decoding = getAttr('decoding') || 'async';
|
|
475
|
+
const sizes = getAttr('sizes');
|
|
476
|
+
|
|
477
|
+
// Build PHP attribute array for wp_get_attachment_image
|
|
478
|
+
const phpAttrs = [];
|
|
479
|
+
if (className)
|
|
480
|
+
phpAttrs.push(`'class' => '${className.replace(/'/g, "\\'")}'`);
|
|
481
|
+
if (alt) phpAttrs.push(`'alt' => '${alt.replace(/'/g, "\\'")}'`);
|
|
482
|
+
if (sizes) phpAttrs.push(`'sizes' => '${sizes.replace(/'/g, "\\'")}'`);
|
|
483
|
+
if (priority) {
|
|
484
|
+
phpAttrs.push(`'fetchpriority' => 'high'`);
|
|
485
|
+
phpAttrs.push(`'loading' => 'eager'`);
|
|
486
|
+
} else {
|
|
487
|
+
if (loading) phpAttrs.push(`'loading' => '${loading}'`);
|
|
488
|
+
if (decoding) phpAttrs.push(`'decoding' => '${decoding}'`);
|
|
489
|
+
}
|
|
490
|
+
const phpAttrStr = `array( ${phpAttrs.join(', ')} )`;
|
|
491
|
+
|
|
492
|
+
// Build standard HTML attributes for <img> tags
|
|
493
|
+
const htmlAttrs = [];
|
|
494
|
+
if (className) htmlAttrs.push(`class="${className}"`);
|
|
495
|
+
if (alt) htmlAttrs.push(`alt="${alt}"`);
|
|
496
|
+
if (width) htmlAttrs.push(`width="${width}"`);
|
|
497
|
+
if (height) htmlAttrs.push(`height="${height}"`);
|
|
498
|
+
if (priority) {
|
|
499
|
+
htmlAttrs.push(`fetchpriority="high"`);
|
|
500
|
+
htmlAttrs.push(`loading="eager"`);
|
|
501
|
+
} else {
|
|
502
|
+
if (loading) htmlAttrs.push(`loading="${loading}"`);
|
|
503
|
+
if (decoding) htmlAttrs.push(`decoding="${decoding}"`);
|
|
504
|
+
}
|
|
505
|
+
if (sizes) htmlAttrs.push(`sizes="${sizes}"`);
|
|
506
|
+
const responsiveAttrs = getResponsiveImageAttributes(
|
|
507
|
+
src,
|
|
508
|
+
assetGraph,
|
|
509
|
+
htmlAttrs,
|
|
510
|
+
);
|
|
511
|
+
htmlAttrs.push(...responsiveAttrs);
|
|
512
|
+
const extraHtmlStr =
|
|
513
|
+
htmlAttrs.length > 0 ? ' ' + htmlAttrs.join(' ') : '';
|
|
514
|
+
const isNumericSrc = id || (/^\d+$/.test(src) ? src : null);
|
|
515
|
+
const isFeaturedImg =
|
|
516
|
+
field === 'featuredImage' ||
|
|
517
|
+
field === 'featured_image' ||
|
|
518
|
+
src === 'featuredImage' ||
|
|
519
|
+
src === 'featured_image';
|
|
520
|
+
|
|
521
|
+
if (isNumericSrc) {
|
|
522
|
+
return `<?php echo wp_get_attachment_image( ${isNumericSrc}, '${size}', false, ${phpAttrStr} ); ?>`;
|
|
523
|
+
} else if (isFeaturedImg) {
|
|
524
|
+
return `<?php echo wp_get_attachment_image( get_post_thumbnail_id( get_the_ID() ), '${size}', false, ${phpAttrStr} ); ?>`;
|
|
366
525
|
} else if (field) {
|
|
367
526
|
return `<?php
|
|
368
527
|
$img_val = get_post_meta( get_the_ID(), '${field}', true );
|
|
369
528
|
if ( is_numeric( $img_val ) ) {
|
|
370
|
-
echo wp_get_attachment_image( $img_val, '${size}', false,
|
|
529
|
+
echo wp_get_attachment_image( $img_val, '${size}', false, ${phpAttrStr} );
|
|
371
530
|
} elseif ( ! empty( $img_val ) ) {
|
|
372
|
-
echo '<img src="' . esc_url( $img_val ) . '"
|
|
531
|
+
echo '<img src="' . esc_url( $img_val ) . '"' . esc_attr( '${extraHtmlStr}' ) . ' />';
|
|
373
532
|
}
|
|
374
533
|
?>`;
|
|
534
|
+
} else if (src) {
|
|
535
|
+
if (/^https?:\/\//i.test(src) || /^\/\//.test(src)) {
|
|
536
|
+
return `<img src="${src}"${extraHtmlStr} />`;
|
|
537
|
+
}
|
|
538
|
+
// Local theme asset path
|
|
539
|
+
const cleanPath = src.replace(/^(\/|\.\/|@\/)+/, '');
|
|
540
|
+
return `<img src="<?php echo esc_url( get_theme_file_uri( '${cleanPath}' ) ); ?>"${extraHtmlStr} />`;
|
|
375
541
|
} else {
|
|
376
|
-
return `<img
|
|
542
|
+
return `<img src="<?php echo esc_url( get_theme_file_uri( 'assets/image-placeholder.png' ) ); ?>"${extraHtmlStr} />`;
|
|
377
543
|
}
|
|
378
544
|
},
|
|
379
545
|
);
|
|
380
546
|
processed = processed.replace(/<\/forgewp-image>/g, '');
|
|
381
547
|
|
|
548
|
+
// ── Static Media Assets (video, audio, images, downloads, preload links) ──
|
|
549
|
+
const MEDIA_EXTS =
|
|
550
|
+
/\.(png|jpe?g|webp|svg|gif|avif|mp4|webm|ogg|mp3|wav|woff2?|ttf|eot|pdf)$/i;
|
|
551
|
+
processed = processed.replace(
|
|
552
|
+
/<(video|audio|source|img|link|a)\b([^>]*)\/?>/gi,
|
|
553
|
+
(tagMatch, tagName, attrsStr) => {
|
|
554
|
+
let updatedAttrs = attrsStr;
|
|
555
|
+
if (tagName.toLowerCase() === 'img') {
|
|
556
|
+
const srcMatch = attrsStr.match(/\bsrc=(?:"([^"]*)"|'([^']*)')/i);
|
|
557
|
+
const src = srcMatch ? srcMatch[1] || srcMatch[2] : '';
|
|
558
|
+
const responsiveAttrs = getResponsiveImageAttributes(
|
|
559
|
+
src,
|
|
560
|
+
assetGraph,
|
|
561
|
+
attrsStr,
|
|
562
|
+
);
|
|
563
|
+
if (responsiveAttrs.length > 0) {
|
|
564
|
+
updatedAttrs += ` ${responsiveAttrs.join(' ')}`;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
updatedAttrs = updatedAttrs.replace(
|
|
568
|
+
/\b(src|poster|href)=(?:"([^"]*)"|'([^']*)')/gi,
|
|
569
|
+
(attrMatch, attrName, doubleVal, singleVal) => {
|
|
570
|
+
const val = doubleVal !== undefined ? doubleVal : singleVal;
|
|
571
|
+
const isThemeAssetAnchor =
|
|
572
|
+
tagName.toLowerCase() !== 'a' ||
|
|
573
|
+
/^(?:\/|\.\/|@\/)?assets\//.test(val);
|
|
574
|
+
if (
|
|
575
|
+
!val ||
|
|
576
|
+
!isThemeAssetAnchor ||
|
|
577
|
+
/^https?:\/\//i.test(val) ||
|
|
578
|
+
/^\/\//.test(val) ||
|
|
579
|
+
/^data:/i.test(val) ||
|
|
580
|
+
/^blob:/i.test(val) ||
|
|
581
|
+
/<\?php/i.test(val) ||
|
|
582
|
+
!MEDIA_EXTS.test(val.split('?')[0])
|
|
583
|
+
) {
|
|
584
|
+
return attrMatch;
|
|
585
|
+
}
|
|
586
|
+
const cleanPath = val.replace(/^(\/|\.\/|@\/)+/, '');
|
|
587
|
+
return `${attrName}="<?php echo esc_url( get_theme_file_uri( '${cleanPath}' ) ); ?>"`;
|
|
588
|
+
},
|
|
589
|
+
);
|
|
590
|
+
return `<${tagName}${updatedAttrs}>`;
|
|
591
|
+
},
|
|
592
|
+
);
|
|
593
|
+
|
|
382
594
|
// ── Declarative WpRepeater Loops ──
|
|
383
595
|
processed = processed.replace(
|
|
384
596
|
/<forgewp-repeater-start\s+name="([^"]+)"\s+subfields="([^"]+)"\s*\/?>/g,
|
|
@@ -387,7 +599,7 @@ ${phpArgs}
|
|
|
387
599
|
.split(',')
|
|
388
600
|
.map((f) => `'${f.trim()}'`)
|
|
389
601
|
.join(', ');
|
|
390
|
-
|
|
602
|
+
|
|
391
603
|
return `<?php
|
|
392
604
|
$repeater_key = '${name}';
|
|
393
605
|
$sub_fields = array(${subfieldsArrayStr});
|
|
@@ -397,41 +609,13 @@ ${phpArgs}
|
|
|
397
609
|
}
|
|
398
610
|
foreach ($repeater_rows as $row) {
|
|
399
611
|
?>`;
|
|
400
|
-
}
|
|
612
|
+
},
|
|
401
613
|
);
|
|
402
614
|
processed = processed.replace(/<\/forgewp-repeater-start>/g, '');
|
|
403
615
|
|
|
404
616
|
processed = processed.replace(/<forgewp-repeater-end\s*\/?>/g, '');
|
|
405
617
|
processed = processed.replace(/<\/forgewp-repeater-end>/g, '<?php } ?>');
|
|
406
618
|
|
|
407
|
-
// ── Dynamic WpIcon Custom SVGs ──
|
|
408
|
-
processed = processed.replace(
|
|
409
|
-
/<forgewp-icon-placeholder\s+([^>]*)\/?>/g,
|
|
410
|
-
(match, attrsStr) => {
|
|
411
|
-
const getAttr = (name) => {
|
|
412
|
-
const regex = new RegExp(
|
|
413
|
-
`(?:${name}|${name.toLowerCase()})=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
|
|
414
|
-
'i',
|
|
415
|
-
);
|
|
416
|
-
const m = attrsStr.match(regex);
|
|
417
|
-
return m ? m[1] || m[2] || m[3] || '' : '';
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
const nameAttr = getAttr('name');
|
|
421
|
-
const provider = getAttr('provider') || 'lucide';
|
|
422
|
-
const className = getAttr('class') || getAttr('className') || '';
|
|
423
|
-
|
|
424
|
-
const fieldMatch = nameAttr.match(/__FORGEWP_REPEATER_FIELD_([a-zA-Z0-9_-]+)__/);
|
|
425
|
-
if (fieldMatch) {
|
|
426
|
-
const fieldName = fieldMatch[1];
|
|
427
|
-
return `<?php forgewp_render_theme_icon($row['${fieldName}'], '${className}', '${provider}'); ?>`;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
return `<?php forgewp_render_theme_icon('${nameAttr}', '${className}', '${provider}'); ?>`;
|
|
431
|
-
}
|
|
432
|
-
);
|
|
433
|
-
processed = processed.replace(/<\/forgewp-icon-placeholder>/g, '');
|
|
434
|
-
|
|
435
619
|
// ── Authentication & Capability Gates ──
|
|
436
620
|
processed = processed.replace(
|
|
437
621
|
/<forgewp-auth-gate-start\s*\/?>/g,
|
|
@@ -469,10 +653,9 @@ ${phpArgs}
|
|
|
469
653
|
);
|
|
470
654
|
processed = processed.replace(/<\/forgewp-capability-gate-end>/g, '');
|
|
471
655
|
|
|
472
|
-
|
|
473
656
|
processed = processed.replace(
|
|
474
657
|
/__FORGEWP_REPEATER_FIELD_([a-zA-Z0-9_-]+)__/g,
|
|
475
|
-
(match, fieldName) => `<?php echo esc_html($row['${fieldName}']);
|
|
658
|
+
(match, fieldName) => `<?php echo esc_html($row['${fieldName}']); ?>`,
|
|
476
659
|
);
|
|
477
660
|
|
|
478
661
|
// ── Page Links Support ──
|
|
@@ -480,28 +663,18 @@ ${phpArgs}
|
|
|
480
663
|
/__FORGEWP_PAGELINK_([a-zA-Z0-9_-]+)_DEFAULT_(.*?)__/g,
|
|
481
664
|
(match, name, defaultVal) => {
|
|
482
665
|
const decoded = decodeURIComponent(defaultVal);
|
|
483
|
-
return `<?php
|
|
484
|
-
$
|
|
485
|
-
$
|
|
486
|
-
if (!empty($current_lang)) {
|
|
487
|
-
$get_pages_args['lang'] = $current_lang;
|
|
488
|
-
}
|
|
489
|
-
$matched_pages = get_pages($get_pages_args);
|
|
490
|
-
echo esc_url(!empty($matched_pages) ? get_permalink($matched_pages[0]->ID) : '${decoded.replace(/'/g, "\\'")}');
|
|
666
|
+
return `<?php
|
|
667
|
+
$__fwp_id = forgewp_resolve_route_page_id('${name}');
|
|
668
|
+
echo esc_url($__fwp_id ? get_permalink($__fwp_id) : '${decoded.replace(/'/g, "\\'")}');
|
|
491
669
|
?>`;
|
|
492
670
|
},
|
|
493
671
|
);
|
|
494
672
|
processed = processed.replace(
|
|
495
673
|
/__FORGEWP_PAGELINK_([a-zA-Z0-9_-]+)__/g,
|
|
496
674
|
(match, name) => {
|
|
497
|
-
return `<?php
|
|
498
|
-
$
|
|
499
|
-
$
|
|
500
|
-
if (!empty($current_lang)) {
|
|
501
|
-
$get_pages_args['lang'] = $current_lang;
|
|
502
|
-
}
|
|
503
|
-
$matched_pages = get_pages($get_pages_args);
|
|
504
|
-
echo esc_url(!empty($matched_pages) ? get_permalink($matched_pages[0]->ID) : '');
|
|
675
|
+
return `<?php
|
|
676
|
+
$__fwp_id = forgewp_resolve_route_page_id('${name}');
|
|
677
|
+
echo esc_url($__fwp_id ? get_permalink($__fwp_id) : '');
|
|
505
678
|
?>`;
|
|
506
679
|
},
|
|
507
680
|
);
|
|
@@ -509,7 +682,10 @@ ${phpArgs}
|
|
|
509
682
|
// ── Auto-hide social media container if no social links exist ──
|
|
510
683
|
let searchIndex = 0;
|
|
511
684
|
while (true) {
|
|
512
|
-
const matchStart = processed.indexOf(
|
|
685
|
+
const matchStart = processed.indexOf(
|
|
686
|
+
'data-forgewp-hide-empty-socials',
|
|
687
|
+
searchIndex,
|
|
688
|
+
);
|
|
513
689
|
if (matchStart === -1) {
|
|
514
690
|
break;
|
|
515
691
|
}
|
|
@@ -527,15 +703,34 @@ ${phpArgs}
|
|
|
527
703
|
const matchEnd = findMatchingClosingDiv(processed, contentStartIndex);
|
|
528
704
|
if (matchEnd !== -1) {
|
|
529
705
|
const fullBlock = processed.substring(divStart, matchEnd);
|
|
530
|
-
const optionMatches = Array.from(
|
|
531
|
-
|
|
532
|
-
|
|
706
|
+
const optionMatches = Array.from(
|
|
707
|
+
fullBlock.matchAll(
|
|
708
|
+
/__FORGEWP_OPTION_(social_[a-zA-Z0-9_-]+?)(?:_DEFAULT_(.*?))?__/g,
|
|
709
|
+
),
|
|
710
|
+
);
|
|
711
|
+
const optionMap = new Map();
|
|
712
|
+
for (const m of optionMatches) {
|
|
713
|
+
const name = m[1];
|
|
714
|
+
const defaultVal = m[2] ? decodeURIComponent(m[2]) : '';
|
|
715
|
+
optionMap.set(name, defaultVal);
|
|
716
|
+
}
|
|
717
|
+
const cleanBlock = fullBlock
|
|
718
|
+
.replace(/\s*data-forgewp-hide-empty-socials="[^"]*"/gi, '')
|
|
719
|
+
.replace(/\s*data-forgewp-hide-empty-socials/gi, '');
|
|
533
720
|
let replacement = cleanBlock;
|
|
534
|
-
if (
|
|
535
|
-
const conditions =
|
|
721
|
+
if (optionMap.size > 0) {
|
|
722
|
+
const conditions = Array.from(optionMap.entries())
|
|
723
|
+
.map(
|
|
724
|
+
([name, defaultVal]) =>
|
|
725
|
+
`! empty( get_option( '${name}', '${defaultVal.replace(/'/g, "\\'")}' ) )`,
|
|
726
|
+
)
|
|
727
|
+
.join(' || ');
|
|
536
728
|
replacement = `<?php if ( ${conditions} ) : ?>${cleanBlock}<?php endif; ?>`;
|
|
537
729
|
}
|
|
538
|
-
processed =
|
|
730
|
+
processed =
|
|
731
|
+
processed.substring(0, divStart) +
|
|
732
|
+
replacement +
|
|
733
|
+
processed.substring(matchEnd);
|
|
539
734
|
searchIndex = divStart + replacement.length;
|
|
540
735
|
} else {
|
|
541
736
|
searchIndex = matchStart + 31;
|
|
@@ -545,14 +740,17 @@ ${phpArgs}
|
|
|
545
740
|
// ── Auto-hide empty social links / options ──
|
|
546
741
|
// If an <a> tag has href="__FORGEWP_OPTION_social_xxx__" and the option is empty, wrap it in a PHP conditional block.
|
|
547
742
|
processed = processed.replace(
|
|
548
|
-
/<a\b([^>]*?href=["']__FORGEWP_OPTION_([a-zA-Z0-9_-]+)__["'][^>]*?)>([\s\S]*?)<\/a>/gi,
|
|
743
|
+
/<a\b([^>]*?href=["']__FORGEWP_OPTION_((?:(?!_DEFAULT_)[a-zA-Z0-9_-])+)__["'][^>]*?)>([\s\S]*?)<\/a>/gi,
|
|
549
744
|
(match, attributes, name, content) => {
|
|
550
745
|
if (name.startsWith('social_')) {
|
|
551
|
-
const cleanAttrs = attributes.replace(
|
|
746
|
+
const cleanAttrs = attributes.replace(
|
|
747
|
+
`__FORGEWP_OPTION_${name}__`,
|
|
748
|
+
`<?php echo esc_url( get_option( '${name}' ) ); ?>`,
|
|
749
|
+
);
|
|
552
750
|
return `<?php if ( ! empty( get_option( '${name}' ) ) ) : ?><a${cleanAttrs}>${content}</a><?php endif; ?>`;
|
|
553
751
|
}
|
|
554
752
|
return match;
|
|
555
|
-
}
|
|
753
|
+
},
|
|
556
754
|
);
|
|
557
755
|
|
|
558
756
|
processed = processed.replace(
|
|
@@ -560,11 +758,14 @@ ${phpArgs}
|
|
|
560
758
|
(match, attributes, name, defaultVal, content) => {
|
|
561
759
|
if (name.startsWith('social_')) {
|
|
562
760
|
const decoded = decodeURIComponent(defaultVal);
|
|
563
|
-
const cleanAttrs = attributes.replace(
|
|
564
|
-
|
|
761
|
+
const cleanAttrs = attributes.replace(
|
|
762
|
+
`__FORGEWP_OPTION_${name}_DEFAULT_${defaultVal}__`,
|
|
763
|
+
`<?php echo esc_url( get_option( '${name}', '${decoded.replace(/'/g, "\\'")}' ) ); ?>`,
|
|
764
|
+
);
|
|
765
|
+
return `<?php if ( ! empty( get_option( '${name}', '${decoded.replace(/'/g, "\\'")}' ) ) ) : ?><a${cleanAttrs}>${content}</a><?php endif; ?>`;
|
|
565
766
|
}
|
|
566
767
|
return match;
|
|
567
|
-
}
|
|
768
|
+
},
|
|
568
769
|
);
|
|
569
770
|
|
|
570
771
|
// ── Options & Customizer Theme Mods Support ──
|
|
@@ -578,11 +779,22 @@ ${phpArgs}
|
|
|
578
779
|
if (name === 'blogdescription') {
|
|
579
780
|
return `<?php echo esc_html( get_bloginfo( 'description' ) ); ?>`;
|
|
580
781
|
}
|
|
581
|
-
|
|
782
|
+
// Resolve any nested __FORGEWP_I18N_text__ tokens inside the default value
|
|
783
|
+
const cleanDecoded = decoded
|
|
784
|
+
.replace(/'/g, "\\'") // escape single quotes first
|
|
785
|
+
.replace(/__FORGEWP_I18N_([^_](?:[^_]|_(?!_))*?)__/gi, (m, text) => {
|
|
786
|
+
const cleanText = text
|
|
787
|
+
.replace(/'/g, "'")
|
|
788
|
+
.replace(/"/g, '"')
|
|
789
|
+
.replace(/&/g, '&')
|
|
790
|
+
.replace(/'/g, "\\'");
|
|
791
|
+
return `' . __('${cleanText}', '${textDomain}') . '`;
|
|
792
|
+
});
|
|
793
|
+
return `<?php echo esc_html( get_option( '${name}', '${cleanDecoded}' ) ); ?>`;
|
|
582
794
|
},
|
|
583
795
|
);
|
|
584
796
|
processed = processed.replace(
|
|
585
|
-
/__FORGEWP_OPTION_([a-zA-Z0-9_-]+)__/g,
|
|
797
|
+
/__FORGEWP_OPTION_((?:(?!_DEFAULT_)[a-zA-Z0-9_-])+)__/g,
|
|
586
798
|
(match, name) => {
|
|
587
799
|
if (name === 'blogname') {
|
|
588
800
|
return `<?php echo esc_html( get_bloginfo( 'name' ) ); ?>`;
|
|
@@ -602,13 +814,13 @@ ${phpArgs}
|
|
|
602
814
|
},
|
|
603
815
|
);
|
|
604
816
|
processed = processed.replace(
|
|
605
|
-
/__FORGEWP_THEME_MOD_([a-zA-Z0-9_-]+)__/g,
|
|
817
|
+
/__FORGEWP_THEME_MOD_((?:(?!_DEFAULT_)[a-zA-Z0-9_-])+)__/g,
|
|
606
818
|
"<?php echo esc_html( get_theme_mod( '$1' ) ); ?>",
|
|
607
819
|
);
|
|
608
820
|
|
|
609
821
|
processed = processed.replace(
|
|
610
822
|
/__FORGEWP_THEME_URI__/g,
|
|
611
|
-
|
|
823
|
+
'<?php echo esc_url( get_template_directory_uri() ); ?>',
|
|
612
824
|
);
|
|
613
825
|
|
|
614
826
|
// ── WooCommerce Product Loop Blocks ──
|
|
@@ -659,20 +871,94 @@ ${phpArgs}
|
|
|
659
871
|
// ── WooCommerce Dynamic Hook Replacements ──
|
|
660
872
|
processed = processed.replace(
|
|
661
873
|
/__FORGEWP_PRODUCT_PRICE__/g,
|
|
662
|
-
'<?php global $product; echo wp_kses_post( $product->get_price_html() ); ?>'
|
|
874
|
+
'<?php global $product; echo wp_kses_post( $product->get_price_html() ); ?>',
|
|
663
875
|
);
|
|
664
876
|
processed = processed.replace(
|
|
665
877
|
/__FORGEWP_PRODUCT_SKU__/g,
|
|
666
|
-
'<?php global $product; echo esc_html( $product->get_sku() ); ?>'
|
|
878
|
+
'<?php global $product; echo esc_html( $product->get_sku() ); ?>',
|
|
667
879
|
);
|
|
668
880
|
processed = processed.replace(
|
|
669
881
|
/__FORGEWP_PRODUCT_RATING__/g,
|
|
670
|
-
'<?php global $product; echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>'
|
|
882
|
+
'<?php global $product; echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>',
|
|
883
|
+
);
|
|
884
|
+
|
|
885
|
+
// ── Translate Compile-Time encodeURIComponent Wrapper to rawurlencode in PHP ──
|
|
886
|
+
processed = processed.replace(
|
|
887
|
+
/__FORGEWP_URLENCODE_START__(.*?)__FORGEWP_URLENCODE_END__/gs,
|
|
888
|
+
(match, content) => {
|
|
889
|
+
const tokens = [];
|
|
890
|
+
let lastIndex = 0;
|
|
891
|
+
const phpRegex = /<\?php\s+(?:echo\s+)?(.*?);\s*\?>/g;
|
|
892
|
+
let m;
|
|
893
|
+
while ((m = phpRegex.exec(content)) !== null) {
|
|
894
|
+
if (m.index > lastIndex) {
|
|
895
|
+
const staticText = content.substring(lastIndex, m.index);
|
|
896
|
+
tokens.push(JSON.stringify(staticText));
|
|
897
|
+
}
|
|
898
|
+
tokens.push(`(${m[1]})`);
|
|
899
|
+
lastIndex = phpRegex.lastIndex;
|
|
900
|
+
}
|
|
901
|
+
if (lastIndex < content.length) {
|
|
902
|
+
const staticText = content.substring(lastIndex);
|
|
903
|
+
tokens.push(JSON.stringify(staticText));
|
|
904
|
+
}
|
|
905
|
+
const phpExpr = tokens.join(' . ');
|
|
906
|
+
return `<?php echo rawurlencode(${phpExpr}); ?>`;
|
|
907
|
+
},
|
|
671
908
|
);
|
|
672
909
|
|
|
673
910
|
return processed;
|
|
674
911
|
}
|
|
675
912
|
|
|
913
|
+
function getResponsiveImageAttributes(src, assetGraph, existingAttrs) {
|
|
914
|
+
if (!src || !assetGraph || typeof assetGraph.getAsset !== 'function') {
|
|
915
|
+
return [];
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const node = assetGraph.getAsset(src);
|
|
919
|
+
if (
|
|
920
|
+
!node ||
|
|
921
|
+
node.classification !== 'local-static' ||
|
|
922
|
+
!Array.isArray(node.variants) ||
|
|
923
|
+
node.variants.length === 0
|
|
924
|
+
) {
|
|
925
|
+
return [];
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
const hasAttribute = (name) =>
|
|
929
|
+
new RegExp(`\\b${name}\\s*=`, 'i').test(existingAttrs);
|
|
930
|
+
const variants = node.variants.filter(
|
|
931
|
+
(variant) =>
|
|
932
|
+
variant &&
|
|
933
|
+
typeof variant.publicUrl === 'string' &&
|
|
934
|
+
Number(variant.width) > 0,
|
|
935
|
+
);
|
|
936
|
+
if (variants.length === 0) return [];
|
|
937
|
+
|
|
938
|
+
const escapePhpString = (value) =>
|
|
939
|
+
value.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
940
|
+
const srcset = variants
|
|
941
|
+
.map(
|
|
942
|
+
(variant) =>
|
|
943
|
+
`<?php echo esc_url( get_theme_file_uri( '${escapePhpString(variant.publicUrl)}' ) ); ?> ${Number(variant.width)}w`,
|
|
944
|
+
)
|
|
945
|
+
.join(', ');
|
|
946
|
+
const attributes = [];
|
|
947
|
+
|
|
948
|
+
if (!hasAttribute('srcset')) attributes.push(`srcset="${srcset}"`);
|
|
949
|
+
if (node.sizes && !hasAttribute('sizes')) {
|
|
950
|
+
attributes.push(`sizes="${node.sizes}"`);
|
|
951
|
+
}
|
|
952
|
+
if (node.width && !hasAttribute('width')) {
|
|
953
|
+
attributes.push(`width="${node.width}"`);
|
|
954
|
+
}
|
|
955
|
+
if (node.height && !hasAttribute('height')) {
|
|
956
|
+
attributes.push(`height="${node.height}"`);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
return attributes;
|
|
960
|
+
}
|
|
961
|
+
|
|
676
962
|
function findMatchingClosingDiv(html, startIndex) {
|
|
677
963
|
let openCount = 1;
|
|
678
964
|
let index = startIndex;
|