@forgewp/compiler 0.4.2 → 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.
Files changed (144) hide show
  1. package/README.md +70 -3
  2. package/bin/add.js +30 -15
  3. package/bin/analyze.js +66 -1
  4. package/bin/cli.js +149 -70
  5. package/bin/doctor.js +21 -12
  6. package/bin/export.js +69 -20
  7. package/bin/fresh.js +6 -1
  8. package/bin/i18n-extract.js +3 -10
  9. package/bin/i18n-translate.js +15 -24
  10. package/bin/make-block.js +24 -0
  11. package/bin/make-editable.js +166 -0
  12. package/bin/make-form.js +131 -0
  13. package/bin/make-island.js +11 -0
  14. package/bin/make-loop.js +147 -0
  15. package/bin/make-mail.js +27 -0
  16. package/bin/make-page.js +83 -0
  17. package/bin/make-post-type.js +68 -29
  18. package/bin/make-sandbox.js +609 -0
  19. package/bin/make-section.js +221 -0
  20. package/bin/make-shell.js +375 -0
  21. package/bin/repair.js +14 -26
  22. package/bin/seed.js +119 -0
  23. package/bin/sync-routes.js +107 -85
  24. package/lib/adapters/html-adapter.js +13 -3
  25. package/lib/adapters/stub-adapter.js +10 -2
  26. package/lib/add-component.js +153 -92
  27. package/lib/asset-loader.js +333 -1
  28. package/lib/assets/asset-graph.js +432 -0
  29. package/lib/assets/asset-pipeline.js +125 -0
  30. package/lib/assets/diagnostics-report.js +345 -0
  31. package/lib/assets/external-fetcher.js +173 -0
  32. package/lib/assets/font-orchestrator.js +348 -0
  33. package/lib/assets/font-usage-scanner.js +242 -0
  34. package/lib/assets/image-optimizer.js +229 -0
  35. package/lib/assets/index.js +51 -0
  36. package/lib/assets/preload-generator.js +70 -0
  37. package/lib/assets/public-url.js +153 -0
  38. package/lib/block-authoring-help.js +11 -0
  39. package/lib/blocks/ast-parser.js +67 -0
  40. package/lib/blocks/discover-blocks.js +146 -0
  41. package/lib/blocks/editor-scope.js +733 -0
  42. package/lib/blocks/editor-transpiler.js +1229 -0
  43. package/lib/blocks/index.js +2838 -0
  44. package/lib/blocks/php-transpiler.js +4928 -0
  45. package/lib/blocks/scanner.js +1487 -0
  46. package/lib/blocks/shared-utils.js +290 -0
  47. package/lib/blocks/source-sanitize.js +1449 -0
  48. package/lib/blueprints.js +77 -5
  49. package/lib/build-assets.js +38 -33
  50. package/lib/collect-page-template-routes.js +102 -0
  51. package/lib/collect-static-routes.js +175 -0
  52. package/lib/diagnostics.js +58 -33
  53. package/lib/export-theme.js +84 -5
  54. package/lib/extract-template-content.js +90 -0
  55. package/lib/forms-preview.js +42 -0
  56. package/lib/functions/cpt-routing.js +69 -0
  57. package/lib/functions/forms.js +2461 -0
  58. package/lib/functions/hydration-enqueuer.js +400 -0
  59. package/lib/functions/index.js +1623 -0
  60. package/lib/functions/load-menus.js +112 -0
  61. package/lib/functions/load-translations.js +148 -0
  62. package/lib/functions/rest-endpoints.js +2923 -0
  63. package/lib/functions/routing.js +765 -0
  64. package/lib/functions/seed-mock-data.js +392 -0
  65. package/lib/functions/seed-products.js +481 -0
  66. package/lib/functions/settings-page.js +273 -0
  67. package/lib/functions/theme-setup.js +494 -0
  68. package/lib/generate-theme.js +2076 -303
  69. package/lib/hydration/editable-schemas.js +332 -0
  70. package/lib/hydration/enter-hidden-initial.js +65 -0
  71. package/lib/hydration/form-schemas.js +227 -0
  72. package/lib/hydration/index.js +12 -0
  73. package/lib/hydration/is-interactive.js +951 -0
  74. package/lib/hydration/island-split.js +1231 -0
  75. package/lib/hydration/islands-scanner.js +599 -0
  76. package/lib/hydration/resolve-island-chunk.js +103 -0
  77. package/lib/hydration/resolve-island-component.js +52 -0
  78. package/lib/hydration/rollup-inputs.js +81 -0
  79. package/lib/hydration/root-class-extractor.js +220 -0
  80. package/lib/hydration/scan-app-providers.js +154 -0
  81. package/lib/hydration/static-lint.js +382 -0
  82. package/lib/hydration/transform.js +257 -0
  83. package/lib/hydration/uses-block-area.js +49 -0
  84. package/lib/hydration/utils.js +119 -0
  85. package/lib/i18n/translation-cache.js +141 -0
  86. package/lib/icon-registry.js +72 -0
  87. package/lib/index.d.ts +324 -8
  88. package/lib/index.js +3 -2
  89. package/lib/load-config.js +338 -144
  90. package/lib/mail-templates.js +37 -0
  91. package/lib/markup-processor.js +483 -92
  92. package/lib/node-runtime.js +7 -0
  93. package/lib/page-config-plugin.js +84 -0
  94. package/lib/php-builders.js +383 -42
  95. package/lib/react-adapter.js +1053 -246
  96. package/lib/registration-metadata.js +11 -0
  97. package/lib/render-theme.mts +1410 -543
  98. package/lib/route-layout.js +76 -0
  99. package/lib/template-discovery.js +58 -0
  100. package/lib/theme-compatibility.js +32 -0
  101. package/lib/validate-export.js +51 -2
  102. package/lib/validate.js +27 -5
  103. package/lib/virtual-plugin.js +319 -0
  104. package/lib/walkthrough.md +26 -0
  105. package/package.json +17 -5
  106. package/templates/PresetsStyle.tsx +1 -1
  107. package/templates/auth/cms/email-logs.json +9 -0
  108. package/templates/auth/cms/menus.json +11 -0
  109. package/templates/auth/cms/mock-data.json +123 -0
  110. package/templates/auth/cms/roles.json +7 -0
  111. package/templates/auth/cms/sessions.json +1 -0
  112. package/templates/auth/cms/site-settings.json +28 -0
  113. package/templates/auth/cms/translations.json +4 -0
  114. package/templates/auth/cms/users.json +46 -0
  115. package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
  116. package/templates/auth/components/forgot-password-form-wrapper.tsx +141 -0
  117. package/templates/auth/components/login-form-wrapper.tsx +300 -0
  118. package/templates/auth/components/reset-password-form-wrapper.tsx +190 -0
  119. package/templates/auth/components/signup-form-wrapper.tsx +257 -0
  120. package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
  121. package/templates/auth/pages/DashboardPage.tsx +12 -0
  122. package/templates/auth/pages/ForgotPasswordPage.tsx +11 -0
  123. package/templates/auth/pages/LoginPage.tsx +11 -0
  124. package/templates/auth/pages/ResetPasswordPage.tsx +11 -0
  125. package/templates/auth/pages/SignUpPage.tsx +11 -0
  126. package/templates/auth/pages/VerifyEmailPage.tsx +11 -0
  127. package/templates/auth/ui/button.tsx +57 -0
  128. package/templates/auth/ui/card.tsx +76 -0
  129. package/templates/auth/ui/field.tsx +242 -0
  130. package/templates/auth/ui/input.tsx +22 -0
  131. package/templates/auth/ui/label.tsx +24 -0
  132. package/templates/auth/ui/separator.tsx +31 -0
  133. package/templates/forgewp-config.ts +70 -3
  134. package/templates/menus.json +12 -10
  135. package/templates/mock-data.json +122 -433
  136. package/templates/products.json +5 -0
  137. package/templates/roles.json +7 -0
  138. package/templates/sessions.json +1 -0
  139. package/templates/users.json +38 -0
  140. package/templates/wordpress.tsx +1835 -1297
  141. package/bin/make-template.js +0 -145
  142. package/lib/block-compiler.js +0 -552
  143. package/lib/functions-builder.js +0 -2044
  144. package/lib/hydration-scanner.js +0 -821
