@@ -4,16 +4,13 @@ import ImageAssetLoader from "../../engine/assets/ImageAssetLoader.js";
44import { prepareVectorGeometryRuntimeAsset } from "./vectorGeometryRuntime.js" ;
55import { ensureArray } from "../../src/shared/utils/arrayUtils.js" ;
66import { cloneJson } from "../../src/shared/utils/jsonUtils.js" ;
7-
8- function sanitizeText ( value ) {
9- return typeof value === "string" ? value . trim ( ) : "" ;
10- }
7+ import { trimSafe } from "../../src/shared/utils/stringUtils.js" ;
118
129function createReport ( level , code , message ) {
1310 return {
14- level : sanitizeText ( level ) || "info" ,
15- code : sanitizeText ( code ) ,
16- message : sanitizeText ( message )
11+ level : trimSafe ( level ) || "info" ,
12+ code : trimSafe ( code ) ,
13+ message : trimSafe ( message )
1714 } ;
1815}
1916
@@ -36,7 +33,7 @@ function validatePackageManifest(manifest) {
3633 if ( ! Number . isFinite ( pkg . version ) ) {
3734 throw new Error ( "Invalid packaged input: package.version must be numeric." ) ;
3835 }
39- if ( ! sanitizeText ( pkg . projectId ) ) {
36+ if ( ! trimSafe ( pkg . projectId ) ) {
4037 throw new Error ( "Invalid packaged input: package.projectId is required." ) ;
4138 }
4239 if ( ! Array . isArray ( pkg . assets ) || pkg . assets . length === 0 ) {
@@ -51,8 +48,8 @@ function validatePackageManifest(manifest) {
5148
5249 const seenIds = new Set ( ) ;
5350 pkg . assets . forEach ( ( asset , index ) => {
54- const id = sanitizeText ( asset ?. id ) ;
55- const type = sanitizeText ( asset ?. type ) ;
51+ const id = trimSafe ( asset ?. id ) ;
52+ const type = trimSafe ( asset ?. type ) ;
5653 if ( ! id ) {
5754 throw new Error ( `Invalid packaged input: asset at index ${ index } is missing id.` ) ;
5855 }
@@ -66,16 +63,16 @@ function validatePackageManifest(manifest) {
6663 } ) ;
6764
6865 pkg . roots . forEach ( ( root , index ) => {
69- const id = sanitizeText ( root ?. id ) ;
66+ const id = trimSafe ( root ?. id ) ;
7067 if ( ! id || ! seenIds . has ( id ) ) {
7168 throw new Error ( `Invalid packaged input: startup root at index ${ index } does not resolve to a packaged asset.` ) ;
7269 }
7370 } ) ;
7471
7572 pkg . dependencies . forEach ( ( dependency , index ) => {
76- const from = sanitizeText ( dependency ?. from ) ;
77- const to = sanitizeText ( dependency ?. to ) ;
78- const type = sanitizeText ( dependency ?. type ) ;
73+ const from = trimSafe ( dependency ?. from ) ;
74+ const to = trimSafe ( dependency ?. to ) ;
75+ const type = trimSafe ( dependency ?. type ) ;
7976 if ( ! from || ! to || ! type ) {
8077 throw new Error ( `Invalid packaged input: dependency at index ${ index } is incomplete.` ) ;
8178 }
@@ -88,12 +85,12 @@ function validatePackageManifest(manifest) {
8885}
8986
9087function createRegistryDefinition ( asset , source ) {
91- const type = sanitizeText ( asset ?. type ) ;
88+ const type = trimSafe ( asset ?. type ) ;
9289 const sourceType = type === "image" ? "image" : "data" ;
9390 return {
94- id : sanitizeText ( asset ?. id ) ,
91+ id : trimSafe ( asset ?. id ) ,
9592 type : sourceType ,
96- path : sanitizeText ( asset ?. path ) ,
93+ path : trimSafe ( asset ?. path ) ,
9794 source
9895 } ;
9996}
@@ -102,7 +99,7 @@ function toBootstrapData(packageManifest, loadedAssets) {
10299 const pkg = packageManifest . package ;
103100 return {
104101 projectId : pkg . projectId ,
105- startupAssetIds : pkg . roots . map ( ( root ) => sanitizeText ( root . id ) ) ,
102+ startupAssetIds : pkg . roots . map ( ( root ) => trimSafe ( root . id ) ) ,
106103 assetTable : loadedAssets . reduce ( ( accumulator , entry ) => {
107104 accumulator [ entry . id ] = entry . asset ;
108105 return accumulator ;
@@ -112,12 +109,12 @@ function toBootstrapData(packageManifest, loadedAssets) {
112109}
113110
114111function finalizeLoadedAsset ( asset , loadedAsset ) {
115- if ( sanitizeText ( asset ?. type ) !== "vector" ) {
112+ if ( trimSafe ( asset ?. type ) !== "vector" ) {
116113 return loadedAsset ;
117114 }
118115 return prepareVectorGeometryRuntimeAsset ( loadedAsset , {
119- sourcePath : sanitizeText ( asset ?. path ) ,
120- assetId : sanitizeText ( asset ?. id )
116+ sourcePath : trimSafe ( asset ?. path ) ,
117+ assetId : trimSafe ( asset ?. id )
121118 } ) ;
122119}
123120
@@ -169,7 +166,7 @@ export async function loadPackagedProjectRuntime(options = {}) {
169166
170167 for ( let index = 0 ; index < pkg . assets . length ; index += 1 ) {
171168 const asset = pkg . assets [ index ] ;
172- const assetId = sanitizeText ( asset ?. id ) ;
169+ const assetId = trimSafe ( asset ?. id ) ;
173170 const resolvedSource = assetProvider ( asset , manifest ) ;
174171 if ( resolvedSource === undefined || resolvedSource === null || resolvedSource === "" ) {
175172 reports . push ( createReport ( "error" , "MISSING_PACKAGED_ASSET" , `Required packaged asset ${ assetId } could not be resolved from package input.` ) ) ;
@@ -189,7 +186,7 @@ export async function loadPackagedProjectRuntime(options = {}) {
189186 } ;
190187 }
191188 const finalizedAsset = finalizeLoadedAsset ( asset , result . asset ) ;
192- if ( sanitizeText ( asset ?. type ) === "vector" ) {
189+ if ( trimSafe ( asset ?. type ) === "vector" ) {
193190 reports . push ( createReport ( "info" , "VECTOR_RUNTIME_READY" , `Prepared vector geometry runtime data for ${ assetId } .` ) ) ;
194191 }
195192 loadedAssets . push ( {
0 commit comments