peachsim 0.1.687 → 0.1.688
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/cli/cloud-client.ts +3 -3
- package/cli/command-registry.ts +2 -0
- package/cli/commands/control.ts +1 -0
- package/cli/commands/debug.ts +10 -33
- package/cli/commands/do-chain.ts +56 -6
- package/cli/commands/inspect/core.ts +2 -0
- package/cli/commands/inspect/list.ts +2 -1
- package/cli/commands/inspect/settling.ts +17 -3
- package/cli/commands/inspect/shared.ts +2 -0
- package/cli/commands/inspect/wait-idle.ts +2 -2
- package/cli/commands/inspect/wait-ready.ts +3 -3
- package/cli/commands/inspect.ts +33 -7
- package/cli/commands/location.ts +164 -0
- package/cli/commands/platform.ts +1 -1
- package/cli/drivers/playwright-sim-host.ts +46 -25
- package/cli/main.ts +6 -0
- package/detox/index.ts +13 -8
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +4 -3
- package/dist-lib/bridge-contract-input.cjs +12 -1
- package/dist-lib/bridge-contract-input.mjs +12 -1
- package/dist-lib/bridge-contract.cjs +4 -3
- package/dist-lib/bridge-contract.mjs +4 -3
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +2 -1
- package/dist-lib/cloud-contract.mjs +2 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +2 -1
- package/dist-lib/cloud.mjs +2 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1197 -65
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +362 -108
- package/dist-lib/host/fetch-proxy-handler.cjs +50 -40
- package/dist-lib/host/fetch-proxy-overrides.cjs +50 -6
- package/dist-lib/host/fetch-proxy-overrides.mjs +48 -5
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +29 -11
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +89 -13
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +5 -3
- package/dist-lib/native-app-identity.cjs +8 -3
- package/dist-lib/native-app-identity.mjs +8 -3
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +21 -6
- package/dist-lib/sdk.mjs +21 -6
- package/dist-lib/skills.cjs +401 -130
- package/dist-lib/swift-compile.cjs +277 -22
- package/dist-lib/swift-compile.mjs +275 -22
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +10 -10
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +280 -44
- package/dist-lib/vite.cjs +1 -1
- package/kotlin/AppSources/android/content/res/Configuration.kt +2 -0
- package/kotlin/AppSources/android/content/res/Resources.kt +6 -3
- package/kotlin/AppSources/android/util/DisplayMetrics.kt +12 -0
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +70 -0
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +12 -10
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +95 -0
- package/kotlin/fixtures/kotlin-app-variants/Bitmaps.kt +50 -0
- package/kotlin/fixtures/kotlin-app-variants/Drawables.kt +53 -0
- package/package.json +2 -2
- package/scripts/dev-server-scanner.ts +3 -1
- package/skills/contrast/SKILL.md +1 -0
- package/src/android-drawables.ts +315 -0
- package/src/android-theme.ts +9 -0
- package/src/bridge-constants.ts +3 -2
- package/src/bridge-contract-input.ts +11 -0
- package/src/bridge-contract.ts +45 -3
- package/src/cloud-contract.ts +1 -0
- package/src/host/fetch-proxy-handler.ts +13 -49
- package/src/host/fetch-proxy-overrides.ts +69 -12
- package/src/kotlin-app.ts +6 -0
- package/src/kotlin-host.ts +103 -15
- package/src/native-app-identity.ts +16 -3
- package/src/swift-compile.ts +366 -24
- package/src/swift-distribution-contract.ts +11 -4
- package/src/swift-distribution.lock.json +11 -9
- package/src/swift-distribution.ts +4 -4
- package/src/swift-icu.ts +8 -11
- package/src/swift-submit.ts +13 -1
- package/src/swift-toolchain.ts +17 -9
- package/src/vite-plugin.ts +86 -34
package/dist-lib/vite-swift.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.688 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -95,7 +95,7 @@ function swiftDistributionHost(platform, arch) {
|
|
|
95
95
|
}
|
|
96
96
|
var isStrings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
97
97
|
function parseSwiftDistributionManifest(value) {
|
|
98
|
-
if (!isRecord(value) || typeof value.id !== "string" || typeof value.release !== "string" || typeof value.wasmSdkChecksum !== "string" || !isStrings(value.modules) || !isStrings(value.objects) || !isStrings(value.link) || !isRecord(value.files) || !Object.values(value.files).every((sha) => typeof sha === "string") || typeof value.host !== "string" || !isStrings(value.plugins)) {
|
|
98
|
+
if (!isRecord(value) || typeof value.id !== "string" || typeof value.release !== "string" || typeof value.wasmSdkId !== "string" || typeof value.wasmSdkUrl !== "string" || typeof value.wasmSdkChecksum !== "string" || !isStrings(value.modules) || !isStrings(value.objects) || !isStrings(value.link) || !isRecord(value.files) || !Object.values(value.files).every((sha) => typeof sha === "string") || typeof value.host !== "string" || !isStrings(value.plugins)) {
|
|
99
99
|
throw new Error(`invalid Swift distribution ${SWIFT_DISTRIBUTION_MANIFEST}`);
|
|
100
100
|
}
|
|
101
101
|
const host2 = SWIFT_DISTRIBUTION_HOSTS.find((candidate) => candidate === value.host);
|
|
@@ -103,6 +103,8 @@ function parseSwiftDistributionManifest(value) {
|
|
|
103
103
|
return {
|
|
104
104
|
id: value.id,
|
|
105
105
|
release: value.release,
|
|
106
|
+
wasmSdkId: value.wasmSdkId,
|
|
107
|
+
wasmSdkUrl: value.wasmSdkUrl,
|
|
106
108
|
wasmSdkChecksum: value.wasmSdkChecksum,
|
|
107
109
|
modules: value.modules,
|
|
108
110
|
objects: value.objects,
|
|
@@ -115,7 +117,7 @@ function parseSwiftDistributionManifest(value) {
|
|
|
115
117
|
};
|
|
116
118
|
}
|
|
117
119
|
function parseSwiftDistributionLock(value) {
|
|
118
|
-
if (!isRecord(value) || typeof value.id !== "string" || !/^[a-f0-9]{16}$/.test(value.id) || typeof value.release !== "string" || typeof value.wasmSdkChecksum !== "string" || typeof value.source !== "string" || !isRecord(value.hosts)) {
|
|
120
|
+
if (!isRecord(value) || typeof value.id !== "string" || !/^[a-f0-9]{16}$/.test(value.id) || typeof value.release !== "string" || typeof value.wasmSdkId !== "string" || typeof value.wasmSdkUrl !== "string" || typeof value.wasmSdkChecksum !== "string" || typeof value.source !== "string" || !isRecord(value.hosts)) {
|
|
119
121
|
throw new Error("invalid Swift distribution lock");
|
|
120
122
|
}
|
|
121
123
|
const hosts = value.hosts;
|
|
@@ -129,6 +131,8 @@ function parseSwiftDistributionLock(value) {
|
|
|
129
131
|
return {
|
|
130
132
|
id: value.id,
|
|
131
133
|
release: value.release,
|
|
134
|
+
wasmSdkId: value.wasmSdkId,
|
|
135
|
+
wasmSdkUrl: value.wasmSdkUrl,
|
|
132
136
|
wasmSdkChecksum: value.wasmSdkChecksum,
|
|
133
137
|
source: value.source,
|
|
134
138
|
hosts: {
|
|
@@ -164,25 +168,25 @@ function memo(cache, key, load2) {
|
|
|
164
168
|
}
|
|
165
169
|
return pending;
|
|
166
170
|
}
|
|
167
|
-
function swiftIcuData(toolchainBin,
|
|
168
|
-
return memo(raw, `${toolchainBin}\0${
|
|
171
|
+
function swiftIcuData(toolchainBin, sdk) {
|
|
172
|
+
return memo(raw, `${toolchainBin}\0${sdk}`, () => load(toolchainBin, sdk));
|
|
169
173
|
}
|
|
170
|
-
function swiftIcuAsset(toolchainBin,
|
|
171
|
-
return memo(assets, `${toolchainBin}\0${
|
|
172
|
-
const zipped = await deflate(await swiftIcuData(toolchainBin,
|
|
174
|
+
function swiftIcuAsset(toolchainBin, sdk) {
|
|
175
|
+
return memo(assets, `${toolchainBin}\0${sdk}`, async () => {
|
|
176
|
+
const zipped = await deflate(await swiftIcuData(toolchainBin, sdk));
|
|
173
177
|
return { sha256: (0, import_node_crypto.createHash)("sha256").update(zipped).digest("hex"), gzip: zipped };
|
|
174
178
|
});
|
|
175
179
|
}
|
|
176
|
-
async function load(toolchainBin,
|
|
180
|
+
async function load(toolchainBin, sdk) {
|
|
177
181
|
const { stdout } = await run(import_node_path.default.join(toolchainBin, "swift"), [
|
|
178
182
|
"sdk",
|
|
179
183
|
"configure",
|
|
180
184
|
"--show-configuration",
|
|
181
|
-
|
|
185
|
+
sdk,
|
|
182
186
|
"wasm32-unknown-wasip1"
|
|
183
187
|
]);
|
|
184
188
|
const resources = /^swiftStaticResourcesPath: (.+)$/m.exec(stdout)?.[1]?.trim();
|
|
185
|
-
if (!resources) throw new Error(`swift-icu: ${
|
|
189
|
+
if (!resources) throw new Error(`swift-icu: ${sdk} names no static resources`);
|
|
186
190
|
return Buffer.from(
|
|
187
191
|
icuSegment(archiveMember((0, import_node_fs.readFileSync)(import_node_path.default.join(resources, ARCHIVE)), MEMBER))
|
|
188
192
|
);
|
|
@@ -311,6 +315,16 @@ function swiftDistributionAt(root) {
|
|
|
311
315
|
if (!(0, import_node_fs2.existsSync)(file)) return null;
|
|
312
316
|
return parseSwiftDistributionManifest(JSON.parse((0, import_node_fs2.readFileSync)(file, "utf8")));
|
|
313
317
|
}
|
|
318
|
+
function swiftModuleSdk(root) {
|
|
319
|
+
const pin = swiftDistributionAt(root) ?? JSON.parse((0, import_node_fs2.readFileSync)(import_node_path2.default.join(root, "toolchain.json"), "utf8"));
|
|
320
|
+
if (!pin || typeof pin !== "object" || typeof Reflect.get(pin, "wasmSdkId") !== "string" || typeof Reflect.get(pin, "wasmSdkUrl") !== "string" || typeof Reflect.get(pin, "wasmSdkChecksum") !== "string")
|
|
321
|
+
throw new Error(`${root} pins no wasm SDK id, url and checksum`);
|
|
322
|
+
return {
|
|
323
|
+
wasmSdkId: String(Reflect.get(pin, "wasmSdkId")),
|
|
324
|
+
wasmSdkUrl: String(Reflect.get(pin, "wasmSdkUrl")),
|
|
325
|
+
wasmSdkChecksum: String(Reflect.get(pin, "wasmSdkChecksum"))
|
|
326
|
+
};
|
|
327
|
+
}
|
|
314
328
|
function swiftModuleInputFiles(root) {
|
|
315
329
|
if (swiftDistributionAt(root)) return [SWIFT_DISTRIBUTION_MANIFEST];
|
|
316
330
|
const files = [
|
|
@@ -322,7 +336,7 @@ function swiftModuleInputFiles(root) {
|
|
|
322
336
|
for (const entry of (0, import_node_fs2.readdirSync)(import_node_path2.default.join(root, dir), { withFileTypes: true })) {
|
|
323
337
|
const relative = `${dir}/${entry.name}`;
|
|
324
338
|
if (entry.isDirectory()) walk(relative);
|
|
325
|
-
else if (/\.(swift|c|h)$/.test(entry.name)) files.push(relative);
|
|
339
|
+
else if (/\.(swift|c|cpp|h)$/.test(entry.name)) files.push(relative);
|
|
326
340
|
}
|
|
327
341
|
};
|
|
328
342
|
walk("Sources");
|
|
@@ -401,7 +415,17 @@ function withNativeSourceGlue(input, glue) {
|
|
|
401
415
|
oneModule: true
|
|
402
416
|
};
|
|
403
417
|
}
|
|
404
|
-
var
|
|
418
|
+
var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
419
|
+
Accelerate: [],
|
|
420
|
+
CryptoKit: [],
|
|
421
|
+
Security: [],
|
|
422
|
+
Statsig: [],
|
|
423
|
+
DatadogCore: [],
|
|
424
|
+
DatadogLogs: ["DatadogCore"],
|
|
425
|
+
DatadogRUM: ["DatadogCore"],
|
|
426
|
+
DatadogTrace: ["DatadogCore"]
|
|
427
|
+
};
|
|
428
|
+
var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
|
|
405
429
|
function swiftTargetDependencies(files, targets) {
|
|
406
430
|
const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
|
|
407
431
|
const siblings = /* @__PURE__ */ new Map();
|
|
@@ -431,12 +455,12 @@ var importsSpriteKit = (files) => Object.entries(files).some(
|
|
|
431
455
|
contents
|
|
432
456
|
)
|
|
433
457
|
);
|
|
434
|
-
var
|
|
458
|
+
var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
|
|
435
459
|
var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
|
|
436
|
-
var MULTI_MANIFEST_VERSION =
|
|
460
|
+
var MULTI_MANIFEST_VERSION = 10;
|
|
437
461
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
438
462
|
const hash = (0, import_node_crypto2.createHash)("sha256");
|
|
439
|
-
hash.update(`swift-compile/
|
|
463
|
+
hash.update(`swift-compile/v12
|
|
440
464
|
${release}
|
|
441
465
|
`);
|
|
442
466
|
if (input.oneModule) hash.update("one-module\n");
|
|
@@ -478,7 +502,7 @@ function emitSwiftPackageManifest(args) {
|
|
|
478
502
|
const reachedFrameworks = new Set(
|
|
479
503
|
[...siblings.values()].flat().filter(
|
|
480
504
|
(name) => OPTIONAL_FRAMEWORKS.has(name) && !targets.some((target) => target.name === name)
|
|
481
|
-
)
|
|
505
|
+
).flatMap((name) => [name, ...OPTIONAL_FRAMEWORK_DEPENDENCIES[name] ?? []])
|
|
482
506
|
);
|
|
483
507
|
const distributionObjects = distribution?.objects.filter(
|
|
484
508
|
(object) => [...OPTIONAL_FRAMEWORKS].every(
|
|
@@ -490,7 +514,7 @@ function emitSwiftPackageManifest(args) {
|
|
|
490
514
|
const stanza = (target) => {
|
|
491
515
|
const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
|
|
492
516
|
const imports = distribution ? `, "-I", ${JSON.stringify(import_node_path2.default.join(moduleRoot, "modules"))}` : "";
|
|
493
|
-
const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${
|
|
517
|
+
const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}])]`;
|
|
494
518
|
const deps = [
|
|
495
519
|
...distribution ? [] : [
|
|
496
520
|
'.product(name: "SwiftUI", package: "sootsim-swift")',
|
|
@@ -560,8 +584,185 @@ var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
|
|
|
560
584
|
var OS_IOS = /\bos\(\s*iOS\s*\)/g;
|
|
561
585
|
var OBJC_ATTRIBUTE = /^@(?:objcMembers\b|objc\b(?:(\s*)\(([^()]*)\))?|IBAction\b)/;
|
|
562
586
|
var SELECTOR = /^#selector\b/;
|
|
587
|
+
var TYPE_AFTER_ATTRIBUTE = /^(?:\s+|\/\/[^\n]*|\/\*[\s\S]*?\*\/|@\w+(?:\([^()]*\))?|\b(?:public|open|final|internal|fileprivate|private|package|nonisolated|indirect)\b)*\b(?:class(?!\s+(?:func|var|let|subscript)\b)|struct|enum|protocol|extension|actor)\b/;
|
|
563
588
|
var DELEGATE_CLASS = /^class\s+[A-Za-z_]\w*\s*(?:<[^>{]*>)?\s*:[^{]*\b(?:UIApplicationDelegate|UISceneDelegate|UIWindowSceneDelegate)\b[^{]*\{/;
|
|
564
|
-
|
|
589
|
+
var REUSABLE_INIT = /^override(?=\s+init\s*\(\s*(?:style\s*:[^,)]*,\s*reuseIdentifier|reuseIdentifier)\s*:)/;
|
|
590
|
+
var REUSABLE_VIEW_BASES = [
|
|
591
|
+
"UICollectionReusableView",
|
|
592
|
+
"UICollectionViewCell",
|
|
593
|
+
"UICollectionViewListCell"
|
|
594
|
+
];
|
|
595
|
+
var CLASS_BASE = /^class\s+([A-Za-z_]\w*)\s*(?:<[^>{]*>)?\s*:\s*([A-Za-z_][\w.]*)[^{]*\{/;
|
|
596
|
+
var FRAME_INIT = /^override(?=\s+(?:(?:public|open|internal)\s+)?init\s*\(\s*frame\s*:)/;
|
|
597
|
+
var APPLE_CLASS = /^(?:UI|NS|CA|SK|WK|MK|AV|PK|CL|GK|PH|SF|AS|QL)[A-Z]/;
|
|
598
|
+
var EXTENSION_DECL = /^extension\s+([A-Za-z_][\w.]*)/;
|
|
599
|
+
var CLASS_DECL = /^class\s+(?!(?:func|var|let|subscript)\b)([A-Za-z_]\w*)/;
|
|
600
|
+
var MODIFIERS = /(?:^|\s)(public|open|internal|fileprivate|private|final|nonisolated|@MainActor)(?=\s)/g;
|
|
601
|
+
var OVERRIDE_FUNC = /^override((?:\s+(?:public|open|internal|fileprivate|private|final|nonisolated|dynamic|@\w+))*)\s+func\s+([A-Za-z_]\w*)\s*(<[^>{}]*>)?\s*\(/;
|
|
602
|
+
var OVERRIDE_VAR = /^override((?:\s+(?:public|open|internal|fileprivate|private|final|nonisolated|dynamic|@\w+))*)\s+var\s+([A-Za-z_]\w*)\s*:\s*([^{=]+?)\s*\{/;
|
|
603
|
+
function splitTopLevel(text) {
|
|
604
|
+
const parts = [];
|
|
605
|
+
let depth = 0;
|
|
606
|
+
let start = 0;
|
|
607
|
+
for (let i = 0; i < text.length; i++) {
|
|
608
|
+
const char = text[i];
|
|
609
|
+
if (char === "(" || char === "[" || char === "<") depth++;
|
|
610
|
+
else if (char === ")" || char === "]" || char === ">" && text[i - 1] !== "-")
|
|
611
|
+
depth--;
|
|
612
|
+
else if (char === "," && depth === 0) {
|
|
613
|
+
parts.push(text.slice(start, i));
|
|
614
|
+
start = i + 1;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
parts.push(text.slice(start));
|
|
618
|
+
return parts.map((part) => part.trim()).filter((part) => part !== "");
|
|
619
|
+
}
|
|
620
|
+
function forwardedArguments(parameters) {
|
|
621
|
+
const args = [];
|
|
622
|
+
for (const parameter of splitTopLevel(parameters)) {
|
|
623
|
+
const match = /^(?:([A-Za-z_]\w*)\s+)?([A-Za-z_]\w*)\s*:\s*([\s\S]*)$/.exec(parameter);
|
|
624
|
+
if (!match || match[3].includes("...")) return null;
|
|
625
|
+
const label = match[1] ?? match[2];
|
|
626
|
+
const value = (/^(?:@\w+\s+)*inout\b/.test(match[3]) ? "&" : "") + match[2];
|
|
627
|
+
args.push(label === "_" ? value : `${label}: ${value}`);
|
|
628
|
+
}
|
|
629
|
+
return args.join(", ");
|
|
630
|
+
}
|
|
631
|
+
function liftExtensionOverrides(source) {
|
|
632
|
+
const { tokens } = swiftCodeScan(source);
|
|
633
|
+
const stack = [];
|
|
634
|
+
let pending = null;
|
|
635
|
+
const classes = /* @__PURE__ */ new Map();
|
|
636
|
+
let declaredBase = null;
|
|
637
|
+
let declaredObjCMembers = false;
|
|
638
|
+
const lifted = [];
|
|
639
|
+
const closing = (open) => {
|
|
640
|
+
let depth = 0;
|
|
641
|
+
for (const at of tokens) {
|
|
642
|
+
if (at < open) continue;
|
|
643
|
+
if (source[at] === "{") depth++;
|
|
644
|
+
else if (source[at] === "}" && --depth === 0) return at + 1;
|
|
645
|
+
}
|
|
646
|
+
return source.length;
|
|
647
|
+
};
|
|
648
|
+
for (const at of tokens) {
|
|
649
|
+
const rest = source.slice(at, at + 600);
|
|
650
|
+
if (rest.startsWith("{")) {
|
|
651
|
+
const frame = pending ?? { kind: "other", name: "" };
|
|
652
|
+
if (frame.kind === "class" && !classes.has(frame.name))
|
|
653
|
+
classes.set(frame.name, {
|
|
654
|
+
brace: at,
|
|
655
|
+
base: declaredBase,
|
|
656
|
+
objcMembers: declaredObjCMembers
|
|
657
|
+
});
|
|
658
|
+
stack.push(frame);
|
|
659
|
+
pending = null;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (rest.startsWith("}")) {
|
|
663
|
+
stack.pop();
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const declared = CLASS_DECL.exec(rest);
|
|
667
|
+
if (declared) {
|
|
668
|
+
pending = { kind: "class", name: declared[1] };
|
|
669
|
+
declaredBase = CLASS_BASE.exec(rest)?.[2]?.split(".").pop() ?? null;
|
|
670
|
+
const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
|
|
671
|
+
declaredObjCMembers = /@objcMembers\b/.test(source.slice(lines, at));
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const extended = EXTENSION_DECL.exec(rest);
|
|
675
|
+
if (extended) {
|
|
676
|
+
pending = { kind: "extension", name: extended[1].split(".").pop() };
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
const top = stack.at(-1);
|
|
680
|
+
if (!rest.startsWith("override") || top?.kind !== "extension" || pending) continue;
|
|
681
|
+
const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
|
|
682
|
+
const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
|
|
683
|
+
const func = OVERRIDE_FUNC.exec(rest);
|
|
684
|
+
if (func) {
|
|
685
|
+
const name = func[2];
|
|
686
|
+
const open = at + func[0].length - 1;
|
|
687
|
+
let depth = 0;
|
|
688
|
+
let close = open;
|
|
689
|
+
for (; close < source.length; close++) {
|
|
690
|
+
if (source[close] === "(") depth++;
|
|
691
|
+
else if (source[close] === ")" && --depth === 0) break;
|
|
692
|
+
}
|
|
693
|
+
const body = tokens.find((token) => token > close && source[token] === "{");
|
|
694
|
+
if (body === void 0) continue;
|
|
695
|
+
const clause = source.slice(close + 1, body).trim();
|
|
696
|
+
const args = forwardedArguments(source.slice(open + 1, close));
|
|
697
|
+
if (args === null) continue;
|
|
698
|
+
const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
|
|
699
|
+
const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
|
|
700
|
+
lifted.push({
|
|
701
|
+
type: top.name,
|
|
702
|
+
member: name,
|
|
703
|
+
stub: `${[...modifiers, "override"].join(" ")} ${signature} { ${call} };`,
|
|
704
|
+
edits: [
|
|
705
|
+
[at, "override".length, " ".repeat("override".length)],
|
|
706
|
+
[
|
|
707
|
+
at + rest.indexOf(
|
|
708
|
+
name,
|
|
709
|
+
rest.indexOf("func", "override".length + func[1].length) + 4
|
|
710
|
+
),
|
|
711
|
+
0,
|
|
712
|
+
"__peach_ext_"
|
|
713
|
+
]
|
|
714
|
+
]
|
|
715
|
+
});
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
const property = OVERRIDE_VAR.exec(rest);
|
|
719
|
+
if (property) {
|
|
720
|
+
const open = at + property[0].length - 1;
|
|
721
|
+
if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
|
|
722
|
+
const name = property[2];
|
|
723
|
+
lifted.push({
|
|
724
|
+
type: top.name,
|
|
725
|
+
member: name,
|
|
726
|
+
stub: `${[...modifiers, "override"].join(" ")} var ${name}: ${property[3].trim()} { __peach_ext_${name} };`,
|
|
727
|
+
edits: [
|
|
728
|
+
[at, "override".length, " ".repeat("override".length)],
|
|
729
|
+
[at + rest.indexOf(name, rest.indexOf("var")), 0, "__peach_ext_"]
|
|
730
|
+
]
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
const overridesObjC = (type, member) => {
|
|
735
|
+
let base = classes.get(type)?.base ?? null;
|
|
736
|
+
while (base !== null) {
|
|
737
|
+
if (APPLE_CLASS.test(base)) return true;
|
|
738
|
+
const declaredClass = classes.get(base);
|
|
739
|
+
if (!declaredClass) return false;
|
|
740
|
+
const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
|
|
741
|
+
const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
|
|
742
|
+
if (found) {
|
|
743
|
+
const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
|
|
744
|
+
return declaredClass.objcMembers || /@objc\b/.test(line);
|
|
745
|
+
}
|
|
746
|
+
base = declaredClass.base;
|
|
747
|
+
}
|
|
748
|
+
return false;
|
|
749
|
+
};
|
|
750
|
+
const edits = [];
|
|
751
|
+
const stubs = /* @__PURE__ */ new Map();
|
|
752
|
+
for (const entry of lifted) {
|
|
753
|
+
const brace = classes.get(entry.type)?.brace;
|
|
754
|
+
if (brace === void 0 || !overridesObjC(entry.type, entry.member)) continue;
|
|
755
|
+
edits.push(...entry.edits);
|
|
756
|
+
stubs.set(brace, [...stubs.get(brace) ?? [], entry.stub]);
|
|
757
|
+
}
|
|
758
|
+
for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
|
|
759
|
+
let out = source;
|
|
760
|
+
for (const [at, remove, insert] of edits.sort((a, b) => b[0] - a[0]))
|
|
761
|
+
out = out.slice(0, at) + insert + out.slice(at + remove);
|
|
762
|
+
return out;
|
|
763
|
+
}
|
|
764
|
+
function swiftSourceAsIOS(original) {
|
|
765
|
+
const source = liftExtensionOverrides(original);
|
|
565
766
|
const { lineStarts, tokens } = swiftCodeScan(source);
|
|
566
767
|
let offset = 0;
|
|
567
768
|
const conditioned = source.split("\n").map((line) => {
|
|
@@ -572,8 +773,30 @@ function swiftSourceAsIOS(source) {
|
|
|
572
773
|
}).join("\n");
|
|
573
774
|
let out = "";
|
|
574
775
|
let copied = 0;
|
|
776
|
+
const reusableViews = new Set(REUSABLE_VIEW_BASES);
|
|
777
|
+
const reusableBodies = [];
|
|
778
|
+
let depth = 0;
|
|
779
|
+
let opensReusableBody = false;
|
|
575
780
|
for (const at of tokens) {
|
|
576
781
|
const rest = conditioned.slice(at, at + 400);
|
|
782
|
+
if (rest.startsWith("{")) {
|
|
783
|
+
depth++;
|
|
784
|
+
if (opensReusableBody) reusableBodies.push(depth);
|
|
785
|
+
opensReusableBody = false;
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
if (rest.startsWith("}")) {
|
|
789
|
+
if (reusableBodies.at(-1) === depth) reusableBodies.pop();
|
|
790
|
+
depth--;
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
if (rest.startsWith("override")) {
|
|
794
|
+
if (REUSABLE_INIT.test(rest) || reusableBodies.at(-1) === depth && FRAME_INIT.test(rest)) {
|
|
795
|
+
out += `${conditioned.slice(copied, at)}required`;
|
|
796
|
+
copied = at + "override".length;
|
|
797
|
+
}
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
577
800
|
const imported = /^import\s+CoreImage\.CIFilterBuiltins\b/.exec(rest);
|
|
578
801
|
if (imported) {
|
|
579
802
|
out += conditioned.slice(copied, at) + "import CoreImage".padEnd(imported[0].length);
|
|
@@ -586,6 +809,11 @@ function swiftSourceAsIOS(source) {
|
|
|
586
809
|
continue;
|
|
587
810
|
}
|
|
588
811
|
if (rest.startsWith("class")) {
|
|
812
|
+
const declared = CLASS_BASE.exec(rest);
|
|
813
|
+
if (declared && reusableViews.has(declared[2].split(".").pop())) {
|
|
814
|
+
reusableViews.add(declared[1]);
|
|
815
|
+
opensReusableBody = true;
|
|
816
|
+
}
|
|
589
817
|
const modifiers = conditioned.slice(conditioned.lastIndexOf("\n", at - 1) + 1, at);
|
|
590
818
|
if (DELEGATE_CLASS.test(rest) && !/\b(?:final|open)\b/.test(modifiers)) {
|
|
591
819
|
out += `${conditioned.slice(copied, at)}final `;
|
|
@@ -600,6 +828,8 @@ function swiftSourceAsIOS(source) {
|
|
|
600
828
|
if (selector) replacement = "#Selector";
|
|
601
829
|
else if (match[0] === "@objcMembers") replacement = "@ObjCMembers";
|
|
602
830
|
else if (match[0] === "@IBAction") replacement = "@ObjC".padEnd(match[0].length);
|
|
831
|
+
else if (TYPE_AFTER_ATTRIBUTE.test(rest.slice(match[0].length)))
|
|
832
|
+
replacement = " ".repeat(match[0].length);
|
|
603
833
|
else if (match[2] !== void 0)
|
|
604
834
|
replacement = `@ObjC${match[1]}("${match[2].trim()}")`;
|
|
605
835
|
out += conditioned.slice(copied, at) + replacement;
|
|
@@ -678,6 +908,9 @@ function swiftCodeScan(source) {
|
|
|
678
908
|
if (hashes > 0) tokens.push(at - 1);
|
|
679
909
|
i = Math.max(at, i + 1);
|
|
680
910
|
}
|
|
911
|
+
} else if (char === "{" || char === "}") {
|
|
912
|
+
tokens.push(i);
|
|
913
|
+
i++;
|
|
681
914
|
} else if (char === "(") {
|
|
682
915
|
top.parens++;
|
|
683
916
|
i++;
|
|
@@ -686,7 +919,7 @@ function swiftCodeScan(source) {
|
|
|
686
919
|
else top.parens--;
|
|
687
920
|
i++;
|
|
688
921
|
} else {
|
|
689
|
-
const keyword = source.startsWith("class", i) ? "class" : source.startsWith("import", i) ? "import" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
|
|
922
|
+
const keyword = source.startsWith("class", i) ? "class" : source.startsWith("extension", i) ? "extension" : source.startsWith("override", i) ? "override" : source.startsWith("import", i) ? "import" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
|
|
690
923
|
if (keyword && !/[\w$]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + keyword.length] ?? "")) {
|
|
691
924
|
tokens.push(i);
|
|
692
925
|
i += keyword.length;
|
|
@@ -741,7 +974,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
741
974
|
}
|
|
742
975
|
if (input.oneModule) {
|
|
743
976
|
const product = '.product(name: "CoreLocation", package: "sootsim-swift"),';
|
|
744
|
-
const flags = `"-Osize"${
|
|
977
|
+
const flags = `"-Osize"${FOUNDATION_IMPLICIT_FLAGS}`;
|
|
745
978
|
if (!manifest.includes(product) || !manifest.includes(flags)) {
|
|
746
979
|
throw new Error(
|
|
747
980
|
"scripts/contrast-app-Package.swift lost the lines the One module links at"
|
|
@@ -865,7 +1098,8 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
865
1098
|
);
|
|
866
1099
|
}
|
|
867
1100
|
const macroPlugins = await ensureMacroPlugins(moduleRoot, options.toolchainBin);
|
|
868
|
-
const
|
|
1101
|
+
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
1102
|
+
const icu = swiftIcuAsset(options.toolchainBin, sdk);
|
|
869
1103
|
try {
|
|
870
1104
|
await run2(
|
|
871
1105
|
swift,
|
|
@@ -876,7 +1110,7 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
876
1110
|
"--package-path",
|
|
877
1111
|
root,
|
|
878
1112
|
"--swift-sdk",
|
|
879
|
-
|
|
1113
|
+
sdk,
|
|
880
1114
|
"-c",
|
|
881
1115
|
"release",
|
|
882
1116
|
"-Xswiftc",
|
|
@@ -1487,22 +1721,24 @@ function extractTarball(tarPath, destDir, stripComponents) {
|
|
|
1487
1721
|
|
|
1488
1722
|
// src/swift-distribution.lock.json
|
|
1489
1723
|
var swift_distribution_lock_default = {
|
|
1490
|
-
id: "
|
|
1724
|
+
id: "37329dbb7d21fea3",
|
|
1491
1725
|
release: "swift-6.3-RELEASE",
|
|
1492
|
-
|
|
1493
|
-
|
|
1726
|
+
wasmSdkId: "swift-6.3-RELEASE_wasm-peach-503c2533",
|
|
1727
|
+
wasmSdkUrl: "https://r2.sootsim.com/swift-wasm-sdk/swift-6.3-RELEASE_wasm-peach-503c2533.artifactbundle.tar.gz",
|
|
1728
|
+
wasmSdkChecksum: "00fd9cc559652638552cc19c27624ea350f30bb866d87c41bbfe97d2ae1810eb",
|
|
1729
|
+
source: "dd8c803162eb6e23ce3fca4ab40d5eedf8717d9f",
|
|
1494
1730
|
hosts: {
|
|
1495
1731
|
"darwin-arm64": {
|
|
1496
|
-
sha256: "
|
|
1497
|
-
size:
|
|
1732
|
+
sha256: "b00c5daa751bd315c8157bddb2dc5037b475c3587e4040d12ccb624bfe3f1bb2",
|
|
1733
|
+
size: 6796662
|
|
1498
1734
|
},
|
|
1499
1735
|
"linux-x64": {
|
|
1500
|
-
sha256: "
|
|
1501
|
-
size:
|
|
1736
|
+
sha256: "d3f00367c7d3858e922574a49f5c80281fecaa0b2fc595f43c6bbdfc1aed9ac6",
|
|
1737
|
+
size: 6802137
|
|
1502
1738
|
},
|
|
1503
1739
|
"linux-arm64": {
|
|
1504
|
-
sha256: "
|
|
1505
|
-
size:
|
|
1740
|
+
sha256: "2b58ae90a2c2c9709a6487ada493e2f556e74db42d16ebb93bc819e60139b363",
|
|
1741
|
+
size: 6801173
|
|
1506
1742
|
}
|
|
1507
1743
|
}
|
|
1508
1744
|
};
|
|
@@ -1527,8 +1763,8 @@ function swiftToolchainBin(release) {
|
|
|
1527
1763
|
return (process.env.PATH ?? "").split(import_node_path6.default.delimiter).find((dir) => dir && import_node_fs5.default.existsSync(import_node_path6.default.join(dir, "swift"))) ?? image;
|
|
1528
1764
|
}
|
|
1529
1765
|
var verified = /* @__PURE__ */ new Map();
|
|
1530
|
-
function swiftToolchain(release,
|
|
1531
|
-
const cached = verified.get(release);
|
|
1766
|
+
function swiftToolchain(release, sdk) {
|
|
1767
|
+
const cached = verified.get(`${release}\0${sdk.wasmSdkId}`);
|
|
1532
1768
|
if (cached) return cached;
|
|
1533
1769
|
const bin = swiftToolchainBin(release);
|
|
1534
1770
|
const swift = import_node_path6.default.join(bin, "swift");
|
|
@@ -1540,26 +1776,26 @@ function swiftToolchain(release, wasmSdkChecksum) {
|
|
|
1540
1776
|
const found = version ? `found ${version.split("\n")[0]?.trim()} at ${swift}` : process.platform === "darwin" ? `found no ${release}.xctoolchain in ~/Library/Developer/Toolchains or /Library/Developer/Toolchains` : "found no swift on PATH";
|
|
1541
1777
|
throw new Error(
|
|
1542
1778
|
`peach compiles Swift with the swift.org toolchain ${release} and its wasm SDK; ${found}.
|
|
1543
|
-
${swiftInstallSteps(release,
|
|
1779
|
+
${swiftInstallSteps(release, sdk)}`
|
|
1544
1780
|
);
|
|
1545
1781
|
}
|
|
1546
1782
|
const sdks = (0, import_node_child_process4.execFileSync)(swift, ["sdk", "list"], {
|
|
1547
1783
|
encoding: "utf8",
|
|
1548
1784
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1549
1785
|
});
|
|
1550
|
-
if (!sdks.split("\n").some((line) => line.trim() ===
|
|
1786
|
+
if (!sdks.split("\n").some((line) => line.trim() === sdk.wasmSdkId)) {
|
|
1551
1787
|
throw new Error(
|
|
1552
|
-
`peach compiles Swift with the ${
|
|
1553
|
-
${swiftInstallSteps(release,
|
|
1788
|
+
`peach compiles Swift with the ${sdk.wasmSdkId} SDK, which ${swift} does not have.
|
|
1789
|
+
${swiftInstallSteps(release, sdk)}`
|
|
1554
1790
|
);
|
|
1555
1791
|
}
|
|
1556
|
-
verified.set(release
|
|
1792
|
+
verified.set(`${release}\0${sdk.wasmSdkId}`, bin);
|
|
1557
1793
|
return bin;
|
|
1558
1794
|
}
|
|
1559
|
-
function swiftInstallSteps(release,
|
|
1795
|
+
function swiftInstallSteps(release, wasmSdk) {
|
|
1560
1796
|
const version = release.replace(/^swift-/, "").toLowerCase();
|
|
1561
1797
|
const downloads = `https://download.swift.org/swift-${version}`;
|
|
1562
|
-
const sdk = `swift sdk install ${
|
|
1798
|
+
const sdk = `swift sdk install ${wasmSdk.wasmSdkUrl} --checksum ${wasmSdk.wasmSdkChecksum}`;
|
|
1563
1799
|
if (process.platform === "darwin") {
|
|
1564
1800
|
const swift = `~/Library/Developer/Toolchains/${release}.xctoolchain/usr/bin/swift`;
|
|
1565
1801
|
return [
|
|
@@ -1592,7 +1828,7 @@ function swiftDistributionRoot() {
|
|
|
1592
1828
|
`peach has no Swift distribution for ${process.platform}-${process.arch}; it ships for macOS arm64 and Linux x64 and arm64`
|
|
1593
1829
|
);
|
|
1594
1830
|
}
|
|
1595
|
-
swiftToolchain(lock.release, lock
|
|
1831
|
+
swiftToolchain(lock.release, lock);
|
|
1596
1832
|
const dir = import_node_path7.default.join(rnxHomeDir(), "swift", `${lock.id}-${host2}`);
|
|
1597
1833
|
let pending = installs.get(dir);
|
|
1598
1834
|
if (!pending) {
|
|
@@ -1629,7 +1865,7 @@ function swiftModuleToolchain(root) {
|
|
|
1629
1865
|
const pin = swiftDistributionAt(root) ?? JSON.parse(import_node_fs6.default.readFileSync(import_node_path7.default.join(root, "toolchain.json"), "utf8"));
|
|
1630
1866
|
return {
|
|
1631
1867
|
release: pin.release,
|
|
1632
|
-
toolchainBin: swiftToolchain(pin.release,
|
|
1868
|
+
toolchainBin: swiftToolchain(pin.release, swiftModuleSdk(root))
|
|
1633
1869
|
};
|
|
1634
1870
|
}
|
|
1635
1871
|
|
|
@@ -1643,7 +1879,7 @@ var MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES = 8 * 1024 * 1024;
|
|
|
1643
1879
|
var MAX_SWIFT_COMPILE_IMAGES = 128;
|
|
1644
1880
|
var MAX_SWIFT_COMPILE_IMAGE_BYTES = 4 * 1024 * 1024;
|
|
1645
1881
|
var MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024;
|
|
1646
|
-
var SWIFT_HOST_ABI =
|
|
1882
|
+
var SWIFT_HOST_ABI = 15;
|
|
1647
1883
|
var POLL_INTERVAL_MS = 1500;
|
|
1648
1884
|
function swiftNativeEntry(native, file) {
|
|
1649
1885
|
return {
|
package/dist-lib/vite.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.688 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -7,6 +7,8 @@ class Configuration {
|
|
|
7
7
|
var uiMode: Int = UI_MODE_TYPE_NORMAL or UI_MODE_NIGHT_NO
|
|
8
8
|
internal var localeTag: String = ""
|
|
9
9
|
|
|
10
|
+
internal fun isNight() = uiMode and UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES
|
|
11
|
+
|
|
10
12
|
fun setTo(other: Configuration) {
|
|
11
13
|
uiMode = other.uiMode
|
|
12
14
|
localeTag = other.localeTag
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
package android.content.res
|
|
2
2
|
|
|
3
|
+
import android.util.DisplayMetrics
|
|
3
4
|
import dev.peach.app.javaFormat
|
|
4
5
|
import dev.peach.app.peachAppArrays
|
|
5
6
|
import dev.peach.app.peachAppColors
|
|
6
7
|
import dev.peach.app.peachAppPlurals
|
|
7
8
|
import dev.peach.app.peachAppStrings
|
|
8
9
|
|
|
9
|
-
class Resources internal constructor(
|
|
10
|
+
class Resources internal constructor(
|
|
11
|
+
val configuration: Configuration,
|
|
12
|
+
val displayMetrics: DisplayMetrics,
|
|
13
|
+
) {
|
|
10
14
|
class NotFoundException(name: String) : RuntimeException(name)
|
|
11
15
|
|
|
12
16
|
// a context's theme; app color resources are plain values, so getColor
|
|
@@ -40,8 +44,7 @@ class Resources internal constructor(val configuration: Configuration) {
|
|
|
40
44
|
// values
|
|
41
45
|
fun getColor(id: Int, theme: Theme?): Int {
|
|
42
46
|
val colors = peachAppColors[id] ?: throw NotFoundException("Resource ID #0x${id.toString(16)}")
|
|
43
|
-
|
|
44
|
-
return colors[if (night) 1 else 0]
|
|
47
|
+
return colors[if (configuration.isNight()) 1 else 0]
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
@Deprecated("Use getColor(int, Theme) instead.")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
package android.util
|
|
2
|
+
|
|
3
|
+
// the display's density as resources read it: densityDpi is the bucketless
|
|
4
|
+
// dots per inch and density its scale over the 160 dpi baseline
|
|
5
|
+
class DisplayMetrics {
|
|
6
|
+
var density: Float = 0f
|
|
7
|
+
var densityDpi: Int = 0
|
|
8
|
+
|
|
9
|
+
companion object {
|
|
10
|
+
const val DENSITY_DEFAULT = 160
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
package androidx.compose.ui.res
|
|
2
|
+
|
|
3
|
+
import android.content.res.Resources
|
|
4
|
+
import androidx.compose.runtime.Composable
|
|
5
|
+
import androidx.compose.runtime.remember
|
|
6
|
+
import androidx.compose.ui.graphics.ImageBitmap
|
|
7
|
+
import androidx.compose.ui.graphics.painter.BitmapPainter
|
|
8
|
+
import androidx.compose.ui.graphics.painter.Painter
|
|
9
|
+
import androidx.compose.ui.graphics.vector.ImageVector
|
|
10
|
+
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
|
11
|
+
import androidx.compose.ui.platform.LocalConfiguration
|
|
12
|
+
import androidx.compose.ui.platform.LocalResources
|
|
13
|
+
import dev.peach.app.PeachDrawable
|
|
14
|
+
import dev.peach.app.peachAppDrawables
|
|
15
|
+
import dev.peach.app.peachDecodeBitmap
|
|
16
|
+
import dev.peach.app.peachDrawable
|
|
17
|
+
|
|
18
|
+
// PainterResources.android.kt, VectorResources.android.kt and
|
|
19
|
+
// ImageResources.android.kt: the drawable file the display's density selects,
|
|
20
|
+
// a vector built for the configuration and cached per configuration as the
|
|
21
|
+
// image vector cache is pruned on a configuration change, or a bitmap
|
|
22
|
+
|
|
23
|
+
@Composable
|
|
24
|
+
fun painterResource(id: Int): Painter {
|
|
25
|
+
val res = LocalResources.current
|
|
26
|
+
val configuration = LocalConfiguration.current
|
|
27
|
+
return when (val drawable = res.drawable(id)) {
|
|
28
|
+
is PeachDrawable.Vector ->
|
|
29
|
+
rememberVectorPainter(remember(id, configuration) { drawable.build(res.configuration.isNight()) })
|
|
30
|
+
is PeachDrawable.Xml -> throw IllegalArgumentException(
|
|
31
|
+
"Only VectorDrawables and rasterized asset types are supported ex. PNG, JPG, WEBP",
|
|
32
|
+
)
|
|
33
|
+
is PeachDrawable.Bitmap ->
|
|
34
|
+
BitmapPainter(remember(drawable.path, id) { peachDecodeBitmap(drawable, res.displayMetrics.densityDpi) })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Composable
|
|
39
|
+
fun ImageVector.Companion.vectorResource(id: Int): ImageVector {
|
|
40
|
+
val res = LocalResources.current
|
|
41
|
+
return remember(id, res, res.configuration) { vectorResource(res, id) }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun ImageVector.Companion.vectorResource(res: Resources, resId: Int): ImageVector =
|
|
45
|
+
when (val drawable = res.drawable(resId)) {
|
|
46
|
+
is PeachDrawable.Vector -> drawable.build(res.configuration.isNight())
|
|
47
|
+
// the parser reads another root tag's missing viewport
|
|
48
|
+
else -> throw IllegalArgumentException("${drawable.path}: <VectorGraphic> tag requires viewportWidth > 0")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Composable
|
|
52
|
+
fun ImageBitmap.Companion.imageResource(id: Int): ImageBitmap {
|
|
53
|
+
val res = LocalResources.current
|
|
54
|
+
val drawable = res.drawable(id)
|
|
55
|
+
return remember(drawable.path) { imageResource(res, id) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// the drawable must be a BitmapDrawable
|
|
59
|
+
fun ImageBitmap.Companion.imageResource(res: Resources, id: Int): ImageBitmap =
|
|
60
|
+
when (val drawable = res.drawable(id)) {
|
|
61
|
+
is PeachDrawable.Bitmap -> peachDecodeBitmap(drawable, res.displayMetrics.densityDpi)
|
|
62
|
+
else -> throw ClassCastException("${drawable.path} is not a BitmapDrawable")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private fun Resources.drawable(id: Int): PeachDrawable =
|
|
66
|
+
peachDrawable(
|
|
67
|
+
peachAppDrawables[id]?.takeUnless { it.isEmpty() }
|
|
68
|
+
?: throw Resources.NotFoundException("Resource ID #0x${id.toString(16)}"),
|
|
69
|
+
displayMetrics.densityDpi,
|
|
70
|
+
)
|