@weapp-vite/web 2.0.0 → 2.0.1
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/compiler/wxml/compile.mjs +9 -33
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/dependency.mjs +9 -1
- package/dist/compiler/wxml/dependency.mjs.map +1 -1
- package/dist/compiler/wxml/prepare.mjs +43 -0
- package/dist/compiler/wxml/prepare.mjs.map +1 -0
- package/dist/plugin/assets.d.mts +1 -0
- package/dist/plugin/constants.mjs +4 -2
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/hostTypes.d.mts +1 -0
- package/dist/plugin/index.mjs +24 -19
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/sfcHmr.mjs +27 -8
- package/dist/plugin/sfcHmr.mjs.map +1 -1
- package/dist/runtime/eventBinding.d.mts +1 -0
- package/dist/runtime/hostGlobals.d.mts +1 -0
- package/dist/runtime/nativeComponents/index.mjs +0 -1
- package/dist/runtime/nativeComponents/index.mjs.map +1 -1
- package/dist/runtime/nativeComponents/richText/index.mjs +2 -2
- package/dist/runtime/nativeComponents/richText/index.mjs.map +1 -1
- package/dist/runtime/pageLayout.d.mts +1 -0
- package/dist/runtime/polyfill/index.mjs +1 -1
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +1 -0
- package/dist/runtime/wevu.d.mts +1 -0
- package/package.json +8 -8
- package/dist/runtime/nativeComponents/richText/helpers.mjs +0 -230
- package/dist/runtime/nativeComponents/richText/helpers.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { RUNTIME_ID } from "../../plugin/constants.mjs";
|
|
2
|
-
import { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate } from "./dependency.mjs";
|
|
3
|
-
import { buildNavigationBarAttrs
|
|
4
|
-
import {
|
|
2
|
+
import { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate } from "./dependency.mjs";
|
|
3
|
+
import { buildNavigationBarAttrs } from "./navigation.mjs";
|
|
4
|
+
import { normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from "./specialNodes.mjs";
|
|
5
|
+
import { prepareWxml } from "./prepare.mjs";
|
|
5
6
|
import { renderer } from "./renderer.mjs";
|
|
6
|
-
import { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from "./specialNodes.mjs";
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
|
|
9
9
|
//#region src/compiler/wxml/compile.ts
|
|
@@ -33,44 +33,20 @@ function compileWxml(options) {
|
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
36
|
-
const result =
|
|
36
|
+
const result = prepareWxml({
|
|
37
37
|
id: target,
|
|
38
38
|
source,
|
|
39
39
|
resolveTemplatePath: options.resolveTemplatePath,
|
|
40
|
-
resolveWxsPath: options.resolveWxsPath
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
expandDependencyTree(result.dependencies, target);
|
|
40
|
+
resolveWxsPath: options.resolveWxsPath
|
|
41
|
+
}, dependencyContext);
|
|
42
|
+
expandDependencyTree(collectDependencies(result, dependencyContext), target);
|
|
45
43
|
} catch (error) {
|
|
46
44
|
if (error instanceof Error && error.message) warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`);
|
|
47
45
|
}
|
|
48
46
|
dependencyContext.active.delete(target);
|
|
49
47
|
}
|
|
50
48
|
};
|
|
51
|
-
|
|
52
|
-
let navigationBarAttrs;
|
|
53
|
-
if (options.navigationBar) {
|
|
54
|
-
const extracted = extractNavigationBarFromPageMeta(nodes);
|
|
55
|
-
nodes = extracted.nodes;
|
|
56
|
-
if (extracted.warnings.length > 0) warnings.push(...extracted.warnings);
|
|
57
|
-
navigationBarAttrs = extracted.attrs;
|
|
58
|
-
}
|
|
59
|
-
const templates = [];
|
|
60
|
-
const includes = [];
|
|
61
|
-
const imports = [];
|
|
62
|
-
const wxs = [];
|
|
63
|
-
const renderNodesList = collectSpecialNodes(nodes, {
|
|
64
|
-
templates,
|
|
65
|
-
includes,
|
|
66
|
-
imports,
|
|
67
|
-
wxs,
|
|
68
|
-
wxsModules: /* @__PURE__ */ new Map(),
|
|
69
|
-
warnings,
|
|
70
|
-
sourceId: options.id,
|
|
71
|
-
resolveTemplate: (raw) => options.resolveTemplatePath(raw, options.id),
|
|
72
|
-
resolveWxs: (raw) => options.resolveWxsPath(raw, options.id)
|
|
73
|
-
});
|
|
49
|
+
const { renderNodes: renderNodesList, navigationBarAttrs, templates, includes, imports, wxs } = prepareWxml(options, dependencyContext);
|
|
74
50
|
if (options.navigationBar && options.navigationBar.config.navigationStyle !== "custom") {
|
|
75
51
|
const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs);
|
|
76
52
|
renderNodesList.unshift({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n TemplateDefinition,\n WxmlCompileOptions,\n WxmlCompileResult,\n WxsEntry,\n} from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { RUNTIME_ID } from '../../plugin/constants'\nimport { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs, extractNavigationBarFromPageMeta } from './navigation'\nimport { parseWxml } from './parser'\nimport { renderer } from './renderer'\nimport { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\n\nconst WEB_TEMPLATE_QUERY = 'weapp-web-template'\n\nfunction appendTemplateQuery(pathname: string) {\n return `${pathname}${pathname.includes('?') ? '&' : '?'}${WEB_TEMPLATE_QUERY}`\n}\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = compileWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n dependencyContext,\n expandDependencies: false,\n })\n expandDependencyTree(result.dependencies, target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n let nodes = parseWxml(options.source)\n let navigationBarAttrs: Record<string, string> | undefined\n if (options.navigationBar) {\n const extracted = extractNavigationBarFromPageMeta(nodes)\n nodes = extracted.nodes\n if (extracted.warnings.length > 0) {\n warnings.push(...extracted.warnings)\n }\n navigationBarAttrs = extracted.attrs\n }\n\n const templates: TemplateDefinition[] = []\n const includes: IncludeEntry[] = []\n const imports: ImportEntry[] = []\n const wxs: WxsEntry[] = []\n const wxsModules = new Map<string, string>()\n\n const renderNodesList = collectSpecialNodes(nodes, {\n templates,\n includes,\n imports,\n wxs,\n wxsModules,\n warnings,\n sourceId: options.id,\n resolveTemplate: (raw: string) => options.resolveTemplatePath(raw, options.id),\n resolveWxs: (raw: string) => options.resolveWxsPath(raw, options.id),\n })\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n `import { bindRuntimeEvent } from '${RUNTIME_ID}'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree(directDependencies, options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,UAAkB;CAC7C,OAAO,GAAG,WAAW,SAAS,SAAS,GAAG,IAAI,MAAM,MAAM;AAC5D;AAEA,SAAgB,YAAY,SAAgD;CAC1E,MAAM,oBAAoB,QAAQ,qBAAqB,wBAAwB;CAC/E,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,M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BAAiB,SAAS,iBAAiB,QAAQ,aAAa;CAC3G,MAAM,cAAc,eAAe,SAAS,IACxC,IAAI,CAAC,GAAG,gBAAgB,aAAa,CAAC,CAAC,KAAK,IAAI,EAAE,KAClD;CAEJ,UAAU,KAAK,sCAAsC;CACrD,IAAI,IAAI,SAAS,GACf,UAAU,KAAK,4CAA4C;CAE7D,UAAU,KAAK,YAAY,aAAa;CACxC,UAAU,KAAK,GAAG;CAClB,UAAU,KAAK,sCAAsC;CACrD,UAAU,KAAK,uBAAuB;CAEtC,IAAI,oBAAoB;EACtB,kBAAkB,QAAQ,IAAI,QAAQ,EAAE;EACxC,kBAAkB,OAAO,IAAI,QAAQ,EAAE;EACvC,qBAAqB,oBAAoB,QAAQ,EAAE;EACnD,kBAAkB,OAAO,OAAO,QAAQ,EAAE;CAC5C;CAIA,OAAO;EACL,MAHW;GAAC,GAAG;GAAa;GAAI,GAAG;EAAS,CAAC,CAAC,KAAK,IAGhD;EACH,cAHmB,qBAAqB,kBAAkB,eAAe;EAIzE,UAAU,SAAS,SAAS,IAAI,WAAW;CAC7C;AACF"}
|
|
1
|
+
{"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type { WxmlCompileOptions, WxmlCompileResult } from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { RUNTIME_ID } from '../../plugin/constants'\nimport { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs } from './navigation'\nimport { prepareWxml } from './prepare'\nimport { renderer } from './renderer'\nimport { normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\n\nconst WEB_TEMPLATE_QUERY = 'weapp-web-template'\n\nfunction appendTemplateQuery(pathname: string) {\n return `${pathname}${pathname.includes('?') ? '&' : '?'}${WEB_TEMPLATE_QUERY}`\n}\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = prepareWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n }, dependencyContext)\n expandDependencyTree(collectDependencies(result, dependencyContext), target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n const {\n renderNodes: renderNodesList,\n navigationBarAttrs,\n templates,\n includes,\n imports,\n wxs,\n } = prepareWxml(options, dependencyContext)\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n `import { bindRuntimeEvent } from '${RUNTIME_ID}'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree(directDependencies, options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,UAAkB;CAC7C,OAAO,GAAG,WAAW,SAAS,SAAS,GAAG,IAAI,MAAM,MAAM;AAC5D;AAEA,SAAgB,YAAY,SAAgD;CAC1E,MAAM,oBAAoB,QAAQ,qBAAqB,wBAAwB;CAC/E,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,MAAM,WAAW,kBAAkB;CAEnC,MAAM,wBAAwB,cAAwB,aAAqB;EACzE,KAAK,MAAM,UAAU,cAAc;GACjC,IAAI,kBAAkB,OAAO,IAAI,MAAM,GAAG;IACxC,qBAAqB,mBAAmB,UAAU,MAAM;IACxD;GACF;GACA,IAAI,kBAAkB,QAAQ,IAAI,MAAM,GACtC;GAEF,kBAAkB,QAAQ,IAAI,MAAM;GACpC,kBAAkB,OAAO,IAAI,MAAM;GACnC,IAAI;GACJ,IAAI;IACF,SAAS,aAAa,QAAQ,MAAM;GACt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描完成分析后,按编译器的分组顺序登记直接依赖。 */
|
|
20
|
+
function collectDependencies(entries, context) {
|
|
21
|
+
const dependencies = [];
|
|
22
|
+
for (const entry of entries.imports) addDependency(entry.id, context, dependencies);
|
|
23
|
+
for (const entry of entries.includes) addDependency(entry.id, context, dependencies);
|
|
24
|
+
for (const entry of entries.wxs) if (entry.kind === "src") addDependency(entry.value, context, dependencies);
|
|
25
|
+
return dependencies;
|
|
26
|
+
}
|
|
19
27
|
function warnReadTemplate(context, target) {
|
|
20
28
|
context.warnings.push(`[web] 无法读取模板依赖: ${target}`);
|
|
21
29
|
}
|
|
@@ -27,5 +35,5 @@ function warnCircularTemplate(context, from, target) {
|
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
//#endregion
|
|
30
|
-
export { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate };
|
|
38
|
+
export { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate };
|
|
31
39
|
//# sourceMappingURL=dependency.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency.mjs","names":[],"sources":["../../../src/compiler/wxml/dependency.ts"],"sourcesContent":["import type { WxmlDependencyContext } from './types'\n\nexport function createDependencyContext(): WxmlDependencyContext {\n return {\n warnings: [],\n dependencies: [],\n dependencySet: new Set(),\n visited: new Set(),\n active: new Set(),\n circularWarnings: new Set(),\n }\n}\n\nexport function addDependency(\n value: string,\n context: WxmlDependencyContext,\n direct?: string[],\n) {\n if (!context.dependencySet.has(value)) {\n context.dependencySet.add(value)\n context.dependencies.push(value)\n direct?.push(value)\n }\n}\n\nexport function warnReadTemplate(context: WxmlDependencyContext, target: string) {\n context.warnings.push(`[web] 无法读取模板依赖: ${target}`)\n}\n\nexport function warnCircularTemplate(\n context: WxmlDependencyContext,\n from: string,\n target: string,\n) {\n const key = `${from}=>${target}`\n if (context.circularWarnings.has(key)) {\n return\n }\n context.circularWarnings.add(key)\n context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`)\n}\n"],"mappings":";AAEA,SAAgB,0BAAiD;CAC/D,OAAO;EACL,UAAU,CAAC;EACX,cAAc,CAAC;EACf,+BAAe,IAAI,IAAI;EACvB,yBAAS,IAAI,IAAI;EACjB,wBAAQ,IAAI,IAAI;EAChB,kCAAkB,IAAI,IAAI;CAC5B;AACF;AAEA,SAAgB,cACd,OACA,SACA,QACA;CACA,IAAI,CAAC,QAAQ,cAAc,IAAI,KAAK,GAAG;EACrC,QAAQ,cAAc,IAAI,KAAK;EAC/B,QAAQ,aAAa,KAAK,KAAK;EAC/B,QAAQ,KAAK,KAAK;CACpB;AACF;AAEA,SAAgB,iBAAiB,SAAgC,QAAgB;CAC/E,QAAQ,SAAS,KAAK,mBAAmB,QAAQ;AACnD;AAEA,SAAgB,qBACd,SACA,MACA,QACA;CACA,MAAM,MAAM,GAAG,KAAK,IAAI;CACxB,IAAI,QAAQ,iBAAiB,IAAI,GAAG,GAClC;CAEF,QAAQ,iBAAiB,IAAI,GAAG;CAChC,QAAQ,SAAS,KAAK,oBAAoB,KAAK,MAAM,QAAQ;AAC/D"}
|
|
1
|
+
{"version":3,"file":"dependency.mjs","names":[],"sources":["../../../src/compiler/wxml/dependency.ts"],"sourcesContent":["import type { ImportEntry, IncludeEntry, WxmlDependencyContext, WxsEntry } from './types'\n\nexport function createDependencyContext(): WxmlDependencyContext {\n return {\n warnings: [],\n dependencies: [],\n dependencySet: new Set(),\n visited: new Set(),\n active: new Set(),\n circularWarnings: new Set(),\n }\n}\n\nexport function addDependency(\n value: string,\n context: WxmlDependencyContext,\n direct?: string[],\n) {\n if (!context.dependencySet.has(value)) {\n context.dependencySet.add(value)\n context.dependencies.push(value)\n direct?.push(value)\n }\n}\n\n/** 依赖扫描完成分析后,按编译器的分组顺序登记直接依赖。 */\nexport function collectDependencies(\n entries: { imports: ImportEntry[], includes: IncludeEntry[], wxs: WxsEntry[] },\n context: WxmlDependencyContext,\n) {\n const dependencies: string[] = []\n for (const entry of entries.imports) {\n addDependency(entry.id, context, dependencies)\n }\n for (const entry of entries.includes) {\n addDependency(entry.id, context, dependencies)\n }\n for (const entry of entries.wxs) {\n if (entry.kind === 'src') {\n addDependency(entry.value, context, dependencies)\n }\n }\n return dependencies\n}\n\nexport function warnReadTemplate(context: WxmlDependencyContext, target: string) {\n context.warnings.push(`[web] 无法读取模板依赖: ${target}`)\n}\n\nexport function warnCircularTemplate(\n context: WxmlDependencyContext,\n from: string,\n target: string,\n) {\n const key = `${from}=>${target}`\n if (context.circularWarnings.has(key)) {\n return\n }\n context.circularWarnings.add(key)\n context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`)\n}\n"],"mappings":";AAEA,SAAgB,0BAAiD;CAC/D,OAAO;EACL,UAAU,CAAC;EACX,cAAc,CAAC;EACf,+BAAe,IAAI,IAAI;EACvB,yBAAS,IAAI,IAAI;EACjB,wBAAQ,IAAI,IAAI;EAChB,kCAAkB,IAAI,IAAI;CAC5B;AACF;AAEA,SAAgB,cACd,OACA,SACA,QACA;CACA,IAAI,CAAC,QAAQ,cAAc,IAAI,KAAK,GAAG;EACrC,QAAQ,cAAc,IAAI,KAAK;EAC/B,QAAQ,aAAa,KAAK,KAAK;EAC/B,QAAQ,KAAK,KAAK;CACpB;AACF;;AAGA,SAAgB,oBACd,SACA,SACA;CACA,MAAM,eAAyB,CAAC;CAChC,KAAK,MAAM,SAAS,QAAQ,SAC1B,cAAc,MAAM,IAAI,SAAS,YAAY;CAE/C,KAAK,MAAM,SAAS,QAAQ,UAC1B,cAAc,MAAM,IAAI,SAAS,YAAY;CAE/C,KAAK,MAAM,SAAS,QAAQ,KAC1B,IAAI,MAAM,SAAS,OACjB,cAAc,MAAM,OAAO,SAAS,YAAY;CAGpD,OAAO;AACT;AAEA,SAAgB,iBAAiB,SAAgC,QAAgB;CAC/E,QAAQ,SAAS,KAAK,mBAAmB,QAAQ;AACnD;AAEA,SAAgB,qBACd,SACA,MACA,QACA;CACA,MAAM,MAAM,GAAG,KAAK,IAAI;CACxB,IAAI,QAAQ,iBAAiB,IAAI,GAAG,GAClC;CAEF,QAAQ,iBAAiB,IAAI,GAAG;CAChC,QAAQ,SAAS,KAAK,oBAAoB,KAAK,MAAM,QAAQ;AAC/D"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { extractNavigationBarFromPageMeta } from "./navigation.mjs";
|
|
2
|
+
import { parseWxml } from "./parser.mjs";
|
|
3
|
+
import { collectSpecialNodes } from "./specialNodes.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/compiler/wxml/prepare.ts
|
|
6
|
+
/** 共享模板分析阶段,依赖扫描复用其结果而不生成渲染代码。 */
|
|
7
|
+
function prepareWxml(options, dependencyContext) {
|
|
8
|
+
const warnings = dependencyContext.warnings;
|
|
9
|
+
let nodes = parseWxml(options.source);
|
|
10
|
+
let navigationBarAttrs;
|
|
11
|
+
if (options.navigationBar) {
|
|
12
|
+
const extracted = extractNavigationBarFromPageMeta(nodes);
|
|
13
|
+
nodes = extracted.nodes;
|
|
14
|
+
if (extracted.warnings.length > 0) warnings.push(...extracted.warnings);
|
|
15
|
+
navigationBarAttrs = extracted.attrs;
|
|
16
|
+
}
|
|
17
|
+
const templates = [];
|
|
18
|
+
const includes = [];
|
|
19
|
+
const imports = [];
|
|
20
|
+
const wxs = [];
|
|
21
|
+
return {
|
|
22
|
+
renderNodes: collectSpecialNodes(nodes, {
|
|
23
|
+
templates,
|
|
24
|
+
includes,
|
|
25
|
+
imports,
|
|
26
|
+
wxs,
|
|
27
|
+
wxsModules: /* @__PURE__ */ new Map(),
|
|
28
|
+
warnings,
|
|
29
|
+
sourceId: options.id,
|
|
30
|
+
resolveTemplate: (raw) => options.resolveTemplatePath(raw, options.id),
|
|
31
|
+
resolveWxs: (raw) => options.resolveWxsPath(raw, options.id)
|
|
32
|
+
}),
|
|
33
|
+
navigationBarAttrs,
|
|
34
|
+
templates,
|
|
35
|
+
includes,
|
|
36
|
+
imports,
|
|
37
|
+
wxs
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { prepareWxml };
|
|
43
|
+
//# sourceMappingURL=prepare.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare.mjs","names":[],"sources":["../../../src/compiler/wxml/prepare.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n TemplateDefinition,\n WxmlCompileOptions,\n WxmlDependencyContext,\n WxsEntry,\n} from './types'\nimport { extractNavigationBarFromPageMeta } from './navigation'\nimport { parseWxml } from './parser'\nimport { collectSpecialNodes } from './specialNodes'\n\n/** 共享模板分析阶段,依赖扫描复用其结果而不生成渲染代码。 */\nexport function prepareWxml(options: WxmlCompileOptions, dependencyContext: WxmlDependencyContext) {\n const warnings = dependencyContext.warnings\n let nodes = parseWxml(options.source)\n let navigationBarAttrs: Record<string, string> | undefined\n if (options.navigationBar) {\n const extracted = extractNavigationBarFromPageMeta(nodes)\n nodes = extracted.nodes\n if (extracted.warnings.length > 0) {\n warnings.push(...extracted.warnings)\n }\n navigationBarAttrs = extracted.attrs\n }\n\n const templates: TemplateDefinition[] = []\n const includes: IncludeEntry[] = []\n const imports: ImportEntry[] = []\n const wxs: WxsEntry[] = []\n const renderNodes = collectSpecialNodes(nodes, {\n templates,\n includes,\n imports,\n wxs,\n wxsModules: new Map<string, string>(),\n warnings,\n sourceId: options.id,\n resolveTemplate: (raw: string) => options.resolveTemplatePath(raw, options.id),\n resolveWxs: (raw: string) => options.resolveWxsPath(raw, options.id),\n })\n\n return { renderNodes, navigationBarAttrs, templates, includes, imports, wxs }\n}\n"],"mappings":";;;;;;AAaA,SAAgB,YAAY,SAA6B,mBAA0C;CACjG,MAAM,WAAW,kBAAkB;CACnC,IAAI,QAAQ,UAAU,QAAQ,MAAM;CACpC,IAAI;CACJ,IAAI,QAAQ,eAAe;EACzB,MAAM,YAAY,iCAAiC,KAAK;EACxD,QAAQ,UAAU;EAClB,IAAI,UAAU,SAAS,SAAS,GAC9B,SAAS,KAAK,GAAG,UAAU,QAAQ;EAErC,qBAAqB,UAAU;CACjC;CAEA,MAAM,YAAkC,CAAC;CACzC,MAAM,WAA2B,CAAC;CAClC,MAAM,UAAyB,CAAC;CAChC,MAAM,MAAkB,CAAC;CAazB,OAAO;EAAE,aAZW,oBAAoB,OAAO;GAC7C;GACA;GACA;GACA;GACA,4BAAY,IAAI,IAAoB;GACpC;GACA,UAAU,QAAQ;GAClB,kBAAkB,QAAgB,QAAQ,oBAAoB,KAAK,QAAQ,EAAE;GAC7E,aAAa,QAAgB,QAAQ,eAAe,KAAK,QAAQ,EAAE;EACrE,CAEmB;EAAG;EAAoB;EAAW;EAAU;EAAS;CAAI;AAC9E"}
|
package/dist/plugin/assets.d.mts
CHANGED
|
@@ -3,4 +3,5 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
3
3
|
type WebAssetNext = (error?: unknown) => void;
|
|
4
4
|
export declare function createWebAssetMiddleware(srcRoot: string): (request: IncomingMessage, response: ServerResponse, next: WebAssetNext) => void;
|
|
5
5
|
//#endregion
|
|
6
|
+
export {};
|
|
6
7
|
//# sourceMappingURL=assets.d.mts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { WEAPP_VITE_WEB_AUTO_ROUTES_RESOLVED_MODULE_ID, WEAPP_VITE_WEB_ENTRY_RESOLVED_MODULE_ID } from "@weapp-core/constants";
|
|
2
|
+
|
|
1
3
|
//#region src/plugin/constants.ts
|
|
2
4
|
const SCRIPT_EXTS = [
|
|
3
5
|
".vue",
|
|
@@ -37,10 +39,10 @@ const WXS_RESOLVE_EXTS = [
|
|
|
37
39
|
".ts",
|
|
38
40
|
".js"
|
|
39
41
|
];
|
|
40
|
-
const ENTRY_ID =
|
|
42
|
+
const ENTRY_ID = WEAPP_VITE_WEB_ENTRY_RESOLVED_MODULE_ID;
|
|
41
43
|
const RUNTIME_ID = "/@weapp-vite/web/runtime";
|
|
42
44
|
const AUTO_ROUTES_ID = "weapp-vite/auto-routes";
|
|
43
|
-
const RESOLVED_AUTO_ROUTES_ID =
|
|
45
|
+
const RESOLVED_AUTO_ROUTES_ID = WEAPP_VITE_WEB_AUTO_ROUTES_RESOLVED_MODULE_ID;
|
|
44
46
|
const TEMPLATE_QUERY = "weapp-web-template";
|
|
45
47
|
const STYLE_QUERY = "weapp-web-style";
|
|
46
48
|
const SFC_TEMPLATE_QUERY = "weapp-web-sfc-template";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/plugin/constants.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/plugin/constants.ts"],"sourcesContent":["import {\n WEAPP_VITE_WEB_AUTO_ROUTES_RESOLVED_MODULE_ID,\n WEAPP_VITE_WEB_ENTRY_RESOLVED_MODULE_ID,\n} from '@weapp-core/constants'\n\nexport const SCRIPT_EXTS = ['.vue', '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs']\nexport const STYLE_EXTS = ['.wxss', '.scss', '.less', '.css']\nexport const TRANSFORM_STYLE_EXTS = ['.wxss']\nexport const TEMPLATE_EXTS = ['.wxml', '.axml', '.swan', '.ttml', '.qml', '.ksml', '.xhsml', '.html']\nexport const WXS_EXTS = ['.wxs', '.wxs.ts', '.wxs.js']\nexport const WXS_RESOLVE_EXTS = ['.wxs', '.wxs.ts', '.wxs.js', '.ts', '.js']\n\nexport const ENTRY_ID = WEAPP_VITE_WEB_ENTRY_RESOLVED_MODULE_ID\nexport const RUNTIME_ID = '/@weapp-vite/web/runtime'\nexport const AUTO_ROUTES_ID = 'weapp-vite/auto-routes'\nexport const RESOLVED_AUTO_ROUTES_ID = WEAPP_VITE_WEB_AUTO_ROUTES_RESOLVED_MODULE_ID\nexport const TEMPLATE_QUERY = 'weapp-web-template'\nexport const STYLE_QUERY = 'weapp-web-style'\nexport const SFC_TEMPLATE_QUERY = 'weapp-web-sfc-template'\nexport const SFC_STYLE_QUERY = 'weapp-web-sfc-style'\nexport const WEB_COMPONENT_PREFIX = '/@weapp-vite/web/component/'\nexport const WEB_COMPONENT_QUERY = 'weapp-web-component'\n"],"mappings":";;;AAKA,MAAa,cAAc;CAAC;CAAQ;CAAO;CAAQ;CAAO;CAAQ;CAAQ;AAAM;AAChF,MAAa,aAAa;CAAC;CAAS;CAAS;CAAS;AAAM;AAC5D,MAAa,uBAAuB,CAAC,OAAO;AAC5C,MAAa,gBAAgB;CAAC;CAAS;CAAS;CAAS;CAAS;CAAQ;CAAS;CAAU;AAAO;AACpG,MAAa,WAAW;CAAC;CAAQ;CAAW;AAAS;AACrD,MAAa,mBAAmB;CAAC;CAAQ;CAAW;CAAW;CAAO;AAAK;AAE3E,MAAa,WAAW;AACxB,MAAa,aAAa;AAC1B,MAAa,iBAAiB;AAC9B,MAAa,0BAA0B;AACvC,MAAa,iBAAiB;AAC9B,MAAa,cAAc;AAC3B,MAAa,qBAAqB;AAClC,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB;AACpC,MAAa,sBAAsB"}
|
package/dist/plugin/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { createMiniProgramPackageResolver, getAncestorNodeModulesPaths } from ".
|
|
|
11
11
|
import { transformScriptModule } from "./register.mjs";
|
|
12
12
|
import { ensureWebVueSfcResult, generateWebVueSfcStyle, generateWebVueSfcTemplate, resolveWebVueSfcStyleLanguage, transformWebVueSfcScript } from "./vueSfc.mjs";
|
|
13
13
|
import { getStableWebComponentId, scanProject } from "./scan.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { collectSfcHmrModules } from "./sfcHmr.mjs";
|
|
15
15
|
import { createEmptyScanState } from "./state.mjs";
|
|
16
16
|
import { createInlineStyleModule } from "./styleModule.mjs";
|
|
17
17
|
import { readFile } from "node:fs/promises";
|
|
@@ -125,7 +125,13 @@ function weappWebPlugin(options = {}) {
|
|
|
125
125
|
};
|
|
126
126
|
};
|
|
127
127
|
const scan = (context) => {
|
|
128
|
+
const graph = devServer?.moduleGraph;
|
|
129
|
+
for (const id of SCAN_VIRTUAL_MODULE_IDS) {
|
|
130
|
+
const module = graph?.getModuleById(id);
|
|
131
|
+
if (module) graph?.invalidateModule(module);
|
|
132
|
+
}
|
|
128
133
|
const result = scanQueue.then(async () => {
|
|
134
|
+
const previousState = state;
|
|
129
135
|
const nextState = createEmptyScanState();
|
|
130
136
|
await scanProject({
|
|
131
137
|
srcRoot,
|
|
@@ -139,7 +145,6 @@ function weappWebPlugin(options = {}) {
|
|
|
139
145
|
});
|
|
140
146
|
const nextComponentImportIdMap = /* @__PURE__ */ new Map();
|
|
141
147
|
for (const component of nextState.scanResult.components) if (component.importId) nextComponentImportIdMap.set(component.importId, component.script);
|
|
142
|
-
const graph = devServer?.moduleGraph;
|
|
143
148
|
const files = graph ? /* @__PURE__ */ new Set() : void 0;
|
|
144
149
|
if (files) for (const snapshot of [state, nextState]) {
|
|
145
150
|
for (const file of snapshot.moduleMeta.keys()) files.add(file);
|
|
@@ -148,25 +153,20 @@ function weappWebPlugin(options = {}) {
|
|
|
148
153
|
}
|
|
149
154
|
state = nextState;
|
|
150
155
|
componentImportIdMap = nextComponentImportIdMap;
|
|
151
|
-
if (graph && files) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (module) graph.invalidateModule(module);
|
|
155
|
-
}
|
|
156
|
-
for (const file of files) {
|
|
157
|
-
const modules = graph.getModulesByFile(file);
|
|
158
|
-
if (modules) for (const module of modules) graph.invalidateModule(module);
|
|
159
|
-
}
|
|
156
|
+
if (graph && files) for (const file of files) {
|
|
157
|
+
const modules = graph.getModulesByFile(file);
|
|
158
|
+
if (modules) for (const module of modules) graph.invalidateModule(module);
|
|
160
159
|
}
|
|
160
|
+
return [previousState, nextState];
|
|
161
161
|
});
|
|
162
|
-
scanQueue = result.
|
|
162
|
+
scanQueue = result.then(() => {}, () => {});
|
|
163
163
|
return result;
|
|
164
164
|
};
|
|
165
165
|
const scanChangedFile = async (context, file) => {
|
|
166
166
|
const clean = cleanUrl(file);
|
|
167
167
|
const normalized = normalizePath(clean);
|
|
168
168
|
if (!isInsideDir(clean, srcRoot) && !state.moduleMeta.has(normalized) && !state.templatePathSet.has(normalized)) return;
|
|
169
|
-
if (state.templatePathSet.has(normalized) || clean.endsWith(".json") || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith(".wxss") || SCRIPT_EXTS.includes(extname(clean)))
|
|
169
|
+
if (state.templatePathSet.has(normalized) || clean.endsWith(".json") || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith(".wxss") || SCRIPT_EXTS.includes(extname(clean))) return scan(context);
|
|
170
170
|
};
|
|
171
171
|
return {
|
|
172
172
|
name: "@weapp-vite/web",
|
|
@@ -236,8 +236,14 @@ function weappWebPlugin(options = {}) {
|
|
|
236
236
|
return resolveMiniProgramModuleId?.(id, importer).then((resolved) => resolved ?? null) ?? null;
|
|
237
237
|
},
|
|
238
238
|
async load(id) {
|
|
239
|
-
if (id ===
|
|
240
|
-
|
|
239
|
+
if (id === ENTRY_ID) {
|
|
240
|
+
await scanQueue;
|
|
241
|
+
return generateEntryModule(state.scanResult, root, wxssOptions, options);
|
|
242
|
+
}
|
|
243
|
+
if (id === RESOLVED_AUTO_ROUTES_ID) {
|
|
244
|
+
await scanQueue;
|
|
245
|
+
return generateAutoRoutesModule(state.scanResult);
|
|
246
|
+
}
|
|
241
247
|
if (hasQuery(id, "weapp-web-template")) {
|
|
242
248
|
const filename = cleanUrl(id);
|
|
243
249
|
let source = await readFile(filename, "utf8");
|
|
@@ -320,10 +326,9 @@ function weappWebPlugin(options = {}) {
|
|
|
320
326
|
},
|
|
321
327
|
async handleHotUpdate(ctx) {
|
|
322
328
|
const graph = devServer?.moduleGraph;
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return ctx.modules || affected.size ? [...affected] : void 0;
|
|
329
|
+
const snapshots = await scanChangedFile(this, ctx.file);
|
|
330
|
+
const affected = graph ? collectSfcHmrModules(snapshots ?? [state], cleanUrl(ctx.file), graph, ctx.modules) : ctx.modules;
|
|
331
|
+
return ctx.modules || affected?.length ? affected : void 0;
|
|
327
332
|
},
|
|
328
333
|
async transform(code, id) {
|
|
329
334
|
const clean = cleanUrl(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/index.ts"],"sourcesContent":["import type { WeappWebVitePlugin, WebCssConfig, WebDevServer, WebHmrContext, WebPluginContext, WebResolvedConfig, WebUserConfig } from './hostTypes'\nimport type { ResolveWebAutoImportTag, ResolveWebModuleId, WeappWebPluginOptions, WebResolvedComponent, WebStylePreprocessOptions } from './types'\nimport { readFile } from 'node:fs/promises'\nimport process from 'node:process'\n\nimport { dirname, extname, resolve } from 'pathe'\nimport { isUniAppCompatibilityFile, transformUniAppSource } from 'wevu/compiler'\nimport { compileWxml } from '../compiler/wxml'\nimport { transformWxsToEsm } from '../compiler/wxs'\nimport { createWxssPostcssPlugin, transformWxssToCss } from '../css/wxss'\nimport { createWebAssetMiddleware, emitWebAssets } from './assets'\nimport { AUTO_ROUTES_ID, ENTRY_ID, RESOLVED_AUTO_ROUTES_ID, RUNTIME_ID, SCRIPT_EXTS, SFC_STYLE_QUERY, SFC_TEMPLATE_QUERY, STYLE_EXTS, STYLE_QUERY, TEMPLATE_EXTS, TEMPLATE_QUERY, TRANSFORM_STYLE_EXTS, WEB_COMPONENT_PREFIX, WEB_COMPONENT_QUERY, WXS_EXTS } from './constants'\nimport { collectExternalComponentOptimizeDeps } from './dependencyScan'\nimport { generateAutoRoutesModule, generateEntryModule } from './entry'\nimport { wrapPageTemplate } from './layout'\nimport { createMiniProgramPackageResolver, getAncestorNodeModulesPaths } from './packageResolution'\nimport { cleanUrl, isHtmlEntry, isInsideDir, normalizePath, resolveFileWithExtensionsSync, resolveRuntimePolyfillPath, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport, toViteFsImport } from './path'\nimport { transformScriptModule } from './register'\nimport { getStableWebComponentId, scanProject } from './scan'\nimport { collectSfcHmrFiles } from './sfcHmr'\nimport { createEmptyScanState } from './state'\nimport { createInlineStyleModule } from './styleModule'\nimport { ensureWebVueSfcResult, generateWebVueSfcStyle, generateWebVueSfcTemplate, resolveWebVueSfcStyleLanguage, transformWebVueSfcScript } from './vueSfc'\n\nconst WEB_RUNTIME_MODULE_IDS = [\n 'lit',\n 'lit/async-directive.js',\n 'lit/directives/repeat.js',\n] as const\n\nconst SCAN_VIRTUAL_MODULE_IDS = [ENTRY_ID, RESOLVED_AUTO_ROUTES_ID] as const\n\nfunction isTemplateFile(id: string) {\n const lower = id.toLowerCase()\n return TEMPLATE_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction isWxsFile(id: string) {\n const lower = id.toLowerCase()\n return WXS_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction hasWxsQuery(id: string) {\n return id.includes('?wxs') || id.includes('&wxs')\n}\n\nfunction hasQuery(id: string, query: string) {\n return id.includes(`?${query}`) || id.includes(`&${query}`)\n}\n\nfunction isUniAppDependency(id: string, includes: readonly string[]) {\n return includes.some(packageName => id === packageName || id.startsWith(`${packageName}/`))\n}\n\nfunction resolveSfcStyleSourceFilename(id: string) {\n const filename = cleanUrl(id)\n const vueSuffixIndex = filename.lastIndexOf('.vue.')\n return vueSuffixIndex >= 0\n ? filename.slice(0, vueSuffixIndex + '.vue'.length)\n : filename\n}\n\nfunction createWebCssConfig(\n config: WebUserConfig,\n wxssOptions: WeappWebPluginOptions['wxss'],\n warn?: (message: string) => void,\n): WebCssConfig | undefined {\n const postcssConfig = config.css?.postcss\n if (typeof postcssConfig === 'string') {\n warn?.('[@weapp-vite/web] css.postcss 使用配置文件路径时无法注入 WXSS 转换插件。')\n return undefined\n }\n\n const plugins = postcssConfig?.plugins ?? []\n if (plugins.some(plugin => 'postcssPlugin' in plugin && plugin.postcssPlugin === 'weapp-vite-web-wxss')) {\n return undefined\n }\n\n return {\n postcss: {\n ...postcssConfig,\n plugins: [...plugins, createWxssPostcssPlugin(wxssOptions)],\n },\n preprocessorOptions: config.css?.preprocessorOptions,\n }\n}\n\nfunction resolveStylePreprocessOptions(\n options: WebStylePreprocessOptions | undefined,\n root: string,\n): WebStylePreprocessOptions | undefined {\n if (!options) {\n return undefined\n }\n\n const nodeModules = getAncestorNodeModulesPaths(root)\n return Object.fromEntries(Object.entries(options).map(([language, languageOptions]) => {\n if (!['sass', 'scss'].includes(language)) {\n return [language, languageOptions]\n }\n\n const loadPaths = Array.isArray(languageOptions.loadPaths)\n ? languageOptions.loadPaths.filter((value): value is string => typeof value === 'string')\n : []\n return [language, {\n ...languageOptions,\n loadPaths: Array.from(new Set([...loadPaths, ...nodeModules])),\n }]\n }))\n}\n\nexport function weappWebPlugin(options: WeappWebPluginOptions = {}): WeappWebVitePlugin {\n let root = process.cwd()\n let srcRoot = resolve(root, options.srcDir ?? 'src')\n let enableHmr = false\n let devServer: WebDevServer | undefined\n let resolveWebModuleId: ResolveWebModuleId | undefined\n let resolveMiniProgramModuleId: ResolveWebModuleId | undefined\n let resolveWebAutoImportTag: ResolveWebAutoImportTag | undefined\n const webRuntimeModules = new Map<string, string>()\n let stylePreprocessOptions: WebStylePreprocessOptions | undefined\n let componentImportIdMap = new Map<string, string>()\n\n let state = createEmptyScanState()\n let scanQueue: Promise<void> = Promise.resolve()\n const wxssOptions = options.wxss\n const runtimeProvider = options.__runtimeProvider\n const hmrAcceptCode = runtimeProvider\n ? runtimeProvider.hmrAcceptCode\n : 'if (import.meta.hot) { import.meta.hot.accept() }'\n\n const resolveTemplatePath = (raw: string, importer: string) => resolveTemplatePathSync(raw, importer, srcRoot)\n const resolveWxsPath = (raw: string, importer: string) => resolveWxsPathSync(raw, importer, srcRoot)\n const resolveMetaByTemplate = (filename: string) => {\n const normalized = normalizePath(filename)\n for (const meta of state.moduleMeta.values()) {\n if (meta.templatePath && normalizePath(meta.templatePath) === normalized) {\n return meta\n }\n }\n return undefined\n }\n\n const createAutoImportTagResolver = (): ResolveWebAutoImportTag | undefined => {\n const resolvers = options.__autoImportResolvers\n if (!resolvers?.length) {\n return undefined\n }\n return async (tag, importer) => {\n for (const resolver of resolvers) {\n let matched: WebResolvedComponent | void\n if (typeof resolver === 'function') {\n matched = resolver(tag, importer)\n }\n else if (typeof resolver.resolve === 'function') {\n matched = resolver.resolve(tag, importer)\n }\n else {\n const from = resolver.components?.[tag]\n matched = from ? { name: tag, from } : undefined\n }\n if (!matched) {\n continue\n }\n const request = matched.resolvedId ?? matched.from\n const resolvedId = await resolveWebModuleId?.(request, importer)\n return {\n ...matched,\n resolvedId: resolvedId ?? matched.resolvedId,\n sourceType: matched.sourceType ?? (resolvedId?.endsWith('.vue') ? 'wevu-sfc' : 'native'),\n }\n }\n return undefined\n }\n }\n\n const scan = (context: WebPluginContext) => {\n const result = scanQueue.then(async () => {\n const nextState = createEmptyScanState()\n await scanProject({\n srcRoot,\n warn: context.warn?.bind(context),\n state: nextState,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n resolveAppConfig: options.__resolveAppConfig,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n const nextComponentImportIdMap = new Map<string, string>()\n for (const component of nextState.scanResult.components) {\n if (component.importId) {\n nextComponentImportIdMap.set(component.importId, component.script)\n }\n }\n const graph = devServer?.moduleGraph\n const files = graph ? new Set<string>() : undefined\n if (files) {\n for (const snapshot of [state, nextState]) {\n for (const file of snapshot.moduleMeta.keys()) {\n files.add(file)\n }\n for (const file of snapshot.templatePathSet) {\n files.add(file)\n }\n for (const [file, result] of snapshot.sfcResults) {\n files.add(`${file}.${resolveWebVueSfcStyleLanguage(result, file)}`)\n }\n }\n }\n // 虚拟模块始终读取最后一次完整快照,不暴露扫描过程中的空映射。\n state = nextState\n componentImportIdMap = nextComponentImportIdMap\n if (graph && files) {\n for (const id of SCAN_VIRTUAL_MODULE_IDS) {\n const module = graph.getModuleById(id)\n if (module) {\n graph.invalidateModule(module)\n }\n }\n // 入口失效不会向下传播;脚本、模板和合成样式同样属于扫描快照。\n for (const file of files) {\n const modules = graph.getModulesByFile(file)\n if (modules) {\n for (const module of modules) {\n graph.invalidateModule(module)\n }\n }\n }\n }\n })\n // 调用方仍接收原始错误;队尾只负责允许下一次文件变更恢复扫描。\n scanQueue = result.catch(() => {})\n return result\n }\n\n const scanChangedFile = async (context: WebPluginContext, file: string) => {\n const clean = cleanUrl(file)\n const normalized = normalizePath(clean)\n if (!isInsideDir(clean, srcRoot) && !state.moduleMeta.has(normalized) && !state.templatePathSet.has(normalized)) {\n return\n }\n if (state.templatePathSet.has(normalized) || clean.endsWith('.json') || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith('.wxss') || SCRIPT_EXTS.includes(extname(clean))) {\n await scan(context)\n }\n }\n\n return {\n name: '@weapp-vite/web',\n enforce: 'pre',\n config(this: WebPluginContext, config: WebUserConfig) {\n const css = createWebCssConfig(config, wxssOptions, this.warn?.bind(this))\n return css ? { css } : undefined\n },\n async configResolved(this: WebPluginContext, config: WebResolvedConfig) {\n root = config.root\n const { createRequire } = await import('node:module')\n const requireFromWebRuntime = createRequire(import.meta.url)\n const requireFromProject = createRequire(resolve(root, 'package.json'))\n for (const id of WEB_RUNTIME_MODULE_IDS) {\n webRuntimeModules.set(id, requireFromWebRuntime.resolve(id))\n }\n webRuntimeModules.set(RUNTIME_ID, resolveRuntimePolyfillPath())\n resolveMiniProgramModuleId = createMiniProgramPackageResolver(requireFromProject.resolve)\n srcRoot = resolve(root, options.srcDir ?? 'src')\n stylePreprocessOptions = resolveStylePreprocessOptions(config.css?.preprocessorOptions, root)\n enableHmr = config.command === 'serve'\n const resolveViteModuleId = config.createResolver?.()\n resolveWebModuleId = resolveViteModuleId\n ? async (source, importer) => {\n const resolved = await resolveViteModuleId(source, importer)\n return await resolveMiniProgramModuleId?.(resolved ?? source, importer)\n ?? await resolveMiniProgramModuleId?.(source, importer)\n ?? resolved\n }\n : undefined\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n const componentDependencies = await collectExternalComponentOptimizeDeps(state.scanResult.components)\n const uniAppIncludes = options.__uniApp?.include ?? []\n config.optimizeDeps ??= {}\n config.optimizeDeps.exclude = Array.from(new Set([\n ...(config.optimizeDeps.exclude ?? []),\n ...uniAppIncludes,\n ]))\n config.optimizeDeps.include = Array.from(new Set([\n ...(config.optimizeDeps.include ?? []),\n ...componentDependencies,\n ])).filter(dependency => !isUniAppDependency(dependency, uniAppIncludes))\n },\n configureServer(server: WebDevServer) {\n devServer = server\n server.middlewares.use(createWebAssetMiddleware(srcRoot))\n },\n async buildStart(this: WebPluginContext) {\n if (!resolveWebModuleId && this.resolve) {\n resolveWebModuleId = async (source, importer) => {\n const resolved = await this.resolve?.(source, importer, { skipSelf: true })\n return await resolveMiniProgramModuleId?.(resolved?.id ?? source, importer)\n ?? await resolveMiniProgramModuleId?.(source, importer)\n ?? resolved?.id\n }\n }\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n if (!enableHmr) {\n await emitWebAssets(this, srcRoot)\n }\n },\n resolveId(id: string, importer?: string) {\n const runtimeModule = webRuntimeModules.get(id)\n if (runtimeModule) {\n return runtimeModule\n }\n if (id === '/@weapp-vite/web/entry' || id === '@weapp-vite/web/entry') {\n return ENTRY_ID\n }\n if (id === AUTO_ROUTES_ID) {\n return RESOLVED_AUTO_ROUTES_ID\n }\n if (id.startsWith(WEB_COMPONENT_PREFIX)) {\n const request = decodeURIComponent(id.slice(WEB_COMPONENT_PREFIX.length))\n const resolvedId = componentImportIdMap.get(request)\n return resolvedId ? `${cleanUrl(resolvedId)}?${WEB_COMPONENT_QUERY}` : null\n }\n if (id.startsWith('.') && importer && cleanUrl(importer).endsWith('.vue') && !extname(id)) {\n const resolvedScript = resolveFileWithExtensionsSync(resolve(dirname(cleanUrl(importer)), id), SCRIPT_EXTS)\n if (resolvedScript?.endsWith('.vue')) {\n return resolvedScript\n }\n }\n if (hasQuery(id, SFC_STYLE_QUERY)) {\n const queryIndex = id.indexOf('?')\n const pathname = queryIndex >= 0 ? id.slice(0, queryIndex) : id\n const query = queryIndex >= 0 ? id.slice(queryIndex) : ''\n if (pathname.startsWith('.') && importer) {\n return `${resolve(dirname(cleanUrl(importer)), pathname)}${query}`\n }\n return id\n }\n return resolveMiniProgramModuleId?.(id, importer).then(resolved => resolved ?? null) ?? null\n },\n async load(this: WebPluginContext, id: string) {\n if (id === ENTRY_ID) {\n return generateEntryModule(state.scanResult, root, wxssOptions, options)\n }\n if (id === RESOLVED_AUTO_ROUTES_ID) {\n return generateAutoRoutesModule(state.scanResult)\n }\n if (hasQuery(id, TEMPLATE_QUERY)) {\n const filename = cleanUrl(id)\n let source = await readFile(filename, 'utf8')\n const pageMeta = resolveMetaByTemplate(filename)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n source = wrapPageTemplate(source, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizePath(filename))\n const componentTags = state.templateComponentMap.get(normalizePath(filename))\n const compiled = compileWxml({\n id: filename,\n source,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasWxsQuery(id)) {\n const filename = cleanUrl(id)\n const source = await readFile(filename, 'utf8')\n const compiled = transformWxsToEsm(source, filename, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasQuery(id, STYLE_QUERY)) {\n const source = await readFile(cleanUrl(id), 'utf8')\n const { css } = transformWxssToCss(source, wxssOptions)\n return createInlineStyleModule(css)\n }\n if (id.includes(`?${SFC_TEMPLATE_QUERY}`) || id.includes(`&${SFC_TEMPLATE_QUERY}`)) {\n const filename = cleanUrl(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n const compiled = generateWebVueSfcTemplate(result, meta, filename, srcRoot)\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (id.includes(`?${SFC_STYLE_QUERY}`) || id.includes(`&${SFC_STYLE_QUERY}`)) {\n const filename = resolveSfcStyleSourceFilename(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n this.addWatchFile?.(filename)\n for (const dependency of result.meta?.sfcSrcDeps ?? []) {\n this.addWatchFile?.(dependency)\n }\n return generateWebVueSfcStyle(result)\n }\n return null\n },\n watchChange: {\n order: 'post',\n sequential: true,\n async handler(this: WebPluginContext, id, change) {\n // Vite 的 handleHotUpdate 不处理增删;必须在结构性 HMR 前发布完整入口。\n if (enableHmr && change.event !== 'update') {\n await scanChangedFile(this, id)\n }\n },\n },\n async handleHotUpdate<Module extends object>(this: WebPluginContext, ctx: WebHmrContext<Module>) {\n const graph = devServer?.moduleGraph\n const affected = new Set(ctx.modules)\n if (graph) {\n for (const file of collectSfcHmrFiles(state, cleanUrl(ctx.file))) {\n // 在扫描替换入口快照前保留旧节点,覆盖外部块删除及样式后缀变更。\n for (const module of graph.getModulesByFile(file) ?? []) {\n // 图与本次 HMR 上下文来自同一 Vite server,保留宿主模块节点的具体类型。\n affected.add(module as Module)\n }\n }\n }\n await scanChangedFile(this, ctx.file)\n return ctx.modules || affected.size ? [...affected] : undefined\n },\n async transform(this: WebPluginContext, code: string, id: string) {\n const clean = cleanUrl(id)\n let uniAppTransformed = false\n\n if (\n options.__uniApp\n && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n && !clean.endsWith('.vue')\n ) {\n const transformed = transformUniAppSource(code, { filename: clean, target: 'h5' })\n if (transformed.changed) {\n code = transformed.code\n uniAppTransformed = true\n }\n }\n\n if (\n hasQuery(id, TEMPLATE_QUERY)\n || hasWxsQuery(id)\n || hasQuery(id, STYLE_QUERY)\n || hasQuery(id, SFC_TEMPLATE_QUERY)\n || hasQuery(id, SFC_STYLE_QUERY)\n ) {\n return null\n }\n\n if (clean.endsWith('.vue')) {\n const normalized = normalizePath(clean)\n const meta = state.moduleMeta.get(normalized) ?? {\n kind: 'component' as const,\n id: getStableWebComponentId(clean, srcRoot),\n scriptPath: clean,\n sourceType: 'vue-sfc' as const,\n }\n state.moduleMeta.set(normalized, meta)\n const result = await ensureWebVueSfcResult({\n filename: clean,\n meta,\n srcRoot,\n state,\n source: code,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n return transformWebVueSfcScript({\n code: result.script!,\n filename: clean,\n meta,\n runtimeModuleId: runtimeProvider?.moduleId ?? toViteFsImport(resolveRuntimePolyfillPath()),\n styleLanguage: resolveWebVueSfcStyleLanguage(result, clean),\n enableHmr,\n hmrAcceptCode,\n })\n }\n\n if (isTemplateFile(clean)) {\n if (isHtmlEntry(clean, root)) {\n return null\n }\n const normalizedId = normalizePath(clean)\n if (state.templatePathSet.size > 0) {\n if (!isInsideDir(clean, srcRoot)) {\n return null\n }\n if (!state.templatePathSet.has(normalizedId)) {\n return null\n }\n }\n let templateSource = code\n const pageMeta = resolveMetaByTemplate(clean)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n templateSource = wrapPageTemplate(code, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizedId)\n const componentTags = state.templateComponentMap.get(normalizedId)\n const { code: compiled, dependencies, warnings } = compileWxml({\n id: clean,\n source: templateSource,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (isWxsFile(clean) || hasWxsQuery(id)) {\n const { code: compiled, dependencies, warnings } = transformWxsToEsm(code, clean, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (TRANSFORM_STYLE_EXTS.some(ext => clean.endsWith(ext))) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return {\n code: createInlineStyleModule(css),\n map: null,\n }\n }\n\n if (STYLE_EXTS.some(ext => clean.endsWith(ext)) && !clean.endsWith('.wxss')) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return { code: css, map: null }\n }\n\n if (!SCRIPT_EXTS.some(ext => clean.endsWith(ext))) {\n return uniAppTransformed ? { code, map: null } : null\n }\n if (clean.includes('node_modules') && !hasQuery(id, WEB_COMPONENT_QUERY)) {\n return options.__uniApp && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n ? { code, map: null }\n : null\n }\n\n const meta = state.moduleMeta.get(normalizePath(clean))\n if (!meta) {\n return null\n }\n\n return transformScriptModule({\n code,\n cleanId: clean,\n meta,\n enableHmr,\n runtimeModuleId: runtimeProvider?.moduleId,\n hmrAcceptCode,\n })\n },\n }\n}\n\nexport type { WeappWebPluginOptions } from './types'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,yBAAyB;CAC7B;CACA;CACA;AACF;AAEA,MAAM,0BAA0B,CAAC,UAAU,uBAAuB;AAElE,SAAS,eAAe,IAAY;CAClC,MAAM,QAAQ,GAAG,YAAY;CAC7B,OAAO,cAAc,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AACtD;AAEA,SAAS,UAAU,IAAY;CAC7B,MAAM,QAAQ,GAAG,YAAY;CAC7B,OAAO,SAAS,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AACjD;AAEA,SAAS,YAAY,IAAY;CAC/B,OAAO,GAAG,SAAS,MAAM,KAAK,GAAG,SAAS,MAAM;AAClD;AAEA,SAAS,SAAS,IAAY,OAAe;CAC3C,OAAO,GAAG,SAAS,IAAI,OAAO,KAAK,GAAG,SAAS,IAAI,OAAO;AAC5D;AAEA,SAAS,mBAAmB,IAAY,UAA6B;CACnE,OAAO,SAAS,MAAK,gBAAe,OAAO,eAAe,GAAG,WAAW,GAAG,YAAY,EAAE,CAAC;AAC5F;AAEA,SAAS,8BAA8B,IAAY;CACjD,MAAM,WAAW,SAAS,EAAE;CAC5B,MAAM,iBAAiB,SAAS,YAAY,OAAO;CACnD,OAAO,kBAAkB,IACrB,SAAS,MAAM,GAAG,iBAAiB,CAAa,IAChD;AACN;AAEA,SAAS,mBACP,QACA,aACA,MAC0B;CAC1B,MAAM,gBAAgB,OAAO,KAAK;CAClC,IAAI,OAAO,kBAAkB,UAAU;EACrC,OAAO,wDAAwD;EAC/D;CACF;CAEA,MAAM,UAAU,eAAe,WAAW,CAAC;CAC3C,IAAI,QAAQ,MAAK,WAAU,mBAAmB,UAAU,OAAO,kBAAkB,qBAAqB,GACpG;CAGF,OAAO;E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GAAG;IAG/B,MAAM,OAAO,KAAK;IAClB,IAAI,UAAU,UAAU,MACtB,KAAK,MAAM,WAAW,UACpB,KAAK,KAAK,MAAM,OAAO;IAG3B,OAAO;KAAE,MAAM;KAAU,KAAK;IAAK;GACrC;GAEA,IAAI,qBAAqB,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,GAAG;IACzD,MAAM,EAAE,QAAQ,mBAAmB,MAAM,WAAW;IACpD,OAAO;KACL,MAAM,wBAAwB,GAAG;KACjC,KAAK;IACP;GACF;GAEA,IAAI,WAAW,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,MAAM,SAAS,OAAO,GAAG;IAC3E,MAAM,EAAE,QAAQ,mBAAmB,MAAM,WAAW;IACpD,OAAO;KAAE,MAAM;KAAK,KAAK;IAAK;GAChC;GAEA,IAAI,CAAC,YAAY,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,GAC9C,OAAO,oBAAoB;IAAE;IAAM,KAAK;GAAK,IAAI;GAEnD,IAAI,MAAM,SAAS,cAAc,KAAK,CAAC,SAAS,yBAAuB,GACrE,OAAO,QAAQ,YAAY,0BAA0B,OAAO,SAAS,QAAQ,SAAS,OAAO,IACzF;IAAE;IAAM,KAAK;GAAK,IAClB;GAGN,MAAM,OAAO,MAAM,WAAW,IAAI,cAAc,KAAK,CAAC;GACtD,IAAI,CAAC,MACH,OAAO;GAGT,OAAO,sBAAsB;IAC3B;IACA,SAAS;IACT;IACA;IACA,iBAAiB,iBAAiB;IAClC;GACF,CAAC;EACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/index.ts"],"sourcesContent":["import type { WeappWebVitePlugin, WebCssConfig, WebDevServer, WebHmrContext, WebPluginContext, WebResolvedConfig, WebUserConfig } from './hostTypes'\nimport type { ResolveWebAutoImportTag, ResolveWebModuleId, WeappWebPluginOptions, WebResolvedComponent, WebStylePreprocessOptions } from './types'\nimport { readFile } from 'node:fs/promises'\nimport process from 'node:process'\n\nimport { dirname, extname, resolve } from 'pathe'\nimport { isUniAppCompatibilityFile, transformUniAppSource } from 'wevu/compiler'\nimport { compileWxml } from '../compiler/wxml'\nimport { transformWxsToEsm } from '../compiler/wxs'\nimport { createWxssPostcssPlugin, transformWxssToCss } from '../css/wxss'\nimport { createWebAssetMiddleware, emitWebAssets } from './assets'\nimport { AUTO_ROUTES_ID, ENTRY_ID, RESOLVED_AUTO_ROUTES_ID, RUNTIME_ID, SCRIPT_EXTS, SFC_STYLE_QUERY, SFC_TEMPLATE_QUERY, STYLE_EXTS, STYLE_QUERY, TEMPLATE_EXTS, TEMPLATE_QUERY, TRANSFORM_STYLE_EXTS, WEB_COMPONENT_PREFIX, WEB_COMPONENT_QUERY, WXS_EXTS } from './constants'\nimport { collectExternalComponentOptimizeDeps } from './dependencyScan'\nimport { generateAutoRoutesModule, generateEntryModule } from './entry'\nimport { wrapPageTemplate } from './layout'\nimport { createMiniProgramPackageResolver, getAncestorNodeModulesPaths } from './packageResolution'\nimport { cleanUrl, isHtmlEntry, isInsideDir, normalizePath, resolveFileWithExtensionsSync, resolveRuntimePolyfillPath, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport, toViteFsImport } from './path'\nimport { transformScriptModule } from './register'\nimport { getStableWebComponentId, scanProject } from './scan'\nimport { collectSfcHmrModules } from './sfcHmr'\nimport { createEmptyScanState } from './state'\nimport { createInlineStyleModule } from './styleModule'\nimport { ensureWebVueSfcResult, generateWebVueSfcStyle, generateWebVueSfcTemplate, resolveWebVueSfcStyleLanguage, transformWebVueSfcScript } from './vueSfc'\n\nconst WEB_RUNTIME_MODULE_IDS = [\n 'lit',\n 'lit/async-directive.js',\n 'lit/directives/repeat.js',\n] as const\n\nconst SCAN_VIRTUAL_MODULE_IDS = [ENTRY_ID, RESOLVED_AUTO_ROUTES_ID] as const\n\nfunction isTemplateFile(id: string) {\n const lower = id.toLowerCase()\n return TEMPLATE_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction isWxsFile(id: string) {\n const lower = id.toLowerCase()\n return WXS_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction hasWxsQuery(id: string) {\n return id.includes('?wxs') || id.includes('&wxs')\n}\n\nfunction hasQuery(id: string, query: string) {\n return id.includes(`?${query}`) || id.includes(`&${query}`)\n}\n\nfunction isUniAppDependency(id: string, includes: readonly string[]) {\n return includes.some(packageName => id === packageName || id.startsWith(`${packageName}/`))\n}\n\nfunction resolveSfcStyleSourceFilename(id: string) {\n const filename = cleanUrl(id)\n const vueSuffixIndex = filename.lastIndexOf('.vue.')\n return vueSuffixIndex >= 0\n ? filename.slice(0, vueSuffixIndex + '.vue'.length)\n : filename\n}\n\nfunction createWebCssConfig(\n config: WebUserConfig,\n wxssOptions: WeappWebPluginOptions['wxss'],\n warn?: (message: string) => void,\n): WebCssConfig | undefined {\n const postcssConfig = config.css?.postcss\n if (typeof postcssConfig === 'string') {\n warn?.('[@weapp-vite/web] css.postcss 使用配置文件路径时无法注入 WXSS 转换插件。')\n return undefined\n }\n\n const plugins = postcssConfig?.plugins ?? []\n if (plugins.some(plugin => 'postcssPlugin' in plugin && plugin.postcssPlugin === 'weapp-vite-web-wxss')) {\n return undefined\n }\n\n return {\n postcss: {\n ...postcssConfig,\n plugins: [...plugins, createWxssPostcssPlugin(wxssOptions)],\n },\n preprocessorOptions: config.css?.preprocessorOptions,\n }\n}\n\nfunction resolveStylePreprocessOptions(\n options: WebStylePreprocessOptions | undefined,\n root: string,\n): WebStylePreprocessOptions | undefined {\n if (!options) {\n return undefined\n }\n\n const nodeModules = getAncestorNodeModulesPaths(root)\n return Object.fromEntries(Object.entries(options).map(([language, languageOptions]) => {\n if (!['sass', 'scss'].includes(language)) {\n return [language, languageOptions]\n }\n\n const loadPaths = Array.isArray(languageOptions.loadPaths)\n ? languageOptions.loadPaths.filter((value): value is string => typeof value === 'string')\n : []\n return [language, {\n ...languageOptions,\n loadPaths: Array.from(new Set([...loadPaths, ...nodeModules])),\n }]\n }))\n}\n\nexport function weappWebPlugin(options: WeappWebPluginOptions = {}): WeappWebVitePlugin {\n let root = process.cwd()\n let srcRoot = resolve(root, options.srcDir ?? 'src')\n let enableHmr = false\n let devServer: WebDevServer | undefined\n let resolveWebModuleId: ResolveWebModuleId | undefined\n let resolveMiniProgramModuleId: ResolveWebModuleId | undefined\n let resolveWebAutoImportTag: ResolveWebAutoImportTag | undefined\n const webRuntimeModules = new Map<string, string>()\n let stylePreprocessOptions: WebStylePreprocessOptions | undefined\n let componentImportIdMap = new Map<string, string>()\n\n let state = createEmptyScanState()\n let scanQueue: Promise<void> = Promise.resolve()\n const wxssOptions = options.wxss\n const runtimeProvider = options.__runtimeProvider\n const hmrAcceptCode = runtimeProvider\n ? runtimeProvider.hmrAcceptCode\n : 'if (import.meta.hot) { import.meta.hot.accept() }'\n\n const resolveTemplatePath = (raw: string, importer: string) => resolveTemplatePathSync(raw, importer, srcRoot)\n const resolveWxsPath = (raw: string, importer: string) => resolveWxsPathSync(raw, importer, srcRoot)\n const resolveMetaByTemplate = (filename: string) => {\n const normalized = normalizePath(filename)\n for (const meta of state.moduleMeta.values()) {\n if (meta.templatePath && normalizePath(meta.templatePath) === normalized) {\n return meta\n }\n }\n return undefined\n }\n\n const createAutoImportTagResolver = (): ResolveWebAutoImportTag | undefined => {\n const resolvers = options.__autoImportResolvers\n if (!resolvers?.length) {\n return undefined\n }\n return async (tag, importer) => {\n for (const resolver of resolvers) {\n let matched: WebResolvedComponent | void\n if (typeof resolver === 'function') {\n matched = resolver(tag, importer)\n }\n else if (typeof resolver.resolve === 'function') {\n matched = resolver.resolve(tag, importer)\n }\n else {\n const from = resolver.components?.[tag]\n matched = from ? { name: tag, from } : undefined\n }\n if (!matched) {\n continue\n }\n const request = matched.resolvedId ?? matched.from\n const resolvedId = await resolveWebModuleId?.(request, importer)\n return {\n ...matched,\n resolvedId: resolvedId ?? matched.resolvedId,\n sourceType: matched.sourceType ?? (resolvedId?.endsWith('.vue') ? 'wevu-sfc' : 'native'),\n }\n }\n return undefined\n }\n }\n\n const scan = (context: WebPluginContext) => {\n const graph = devServer?.moduleGraph\n // 先撤销旧拓扑响应,避免扫描期间的浏览器重验证通过缓存跳过 load。\n for (const id of SCAN_VIRTUAL_MODULE_IDS) {\n const module = graph?.getModuleById(id)\n if (module) {\n graph?.invalidateModule(module)\n }\n }\n const result = scanQueue.then(async () => {\n const previousState = state\n const nextState = createEmptyScanState()\n await scanProject({\n srcRoot,\n warn: context.warn?.bind(context),\n state: nextState,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n resolveAppConfig: options.__resolveAppConfig,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n const nextComponentImportIdMap = new Map<string, string>()\n for (const component of nextState.scanResult.components) {\n if (component.importId) {\n nextComponentImportIdMap.set(component.importId, component.script)\n }\n }\n const files = graph ? new Set<string>() : undefined\n if (files) {\n for (const snapshot of [state, nextState]) {\n for (const file of snapshot.moduleMeta.keys()) {\n files.add(file)\n }\n for (const file of snapshot.templatePathSet) {\n files.add(file)\n }\n for (const [file, result] of snapshot.sfcResults) {\n files.add(`${file}.${resolveWebVueSfcStyleLanguage(result, file)}`)\n }\n }\n }\n // 源模块始终读取最后一次完整快照,不暴露扫描过程中的空映射。\n state = nextState\n componentImportIdMap = nextComponentImportIdMap\n if (graph && files) {\n // 入口失效不会向下传播;脚本、模板和合成样式同样属于扫描快照。\n for (const file of files) {\n const modules = graph.getModulesByFile(file)\n if (modules) {\n for (const module of modules) {\n graph.invalidateModule(module)\n }\n }\n }\n }\n return [previousState, nextState] as const\n })\n // 调用方仍接收原始错误;队尾只负责允许下一次文件变更恢复扫描。\n scanQueue = result.then(() => {}, () => {})\n return result\n }\n\n const scanChangedFile = async (context: WebPluginContext, file: string) => {\n const clean = cleanUrl(file)\n const normalized = normalizePath(clean)\n if (!isInsideDir(clean, srcRoot) && !state.moduleMeta.has(normalized) && !state.templatePathSet.has(normalized)) {\n return\n }\n if (state.templatePathSet.has(normalized) || clean.endsWith('.json') || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith('.wxss') || SCRIPT_EXTS.includes(extname(clean))) {\n return scan(context)\n }\n }\n\n return {\n name: '@weapp-vite/web',\n enforce: 'pre',\n config(this: WebPluginContext, config: WebUserConfig) {\n const css = createWebCssConfig(config, wxssOptions, this.warn?.bind(this))\n return css ? { css } : undefined\n },\n async configResolved(this: WebPluginContext, config: WebResolvedConfig) {\n root = config.root\n const { createRequire } = await import('node:module')\n const requireFromWebRuntime = createRequire(import.meta.url)\n const requireFromProject = createRequire(resolve(root, 'package.json'))\n for (const id of WEB_RUNTIME_MODULE_IDS) {\n webRuntimeModules.set(id, requireFromWebRuntime.resolve(id))\n }\n webRuntimeModules.set(RUNTIME_ID, resolveRuntimePolyfillPath())\n resolveMiniProgramModuleId = createMiniProgramPackageResolver(requireFromProject.resolve)\n srcRoot = resolve(root, options.srcDir ?? 'src')\n stylePreprocessOptions = resolveStylePreprocessOptions(config.css?.preprocessorOptions, root)\n enableHmr = config.command === 'serve'\n const resolveViteModuleId = config.createResolver?.()\n resolveWebModuleId = resolveViteModuleId\n ? async (source, importer) => {\n const resolved = await resolveViteModuleId(source, importer)\n return await resolveMiniProgramModuleId?.(resolved ?? source, importer)\n ?? await resolveMiniProgramModuleId?.(source, importer)\n ?? resolved\n }\n : undefined\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n const componentDependencies = await collectExternalComponentOptimizeDeps(state.scanResult.components)\n const uniAppIncludes = options.__uniApp?.include ?? []\n config.optimizeDeps ??= {}\n config.optimizeDeps.exclude = Array.from(new Set([\n ...(config.optimizeDeps.exclude ?? []),\n ...uniAppIncludes,\n ]))\n config.optimizeDeps.include = Array.from(new Set([\n ...(config.optimizeDeps.include ?? []),\n ...componentDependencies,\n ])).filter(dependency => !isUniAppDependency(dependency, uniAppIncludes))\n },\n configureServer(server: WebDevServer) {\n devServer = server\n server.middlewares.use(createWebAssetMiddleware(srcRoot))\n },\n async buildStart(this: WebPluginContext) {\n if (!resolveWebModuleId && this.resolve) {\n resolveWebModuleId = async (source, importer) => {\n const resolved = await this.resolve?.(source, importer, { skipSelf: true })\n return await resolveMiniProgramModuleId?.(resolved?.id ?? source, importer)\n ?? await resolveMiniProgramModuleId?.(source, importer)\n ?? resolved?.id\n }\n }\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n if (!enableHmr) {\n await emitWebAssets(this, srcRoot)\n }\n },\n resolveId(id: string, importer?: string) {\n const runtimeModule = webRuntimeModules.get(id)\n if (runtimeModule) {\n return runtimeModule\n }\n if (id === '/@weapp-vite/web/entry' || id === '@weapp-vite/web/entry') {\n return ENTRY_ID\n }\n if (id === AUTO_ROUTES_ID) {\n return RESOLVED_AUTO_ROUTES_ID\n }\n if (id.startsWith(WEB_COMPONENT_PREFIX)) {\n const request = decodeURIComponent(id.slice(WEB_COMPONENT_PREFIX.length))\n const resolvedId = componentImportIdMap.get(request)\n return resolvedId ? `${cleanUrl(resolvedId)}?${WEB_COMPONENT_QUERY}` : null\n }\n if (id.startsWith('.') && importer && cleanUrl(importer).endsWith('.vue') && !extname(id)) {\n const resolvedScript = resolveFileWithExtensionsSync(resolve(dirname(cleanUrl(importer)), id), SCRIPT_EXTS)\n if (resolvedScript?.endsWith('.vue')) {\n return resolvedScript\n }\n }\n if (hasQuery(id, SFC_STYLE_QUERY)) {\n const queryIndex = id.indexOf('?')\n const pathname = queryIndex >= 0 ? id.slice(0, queryIndex) : id\n const query = queryIndex >= 0 ? id.slice(queryIndex) : ''\n if (pathname.startsWith('.') && importer) {\n return `${resolve(dirname(cleanUrl(importer)), pathname)}${query}`\n }\n return id\n }\n return resolveMiniProgramModuleId?.(id, importer).then(resolved => resolved ?? null) ?? null\n },\n async load(this: WebPluginContext, id: string) {\n if (id === ENTRY_ID) {\n await scanQueue\n return generateEntryModule(state.scanResult, root, wxssOptions, options)\n }\n if (id === RESOLVED_AUTO_ROUTES_ID) {\n await scanQueue\n return generateAutoRoutesModule(state.scanResult)\n }\n if (hasQuery(id, TEMPLATE_QUERY)) {\n const filename = cleanUrl(id)\n let source = await readFile(filename, 'utf8')\n const pageMeta = resolveMetaByTemplate(filename)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n source = wrapPageTemplate(source, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizePath(filename))\n const componentTags = state.templateComponentMap.get(normalizePath(filename))\n const compiled = compileWxml({\n id: filename,\n source,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasWxsQuery(id)) {\n const filename = cleanUrl(id)\n const source = await readFile(filename, 'utf8')\n const compiled = transformWxsToEsm(source, filename, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasQuery(id, STYLE_QUERY)) {\n const source = await readFile(cleanUrl(id), 'utf8')\n const { css } = transformWxssToCss(source, wxssOptions)\n return createInlineStyleModule(css)\n }\n if (id.includes(`?${SFC_TEMPLATE_QUERY}`) || id.includes(`&${SFC_TEMPLATE_QUERY}`)) {\n const filename = cleanUrl(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n const compiled = generateWebVueSfcTemplate(result, meta, filename, srcRoot)\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (id.includes(`?${SFC_STYLE_QUERY}`) || id.includes(`&${SFC_STYLE_QUERY}`)) {\n const filename = resolveSfcStyleSourceFilename(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n this.addWatchFile?.(filename)\n for (const dependency of result.meta?.sfcSrcDeps ?? []) {\n this.addWatchFile?.(dependency)\n }\n return generateWebVueSfcStyle(result)\n }\n return null\n },\n watchChange: {\n order: 'post',\n sequential: true,\n async handler(this: WebPluginContext, id, change) {\n // Vite 的 handleHotUpdate 不处理增删;必须在结构性 HMR 前发布完整入口。\n if (enableHmr && change.event !== 'update') {\n await scanChangedFile(this, id)\n }\n },\n },\n async handleHotUpdate<Module extends object>(this: WebPluginContext, ctx: WebHmrContext<Module>) {\n const graph = devServer?.moduleGraph\n // 扫描排队期间仍可能发布前一轮拓扑;节点归属必须来自本轮实际提交的前后快照。\n // 保留前快照中的已删除 owner、外部块和旧样式后缀,同时用后快照识别恢复的 SFC。\n const snapshots = await scanChangedFile(this, ctx.file)\n const affected = graph\n ? collectSfcHmrModules(snapshots ?? [state], cleanUrl(ctx.file), graph, ctx.modules)\n : ctx.modules\n return ctx.modules || affected?.length ? affected : undefined\n },\n async transform(this: WebPluginContext, code: string, id: string) {\n const clean = cleanUrl(id)\n let uniAppTransformed = false\n\n if (\n options.__uniApp\n && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n && !clean.endsWith('.vue')\n ) {\n const transformed = transformUniAppSource(code, { filename: clean, target: 'h5' })\n if (transformed.changed) {\n code = transformed.code\n uniAppTransformed = true\n }\n }\n\n if (\n hasQuery(id, TEMPLATE_QUERY)\n || hasWxsQuery(id)\n || hasQuery(id, STYLE_QUERY)\n || hasQuery(id, SFC_TEMPLATE_QUERY)\n || hasQuery(id, SFC_STYLE_QUERY)\n ) {\n return null\n }\n\n if (clean.endsWith('.vue')) {\n const normalized = normalizePath(clean)\n const meta = state.moduleMeta.get(normalized) ?? {\n kind: 'component' as const,\n id: getStableWebComponentId(clean, srcRoot),\n scriptPath: clean,\n sourceType: 'vue-sfc' as const,\n }\n state.moduleMeta.set(normalized, meta)\n const result = await ensureWebVueSfcResult({\n filename: clean,\n meta,\n srcRoot,\n state,\n source: code,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n stylePreprocessOptions,\n })\n return transformWebVueSfcScript({\n code: result.script!,\n filename: clean,\n meta,\n runtimeModuleId: runtimeProvider?.moduleId ?? toViteFsImport(resolveRuntimePolyfillPath()),\n styleLanguage: resolveWebVueSfcStyleLanguage(result, clean),\n enableHmr,\n hmrAcceptCode,\n })\n }\n\n if (isTemplateFile(clean)) {\n if (isHtmlEntry(clean, root)) {\n return null\n }\n const normalizedId = normalizePath(clean)\n if (state.templatePathSet.size > 0) {\n if (!isInsideDir(clean, srcRoot)) {\n return null\n }\n if (!state.templatePathSet.has(normalizedId)) {\n return null\n }\n }\n let templateSource = code\n const pageMeta = resolveMetaByTemplate(clean)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n templateSource = wrapPageTemplate(code, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizedId)\n const componentTags = state.templateComponentMap.get(normalizedId)\n const { code: compiled, dependencies, warnings } = compileWxml({\n id: clean,\n source: templateSource,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (isWxsFile(clean) || hasWxsQuery(id)) {\n const { code: compiled, dependencies, warnings } = transformWxsToEsm(code, clean, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (TRANSFORM_STYLE_EXTS.some(ext => clean.endsWith(ext))) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return {\n code: createInlineStyleModule(css),\n map: null,\n }\n }\n\n if (STYLE_EXTS.some(ext => clean.endsWith(ext)) && !clean.endsWith('.wxss')) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return { code: css, map: null }\n }\n\n if (!SCRIPT_EXTS.some(ext => clean.endsWith(ext))) {\n return uniAppTransformed ? { code, map: null } : null\n }\n if (clean.includes('node_modules') && !hasQuery(id, WEB_COMPONENT_QUERY)) {\n return options.__uniApp && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n ? { code, map: null }\n : null\n }\n\n const meta = state.moduleMeta.get(normalizePath(clean))\n if (!meta) {\n return null\n }\n\n return transformScriptModule({\n code,\n cleanId: clean,\n meta,\n enableHmr,\n runtimeModuleId: runtimeProvider?.moduleId,\n hmrAcceptCode,\n })\n },\n }\n}\n\nexport type { WeappWebPluginOptions } from './types'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,yBAAyB;CAC7B;CACA;CACA;AACF;AAEA,MAAM,0BAA0B,CAAC,UAAU,uBAAuB;AAElE,SAAS,eAAe,IAAY;CAClC,MAAM,QAAQ,GAAG,YAAY;CAC7B,OAAO,cAAc,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AACtD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,GAAG,CAAC,KAAK,CAAC,MAAM,SAAS,OAAO,GAAG;IAC3E,MAAM,EAAE,QAAQ,mBAAmB,MAAM,WAAW;IACpD,OAAO;KAAE,MAAM;KAAK,KAAK;IAAK;GAChC;GAEA,IAAI,CAAC,YAAY,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,GAC9C,OAAO,oBAAoB;IAAE;IAAM,KAAK;GAAK,IAAI;GAEnD,IAAI,MAAM,SAAS,cAAc,KAAK,CAAC,SAAS,yBAAuB,GACrE,OAAO,QAAQ,YAAY,0BAA0B,OAAO,SAAS,QAAQ,SAAS,OAAO,IACzF;IAAE;IAAM,KAAK;GAAK,IAClB;GAGN,MAAM,OAAO,MAAM,WAAW,IAAI,cAAc,KAAK,CAAC;GACtD,IAAI,CAAC,MACH,OAAO;GAGT,OAAO,sBAAsB;IAC3B;IACA,SAAS;IACT;IACA;IACA,iBAAiB,iBAAiB;IAClC;GACF,CAAC;EACH;CACF;AACF"}
|
package/dist/plugin/sfcHmr.mjs
CHANGED
|
@@ -2,18 +2,37 @@ import { normalizePath } from "./path.mjs";
|
|
|
2
2
|
import { resolveWebVueSfcStyleLanguage } from "./vueSfc.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin/sfcHmr.ts
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function reachesSfcOwner(module, owners) {
|
|
6
|
+
const pending = [module];
|
|
7
|
+
const visited = /* @__PURE__ */ new Set();
|
|
8
|
+
while (pending.length) {
|
|
9
|
+
const current = pending.pop();
|
|
10
|
+
if (owners.has(current)) return true;
|
|
11
|
+
if (!visited.has(current)) {
|
|
12
|
+
visited.add(current);
|
|
13
|
+
pending.push(...current.importers);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
/** 只将仍连接到 SFC 注册模块的派生节点交给 Vite,避免删除恢复后旧节点触发额外刷新。 */
|
|
19
|
+
function collectSfcHmrModules(states, changedFile, graph, modules) {
|
|
7
20
|
const changed = normalizePath(changedFile);
|
|
8
|
-
const
|
|
9
|
-
|
|
21
|
+
const owners = /* @__PURE__ */ new Set();
|
|
22
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const state of states) for (const [filename, result] of state.sfcResults) {
|
|
10
24
|
if (filename !== changed && !result.meta?.sfcSrcDeps?.some((dependency) => normalizePath(dependency) === changed)) continue;
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
for (const file of [filename, `${filename}.${resolveWebVueSfcStyleLanguage(result, filename)}`]) for (const module of graph.getModulesByFile(file) ?? []) {
|
|
26
|
+
candidates.add(module);
|
|
27
|
+
if (module.id && normalizePath(module.id) === filename) owners.add(module);
|
|
28
|
+
}
|
|
13
29
|
}
|
|
14
|
-
|
|
30
|
+
const affected = new Set(modules);
|
|
31
|
+
for (const module of candidates) if (reachesSfcOwner(module, owners)) affected.add(module);
|
|
32
|
+
else affected.delete(module);
|
|
33
|
+
return [...affected];
|
|
15
34
|
}
|
|
16
35
|
|
|
17
36
|
//#endregion
|
|
18
|
-
export {
|
|
37
|
+
export { collectSfcHmrModules };
|
|
19
38
|
//# sourceMappingURL=sfcHmr.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sfcHmr.mjs","names":[],"sources":["../../src/plugin/sfcHmr.ts"],"sourcesContent":["import type { ScanState } from './types'\nimport { normalizePath } from './path'\nimport { resolveWebVueSfcStyleLanguage } from './vueSfc'\n\n/**
|
|
1
|
+
{"version":3,"file":"sfcHmr.mjs","names":[],"sources":["../../src/plugin/sfcHmr.ts"],"sourcesContent":["import type { ModuleNode } from 'vite'\nimport type { WebDevServer } from './hostTypes'\nimport type { ScanState } from './types'\nimport { normalizePath } from './path'\nimport { resolveWebVueSfcStyleLanguage } from './vueSfc'\n\nfunction reachesSfcOwner(module: ModuleNode, owners: Set<ModuleNode>) {\n const pending = [module]\n const visited = new Set<ModuleNode>()\n while (pending.length) {\n const current = pending.pop()!\n if (owners.has(current)) {\n return true\n }\n if (!visited.has(current)) {\n visited.add(current)\n pending.push(...current.importers)\n }\n }\n return false\n}\n\n/** 只将仍连接到 SFC 注册模块的派生节点交给 Vite,避免删除恢复后旧节点触发额外刷新。 */\nexport function collectSfcHmrModules<Module extends object>(\n states: readonly ScanState[],\n changedFile: string,\n graph: NonNullable<WebDevServer['moduleGraph']>,\n modules?: Module[],\n) {\n const changed = normalizePath(changedFile)\n const owners = new Set<ModuleNode>()\n const candidates = new Set<ModuleNode>()\n for (const state of states) {\n for (const [filename, result] of state.sfcResults) {\n if (filename !== changed && !result.meta?.sfcSrcDeps?.some(dependency => normalizePath(dependency) === changed)) {\n continue\n }\n for (const file of [filename, `${filename}.${resolveWebVueSfcStyleLanguage(result, filename)}`]) {\n for (const module of graph.getModulesByFile(file) ?? []) {\n candidates.add(module)\n if (module.id && normalizePath(module.id) === filename) {\n owners.add(module)\n }\n }\n }\n }\n }\n const affected = new Set(modules)\n for (const module of candidates) {\n // Vite 的 unlink 会拆除反向依赖,但保留旧文件节点;仅有节点身份不能证明它仍属于当前 SFC。\n if (reachesSfcOwner(module, owners)) {\n affected.add(module as Module)\n }\n else {\n affected.delete(module as Module)\n }\n }\n return [...affected]\n}\n"],"mappings":";;;;AAMA,SAAS,gBAAgB,QAAoB,QAAyB;CACpE,MAAM,UAAU,CAAC,MAAM;CACvB,MAAM,0BAAU,IAAI,IAAgB;CACpC,OAAO,QAAQ,QAAQ;EACrB,MAAM,UAAU,QAAQ,IAAI;EAC5B,IAAI,OAAO,IAAI,OAAO,GACpB,OAAO;EAET,IAAI,CAAC,QAAQ,IAAI,OAAO,GAAG;GACzB,QAAQ,IAAI,OAAO;GACnB,QAAQ,KAAK,GAAG,QAAQ,SAAS;EACnC;CACF;CACA,OAAO;AACT;;AAGA,SAAgB,qBACd,QACA,aACA,OACA,SACA;CACA,MAAM,UAAU,cAAc,WAAW;CACzC,MAAM,yBAAS,IAAI,IAAgB;CACnC,MAAM,6BAAa,IAAI,IAAgB;CACvC,KAAK,MAAM,SAAS,QAClB,KAAK,MAAM,CAAC,UAAU,WAAW,MAAM,YAAY;EACjD,IAAI,aAAa,WAAW,CAAC,OAAO,MAAM,YAAY,MAAK,eAAc,cAAc,UAAU,MAAM,OAAO,GAC5G;EAEF,KAAK,MAAM,QAAQ,CAAC,UAAU,GAAG,SAAS,GAAG,8BAA8B,QAAQ,QAAQ,GAAG,GAC5F,KAAK,MAAM,UAAU,MAAM,iBAAiB,IAAI,KAAK,CAAC,GAAG;GACvD,WAAW,IAAI,MAAM;GACrB,IAAI,OAAO,MAAM,cAAc,OAAO,EAAE,MAAM,UAC5C,OAAO,IAAI,MAAM;EAErB;CAEJ;CAEF,MAAM,WAAW,IAAI,IAAI,OAAO;CAChC,KAAK,MAAM,UAAU,YAEnB,IAAI,gBAAgB,QAAQ,MAAM,GAChC,SAAS,IAAI,MAAgB;MAG7B,SAAS,OAAO,MAAgB;CAGpC,OAAO,CAAC,GAAG,QAAQ;AACrB"}
|
|
@@ -13,4 +13,5 @@ declare class RuntimeEventBindingDirective extends AsyncDirective {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const bindRuntimeEvent: (_eventName: string, _listener: EventListener, _flags?: RuntimeEventFlags | undefined) => import("lit/async-directive.js").DirectiveResult<typeof RuntimeEventBindingDirective>;
|
|
15
15
|
//#endregion
|
|
16
|
+
export {};
|
|
16
17
|
//# sourceMappingURL=eventBinding.d.mts.map
|
|
@@ -23,7 +23,6 @@ import { WeappPickerView } from "./pickerView/index.mjs";
|
|
|
23
23
|
import { createProgressActiveEndDetail, resolveProgressAnimationDuration, resolveProgressConfig } from "./progress/helpers.mjs";
|
|
24
24
|
import { WeappProgress } from "./progress/index.mjs";
|
|
25
25
|
import { WeappRadio, WeappRadioGroup, collectRadioGroupValue } from "./radio.mjs";
|
|
26
|
-
import { normalizeRichTextNodes, sanitizeRichTextAttributes, sanitizeRichTextStyle } from "./richText/helpers.mjs";
|
|
27
26
|
import { WeappRichText } from "./richText/index.mjs";
|
|
28
27
|
import { WeappScrollView, createScrollEventDetail } from "./scrollView.mjs";
|
|
29
28
|
import { createSliderEventDetail, resolveSliderConfig } from "./slider/helpers.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/index.ts"],"sourcesContent":["import type { NativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_DESCRIPTORS } from '../../shared/nativeComponents'\nimport { WeappButton } from '../button'\nimport { WeappCanvas } from './canvas'\nimport { WeappCheckbox, WeappCheckboxGroup } from './checkbox'\nimport { WeappCoverImage, WeappCoverView } from './cover'\nimport { WeappForm } from './form'\nimport { WeappIcon } from './icon'\nimport { WeappImage } from './image'\nimport { WeappInput } from './input'\nimport { WeappLabel } from './label'\nimport { WeappMovableArea, WeappMovableView } from './movable'\nimport { WeappNavigator } from './navigator'\nimport { WeappPicker } from './picker'\nimport { WeappPickerView, WeappPickerViewColumn } from './pickerView'\nimport { WeappText, WeappView } from './primitives'\nimport { WeappProgress } from './progress'\nimport { WeappRadio, WeappRadioGroup } from './radio'\nimport { WeappRichText } from './richText'\nimport { WeappScrollView } from './scrollView'\nimport { WeappSlider } from './slider'\nimport { WeappSwiper } from './swiper'\nimport { WeappSwiperItem } from './swiper/item'\nimport { WeappSwitch } from './switch'\nimport { WeappTextarea } from './textarea'\nimport { WeappVideo } from './video'\n\nconst constructors = {\n 'weapp-view': WeappView,\n 'weapp-text': WeappText,\n 'weapp-image': WeappImage,\n 'weapp-button': WeappButton,\n 'weapp-input': WeappInput,\n 'weapp-textarea': WeappTextarea,\n 'weapp-form': WeappForm,\n 'weapp-label': WeappLabel,\n 'weapp-checkbox-group': WeappCheckboxGroup,\n 'weapp-checkbox': WeappCheckbox,\n 'weapp-radio-group': WeappRadioGroup,\n 'weapp-radio': WeappRadio,\n 'weapp-switch': WeappSwitch,\n 'weapp-picker': WeappPicker,\n 'weapp-picker-view': WeappPickerView,\n 'weapp-picker-view-column': WeappPickerViewColumn,\n 'weapp-slider': WeappSlider,\n 'weapp-icon': WeappIcon,\n 'weapp-progress': WeappProgress,\n 'weapp-rich-text': WeappRichText,\n 'weapp-scroll-view': WeappScrollView,\n 'weapp-navigator': WeappNavigator,\n 'weapp-swiper': WeappSwiper,\n 'weapp-swiper-item': WeappSwiperItem,\n 'weapp-canvas': WeappCanvas,\n 'weapp-video': WeappVideo,\n 'weapp-cover-view': WeappCoverView,\n 'weapp-cover-image': WeappCoverImage,\n 'weapp-movable-area': WeappMovableArea,\n 'weapp-movable-view': WeappMovableView,\n} satisfies Record<NativeComponentWebTag, CustomElementConstructor>\n\nexport function ensureNativeComponentsDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n for (const descriptor of NATIVE_COMPONENT_DESCRIPTORS) {\n if (customElements.get(descriptor.webTag)) {\n continue\n }\n const constructor = constructors[descriptor.webTag]\n customElements.define(descriptor.webTag, constructor)\n }\n}\n\nexport { collectCheckboxGroupValue } from './checkbox'\nexport { collectFormControlValues } from './formControl'\nexport { resolveIconColor, resolveIconSize, resolveIconType } from './icon/helpers'\nexport { resolveImageModeStyle } from './image'\nexport { createInputEventDetail } from './input'\nexport { clampMovablePosition, resolveMovableDirection } from './movable/helpers'\nexport {\n createPickerChangeDetail,\n normalizePickerIndexes,\n resolvePickerColumns,\n resolvePickerMode,\n} from './picker/helpers'\nexport { normalizePickerViewValue } from './pickerView/helpers'\nexport {\n createProgressActiveEndDetail,\n resolveProgressAnimationDuration,\n resolveProgressConfig,\n} from './progress/helpers'\nexport { collectRadioGroupValue } from './radio'\nexport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/index.ts"],"sourcesContent":["import type { NativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_DESCRIPTORS } from '../../shared/nativeComponents'\nimport { WeappButton } from '../button'\nimport { WeappCanvas } from './canvas'\nimport { WeappCheckbox, WeappCheckboxGroup } from './checkbox'\nimport { WeappCoverImage, WeappCoverView } from './cover'\nimport { WeappForm } from './form'\nimport { WeappIcon } from './icon'\nimport { WeappImage } from './image'\nimport { WeappInput } from './input'\nimport { WeappLabel } from './label'\nimport { WeappMovableArea, WeappMovableView } from './movable'\nimport { WeappNavigator } from './navigator'\nimport { WeappPicker } from './picker'\nimport { WeappPickerView, WeappPickerViewColumn } from './pickerView'\nimport { WeappText, WeappView } from './primitives'\nimport { WeappProgress } from './progress'\nimport { WeappRadio, WeappRadioGroup } from './radio'\nimport { WeappRichText } from './richText'\nimport { WeappScrollView } from './scrollView'\nimport { WeappSlider } from './slider'\nimport { WeappSwiper } from './swiper'\nimport { WeappSwiperItem } from './swiper/item'\nimport { WeappSwitch } from './switch'\nimport { WeappTextarea } from './textarea'\nimport { WeappVideo } from './video'\n\nconst constructors = {\n 'weapp-view': WeappView,\n 'weapp-text': WeappText,\n 'weapp-image': WeappImage,\n 'weapp-button': WeappButton,\n 'weapp-input': WeappInput,\n 'weapp-textarea': WeappTextarea,\n 'weapp-form': WeappForm,\n 'weapp-label': WeappLabel,\n 'weapp-checkbox-group': WeappCheckboxGroup,\n 'weapp-checkbox': WeappCheckbox,\n 'weapp-radio-group': WeappRadioGroup,\n 'weapp-radio': WeappRadio,\n 'weapp-switch': WeappSwitch,\n 'weapp-picker': WeappPicker,\n 'weapp-picker-view': WeappPickerView,\n 'weapp-picker-view-column': WeappPickerViewColumn,\n 'weapp-slider': WeappSlider,\n 'weapp-icon': WeappIcon,\n 'weapp-progress': WeappProgress,\n 'weapp-rich-text': WeappRichText,\n 'weapp-scroll-view': WeappScrollView,\n 'weapp-navigator': WeappNavigator,\n 'weapp-swiper': WeappSwiper,\n 'weapp-swiper-item': WeappSwiperItem,\n 'weapp-canvas': WeappCanvas,\n 'weapp-video': WeappVideo,\n 'weapp-cover-view': WeappCoverView,\n 'weapp-cover-image': WeappCoverImage,\n 'weapp-movable-area': WeappMovableArea,\n 'weapp-movable-view': WeappMovableView,\n} satisfies Record<NativeComponentWebTag, CustomElementConstructor>\n\nexport function ensureNativeComponentsDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n for (const descriptor of NATIVE_COMPONENT_DESCRIPTORS) {\n if (customElements.get(descriptor.webTag)) {\n continue\n }\n const constructor = constructors[descriptor.webTag]\n customElements.define(descriptor.webTag, constructor)\n }\n}\n\nexport { collectCheckboxGroupValue } from './checkbox'\nexport { collectFormControlValues } from './formControl'\nexport { resolveIconColor, resolveIconSize, resolveIconType } from './icon/helpers'\nexport { resolveImageModeStyle } from './image'\nexport { createInputEventDetail } from './input'\nexport { clampMovablePosition, resolveMovableDirection } from './movable/helpers'\nexport {\n createPickerChangeDetail,\n normalizePickerIndexes,\n resolvePickerColumns,\n resolvePickerMode,\n} from './picker/helpers'\nexport { normalizePickerViewValue } from './pickerView/helpers'\nexport {\n createProgressActiveEndDetail,\n resolveProgressAnimationDuration,\n resolveProgressConfig,\n} from './progress/helpers'\nexport { collectRadioGroupValue } from './radio'\nexport { createScrollEventDetail } from './scrollView'\nexport { createSliderEventDetail, resolveSliderConfig } from './slider/helpers'\nexport { NATIVE_COMPONENT_STYLE } from './style'\nexport {\n createSwiperChangeDetail,\n resolveSwiperIndex,\n resolveSwiperNumber,\n resolveSwipeTarget,\n} from './swiper/helpers'\nexport { createSwitchEventDetail } from './switch'\nexport { createTextareaLineChangeDetail } from './textarea'\nexport {\n createVideoProgressDetail,\n createVideoTimeUpdateDetail,\n resolveVideoObjectFit,\n} from './video/helpers'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,eAAe;CACnB,cAAc;CACd,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,cAAc;CACd,eAAe;CACf,wBAAwB;CACxB,kBAAkB;CAClB,qBAAqB;CACrB,eAAe;CACf,gBAAgB;CAChB,gBAAgB;CAChB,qBAAqB;CACrB,4BAA4B;CAC5B,gBAAgB;CAChB,cAAc;CACd,kBAAkB;CAClB,mBAAmB;CACnB,qBAAqB;CACrB,mBAAmB;CACnB,gBAAgB;CAChB,qBAAqB;CACrB,gBAAgB;CAChB,eAAe;CACf,oBAAoB;CACpB,qBAAqB;CACrB,sBAAsB;CACtB,sBAAsB;AACxB;AAEA,SAAgB,gCAAgC;CAC9C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,KAAK,MAAM,cAAc,8BAA8B;EACrD,IAAI,eAAe,IAAI,WAAW,MAAM,GACtC;EAEF,MAAM,cAAc,aAAa,WAAW;EAC5C,eAAe,OAAO,WAAW,QAAQ,WAAW;CACtD;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getNativeComponentDescriptor } from "../../../shared/nativeComponents.mjs";
|
|
2
2
|
import { readBooleanAttribute, resolveContainingShadowRoot } from "../helpers.mjs";
|
|
3
3
|
import { ensureNativeComponentStyle } from "../style.mjs";
|
|
4
|
-
import { normalizeRichTextNodes
|
|
4
|
+
import { normalizeRichTextNodes } from "@weapp-core/shared/rich-text";
|
|
5
5
|
|
|
6
6
|
//#region src/runtime/nativeComponents/richText/index.ts
|
|
7
7
|
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
@@ -70,5 +70,5 @@ var WeappRichText = class extends BaseElement {
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
//#endregion
|
|
73
|
-
export { WeappRichText
|
|
73
|
+
export { WeappRichText };
|
|
74
74
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/richText/index.ts"],"sourcesContent":["import type { SafeRichTextNode } from '
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/richText/index.ts"],"sourcesContent":["import type { SafeRichTextNode } from '@weapp-core/shared/rich-text'\nimport { normalizeRichTextNodes } from '@weapp-core/shared/rich-text'\nimport { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { readBooleanAttribute, resolveContainingShadowRoot } from '../helpers'\nimport { ensureNativeComponentStyle } from '../style'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nfunction createRichTextDomNode(node: SafeRichTextNode): globalThis.Node {\n if (node.type === 'text') {\n return document.createTextNode(node.text)\n }\n const element = document.createElement(node.name)\n for (const [name, value] of Object.entries(node.attrs)) {\n element.setAttribute(name, value)\n }\n element.append(...node.children.map(createRichTextDomNode))\n return element\n}\n\nexport class WeappRichText extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('rich-text')!.attributes]\n\n #content?: HTMLDivElement\n #nodes: unknown = ''\n\n get nodes() {\n return this.#nodes\n }\n\n set nodes(value: unknown) {\n if (Object.is(this.#nodes, value)) {\n return\n }\n this.#nodes = value\n this.#renderNodes()\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n if (this.#nodes === '') {\n this.#nodes = this.getAttribute('nodes') ?? ''\n }\n this.#syncAttributes()\n this.#renderNodes()\n }\n\n attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {\n if (name === 'nodes') {\n this.#nodes = newValue ?? ''\n this.#renderNodes()\n return\n }\n this.#syncAttributes()\n }\n\n #ensureStructure() {\n if (this.#content || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = `\n :host { overflow-wrap: break-word; }\n .content { display: block; min-width: 0; }\n img { max-width: 100%; }\n `\n const content = document.createElement('div')\n content.className = 'content'\n content.addEventListener('click', (event) => {\n const target = event.target\n if (target instanceof Element && target.closest('a')) {\n event.preventDefault()\n }\n })\n root.append(style, content)\n this.#content = content\n }\n\n #syncAttributes() {\n if (!this.#content) {\n return\n }\n const space = this.getAttribute('space')\n this.#content.style.whiteSpace = space === 'nbsp' || space === 'ensp' || space === 'emsp'\n ? 'pre-wrap'\n : 'normal'\n this.#content.style.userSelect = readBooleanAttribute(this, 'user-select') ? 'text' : ''\n }\n\n #renderNodes() {\n if (!this.#content || typeof document === 'undefined') {\n return\n }\n this.#content.replaceChildren(...normalizeRichTextNodes(this.#nodes).map(createRichTextDomNode))\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AAEtD,SAAS,sBAAsB,MAAyC;CACtE,IAAI,KAAK,SAAS,QAChB,OAAO,SAAS,eAAe,KAAK,IAAI;CAE1C,MAAM,UAAU,SAAS,cAAc,KAAK,IAAI;CAChD,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,KAAK,GACnD,QAAQ,aAAa,MAAM,KAAK;CAElC,QAAQ,OAAO,GAAG,KAAK,SAAS,IAAI,qBAAqB,CAAC;CAC1D,OAAO;AACT;AAEA,IAAa,gBAAb,cAAmC,YAAY;CAC7C,OAAO,qBAAqB,CAAC,GAAG,6BAA6B,WAAW,CAAC,CAAE,UAAU;CAErF;CACA,SAAkB;CAElB,IAAI,QAAQ;EACV,OAAO,KAAK;CACd;CAEA,IAAI,MAAM,OAAgB;EACxB,IAAI,OAAO,GAAG,KAAK,QAAQ,KAAK,GAC9B;EAEF,KAAK,SAAS;EACd,KAAK,aAAa;CACpB;CAEA,oBAAoB;EAClB,2BAA2B,4BAA4B,IAAI,CAAC;EAC5D,KAAK,iBAAiB;EACtB,IAAI,KAAK,WAAW,IAClB,KAAK,SAAS,KAAK,aAAa,OAAO,KAAK;EAE9C,KAAK,gBAAgB;EACrB,KAAK,aAAa;CACpB;CAEA,yBAAyB,MAAc,WAA0B,UAAyB;EACxF,IAAI,SAAS,SAAS;GACpB,KAAK,SAAS,YAAY;GAC1B,KAAK,aAAa;GAClB;EACF;EACA,KAAK,gBAAgB;CACvB;CAEA,mBAAmB;EACjB,IAAI,KAAK,YAAY,OAAO,aAAa,aACvC;EAEF,MAAM,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAClE,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;;;;;EAKpB,MAAM,UAAU,SAAS,cAAc,KAAK;EAC5C,QAAQ,YAAY;EACpB,QAAQ,iBAAiB,UAAU,UAAU;GAC3C,MAAM,SAAS,MAAM;GACrB,IAAI,kBAAkB,WAAW,OAAO,QAAQ,GAAG,GACjD,MAAM,eAAe;EAEzB,CAAC;EACD,KAAK,OAAO,OAAO,OAAO;EAC1B,KAAK,WAAW;CAClB;CAEA,kBAAkB;EAChB,IAAI,CAAC,KAAK,UACR;EAEF,MAAM,QAAQ,KAAK,aAAa,OAAO;EACvC,KAAK,SAAS,MAAM,aAAa,UAAU,UAAU,UAAU,UAAU,UAAU,SAC/E,aACA;EACJ,KAAK,SAAS,MAAM,aAAa,qBAAqB,MAAM,aAAa,IAAI,SAAS;CACxF;CAEA,eAAe;EACb,IAAI,CAAC,KAAK,YAAY,OAAO,aAAa,aACxC;EAEF,KAAK,SAAS,gBAAgB,GAAG,uBAAuB,KAAK,MAAM,CAAC,CAAC,IAAI,qBAAqB,CAAC;CACjG;AACF"}
|
|
@@ -5,4 +5,5 @@ type ResolveTypedPageLayoutProps<Name extends string> = Name extends keyof WevuP
|
|
|
5
5
|
export declare function setPageLayout(layout: false): void;
|
|
6
6
|
export declare function setPageLayout<Name extends ResolveTypedPageLayoutName>(layout: Name, props?: ResolveTypedPageLayoutProps<Name>): void;
|
|
7
7
|
//#endregion
|
|
8
|
+
export {};
|
|
8
9
|
//# sourceMappingURL=pageLayout.d.mts.map
|
|
@@ -16,8 +16,8 @@ import { clearStorage, clearStorageSync, createCanvasContext, createIntersection
|
|
|
16
16
|
import { offAppRoute, offAppRouteDone, offBeforeAppRoute, offBeforePageUnload, onAppRoute, onAppRouteDone, onBeforeAppRoute, onBeforePageUnload } from "./routeRuntime/events.mjs";
|
|
17
17
|
import { getAppInstance, getCurrentPagesInternal, getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, offAppHide, offAppShow, onAppHide, onAppShow, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./routeRuntime.mjs";
|
|
18
18
|
import { chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, compressImage, compressVideo, getClipboardData, getImageInfo, getVideoInfo, hideLoading, hideTabBar, hideTabBarRedDot, makePhoneCall, openCustomerServiceChat, openDocument, openLocation, openVideoEditor, previewImage, previewMedia, removeTabBarBadge, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setClipboardData, setTabBarBadge, setTabBarItem, setTabBarStyle, showActionSheet, showLoading, showModal, showShareMenu, showTabBar, showTabBarRedDot, showToast, uiMediaApi_exports, updateShareMenu } from "./uiMediaApi.mjs";
|
|
19
|
-
import { getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys } from "@weapp-core/shared/platforms/runtime";
|
|
20
19
|
import { WEVU_PAGE_SCROLL_EVENT_CONTRACT_KEY, WEVU_PAGE_SCROLL_RESTORATION_OWNER_KEY, WEVU_ROUTE_EVENT_CONTRACT_KEY } from "@weapp-core/constants";
|
|
20
|
+
import { getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys } from "@weapp-core/shared/platforms/runtime";
|
|
21
21
|
|
|
22
22
|
//#region src/runtime/polyfill/index.ts
|
|
23
23
|
const MINI_PROGRAM_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys();
|
|
@@ -45,4 +45,5 @@ export interface NavigateBackOptions extends MiniProgramAsyncOptions<MiniProgram
|
|
|
45
45
|
export type PageRawOptions = ComponentOptions & PageHooks & Record<string, unknown>;
|
|
46
46
|
export type ComponentRawOptions = ComponentOptions & Record<string, unknown>;
|
|
47
47
|
//#endregion
|
|
48
|
+
export {};
|
|
48
49
|
//# sourceMappingURL=options.d.mts.map
|
package/dist/runtime/wevu.d.mts
CHANGED
|
@@ -20,4 +20,5 @@ export declare function registerWebWevuComponentFactory<TArgs extends unknown[],
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function installWebModuleRegistration(meta: WevuRegisterMeta, target?: Record<string, any>): () => void;
|
|
22
22
|
//#endregion
|
|
23
|
+
export {};
|
|
23
24
|
//# sourceMappingURL=wevu.d.mts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/web",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"description": "Experimental web runtime for weapp-vite templates",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -65,23 +65,23 @@
|
|
|
65
65
|
"@babel/parser": "^8.0.7",
|
|
66
66
|
"@babel/traverse": "^8.0.7",
|
|
67
67
|
"@babel/types": "^8.0.6",
|
|
68
|
-
"@weapp-core/constants": "0.
|
|
69
|
-
"@weapp-core/shared": "3.
|
|
68
|
+
"@weapp-core/constants": "0.4.0",
|
|
69
|
+
"@weapp-core/shared": "3.3.0",
|
|
70
70
|
"domhandler": "^6.0.1",
|
|
71
71
|
"esbuild": "^0.28.2",
|
|
72
72
|
"htmlparser2": "^12.0.0",
|
|
73
73
|
"lit": "^3.3.3",
|
|
74
74
|
"magic-string": "^1.4.3",
|
|
75
75
|
"pathe": "^2.0.3",
|
|
76
|
-
"postcss": "^8.5.
|
|
76
|
+
"postcss": "^8.5.30",
|
|
77
77
|
"postcss-selector-parser": "^7.1.6",
|
|
78
|
-
"rolldown": "1.2.
|
|
79
|
-
"rolldown-require": "2.0.
|
|
78
|
+
"rolldown": "1.2.14",
|
|
79
|
+
"rolldown-require": "2.0.36",
|
|
80
80
|
"vite": "8.3.4",
|
|
81
|
-
"wevu": "7.
|
|
81
|
+
"wevu": "7.6.0"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"happy-dom": "^
|
|
84
|
+
"happy-dom": "^21.0.3"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public",
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { parseDocument } from "htmlparser2";
|
|
2
|
-
|
|
3
|
-
//#region src/runtime/nativeComponents/richText/helpers.ts
|
|
4
|
-
const ALLOWED_TAGS = /* @__PURE__ */ new Set([
|
|
5
|
-
"a",
|
|
6
|
-
"abbr",
|
|
7
|
-
"address",
|
|
8
|
-
"article",
|
|
9
|
-
"aside",
|
|
10
|
-
"b",
|
|
11
|
-
"bdi",
|
|
12
|
-
"bdo",
|
|
13
|
-
"big",
|
|
14
|
-
"blockquote",
|
|
15
|
-
"br",
|
|
16
|
-
"caption",
|
|
17
|
-
"center",
|
|
18
|
-
"cite",
|
|
19
|
-
"code",
|
|
20
|
-
"col",
|
|
21
|
-
"colgroup",
|
|
22
|
-
"dd",
|
|
23
|
-
"del",
|
|
24
|
-
"div",
|
|
25
|
-
"dl",
|
|
26
|
-
"dt",
|
|
27
|
-
"em",
|
|
28
|
-
"fieldset",
|
|
29
|
-
"font",
|
|
30
|
-
"h1",
|
|
31
|
-
"h2",
|
|
32
|
-
"h3",
|
|
33
|
-
"h4",
|
|
34
|
-
"h5",
|
|
35
|
-
"h6",
|
|
36
|
-
"header",
|
|
37
|
-
"hr",
|
|
38
|
-
"i",
|
|
39
|
-
"img",
|
|
40
|
-
"ins",
|
|
41
|
-
"label",
|
|
42
|
-
"legend",
|
|
43
|
-
"li",
|
|
44
|
-
"mark",
|
|
45
|
-
"ol",
|
|
46
|
-
"p",
|
|
47
|
-
"pre",
|
|
48
|
-
"q",
|
|
49
|
-
"rt",
|
|
50
|
-
"ruby",
|
|
51
|
-
"s",
|
|
52
|
-
"section",
|
|
53
|
-
"small",
|
|
54
|
-
"span",
|
|
55
|
-
"strong",
|
|
56
|
-
"sub",
|
|
57
|
-
"sup",
|
|
58
|
-
"table",
|
|
59
|
-
"tbody",
|
|
60
|
-
"td",
|
|
61
|
-
"tfoot",
|
|
62
|
-
"th",
|
|
63
|
-
"thead",
|
|
64
|
-
"tr",
|
|
65
|
-
"tt",
|
|
66
|
-
"u",
|
|
67
|
-
"ul"
|
|
68
|
-
]);
|
|
69
|
-
const ALLOWED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
70
|
-
"abbr",
|
|
71
|
-
"align",
|
|
72
|
-
"alt",
|
|
73
|
-
"axis",
|
|
74
|
-
"bgcolor",
|
|
75
|
-
"border",
|
|
76
|
-
"cellpadding",
|
|
77
|
-
"cellspacing",
|
|
78
|
-
"class",
|
|
79
|
-
"colspan",
|
|
80
|
-
"dir",
|
|
81
|
-
"height",
|
|
82
|
-
"href",
|
|
83
|
-
"id",
|
|
84
|
-
"lang",
|
|
85
|
-
"rowspan",
|
|
86
|
-
"scope",
|
|
87
|
-
"span",
|
|
88
|
-
"start",
|
|
89
|
-
"style",
|
|
90
|
-
"summary",
|
|
91
|
-
"target",
|
|
92
|
-
"title",
|
|
93
|
-
"type",
|
|
94
|
-
"valign",
|
|
95
|
-
"width"
|
|
96
|
-
]);
|
|
97
|
-
const URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src"]);
|
|
98
|
-
const ALLOWED_STYLE_PROPERTIES = /* @__PURE__ */ new Set([
|
|
99
|
-
"background",
|
|
100
|
-
"background-color",
|
|
101
|
-
"border",
|
|
102
|
-
"border-bottom",
|
|
103
|
-
"border-color",
|
|
104
|
-
"border-left",
|
|
105
|
-
"border-radius",
|
|
106
|
-
"border-right",
|
|
107
|
-
"border-style",
|
|
108
|
-
"border-top",
|
|
109
|
-
"border-width",
|
|
110
|
-
"color",
|
|
111
|
-
"display",
|
|
112
|
-
"font-family",
|
|
113
|
-
"font-size",
|
|
114
|
-
"font-style",
|
|
115
|
-
"font-weight",
|
|
116
|
-
"height",
|
|
117
|
-
"letter-spacing",
|
|
118
|
-
"line-height",
|
|
119
|
-
"margin",
|
|
120
|
-
"margin-bottom",
|
|
121
|
-
"margin-left",
|
|
122
|
-
"margin-right",
|
|
123
|
-
"margin-top",
|
|
124
|
-
"max-height",
|
|
125
|
-
"max-width",
|
|
126
|
-
"min-height",
|
|
127
|
-
"min-width",
|
|
128
|
-
"opacity",
|
|
129
|
-
"overflow",
|
|
130
|
-
"padding",
|
|
131
|
-
"padding-bottom",
|
|
132
|
-
"padding-left",
|
|
133
|
-
"padding-right",
|
|
134
|
-
"padding-top",
|
|
135
|
-
"text-align",
|
|
136
|
-
"text-decoration",
|
|
137
|
-
"text-indent",
|
|
138
|
-
"text-overflow",
|
|
139
|
-
"text-transform",
|
|
140
|
-
"vertical-align",
|
|
141
|
-
"white-space",
|
|
142
|
-
"width",
|
|
143
|
-
"word-break",
|
|
144
|
-
"word-wrap"
|
|
145
|
-
]);
|
|
146
|
-
function isRecord(value) {
|
|
147
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
148
|
-
}
|
|
149
|
-
function isSafeUrl(value, attribute) {
|
|
150
|
-
const normalized = Array.from(value).filter((character) => character.charCodeAt(0) > 32).join("").toLowerCase();
|
|
151
|
-
if (!normalized || normalized.startsWith("#") || normalized.startsWith("/") || normalized.startsWith("./") || normalized.startsWith("../")) return true;
|
|
152
|
-
if (/^(?:https?:|mailto:|tel:)/.test(normalized)) return true;
|
|
153
|
-
return attribute === "src" && /^data:image\/(?:gif|jpe?g|png|webp);base64,/.test(normalized);
|
|
154
|
-
}
|
|
155
|
-
function isSafeStyleValue(value) {
|
|
156
|
-
const normalized = value.toLowerCase().replace(/\s+/g, "");
|
|
157
|
-
return !normalized.includes("url(") && !normalized.includes("expression(") && !normalized.includes("javascript:") && !normalized.includes("behavior:") && !normalized.includes("-moz-binding");
|
|
158
|
-
}
|
|
159
|
-
function sanitizeRichTextStyle(value) {
|
|
160
|
-
const source = isRecord(value) ? Object.entries(value).map(([property, propertyValue]) => `${property}:${String(propertyValue)}`).join(";") : String(value ?? "");
|
|
161
|
-
const declarations = [];
|
|
162
|
-
for (const declaration of source.split(";")) {
|
|
163
|
-
const separator = declaration.indexOf(":");
|
|
164
|
-
if (separator <= 0) continue;
|
|
165
|
-
const property = declaration.slice(0, separator).trim().toLowerCase();
|
|
166
|
-
const propertyValue = declaration.slice(separator + 1).trim();
|
|
167
|
-
if (ALLOWED_STYLE_PROPERTIES.has(property) && propertyValue && isSafeStyleValue(propertyValue)) declarations.push(`${property}: ${propertyValue}`);
|
|
168
|
-
}
|
|
169
|
-
return declarations.join("; ");
|
|
170
|
-
}
|
|
171
|
-
function sanitizeRichTextAttributes(value, tagName) {
|
|
172
|
-
if (!isRecord(value)) return {};
|
|
173
|
-
const attributes = {};
|
|
174
|
-
for (const [rawName, rawValue] of Object.entries(value)) {
|
|
175
|
-
const name = rawName.trim().toLowerCase();
|
|
176
|
-
if (name.startsWith("on") || name === "srcdoc") continue;
|
|
177
|
-
if (!ALLOWED_ATTRIBUTES.has(name) && name !== "src" && !name.startsWith("aria-") && !name.startsWith("data-")) continue;
|
|
178
|
-
if (name === "src" && tagName !== "img") continue;
|
|
179
|
-
const serialized = name === "style" ? sanitizeRichTextStyle(rawValue) : String(rawValue ?? "");
|
|
180
|
-
if (!serialized || URL_ATTRIBUTES.has(name) && !isSafeUrl(serialized, name)) continue;
|
|
181
|
-
attributes[name] = serialized;
|
|
182
|
-
}
|
|
183
|
-
if (tagName === "a") attributes.rel = "noopener noreferrer";
|
|
184
|
-
return attributes;
|
|
185
|
-
}
|
|
186
|
-
function convertSourceNode(value) {
|
|
187
|
-
if (!isRecord(value)) return [];
|
|
188
|
-
if (value.type === "text" || !value.name && typeof value.text === "string") return [{
|
|
189
|
-
type: "text",
|
|
190
|
-
text: String(value.text ?? "")
|
|
191
|
-
}];
|
|
192
|
-
const children = Array.isArray(value.children) ? value.children.flatMap(convertSourceNode) : [];
|
|
193
|
-
const name = String(value.name ?? "").toLowerCase();
|
|
194
|
-
if (!ALLOWED_TAGS.has(name)) return children;
|
|
195
|
-
return [{
|
|
196
|
-
type: "element",
|
|
197
|
-
name,
|
|
198
|
-
attrs: sanitizeRichTextAttributes(value.attrs, name),
|
|
199
|
-
children
|
|
200
|
-
}];
|
|
201
|
-
}
|
|
202
|
-
function convertParsedNode(node) {
|
|
203
|
-
if (node.type === "text") return [{
|
|
204
|
-
type: "text",
|
|
205
|
-
text: node.data
|
|
206
|
-
}];
|
|
207
|
-
if (node.type !== "tag") return [];
|
|
208
|
-
const element = node;
|
|
209
|
-
const children = element.children.flatMap(convertParsedNode);
|
|
210
|
-
const name = element.name.toLowerCase();
|
|
211
|
-
if (!ALLOWED_TAGS.has(name)) return children;
|
|
212
|
-
return [{
|
|
213
|
-
type: "element",
|
|
214
|
-
name,
|
|
215
|
-
attrs: sanitizeRichTextAttributes(element.attribs, name),
|
|
216
|
-
children
|
|
217
|
-
}];
|
|
218
|
-
}
|
|
219
|
-
function normalizeRichTextNodes(value) {
|
|
220
|
-
if (typeof value === "string") return parseDocument(value, {
|
|
221
|
-
decodeEntities: true,
|
|
222
|
-
lowerCaseAttributeNames: true,
|
|
223
|
-
lowerCaseTags: true
|
|
224
|
-
}).children.flatMap(convertParsedNode);
|
|
225
|
-
return (Array.isArray(value) ? value : [value]).flatMap(convertSourceNode);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
//#endregion
|
|
229
|
-
export { normalizeRichTextNodes, sanitizeRichTextAttributes, sanitizeRichTextStyle };
|
|
230
|
-
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/richText/helpers.ts"],"sourcesContent":["import type { DataNode, Element, Node } from 'domhandler'\nimport { parseDocument } from 'htmlparser2'\n\nexport interface RichTextSourceNode {\n type?: string\n name?: string\n attrs?: Record<string, unknown>\n children?: RichTextSourceNode[]\n text?: string\n}\n\nexport type SafeRichTextNode\n = | { type: 'text', text: string }\n | { type: 'element', name: string, attrs: Record<string, string>, children: SafeRichTextNode[] }\n\nconst ALLOWED_TAGS = new Set([\n 'a',\n 'abbr',\n 'address',\n 'article',\n 'aside',\n 'b',\n 'bdi',\n 'bdo',\n 'big',\n 'blockquote',\n 'br',\n 'caption',\n 'center',\n 'cite',\n 'code',\n 'col',\n 'colgroup',\n 'dd',\n 'del',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'fieldset',\n 'font',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hr',\n 'i',\n 'img',\n 'ins',\n 'label',\n 'legend',\n 'li',\n 'mark',\n 'ol',\n 'p',\n 'pre',\n 'q',\n 'rt',\n 'ruby',\n 's',\n 'section',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'tfoot',\n 'th',\n 'thead',\n 'tr',\n 'tt',\n 'u',\n 'ul',\n])\n\nconst ALLOWED_ATTRIBUTES = new Set([\n 'abbr',\n 'align',\n 'alt',\n 'axis',\n 'bgcolor',\n 'border',\n 'cellpadding',\n 'cellspacing',\n 'class',\n 'colspan',\n 'dir',\n 'height',\n 'href',\n 'id',\n 'lang',\n 'rowspan',\n 'scope',\n 'span',\n 'start',\n 'style',\n 'summary',\n 'target',\n 'title',\n 'type',\n 'valign',\n 'width',\n])\n\nconst URL_ATTRIBUTES = new Set(['href', 'src'])\n\nconst ALLOWED_STYLE_PROPERTIES = new Set([\n 'background',\n 'background-color',\n 'border',\n 'border-bottom',\n 'border-color',\n 'border-left',\n 'border-radius',\n 'border-right',\n 'border-style',\n 'border-top',\n 'border-width',\n 'color',\n 'display',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'height',\n 'letter-spacing',\n 'line-height',\n 'margin',\n 'margin-bottom',\n 'margin-left',\n 'margin-right',\n 'margin-top',\n 'max-height',\n 'max-width',\n 'min-height',\n 'min-width',\n 'opacity',\n 'overflow',\n 'padding',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'padding-top',\n 'text-align',\n 'text-decoration',\n 'text-indent',\n 'text-overflow',\n 'text-transform',\n 'vertical-align',\n 'white-space',\n 'width',\n 'word-break',\n 'word-wrap',\n])\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction isSafeUrl(value: string, attribute: string) {\n const normalized = Array.from(value)\n .filter(character => character.charCodeAt(0) > 0x20)\n .join('')\n .toLowerCase()\n if (!normalized || normalized.startsWith('#') || normalized.startsWith('/') || normalized.startsWith('./') || normalized.startsWith('../')) {\n return true\n }\n if (/^(?:https?:|mailto:|tel:)/.test(normalized)) {\n return true\n }\n return attribute === 'src' && /^data:image\\/(?:gif|jpe?g|png|webp);base64,/.test(normalized)\n}\n\nfunction isSafeStyleValue(value: string) {\n const normalized = value.toLowerCase().replace(/\\s+/g, '')\n return !normalized.includes('url(')\n && !normalized.includes('expression(')\n && !normalized.includes('javascript:')\n && !normalized.includes('behavior:')\n && !normalized.includes('-moz-binding')\n}\n\nexport function sanitizeRichTextStyle(value: unknown) {\n const source = isRecord(value)\n ? Object.entries(value)\n .map(([property, propertyValue]) => `${property}:${String(propertyValue)}`)\n .join(';')\n : String(value ?? '')\n const declarations: string[] = []\n for (const declaration of source.split(';')) {\n const separator = declaration.indexOf(':')\n if (separator <= 0) {\n continue\n }\n const property = declaration.slice(0, separator).trim().toLowerCase()\n const propertyValue = declaration.slice(separator + 1).trim()\n if (ALLOWED_STYLE_PROPERTIES.has(property) && propertyValue && isSafeStyleValue(propertyValue)) {\n declarations.push(`${property}: ${propertyValue}`)\n }\n }\n return declarations.join('; ')\n}\n\nexport function sanitizeRichTextAttributes(value: unknown, tagName: string) {\n if (!isRecord(value)) {\n return {}\n }\n const attributes: Record<string, string> = {}\n for (const [rawName, rawValue] of Object.entries(value)) {\n const name = rawName.trim().toLowerCase()\n if (name.startsWith('on') || name === 'srcdoc') {\n continue\n }\n if (!ALLOWED_ATTRIBUTES.has(name) && name !== 'src' && !name.startsWith('aria-') && !name.startsWith('data-')) {\n continue\n }\n if (name === 'src' && tagName !== 'img') {\n continue\n }\n const serialized = name === 'style' ? sanitizeRichTextStyle(rawValue) : String(rawValue ?? '')\n if (!serialized || (URL_ATTRIBUTES.has(name) && !isSafeUrl(serialized, name))) {\n continue\n }\n attributes[name] = serialized\n }\n if (tagName === 'a') {\n attributes.rel = 'noopener noreferrer'\n }\n return attributes\n}\n\nfunction convertSourceNode(value: unknown): SafeRichTextNode[] {\n if (!isRecord(value)) {\n return []\n }\n if (value.type === 'text' || (!value.name && typeof value.text === 'string')) {\n return [{ type: 'text', text: String(value.text ?? '') }]\n }\n const children = Array.isArray(value.children)\n ? value.children.flatMap(convertSourceNode)\n : []\n const name = String(value.name ?? '').toLowerCase()\n if (!ALLOWED_TAGS.has(name)) {\n return children\n }\n return [{\n type: 'element',\n name,\n attrs: sanitizeRichTextAttributes(value.attrs, name),\n children,\n }]\n}\n\nfunction convertParsedNode(node: Node): SafeRichTextNode[] {\n if (node.type === 'text') {\n return [{ type: 'text', text: (node as DataNode).data }]\n }\n if (node.type !== 'tag') {\n return []\n }\n const element = node as Element\n const children = element.children.flatMap(convertParsedNode)\n const name = element.name.toLowerCase()\n if (!ALLOWED_TAGS.has(name)) {\n return children\n }\n return [{\n type: 'element',\n name,\n attrs: sanitizeRichTextAttributes(element.attribs, name),\n children,\n }]\n}\n\nexport function normalizeRichTextNodes(value: unknown): SafeRichTextNode[] {\n if (typeof value === 'string') {\n const document = parseDocument(value, {\n decodeEntities: true,\n lowerCaseAttributeNames: true,\n lowerCaseTags: true,\n })\n return document.children.flatMap(convertParsedNode)\n }\n const values = Array.isArray(value) ? value : [value]\n return values.flatMap(convertSourceNode)\n}\n"],"mappings":";;;AAeA,MAAM,+BAAe,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,qCAAqB,IAAI,IAAI;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,iCAAiB,IAAI,IAAI,CAAC,QAAQ,KAAK,CAAC;AAE9C,MAAM,2CAA2B,IAAI,IAAI;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,SAAS,OAAkD;CAClE,OAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,UAAU,OAAe,WAAmB;CACnD,MAAM,aAAa,MAAM,KAAK,KAAK,CAAC,CACjC,QAAO,cAAa,UAAU,WAAW,CAAC,IAAI,EAAI,CAAC,CACnD,KAAK,EAAE,CAAC,CACR,YAAY;CACf,IAAI,CAAC,cAAc,WAAW,WAAW,GAAG,KAAK,WAAW,WAAW,GAAG,KAAK,WAAW,WAAW,IAAI,KAAK,WAAW,WAAW,KAAK,GACvI,OAAO;CAET,IAAI,4BAA4B,KAAK,UAAU,GAC7C,OAAO;CAET,OAAO,cAAc,SAAS,8CAA8C,KAAK,UAAU;AAC7F;AAEA,SAAS,iBAAiB,OAAe;CACvC,MAAM,aAA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