init commit

This commit is contained in:
rxliuli
2025-11-04 05:03:50 +08:00
commit bce557cc2d
1396 changed files with 172991 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
import type {
ClientIdentifier,
Host as NativeHost,
ProcessPlatform,
} from '@jet/environment';
import type {} from '@jet/engine'; // For ClientIdentifier.Unknown
export class Host implements NativeHost {
platform: ProcessPlatform = 'web';
get osBuild(): never {
throw makeWebDoesNotImplementException('osBuild');
}
get deviceModel(): string {
return 'web';
}
get devicePhysicalModel(): never {
throw makeWebDoesNotImplementException('devicePhysicalModel');
}
get deviceLocalizedModel() {
return '';
}
get deviceModelFamily(): never {
throw makeWebDoesNotImplementException('deviceModelFamily');
}
get clientIdentifier(): ClientIdentifier {
// We can't directly use the `ClientIdentifier.Unknown` enum member value
// because we cannot access "ambient const enums" with our TypeScript config.
// Enum handling is known to be tough in TypeScript and, for reasons like
// this, they are generally avoided.
// This returns a value defined on this enum by `@jet/engine`'s type definition
return 'unknown' as ClientIdentifier.Unknown;
}
get clientVersion(): never {
throw makeWebDoesNotImplementException('clientVersion');
}
isOSAtLeast(
_majorVersion: number,
_minorVersion: number,
_patchVersion: number,
): boolean {
return true;
}
}
export function makeWebDoesNotImplementException(property: keyof NativeHost) {
return new Error(
`\`Host\` property \`${property}\` is not implemented for the "web" platform`,
);
}

View File

@@ -0,0 +1,18 @@
import type { Random as IRandom } from '@jet/environment';
import { generateUuid } from '@amp/web-apps-utils';
export class Random implements IRandom {
nextBoolean(): boolean {
// See: https://stashweb.sd.apple.com/projects/AS/repos/jet-infrastructure/browse/Frameworks/JetEngine/JetEngine/JavaScript/Stack/Native%20APIs/JSRandomObject.swift?at=e90a88fa061f5cb6b9536d29a7ffd67e5db942db#41
return Math.random() < 0.5;
}
nextNumber(): number {
// See: https://stashweb.sd.apple.com/projects/AS/repos/jet-infrastructure/browse/Frameworks/JetEngine/JetEngine/JavaScript/Stack/Native%20APIs/JSRandomObject.swift?at=e90a88fa061f5cb6b9536d29a7ffd67e5db942db#45
return Math.random();
}
nextUUID(): string {
return generateUuid();
}
}