@ariel-salgado/vite-plugin-shadow-dom 0.0.2 → 0.0.3
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/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +73 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/plugin.ts"],"mappings":";;;;KAEY,UAAA;AAAA,KACA,WAAA;AAAA,UAEK,gBAAA;EAHL;;;;;AACZ;EASC,IAAA,GAAO,UAAA;;;;AAPR;;EAcC,WAAA,GAAc,WAAA;EAPP;;;;EAaP,MAAA;EAbA;;;;EAmBA,UAAA;EAAA;;;;;EAOA,cAAA;EA6BA;;;;;EAtBA,YAAA;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/plugin.ts"],"mappings":";;;;KAEY,UAAA;AAAA,KACA,WAAA;AAAA,UAEK,gBAAA;EAHL;;;;;AACZ;EASC,IAAA,GAAO,UAAA;;;;AAPR;;EAcC,WAAA,GAAc,WAAA;EAPP;;;;EAaP,MAAA;EAbA;;;;EAmBA,UAAA;EAAA;;;;;EAOA,cAAA;EA6BA;;;;;EAtBA,YAAA;;;;ACRD;;EDeC,KAAA;ECfgE;;;;;EDsBhE,OAAA,gBAAuB,QAAA;;;;;;;EAQvB,gBAAA;;;;;;;;EASA,aAAA;;;;;;;EAQA,YAAA,aAAyB,mBAAA;AAAA;;;iBC/CV,SAAA,CAAU,OAAA,GAAS,gBAAA,GAAwB,MAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import beautify from "js-beautify";
|
|
2
|
+
|
|
1
3
|
//#region src/constants.ts
|
|
2
4
|
const VOID_TAGS = new Set([
|
|
3
5
|
"area",
|
|
@@ -31,6 +33,26 @@ const DOCUMENT_METHODS_TO_PATCH = [
|
|
|
31
33
|
"querySelector",
|
|
32
34
|
"querySelectorAll"
|
|
33
35
|
];
|
|
36
|
+
const DEFAULT_BEAUTIFY_OPTIONS = {
|
|
37
|
+
end_with_newline: true,
|
|
38
|
+
eol: "\n",
|
|
39
|
+
indent_with_tabs: true,
|
|
40
|
+
indent_size: 4,
|
|
41
|
+
wrap_line_length: 0,
|
|
42
|
+
indent_inner_html: true,
|
|
43
|
+
max_preserve_newlines: 0,
|
|
44
|
+
preserve_newlines: false,
|
|
45
|
+
extra_liners: []
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/process/format.ts
|
|
50
|
+
function format_html(html, options) {
|
|
51
|
+
return beautify.html(html, {
|
|
52
|
+
...DEFAULT_BEAUTIFY_OPTIONS,
|
|
53
|
+
...options
|
|
54
|
+
});
|
|
55
|
+
}
|
|
34
56
|
|
|
35
57
|
//#endregion
|
|
36
58
|
//#region src/process/html.ts
|
|
@@ -42,11 +64,10 @@ const DOCUMENT_METHODS_TO_PATCH = [
|
|
|
42
64
|
function extract_assets(html) {
|
|
43
65
|
const css_hrefs = [];
|
|
44
66
|
const js_srcs = [];
|
|
45
|
-
html
|
|
67
|
+
html.replace(/<link\b[^>]*>/g, (tag) => {
|
|
46
68
|
if (get_attr(tag, "rel") === "stylesheet") {
|
|
47
69
|
const href = get_attr(tag, "href");
|
|
48
70
|
if (href) css_hrefs.push(href);
|
|
49
|
-
return "";
|
|
50
71
|
}
|
|
51
72
|
return tag;
|
|
52
73
|
});
|
|
@@ -147,8 +168,6 @@ function get_attr(tag, attr) {
|
|
|
147
168
|
* Iterates over the query methods that ShadowRoot implements, replacing each
|
|
148
169
|
* on `document` with a version that searches the shadow root first and falls
|
|
149
170
|
* back to the original document method when nothing is found in the shadow.
|
|
150
|
-
*
|
|
151
|
-
* Adding support for a new method is a one-line change to PATCHED_METHODS.
|
|
152
171
|
*/
|
|
153
172
|
function build_document_patch(global_name) {
|
|
154
173
|
return `
|
|
@@ -165,6 +184,37 @@ function build_document_patch(global_name) {
|
|
|
165
184
|
}
|
|
166
185
|
`.trim();
|
|
167
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Generates a MutationObserver snippet that clones any <style> tag added
|
|
189
|
+
* to document.head into the shadow root.
|
|
190
|
+
*
|
|
191
|
+
* This is required in dev mode where Vite injects CSS as runtime <style>
|
|
192
|
+
* elements rather than emitting <link> tags. Without this, styles from
|
|
193
|
+
* `import './style.css'` in the app entry never reach the shadow tree.
|
|
194
|
+
*
|
|
195
|
+
* Safe to include in production too — no <style> tags are injected there
|
|
196
|
+
* so the observer fires zero times and has no cost.
|
|
197
|
+
*/
|
|
198
|
+
function build_style_observer(global_name) {
|
|
199
|
+
return `
|
|
200
|
+
const __style_target = window['${global_name}'];
|
|
201
|
+
const __existing_styles = document.head.querySelectorAll('style');
|
|
202
|
+
|
|
203
|
+
for (const s of __existing_styles) {
|
|
204
|
+
__style_target.appendChild(s.cloneNode(true));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
new MutationObserver(mutations => {
|
|
208
|
+
for (const mutation of mutations) {
|
|
209
|
+
for (const node of mutation.addedNodes) {
|
|
210
|
+
if (node.nodeName === 'STYLE') {
|
|
211
|
+
__style_target.appendChild(node.cloneNode(true));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}).observe(document.head, { childList: true });
|
|
216
|
+
`.trim();
|
|
217
|
+
}
|
|
168
218
|
|
|
169
219
|
//#endregion
|
|
170
220
|
//#region src/process/inject.ts
|
|
@@ -172,21 +222,25 @@ function build_bootstrap_script(css_hrefs, js_srcs, opts) {
|
|
|
172
222
|
const css_block = css_hrefs.length > 0 ? opts.cssStrategy === "constructable" ? build_constructable_css(css_hrefs) : build_link_css(css_hrefs) : "";
|
|
173
223
|
const js_block = js_srcs.map((src) => ` import('${src}');`).join("\n");
|
|
174
224
|
const patch_block = opts.patchDocument ? build_document_patch(opts.shadowRootGlobal) : "";
|
|
225
|
+
const style_observer = build_style_observer(opts.shadowRootGlobal);
|
|
175
226
|
return `
|
|
176
227
|
<script type="module">
|
|
177
228
|
const host = document.getElementById('${opts.hostId}');
|
|
229
|
+
|
|
178
230
|
const shadow = host.attachShadow({
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
231
|
+
mode: '${opts.mode}',
|
|
232
|
+
delegatesFocus: ${opts.delegatesFocus},
|
|
233
|
+
serializable: ${opts.serializable},
|
|
182
234
|
});
|
|
183
235
|
|
|
184
236
|
const tpl = document.getElementById('${opts.templateId}');
|
|
237
|
+
|
|
185
238
|
shadow.appendChild(tpl.content.cloneNode(true));
|
|
186
239
|
|
|
187
240
|
window['${opts.shadowRootGlobal}'] = shadow;
|
|
188
241
|
|
|
189
242
|
${patch_block}
|
|
243
|
+
${style_observer}
|
|
190
244
|
${css_block}
|
|
191
245
|
${js_block}
|
|
192
246
|
<\/script>
|
|
@@ -234,14 +288,14 @@ function transform_html(html, opts) {
|
|
|
234
288
|
if (!body_slice) return html;
|
|
235
289
|
const script = build_bootstrap_script(css_hrefs, js_srcs, opts);
|
|
236
290
|
const injection = `
|
|
237
|
-
<div id="${opts.hostId}"></div>
|
|
291
|
+
<div id="${opts.hostId}" style="display: contents; width: 100%; height: 100%;"></div>
|
|
238
292
|
|
|
239
293
|
<template id="${opts.templateId}">
|
|
240
|
-
|
|
294
|
+
${slice.element.trim()}
|
|
241
295
|
</template>
|
|
242
296
|
|
|
243
297
|
${script}
|
|
244
|
-
|
|
298
|
+
`;
|
|
245
299
|
const body_with_host = body_slice.content.replace("PLACEHOLDER", injection);
|
|
246
300
|
return body_slice.before + body_with_host + body_slice.after;
|
|
247
301
|
}
|
|
@@ -277,6 +331,15 @@ function shadowDOM(options = {}) {
|
|
|
277
331
|
if (resolved.exclude(ctx.filename)) return html;
|
|
278
332
|
return transform_html(html, resolved);
|
|
279
333
|
}
|
|
334
|
+
},
|
|
335
|
+
generateBundle(_, bundle) {
|
|
336
|
+
for (const filename of Object.keys(bundle)) {
|
|
337
|
+
const chunk = bundle[filename];
|
|
338
|
+
if (chunk.type === "asset" && filename.endsWith(".html")) {
|
|
339
|
+
const source = chunk.source;
|
|
340
|
+
chunk.source = format_html(source);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
280
343
|
}
|
|
281
344
|
};
|
|
282
345
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/constants.ts","../src/process/html.ts","../src/dom/patch.ts","../src/process/inject.ts","../src/process/transform.ts","../src/plugin.ts"],"sourcesContent":["import type { ResolvedOptions } from './types';\nimport type { HTMLBeautifyOptions } from 'js-beautify';\n\nexport const VOID_TAGS = new Set([\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n]);\n\nexport const DEFAULT_PLUGIN_OPTIONS: Partial<ResolvedOptions> = {\n\tmode: 'open',\n\tcssStrategy: 'link',\n\thostId: 'shadow-host',\n\ttemplateId: 'shadow-template',\n\tdelegatesFocus: true,\n\tserializable: true,\n\tappId: 'app',\n\tshadowRootGlobal: '__shadowRoot',\n\tpatchDocument: true,\n};\n\nexport const DOCUMENT_METHODS_TO_PATCH = [\n\t'getElementById',\n\t'querySelector',\n\t'querySelectorAll',\n];\n\nexport const DEFAULT_OPTIONS: HTMLBeautifyOptions = {\n\tend_with_newline: true,\n\teol: '\\n',\n\tindent_with_tabs: true,\n\twrap_line_length: 100,\n\tindent_size: 4,\n};\n","import type { BodySlice, ElementSlice, ExtractedAssets } from '../types';\n\nimport { VOID_TAGS } from '../constants';\n\n/**\n * Strips all Vite-injected <link rel=\"stylesheet\"> and <script type=\"module\" src=\"...\">\n * tags from HTML, collecting their URLs for manual injection into the shadow root.\n * Non-stylesheet links (favicon, preload, etc.) and inline module scripts are preserved.\n */\nexport function extract_assets(html: string): ExtractedAssets {\n\tconst css_hrefs: string[] = [];\n\tconst js_srcs: string[] = [];\n\n\thtml = html.replace(/<link\\b[^>]*>/g, (tag) => {\n\t\tif (get_attr(tag, 'rel') === 'stylesheet') {\n\t\t\tconst href = get_attr(tag, 'href');\n\t\t\tif (href)\n\t\t\t\tcss_hrefs.push(href);\n\t\t\treturn '';\n\t\t}\n\t\treturn tag;\n\t});\n\n\thtml = html.replace(/<script\\b[^>]*><\\/script>/g, (tag) => {\n\t\tif (get_attr(tag, 'type') === 'module') {\n\t\t\tconst src = get_attr(tag, 'src');\n\t\t\tif (src)\n\t\t\t\tjs_srcs.push(src);\n\t\t\treturn '';\n\t\t}\n\t\treturn tag;\n\t});\n\n\treturn { html, css_hrefs, js_srcs };\n}\n\n/**\n * Splits HTML around the <body> element using index-based slicing.\n * Immune to </body> strings inside scripts or templates.\n */\nexport function slice_body(html: string): BodySlice | null {\n\tconst body_open = html.indexOf('<body');\n\tif (body_open === -1)\n\t\treturn null;\n\n\tconst tag_end = html.indexOf('>', body_open);\n\tif (tag_end === -1)\n\t\treturn null;\n\n\tconst body_start = tag_end + 1;\n\tconst body_end = html.lastIndexOf('</body>');\n\tif (body_end === -1)\n\t\treturn null;\n\n\treturn {\n\t\tbefore: html.slice(0, body_start),\n\t\tcontent: html.slice(body_start, body_end),\n\t\tafter: html.slice(body_end),\n\t};\n}\n\n/**\n * Finds and extracts an element by id from an HTML string using nesting-aware scanning.\n * Supports any depth of same-tag nesting. Only supports id= attribute selectors.\n * Returns null if the element is not found or the HTML is malformed.\n */\nexport function find_element_by_id(html: string, id: string): ElementSlice | null {\n\tconst id_re = new RegExp(`<(\\\\w+)\\\\b[^>]*\\\\bid=\"${id}\"[^>]*>`, 'i');\n\tconst match = id_re.exec(html);\n\tif (!match)\n\t\treturn null;\n\n\tconst tag_name = match[1].toLowerCase();\n\tconst tag_start = match.index;\n\tconst opening_end = tag_start + match[0].length;\n\n\tif (VOID_TAGS.has(tag_name) || match[0].endsWith('/>')) {\n\t\treturn {\n\t\t\tbefore: html.slice(0, tag_start),\n\t\t\telement: match[0],\n\t\t\tafter: html.slice(opening_end),\n\t\t};\n\t}\n\n\tconst open_seq = `<${tag_name}`;\n\tconst close_seq = `</${tag_name}`;\n\n\tlet pos = opening_end;\n\tlet depth = 1;\n\n\twhile (depth > 0 && pos < html.length) {\n\t\tconst next_open = html.indexOf(open_seq, pos);\n\n\t\tlet next_close = html.indexOf(close_seq, pos);\n\t\twhile (next_close !== -1) {\n\t\t\tconst c = html[next_close + close_seq.length];\n\t\t\tif (c === '>' || c === ' ' || c === '\\n' || c === '\\t' || c === '\\r')\n\t\t\t\tbreak;\n\t\t\tnext_close = html.indexOf(close_seq, next_close + 1);\n\t\t}\n\n\t\tif (next_close === -1)\n\t\t\treturn null; // malformed HTML\n\n\t\tif (next_open !== -1 && next_open < next_close) {\n\t\t\tconst char_after = html[next_open + open_seq.length];\n\t\t\tif (\n\t\t\t\tchar_after === '>'\n\t\t\t\t|| char_after === ' '\n\t\t\t\t|| char_after === '\\n'\n\t\t\t\t|| char_after === '\\t'\n\t\t\t\t|| char_after === '\\r'\n\t\t\t\t|| char_after === '/'\n\t\t\t) {\n\t\t\t\tdepth++;\n\t\t\t\tpos = next_open + open_seq.length;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tpos = next_open + 1;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tdepth--;\n\t\t\tconst close_end = html.indexOf('>', next_close) + 1;\n\t\t\tif (close_end === 0)\n\t\t\t\treturn null;\n\t\t\tif (depth === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tbefore: html.slice(0, tag_start),\n\t\t\t\t\telement: html.slice(tag_start, close_end),\n\t\t\t\t\tafter: html.slice(close_end),\n\t\t\t\t};\n\t\t\t}\n\t\t\tpos = close_end;\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Extracts the value of a named attribute from an HTML opening tag string.\n * Order-independent — works regardless of attribute position in the tag.\n */\nexport function get_attr(tag: string, attr: string): string | undefined {\n\treturn tag.match(new RegExp(`\\\\b${attr}=\"([^\"]+)\"`))?.[1];\n}\n","import { DOCUMENT_METHODS_TO_PATCH } from '../constants';\n\n/**\n * Generates the document-patching snippet injected into the bootstrap script.\n *\n * Iterates over the query methods that ShadowRoot implements, replacing each\n * on `document` with a version that searches the shadow root first and falls\n * back to the original document method when nothing is found in the shadow.\n *\n * Adding support for a new method is a one-line change to PATCHED_METHODS.\n */\nexport function build_document_patch(global_name: string): string {\n\treturn `\n\t\tconst __shadow = window['${global_name}'];\n\n\t\tfor (const m of ${JSON.stringify(DOCUMENT_METHODS_TO_PATCH)}) {\n\t\t\tconst orig = document[m].bind(document);\n\t\t\tdocument[m] = (...args) => {\n\t\t\t\tconst r = __shadow[m](...args);\n\t\t\t\treturn r != null && (!('length' in r) || r.length > 0)\n\t\t\t\t? r\n\t\t\t\t: orig(...args);\n\t\t\t};\n\t\t}\n `.trim();\n}\n","import type { ResolvedOptions } from '../types.js';\n\nimport { build_document_patch } from '../dom/patch.js';\n\nexport function build_bootstrap_script(\n\tcss_hrefs: string[],\n\tjs_srcs: string[],\n\topts: ResolvedOptions,\n): string {\n\tconst css_block\n\t\t= css_hrefs.length > 0\n\t\t\t? opts.cssStrategy === 'constructable'\n\t\t\t\t? build_constructable_css(css_hrefs)\n\t\t\t\t: build_link_css(css_hrefs)\n\t\t\t: '';\n\n\tconst js_block = js_srcs.map(src => ` import('${src}');`).join('\\n');\n\n\tconst patch_block = opts.patchDocument\n\t\t? build_document_patch(opts.shadowRootGlobal)\n\t\t: '';\n\n\treturn `\n\t\t<script type=\"module\">\n\t\t\tconst host = document.getElementById('${opts.hostId}');\n\t\t\tconst shadow = host.attachShadow({\n\t\t\t\tmode: '${opts.mode}',\n\t\t\t\tdelegatesFocus: ${opts.delegatesFocus},\n\t\t\t\tserializable: ${opts.serializable},\n\t\t\t});\n\n\t\t\tconst tpl = document.getElementById('${opts.templateId}');\n\t\t\tshadow.appendChild(tpl.content.cloneNode(true));\n\n\t\t\twindow['${opts.shadowRootGlobal}'] = shadow;\n\n\t\t\t${patch_block}\n\t\t\t${css_block}\n\t\t\t${js_block}\n\t\t</script>\n\t`;\n}\n\nfunction build_link_css(hrefs: string[]): string {\n\treturn hrefs.map(href => `\n\t\tconst link = document.createElement('link');\n\t\tlink.rel = 'stylesheet';\n\t\tlink.href = '${href}';\n\t\tshadow.appendChild(link);\n\t`).join('\\n');\n}\n\nfunction build_constructable_css(hrefs: string[]): string {\n\tconst fetches = hrefs.map((href, i) => `\n\t\tconst res_${i} = await fetch('${href}');\n\t\tconst sheet_${i} = new CSSStyleSheet();\n\t\tawait sheet_${i}.replace(await res_${i}.text());\n\t`).join('\\n');\n\n\tconst sheet_refs = hrefs.map((_, i) => `sheet_${i}`).join(', ');\n\n\treturn `\n\t\t(async () => {\n\t\t\t${fetches}\n\t\t\tshadow.adoptedStyleSheets = [${sheet_refs}];\n\t\t})();\n\t`;\n}\n","import type { ResolvedOptions } from '../types.js';\n\nimport { extract_assets, find_element_by_id, slice_body } from './html.js';\nimport { build_bootstrap_script } from './inject.js';\n\n/**\n * Full HTML transformation pipeline.\n *\n * When appId is set (default: 'app'):\n * - Finds the element with that id in the body\n * - Replaces it in-place with the shadow host div\n * - Appends the template and bootstrap script at the end of body\n * - Everything else in the body remains untouched\n *\n * Returns the original HTML unchanged if the target element cannot be found.\n */\nexport function transform_html(html: string, opts: ResolvedOptions): string {\n\tconst { html: stripped, css_hrefs, js_srcs } = extract_assets(html);\n\n\tconst slice = find_element_by_id(stripped, opts.appId);\n\tif (!slice)\n\t\treturn html;\n\n\tconst body_slice = slice_body(`${slice.before}PLACEHOLDER${slice.after}`);\n\tif (!body_slice)\n\t\treturn html;\n\n\tconst script = build_bootstrap_script(css_hrefs, js_srcs, opts);\n\n\tconst injection = `\n\t\t<div id=\"${opts.hostId}\"></div>\n\n\t\t<template id=\"${opts.templateId}\">\n\t\t\t${slice.element.trim()}\n\t\t</template>\n\n\t\t${script}\n \t`;\n\n\tconst body_with_host = body_slice.content.replace('PLACEHOLDER', injection);\n\n\treturn body_slice.before + body_with_host + body_slice.after;\n}\n","import type { ResolvedOptions, ShadowDOMOptions } from './types.js';\nimport type { Plugin } from 'vite';\n\nimport { DEFAULT_PLUGIN_OPTIONS } from './constants.js';\nimport { transform_html } from './process/transform.js';\n\nfunction build_exclude_predicate(\n\texclude: ShadowDOMOptions['exclude'],\n): (filename: string) => boolean {\n\tif (!exclude)\n\t\treturn () => false;\n\tif (typeof exclude === 'function')\n\t\treturn exclude;\n\treturn (filename: string) => exclude.some(pattern => filename.includes(pattern));\n}\n\nfunction resolve_format_option(\n\toption: ShadowDOMOptions['formatOutput'],\n): ResolvedOptions['formatOutput'] {\n\tif (option === false)\n\t\treturn false;\n\tif (option === true || option === undefined)\n\t\treturn {};\n\treturn option;\n}\n\nfunction resolve_options(options: ShadowDOMOptions): ResolvedOptions {\n\tconst merged = { ...DEFAULT_PLUGIN_OPTIONS, ...options } as ResolvedOptions;\n\n\treturn {\n\t\t...merged,\n\t\texclude: build_exclude_predicate(options.exclude),\n\t\tformatOutput: resolve_format_option(options.formatOutput),\n\t};\n}\n\nexport function shadowDOM(options: ShadowDOMOptions = {}): Plugin {\n\tconst resolved = resolve_options(options);\n\n\treturn {\n\t\tname: '@ariel-salgado/vite-plugin-shadow-dom',\n\t\tenforce: 'post',\n\t\ttransformIndexHtml: {\n\t\t\torder: 'post',\n\t\t\thandler(html, ctx) {\n\t\t\t\tif ((resolved.exclude as ((filename: string) => boolean))(ctx.filename))\n\t\t\t\t\treturn html;\n\t\t\t\treturn transform_html(html, resolved);\n\t\t\t},\n\t\t},\n\t};\n}\n"],"mappings":";AAGA,MAAa,YAAY,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,CAAC;AAEF,MAAa,yBAAmD;CAC/D,MAAM;CACN,aAAa;CACb,QAAQ;CAC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,MAAM,QAAQ,MAAM,CAAC;;;IAGtB,OAAO;;CAGV,MAAM,iBAAiB,WAAW,QAAQ,QAAQ,eAAe,UAAU;AAE3E,QAAO,WAAW,SAAS,iBAAiB,WAAW;;;;;ACnCxD,SAAS,wBACR,SACgC;AAChC,KAAI,CAAC,QACJ,cAAa;AACd,KAAI,OAAO,YAAY,WACtB,QAAO;AACR,SAAQ,aAAqB,QAAQ,MAAK,YAAW,SAAS,SAAS,QAAQ,CAAC;;AAGjF,SAAS,sBACR,QACkC;AAClC,KAAI,WAAW,MACd,QAAO;AACR,KAAI,WAAW,QAAQ,WAAW,OACjC,QAAO,EAAE;AACV,QAAO;;AAGR,SAAS,gBAAgB,SAA4C;AAGpE,QAAO;EAFU,GAAG;EAAwB,GAAG;EAI9C,SAAS,wBAAwB,QAAQ,QAAQ;EACjD,cAAc,sBAAsB,QAAQ,aAAa;EACzD;;AAGF,SAAgB,UAAU,UAA4B,EAAE,EAAU;CACjE,MAAM,WAAW,gBAAgB,QAAQ;AAEzC,QAAO;EACN,MAAM;EACN,SAAS;EACT,oBAAoB;GACnB,OAAO;GACP,QAAQ,MAAM,KAAK;AAClB,QAAK,SAAS,QAA4C,IAAI,SAAS,CACtE,QAAO;AACR,WAAO,eAAe,MAAM,SAAS;;GAEtC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/constants.ts","../src/process/format.ts","../src/process/html.ts","../src/dom/patch.ts","../src/process/inject.ts","../src/process/transform.ts","../src/plugin.ts"],"sourcesContent":["import type { ResolvedOptions } from './types';\nimport type { HTMLBeautifyOptions } from 'js-beautify';\n\nexport const VOID_TAGS = new Set([\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n]);\n\nexport const DEFAULT_PLUGIN_OPTIONS: Partial<ResolvedOptions> = {\n\tmode: 'open',\n\tcssStrategy: 'link',\n\thostId: 'shadow-host',\n\ttemplateId: 'shadow-template',\n\tdelegatesFocus: true,\n\tserializable: true,\n\tappId: 'app',\n\tshadowRootGlobal: '__shadowRoot',\n\tpatchDocument: true,\n};\n\nexport const DOCUMENT_METHODS_TO_PATCH = [\n\t'getElementById',\n\t'querySelector',\n\t'querySelectorAll',\n];\n\nexport const DEFAULT_BEAUTIFY_OPTIONS: HTMLBeautifyOptions = {\n\tend_with_newline: true,\n\teol: '\\n',\n\tindent_with_tabs: true,\n\tindent_size: 4,\n\twrap_line_length: 0,\n\tindent_inner_html: true,\n\tmax_preserve_newlines: 0,\n\tpreserve_newlines: false,\n\textra_liners: [],\n};\n","import type { HTMLBeautifyOptions } from 'js-beautify';\n\nimport beautify from 'js-beautify';\n\nimport { DEFAULT_BEAUTIFY_OPTIONS } from '../constants';\n\nexport function format_html(html: string, options?: HTMLBeautifyOptions): string {\n\treturn beautify.html(html, { ...DEFAULT_BEAUTIFY_OPTIONS, ...options });\n}\n","import type { BodySlice, ElementSlice, ExtractedAssets } from '../types';\n\nimport { VOID_TAGS } from '../constants';\n\n/**\n * Strips all Vite-injected <link rel=\"stylesheet\"> and <script type=\"module\" src=\"...\">\n * tags from HTML, collecting their URLs for manual injection into the shadow root.\n * Non-stylesheet links (favicon, preload, etc.) and inline module scripts are preserved.\n */\nexport function extract_assets(html: string): ExtractedAssets {\n\tconst css_hrefs: string[] = [];\n\tconst js_srcs: string[] = [];\n\n\thtml.replace(/<link\\b[^>]*>/g, (tag) => {\n\t\tif (get_attr(tag, 'rel') === 'stylesheet') {\n\t\t\tconst href = get_attr(tag, 'href');\n\t\t\tif (href)\n\t\t\t\tcss_hrefs.push(href);\n\t\t}\n\t\treturn tag;\n\t});\n\n\thtml = html.replace(/<script\\b[^>]*><\\/script>/g, (tag) => {\n\t\tif (get_attr(tag, 'type') === 'module') {\n\t\t\tconst src = get_attr(tag, 'src');\n\t\t\tif (src)\n\t\t\t\tjs_srcs.push(src);\n\t\t\treturn '';\n\t\t}\n\t\treturn tag;\n\t});\n\n\treturn { html, css_hrefs, js_srcs };\n}\n\n/**\n * Splits HTML around the <body> element using index-based slicing.\n * Immune to </body> strings inside scripts or templates.\n */\nexport function slice_body(html: string): BodySlice | null {\n\tconst body_open = html.indexOf('<body');\n\tif (body_open === -1)\n\t\treturn null;\n\n\tconst tag_end = html.indexOf('>', body_open);\n\tif (tag_end === -1)\n\t\treturn null;\n\n\tconst body_start = tag_end + 1;\n\tconst body_end = html.lastIndexOf('</body>');\n\tif (body_end === -1)\n\t\treturn null;\n\n\treturn {\n\t\tbefore: html.slice(0, body_start),\n\t\tcontent: html.slice(body_start, body_end),\n\t\tafter: html.slice(body_end),\n\t};\n}\n\n/**\n * Finds and extracts an element by id from an HTML string using nesting-aware scanning.\n * Supports any depth of same-tag nesting. Only supports id= attribute selectors.\n * Returns null if the element is not found or the HTML is malformed.\n */\nexport function find_element_by_id(html: string, id: string): ElementSlice | null {\n\tconst id_re = new RegExp(`<(\\\\w+)\\\\b[^>]*\\\\bid=\"${id}\"[^>]*>`, 'i');\n\tconst match = id_re.exec(html);\n\tif (!match)\n\t\treturn null;\n\n\tconst tag_name = match[1].toLowerCase();\n\tconst tag_start = match.index;\n\tconst opening_end = tag_start + match[0].length;\n\n\tif (VOID_TAGS.has(tag_name) || match[0].endsWith('/>')) {\n\t\treturn {\n\t\t\tbefore: html.slice(0, tag_start),\n\t\t\telement: match[0],\n\t\t\tafter: html.slice(opening_end),\n\t\t};\n\t}\n\n\tconst open_seq = `<${tag_name}`;\n\tconst close_seq = `</${tag_name}`;\n\n\tlet pos = opening_end;\n\tlet depth = 1;\n\n\twhile (depth > 0 && pos < html.length) {\n\t\tconst next_open = html.indexOf(open_seq, pos);\n\n\t\tlet next_close = html.indexOf(close_seq, pos);\n\t\twhile (next_close !== -1) {\n\t\t\tconst c = html[next_close + close_seq.length];\n\t\t\tif (c === '>' || c === ' ' || c === '\\n' || c === '\\t' || c === '\\r')\n\t\t\t\tbreak;\n\t\t\tnext_close = html.indexOf(close_seq, next_close + 1);\n\t\t}\n\n\t\tif (next_close === -1)\n\t\t\treturn null; // malformed HTML\n\n\t\tif (next_open !== -1 && next_open < next_close) {\n\t\t\tconst char_after = html[next_open + open_seq.length];\n\t\t\tif (\n\t\t\t\tchar_after === '>'\n\t\t\t\t|| char_after === ' '\n\t\t\t\t|| char_after === '\\n'\n\t\t\t\t|| char_after === '\\t'\n\t\t\t\t|| char_after === '\\r'\n\t\t\t\t|| char_after === '/'\n\t\t\t) {\n\t\t\t\tdepth++;\n\t\t\t\tpos = next_open + open_seq.length;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tpos = next_open + 1;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tdepth--;\n\t\t\tconst close_end = html.indexOf('>', next_close) + 1;\n\t\t\tif (close_end === 0)\n\t\t\t\treturn null;\n\t\t\tif (depth === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tbefore: html.slice(0, tag_start),\n\t\t\t\t\telement: html.slice(tag_start, close_end),\n\t\t\t\t\tafter: html.slice(close_end),\n\t\t\t\t};\n\t\t\t}\n\t\t\tpos = close_end;\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Extracts the value of a named attribute from an HTML opening tag string.\n * Order-independent — works regardless of attribute position in the tag.\n */\nexport function get_attr(tag: string, attr: string): string | undefined {\n\treturn tag.match(new RegExp(`\\\\b${attr}=\"([^\"]+)\"`))?.[1];\n}\n","import { DOCUMENT_METHODS_TO_PATCH } from '../constants';\n\n/**\n * Generates the document-patching snippet injected into the bootstrap script.\n *\n * Iterates over the query methods that ShadowRoot implements, replacing each\n * on `document` with a version that searches the shadow root first and falls\n * back to the original document method when nothing is found in the shadow.\n */\nexport function build_document_patch(global_name: string): string {\n\treturn `\n\t\tconst __shadow = window['${global_name}'];\n\n\t\tfor (const m of ${JSON.stringify(DOCUMENT_METHODS_TO_PATCH)}) {\n\t\t\tconst orig = document[m].bind(document);\n\t\t\tdocument[m] = (...args) => {\n\t\t\t\tconst r = __shadow[m](...args);\n\t\t\t\treturn r != null && (!('length' in r) || r.length > 0)\n\t\t\t\t? r\n\t\t\t\t: orig(...args);\n\t\t\t};\n\t\t}\n `.trim();\n}\n\n/**\n * Generates a MutationObserver snippet that clones any <style> tag added\n * to document.head into the shadow root.\n *\n * This is required in dev mode where Vite injects CSS as runtime <style>\n * elements rather than emitting <link> tags. Without this, styles from\n * `import './style.css'` in the app entry never reach the shadow tree.\n *\n * Safe to include in production too — no <style> tags are injected there\n * so the observer fires zero times and has no cost.\n */\nexport function build_style_observer(global_name: string): string {\n\treturn `\n\t\tconst __style_target = window['${global_name}'];\n\t\tconst __existing_styles = document.head.querySelectorAll('style');\n\n\t\tfor (const s of __existing_styles) {\n\t\t\t__style_target.appendChild(s.cloneNode(true));\n\t\t}\n\n\t\tnew MutationObserver(mutations => {\n\t\t\tfor (const mutation of mutations) {\n\t\t\t\tfor (const node of mutation.addedNodes) {\n\t\t\t\t\tif (node.nodeName === 'STYLE') {\n\t\t\t\t\t\t__style_target.appendChild(node.cloneNode(true));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}).observe(document.head, { childList: true });\n\t`.trim();\n}\n","import type { ResolvedOptions } from '../types.js';\n\nimport { build_document_patch, build_style_observer } from '../dom/patch.js';\n\nexport function build_bootstrap_script(\n\tcss_hrefs: string[],\n\tjs_srcs: string[],\n\topts: ResolvedOptions,\n): string {\n\tconst css_block = css_hrefs.length > 0\n\t\t? opts.cssStrategy === 'constructable'\n\t\t\t? build_constructable_css(css_hrefs)\n\t\t\t: build_link_css(css_hrefs)\n\t\t: '';\n\n\tconst js_block = js_srcs.map(src => ` import('${src}');`).join('\\n');\n\tconst patch_block = opts.patchDocument ? build_document_patch(opts.shadowRootGlobal) : '';\n\tconst style_observer = build_style_observer(opts.shadowRootGlobal);\n\n\treturn `\n\t\t<script type=\"module\">\n\t\t\tconst host = document.getElementById('${opts.hostId}');\n\n\t\t\tconst shadow = host.attachShadow({\n\t\t\t mode: '${opts.mode}',\n\t\t\t delegatesFocus: ${opts.delegatesFocus},\n\t\t\t serializable: ${opts.serializable},\n\t\t\t});\n\n\t\t\tconst tpl = document.getElementById('${opts.templateId}');\n\n\t\t\tshadow.appendChild(tpl.content.cloneNode(true));\n\n\t\t\twindow['${opts.shadowRootGlobal}'] = shadow;\n\n\t\t\t${patch_block}\n\t\t\t${style_observer}\n\t\t\t${css_block}\n\t\t\t${js_block}\n\t\t</script>\n\t`;\n}\n\nfunction build_link_css(hrefs: string[]): string {\n\treturn hrefs.map(href => `\n\t\tconst link = document.createElement('link');\n\t\tlink.rel = 'stylesheet';\n\t\tlink.href = '${href}';\n\t\tshadow.appendChild(link);\n\t`).join('\\n');\n}\n\nfunction build_constructable_css(hrefs: string[]): string {\n\tconst fetches = hrefs.map((href, i) => `\n\t\tconst res_${i} = await fetch('${href}');\n\t\tconst sheet_${i} = new CSSStyleSheet();\n\t\tawait sheet_${i}.replace(await res_${i}.text());\n\t`).join('\\n');\n\n\tconst sheet_refs = hrefs.map((_, i) => `sheet_${i}`).join(', ');\n\n\treturn `\n\t\t(async () => {\n\t\t\t${fetches}\n\t\t\tshadow.adoptedStyleSheets = [${sheet_refs}];\n\t\t})();\n\t`;\n}\n","import type { ResolvedOptions } from '../types.js';\n\nimport { extract_assets, find_element_by_id, slice_body } from './html.js';\nimport { build_bootstrap_script } from './inject.js';\n\n/**\n * Full HTML transformation pipeline.\n *\n * When appId is set (default: 'app'):\n * - Finds the element with that id in the body\n * - Replaces it in-place with the shadow host div\n * - Appends the template and bootstrap script at the end of body\n * - Everything else in the body remains untouched\n *\n * Returns the original HTML unchanged if the target element cannot be found.\n */\nexport function transform_html(html: string, opts: ResolvedOptions): string {\n\tconst { html: stripped, css_hrefs, js_srcs } = extract_assets(html);\n\n\tconst slice = find_element_by_id(stripped, opts.appId);\n\tif (!slice)\n\t\treturn html;\n\n\tconst body_slice = slice_body(`${slice.before}PLACEHOLDER${slice.after}`);\n\tif (!body_slice)\n\t\treturn html;\n\n\tconst script = build_bootstrap_script(css_hrefs, js_srcs, opts);\n\n\tconst injection = `\n\t\t<div id=\"${opts.hostId}\" style=\"display: contents; width: 100%; height: 100%;\"></div>\n\n\t\t<template id=\"${opts.templateId}\">\n\t\t ${slice.element.trim()}\n\t\t</template>\n\n\t\t${script}\n\t`;\n\n\tconst body_with_host = body_slice.content.replace('PLACEHOLDER', injection);\n\n\treturn body_slice.before + body_with_host + body_slice.after;\n}\n","import type { ResolvedOptions, ShadowDOMOptions } from './types.js';\nimport type { Plugin } from 'vite';\n\nimport { DEFAULT_PLUGIN_OPTIONS } from './constants.js';\nimport { format_html } from './process/format.js';\nimport { transform_html } from './process/transform.js';\n\nfunction build_exclude_predicate(\n\texclude: ShadowDOMOptions['exclude'],\n): (filename: string) => boolean {\n\tif (!exclude)\n\t\treturn () => false;\n\tif (typeof exclude === 'function')\n\t\treturn exclude;\n\treturn (filename: string) => exclude.some(pattern => filename.includes(pattern));\n}\n\nfunction resolve_format_option(\n\toption: ShadowDOMOptions['formatOutput'],\n): ResolvedOptions['formatOutput'] {\n\tif (option === false)\n\t\treturn false;\n\tif (option === true || option === undefined)\n\t\treturn {};\n\treturn option;\n}\n\nfunction resolve_options(options: ShadowDOMOptions): ResolvedOptions {\n\tconst merged = { ...DEFAULT_PLUGIN_OPTIONS, ...options } as ResolvedOptions;\n\n\treturn {\n\t\t...merged,\n\t\texclude: build_exclude_predicate(options.exclude),\n\t\tformatOutput: resolve_format_option(options.formatOutput),\n\t};\n}\n\nexport function shadowDOM(options: ShadowDOMOptions = {}): Plugin {\n\tconst resolved = resolve_options(options);\n\n\treturn {\n\t\tname: '@ariel-salgado/vite-plugin-shadow-dom',\n\t\tenforce: 'post',\n\t\ttransformIndexHtml: {\n\t\t\torder: 'post',\n\t\t\thandler(html, ctx) {\n\t\t\t\tif ((resolved.exclude as ((filename: string) => boolean))(ctx.filename))\n\t\t\t\t\treturn html;\n\t\t\t\treturn transform_html(html, resolved);\n\t\t\t},\n\t\t},\n\t\tgenerateBundle(_, bundle) {\n\t\t\tfor (const filename of Object.keys(bundle)) {\n\t\t\t\tconst chunk = bundle[filename];\n\n\t\t\t\tif (chunk.type === 'asset' && filename.endsWith('.html')) {\n\t\t\t\t\tconst source = chunk.source as string;\n\t\t\t\t\tchunk.source = format_html(source);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;AAGA,MAAa,YAAY,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,CAAC;AAEF,MAAa,yBAAmD;CAC/D,MAAM;CACN,aAAa;CACb,QAAQ;CACR,YAAY;CACZ,gBAAgB;CAChB,cAAc;CACd,OAAO;CACP,kBAAkB;CAClB,eAAe;CACf;AAED,MAAa,4BAA4B;CACxC;CACA;CACA;CACA;AAED,MAAa,2BAAgD;CAC5D,kBAAkB;CAClB,KAAK;CACL,kBAAkB;CAClB,aAAa;CACb,kBAAkB;CAClB,mBAAmB;CACnB,uBAAuB;CACvB,mBAAmB;CACnB,cAAc,EAAE;CAChB;;;;AC1CD,SAAgB,YAAY,MAAc,SAAuC;AAChF,QAAO,SAAS,KAAK,MAAM;EAAE,GAAG;EAA0B,GAAG;EAAS,CAAC;;;;;;;;;;ACExE,SAAgB,eAAe,MAA+B;CAC7D,MAAM,YAAsB,EAAE;CAC9B,MAAM,UAAoB,EAAE;AAE5B,MAAK,QAAQ,mBAAmB,QAAQ;AACvC,MAAI,SAAS,KAAK,MAAM,KAAK,cAAc;GAC1C,MAAM,OAAO,SAAS,KAAK,OAAO;AAClC,OAAI,KACH,WAAU,KAAK,KAAK;;AAEtB,SAAO;GACN;AAEF,QAAO,KAAK,QAAQ,+BAA+B,QAAQ;AAC1D,MAAI,SAAS,KAAK,OAAO,KAAK,UAAU;GACvC,MAAM,MAAM,SAAS,KAAK,MAAM;AAChC,OAAI,IACH,SAAQ,KAAK,IAAI;AAClB,UAAO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AAO;;AAGR,SAAS,gBAAgB,SAA4C;AAGpE,QAAO;EAFU,GAAG;EAAwB,GAAG;EAI9C,SAAS,wBAAwB,QAAQ,QAAQ;EACjD,cAAc,sBAAsB,QAAQ,aAAa;EACzD;;AAGF,SAAgB,UAAU,UAA4B,EAAE,EAAU;CACjE,MAAM,WAAW,gBAAgB,QAAQ;AAEzC,QAAO;EACN,MAAM;EACN,SAAS;EACT,oBAAoB;GACnB,OAAO;GACP,QAAQ,MAAM,KAAK;AAClB,QAAK,SAAS,QAA4C,IAAI,SAAS,CACtE,QAAO;AACR,WAAO,eAAe,MAAM,SAAS;;GAEtC;EACD,eAAe,GAAG,QAAQ;AACzB,QAAK,MAAM,YAAY,OAAO,KAAK,OAAO,EAAE;IAC3C,MAAM,QAAQ,OAAO;AAErB,QAAI,MAAM,SAAS,WAAW,SAAS,SAAS,QAAQ,EAAE;KACzD,MAAM,SAAS,MAAM;AACrB,WAAM,SAAS,YAAY,OAAO;;;;EAIrC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ariel-salgado/vite-plugin-shadow-dom",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "Vite plugin that isolates page content into a Shadow DOM",
|
|
6
6
|
"author": "Ariel Salgado <ariel.salgado.acevedo@gmail.com> (https://github.com/ariel-salgado/)",
|
|
7
7
|
"license": "MIT",
|