@nuasite/cms-marker 0.0.53 → 0.0.54
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 +0 -4
- package/dist/types/astro-transform.d.ts +21 -0
- package/dist/types/astro-transform.d.ts.map +1 -0
- package/dist/types/build-processor.d.ts +10 -0
- package/dist/types/build-processor.d.ts.map +1 -0
- package/dist/types/component-registry.d.ts +63 -0
- package/dist/types/component-registry.d.ts.map +1 -0
- package/dist/types/dev-middleware.d.ts +7 -0
- package/dist/types/dev-middleware.d.ts.map +1 -0
- package/dist/types/html-processor.d.ts +51 -0
- package/dist/types/html-processor.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/manifest-writer.d.ts +75 -0
- package/dist/types/manifest-writer.d.ts.map +1 -0
- package/dist/types/source-finder.d.ts +97 -0
- package/dist/types/source-finder.d.ts.map +1 -0
- package/dist/types/tailwind-colors.d.ts +66 -0
- package/dist/types/tailwind-colors.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types.d.ts +195 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +38 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/vite-plugin.d.ts +14 -0
- package/dist/types/vite-plugin.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/astro-transform.ts +4 -4
- package/src/build-processor.ts +1 -1
- package/src/component-registry.ts +2 -2
- package/src/dev-middleware.ts +5 -5
- package/src/html-processor.ts +180 -6
- package/src/index.ts +0 -1
- package/src/manifest-writer.ts +47 -1
- package/src/source-finder.ts +117 -6
- package/src/tailwind-colors.ts +338 -0
- package/src/tsconfig.json +1 -1
- package/src/types.ts +123 -1
- package/src/utils.ts +99 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import type { ManifestEntry, SourceContext } from './types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate a SHA256 hash of the given content
|
|
6
|
+
*/
|
|
7
|
+
export function sha256(content: string): string {
|
|
8
|
+
return createHash('sha256').update(content, 'utf8').digest('hex')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generate a short hash (first 12 characters of SHA256)
|
|
13
|
+
* Used for stableId to keep it reasonably short but still unique
|
|
14
|
+
*/
|
|
15
|
+
export function shortHash(content: string): string {
|
|
16
|
+
return sha256(content).substring(0, 12)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generate a stable ID for an element based on its content and context.
|
|
21
|
+
* This ID survives rebuilds as long as the content and structure remain similar.
|
|
22
|
+
*
|
|
23
|
+
* Components:
|
|
24
|
+
* - tag name
|
|
25
|
+
* - first 50 chars of text content
|
|
26
|
+
* - source path (if available)
|
|
27
|
+
* - parent tag
|
|
28
|
+
* - sibling index
|
|
29
|
+
*/
|
|
30
|
+
export function generateStableId(
|
|
31
|
+
tag: string,
|
|
32
|
+
text: string,
|
|
33
|
+
sourcePath?: string,
|
|
34
|
+
context?: SourceContext,
|
|
35
|
+
): string {
|
|
36
|
+
const components = [
|
|
37
|
+
tag,
|
|
38
|
+
text.substring(0, 50).trim(),
|
|
39
|
+
sourcePath || '',
|
|
40
|
+
context?.parentTag || '',
|
|
41
|
+
context?.siblingIndex?.toString() || '',
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
return shortHash(components.join('|'))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Generate a hash of the source snippet for conflict detection.
|
|
49
|
+
* If the source file changes, this hash will differ from what's stored in manifest.
|
|
50
|
+
*/
|
|
51
|
+
export function generateSourceHash(sourceSnippet: string): string {
|
|
52
|
+
return sha256(sourceSnippet)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generate a content hash for the entire manifest (all entries).
|
|
57
|
+
* Used for quick drift detection without comparing individual entries.
|
|
58
|
+
*/
|
|
59
|
+
export function generateManifestContentHash(entries: Record<string, ManifestEntry>): string {
|
|
60
|
+
// Sort keys for deterministic hashing
|
|
61
|
+
const sortedKeys = Object.keys(entries).sort()
|
|
62
|
+
const content = sortedKeys.map(key => {
|
|
63
|
+
const entry = entries[key]!
|
|
64
|
+
// Hash only content-relevant fields, not generated IDs
|
|
65
|
+
return `${entry.tag}|${entry.text}|${entry.html || ''}|${entry.sourcePath || ''}`
|
|
66
|
+
}).join('\n')
|
|
67
|
+
|
|
68
|
+
return sha256(content)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Generate per-source-file hashes for granular conflict detection.
|
|
73
|
+
* Maps source file path -> hash of all entries from that file.
|
|
74
|
+
*/
|
|
75
|
+
export function generateSourceFileHashes(entries: Record<string, ManifestEntry>): Record<string, string> {
|
|
76
|
+
// Group entries by source file
|
|
77
|
+
const entriesByFile: Record<string, ManifestEntry[]> = {}
|
|
78
|
+
|
|
79
|
+
for (const entry of Object.values(entries)) {
|
|
80
|
+
const sourcePath = entry.sourcePath
|
|
81
|
+
if (sourcePath) {
|
|
82
|
+
if (!entriesByFile[sourcePath]) {
|
|
83
|
+
entriesByFile[sourcePath] = []
|
|
84
|
+
}
|
|
85
|
+
entriesByFile[sourcePath].push(entry)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Generate hash for each file
|
|
90
|
+
const hashes: Record<string, string> = {}
|
|
91
|
+
for (const [filePath, fileEntries] of Object.entries(entriesByFile)) {
|
|
92
|
+
// Sort entries by line number for determinism
|
|
93
|
+
const sorted = fileEntries.sort((a, b) => (a.sourceLine || 0) - (b.sourceLine || 0))
|
|
94
|
+
const content = sorted.map(e => `${e.sourceLine || 0}|${e.text}|${e.sourceSnippet || ''}`).join('\n')
|
|
95
|
+
hashes[filePath] = sha256(content)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return hashes
|
|
99
|
+
}
|