@@ -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(html, textDomain = 'theme') {
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
- 'href="<?php echo esc_url( function_exists( \'pll_home_url\' ) ? pll_home_url( function_exists( \'pll_current_language\' ) ? pll_current_language() : \'\' ) : home_url( \'/\' ) ); ?>"',
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
- '<?php echo html_entity_decode( get_the_title(), ENT_QUOTES | ENT_HTML5, \'UTF-8\' ); ?>',
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(/&#39;/g, "'")
151
+ .replace(/&quot;/g, '"')
152
+ .replace(/&amp;/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_(.*?)__/g,
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_([^_](?:[^_]|_(?!_))*?)__/g,
192
+ /__FORGEWP_I18N_([^_](?:[^_]|_(?!_))*?)__/gi,
106
193
  (m, text) => {
107
194
  const cleanText = text
108
195
  .replace(/&#39;/g, "'")
@@ -110,11 +197,21 @@ export function processMarkup(html, textDomain = 'theme') {
110
197
  .replace(/&amp;/g, '&')
111
198
  .replace(/'/g, "\\'");
112
199
  return `' . __('${cleanText}', '${textDomain}') . '`;
113
- }
200
+ },
114
201
  );
115
- const isRichText = decoded.includes('<p>') || decoded.includes('</p>') || decoded.includes('<br') || key.includes('subtitle') || key.includes('content') || key.includes('bio');
116
- return `<?php echo forgewp_get_meta_value( '${key}', '${cleanDecoded}', ${isRichText ? 'true' : 'false'} ); ?>`;
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 = getAttr('class') || getAttr('className') || '';
170
- const linkClass = getAttr('linkClassName') || getAttr('linkclassname') || '';
171
- const showFlags = getAttr('showFlags') === '1';
172
- const showNames = getAttr('showNames') === '1';
173
- const showCodes = getAttr('showCodes') !== '0'; // default true
174
-
175
- const flagsPart = showFlags ? "echo '<img src=\"' . esc_url($l['flag']) . '\" alt=\"' . esc_attr($l['name']) . '\" />';" : '';
176
- const codesPart = showCodes ? "echo esc_html(strtoupper($l['slug']));" : '';
177
- const namesPart = showNames ? "echo ' ' . esc_html($l['name']);" : '';
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,10 +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') || '';
362
+ const orderby = getAttr('orderby') || '';
363
+ const order = getAttr('order') || '';
259
364
  const metaKey = getAttr('metaKey') || getAttr('metakey') || '';
260
365
  const metaValue = getAttr('metaValue') || getAttr('metavalue') || '';
261
- const metaCompare = getAttr('metaCompare') || getAttr('metacompare') || '=';
262
- const taxTaxonomy = getAttr('taxTaxonomy') || getAttr('taxtaxonomy') || '';
366
+ const metaCompare =
367
+ getAttr('metaCompare') || getAttr('metacompare') || '=';
368
+ const taxTaxonomy =
369
+ getAttr('taxTaxonomy') || getAttr('taxtaxonomy') || '';
263
370
  const taxTerms = getAttr('taxTerms') || getAttr('taxterms') || '';
264
371
  const postIn = getAttr('postIn') || getAttr('postin') || '';
265
372
 
@@ -282,11 +389,20 @@ if (function_exists('pll_the_languages')) {
282
389
  }
283
390
 
284
391
  let phpArgs = ` 'post_type' => '${postType}',\n 'posts_per_page' => ${postsPerPage},`;
285
-
392
+
393
+ if (orderby !== '') {
394
+ phpArgs += `\n 'orderby' => '${orderby}',`;
395
+ }
396
+ if (order !== '') {
397
+ phpArgs += `\n 'order' => '${order}',`;
398
+ }
286
399
  if (categoryName !== '') {
287
400
  phpArgs += `\n 'category_name' => '${categoryName}',`;
288
401
  }
289
-
402
+ if (/^\d+$/.test(postId)) {
403
+ phpArgs += `\n 'p' => ${postId},`;
404
+ }
405
+
290
406
  if (metaKey !== '') {
291
407
  let valExpr = `'${metaValue}'`;
292
408
  if (metaValue === 'CURRENT_POST_ID') {
@@ -294,7 +410,7 @@ if (function_exists('pll_the_languages')) {
294
410
  } else if (metaValue === ',CURRENT_POST_ID,') {
295
411
  valExpr = "',' . get_the_ID() . ','";
296
412
  }
297
-
413
+
298
414
  phpArgs += `\n 'meta_query' => array(
299
415
  array(
300
416
  'key' => '${metaKey}',
@@ -303,7 +419,7 @@ if (function_exists('pll_the_languages')) {
303
419
  )
304
420
  ),`;
305
421
  }
306
-
422
+
307
423
  if (taxTaxonomy !== '') {
308
424
  phpArgs += `\n 'tax_query' => array(
309
425
  array(
@@ -347,30 +463,134 @@ ${phpArgs}
347
463
 
348
464
  const id = getAttr('id');
349
465
  const field = getAttr('field');
466
+ const src = getAttr('src');
350
467
  const size = getAttr('size') || 'full';
351
- const className = getAttr('class-name');
468
+ const className = getAttr('class-name') || getAttr('class');
352
469
  const alt = getAttr('alt');
353
-
354
- if (id) {
355
- return `<?php echo wp_get_attachment_image( ${id}, '${size}', false, array( 'class' => '${className}', 'alt' => '${alt}' ) ); ?>`;
356
- } else if (field === 'featuredImage') {
357
- return `<?php echo wp_get_attachment_image( get_post_thumbnail_id( get_the_ID() ), '${size}', false, array( 'class' => '${className}', 'alt' => '${alt}' ) ); ?>`;
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} ); ?>`;
358
525
  } else if (field) {
359
526
  return `<?php
360
527
  $img_val = get_post_meta( get_the_ID(), '${field}', true );
361
528
  if ( is_numeric( $img_val ) ) {
362
- echo wp_get_attachment_image( $img_val, '${size}', false, array( 'class' => '${className}', 'alt' => '${alt}' ) );
529
+ echo wp_get_attachment_image( $img_val, '${size}', false, ${phpAttrStr} );
363
530
  } elseif ( ! empty( $img_val ) ) {
364
- echo '<img src="' . esc_url( $img_val ) . '" class="' . esc_attr( '${className}' ) . '" alt="' . esc_attr( '${alt}' ) . '" />';
531
+ echo '<img src="' . esc_url( $img_val ) . '"' . esc_attr( '${extraHtmlStr}' ) . ' />';
365
532
  }
366
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} />`;
367
541
  } else {
368
- return `<img class="${className}" alt="${alt}" src="<?php echo esc_url( get_theme_file_uri( 'assets/image-placeholder.png' ) ); ?>" />`;
542
+ return `<img src="<?php echo esc_url( get_theme_file_uri( 'assets/image-placeholder.png' ) ); ?>"${extraHtmlStr} />`;
369
543
  }
370
544
  },
371
545
  );
372
546
  processed = processed.replace(/<\/forgewp-image>/g, '');
373
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
+
374
594
  // ── Declarative WpRepeater Loops ──
375
595
  processed = processed.replace(
376
596
  /<forgewp-repeater-start\s+name="([^"]+)"\s+subfields="([^"]+)"\s*\/?>/g,
@@ -379,7 +599,7 @@ ${phpArgs}
379
599
  .split(',')
380
600
  .map((f) => `'${f.trim()}'`)
381
601
  .join(', ');
382
-
602
+
383
603
  return `<?php
384
604
  $repeater_key = '${name}';
385
605
  $sub_fields = array(${subfieldsArrayStr});
@@ -389,44 +609,53 @@ ${phpArgs}
389
609
  }
390
610
  foreach ($repeater_rows as $row) {
391
611
  ?>`;
392
- }
612
+ },
393
613
  );
394
614
  processed = processed.replace(/<\/forgewp-repeater-start>/g, '');
395
615
 
396
616
  processed = processed.replace(/<forgewp-repeater-end\s*\/?>/g, '');
397
617
  processed = processed.replace(/<\/forgewp-repeater-end>/g, '<?php } ?>');
398
618
 
399
- // ── Dynamic WpIcon Custom SVGs ──
619
+ // ── Authentication & Capability Gates ──
400
620
  processed = processed.replace(
401
- /<forgewp-icon-placeholder\s+([^>]*)\/?>/g,
402
- (match, attrsStr) => {
403
- const getAttr = (name) => {
404
- const regex = new RegExp(
405
- `(?:${name}|${name.toLowerCase()})=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
406
- 'i',
407
- );
408
- const m = attrsStr.match(regex);
409
- return m ? m[1] || m[2] || m[3] || '' : '';
410
- };
621
+ /<forgewp-auth-gate-start\s*\/?>/g,
622
+ '<?php if ( is_user_logged_in() ) : ?>',
623
+ );
624
+ processed = processed.replace(/<\/forgewp-auth-gate-start>/g, '');
411
625
 
412
- const nameAttr = getAttr('name');
413
- const provider = getAttr('provider') || 'lucide';
414
- const className = getAttr('class') || getAttr('className') || '';
626
+ processed = processed.replace(
627
+ /<forgewp-auth-gate-fallback\s*\/?>/g,
628
+ '<?php else : ?>',
629
+ );
630
+ processed = processed.replace(/<\/forgewp-auth-gate-fallback>/g, '');
415
631
 
416
- const fieldMatch = nameAttr.match(/__FORGEWP_REPEATER_FIELD_([a-zA-Z0-9_-]+)__/);
417
- if (fieldMatch) {
418
- const fieldName = fieldMatch[1];
419
- return `<?php forgewp_render_theme_icon($row['${fieldName}'], '${className}', '${provider}'); ?>`;
420
- }
632
+ processed = processed.replace(
633
+ /<forgewp-auth-gate-end\s*\/?>/g,
634
+ '<?php endif; ?>',
635
+ );
636
+ processed = processed.replace(/<\/forgewp-auth-gate-end>/g, '');
421
637
 
422
- return `<?php forgewp_render_theme_icon('${nameAttr}', '${className}', '${provider}'); ?>`;
423
- }
638
+ processed = processed.replace(
639
+ /<forgewp-capability-gate-start\s+[^>]*allowed="([^"]+)"\s*\/?>/g,
640
+ "<?php if ( current_user_can( '$1' ) ) : ?>",
424
641
  );
425
- processed = processed.replace(/<\/forgewp-icon-placeholder>/g, '');
642
+ processed = processed.replace(/<\/forgewp-capability-gate-start>/g, '');
643
+
644
+ processed = processed.replace(
645
+ /<forgewp-capability-gate-fallback\s*\/?>/g,
646
+ '<?php else : ?>',
647
+ );
648
+ processed = processed.replace(/<\/forgewp-capability-gate-fallback>/g, '');
649
+
650
+ processed = processed.replace(
651
+ /<forgewp-capability-gate-end\s*\/?>/g,
652
+ '<?php endif; ?>',
653
+ );
654
+ processed = processed.replace(/<\/forgewp-capability-gate-end>/g, '');
426
655
 
427
656
  processed = processed.replace(
428
657
  /__FORGEWP_REPEATER_FIELD_([a-zA-Z0-9_-]+)__/g,
429
- (match, fieldName) => `<?php echo esc_html($row['${fieldName}']); ?>`
658
+ (match, fieldName) => `<?php echo esc_html($row['${fieldName}']); ?>`,
430
659
  );
431
660
 
432
661
  // ── Page Links Support ──
@@ -434,28 +663,18 @@ ${phpArgs}
434
663
  /__FORGEWP_PAGELINK_([a-zA-Z0-9_-]+)_DEFAULT_(.*?)__/g,
435
664
  (match, name, defaultVal) => {
436
665
  const decoded = decodeURIComponent(defaultVal);
437
- return `<?php
438
- $current_lang = function_exists('pll_current_language') ? pll_current_language() : '';
439
- $get_pages_args = array('meta_key' => '_wp_page_template', 'meta_value' => 'page-${name}.php', 'number' => 1);
440
- if (!empty($current_lang)) {
441
- $get_pages_args['lang'] = $current_lang;
442
- }
443
- $matched_pages = get_pages($get_pages_args);
444
- 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, "\\'")}');
445
669
  ?>`;
446
670
  },
447
671
  );
448
672
  processed = processed.replace(
449
673
  /__FORGEWP_PAGELINK_([a-zA-Z0-9_-]+)__/g,
450
674
  (match, name) => {
451
- return `<?php
452
- $current_lang = function_exists('pll_current_language') ? pll_current_language() : '';
453
- $get_pages_args = array('meta_key' => '_wp_page_template', 'meta_value' => 'page-${name}.php', 'number' => 1);
454
- if (!empty($current_lang)) {
455
- $get_pages_args['lang'] = $current_lang;
456
- }
457
- $matched_pages = get_pages($get_pages_args);
458
- 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) : '');
459
678
  ?>`;
460
679
  },
461
680
  );
@@ -463,7 +682,10 @@ ${phpArgs}
463
682
  // ── Auto-hide social media container if no social links exist ──
464
683
  let searchIndex = 0;
465
684
  while (true) {
466
- const matchStart = processed.indexOf('data-forgewp-hide-empty-socials', searchIndex);
685
+ const matchStart = processed.indexOf(
686
+ 'data-forgewp-hide-empty-socials',
687
+ searchIndex,
688
+ );
467
689
  if (matchStart === -1) {
468
690
  break;
469
691
  }
@@ -481,15 +703,34 @@ ${phpArgs}
481
703
  const matchEnd = findMatchingClosingDiv(processed, contentStartIndex);
482
704
  if (matchEnd !== -1) {
483
705
  const fullBlock = processed.substring(divStart, matchEnd);
484
- const optionMatches = Array.from(fullBlock.matchAll(/__FORGEWP_OPTION_(social_[a-zA-Z0-9_-]+)__/g));
485
- const optionNames = Array.from(new Set(optionMatches.map(m => m[1])));
486
- const cleanBlock = fullBlock.replace(/\s*data-forgewp-hide-empty-socials="[^"]*"/gi, '').replace(/\s*data-forgewp-hide-empty-socials/gi, '');
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, '');
487
720
  let replacement = cleanBlock;
488
- if (optionNames.length > 0) {
489
- const conditions = optionNames.map(name => `! empty( get_option( '${name}' ) )`).join(' || ');
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(' || ');
490
728
  replacement = `<?php if ( ${conditions} ) : ?>${cleanBlock}<?php endif; ?>`;
491
729
  }
492
- processed = processed.substring(0, divStart) + replacement + processed.substring(matchEnd);
730
+ processed =
731
+ processed.substring(0, divStart) +
732
+ replacement +
733
+ processed.substring(matchEnd);
493
734
  searchIndex = divStart + replacement.length;
494
735
  } else {
495
736
  searchIndex = matchStart + 31;
@@ -499,14 +740,17 @@ ${phpArgs}
499
740
  // ── Auto-hide empty social links / options ──
500
741
  // If an <a> tag has href="__FORGEWP_OPTION_social_xxx__" and the option is empty, wrap it in a PHP conditional block.
501
742
  processed = processed.replace(
502
- /<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,
503
744
  (match, attributes, name, content) => {
504
745
  if (name.startsWith('social_')) {
505
- const cleanAttrs = attributes.replace(`__FORGEWP_OPTION_${name}__`, `<?php echo esc_url( get_option( '${name}' ) ); ?>`);
746
+ const cleanAttrs = attributes.replace(
747
+ `__FORGEWP_OPTION_${name}__`,
748
+ `<?php echo esc_url( get_option( '${name}' ) ); ?>`,
749
+ );
506
750
  return `<?php if ( ! empty( get_option( '${name}' ) ) ) : ?><a${cleanAttrs}>${content}</a><?php endif; ?>`;
507
751
  }
508
752
  return match;
509
- }
753
+ },
510
754
  );
511
755
 
512
756
  processed = processed.replace(
@@ -514,11 +758,14 @@ ${phpArgs}
514
758
  (match, attributes, name, defaultVal, content) => {
515
759
  if (name.startsWith('social_')) {
516
760
  const decoded = decodeURIComponent(defaultVal);
517
- const cleanAttrs = attributes.replace(`__FORGEWP_OPTION_${name}_DEFAULT_${defaultVal}__`, `<?php echo esc_url( get_option( '${name}', '${decoded}' ) ); ?>`);
518
- return `<?php if ( ! empty( get_option( '${name}' ) ) ) : ?><a${cleanAttrs}>${content}</a><?php endif; ?>`;
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; ?>`;
519
766
  }
