@witbitz/sdk 0.0.0-stage → 4.4.0
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/LICENSE +21 -0
- package/README.md +20 -2
- package/a2aCore.js +221 -0
- package/a2aShared.js +27 -0
- package/accountErase.js +228 -0
- package/accountIndexDoc.js +122 -0
- package/accountOwner.js +59 -0
- package/accountRecord.js +90 -0
- package/accountScope.js +114 -0
- package/accountSeal.js +42 -0
- package/accountStores.js +173 -0
- package/acctV2App.js +619 -0
- package/acctV2Check.js +29 -0
- package/acctV2Client.js +382 -0
- package/acctV2Keys.js +43 -0
- package/acctV2Legacy.js +14 -0
- package/acctV2Switch.js +80 -0
- package/acctV2UiCore.js +857 -0
- package/acctV2WebAuthn.js +61 -0
- package/acctV2Wire.js +59 -0
- package/address.js +42 -0
- package/agentDoorTools.js +28 -0
- package/attestedBox.js +30 -0
- package/attestedRooms.js +78 -0
- package/awsKey.js +98 -0
- package/backupRecord.js +106 -0
- package/backupVault.js +97 -0
- package/blocks.js +115 -0
- package/blocksPush.js +64 -0
- package/browseSeal.js +103 -0
- package/cbor.js +225 -0
- package/changePush.js +75 -0
- package/chatLock.js +165 -0
- package/chatLockSw.js +13 -0
- package/cloudDeviceBuilds.js +11 -0
- package/cloudDevicePins.js +33 -0
- package/cloudDeviceSeal.js +53 -0
- package/codeAttachments.js +100 -0
- package/codeBrowse.js +224 -0
- package/codeCache.js +149 -0
- package/codeCloud.js +650 -0
- package/codeCloudKeys.js +112 -0
- package/codeCommands.js +167 -0
- package/codeComputers.js +389 -0
- package/codeEgress.js +123 -0
- package/codeFilesRoutes.js +17 -0
- package/codeFolders.js +116 -0
- package/codeHistory.js +76 -0
- package/codeLanguage.js +54 -0
- package/codeMkdir.js +8 -0
- package/codeModes.js +59 -0
- package/codeOrphanKeys.js +42 -0
- package/codeOutputs.js +141 -0
- package/codeProgress.js +54 -0
- package/codeRelay.js +505 -0
- package/codeSent.js +68 -0
- package/codeSentinel.js +86 -0
- package/codeSubagents.js +107 -0
- package/codeTransport.js +317 -0
- package/codeUndo.js +48 -0
- package/compress.js +24 -0
- package/config.js +11 -0
- package/connCatalog.js +164 -0
- package/connDisp.js +76 -0
- package/connOtherWays.js +74 -0
- package/connPending.js +16 -0
- package/connWrap.js +53 -0
- package/connectionEntry.js +89 -0
- package/connections.js +561 -0
- package/credits.js +30 -0
- package/csAttest.js +112 -0
- package/decrypt.html +384 -0
- package/deviceAttest.js +527 -0
- package/deviceCall.js +54 -0
- package/deviceKeyCore.js +41 -0
- package/deviceSeal.js +59 -0
- package/e2ee.js +323 -0
- package/eat.js +103 -0
- package/emailFork.js +275 -0
- package/emailSignIn.js +81 -0
- package/emptySpaces.js +111 -0
- package/encSource.js +55 -0
- package/enclaveAccept.js +214 -0
- package/enclaveClaim.js +241 -0
- package/enclaveRoute.js +102 -0
- package/enclaveSnapshotMerge.js +44 -0
- package/entrySig.js +165 -0
- package/env.js +73 -0
- package/eraseFile.js +58 -0
- package/followImage.js +86 -0
- package/healNames.js +45 -0
- package/idb.js +113 -0
- package/idbSeal.js +119 -0
- package/indexGone.js +12 -0
- package/invite.js +51 -0
- package/inviteEnroll.js +67 -0
- package/inviteSend.js +68 -0
- package/jobAgents.js +87 -0
- package/keptMerge.js +91 -0
- package/l1-worker-src.js +2 -0
- package/l1-worker.js +894 -0
- package/laneAssociation.js +68 -0
- package/laneConfig.js +58 -0
- package/laneLinkCore.js +177 -0
- package/ledgerView.js +64 -0
- package/manifest.json +239 -0
- package/mcpRecommended.js +25 -0
- package/memberChange.js +125 -0
- package/mirrorBatch.js +47 -0
- package/mkseal.js +101 -0
- package/nativePush.js +153 -0
- package/nitroVerify.js +220 -0
- package/noble-p256.js +27 -0
- package/notice.js +116 -0
- package/notifKey.js +58 -0
- package/offlineBundle.js +62 -0
- package/ohttp.js +177 -0
- package/opRouting.js +10 -0
- package/opencodeWire.js +282 -0
- package/oprf.js +70 -0
- package/ownAgentLink.js +96 -0
- package/ownerPolicy.js +117 -0
- package/package.json +273 -4
- package/pdfOptions.js +13 -0
- package/pdfText.js +107 -0
- package/pdfjs.mjs +28 -0
- package/pdfjs.worker.mjs +28 -0
- package/pollVerdict.js +33 -0
- package/prefetchPoll.js +60 -0
- package/protectedLocal.js +426 -0
- package/pushCore.js +42 -0
- package/recovery.js +107 -0
- package/regions.js +42 -0
- package/removedMessage.js +11 -0
- package/renameRefusal.js +9 -0
- package/replyQuote.js +34 -0
- package/reqEnvelope.js +126 -0
- package/roomDefaultPrefs.js +76 -0
- package/roomDelete.js +109 -0
- package/roomEmbed.js +111 -0
- package/roomName.js +177 -0
- package/roomPass.js +256 -0
- package/roomRoster.js +305 -0
- package/roomSettings.js +61 -0
- package/roomState.js +58 -0
- package/roomStreamClient.js +115 -0
- package/rosterCount.js +52 -0
- package/rosterHash.js +13 -0
- package/rowSchema.js +113 -0
- package/safeMedia.js +116 -0
- package/safeMediaPins.js +17 -0
- package/schedulesDoc.js +78 -0
- package/sdkA2A.js +524 -0
- package/sdkAccount.js +483 -0
- package/sdkAccountDoc.js +89 -0
- package/sdkAccountSections.js +332 -0
- package/sdkAgui.js +141 -0
- package/sdkAttest.js +34 -0
- package/sdkBackup.js +507 -0
- package/sdkBackupV2.js +630 -0
- package/sdkBrowserPrivate.js +28 -0
- package/sdkBuilds.js +208 -0
- package/sdkCloudDevice.js +221 -0
- package/sdkComputers.js +1009 -0
- package/sdkDictation.js +232 -0
- package/sdkErase.js +288 -0
- package/sdkExports.js +71 -0
- package/sdkInvitations.js +34 -0
- package/sdkKeptAgent.js +188 -0
- package/sdkLaneLink.js +205 -0
- package/sdkPlan.js +96 -0
- package/sdkProtect.js +228 -0
- package/sdkRedact.js +36 -0
- package/sdkRekey.js +340 -0
- package/sdkReport.js +68 -0
- package/sdkSafeMedia.js +255 -0
- package/sdkSchedules.js +39 -0
- package/sdkSpeech.js +71 -0
- package/sdkTemporaryRooms.js +123 -0
- package/sdkTurn.js +117 -0
- package/sdkVault.js +180 -0
- package/sealShare.js +18 -0
- package/sealedNames.js +64 -0
- package/sealedReceipt.js +17 -0
- package/sentinelRelease.js +155 -0
- package/shamir.js +85 -0
- package/sharedViews.js +52 -0
- package/sheetChrome.js +450 -0
- package/siri.js +278 -0
- package/spaceClient.js +1429 -0
- package/spaceConfig.js +81 -0
- package/spaceEmailGate.js +813 -0
- package/spaceExport.js +125 -0
- package/spaceFork.js +216 -0
- package/spaceLock.js +358 -0
- package/spacePasskey.js +180 -0
- package/spaceTemplates.js +99 -0
- package/speechOut.js +102 -0
- package/splitKeyClient.js +90 -0
- package/store.js +656 -0
- package/streamHint.js +36 -0
- package/sttCloud.js +220 -0
- package/sttWorklet.js +38 -0
- package/sw-notif-core.js +540 -0
- package/tempList.js +48 -0
- package/tinfoilVerifier.js +78 -0
- package/toolBooks.js +31 -0
- package/toolRules.js +52 -0
- package/turnCerts.js +254 -0
- package/turnFeed.js +58 -0
- package/turnVerdict.js +37 -0
- package/usageReceipts.js +176 -0
- package/usageSummary.js +90 -0
- package/util.js +181 -0
- package/vault-core.js +2326 -0
- package/vault-kit.mjs +354 -0
- package/vault-screens.js +261 -0
- package/vaultAtRest.js +208 -0
- package/vaultCoreLock.js +111 -0
- package/vaultCorePush.js +140 -0
- package/vaultDeviceKey.js +95 -0
- package/vaultEnclaveHandoff.js +114 -0
- package/vaultKeep.js +287 -0
- package/vaultSealedStore.js +77 -0
- package/vaultWorkerHost.js +117 -0
- package/vcWorker.js +34 -0
- package/voiceAttest.js +50 -0
- package/voiceCert.js +51 -0
- package/witbitz-admin.d.ts +135 -0
- package/witbitz-admin.js +529 -0
- package/witbitz-admin.mjs +1460 -0
- package/witbitz-sdk.d.ts +1197 -0
- package/witbitz-sdk.js +4258 -0
- package/workerClient.js +16 -0
- package/workerLiveness.js +21 -0
- package/x509.js +218 -0
package/shamir.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// witz/public/shamir.js — Shamir's Secret Sharing over GF(256) (M3, docs/configurable-space-m3.md).
|
|
2
|
+
//
|
|
3
|
+
// The GENERAL shared-presence key model for a Space: split the room key `mk` into `n` shares so that ANY `k` of them
|
|
4
|
+
// reconstruct it and any `k-1` reveal NOTHING (information-theoretic). Generalizes the 2-of-2 XOR split (the k=n=2 case)
|
|
5
|
+
// to teams — "N members, any k present to open". Pure JS (no WebCrypto) → runs in the browser AND Node.
|
|
6
|
+
//
|
|
7
|
+
// Byte-wise: for each secret byte, a random degree-(k-1) polynomial with the byte as f(0); share j = f(j) at x=1..n;
|
|
8
|
+
// reconstruct via Lagrange interpolation at x=0. A share's wire form is base64url([x, ...yBytes]) — x is the 1-byte
|
|
9
|
+
// evaluation point, the rest are one y-byte per secret byte.
|
|
10
|
+
|
|
11
|
+
// base64url without Buffer (browser-safe; atob/btoa exist in Node 18+ too — same as e2ee.js).
|
|
12
|
+
const b64 = (bytes) => btoa(String.fromCharCode.apply(null, Array.from(bytes))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
13
|
+
const ub64 = (s) => {
|
|
14
|
+
const bin = atob(String(s).replace(/-/g, '+').replace(/_/g, '/'))
|
|
15
|
+
const a = new Uint8Array(bin.length)
|
|
16
|
+
for (let i = 0; i < bin.length; i++) a[i] = bin.charCodeAt(i)
|
|
17
|
+
return a
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ── GF(256) tables (AES field x^8+x^4+x^3+x+1 = 0x11b, generator 3) ──
|
|
21
|
+
const EXP = new Uint8Array(512)
|
|
22
|
+
const LOG = new Uint8Array(256)
|
|
23
|
+
;(function initField() {
|
|
24
|
+
let x = 1
|
|
25
|
+
for (let i = 0; i < 255; i++) {
|
|
26
|
+
EXP[i] = x
|
|
27
|
+
LOG[x] = i
|
|
28
|
+
let x2 = x << 1
|
|
29
|
+
if (x2 & 0x100) x2 ^= 0x11b // x*2 in GF(256)
|
|
30
|
+
x = (x2 ^ x) & 0xff // x = x*3 (the generator)
|
|
31
|
+
}
|
|
32
|
+
for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255] // doubled so mul/div need no modulo
|
|
33
|
+
})()
|
|
34
|
+
const mul = (a, b) => (a === 0 || b === 0 ? 0 : EXP[LOG[a] + LOG[b]])
|
|
35
|
+
const div = (a, b) => (a === 0 ? 0 : EXP[LOG[a] + 255 - LOG[b]]) // b must be non-zero
|
|
36
|
+
|
|
37
|
+
// random bytes (WebCrypto's getRandomValues is a global in browser + Node — it's not part of subtle)
|
|
38
|
+
const rand = (n) => crypto.getRandomValues(new Uint8Array(n))
|
|
39
|
+
|
|
40
|
+
/** Split mk (base64url) into `n` shares (base64url strings); any `k` reconstruct it. Requires 2 ≤ k ≤ n ≤ 255. */
|
|
41
|
+
export function shamirSplit(mk, k, n) {
|
|
42
|
+
const secret = ub64(mk)
|
|
43
|
+
if (!secret.length) throw new Error('shamirSplit needs a key')
|
|
44
|
+
if (!(k >= 2 && k <= n && n <= 255)) throw new Error('need 2 ≤ k ≤ n ≤ 255')
|
|
45
|
+
const shares = []
|
|
46
|
+
for (let j = 1; j <= n; j++) shares.push({ x: j, y: new Uint8Array(secret.length) })
|
|
47
|
+
for (let bi = 0; bi < secret.length; bi++) {
|
|
48
|
+
const coeffs = new Uint8Array(k)
|
|
49
|
+
coeffs[0] = secret[bi] // f(0) = the secret byte
|
|
50
|
+
const rc = rand(k - 1)
|
|
51
|
+
for (let c = 1; c < k; c++) coeffs[c] = rc[c - 1] // random higher coefficients
|
|
52
|
+
for (const s of shares) {
|
|
53
|
+
let y = 0 // Horner: f(x) = ((c_{k-1}·x + c_{k-2})·x + …)·x + c_0
|
|
54
|
+
for (let c = k - 1; c >= 0; c--) y = mul(y, s.x) ^ coeffs[c]
|
|
55
|
+
s.y[bi] = y
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return shares.map((s) => b64(Uint8Array.of(s.x, ...s.y)))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Reconstruct mk (base64url) from ≥ k shares. Fewer than k → a WRONG value (verify with commit()). Order-independent;
|
|
62
|
+
* duplicate x's are rejected. */
|
|
63
|
+
export function shamirCombine(shareStrings) {
|
|
64
|
+
const pts = (shareStrings || []).map((s) => { const a = ub64(s); return { x: a[0], y: a.slice(1) } }).filter((p) => p.x)
|
|
65
|
+
if (pts.length < 2) return null
|
|
66
|
+
const xs = pts.map((p) => p.x)
|
|
67
|
+
if (new Set(xs).size !== xs.length) return null // duplicate share indices
|
|
68
|
+
const len = pts[0].y.length
|
|
69
|
+
const out = new Uint8Array(len)
|
|
70
|
+
for (let bi = 0; bi < len; bi++) {
|
|
71
|
+
let acc = 0
|
|
72
|
+
for (let j = 0; j < pts.length; j++) {
|
|
73
|
+
let num = 1
|
|
74
|
+
let den = 1
|
|
75
|
+
for (let m = 0; m < pts.length; m++) {
|
|
76
|
+
if (m === j) continue
|
|
77
|
+
num = mul(num, pts[m].x) // (0 - x_m) = x_m in GF(256)
|
|
78
|
+
den = mul(den, pts[j].x ^ pts[m].x) // (x_j - x_m) = x_j XOR x_m
|
|
79
|
+
}
|
|
80
|
+
acc ^= mul(pts[j].y[bi], div(num, den)) // y_j · L_j(0)
|
|
81
|
+
}
|
|
82
|
+
out[bi] = acc
|
|
83
|
+
}
|
|
84
|
+
return b64(out)
|
|
85
|
+
}
|
package/sharedViews.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// sharedViews.js — a shared room's VIEWS (its itinerary and maps) as compact text for a private lane's assistant, one
|
|
2
|
+
// rendering for the Spaces app (mirrorLoop.js) and the SDK (witbitz-sdk.js Lane). The lane's assistant cannot read the
|
|
3
|
+
// shared room's widget docs — another room, another key — so the member's device, which holds both keys, writes this text
|
|
4
|
+
// into the lane's sealed `sharedviews` doc, and the lane's turn reads it (agent/asyncTurn.mjs). The SDK never wrote it
|
|
5
|
+
// (sync sweep, 2026-10-10): an SDK lane's assistant could not see the plan everyone else was looking at.
|
|
6
|
+
// Pure — no DOM, no network. spaces/test/sharedViews.test.mjs.
|
|
7
|
+
|
|
8
|
+
export const SHARED_VIEWS_DOC = 'sharedviews'
|
|
9
|
+
export const SHARED_VIEWS_MAX = 12000 // the state allows 32 KB; a long multi-week plan must arrive whole
|
|
10
|
+
|
|
11
|
+
/** `views` = [{ label, state }] (a widget's label and its doc's state) → the text, or '' when there is nothing to say. */
|
|
12
|
+
export function renderSharedViews(views, source = '') {
|
|
13
|
+
const parts = []
|
|
14
|
+
for (const v of Array.isArray(views) ? views : []) {
|
|
15
|
+
const st = v && v.state
|
|
16
|
+
if (!st || typeof st !== 'object') continue
|
|
17
|
+
if (Array.isArray(st.days) && st.days.length) {
|
|
18
|
+
parts.push('ITINERARY' + (st.title ? ' — ' + st.title : '') + '\n' + st.days.map((d) => `${(d && d.name) || 'Day'}: ${((d && d.items) || []).map((i) => `${i && i.when ? i.when + ' — ' : ''}${(i && i.text) || ''}`).filter(Boolean).join('; ')}`).join('\n'))
|
|
19
|
+
} else if (Array.isArray(st.places) && st.places.length) {
|
|
20
|
+
parts.push('MAP (' + String((v && v.label) || 'map').replace(/^\W+\s*/, '') + '): ' + st.places.map((pl) => `${(pl && pl.name) || 'place'}${pl && Number.isFinite(pl.rating) ? ` ★${pl.rating}` : ''}${pl && pl.chosen ? ' (shortlisted)' : ''}`).join(', '))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const chars = Array.from(parts.join('\n\n').slice(0, SHARED_VIEWS_MAX))
|
|
24
|
+
const size = text => new TextEncoder().encode(JSON.stringify({ source, text })).length
|
|
25
|
+
const text = chars.join('')
|
|
26
|
+
if (size(text) <= 32000) return text
|
|
27
|
+
let low = 0, high = chars.length
|
|
28
|
+
while (low < high) {
|
|
29
|
+
const mid = Math.ceil((low + high) / 2)
|
|
30
|
+
if (size(chars.slice(0, mid).join('')) <= 32000) low = mid
|
|
31
|
+
else high = mid - 1
|
|
32
|
+
}
|
|
33
|
+
return chars.slice(0, low).join('')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The views a room's log names: each widget's doc name and label, newest first, at most `max`. */
|
|
37
|
+
export function viewsNamedIn(entries, max = 12) {
|
|
38
|
+
const out = [], seen = new Set()
|
|
39
|
+
const list = Array.isArray(entries) ? entries : []
|
|
40
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
41
|
+
const ws = list[i] && Array.isArray(list[i].widgets) ? list[i].widgets : []
|
|
42
|
+
for (const w of ws) {
|
|
43
|
+
if (!w || typeof w.name !== 'string' || !w.name || seen.has(w.name)) continue
|
|
44
|
+
if (out.length >= max) {
|
|
45
|
+
if (w.name !== 'itinerary' || !out.length) continue
|
|
46
|
+
out.pop()
|
|
47
|
+
}
|
|
48
|
+
seen.add(w.name); out.push({ name: w.name, label: typeof w.title === 'string' && w.title ? w.title : w.name })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out
|
|
52
|
+
}
|
package/sheetChrome.js
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
// sheetChrome.js — ONE chrome for every sheet-shaped card in the app: a grab handle, a round ✕, and one set of ways
|
|
2
|
+
// out (pull the card down, tap the scrim, press Escape). Nine mechanisms and ~55 instances had grown here with
|
|
3
|
+
// different chrome — a Cancel row on one, a handle on another, an ✕ on a third; scrim tap on 11 of 26, Escape on
|
|
4
|
+
// none of them, a pull gesture on five, written three ways (the owner, 2026-09-26: "some cards have cancel instead
|
|
5
|
+
// of a handle — let's make the UI as universal as possible"). This is dep-free DOM: a sheet keeps its own open/close
|
|
6
|
+
// (a `.hidden` class, a `hidden` attribute, whatever it has) and tells this module how to close and whether it is open.
|
|
7
|
+
//
|
|
8
|
+
// attachSheetChrome(root, { card, close, isOpen, scrim?, grab?, x?, body?, mouseFrom?, pull?, head?, onEscape? })
|
|
9
|
+
// root the fixed full-screen layer (often it IS the backdrop) card the panel inside it
|
|
10
|
+
// close closes the sheet (the sheet's own way) isOpen () => boolean
|
|
11
|
+
// scrim a separate backdrop element when the root is not the backdrop
|
|
12
|
+
// grab/x existing handle / close button to adopt instead of inserting ours (the Code steps sheet has both);
|
|
13
|
+
// `x:false` = no ✕ at all (the artifact card and the file viewer — the owner: "the card doesn't need an x.
|
|
14
|
+
// It is better with a handle")
|
|
15
|
+
// body the scrolling region: a pull from it counts only while it is scrolled to the top
|
|
16
|
+
// mouseFrom more elements a MOUSE may drag the card by (the artifact card's title bar)
|
|
17
|
+
// pull () => boolean — whether the pull applies right now (the assistant panel is a rail on a wide screen)
|
|
18
|
+
// Idempotent per root. Returns { head, grab, x }. A card whose CSS moves it by `--wdy` (the artifact card, the file
|
|
19
|
+
// viewer: their wide-screen centring is a transform of their own) is pulled through that variable, not an inline transform.
|
|
20
|
+
// Phase 2 (2026-09-26): the five bespoke gestures — widgetRegistry's attachSheetDrag (artifact card, file viewer, views
|
|
21
|
+
// picker), assistPanel's handle drag, messageActions' who-sheet, the vault's account sheet — are on this module.
|
|
22
|
+
//
|
|
23
|
+
// ★ THE GESTURE, and what it learned on the Code steps sheet (codeSteps.js, 2026-09-25): the pull must listen on a
|
|
24
|
+
// REGION, not a glyph — a 40×5 px pill and a title's text line left most of the card's top dead to a thumb ("dragging
|
|
25
|
+
// it down is sometimes unresponsive"). Here the whole card pulls, minus what scrolls (a scroller not at its top) and
|
|
26
|
+
// what types (a field), and a drag of more than DRAG_PX swallows the click it would otherwise land on a button. A touch
|
|
27
|
+
// the browser takes over (`touchcancel`) resets the card; a short pull springs back; the close threshold is 90 px or a
|
|
28
|
+
// flick. Touch events, not pointer: a pointer drag on a scroller needs `touch-action:none`, which kills the scroll.
|
|
29
|
+
|
|
30
|
+
const CLOSE_PX = 90, FLICK = 0.6 /* px per ms */
|
|
31
|
+
// A DRAG is DRAG_PX of travel, not 8. The 8 px line swallowed TAPS on iOS: WebKit delivers every touchmove, a thumb
|
|
32
|
+
// wobbles 9–15 px in an ordinary tap, and iOS still synthesises the click for that (it is inside its own slop) — so
|
|
33
|
+
// the click landed on the ✕ and was thrown away as "a drag that ended on a button". Chromium never showed it: it hands
|
|
34
|
+
// the page NO touchmove inside its slop (measured 2026-09-27: 14 px of wobble, 0 moves seen, click delivered). The
|
|
35
|
+
// steps sheet's ✕ "does not work" (the owner) while the pull-down does — a deliberate pull is far past any wobble.
|
|
36
|
+
const DRAG_PX = 24
|
|
37
|
+
const attached = new WeakMap() // root → chrome
|
|
38
|
+
const chromeFit = new WeakMap() // root → re-read the card's colour + padding (on each open: a sheet restyled while closed)
|
|
39
|
+
const roots = new Set()
|
|
40
|
+
// When each sheet last OPENED (a counter, not a clock): Escape closes the newest. Attach order lost to the menu's pages
|
|
41
|
+
// (pageHandles.js attaches New Space last, so Escape closed it under the people picker), and DOM order loses to a
|
|
42
|
+
// confirm raised over a sheet that sits after it in the page.
|
|
43
|
+
const openedAt = new WeakMap()
|
|
44
|
+
let openSeq = 0
|
|
45
|
+
let css = false
|
|
46
|
+
|
|
47
|
+
function ensureCss() {
|
|
48
|
+
if (css || typeof document === 'undefined' || typeof document.createElement !== 'function' || !document.head) return // a test's stub document (no head): nothing to dress
|
|
49
|
+
css = true
|
|
50
|
+
const s = document.createElement('style'); s.id = 'sheetChromeCss'
|
|
51
|
+
s.textContent = `
|
|
52
|
+
.sc-head { position:sticky; top:calc(-1 * var(--sc-pt, 0px)); margin-top:calc(-1 * var(--sc-pt, 0px)); padding-top:var(--sc-pt, 0px); z-index:3; background:inherit; border-radius:inherit; border-bottom-left-radius:0; border-bottom-right-radius:0; flex:0 0 auto; min-height:calc(38px + var(--sc-pt, 0px)); touch-action:none; cursor:grab; user-select:none; -webkit-user-select:none; } /* sticky: a card that scrolls keeps its handle and ✕ in reach */
|
|
53
|
+
.sc-grab { position:absolute; left:50%; top:calc(8px + var(--sc-pt, 0px)); width:38px; height:5px; margin-left:-19px; border-radius:3px; background:var(--line, #c8c8cc); opacity:.9; }
|
|
54
|
+
.sc-x { position:absolute; left:0; top:calc(4px + var(--sc-pt, 0px)); width:36px; height:36px; padding:0; border:0; border-radius:50%; display:inline-flex; align-items:center; justify-content:center; background:var(--field, rgba(0,0,0,.06)); color:var(--fg, #111); font:inherit; font-size:18px; line-height:1; cursor:pointer; }
|
|
55
|
+
.sc-x svg { width:22px; height:22px; display:block; } .sc-head:has(+ .sc-title) .sc-x svg { width:24px; height:24px; } /* the owner, 2026-10-14: "The x and < should be larger to match Claude code" (were 18px) */
|
|
56
|
+
@media (hover:hover) { .sc-x:hover { filter:brightness(.95); } }
|
|
57
|
+
.sc-pulling { transition:none !important; }
|
|
58
|
+
.sc-head + .sc-title { position:sticky; top:calc(var(--sc-g, 16px) - 14px - var(--sc-pt, 0px)); z-index:2; pointer-events:none; margin:calc(var(--sc-g, 16px) - 52px - var(--sc-pt, 0px)) calc(-1 * var(--sc-px, 16px)) 0; padding:14px 64px 22px; min-height:44px; line-height:44px; box-sizing:content-box; text-align:center; font-size:17px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; background:linear-gradient(var(--sc-bg, #fff) calc(100% - 14px), transparent); box-shadow:0 min(0px, calc(14px - var(--sc-g, 16px))) 0 0 var(--sc-bg, #fff); border-top-left-radius:inherit; border-top-right-radius:inherit; }
|
|
59
|
+
.sc-title button, .sc-title a, .sc-title input { pointer-events:auto; }
|
|
60
|
+
.sc-title > .sheet-title { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } /* a title row with tools (the Code section): its text cut the same way */
|
|
61
|
+
.sc-scrolled > .sc-head + .sc-title { background:linear-gradient(var(--sc-bg, #fff) 22px, color-mix(in srgb, var(--sc-bg, #fff) 88%, transparent) 40%, color-mix(in srgb, var(--sc-bg, #fff) 62%, transparent) 62%, color-mix(in srgb, var(--sc-bg, #fff) 28%, transparent) 84%, transparent); }
|
|
62
|
+
.sc-head:has(+ .sc-title) { background:transparent; }
|
|
63
|
+
.sc-head:has(+ .sc-title) .sc-grab { top:8px; } /* the handle close to the card's edge, above the ✕ and title row (the owner, 2026-10-12: "a little more up") */
|
|
64
|
+
.sc-head:has(+ .sc-title) .sc-x { width:44px; height:44px; top:var(--sc-g, 16px); left:calc(var(--sc-g, 16px) - var(--sc-px, 16px)); } /* CONCENTRIC with the card's corner (the owner, 2026-10-12: "The x circle should exactly fit the corner curve"): its centre on the corner curve's centre — an even gap all round (--sc-g = radius − 22, read from the card at attach), the title centred on the same line */
|
|
65
|
+
.sc-head:has(+ .sc-title :is(button, a):not(.sc-gone)) { pointer-events:none; } .sc-head:has(+ .sc-title :is(button, a)) .sc-x { pointer-events:auto; }
|
|
66
|
+
.sc-gone { display:none !important; } /* a sheet's own Cancel/Close row once the chrome provides the ✕ — kept in the DOM for its handler */
|
|
67
|
+
/* GLASS (the owner, 2026-10-14, after iOS 26's Liquid Glass ✕ / ⓘ — "the outline … glows at the bottom and top while on
|
|
68
|
+
the sides it is more black"). MEASURED on Claude's ✕ (light, 3× screenshot), and built to it: (1) a HAIRLINE outline, one
|
|
69
|
+
device pixel, ~30% black on the sides fading to ~10% at the top and bottom; (2) the glint is INSIDE the edge — a white
|
|
70
|
+
band under the top and over the bottom, fading into the button; (3) the fill is nearly the card's own colour (translucent
|
|
71
|
+
white over a blur), and the shadow is a breath (~1% at its darkest) — a solid white disc with a 10% shadow read as a
|
|
72
|
+
glowing halo. The outline is a ring masked from a top-to-bottom gradient, so a circle and the wide input pill both work. */
|
|
73
|
+
/* ON A TOUCH SCREEN ONLY (the owner, 2026-10-21: "On desktop don't do the fake glow effect of iOS"): the glass is iOS 26's
|
|
74
|
+
look, and with a mouse it reads as a fake glow — a computer keeps each button's own flat style. */
|
|
75
|
+
@media (hover: none) and (pointer: coarse) {
|
|
76
|
+
:where(.set-back, .cp-x, .conn-filter, .conn-count, #composer .pill, .dw-gear, .gear, .computer-pick, #toApp, #searchBtn, .dw-round) { position:relative; } /* + the ☰ drawer's Settings pill (app .dw-gear, Code .gear) and Code's computer pick */
|
|
77
|
+
.conn-filter, .conn-count { border-color:transparent; } /* the Connections search filter and the connected pill: the outline replaces their grey border */
|
|
78
|
+
:is(.sc-x, .set-back, .cp-x, #lockBack, #scrollBtn, #kbMenuBtn, .conn-filter, .conn-count, #composer .pill, .dw-gear, .gear, .computer-pick, #toApp, #searchBtn, .dw-round)::before { content:''; position:absolute; inset:0; border-radius:inherit; padding:var(--rim-w); pointer-events:none;
|
|
79
|
+
background:linear-gradient(180deg, var(--rim-hi) 0%, var(--rim-lo) 35%, var(--rim-lo) 65%, var(--rim-hi) 100%);
|
|
80
|
+
-webkit-mask:linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite:xor; mask-composite:exclude; }
|
|
81
|
+
:is(.conn-filter, .conn-count)::before { inset:-1px; }
|
|
82
|
+
:root { --rim-w:1px; --rim-hi:rgba(0,0,0,.12); --rim-lo:rgba(0,0,0,.42); }
|
|
83
|
+
@media (min-resolution:2dppx), (-webkit-min-device-pixel-ratio:2) { :root { --rim-w:.5px; } }
|
|
84
|
+
@media (min-resolution:3dppx), (-webkit-min-device-pixel-ratio:3) { :root { --rim-w:.5px; } }
|
|
85
|
+
@media (prefers-color-scheme: light) {
|
|
86
|
+
#scrollBtn { border-color:transparent; } /* glass carries its own rim */
|
|
87
|
+
:is(.sc-x, .set-back, .cp-x, #scrollBtn, #kbMenuBtn, .conn-filter, .conn-count, #composer .pill, .dw-gear, .gear, .computer-pick, #toApp, #searchBtn, .dw-round):not(.conn-filter-on) {
|
|
88
|
+
background:rgba(255,255,255,.28); -webkit-backdrop-filter:blur(12px) saturate(1.6); backdrop-filter:blur(12px) saturate(1.6);
|
|
89
|
+
box-shadow:inset 0 5px 6px -4px #fff, inset 0 -5px 6px -4px #fff, inset 0 0 0 1.5px rgba(255,255,255,.7), 0 3px 14px rgba(0,0,0,.05); }
|
|
90
|
+
}
|
|
91
|
+
@media (prefers-color-scheme: dark) { :root { --rim-hi:rgba(255,255,255,.34); --rim-lo:rgba(0,0,0,.55); } }
|
|
92
|
+
/* PRESSED GLASS — buttons only, never the input box (#composer .pill: the owner, 2026-10-15: a tap to write "also makes the glow animation. This is not needed at all") (the owner, 2026-10-14: "The feedback when pressing a glowing button should be more noticeable" → iOS 26's own:
|
|
93
|
+
it swells and lights from inside the moment the finger lands, and springs back). \`scale\`, not \`transform\`, so a button
|
|
94
|
+
that positions itself with a transform (the scroll-down arrow) keeps it. Reduced motion: the light only. */
|
|
95
|
+
:is(.sc-x, .set-back, .cp-x, #scrollBtn, #kbMenuBtn, .conn-filter, .conn-count, .dw-gear, .gear, .computer-pick, #toApp, #searchBtn, .dw-round) { transition:scale .22s cubic-bezier(.34,1.56,.64,1), filter .18s ease, box-shadow .18s ease; }
|
|
96
|
+
:is(.sc-x, .set-back, .cp-x, #scrollBtn, #kbMenuBtn, .conn-filter, .conn-count, .dw-gear, .gear, .computer-pick, #toApp, #searchBtn, .dw-round):active { scale:1.14; filter:brightness(1.12) saturate(1.1); transition-duration:.08s; box-shadow:inset 0 0 0 1.5px rgba(255,255,255,.9), 0 0 0 5px rgba(255,255,255,.28), 0 6px 22px rgba(0,0,0,.14); }
|
|
97
|
+
/* ↓ grows by its own .pressed (the pages, with its centring translate) — here only the light (the owner, 2026-10-15: "make the down arrow glow too") */
|
|
98
|
+
#scrollBtn:active { scale:none; } #scrollBtn.pressed { filter:brightness(1.12) saturate(1.1); box-shadow:inset 0 0 0 1.5px rgba(255,255,255,.9), 0 0 0 5px rgba(255,255,255,.28), 0 6px 22px rgba(0,0,0,.14); }
|
|
99
|
+
@media (prefers-reduced-motion: reduce) { :is(.sc-x, .set-back, .cp-x, #scrollBtn, #kbMenuBtn, .conn-filter, .conn-count, .dw-gear, .gear, .computer-pick, #toApp, #searchBtn, .dw-round):active { scale:none; } }
|
|
100
|
+
}
|
|
101
|
+
/* NO HANDLE MARK (the owner, 2026-10-14: "let's remove the handle mark itself from every card"): the strip stays — the whole
|
|
102
|
+
card still pulls down to close — only the bar is not drawn. */
|
|
103
|
+
.sc-grab { background:transparent !important; }
|
|
104
|
+
/* A SWITCH ROW DOES NOT FLASH (the owner, 2026-10-16: "When you press the line of a switch just don't do anything. Currently it
|
|
105
|
+
blinks"): no tap highlight on the row; only its switch flips it (guardSwitchTaps below) */
|
|
106
|
+
:is([role="switch"], label:has(> input.set-sw)) { -webkit-tap-highlight-color:transparent; }
|
|
107
|
+
/* NO BLUE ON ANDROID (the owner, 2026-10-27: "when I long press the x … I get a blue background under the x like it is being
|
|
108
|
+
copied" → "I want it to have the glowing effect like in iPhone"): Chrome on Android paints its tap highlight over a pressed
|
|
109
|
+
button and holds it through a long press, on top of the glass. No highlight, no long-press menu or selection on the glass
|
|
110
|
+
buttons: the press is the PRESSED GLASS above — it swells and glows, as on the iPhone. */
|
|
111
|
+
:is(.sc-x, .set-back, .cp-x, #lockBack, #scrollBtn, #kbMenuBtn, .conn-filter, .conn-count, .dw-gear, .gear, .computer-pick, #toApp, #searchBtn, .dw-round) { -webkit-tap-highlight-color:transparent; -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }
|
|
112
|
+
/* GREY, NOT BLUE — EVERYWHERE (the owner, 2026-10-27: "Suppress the blue copy on them too" — "The pen, the three lines, the
|
|
113
|
+
three dots etc" — "when I press an item on the drawer it should be grayed not blue (Same as iPhone)" — "This goes to every
|
|
114
|
+
menu pick" — "Also in the input line"). Android's tap highlight is BLUE and is held through a long press; the iPhone's is a
|
|
115
|
+
soft grey. So the app's highlight is that grey (it is inherited: every menu pick, row and link gets it), and what already has
|
|
116
|
+
its own press look takes none, so nothing is shaded twice: the glass (it glows, above), the top bar's icons (.tb-ic: their
|
|
117
|
+
circle), the drawer (its rows grey themselves, .dw-item:active / .dw-new:active) and the input line (the box and its buttons).
|
|
118
|
+
A long press selects no button's label and opens no menu on it. */
|
|
119
|
+
html { -webkit-tap-highlight-color:color-mix(in srgb, var(--fg, #111) 13%, transparent); }
|
|
120
|
+
:is(.tb-ic, #drawer, #composer, input, textarea, [contenteditable="true"]) { -webkit-tap-highlight-color:transparent; }
|
|
121
|
+
:is(button, [role="button"], summary, #drawer a) { -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }
|
|
122
|
+
`
|
|
123
|
+
document.head.append(s)
|
|
124
|
+
}
|
|
125
|
+
ensureCss() // at load: the rim also dresses buttons no sheet attaches (the scroll-down arrow, the settings pages' ‹)
|
|
126
|
+
|
|
127
|
+
// The way BACK (the owner, 2026-10-10: "It should return to the sheet it came from … maybe the x should be changed to <"):
|
|
128
|
+
// a sheet opened from another sheet wears ‹ in the ✕'s place, and the button returns there (util.js openSheet).
|
|
129
|
+
export const BACK_SVG = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 6l-6 6 6 6"/></svg>'
|
|
130
|
+
// ONLY THE SWITCH FLIPS A SWITCH (the owner, 2026-10-16: "When you toggle you actually need to press the toggle button. Do it
|
|
131
|
+
// everywhere that has a switch"). A switch row is either the switch itself (role="switch", its knob a .set-sw inside) or a label
|
|
132
|
+
// around an <input class="set-sw">; a tap anywhere on the row used to flip it. Now a tap that is not on the knob does nothing.
|
|
133
|
+
// A keyboard's Enter/Space (a click with detail 0), code's .click(), and a field inside the row (Siri's name editor) are untouched.
|
|
134
|
+
let switchGuard = false
|
|
135
|
+
export function guardSwitchTaps (doc = document) {
|
|
136
|
+
if (switchGuard) return; switchGuard = true
|
|
137
|
+
doc.addEventListener('click', (e) => {
|
|
138
|
+
if (!e.detail) return // the keyboard or code
|
|
139
|
+
const t = e.target; if (!t || !t.closest) return
|
|
140
|
+
if (t.closest('.set-sw')) return // the knob: as always
|
|
141
|
+
const row = t.closest('[role="switch"]'), lab = !row && t.closest('label')
|
|
142
|
+
const host = row && row.querySelector('.set-sw') ? row : (lab && lab.querySelector('input.set-sw') ? lab : null)
|
|
143
|
+
if (!host) return
|
|
144
|
+
const act = t.closest('input,textarea,select,[contenteditable="true"],button,a')
|
|
145
|
+
if (act && act !== host && host.contains(act) && !act.classList.contains('dw-link')) return // a control of its own inside the row
|
|
146
|
+
e.preventDefault(); e.stopPropagation()
|
|
147
|
+
}, true)
|
|
148
|
+
}
|
|
149
|
+
try { guardSwitchTaps() } catch { /* no document (a worker / node) */ }
|
|
150
|
+
|
|
151
|
+
export const X_SVG = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>'
|
|
152
|
+
|
|
153
|
+
const isTyping = (t) => !!(t && t.closest && t.closest('input, textarea, select, [contenteditable=""], [contenteditable="true"]'))
|
|
154
|
+
/** The nearest scrolled ancestor inside the card: a pull that starts on one is a scroll, not a dismiss. */
|
|
155
|
+
function scrolledAncestor(t, card) {
|
|
156
|
+
for (let n = t; n && n !== card; n = n.parentElement) {
|
|
157
|
+
if (n.scrollTop > 0) return n
|
|
158
|
+
const o = getComputedStyle(n).overflowY
|
|
159
|
+
if ((o === 'auto' || o === 'scroll') && n.scrollHeight > n.clientHeight && n.scrollTop > 0) return n
|
|
160
|
+
}
|
|
161
|
+
return null
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Can something from `t` up to the card scroll the way the finger is going? A sideways move asks only whether a row
|
|
165
|
+
* there scrolls sideways at all (RTL makes scrollLeft's sign the direction's business, not ours). */
|
|
166
|
+
function scrollsThatWay(t, card, dx, dy, axis = null) {
|
|
167
|
+
const sideways = axis ? axis === 'x' : Math.abs(dx) > Math.abs(dy)
|
|
168
|
+
for (let n = t; n && n.nodeType === 1; n = n.parentElement) {
|
|
169
|
+
const cs = getComputedStyle(n)
|
|
170
|
+
if (sideways) { if (/auto|scroll/.test(cs.overflowX) && n.scrollWidth > n.clientWidth) return true }
|
|
171
|
+
else if (/auto|scroll/.test(cs.overflowY) && n.scrollHeight > n.clientHeight && (dy < 0 ? n.scrollTop + n.clientHeight < n.scrollHeight - 1 : n.scrollTop > 0)) return true
|
|
172
|
+
if (n === card) break
|
|
173
|
+
}
|
|
174
|
+
return false
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ★ A SEARCH HOLDS THE CARD'S HEIGHT (the owner, 2026-10-14: "When you search pin down the search box position and what is
|
|
178
|
+
// above it. Else it can be covered by the composer"). A card is anchored at the bottom, so a list that filters down made it
|
|
179
|
+
// SHORTER and the search box dropped down behind the keyboard and the composer. Once a search field in a card has the focus,
|
|
180
|
+
// the card keeps the height it had (min-height) — the field and everything above it stay put — until the field is left empty.
|
|
181
|
+
if (typeof document !== 'undefined') {
|
|
182
|
+
const cardOf = (t) => (t && t.matches && t.matches('input[type="search"]') && t.closest) ? t.closest('.sheet-card') : null
|
|
183
|
+
// ⛔ …NEVER TALLER THAN THE AREA ABOVE THE KEYS (the owner, 2026-11-16, Settings → Connections → Search services on the iPhone: the
|
|
184
|
+
// field 146 pt above the screen, `vv h544`). The height is measured as the field takes the focus — before the keys are up — and a
|
|
185
|
+
// min-height beats the card's keyboard cap (space.html … .sheet-card max-height): the whole card stayed, its top off the screen.
|
|
186
|
+
// The pin is also kept as --sc-pin, and with the keys up space.html caps it: min(--sc-pin, the visible area).
|
|
187
|
+
document.addEventListener('focusin', (e) => { const c = cardOf(e.target); if (c && !c.style.minHeight) { const h = c.getBoundingClientRect().height + 'px'; c.style.minHeight = h; c.style.setProperty('--sc-pin', h) } }, true)
|
|
188
|
+
document.addEventListener('focusout', (e) => { const c = cardOf(e.target); if (c && !String(e.target.value || '').trim()) { c.style.minHeight = ''; c.style.removeProperty('--sc-pin') } }, true)
|
|
189
|
+
// a card opened again starts at its own height (its sheet's class goes back to hidden on close)
|
|
190
|
+
if (typeof MutationObserver === 'function') new MutationObserver((ms) => { for (const m of ms) { const el = m.target; if (el.classList && el.classList.contains('sheet') && el.classList.contains('hidden')) for (const c of el.querySelectorAll('.sheet-card')) { if (c.style.minHeight) c.style.minHeight = ''; c.style.removeProperty('--sc-pin') } } })
|
|
191
|
+
.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['class'] })
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ★ A FIELD IN A CARD IS SHOWN ABOVE THE KEYS (the owner, 2026-11-09, Outside agents' name field under the composer; 2026-11-15, the
|
|
195
|
+
// email-code card — a box built in JS, class `kbfit`): with the keys up
|
|
196
|
+
// the card is capped to the visible area (space.html, body.kb-open … .sheet-card), so a field low in a long card must be scrolled
|
|
197
|
+
// into the card's view once the keys are up — iOS does not pan a fixed sheet for it.
|
|
198
|
+
if (typeof document !== 'undefined') {
|
|
199
|
+
const fieldIn = (t) => !!(t && t.matches && t.matches('input:not([type="checkbox"]):not([type="radio"]):not([type="button"]), textarea') && t.closest && t.closest('.sheet-card, .kbfit > *'))
|
|
200
|
+
const reveal = (t) => { try { if (document.activeElement === t) t.scrollIntoView({ block: 'nearest' }) } catch { /* */ } }
|
|
201
|
+
// DIAGNOSTICS (the owner, 2026-11-16: "It did not work" — the Connections search on the iPhone, after f991ea03c): what the fit
|
|
202
|
+
// actually saw, in the boot log (Settings → five taps on the build line). The flags, the sizes the rules use, what the iPhone
|
|
203
|
+
// reports, and where the sheet, the card and the field are. Read-only.
|
|
204
|
+
const fitLog = (t, when) => {
|
|
205
|
+
try {
|
|
206
|
+
const b = document.body, cs = getComputedStyle(document.documentElement), vv = window.visualViewport
|
|
207
|
+
const card = t.closest('.sheet-card, .kbfit > *'), sheet = card && card.parentElement
|
|
208
|
+
const r = (el) => { if (!el) return '-'; const x = el.getBoundingClientRect(); return Math.round(x.top) + '+' + Math.round(x.height) }
|
|
209
|
+
const fl = ['inscroll', 'kb-open', 'inscroll-kb', 'embedded', 'in-chat'].filter((c) => b.classList.contains(c)).join(',')
|
|
210
|
+
const line = `sheetfit ${when} #${(sheet && sheet.id) || '?'} flags=${fl || 'none'} html=${['inscroll', 'kb-open'].filter((c) => document.documentElement.classList.contains(c)).join(',') || 'none'}` +
|
|
211
|
+
` vvh=${cs.getPropertyValue('--vvh').trim() || '-'} vvtop=${cs.getPropertyValue('--vvtop').trim() || '-'} vv=${vv ? Math.round(vv.height) + '@' + Math.round(vv.offsetTop) : '-'} ih=${innerHeight} sy=${Math.round(scrollY)}` +
|
|
212
|
+
` sheet=${r(sheet)} card=${r(card)} cardMax=${card ? getComputedStyle(card).maxHeight : '-'} cardScroll=${card ? Math.round(card.scrollTop) : '-'} field=${r(t)}`
|
|
213
|
+
const k = 'space:bootlog', a = JSON.parse(localStorage.getItem(k) || '[]'); a.push(new Date().toISOString().slice(11, 23) + ' ' + line); while (a.length > 1000) a.shift(); localStorage.setItem(k, JSON.stringify(a))
|
|
214
|
+
} catch { /* diagnostics only */ }
|
|
215
|
+
}
|
|
216
|
+
document.addEventListener('focusin', (e) => { const t = e.target; if (!fieldIn(t)) return; fitLog(t, 'focus'); setTimeout(() => fitLog(t, '+350'), 340); setTimeout(() => fitLog(t, '+1200'), 1200); setTimeout(() => reveal(t), 350); try { addEventListener('wb-keys-up', () => reveal(t), { once: true }) } catch { /* */ } }, true)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ★ ONE STYLE READ FOR EVERY CARD AT START (the launch profile, 2026-10-26: the real app's start-up in Chromium with the CPU 4×
|
|
220
|
+
// slow spent 95 ms of its ~170 ms of JavaScript in fitCard/fitHead — each attach changed the page, then read its card's
|
|
221
|
+
// computed style, so every sheet the app attaches as it starts forced its own style recalculation of the whole page). The
|
|
222
|
+
// first fit is queued: before the next frame, every queued card is read, then every one written — one recalculation. A
|
|
223
|
+
// sheet is fitted again as it opens (chromeFit, below) and on resize, as before; only the first measurement waits a frame.
|
|
224
|
+
const fitQueue = []
|
|
225
|
+
let fitArmed = false
|
|
226
|
+
function queueFit (read) {
|
|
227
|
+
fitQueue.push(read)
|
|
228
|
+
if (fitArmed) return
|
|
229
|
+
fitArmed = true
|
|
230
|
+
const run = () => {
|
|
231
|
+
fitArmed = false
|
|
232
|
+
const writes = fitQueue.splice(0).map((r) => { try { return r() } catch { return null } }) // every read first…
|
|
233
|
+
for (const w of writes) { try { if (w) w() } catch { /* */ } } // …then every write
|
|
234
|
+
}
|
|
235
|
+
try { requestAnimationFrame(run) } catch { setTimeout(run, 0) }
|
|
236
|
+
}
|
|
237
|
+
export function attachSheetChrome(root, { card, close, isOpen, scrim = null, grab = null, x = null, body = null, onEscape = null, head: wantHead = true, mouseFrom = [], pull = null, pullFrom = null } = {}) {
|
|
238
|
+
if (!root || !card) return null
|
|
239
|
+
if (attached.has(root)) return attached.get(root)
|
|
240
|
+
ensureCss()
|
|
241
|
+
const noX = x === false; if (noX) x = null
|
|
242
|
+
// The head: adopt the sheet's own handle / ✕ when it has them (the steps sheet), else insert ours as the card's first
|
|
243
|
+
// row. `head:false` = the ways out without the furniture — a centred QUESTION (the confirm) has its answer buttons
|
|
244
|
+
// for chrome; it still pulls, still closes on the scrim and on Escape, all as "no".
|
|
245
|
+
let head = null
|
|
246
|
+
if (!grab && wantHead) {
|
|
247
|
+
head = document.createElement('div'); head.className = 'sc-head'
|
|
248
|
+
grab = document.createElement('div'); grab.className = 'sc-grab'; grab.setAttribute('aria-hidden', 'true')
|
|
249
|
+
head.append(grab)
|
|
250
|
+
card.prepend(head)
|
|
251
|
+
// ★ THE HEAD COVERS THE CARD'S TOP PADDING (the owner, 2026-10-05: "a piece of strip above the handle and x where the
|
|
252
|
+
// text reveals. Again."). Sticky top:0 is the top of the card's CONTENT box, so a scrolled card showed its rows
|
|
253
|
+
// through the padding above the head. --sc-pt pulls the head up over that padding (negative top + margin, the same
|
|
254
|
+
// padding inside it) and moves the handle and ✕ down by it: they sit exactly where they did; only the strip is gone.
|
|
255
|
+
const readHead = () => { const pt = (parseFloat(getComputedStyle(card).paddingTop) || 0) + 'px'; return () => head.style.setProperty('--sc-pt', pt) }
|
|
256
|
+
const fitHead = () => { try { readHead()() } catch { /* */ } }
|
|
257
|
+
queueFit(readHead); try { window.addEventListener('resize', fitHead) } catch { /* */ }
|
|
258
|
+
}
|
|
259
|
+
// ★ THE TITLE, SHARED (the owner, 2026-10-12: the Code section's card "moves the title with the scroll … don't we use a
|
|
260
|
+
// general card layout for this?" → "Let's try to share the title"). The row right after the head — `.sheet-title`
|
|
261
|
+
// (the room sheets, the vault's account sheet) or `.sheet-head` (the Code section: the title and its tools) — is THE
|
|
262
|
+
// title: `.sc-title` sticks it where it rests, beside the ‹/✕, and the rows scroll and fade under it (the CSS above).
|
|
263
|
+
// Each page used to style its own, and the Code page's scrolled away. The band is painted in the card's own colour,
|
|
264
|
+
// read here (--sc-bg), and spans its padding (--sc-px), so one rule fits every card.
|
|
265
|
+
if (head) {
|
|
266
|
+
const t = head.nextElementSibling
|
|
267
|
+
if (t && t.matches('.sheet-title, .sheet-head')) t.classList.add('sc-title')
|
|
268
|
+
const readCard = () => {
|
|
269
|
+
const cs = getComputedStyle(card), bg = cs.backgroundColor, px = (parseFloat(cs.paddingLeft) || 0) + 'px', pt = (parseFloat(cs.paddingTop) || 0) + 'px', g = Math.max((parseFloat(cs.borderTopLeftRadius) || 0) - 22, 12) + 'px'
|
|
270
|
+
return () => { card.style.setProperty('--sc-bg', bg); card.style.setProperty('--sc-px', px); card.style.setProperty('--sc-pt', pt); card.style.setProperty('--sc-g', g) }
|
|
271
|
+
}
|
|
272
|
+
const fitCard = () => { try { readCard()() } catch { /* */ } }
|
|
273
|
+
queueFit(readCard); chromeFit.set(root, fitCard)
|
|
274
|
+
try { window.addEventListener('resize', fitCard); matchMedia('(prefers-color-scheme: dark)').addEventListener('change', fitCard) } catch { /* */ }
|
|
275
|
+
}
|
|
276
|
+
if (!x && wantHead && !noX) { // an adopted ✕ keeps its owner's handler (the steps sheet's turns into a back arrow); ours closes
|
|
277
|
+
x = document.createElement('button'); x.type = 'button'; x.className = 'sc-x'; x.setAttribute('aria-label', 'Close'); x.title = 'Close'; x.innerHTML = X_SVG
|
|
278
|
+
;(head || grab.parentElement || card).append(x)
|
|
279
|
+
x.addEventListener('click', (e) => { e.stopPropagation(); close() })
|
|
280
|
+
}
|
|
281
|
+
// Scrim: the root itself when it is the backdrop (a tap beside the card lands on it), else the element given. A card
|
|
282
|
+
// that IS its own root (the artifact card, the file viewer) has no backdrop of its own here — its scrim is `scrim`.
|
|
283
|
+
if (root !== card) root.addEventListener('click', (e) => { if (e.target === root) close() })
|
|
284
|
+
if (scrim) scrim.addEventListener('click', () => close())
|
|
285
|
+
// A WHEEL over the backdrop is a reach for the page beneath — it closes the sheet like a tap there (the owner, 2026-10-10,
|
|
286
|
+
// desktop Settings: "when touching the underneath scroll it should hide the settings (like any other tap)"). Inside the card
|
|
287
|
+
// the wheel scrolls the card; the target test keeps it apart.
|
|
288
|
+
if (root !== card) root.addEventListener('wheel', (e) => { if (e.target === root) close() }, { passive: true })
|
|
289
|
+
if (scrim) scrim.addEventListener('wheel', () => close(), { passive: true })
|
|
290
|
+
// The pull. A card whose stylesheet already moves it by `--wdy` keeps its own transform (the wide-screen centring is
|
|
291
|
+
// `translateX(-50%) translateY(var(--wdy))` — an inline transform would drop the centring mid-pull); anything else
|
|
292
|
+
// is moved by an inline transform.
|
|
293
|
+
const byVar = () => getComputedStyle(card).getPropertyValue('--wdy').trim() !== ''
|
|
294
|
+
const place = (dy) => { if (byVar()) { card.style.setProperty('--wdy', dy + 'px'); card.style.transform = '' } else card.style.transform = dy ? `translateY(${dy}px)` : '' }
|
|
295
|
+
let y0 = null, t0 = 0, dy = 0, dragged = false, scroller = null
|
|
296
|
+
const reset = () => { y0 = null; card.classList.remove('sc-pulling'); card.style.transform = ''; card.style.removeProperty('--wdy') }
|
|
297
|
+
const mayPull = () => isOpen() && (!pull || pull())
|
|
298
|
+
// The open animation must not fight the finger, and it must NOT RESTART when the finger lifts. `.sc-pulling` used to
|
|
299
|
+
// carry `animation:none !important` for that — but a CSS animation whose property goes none → <name> starts over, so
|
|
300
|
+
// EVERY touch on the card (a tap on a row: touchstart, touchend) replayed the slide-in the moment the class came off.
|
|
301
|
+
// Measured on the Code steps sheet (2026-09-27): a bare touchstart+touchend on a row, and the card is at translateY
|
|
302
|
+
// +213 px and sliding for 260 ms; the click iOS fires after the touchend lands where the finger was — above the card,
|
|
303
|
+
// on the backdrop — and the backdrop CLOSES the sheet ("pressing the nested cards doesn't work", the owner). Finishing
|
|
304
|
+
// the running animations instead jumps them to their end state and leaves the property alone: nothing to restart.
|
|
305
|
+
const settleAnimations = () => { try { for (const a of card.getAnimations()) a.finish() } catch { /* an engine without the Web Animations API keeps its animation */ } }
|
|
306
|
+
const start = (e) => {
|
|
307
|
+
if (!mayPull() || e.touches.length !== 1 || isTyping(e.target)) return
|
|
308
|
+
// A ZOOMABLE card pulls only from its top (the owner, 2026-10-16: "Because it is zoomable it is better to disable the drag
|
|
309
|
+
// … Enable it only at the top"): `pullFrom` lists where a pull may start (the handle strip, the title bar).
|
|
310
|
+
if (Array.isArray(pullFrom) && !pullFrom.some((el) => el && el.contains(e.target))) return
|
|
311
|
+
scroller = scrolledAncestor(e.target, card); if (scroller) return
|
|
312
|
+
// THE CARD ITSELF may be the scroller (a grouped menu, Settings): scrolled down, a drag in it is a scroll — except on
|
|
313
|
+
// the pinned head, which is exactly where a pull to close belongs.
|
|
314
|
+
if (card.scrollTop > 0 && !(head && head.contains(e.target)) && e.target !== grab) return
|
|
315
|
+
y0 = e.touches[0].clientY; t0 = performance.now(); dy = 0; dragged = false
|
|
316
|
+
settleAnimations(); card.classList.add('sc-pulling'); place(0)
|
|
317
|
+
}
|
|
318
|
+
const move = (e) => {
|
|
319
|
+
if (y0 == null) return
|
|
320
|
+
if (axis === 'x') { reset(); return } // a sideways gesture never pulls the card
|
|
321
|
+
// The body began scrolling after all (it was at the top, the finger went up then down): hand the gesture back.
|
|
322
|
+
if (((body && body.scrollTop > 0) || card.scrollTop > 0) && e.target !== grab && !(head && head.contains(e.target))) { reset(); return }
|
|
323
|
+
dy = Math.max(0, e.touches[0].clientY - y0); if (dy > DRAG_PX) dragged = true
|
|
324
|
+
place(dy)
|
|
325
|
+
}
|
|
326
|
+
const end = () => {
|
|
327
|
+
if (y0 == null) return
|
|
328
|
+
const flick = dy / Math.max(1, performance.now() - t0)
|
|
329
|
+
const out = dy > CLOSE_PX || (dy > 30 && flick > FLICK)
|
|
330
|
+
reset()
|
|
331
|
+
if (out) { dragged = false; close() } // close() may click the sheet's own Cancel — that click must not be swallowed below
|
|
332
|
+
}
|
|
333
|
+
// ⛔ A DRAG ON A SHEET NEVER SCROLLS WHAT IS UNDER IT (the owner, 2026-10-06, an iPhone: "When a card is dragged the sheet
|
|
334
|
+
// under it scrolls … It is inconsistent"). iOS hands a touchmove nothing in the card can use to the page beneath — the
|
|
335
|
+
// chat scrolled under the Connections sheet (its content fits: no scroller) while a long sheet, scrolling itself, did
|
|
336
|
+
// not. This listener was passive, so it moved the card but could never stop that. Now a move is refused unless
|
|
337
|
+
// something inside the card scrolls that way, or the finger is in a field; the scrim beside the card refuses them all.
|
|
338
|
+
// ★ ONE AXIS PER GESTURE (the owner, 2026-10-14, the room map's sideways row: "It jitters"). The direction was decided
|
|
339
|
+
// again on every move, so a sideways swipe that drifted a pixel down read as vertical for that move and was refused —
|
|
340
|
+
// the native scroll stuttered — and the pull-down followed the drift, so the card wobbled. Now the first ~8 px decide
|
|
341
|
+
// it, and it holds until the finger lifts: sideways scrolls sideways only, and never pulls the card.
|
|
342
|
+
let gx = 0, gy = 0, sx = 0, sy = 0, axis = null
|
|
343
|
+
const AXIS_PX = 8
|
|
344
|
+
const track = (e) => { const p = e.touches[0]; if (p) { gx = sx = p.clientX; gy = sy = p.clientY; axis = null } }
|
|
345
|
+
const guard = (e) => {
|
|
346
|
+
const p = e.touches[0]; if (!p || e.touches.length !== 1) return // a pinch is the browser's
|
|
347
|
+
const dx = p.clientX - gx, dy = p.clientY - gy; gx = p.clientX; gy = p.clientY
|
|
348
|
+
if (!axis) { const tx = p.clientX - sx, ty = p.clientY - sy; if (Math.abs(tx) + Math.abs(ty) >= AXIS_PX) axis = Math.abs(tx) > Math.abs(ty) ? 'x' : 'y' }
|
|
349
|
+
if (!e.cancelable || !isOpen() || (!dx && !dy) || isTyping(e.target)) return
|
|
350
|
+
if (!scrollsThatWay(e.target, card, dx, dy, axis)) e.preventDefault()
|
|
351
|
+
}
|
|
352
|
+
card.addEventListener('touchstart', track, { passive: true })
|
|
353
|
+
card.addEventListener('touchstart', start, { passive: true })
|
|
354
|
+
card.addEventListener('touchmove', (e) => { guard(e); move(e) }, { passive: false })
|
|
355
|
+
// ★ GROWTH GLIDES (the owner, 2026-10-06: a card "does a little vertical expansion right after. A jump." → "Maybe we can
|
|
356
|
+
// just do a progressive animation"). A sheet whose content arrives after it opened (Settings → Siri waits on the
|
|
357
|
+
// Sentinel) grew in one frame, and anchored at the bottom its top jumped. Now when an open card GROWS, its top glides
|
|
358
|
+
// from where it was to where it is: FLIP on transform, started before the frame paints (a ResizeObserver runs after
|
|
359
|
+
// layout). Only growth — a shrinking card would lift off its bottom edge — and never mid-pull, never during its own open
|
|
360
|
+
// animation, never on a card moved by --wdy, never under reduced motion, never when the window itself changed size —
|
|
361
|
+
// and never for what the user just did: a tap or a key in the card that opens a field shows it at once, under the
|
|
362
|
+
// finger (the Code picker's "New folder"); only content that ARRIVES on its own (the network's answer) glides in.
|
|
363
|
+
if (typeof ResizeObserver === 'function') {
|
|
364
|
+
let last = null, actedAt = -1e9
|
|
365
|
+
const acted = () => { actedAt = performance.now() }
|
|
366
|
+
for (const ev of ['pointerdown', 'keydown', 'input']) card.addEventListener(ev, acted, { capture: true, passive: true })
|
|
367
|
+
new ResizeObserver(() => {
|
|
368
|
+
const r = card.getBoundingClientRect(), prev = last
|
|
369
|
+
last = { top: r.top, h: r.height, vh: window.innerHeight }
|
|
370
|
+
if (!prev || !isOpen() || y0 != null || r.height <= prev.h || prev.vh !== window.innerHeight || byVar()) return
|
|
371
|
+
if (performance.now() - actedAt < 700) return
|
|
372
|
+
const d = prev.top - r.top; if (d < 4) return
|
|
373
|
+
try { if (matchMedia('(prefers-reduced-motion: reduce)').matches) return } catch { /* */ }
|
|
374
|
+
try {
|
|
375
|
+
if (card.getAnimations().some((a) => a.id !== 'sc-grow' && a.playState === 'running')) return // its own open slide is moving it
|
|
376
|
+
card.animate([{ transform: `translateY(${d}px)` }, { transform: 'translateY(0)' }], { duration: 220, easing: 'cubic-bezier(.32,.72,.24,1)', id: 'sc-grow' })
|
|
377
|
+
} catch { /* no Web Animations: it takes its new size at once, as before */ }
|
|
378
|
+
}).observe(card)
|
|
379
|
+
}
|
|
380
|
+
const still = (e) => { if (e.cancelable && isOpen() && !card.contains(e.target)) e.preventDefault() }
|
|
381
|
+
if (root !== card) root.addEventListener('touchmove', still, { passive: false })
|
|
382
|
+
if (scrim) scrim.addEventListener('touchmove', still, { passive: false })
|
|
383
|
+
card.addEventListener('touchend', end)
|
|
384
|
+
card.addEventListener('touchcancel', reset)
|
|
385
|
+
// A MOUSE can drag the head too (a desktop courtesy, and what the views-picker test does). Mouse only — a finger is
|
|
386
|
+
// handled above, and a pointer drag on the scrolling body would need touch-action:none, which kills the scroll.
|
|
387
|
+
// ⛑ The surface is OUR head, or an adopted handle's own row when it has one — never the card. The steps sheet's grab
|
|
388
|
+
// is a direct child of its card, and `grab.parentElement` made the whole card the surface; with pointer CAPTURE on
|
|
389
|
+
// it, the browser retargeted every mouseup — and so every click — onto the card, and a step row could not be
|
|
390
|
+
// opened (two opencodeSection tests). So: no capture; the move/up ride the document only while a drag is on.
|
|
391
|
+
const dragSurface = head || (grab && grab.parentElement !== card ? grab.parentElement : grab) || null
|
|
392
|
+
const surfaces = [dragSurface, ...mouseFrom].filter(Boolean)
|
|
393
|
+
if (surfaces.length) {
|
|
394
|
+
let pid = null
|
|
395
|
+
const pmove = (e) => { if (pid == null || e.pointerId !== pid) return; dy = Math.max(0, e.clientY - y0); if (dy > DRAG_PX) dragged = true; place(dy) }
|
|
396
|
+
const off = () => { pid = null; document.removeEventListener('pointermove', pmove); document.removeEventListener('pointerup', pend); document.removeEventListener('pointercancel', pcancel) }
|
|
397
|
+
const pend = (e) => { if (pid == null || e.pointerId !== pid) return; off(); end() }
|
|
398
|
+
const pcancel = (e) => { if (pid == null || e.pointerId !== pid) return; off(); reset() }
|
|
399
|
+
for (const s of surfaces) s.addEventListener('pointerdown', (e) => {
|
|
400
|
+
if (e.pointerType !== 'mouse' || e.button !== 0 || pid != null || !mayPull() || e.target === x || (x && x.contains(e.target)) || (e.target.closest && e.target.closest('button, a, input, select, textarea') && e.target !== s)) return
|
|
401
|
+
pid = e.pointerId; y0 = e.clientY; t0 = performance.now(); dy = 0; dragged = false; settleAnimations(); card.classList.add('sc-pulling'); place(0)
|
|
402
|
+
document.addEventListener('pointermove', pmove); document.addEventListener('pointerup', pend); document.addEventListener('pointercancel', pcancel)
|
|
403
|
+
})
|
|
404
|
+
}
|
|
405
|
+
// SCROLLED: a card whose rows have scrolled up under its title says so (`sc-scrolled`), so the title's fade can grow only
|
|
406
|
+
// then — a long fade at rest would fade the first row (the owner, 2026-10-11: "Is there a fade out? I can hardly see").
|
|
407
|
+
const markScrolled = () => card.classList.toggle('sc-scrolled', card.scrollTop > 2)
|
|
408
|
+
card.addEventListener('scroll', markScrolled, { passive: true })
|
|
409
|
+
// A drag that ended on a button must not press it: the browser's own click after a touch (trusted) is swallowed once.
|
|
410
|
+
card.addEventListener('click', (e) => { if (dragged && e.isTrusted) { dragged = false; e.stopPropagation(); e.preventDefault() } }, true)
|
|
411
|
+
const chrome = { root, card, head, grab, x, close, isOpen, scrim, onEscape: onEscape || close } // a two-view sheet goes BACK on Escape first
|
|
412
|
+
attached.set(root, chrome); roots.add(root)
|
|
413
|
+
let wasOpen = false
|
|
414
|
+
const stamp = () => { const now = !!isOpen(); if (now && !wasOpen) { openedAt.set(root, ++openSeq); const f = chromeFit.get(root); if (f) f() } wasOpen = now }
|
|
415
|
+
stamp()
|
|
416
|
+
try { new MutationObserver(stamp).observe(root, { attributes: true, attributeFilter: ['class', 'style', 'hidden'] }) } catch { /* no observer: attach order decides, as before */ }
|
|
417
|
+
return chrome
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** The TOPMOST open sheet — the one opened last among those open, the order they stack in. */
|
|
421
|
+
function topSheet() {
|
|
422
|
+
let top = null
|
|
423
|
+
for (const r of roots) { // an artifact card that left the DOM (a re-render) is forgotten here rather than kept for ever
|
|
424
|
+
if (!r.isConnected) { roots.delete(r); continue }
|
|
425
|
+
const c = attached.get(r); if (!c || !c.isOpen()) continue
|
|
426
|
+
if (!top || (openedAt.get(r) || 0) >= (openedAt.get(top.root) || 0)) top = c
|
|
427
|
+
}
|
|
428
|
+
return top
|
|
429
|
+
}
|
|
430
|
+
/** Escape closes the topmost open sheet. */
|
|
431
|
+
function onKey(e) {
|
|
432
|
+
if (e.key !== 'Escape') return
|
|
433
|
+
if (e.target && e.target.closest && e.target.closest('[data-keeps-escape]')) return // a field that undoes its own edit on Escape (siriSheet's alias)
|
|
434
|
+
const top = topSheet()
|
|
435
|
+
if (top) { e.stopImmediatePropagation(); top.onEscape() }
|
|
436
|
+
}
|
|
437
|
+
if (typeof document !== 'undefined') document.addEventListener('keydown', onKey, true)
|
|
438
|
+
// A press on the PAGE'S OWN SCROLLBAR closes the topmost sheet, like a tap beside it. The scrollbar is outside the page, so
|
|
439
|
+
// the backdrop never sees it; the browser reports it as a press on the root element itself, which nothing else produces.
|
|
440
|
+
if (typeof document !== 'undefined') document.addEventListener('pointerdown', (e) => {
|
|
441
|
+
if (e.target !== document.documentElement) return
|
|
442
|
+
const top = topSheet(); if (top) top.close()
|
|
443
|
+
}, true)
|
|
444
|
+
|
|
445
|
+
/** For tests: which attached sheets are open right now. */
|
|
446
|
+
export const openSheets = () => [...roots].filter((r) => r.isConnected && attached.get(r).isOpen())
|
|
447
|
+
/** Is `t` inside an open sheet — its layer, or the separate scrim of a card that is its own root? A gesture of the page
|
|
448
|
+
* beneath (the drawer's edge drag) must not start there: the owner, 2026-10-06, dragged a sheet's upper-left corner and
|
|
449
|
+
* the drawer opened under it. */
|
|
450
|
+
export const inOpenSheet = (t) => !!t && openSheets().some((r) => { const c = attached.get(r); return r.contains(t) || !!(c.scrim && c.scrim.contains(t)) })
|