mnfst-render 0.1.2 → 0.1.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 (2) hide show
  1. package/manifest.render.mjs +18 -14
  2. package/package.json +1 -1
@@ -384,8 +384,10 @@ function stripPrerenderDynamicBindings(html) {
384
384
  const bindingRegex = /(?:^|\s)(?::|x-bind:)(\w+)=(?:"([^"]*)"|'([^']*)')/g;
385
385
  let m;
386
386
  while ((m = bindingRegex.exec(attrsStr)) !== null) {
387
+ const attrName = (m[1] || '').toLowerCase();
388
+ if (attrName === 'class' || attrName === 'style') continue;
387
389
  const val = (m[2] !== undefined ? m[2] : m[3]) || '';
388
- if (val.indexOf('$x') === -1) toStrip.add(m[1].toLowerCase());
390
+ if (val.indexOf('$x') === -1) toStrip.add(attrName);
389
391
  }
390
392
  if (toStrip.size === 0) return match;
391
393
  let newAttrs = attrsStr;
@@ -951,6 +953,20 @@ async function runPrerender(config) {
951
953
  await page.evaluate(() => {
952
954
  const loopVarRegex = /^\s*(?:\(\s*([A-Za-z_$][\w$]*)(?:\s*,\s*([A-Za-z_$][\w$]*))?\s*\)|([A-Za-z_$][\w$]*))\s+in\s+/;
953
955
  const bindingAttrRegex = /^(?:x-bind:|:|x-text|x-html|x-show|x-if|x-model|x-effect|x-on:|@)/;
956
+ const hasVar = (expr, varName) => varName && new RegExp(`\\b${varName}\\b`).test(expr || '');
957
+ const elementReferencesLoopScope = (el, itemVar, indexVar) => {
958
+ if (!el) return false;
959
+ const nodes = [el, ...Array.from(el.querySelectorAll('*'))];
960
+ for (const node of nodes) {
961
+ const attrs = node.attributes ? Array.from(node.attributes) : [];
962
+ for (const attr of attrs) {
963
+ if (!bindingAttrRegex.test(attr.name)) continue;
964
+ const expr = attr.value || '';
965
+ if (hasVar(expr, itemVar) || hasVar(expr, indexVar)) return true;
966
+ }
967
+ }
968
+ return false;
969
+ };
954
970
 
955
971
  document.querySelectorAll('template[x-for]').forEach((tpl) => {
956
972
  const xFor = (tpl.getAttribute('x-for') || '').trim();
@@ -968,19 +984,7 @@ async function runPrerender(config) {
968
984
  const sameTag = next.tagName === tag;
969
985
  if (!sameTag) break;
970
986
 
971
- let referencesLoopScope = false;
972
- const attrNodes = next.attributes ? Array.from(next.attributes) : [];
973
- for (const attr of attrNodes) {
974
- if (!bindingAttrRegex.test(attr.name)) continue;
975
- const expr = attr.value || '';
976
- if (
977
- (itemVar && new RegExp(`\\b${itemVar}\\b`).test(expr)) ||
978
- (indexVar && new RegExp(`\\b${indexVar}\\b`).test(expr))
979
- ) {
980
- referencesLoopScope = true;
981
- break;
982
- }
983
- }
987
+ const referencesLoopScope = elementReferencesLoopScope(next, itemVar, indexVar);
984
988
 
985
989
  const toRemove = next;
986
990
  next = next.nextElementSibling;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-render",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Render Manifest sites to static HTML for SEO",
5
5
  "type": "module",
6
6
  "bin": {