520
767
  return match;
521
- }
768
+ },
522
769
  );
523
770
 
524
771
  // ── Options & Customizer Theme Mods Support ──
@@ -532,11 +779,22 @@ ${phpArgs}
532
779
  if (name === 'blogdescription') {
533
780
  return `<?php echo esc_html( get_bloginfo( 'description' ) ); ?>`;
534
781
  }
535
- return `<?php echo esc_html( get_option( '${name}', '${decoded}' ) ); ?>`;
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(/&#39;/g, "'")
788
+ .replace(/&quot;/g, '"')
789
+ .replace(/&amp;/g, '&')
790
+ .replace(/'/g, "\\'");
791
+ return `' . __('${cleanText}', '${textDomain}') . '`;
792
+ });
793
+ return `<?php echo esc_html( get_option( '${name}', '${cleanDecoded}' ) ); ?>`;
536
794
  },
537
795
  );
538
796
  processed = processed.replace(
539
- /__FORGEWP_OPTION_([a-zA-Z0-9_-]+)__/g,
797
+ /__FORGEWP_OPTION_((?:(?!_DEFAULT_)[a-zA-Z0-9_-])+)__/g,
540
798
  (match, name) => {
541
799
  if (name === 'blogname') {
542
800
  return `<?php echo esc_html( get_bloginfo( 'name' ) ); ?>`;
@@ -556,18 +814,151 @@ ${phpArgs}
556
814
  },
557
815
  );
558
816
  processed = processed.replace(
559
- /__FORGEWP_THEME_MOD_([a-zA-Z0-9_-]+)__/g,
817
+ /__FORGEWP_THEME_MOD_((?:(?!_DEFAULT_)[a-zA-Z0-9_-])+)__/g,
560
818
  "<?php echo esc_html( get_theme_mod( '$1' ) ); ?>",
561
819
  );
562
820
 
563
821
  processed = processed.replace(
564
822
  /__FORGEWP_THEME_URI__/g,
565
- "<?php echo esc_url( get_template_directory_uri() ); ?>",
823
+ '<?php echo esc_url( get_template_directory_uri() ); ?>',
824
+ );
825
+
826
+ // ── WooCommerce Product Loop Blocks ──
827
+ processed = processed.replace(
828
+ /<forgewp-product-loop-start\s+([^>]*)\/?>/g,
829
+ (match, attrsStr) => {
830
+ const getAttr = (name) => {
831
+ const regex = new RegExp(
832
+ `(?:${name}|${name.toLowerCase()})=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
833
+ 'i',
834
+ );
835
+ const m = attrsStr.match(regex);
836
+ return m ? m[1] || m[2] || m[3] || '' : '';
837
+ };
838
+
839
+ const category = getAttr('category') || '';
840
+ const limit = getAttr('limit') || '10';
841
+ const orderBy = getAttr('orderBy') || getAttr('orderby') || 'date';
842
+ const order = getAttr('order') || 'desc';
843
+ const status = getAttr('status') || 'publish';
844
+
845
+ let catQuery = '';
846
+ if (category !== '') {
847
+ catQuery = `\n 'category' => array('${category}'),`;
848
+ }
849
+
850
+ return `<?php
851
+ $query_args = array(
852
+ 'limit' => ${limit},
853
+ 'orderby' => '${orderBy}',
854
+ 'order' => '${order}',
855
+ 'status' => '${status}',${catQuery}
856
+ );
857
+ $products = wc_get_products($query_args);
858
+ foreach ($products as $product) {
859
+ global $product;
860
+ setup_postdata(get_the_ID());
861
+ ?>`;
862
+ },
863
+ );
864
+ processed = processed.replace(/<\/forgewp-product-loop-start>/g, '');
865
+ processed = processed.replace(
866
+ /<forgewp-product-loop-end\s*\/?>/g,
867
+ '<?php\n }\n wp_reset_postdata();\n ?>',
868
+ );
869
+ processed = processed.replace(/<\/forgewp-product-loop-end>/g, '');
870
+
871
+ // ── WooCommerce Dynamic Hook Replacements ──
872
+ processed = processed.replace(
873
+ /__FORGEWP_PRODUCT_PRICE__/g,
874
+ '<?php global $product; echo wp_kses_post( $product->get_price_html() ); ?>',
875
+ );
876
+ processed = processed.replace(
877
+ /__FORGEWP_PRODUCT_SKU__/g,
878
+ '<?php global $product; echo esc_html( $product->get_sku() ); ?>',
879
+ );
880
+ processed = processed.replace(
881
+ /__FORGEWP_PRODUCT_RATING__/g,
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
+ },
566
908
  );
567
909
 
568
910
  return processed;
569
911
  }
570
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
+
571
962
  function findMatchingClosingDiv(html, startIndex) {
572
963
  let openCount = 1;
573
964
  let index = startIndex;