Archify Diagram Viewer 0.1.0
VS Code extension that previews Archify diagrams from their JSON sources (live, as you type) and opens rendered Archify HTML in a viewer tab. Bundles the Archify 3.0.1 renderer and runs it on VS Code's Node runtime. Adds validation diagnostics, JSON schema help, source-link navigation, export saving, render-to-file and open-in-browser commands. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
const SIDECAR_STEM_NAMESPACE = /\.~archify-[0-9a-f]{64}$/iu;
|
||||
|
||||
export function sidecarStemNeedsBounding(stem, suffixes) {
|
||||
const fits = (value) => value.length <= 255 && Buffer.byteLength(value, 'utf8') <= 255;
|
||||
return !suffixes.every((suffix) => fits(`${stem}${suffix}`));
|
||||
}
|
||||
|
||||
export function boundedSidecarStem(stem, suffixes, { force = false, hashDomain } = {}) {
|
||||
if (!force && !sidecarStemNeedsBounding(stem, suffixes)
|
||||
&& !SIDECAR_STEM_NAMESPACE.test(stem)) return stem;
|
||||
const hashInput = hashDomain ? `${hashDomain}\0${stem}` : stem;
|
||||
const marker = `.~archify-${createHash('sha256').update(hashInput).digest('hex')}`;
|
||||
const codePoints = [...stem];
|
||||
while (codePoints.length
|
||||
&& sidecarStemNeedsBounding(`${codePoints.join('')}${marker}`, suffixes)) {
|
||||
codePoints.pop();
|
||||
}
|
||||
return `${codePoints.join('')}${marker}`;
|
||||
}
|
||||
|
||||
export function sidecarStemFromComponent(component) {
|
||||
if (component.endsWith('.html')) {
|
||||
return {
|
||||
stem: component.slice(0, -'.html'.length),
|
||||
options: undefined,
|
||||
};
|
||||
}
|
||||
return {
|
||||
stem: component,
|
||||
options: { force: true, hashDomain: 'full-component' },
|
||||
};
|
||||
}
|
||||
|
||||
export function isBoundedSidecarStem(stem) {
|
||||
return SIDECAR_STEM_NAMESPACE.test(stem);
|
||||
}
|
||||
Reference in New Issue
Block a user