Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 532x 532x 532x 532x 532x 532x 532x 532x 532x 532x 532x 532x 532x 532x 916x 916x 931x 931x 15x 15x 931x 931x 931x 931x 931x 931x 931x 931x 931x 8x 8x 8x 15x 15x 80x 1x 1x 1x 15x 15x 15x 15x 24x 931x 931x 931x 931x 931x 931x 931x 916x 916x | /**
* @file defer.js
* @description Desugars `<@defer>` (with optional `<@placeholder>` / `<@loading>`) into DOM markers.
*/
import { escapeTemplateMarkers } from '../../../core/utils/templateUtils.js';
/**
* Processes <@defer> tags, converting them to DOM markers with templates for deferred loading.
* Supports triggers via when="<trigger>" (idle, visible, interaction, timer, expression)
* and optional <@placeholder> and <@loading> sub-tags.
* @param {string} template - The template string.
* @returns {string} The processed template.
*/
export function processDefer(template) {
let currentTemplate = template;
while (true) {
const match = currentTemplate.match(/<@defer(?:\s+when=["']([^"']*)["'])?\s*>([\s\S]*?)<\/ ?@defer>/i);
if (!match) break;
const fullMatch = match[0];
const whenCondition = (match[1] || 'idle').trim();
const inner = match[2];
let placeholderContent = '';
let loadingContent = '';
let deferredContent = inner;
const placeholderMatch = inner.match(/<@placeholder>([\s\S]*?)<\/ ?@placeholder>/i);
if (placeholderMatch) {
placeholderContent = escapeTemplateMarkers(placeholderMatch[1]).trim();
deferredContent = deferredContent.replace(placeholderMatch[0], '');
}
const loadingMatch = inner.match(/<@loading>([\s\S]*?)<\/ ?@loading>/i);
if (loadingMatch) {
loadingContent = escapeTemplateMarkers(loadingMatch[1]).trim();
deferredContent = deferredContent.replace(loadingMatch[0], '');
}
deferredContent = escapeTemplateMarkers(deferredContent).trim();
const placeholderTpl = placeholderContent
? `<template data-ax-defer-placeholder>${placeholderContent}</template>`
: '';
const loadingTpl = loadingContent ? `<template data-ax-defer-loading>${loadingContent}</template>` : '';
const contentTpl = `<template data-ax-defer-content>${deferredContent}</template>`;
const replacement = `<div data-ax-defer="true" data-ax-defer-when="${whenCondition}">${placeholderTpl}${loadingTpl}${contentTpl}</div>`;
currentTemplate = currentTemplate.replace(fullMatch, replacement);
}
return currentTemplate;
}
|