@hia-doc/renderer-html 0.1.4 → 0.1.6
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/README.md +21 -4
- package/dist/index.d.ts +123 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +900 -221
- package/dist/index.js.map +1 -1
- package/dist/portal-ui-locale.d.ts +60 -0
- package/dist/portal-ui-locale.d.ts.map +1 -0
- package/dist/portal-ui-locale.js +278 -0
- package/dist/portal-ui-locale.js.map +1 -0
- package/dist/presentation-profile.d.ts +78 -0
- package/dist/presentation-profile.d.ts.map +1 -0
- package/dist/presentation-profile.js +242 -0
- package/dist/presentation-profile.js.map +1 -0
- package/dist/theme-assets.d.ts +31 -0
- package/dist/theme-assets.d.ts.map +1 -0
- package/dist/theme-assets.js +55 -0
- package/dist/theme-assets.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { DOCUMENTATION_PRESENTATION_PROFILE_CONTRACT, DOCUMENTATION_PRESENTATION_PROFILE_CONTRACT_VERSION, createHiaDiagnostic, validateDocumentationPresentationProfile } from "@hia-doc/core";
|
|
3
|
+
import { getPortalThemeSkinCatalog } from "@hia-doc/theme-default";
|
|
4
|
+
/** @lang zh-CN Portal 输出中的中性 presentation profile 固定路径。 @lang en Fixed neutral presentation-profile path in Portal output. */
|
|
5
|
+
export const PORTAL_PRESENTATION_PROFILE_PATH = "documentation-presentation-profile.json";
|
|
6
|
+
/** @lang zh-CN content-addressed public source 目录。 @lang en Content-addressed public-source directory. */
|
|
7
|
+
export const PORTAL_PUBLIC_SOURCE_DIRECTORY = "sources";
|
|
8
|
+
/** @lang zh-CN Git 字节稳定性规则内容。 @lang en Git byte-stability rule content. */
|
|
9
|
+
export const PORTAL_PUBLIC_SOURCE_GITATTRIBUTES = "sources/*.txt -text\n";
|
|
10
|
+
/**
|
|
11
|
+
* @lang zh-CN
|
|
12
|
+
* 从已授权的内存 preview 构造 Portal-owned neutral profile 和同源 content-addressed source assets;不读取文件或网络。
|
|
13
|
+
*
|
|
14
|
+
* @lang en
|
|
15
|
+
* Builds a Portal-owned neutral profile and same-origin content-addressed source assets from authorized in-memory previews; reads no file or network.
|
|
16
|
+
*
|
|
17
|
+
* @param options - 页面、源码与主题选择。Page, source, and theme selections.
|
|
18
|
+
* @returns exact-valid profile、静态资源和安全 entry mapping。Exact-valid profile, static artifacts, and safe entry mapping.
|
|
19
|
+
* @throws 当内部生成结果违反 W-P115 exact contract 时抛出;调用者输入缺正文只形成 refused profile diagnostic。
|
|
20
|
+
* Throws when an internally generated result violates the W-P115 exact contract; a caller source without a body only creates a refused-profile diagnostic.
|
|
21
|
+
*/
|
|
22
|
+
export function createPortalPresentationBundle(options) {
|
|
23
|
+
// <lang><zh-CN>topic 按 entry identity 排序并重新编号,使调用数组顺序不影响 wire output。</zh-CN><en>Sort topics by entry identity and renumber them so caller array order cannot affect wire output.</en></lang>
|
|
24
|
+
const sortedTopics = [...options.topics].sort((left, right) => compareText(left.entryId, right.entryId));
|
|
25
|
+
const topicByEntryId = new Map();
|
|
26
|
+
const singlePageId = stableIdentity("portal.page.single", options.projectId);
|
|
27
|
+
const topics = sortedTopics.map((topic, order) => {
|
|
28
|
+
// <lang><zh-CN>owner route 保留在 project-index;neutral identity 使用确定性、跨平台安全的 opaque id。</zh-CN><en>The owner route remains in project-index; neutral identity uses a deterministic cross-platform-safe opaque id.</en></lang>
|
|
29
|
+
const topicId = stableIdentity("portal.topic", topic.entryId);
|
|
30
|
+
const fragmentId = stableIdentity("portal.fragment", topic.entryId);
|
|
31
|
+
const navigationId = stableIdentity("portal.navigation", topic.entryId);
|
|
32
|
+
const pageId = options.layout === "single-page" ? singlePageId : stableIdentity("portal.page", topic.entryId);
|
|
33
|
+
const relationIds = [...new Set(topic.relationIds.map((relationId) => stableIdentity("portal.relation", relationId)))]
|
|
34
|
+
.sort(compareText);
|
|
35
|
+
topicByEntryId.set(topic.entryId, { fragmentId, navigationId, pageId, topicId });
|
|
36
|
+
return {
|
|
37
|
+
canonicalReference: `${pageId}#${fragmentId}`,
|
|
38
|
+
fragmentId,
|
|
39
|
+
navigationId,
|
|
40
|
+
order,
|
|
41
|
+
pageId,
|
|
42
|
+
relationIds,
|
|
43
|
+
topicId,
|
|
44
|
+
topicKind: safeIdentityOrHash("portal.kind", topic.topicKind)
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
// <lang><zh-CN>正文只在此局部阶段进入 hash/asset;profile、mapping 和 diagnostics 永不保存正文。</zh-CN><en>Bodies enter hashing/assets only in this local stage; profiles, mappings, and diagnostics never retain them.</en></lang>
|
|
48
|
+
const sourceResult = createPortalSourceArtifacts(options.sources, options.sourceMode);
|
|
49
|
+
const diagnostics = [...sourceResult.diagnostics];
|
|
50
|
+
const themeSkins = getPortalThemeSkinCatalog();
|
|
51
|
+
const profile = {
|
|
52
|
+
contract: DOCUMENTATION_PRESENTATION_PROFILE_CONTRACT,
|
|
53
|
+
contractVersion: DOCUMENTATION_PRESENTATION_PROFILE_CONTRACT_VERSION,
|
|
54
|
+
status: diagnostics.length === 0 ? "ready" : "refused",
|
|
55
|
+
profileId: stableIdentity("portal.profile", options.projectId),
|
|
56
|
+
pagePartition: {
|
|
57
|
+
defaultMode: "multi-page",
|
|
58
|
+
mode: options.layout === "split-site" ? "multi-page" : "single-page",
|
|
59
|
+
leafTopicPolicy: "page",
|
|
60
|
+
pageTopicKinds: [...new Set(topics.map(({ topicKind }) => topicKind))].sort(compareText),
|
|
61
|
+
...(options.layout === "single-page" ? { singlePageId } : {}),
|
|
62
|
+
topics
|
|
63
|
+
},
|
|
64
|
+
identityPolicy: {
|
|
65
|
+
stableFields: ["topicId", "fragmentId", "navigationId", "relationIds"],
|
|
66
|
+
pageIdProjection: "partition-mode-only",
|
|
67
|
+
sourceModeAffectsIdentity: false,
|
|
68
|
+
skinAffectsIdentity: false,
|
|
69
|
+
schemeAffectsIdentity: false
|
|
70
|
+
},
|
|
71
|
+
source: {
|
|
72
|
+
defaultMode: "fetch",
|
|
73
|
+
mode: options.sourceMode,
|
|
74
|
+
fallbackPolicy: "none",
|
|
75
|
+
assets: sourceResult.assets,
|
|
76
|
+
readerPolicy: {
|
|
77
|
+
endpointPolicy: "same-origin-relative",
|
|
78
|
+
credentials: "omit",
|
|
79
|
+
requestMode: "same-origin",
|
|
80
|
+
redirect: "error",
|
|
81
|
+
cache: "default",
|
|
82
|
+
bodyExecution: false,
|
|
83
|
+
limits: {
|
|
84
|
+
maxBytes: 1_048_576,
|
|
85
|
+
maxLines: options.maxLines,
|
|
86
|
+
timeoutMs: 10_000
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
theme: {
|
|
91
|
+
skinId: options.skinId,
|
|
92
|
+
scheme: options.scheme,
|
|
93
|
+
requiredCapabilities: ["native-disclosure", "no-script-default", "source-reader", "theme-selector"],
|
|
94
|
+
skins: themeSkins
|
|
95
|
+
},
|
|
96
|
+
privacy: {
|
|
97
|
+
sourceExposure: options.sourceMode === "none" ? "none" : "public-explicit",
|
|
98
|
+
sourceBodyInContract: false,
|
|
99
|
+
sourceBodyInSearchIndex: false,
|
|
100
|
+
absolutePathsIncluded: false,
|
|
101
|
+
credentialsIncluded: false,
|
|
102
|
+
cookiesRequired: false,
|
|
103
|
+
privateSidecarsIncluded: false,
|
|
104
|
+
telemetryEnabled: false
|
|
105
|
+
},
|
|
106
|
+
diagnostics,
|
|
107
|
+
compatibility: {
|
|
108
|
+
versionMatch: "exact",
|
|
109
|
+
unknownProperties: "reject",
|
|
110
|
+
identityChange: "new-contract-version",
|
|
111
|
+
semanticChange: "new-contract-version"
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
// <lang><zh-CN>renderer 自己生成的 contract 若失效就是实现错误,不能作为普通用户 diagnostic 继续输出。</zh-CN><en>An invalid renderer-generated contract is an implementation error and must not continue as an ordinary user diagnostic.</en></lang>
|
|
115
|
+
const validationDiagnostics = validateDocumentationPresentationProfile(profile);
|
|
116
|
+
if (validationDiagnostics.length > 0) {
|
|
117
|
+
throw new TypeError(`HIA_PORTAL_PRESENTATION_PROFILE_INVALID: ${validationDiagnostics.map(({ code }) => code).join(",")}`);
|
|
118
|
+
}
|
|
119
|
+
const profileArtifact = {
|
|
120
|
+
path: PORTAL_PRESENTATION_PROFILE_PATH,
|
|
121
|
+
contents: `${JSON.stringify(profile, null, 2)}\n`,
|
|
122
|
+
contentType: "application/json; charset=utf-8",
|
|
123
|
+
role: "index"
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
profile,
|
|
127
|
+
diagnostics,
|
|
128
|
+
topicByEntryId,
|
|
129
|
+
sourceByEntryId: sourceResult.sourceByEntryId,
|
|
130
|
+
artifacts: [profileArtifact, ...sourceResult.artifacts]
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** @lang zh-CN 构造 public asset 并按 source identity 去重。 @lang en Builds public assets and deduplicates them by source identity. */
|
|
134
|
+
function createPortalSourceArtifacts(sources, mode) {
|
|
135
|
+
if (mode === "none") {
|
|
136
|
+
return { artifacts: [], assets: [], diagnostics: [], sourceByEntryId: new Map() };
|
|
137
|
+
}
|
|
138
|
+
const diagnostics = [];
|
|
139
|
+
const assetsBySourceId = new Map();
|
|
140
|
+
const sourceByEntryId = new Map();
|
|
141
|
+
// <lang zh-CN>缺正文可能覆盖数千 topic;只记录计数并在循环后发出一个有界诊断,避免突破 contract 的 128 项上限。</lang>
|
|
142
|
+
// <lang en>A missing body can affect thousands of topics; retain only a count and emit one bounded diagnostic after the loop to stay within the contract's 128-item limit.</lang>
|
|
143
|
+
let missingAuthorizedAssetCount = 0;
|
|
144
|
+
for (const source of [...sources].sort((left, right) => compareText(left.entryId, right.entryId))) {
|
|
145
|
+
const identitySeed = `${source.sourcePath}:${source.startLine ?? 1}:${source.endLine ?? "open"}`;
|
|
146
|
+
const sourceId = stableIdentity("portal.source", identitySeed);
|
|
147
|
+
const content = source.content;
|
|
148
|
+
if (content === undefined) {
|
|
149
|
+
missingAuthorizedAssetCount += 1;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const byteLength = Buffer.byteLength(content, "utf8");
|
|
153
|
+
if (byteLength > 1_048_576) {
|
|
154
|
+
diagnostics.push(createHiaDiagnostic("PRESENTATION_SOURCE_ASSET_INVALID", "An authorized public source asset exceeds the Portal byte limit.", "error", { targetPath: `source.assets.${stableIdentity("portal.topic", source.entryId)}` }));
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const contentHash = digestHex("sha256", content);
|
|
158
|
+
const existing = assetsBySourceId.get(sourceId);
|
|
159
|
+
if (existing && existing.contentHash !== contentHash) {
|
|
160
|
+
diagnostics.push(createHiaDiagnostic("PRESENTATION_SOURCE_ASSET_INVALID", "One stable source identity resolved to inconsistent authorized content.", "error", { targetPath: `source.assets.${sourceId}` }));
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (existing) {
|
|
164
|
+
sourceByEntryId.set(source.entryId, existing.projection);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const relativeUrl = `${PORTAL_PUBLIC_SOURCE_DIRECTORY}/${contentHash}.txt`;
|
|
168
|
+
const lineCount = content.length === 0 ? 0 : content.split(/\r?\n/u).length;
|
|
169
|
+
const digest = `sha384-${digestBase64("sha384", content)}`;
|
|
170
|
+
const assetId = stableIdentity("portal.asset", `${identitySeed}:${contentHash}`);
|
|
171
|
+
const projection = {
|
|
172
|
+
assetId,
|
|
173
|
+
sourceId,
|
|
174
|
+
relativeUrl,
|
|
175
|
+
revision: `content:${contentHash}`,
|
|
176
|
+
digest,
|
|
177
|
+
byteLength,
|
|
178
|
+
lineCount
|
|
179
|
+
};
|
|
180
|
+
const asset = {
|
|
181
|
+
assetId,
|
|
182
|
+
sourceId,
|
|
183
|
+
classification: "public",
|
|
184
|
+
mediaType: "text/plain",
|
|
185
|
+
revision: projection.revision,
|
|
186
|
+
digest: { algorithm: "sha384", value: digest.slice("sha384-".length) },
|
|
187
|
+
byteLength,
|
|
188
|
+
lineCount,
|
|
189
|
+
...(mode === "fetch" || mode === "link" ? { relativeUrl } : {}),
|
|
190
|
+
...(source.sourceMapId ? { sourceMapId: safeIdentityOrHash("portal.source-map", source.sourceMapId) } : {})
|
|
191
|
+
};
|
|
192
|
+
const artifact = mode === "fetch" || mode === "link"
|
|
193
|
+
? { path: relativeUrl, contents: content, contentType: "text/plain; charset=utf-8", role: "asset" }
|
|
194
|
+
: undefined;
|
|
195
|
+
// <lang zh-CN>仅在 fetch/link 确实产生静态文件时保留 artifact 字段,满足 exact optional property 语义。</lang>
|
|
196
|
+
// <lang en>Retain the artifact field only when fetch/link actually emits a static file, preserving exact optional-property semantics.</lang>
|
|
197
|
+
assetsBySourceId.set(sourceId, {
|
|
198
|
+
asset,
|
|
199
|
+
projection,
|
|
200
|
+
contentHash,
|
|
201
|
+
...(artifact ? { artifact } : {})
|
|
202
|
+
});
|
|
203
|
+
sourceByEntryId.set(source.entryId, projection);
|
|
204
|
+
}
|
|
205
|
+
if (missingAuthorizedAssetCount > 0) {
|
|
206
|
+
diagnostics.unshift(createHiaDiagnostic("PRESENTATION_SOURCE_ASSET_INVALID", `${missingAuthorizedAssetCount} documented source reference(s) have no explicitly authorized public text asset; no fallback mode was selected.`, "warning", { targetPath: "source.assets" }));
|
|
207
|
+
}
|
|
208
|
+
const records = [...assetsBySourceId.values()].sort((left, right) => compareText(left.asset.assetId, right.asset.assetId));
|
|
209
|
+
// <lang zh-CN>内容寻址会让不同 source identity 共享同一路径;按路径再去重可避免输出重复 artifact。</lang>
|
|
210
|
+
// <lang en>Content addressing can map distinct source identities to one path, so deduplicate artifacts by path before emission.</lang>
|
|
211
|
+
const sourceArtifacts = [...new Map(records.flatMap(({ artifact }) => artifact ? [[artifact.path, artifact]] : [])).values()];
|
|
212
|
+
const gitAttributes = sourceArtifacts.length > 0
|
|
213
|
+
? [{ path: ".gitattributes", contents: PORTAL_PUBLIC_SOURCE_GITATTRIBUTES, contentType: "text/plain; charset=utf-8", role: "asset" }]
|
|
214
|
+
: [];
|
|
215
|
+
return {
|
|
216
|
+
diagnostics,
|
|
217
|
+
sourceByEntryId,
|
|
218
|
+
assets: records.map(({ asset }) => asset),
|
|
219
|
+
artifacts: [...gitAttributes, ...sourceArtifacts]
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/** @lang zh-CN 保留已合法的中性 identity,否则生成 opaque hash identity。 @lang en Preserves an already valid neutral identity or creates an opaque hash identity. */
|
|
223
|
+
function safeIdentityOrHash(prefix, value) {
|
|
224
|
+
return /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(value) ? value : stableIdentity(prefix, value);
|
|
225
|
+
}
|
|
226
|
+
/** @lang zh-CN 创建不泄漏原字符串的确定性 identity。 @lang en Creates a deterministic identity that does not disclose the original string. */
|
|
227
|
+
function stableIdentity(prefix, value) {
|
|
228
|
+
return `${prefix}:${digestHex("sha256", value).slice(0, 32)}`;
|
|
229
|
+
}
|
|
230
|
+
/** @lang zh-CN 计算十六进制摘要。 @lang en Computes a hexadecimal digest. */
|
|
231
|
+
function digestHex(algorithm, value) {
|
|
232
|
+
return createHash(algorithm).update(value, "utf8").digest("hex");
|
|
233
|
+
}
|
|
234
|
+
/** @lang zh-CN 计算 contract 使用的 base64 摘要。 @lang en Computes a base64 digest used by the contract. */
|
|
235
|
+
function digestBase64(algorithm, value) {
|
|
236
|
+
return createHash(algorithm).update(value, "utf8").digest("base64");
|
|
237
|
+
}
|
|
238
|
+
/** @lang zh-CN 跨 locale 的稳定 code-point 排序。 @lang en Stable code-point ordering independent of locale. */
|
|
239
|
+
function compareText(left, right) {
|
|
240
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=presentation-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation-profile.js","sourceRo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AAED,oEAAoE;AACpE,SAAS,SAAS,CAAC,SAAmB,EAAE,KAAa;IACnD,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED,qGAAqG;AACrG,SAAS,YAAY,CAAC,SAAmB,EAAE,KAAa;IACtD,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACtE,CAAC;AAED,yGAAyG;AACzG,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC9C,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @lang zh-CN 默认主题资源的显式唯一写入投影与同站URL重定位;不读写文件或修改页面内容字段。
|
|
4
|
+
* @lang en Explicit sole-writer projection and same-site URL relocation for default theme assets, without filesystem I/O or documentation-field mutation.
|
|
5
|
+
*/
|
|
6
|
+
import { type HiaThemeAssetOptions } from "@hia-doc/theme-default";
|
|
7
|
+
import type { RenderedHtmlFile } from "./index.js";
|
|
8
|
+
/**
|
|
9
|
+
* @lang zh-CN 生成可交给显式共享资源写入者的两个默认主题文件,不生成页面或manifest。
|
|
10
|
+
* @lang en Generates two default-theme files for an explicit shared-resource writer, without pages or manifests.
|
|
11
|
+
* @param options <lang><zh-CN>安全颜色覆盖;非法值由主题owner拒绝。</zh-CN><en>Safe color overrides; invalid values are rejected by the theme owner.</en></lang>
|
|
12
|
+
* @returns <lang><zh-CN>全新文件记录,固定安全相对路径;调用者决定唯一输出根。</zh-CN><en>New file records with fixed safe relative paths; callers choose the sole output root.</en></lang>
|
|
13
|
+
*/
|
|
14
|
+
export declare function renderThemeAssets(options?: HiaThemeAssetOptions): RenderedHtmlFile[];
|
|
15
|
+
/** @lang zh-CN 只定义主题资源所有权与URL,不将父相对URL当作文件写入路径。 @lang en Defines only theme-resource ownership and URLs, never treating parent-relative URLs as write paths. */
|
|
16
|
+
export interface ThemeAssetRouting {
|
|
17
|
+
/** @lang zh-CN 默认local,external由外部唯一写入者提供。 @lang en Defaults to local; external resources are supplied by one external writer. */
|
|
18
|
+
mode?: "local" | "external";
|
|
19
|
+
/** @lang zh-CN external资源目录,按输出根相对或站点根相对解释。 @lang en External asset directory, relative to the output root or site root. */
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @lang zh-CN 外部模式移除本次主题资源副本,并按各HTML深度重定位两个固定引用;保留其它资源与全部正文。
|
|
24
|
+
* @lang en External mode removes per-render theme copies and relocates two fixed references by HTML depth, retaining all other resources and prose.
|
|
25
|
+
* @param files <lang><zh-CN>当前renderer生成的文件;不修改原对象。</zh-CN><en>Files produced by the current renderer; original records remain unchanged.</en></lang>
|
|
26
|
+
* @param routing <lang><zh-CN>只允许同站URL,不接受协议、query、fragment或反斜杠。</zh-CN><en>Same-site URLs only, without schemes, queries, fragments or backslashes.</en></lang>
|
|
27
|
+
* @returns <lang><zh-CN>新数组,必要时复制HTML记录;不做文件I/O或外部下载。</zh-CN><en>New array, copying HTML records when needed; no file I/O or external downloads.</en></lang>
|
|
28
|
+
* @throws {TypeError} <lang><zh-CN>非法资源模式或URL,在调用者写文件前拒绝。</zh-CN><en>Invalid resource modes/URLs are rejected before caller file writes.</en></lang>
|
|
29
|
+
*/
|
|
30
|
+
export declare function relocateDefaultThemeAssets(files: readonly RenderedHtmlFile[], routing?: ThemeAssetRouting): RenderedHtmlFile[];
|
|
31
|
+
//# sourceMappingURL=theme-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-assets.d.ts","sourceRoot":"","sources":["../src/theme-assets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAwE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzI,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,oBAAyB,GAAG,gBAAgB,EAAE,CAExF;AAED,gKAAgK;AAChK,MAAM,WAAW,iBAAiB;IAChC,kIAAkI;IAClI,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAC5B,4HAA4H;IAC5H,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,EAAE,CAwBlI"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @lang zh-CN 默认主题资源的显式唯一写入投影与同站URL重定位;不读写文件或修改页面内容字段。
|
|
4
|
+
* @lang en Explicit sole-writer projection and same-site URL relocation for default theme assets, without filesystem I/O or documentation-field mutation.
|
|
5
|
+
*/
|
|
6
|
+
import { DEFAULT_THEME_CSS_PATH, DEFAULT_THEME_JS_PATH, getDefaultThemeAssets } from "@hia-doc/theme-default";
|
|
7
|
+
/**
|
|
8
|
+
* @lang zh-CN 生成可交给显式共享资源写入者的两个默认主题文件,不生成页面或manifest。
|
|
9
|
+
* @lang en Generates two default-theme files for an explicit shared-resource writer, without pages or manifests.
|
|
10
|
+
* @param options <lang><zh-CN>安全颜色覆盖;非法值由主题owner拒绝。</zh-CN><en>Safe color overrides; invalid values are rejected by the theme owner.</en></lang>
|
|
11
|
+
* @returns <lang><zh-CN>全新文件记录,固定安全相对路径;调用者决定唯一输出根。</zh-CN><en>New file records with fixed safe relative paths; callers choose the sole output root.</en></lang>
|
|
12
|
+
*/
|
|
13
|
+
export function renderThemeAssets(options = {}) {
|
|
14
|
+
return getDefaultThemeAssets(options).map((file) => ({ ...file, role: "asset" }));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @lang zh-CN 外部模式移除本次主题资源副本,并按各HTML深度重定位两个固定引用;保留其它资源与全部正文。
|
|
18
|
+
* @lang en External mode removes per-render theme copies and relocates two fixed references by HTML depth, retaining all other resources and prose.
|
|
19
|
+
* @param files <lang><zh-CN>当前renderer生成的文件;不修改原对象。</zh-CN><en>Files produced by the current renderer; original records remain unchanged.</en></lang>
|
|
20
|
+
* @param routing <lang><zh-CN>只允许同站URL,不接受协议、query、fragment或反斜杠。</zh-CN><en>Same-site URLs only, without schemes, queries, fragments or backslashes.</en></lang>
|
|
21
|
+
* @returns <lang><zh-CN>新数组,必要时复制HTML记录;不做文件I/O或外部下载。</zh-CN><en>New array, copying HTML records when needed; no file I/O or external downloads.</en></lang>
|
|
22
|
+
* @throws {TypeError} <lang><zh-CN>非法资源模式或URL,在调用者写文件前拒绝。</zh-CN><en>Invalid resource modes/URLs are rejected before caller file writes.</en></lang>
|
|
23
|
+
*/
|
|
24
|
+
export function relocateDefaultThemeAssets(files, routing = {}) {
|
|
25
|
+
// <lang><zh-CN>资源所有权缺省为本次输出,保留兼容行为。</zh-CN><en>Resource ownership defaults to the current output for compatibility.</en></lang>
|
|
26
|
+
const mode = routing.mode ?? "local";
|
|
27
|
+
if (mode === "local" && routing.baseUrl === undefined)
|
|
28
|
+
return [...files];
|
|
29
|
+
// <lang><zh-CN>目录URL仅参与HTML引用,不参与磁盘路径拼接。</zh-CN><en>The directory URL participates only in HTML references, never disk path joins.</en></lang>
|
|
30
|
+
const base = routing.baseUrl;
|
|
31
|
+
if (mode !== "external" || typeof base !== "string" || !base || /[\s\\<>"']/u.test(base) || base.startsWith("//") || /^[a-z][a-z0-9+.-]*:/iu.test(base))
|
|
32
|
+
throw new TypeError("HIA_THEME_ASSETS_INVALID: External assets require a safe same-site directory URL.");
|
|
33
|
+
try {
|
|
34
|
+
// <lang><zh-CN>使用固定同源哨兵验证URL解析结果,拒绝query/fragment及远端资源。</zh-CN><en>A fixed same-origin sentinel validates URL parsing and rejects queries, fragments and remote assets.</en></lang>
|
|
35
|
+
const parsed = new URL(base, "https://hia.invalid/base/");
|
|
36
|
+
if (parsed.origin !== "https://hia.invalid" || parsed.search || parsed.hash)
|
|
37
|
+
throw new TypeError();
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new TypeError("HIA_THEME_ASSETS_INVALID: External assets require a safe same-site directory URL.");
|
|
41
|
+
}
|
|
42
|
+
// <lang><zh-CN>只重定位默认主题CSS/JS,不碰source、entry、搜索索引或其它资源的URL。</zh-CN><en>Relocate only default-theme CSS/JS, leaving source, entry, search-index and other-resource URLs untouched.</en></lang>
|
|
43
|
+
const directory = base.endsWith("/") ? base : `${base}/`;
|
|
44
|
+
return files.filter((file) => file.role !== "asset" || (file.path !== DEFAULT_THEME_CSS_PATH && file.path !== DEFAULT_THEME_JS_PATH)).map((file) => {
|
|
45
|
+
if (!file.contentType.startsWith("text/html"))
|
|
46
|
+
return file;
|
|
47
|
+
// <lang><zh-CN>页面深度相对于当前输出根;根相对URL保持绝对站点路径。</zh-CN><en>Page depth is relative to the current output root; root-relative URLs retain their absolute site path.</en></lang>
|
|
48
|
+
const prefix = directory.startsWith("/") ? "" : "../".repeat(file.path.split("/").length - 1);
|
|
49
|
+
// <lang><zh-CN>转义URL中的&,避免HTML实体被浏览器解码成绕过同源检查的斜杠。</zh-CN><en>Escape URL ampersands so browser entity decoding cannot introduce slashes that bypass same-origin validation.</en></lang>
|
|
50
|
+
const escapedDirectory = `${prefix}${directory}`.replaceAll("&", "&");
|
|
51
|
+
const contents = file.contents.replace(/\b(href|src)="((?:\.\.\/)*assets\/hia-default\.(css|js))"/gu, (_whole, attribute, _original, extension) => `${attribute}="${escapedDirectory}hia-default.${extension}"`);
|
|
52
|
+
return contents === file.contents ? file : { ...file, contents };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=theme-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-assets.js","sourceRoot":"","sources":["../src/theme-assets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,qBAAqB,EAA6B,MAAM,wBAAwB,CAAC;AAGzI;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAgC,EAAE;IAClE,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AACpF,CAAC;AAUD;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAkC,EAAE,UAA6B,EAAE;IAC5G,gIAAgI;IAChI,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC;IACrC,IAAI,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IACzE,+IAA+I;IAC/I,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;IAC7B,IAAI,IAAI,KAAK,UAAU,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,mFAAmF,CAAC,CAAC;IAClQ,IAAI,CAAC;QACH,oLAAoL;QACpL,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,2BAA2B,CAAC,CAAC;QAC1D,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QACjN,OAAO,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hia-doc/renderer-html",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Minimal HTML renderer for HIA documents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@hia-doc/
|
|
33
|
-
"@hia-doc/
|
|
34
|
-
"@hia-doc/theme-default": "0.1.
|
|
32
|
+
"@hia-doc/source-linkage": "0.1.1",
|
|
33
|
+
"@hia-doc/core": "0.1.2",
|
|
34
|
+
"@hia-doc/theme-default": "0.1.4"
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"scripts": {
|