mirror of
https://github.com/morluto/rea
synced 2026-10-28 06:46:47 -04:00
f430c416c7
* refactor(browser): share captured-script acquisition boundaries Reuse stable capture/source acquisition and identity validation for module and source-map analysis. Preserve host I/O, malformed input, unavailable source and digest mismatch diagnostics. Refs #851 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * feat(browser): trace captured website source-map locations Refs #851. Preserve selected capture/map byte identity, duplicate mappings and embedded source evidence through the pinned upstream codec. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * test(browser): verify source-map artifacts and synchronize generated contracts Cover byte-preserving map reads and actionable filesystem constraints. Refresh generated public schemas and metadata on current main. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): preserve inert source-map URL context The selected URL is local codec context and grants no transport authority. Preserve its reported text and verify normal/userinfo contexts through real public interfaces, alongside independent manifest byte identity. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
33 lines
977 B
TypeScript
33 lines
977 B
TypeScript
/** JavaScript positions use one-based lines and zero-based UTF-16 columns. */
|
|
export interface WebSourcePosition {
|
|
readonly line: number;
|
|
readonly column: number;
|
|
}
|
|
|
|
/** Verify a selected position against actual text without splitting the whole source. */
|
|
export const webSourceOffset = (
|
|
text: string,
|
|
position: WebSourcePosition,
|
|
): number | undefined => {
|
|
if (
|
|
!Number.isSafeInteger(position.line) ||
|
|
position.line < 1 ||
|
|
!Number.isSafeInteger(position.column) ||
|
|
position.column < 0
|
|
)
|
|
return undefined;
|
|
let line = 1;
|
|
let start = 0;
|
|
for (const boundary of text.matchAll(/\r\n?|\n|\u2028|\u2029/gu)) {
|
|
if (line === position.line)
|
|
return position.column <= boundary.index - start
|
|
? start + position.column
|
|
: undefined;
|
|
line += 1;
|
|
start = boundary.index + boundary[0].length;
|
|
}
|
|
return line === position.line && position.column <= text.length - start
|
|
? start + position.column
|
|
: undefined;
|
|
};
|