Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

tray/android: find a document by something inside it, and create one safely (#363)

nyblnet5f1f912d3696
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index faafc820..4a198779 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -979,10 +979,34 @@ trade at this level of consequence, and it is already this repo's idiom for
exactly this problem — the splice contract has a conformance gate in
`release.mjs`, the save-purpose ids have `scripts/test-savepurpose.ts`.
-**Status: not built.** Nothing here has been implemented. The cheap intermediate
-step, if it is wanted before the full library, is a name filter over the existing
-Android recents list — that brings Android level with iOS and touches no
-extraction. Parity table and the standing gap: `tray/README.md` § Android.
+**Status (2026-08-16, later): BUILT ON ANDROID; iOS still to do.** The shape
+above survived contact. `tray/doc-index.mjs` is the reference, `tray/fixtures/`
+is the corpus (11 cases), `scripts/test-doc-index.mjs` and a JVM unit test hold
+the JS and Kotlin implementations to it, and `tray/android` indexes granted
+folders and searches their prose. The iOS session has been handed the same brief.
+
+Two things the corpus caught that reasoning had not:
+
+- **A single string value over 400 characters is not indexed at all.** The value
+ regex is capped at `{1,400}`, so a long speaker note or a wordy text element is
+ invisible to search — in all three hosts, today. Pinned by `longvalue.html` so
+ no port can quietly "fix" it into divergence; changing it has to be a
+ deliberate change everywhere.
+- **JavaScript's `\s` is Unicode-aware and Java's is not** (and Java's
+ `UNICODE_CHARACTER_CLASS` still excludes U+FEFF), so a port spelling it `\s`
+ leaves non-breaking and ideographic spaces in the indexed text and a phrase
+ search across one silently fails. The class is written out in full;
+ `whitespace.html` catches it, verified by mutation.
+
+**Thumbnails are in, and the reasoning that nearly excluded them was wrong.**
+"the preview is HTML, so a native list needs a WebView per row" conflated two
+different things: a WebView per scrolling row (the design this entry rejects) and
+ONE offscreen WebView at index time producing cached bitmaps (which costs nothing
+at launch and leaves the list plain `ImageView`s). The second is the obvious
+design and it was talked past. Details and the three ways an offscreen render
+silently produces the wrong picture: `tray/README.md` § Document search.
+
+Parity table: `tray/README.md` § Android.
## 2026-08-16 — bento/tray gets an Android host (PR #87, rearchitected)
diff --git a/scripts/gen-doc-index-expected.mjs b/scripts/gen-doc-index-expected.mjs
new file mode 100644
index 00000000..d01484aa
--- /dev/null
+++ b/scripts/gen-doc-index-expected.mjs
@@ -0,0 +1,48 @@
+#!/usr/bin/env node
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// Regenerates tray/fixtures/expected.json from the reference indexer.
+// Run this after changing tray/doc-index.mjs or adding a case, then re-run
+// EVERY host's rig — see tray/fixtures/README.md.
+//
+// node scripts/gen-doc-index-expected.mjs
+
+import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
+import { createHash } from 'node:crypto'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+import { describe, TEXT_BUDGET, SNIFF_BYTES, HEAD_BYTES } from '../tray/doc-index.mjs'
+
+const root = join(dirname(fileURLToPath(import.meta.url)), '..')
+const dir = join(root, 'tray/fixtures')
+const sha = (s) => createHash('sha256').update(s, 'utf8').digest('hex').slice(0, 16)
+
+const cases = {}
+for (const f of readdirSync(join(dir, 'cases')).sort()) {
+ const d = describe(readFileSync(join(dir, 'cases', f), 'utf8'))
+ const e = {
+ isDocument: d.isDocument,
+ title: d.title,
+ app: d.app,
+ encrypted: d.encrypted,
+ hasPreview: d.preview !== null,
+ textLength: d.text === null ? null : d.text.length,
+ textSha256_16: d.text === null ? null : sha(d.text),
+ }
+ // Verbatim for the short cases, so the answer key is readable by a human and
+ // not only checkable by a machine.
+ if (d.text !== null && d.text.length <= 200) e.text = d.text
+ cases[f] = e
+}
+
+writeFileSync(join(dir, 'expected.json'), JSON.stringify({
+ note: 'GENERATED by scripts/gen-doc-index-expected.mjs from tray/doc-index.mjs. See README.md here.',
+ textBudget: TEXT_BUDGET,
+ sniffBytes: SNIFF_BYTES,
+ headBytes: HEAD_BYTES,
+ cases,
+}, null, 2) + '\n')
+
+console.log(`regenerated expected.json for ${Object.keys(cases).length} cases`)
diff --git a/scripts/test-doc-index.mjs b/scripts/test-doc-index.mjs
new file mode 100644
index 00000000..893e6323
--- /dev/null
+++ b/scripts/test-doc-index.mjs
@@ -0,0 +1,65 @@
+#!/usr/bin/env node
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// Conformance rig for the document indexer — the JS side of the contract in
+// tray/fixtures/. The Kotlin port runs the same corpus from
+// `./gradlew :app:testDebugUnitTest`, and a Swift port will do the same.
+//
+// node scripts/test-doc-index.mjs
+
+import { readFileSync, readdirSync } from 'node:fs'
+import { createHash } from 'node:crypto'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+import { describe, TEXT_BUDGET, SNIFF_BYTES, HEAD_BYTES } from '../tray/doc-index.mjs'
+
+const root = join(dirname(fileURLToPath(import.meta.url)), '..')
+const dir = join(root, 'tray/fixtures')
+const expected = JSON.parse(readFileSync(join(dir, 'expected.json'), 'utf8'))
+const sha = (s) => createHash('sha256').update(s, 'utf8').digest('hex').slice(0, 16)
+
+let failed = 0
+const fail = (name, what, want, got) => {
+ failed++
+ console.error(` FAIL ${name}: ${what}\n want ${JSON.stringify(want)}\n got ${JSON.stringify(got)}`)
+}
+
+// The constants are part of the contract, not incidental — a port that used a
+// different budget would pass every case whose text is short and diverge only
+// on the large documents nobody tests by hand.
+for (const [k, want] of [['textBudget', TEXT_BUDGET], ['sniffBytes', SNIFF_BYTES], ['headBytes', HEAD_BYTES]]) {
+ if (expected[k] !== want) fail('constants', k, expected[k], want)
+}
+
+const cases = readdirSync(join(dir, 'cases')).sort()
+const unknown = cases.filter((c) => !expected.cases[c])
+if (unknown.length) fail('corpus', 'cases with no expectation (regenerate expected.json)', [], unknown)
+const missing = Object.keys(expected.cases).filter((c) => !cases.includes(c))
+if (missing.length) fail('corpus', 'expectations with no case file', [], missing)
+
+for (const name of cases) {
+ const want = expected.cases[name]
+ if (!want) continue
+ const got = describe(readFileSync(join(dir, 'cases', name), 'utf8'))
+
+ if (got.isDocument !== want.isDocument) fail(name, 'isDocument', want.isDocument, got.isDocument)
+ if (got.title !== want.title) fail(name, 'title', want.title, got.title)
+ if (got.app !== want.app) fail(name, 'app', want.app, got.app)
+ if (got.encrypted !== want.encrypted) fail(name, 'encrypted', want.encrypted, got.encrypted)
+ if ((got.preview !== null) !== want.hasPreview) fail(name, 'hasPreview', want.hasPreview, got.preview !== null)
+
+ const len = got.text === null ? null : got.text.length
+ if (len !== want.textLength) fail(name, 'textLength', want.textLength, len)
+ const digest = got.text === null ? null : sha(got.text)
+ if (digest !== want.textSha256_16) fail(name, 'text digest', want.textSha256_16, digest)
+ // Verbatim text is carried for the short cases so a human can read the answer
+ // key; check it too, or it would rot unnoticed behind the digest.
+ if (want.text !== undefined && got.text !== want.text) fail(name, 'text', want.text, got.text)
+}
+
+console.log(failed
+ ? `\ndoc-index: ${failed} failure(s) across ${cases.length} cases`
+ : `doc-index: ${cases.length} cases pass`)
+process.exit(failed ? 1 : 0)
diff --git a/tray/README.md b/tray/README.md
index aac34a3d..234db172 100644
--- a/tray/README.md
+++ b/tray/README.md
@@ -483,10 +483,12 @@ here rather than discovered later.
| write access to an opened document | always | **may be read-only** | platform-forced |
| status bar while editing | hidden on iPad | always shown | **known gap** |
| whole-folder grant | folder-mode `UIDocumentPickerViewController` | `ACTION_OPEN_DOCUMENT_TREE` | same capability |
-| text extracted from a document | `BentoIndex.swift` | (in progress) | ported per platform |
-| finding a document by its contents | ✓ search screen + Spotlight | — | **gap on Android**, see below |
+| text extracted from a document | `BentoIndex.swift` | `DocumentIndex.kt` | ported per platform, one corpus |
+| finding a document by its contents | ✓ search screen + Spotlight | ✓ search over a folder index | same |
-Two gaps, both named rather than quietly left out.
+One gap left, named rather than quietly left out. (Search was the other, on
+whichever host you read this from — `tray/ios` and `tray/android` landed it a day
+apart, from opposite directions, each believing the other still lacked it.)
**The status bar.** iOS hides it on iPad because nothing else keeps the page off
the whole screen there; the Android equivalent would be to hide it on tablets
@@ -494,51 +496,33 @@ the whole screen there; the Android equivalent would be to hide it on tablets
tablet target, and shipping an untested behaviour is worse than naming an
untested one.
-**Search.** `tray/webext` scans every granted folder and searches **the document's
-own prose**, so a deck is findable by a phrase on a slide rather than by what
-somebody named the file. iOS has that now; Android does not yet.
-
-On iOS it is three pieces, following `docs/DECISIONS.md` (2026-08-16):
-
-- a **whole-folder grant** through the folder-mode document picker, persisted as
- a security-scoped bookmark — the app could previously open one file at a time
- and could not enumerate anything;
-- **`BentoIndex.swift`**, a port of the extension's `extractText`: up to 40KB of
- prose per document pulled out of the `#bento-doc` block as string values, data
- URIs stripped first, encrypted documents never read at all;
-- a **search screen** beside the document browser, and the same prose donated to
- **CoreSpotlight** so results turn up in system search too.
-
-The browser stays the root. It is not a list but a surface — iCloud Drive, every
-File Provider on the device, drag-and-drop, rename in place, favourites and tags
-— so search is one button away from it rather than in place of it.
-
-The port is held in place by `scripts/test-tray-index.mjs`, which runs two checks
-because they fail for different reasons:
-
-- the **shared corpus** in `tray/fixtures/` — the same cases and answer key every
- host answers, budgets included. Skipped, not failed, when that directory is
- absent, since it arrives with the Android work.
-- a diff against the **live `library.js`**, imported and run rather than copied,
- over generated edge cases and every document in the tree. A frozen answer key
- pins a port to a snapshot; when the reference moves, static expectations go
- stale silently and every host stays green while drifting.
-
-That is what makes "each host carries its own copy" safe: a divergence is a
-failing rig rather than a document that is findable on one platform and not
-another. The one deviation currently accepted is written down in
-`BentoIndex.swift` — JavaScript can hold half a surrogate pair at the 40KB cut
-and Swift cannot, so the port drops it.
-
-Indexing prose into CoreSpotlight is a deliberate reach beyond the app, so two
-rules are enforced in code rather than described: an encrypted document yields no
-text and no preview, and revoking a folder deletes everything indexed from it.
-
-**Not built yet, on iOS.** The `data-bento-preview` slice is extracted and stored
-— it is free, the same read produces it — but the results list shows no
-thumbnail, because turning that HTML into an image means snapshotting a WebView
-per row. The document browser already thumbnails these documents; the search
-list does not.
+**Search.** All three hosts have it now. `tray/webext` always did; `tray/ios` and
+`tray/android` landed it a day apart, from opposite directions — which is why the
+parity table above briefly claimed the gap in both directions at once.
+
+A deck is findable by **a phrase on one of its slides** rather than only by what
+somebody called the file. Each host does it the same way, and the sameness is
+enforced rather than hoped for:
+
+- a **whole-folder grant** — folder-mode `UIDocumentPickerViewController` on iOS
+ persisted as a security-scoped bookmark, `ACTION_OPEN_DOCUMENT_TREE` on Android
+ persisted as a URI permission. Both hosts could previously open one file at a
+ time and enumerate nothing.
+- **the extraction, ported per platform** — `BentoIndex.swift` and
+ `DocumentIndex.kt`, both from the reference in `tray/doc-index.mjs`: up to 40KB
+ of prose per document pulled out of the `#bento-doc` block as string values,
+ data URIs stripped first.
+- **one shared corpus** — `tray/fixtures/`, 11 cases, run from each host's own
+ rig (`node scripts/test-doc-index.mjs`, `./gradlew :app:testDebugUnitTest`).
+ The guarantee is deliberately "cannot diverge SILENTLY" rather than "cannot
+ diverge", which is the weaker promise that fits string scanning — unlike
+ `tray/bridge.js`, shared outright because a divergence there wrote documents
+ out as zero bytes.
+
+The shape is settled in `docs/DECISIONS.md` (2026-08-16): **native list UI on
+each host**, not the extension's HTML library screen in a WebView — measured at
+~0.5s of extra cold start, and it would have cost iOS its system document
+browser.
**One thing the extraction inherits from the reference**, visible in snippets: it
pulls string VALUES, so style values (`sans-serif`, `#EAF4FF`, `rgba(…)`) sit in
@@ -546,6 +530,11 @@ the prose alongside real words. That is what makes it format-agnostic, and it is
the extension's behaviour too — narrowing it is a change to all three ports and
belongs in `docs/DECISIONS.md`, not in one host.
+Two properties the corpus pinned that reasoning had not: a single JSON string
+value **over 400 characters is not indexed at all** (the value regex is capped
+`{1,400}`), and **JS `\s` is Unicode-aware where Java's is not**. Both are held
+in place so a port cannot quietly "fix" them into divergence.
+
### What is genuinely different
Three things, and none of them are stylistic.
@@ -639,6 +628,232 @@ At 72 it exactly filled the visible area, so every launcher mask cut its corners
off and the navy frame that makes the mark read was never drawn at all.
+### Document search
+
+Grant a folder once and every Bento document inside it is indexed, so a deck is
+findable by **a phrase on one of its slides**. This is what `tray/webext` has
+always had and what neither native host did.
+
+- **The grant** is `ACTION_OPEN_DOCUMENT_TREE` plus a persistable permission —
+ the analogue of the extension's `showDirectoryPicker`. Note that Android
+ refuses to grant some directories outright (the root of shared storage, and
+ `Download` on current versions): the picker says "Can't use this folder" and
+ the user has to pick a subfolder. That is the platform's rule, not ours.
+- **Nothing is copied.** The index holds extracted text and the first-page
+ preview; the documents stay where the user put them.
+- **A rescan is nearly free.** Rows are keyed by size and timestamp, so an
+ unchanged folder costs one directory listing per folder and no reads at all —
+ the expensive step was never the walk, it is pulling 40KB of prose out of a
+ megabyte of document.
+- **The name is not the test.** Any `.html` is opened and the marker inside it
+ decides, so a deck renamed to `deck.html` to email it is still found — and a
+ stray web page that merely contains the word you searched for is not.
+- **SQLite, not a JSON file**, because the prose budget is 40KB *each*: a few
+ hundred documents is megabytes, which is fine on disk and ruinous to parse
+ into memory on every launch.
+- **Encrypted documents are indexed as encrypted and nothing more** — no text,
+ no preview. A privacy rule, not an optimisation.
+- `MAX_FILES` (5000) bounds a scan, and hitting it is **reported**: a library
+ that quietly stops at N is a library that lies about what it holds.
+
+**Thumbnails**, rendered once and cached. The other two hosts get these free and
+differently: iOS renders nothing at all — `UIDocumentBrowserViewController` asks
+the SYSTEM to thumbnail the file, and the iOS thumbnailer draws the
+`[data-bento-preview]` block because it runs no JavaScript, which is exactly what
+that block exists for. `tray/webext` sets `iframe.srcdoc`. Android has neither a
+system HTML thumbnailer nor a browser for a list, so it renders the block itself:
+**one offscreen WebView, at index time**, into a bitmap cached in `cacheDir`
+(which Android empties under storage pressure — right for something
+reconstructible). The list stays plain `ImageView`s, so nothing here touches cold
+start or accessibility.
+
+Three traps, all of which produced a *plausible-looking wrong picture* rather
+than an error, and all worth knowing before touching `Thumbnails.kt`:
+
+1. **A detached WebView draws the wrong thing, not nothing.** `measure`/`layout`
+ on a view with no window never reaches the renderer, so the CSS viewport stays
+ at WebView's default. It must be attached.
+2. **The viewport has to be the capture box.** The preview's outer element is
+ `position:fixed; width:100%; height:100%` — it covers the VIEWPORT by design,
+ since a thumbnailer injects it into a real document. `width=device-width`
+ means the SCREEN, not the view, so the block rendered far wider than the box
+ and the capture was a magnified crop of its corner. `width=1280` — the width
+ decks are authored at — plus `loadWithOverviewMode` scales the whole slide to
+ fit, with no density arithmetic.
+3. **WebView lays out in DP; the capture is in PIXELS.** Ignoring that renders
+ everything `density` times too large and captures a crop — on a 2.75× device
+ the slide's title filled the frame with three letters of it. The render box is
+ sized in DP and the bitmap is downscaled after, which also gives crisper text
+ than rendering at final size.
+
+Because the preview is already stored in the index, adding this needed **no
+rescan** — existing rows thumbnailed on the spot.
+
+### New documents are fetched, never bundled
+
+Starter decks change often, and there are three Bento apps with more coming — so
+bundling one means picking arbitrarily, and bundling all of them means shipping
+several copies of Bento inside the app, each stale from the moment it was built.
+
+Measured on Android before this changed: the single bundled slides seed was
+**517,161 bytes, 81% of a 630,851-byte release APK**. Removing it took the
+release build to **117,940 bytes**, and the only asset left is `bridge.js`.
+
+So "New" asks which app you want and fetches that app's current signed shell
+(`Releases.kt`), the same channel a document uses to update itself — which also
+means a document created here is the version everyone else has, the same day.
+The shell is cached in `filesDir`, so only the first "New" of a given release
+needs a connection. `tray/webext` already worked this way in principle;
+`tray/ios` still bundles and should follow.
+
+This is the **one** request the host makes on its own account — no launch check,
+no telemetry. `docs/PLATFORM.md` §1 requires no network to open, edit, present or
+save; creating from a template is none of those.
+
+**Both halves are verified**, exactly as `kernel/src/update.ts` does it: the
+manifest's ECDSA P-256 signature over the exact payload bytes, then the shell's
+`sha256` as pinned by that signed payload. These bytes become an executable
+document the user afterwards trusts, so an unverified download would let anyone
+in the path choose what they create.
+
+**Two more checks, and neither is optional** — both catch an attacker who can
+re-serve but cannot forge, which is what an origin or CDN compromise looks like:
+
+- **App identity.** A genuinely signed `bento-slides` manifest served on the
+ dash channel passes the signature AND the digest: every byte authentic, just
+ not what was asked for. Checked against the app the CALLER requested, never
+ against what the payload says about itself — and an ABSENT field must not read
+ as a match, which is the hole `tray/webext` had before PR #318.
+- **A rollback floor**, a per-app high-water mark. A stale but genuine manifest
+ passes everything, because every byte of it really was signed and really does
+ match; it just hands over an older release. `kernel/src/update.ts` refuses to
+ go backwards using its own build version, but a host that CREATES documents
+ has nothing to compare against except what it has seen.
+
+ Two details that are easy to get backwards, and both turn a failed attack into
+ a permanent one if you do. The floor is raised **only after the downloaded
+ bytes pass their digest** — raising it on a merely-verified manifest would let
+ one forged-but-unfetchable release naming 9.9.9 lock the device out of every
+ real release below it. And an **equal version is accepted**: re-fetching the
+ version already seen is the normal case, so treating equal as a downgrade
+ breaks the + button on its second use, not at some edge.
+
+ Accepted cost, taken deliberately: a maintainer's own rollback is refused too,
+ so pulling a bad release needs a version bump rather than a re-point.
+
+ An unreadable store reads as NO floor rather than a refusal — being unable to
+ remember must not mean being unable to create a document — and an unparsable
+ version component sorts as 0, so a strange version can fail to raise the floor
+ but never blocks a release. That last one matches the kernel exactly, including
+ the detail that `Number('1a')` is NaN and NaN is falsy, so `(pa[i] || 0)`
+ coerces it to 0 rather than propagating.
+
+Two traps worth keeping:
+
+- **WebCrypto emits ECDSA signatures as raw `r‖s`; Java expects DER.** The
+ manifest is signed through WebCrypto by `scripts/sign-release.mjs`, so handing
+ its 64 bytes to `SHA256withECDSA` unconverted is simply a bad signature —
+ silent, and indistinguishable from tampering.
+- **Ask for bytes, not a page.** `HttpURLConnection` sends a browser-shaped
+ `Accept` by default, and the release host rewrites responses it believes are
+ pages — see the note below. `Accept: */*` avoids the rewrite; the hash check is
+ what actually makes the bytes trustworthy, and stays regardless.
+
+### Grid or list, and a theme you can override
+
+The documents screen offers both, with the choice remembered. **Grid is the
+default**, matching `tray/webext`, whose home screen has always been a grid of
+thumbnail cards — and it is what makes rendering thumbnails worth the trouble.
+iOS gets the same choice free from the system document browser.
+
+The **theme override** is offered only on API 31+, where
+`UiModeManager.setApplicationNightMode` exists; below it there is no way to
+override the system theme without AndroidX, so the control is not shown at all.
+A button that silently does nothing is worse than no button. Both this and the
+view mode are VIEWER preferences kept on the device — the same shape as the
+runtime's own locale and reduce-motion settings, which default to the OS and
+never enter a document.
+
+### Typography and the mark
+
+The system font, deliberately, because that is what `slides` and `tray/webext`
+both use (`-apple-system, …, Roboto, …`) — on Android the system font IS Roboto,
+so the chrome already matches the apps. The brand faces (`Fraunces`,
+`Instrument Sans`) belong to the marketing site, not to app chrome, and
+bundling them would cost a few hundred KB on a 122 KB app.
+
+What did transfer: the extension's `-.015em` heading tracking (Android's
+`letterSpacing` is already in ems, so the number moves across unchanged) and its
+`font-weight: 600` emphasis — real 600 from API 28, bold below it. The **mark**
+in the header is generated from `tray/assets/tray-logo.svg` by the same script
+as the launcher icon, so the two cannot drift.
+
+### Material 3, dynamic colour, and adaptive layout
+
+The documents screen is Material 3 now, and the reason is specific: **dynamic
+colour** and **adaptive large-screen behaviour** are what Play's editorial
+surfaces reward, and neither can be hand-rolled. Dynamic colour means the app
+adopts the user's wallpaper palette on Android 12+ — so the Bento palette below
+is the FALLBACK for older devices rather than the intent. The brand stays present
+through the mark and the thumbnails, which is the right place for it.
+
+Measured cost, since the earlier decision turned on it: **+1.26 MB**, dominated
+by `resources.arsc` growing 24× — applying an M3 theme references the library's
+whole style and attribute graph and resource shrinking cannot prove any of it
+unused. That ratio was the argument against it while tray was positioned as a
+thin courier; it is worth paying once the goal includes being featured.
+
+`EditorActivity` stays OFF Material on its own plain theme. It hosts one
+full-screen WebView, the document supplies its own chrome, and Material would
+only add inflation requirements.
+
+**Adaptive layout keys off `smallestScreenWidthDp >= 600`, not `screenWidthDp`,**
+and the difference is the whole lesson. A Pixel in landscape reports 873dp wide
+and passes a width test — but it is only ~390dp tall, so a two-pane layout left
+the grid **299px high**: a worse phone layout wearing a tablet's clothes. The
+smallest dimension is the one that means "room in both directions", which is why
+`sw600dp` is the platform's own tablet qualifier. A foldable reports the folded
+width closed and the unfolded width open, and unfolding recreates the activity,
+so it lands on the right layout with no listener.
+
+On a tablet the grid shares the window with a **detail pane**: a large
+first-page render, title, app, folder and date, and Open. That render at 400px is
+the whole argument for having thumbnails at all — at 64×36 in a list row it is a
+hint; at this size it is the document.
+
+Column count comes from the available width, and the card's thumbnail height is
+measured from the GRID rather than the screen — the screen is wrong twice over,
+once because a hardcoded column count sizes every card for a phone, and again
+because with a detail pane the grid is only part of the width.
+
+### What the hand-rolled theme established (superseded by Material, kept for the reasoning)
+
+The documents screen is ours to design — unlike iOS, where the root screen is
+the system document browser — so it carries the same tokens as `tray/webext`
+rather than framework defaults. Palette, radii and the button variants come
+straight from `tray/webext/src/ui.css`, including its dark set: `values/` and
+`values-night/` define the same colour names twice and the `-night` resource
+qualifier switches them, so **dark mode needs no library and no runtime branch**.
+
+It stays dependency-free, and that is now true rather than an excuse. An earlier
+version of this file justified framework defaults with "every dependency this
+screen does not have is one that cannot drift out of step with the WebView
+work" — an argument about dependency risk in the part of the app where risk
+actually lives, misapplied to the cosmetic part.
+
+Material Components was measured rather than argued about: **+1.26 MB**, taking
+a 616 KB app to 1.83 MB. The largest single line was `resources.arsc` growing
+24× (26 KB → 619 KB), because applying an M3 theme references the library's
+whole style and attribute graph and resource shrinking cannot prove any of it
+unused — styles and attrs resolve by name at runtime. For an app whose logic is
+136 KB of dex that is roughly 7× the app to style one screen. It would be the
+right call for a bigger app, and if tray grows settings or onboarding screens it
+becomes one; today it is not.
+
+What that costs: pressed/focus states, minimum touch targets and the dark
+palette are hand-rolled here rather than inherited. `<ripple>` drawables and an
+explicit `48dp` minimum cover the first two.
+
### State: the document cycle works, on an emulator only
Verified end to end on a Pixel 7 / Android 16 emulator, driven through the real
@@ -654,6 +869,15 @@ UI rather than a harness:
present, well-formed from `<!DOCTYPE html>` to `</body></html>`, `docId` minted
- the document reopens from the recents list on its persisted grant
- the adaptive icon renders correctly under a circular launcher mask
+- **New document fetches and verifies**: manifest signature checked, shell
+ sha256 checked, cached as `slides-1.0.18.html` at exactly the signed 689,316
+ bytes, written and opened. A failed fetch removes the empty file that
+ `ACTION_CREATE_DOCUMENT` had already created.
+- **document search works end to end**: a granted folder indexed 2 decks and
+ excluded a decoy `.html` that contains the search word but carries no
+ `#bento-doc` marker; typing `software` — a word in no filename — returns both
+ decks by their own title, `Notes` returns one by file name, and a nonsense
+ query returns none
Not yet verified:
diff --git a/tray/android/app/build.gradle.kts b/tray/android/app/build.gradle.kts
index 886955eb..bfd31eeb 100644
--- a/tray/android/app/build.gradle.kts
+++ b/tray/android/app/build.gradle.kts
@@ -15,24 +15,23 @@ val keystoreProps = Properties().apply {
}
/**
- * Stages everything the app ships that is generated rather than written.
+ * Stages the one generated thing the app ships: `tray/bridge.js`, the File
+ * System Access polyfill SHARED with tray/ios. One copy of semantics whose
+ * comments record a bug that wrote users' documents out as zero bytes; a second
+ * copy would be a second chance to reintroduce it.
*
- * Two inputs, for two reasons:
+ * NO STARTER DECK. It used to stage one here, mirroring tray/ios — and that was
+ * wrong. Starter decks change often and there are three Bento apps with more
+ * coming, so bundling means picking one arbitrarily or shipping several copies
+ * of Bento inside the app, each stale from the moment it is built. Measured
+ * before it was removed: the single slides seed was 517,161 bytes, 81% of a
+ * 630,851-byte release APK.
*
- * - `tray/bridge.js` is the File System Access polyfill, SHARED with tray/ios.
- * One copy of semantics whose comments record a bug that wrote users'
- * documents out as zero bytes; a second copy would be a second chance to
- * reintroduce it.
- * - the starter shell is COPIED FROM THE CURRENT BUILD, never committed: a
- * 587KB binary in git would churn on every release. It ages harmlessly — a
- * new deck self-updates through Bento's normal signed channel the first time
- * it checks.
- *
- * Mirrors the "Stage starter shell" step in tray/ios/project.yml.
+ * A new document now comes from the signed release channel instead — see
+ * `Releases.kt`.
*/
abstract class StageTrayAssets : DefaultTask() {
@get:InputFiles abstract val bridge: ConfigurableFileCollection
- @get:InputFiles abstract val seed: ConfigurableFileCollection
@get:OutputDirectory abstract val outputDir: DirectoryProperty
@TaskAction
@@ -41,25 +40,11 @@ abstract class StageTrayAssets : DefaultTask() {
out.deleteRecursively()
out.mkdirs()
bridge.singleFile.copyTo(out.resolve("bridge.js"), overwrite = true)
-
- // Resolved at EXECUTION time, not configuration time: the seed is a
- // build artefact of a different project, so it routinely appears after
- // this build was last configured.
- val shell = seed.files.firstOrNull { it.exists() }
- if (shell != null) {
- shell.copyTo(out.resolve("starter.bento.html"), overwrite = true)
- } else {
- logger.warn(
- "warning: no starter shell — run 'npm run build:single' in slides/; " +
- "New document will be unavailable in this build"
- )
- }
}
}
val stageAssets = tasks.register<StageTrayAssets>("stageTrayAssets") {
bridge.from(rootProject.file("../bridge.js"))
- seed.from(rootProject.file("../../slides/dist-single/Bento_Slides.bento.html"))
outputDir.set(layout.buildDirectory.dir("staged-assets"))
}
@@ -107,6 +92,11 @@ android {
}
kotlinOptions { jvmTarget = "17" }
+
+ // Android's own classes are stubs on the JVM rig and throw by default.
+ // Returning defaults instead lets Releases' verification sequence — the part
+ // most worth testing — run without a device.
+ testOptions { unitTests.isReturnDefaultValues = true }
}
androidComponents {
@@ -130,4 +120,29 @@ dependencies {
// Both are WebView-side features rather than app-side ones, so the library
// is a thin façade over what the installed WebView already implements.
implementation("androidx.webkit:webkit:1.17.0")
+
+ // Material 3, for the documents screen only. Measured cost at the time it
+ // was added: +1.26 MB, taking a 122 KB app past 1.3 MB — dominated by
+ // resources.arsc, because applying an M3 theme references the library's
+ // whole style and attribute graph and resource shrinking cannot prove any
+ // of it unused.
+ //
+ // That ratio was the argument against it while tray was "a thin courier".
+ // It is worth paying for two things a hand-rolled theme cannot do at all:
+ // DYNAMIC COLOUR (the app adopting the user's wallpaper palette, which is
+ // the clearest signal of a modern Android app) and adaptive large-screen
+ // behaviour. Both are what Play's editorial surfaces actually reward.
+ //
+ // EditorActivity deliberately stays off it — a full-screen WebView gains
+ // nothing from Material and would only inherit the inflation requirements.
+ implementation("com.google.android.material:material:1.12.0")
+
+ // Test-only. The indexer is held to the shared corpus in tray/fixtures/ by
+ // a plain JVM test — no emulator, so there is no excuse not to run it.
+ //
+ // Gson rather than org.json: Android's org.json is a STUB in unit tests
+ // whose methods throw, and whether a real one on the test classpath shadows
+ // it is a coin toss. A test that fails for that reason teaches nothing.
+ testImplementation("junit:junit:4.13.2")
+ testImplementation("com.google.code.gson:gson:2.11.0")
}
diff --git a/tray/android/app/src/main/AndroidManifest.xml b/tray/android/app/src/main/AndroidManifest.xml
index ee2ea496..11815b0f 100644
--- a/tray/android/app/src/main/AndroidManifest.xml
+++ b/tray/android/app/src/main/AndroidManifest.xml
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
- <!-- For the DOCUMENT, never for the host. The app itself makes no network
- request of any kind — no update check, no telemetry, no phoning home.
- But the document it hosts carries its own runtime, and that runtime
- syncs with the collab relay and checks Bento's signed update channel,
- exactly as it would in a browser tab. Withholding this would silently
- break live collaboration and self-update inside every deck. -->
+ <!-- Almost entirely for the DOCUMENT. The document carries its own runtime,
+ which syncs with the collab relay and checks Bento's signed update
+ channel exactly as it would in a browser tab; withholding this would
+ silently break live collaboration and self-update inside every deck.
+
+ The host itself makes exactly ONE request, and only when you create a
+ new document: it fetches that app's current signed shell rather than
+ bundling a starter deck (see Releases.kt — starter decks change often
+ and there are three Bento apps with more coming). No update check of its
+ own, no telemetry, nothing on launch. docs/PLATFORM.md §1 requires no
+ network to OPEN, EDIT, PRESENT or SAVE, and none of those touch it. -->
<uses-permission android:name="android.permission.INTERNET" />
<application
@@ -37,6 +42,7 @@
<activity
android:name=".EditorActivity"
android:exported="true"
+ android:theme="@style/Theme.Tray.Editor"
android:parentActivityName=".DocumentsActivity"
android:documentLaunchMode="intoExisting"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|keyboard|uiMode|density|smallestScreenSize|navigation">
@@ -49,7 +55,7 @@
<!-- Opening a document from a file manager, Drive, Gmail, a share
sheet. LSHandlerRank has no Android equivalent — the chooser
- ranks by user habit — so this simply adds Bento Tray to the
+ ranks by user habit — so this simply adds bento/home to the
list of apps offered for an HTML file rather than claiming it.
An ACTION_VIEW grant is usually READ-ONLY, which is why this is
diff --git a/tray/android/app/src/main/java/page/bento/tray/DocumentIndex.kt b/tray/android/app/src/main/java/page/bento/tray/DocumentIndex.kt
new file mode 100644
index 00000000..019398ed
--- /dev/null
+++ b/tray/android/app/src/main/java/page/bento/tray/DocumentIndex.kt
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+
+package page.bento.tray
+
+/**
+ * What this app can know about a file it did not write.
+ *
+ * A PORT, not an original. `tray/doc-index.mjs` is the reference and
+ * `tray/fixtures/` is the corpus that holds this implementation to it —
+ * `DocumentIndexTest` runs that same corpus on the JVM, so it needs no device
+ * and no emulator. If the two ever disagree, this one is wrong.
+ *
+ * Why a port at all, rather than sharing the JavaScript: the list UI stays
+ * native. Putting the extension's HTML library in a WebView was measured at
+ * ~0.5s of extra cold start, costs iOS its system document browser, and makes
+ * accessibility something you re-earn rather than get. See `docs/DECISIONS.md`,
+ * 2026-08-16.
+ */
+object DocumentIndex {
+
+ /** The splice contract's marker (docs/PLATFORM.md §2), frozen because old
+ * updaters depend on it. A Bento document is one because of what is INSIDE
+ * it — files get renamed to `deck.html` to email them, saved as
+ * `Q3(1).html`, downloaded without the compound extension. */
+ const val MARKER = "id=\"bento-doc\""
+
+ /** Read before deciding a file is not ours. Runs against every stray .html
+ * in a granted folder, most of which are not ours, so it is deliberately
+ * smaller than [HEAD_CHARS]. */
+ const val SNIFF_CHARS = 64 * 1024
+
+ /** Enough to reach the title, which sits inside the block. The block itself
+ * runs to megabytes when a document carries images. */
+ const val HEAD_CHARS = 300 * 1024
+
+ /** Enough prose for any phrase somebody would search for; far short of
+ * storing the document twice. */
+ const val TEXT_BUDGET = 40 * 1024
+
+ // ---------------------------------------------------------------- regexes
+ //
+ // Compiled once. Every one of these mirrors a JavaScript literal in the
+ // reference, and two of them need care because Java and JavaScript disagree:
+ //
+ // - `\s` in JavaScript is UNICODE-AWARE; in Java it is ASCII-only unless
+ // UNICODE_CHARACTER_CLASS is set, and even then it follows the
+ // White_Space property, which EXCLUDES U+FEFF. So the class is written
+ // out in full rather than spelled `\s`. A port that used `\s` would leave
+ // non-breaking and ideographic spaces sitting in the indexed text, and
+ // a phrase search across one of them would silently fail to match.
+ // `whitespace.html` in the corpus is what catches that.
+ // - `.` matches any character except a line terminator in both, so `\\.`
+ // inside the value pattern behaves identically. No flag needed.
+
+ /** One embedded image outweighs every word in a document, so data URIs go
+ * first — before extraction, not after. */
+ private val DATA_URI = Regex("""data:[^"\\]{200,}""")
+
+ /** String VALUES only: `:"…"`, never keys. Deliberately not a JSON parse —
+ * the block runs to megabytes, every app shapes it differently (slides put
+ * prose in `element.html`, spaces in blocks, dash in cells), and a parser
+ * that has to know the format breaks when the format moves.
+ *
+ * NOTE the `{1,400}`: a single value longer than 400 characters does not
+ * match and is therefore NOT INDEXED AT ALL. That is current behaviour
+ * across all three hosts and `longvalue.html` pins it, so a port cannot
+ * quietly "fix" it into divergence. */
+ private val VALUE = Regex(""":"((?:[^"\\]|\\.){1,400})"""")
+
+ /** Ids, hex colours, `12px` — anything without a run of three letters. */
+ private val HAS_WORD = Regex("""[A-Za-z]{3,}""")
+
+ private val TAG = Regex("""<[^>]{1,200}>""")
+ private val ENTITY = Regex("""&[a-z]+;|&#\d+;""", RegexOption.IGNORE_CASE)
+
+ /** JavaScript's `\s`, written out. */
+ private val SPACE = Regex("[\\u0009-\\u000d\\u0020\\u00a0\\u1680\\u2000-\\u200a" +
+ "\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]+")
+
+ private val TITLE = Regex(""""title"\s*:\s*"((?:[^"\\]|\\.){0,200})"""")
+ private val FORMAT = Regex(""""format"\s*:\s*"bento/([a-z]+)"""")
+ private val ENCRYPTED = Regex(""""format"\s*:\s*"bento/enc"""")
+
+ // ------------------------------------------------------------------- API
+
+ fun isDocument(head: String) = head.contains(MARKER)
+
+ fun titleOf(head: String) = TITLE.find(head)?.groupValues?.get(1)
+
+ /** Which Bento this is. A pristine shell has no document yet, so no format:
+ * that is not a failure, it is a document nobody has saved. */
+ fun appOf(head: String) = FORMAT.find(head)?.groupValues?.get(1)
+
+ /** An encrypted document gets NO text and NO preview. A privacy rule, not an
+ * optimisation: a plaintext title page beside the ciphertext is the leak
+ * the password exists to prevent. */
+ fun isEncrypted(head: String) =
+ ENCRYPTED.containsMatchIn(head) || head.contains("data-bento-enc")
+
+ /** The still render of page one that every save writes into the shell
+ * (kernel/src/preview.ts) so file managers can thumbnail it. */
+ fun previewOf(whole: String): String? {
+ val start = whole.indexOf("<div data-bento-preview")
+ if (start == -1) return null
+ val end = whole.indexOf("<script data-bento-preview", start)
+ return if (end > start) whole.substring(start, end) else null
+ }
+
+ /** The words a document actually contains. */
+ fun extractText(html: String): String? {
+ val start = html.indexOf(MARKER)
+ if (start == -1) return null
+ val end = html.indexOf("</script>", start)
+ if (end == -1) return null
+
+ val block = DATA_URI.replace(html.substring(start, end), " ")
+ val out = StringBuilder()
+ var size = 0
+ for (m in VALUE.findAll(block)) {
+ val v = m.groupValues[1]
+ if (!HAS_WORD.containsMatchIn(v)) continue
+ if (out.isNotEmpty()) out.append(' ')
+ out.append(v)
+ size += v.length
+ // Appended THEN tested, matching the reference: the join may exceed
+ // the budget and is truncated below.
+ if (size > TEXT_BUDGET) break
+ }
+
+ var s = TAG.replace(out, " ")
+ s = ENTITY.replace(s, " ")
+ s = SPACE.replace(s, " ").trim()
+ if (s.length > TEXT_BUDGET) s = s.substring(0, TEXT_BUDGET)
+ return s.ifEmpty { null }
+ }
+
+ /** Everything a host needs about one file, from bytes it has already read. */
+ data class Meta(
+ val isDocument: Boolean,
+ val title: String?,
+ val app: String?,
+ val encrypted: Boolean,
+ val preview: String?,
+ val text: String?,
+ )
+
+ fun describe(whole: String): Meta {
+ if (!isDocument(whole.take(SNIFF_CHARS))) {
+ return Meta(false, null, null, false, null, null)
+ }
+ val head = whole.take(HEAD_CHARS)
+ val encrypted = isEncrypted(head)
+ return Meta(
+ isDocument = true,
+ title = titleOf(head),
+ app = appOf(head),
+ encrypted = encrypted,
+ preview = if (encrypted) null else previewOf(whole),
+ text = if (encrypted) null else extractText(whole),
+ )
+ }
+}
diff --git a/tray/android/app/src/main/java/page/bento/tray/DocumentsActivity.kt b/tray/android/app/src/main/java/page/bento/tray/DocumentsActivity.kt
index ef2036db..43950f4f 100644
--- a/tray/android/app/src/main/java/page/bento/tray/DocumentsActivity.kt
+++ b/tray/android/app/src/main/java/page/bento/tray/DocumentsActivity.kt
@@ -3,14 +3,27 @@
package page.bento.tray
-import android.app.Activity
-import android.app.AlertDialog
+import android.app.UiModeManager
+import androidx.appcompat.app.AlertDialog
+import androidx.appcompat.app.AppCompatActivity
+import com.google.android.material.button.MaterialButton
+import com.google.android.material.card.MaterialCardView
+import com.google.android.material.color.DynamicColors
+import com.google.android.material.textfield.TextInputEditText
+import com.google.android.material.textfield.TextInputLayout
+import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.Typeface
import android.net.Uri
import android.os.Build
import android.os.Bundle
+import android.provider.DocumentsContract
+import android.text.Editable
+import android.text.SpannableString
+import android.text.Spanned
+import android.text.style.ForegroundColorSpan
+import android.text.TextWatcher
import android.text.format.DateUtils
import android.util.Log
import android.util.TypedValue
@@ -20,70 +33,231 @@ import android.view.ViewGroup
import android.view.WindowInsets
import android.widget.BaseAdapter
import android.widget.Button
+import android.widget.EditText
+import android.widget.ImageView
import android.widget.LinearLayout
-import android.widget.ListView
+import android.widget.GridView
+import android.widget.Toast
import android.widget.TextView
/**
- * The app's root: the documents this app can reach.
+ * The app's root: every document this app can reach, and a box to find one in.
*
- * iOS gets `UIDocumentBrowserViewController` — a whole file browser, hostable,
- * showing iCloud and every File Provider on the device. Android has nothing to
- * host: its picker is a one-shot dialog that returns a URI and closes. So the
- * root is a list of documents the user has already granted, plus the two ways in.
+ * iOS gets `UIDocumentBrowserViewController` — a whole file browser showing
+ * iCloud and every File Provider on the device. Android has nothing to host: its
+ * picker is a one-shot dialog that returns a URI and closes. So this screen is
+ * ours, and it holds two things:
*
- * That difference is worth stating plainly rather than apologising for. On iOS
- * the app is a lens onto the filesystem; on Android it is a keyring. Both end at
- * the same place — a document opened where it already lives, with edits going
- * back to that same file.
+ * - **Recents**, a keyring of documents opened one at a time (`Recents`).
+ * - **The library**, folders granted once and then indexed (`Library`), which
+ * is what makes a document findable by a phrase on one of its slides rather
+ * than only by what somebody called the file.
+ *
+ * Deliberately NATIVE, and deliberately not the extension's HTML library screen
+ * in a WebView: that was measured at ~0.5s of extra cold start, and it makes
+ * system font scaling, TalkBack and predictive back things you re-earn rather
+ * than get. See `docs/DECISIONS.md`, 2026-08-16.
*/
-class DocumentsActivity : Activity() {
+class DocumentsActivity : AppCompatActivity() {
companion object {
private const val TAG = "BentoTray"
private const val REQ_OPEN = 1
private const val REQ_NEW = 2
- private const val SEED = "starter.bento.html"
+ private const val REQ_FOLDER = 3
}
- private lateinit var list: ListView
+ private lateinit var list: GridView
+
+ /** Grid or list, and the theme override — both VIEWER preferences, kept on
+ * the device and never in a document. Same shape as the runtime's own
+ * locale and reduce-motion settings, which default to the OS and allow an
+ * override without the choice ever entering the file. */
+ private val prefs by lazy { getSharedPreferences("ui", Context.MODE_PRIVATE) }
+ private var gridMode = true
+ private lateinit var viewToggle: TextView
+
+ /** The detail pane, and what it is showing. Only built on a wide screen —
+ * on a phone there is nowhere to put it and a tap opens the document. */
+ private var detail: LinearLayout? = null
+ private var selected: Row? = null
+
+ /**
+ * Is this a tablet-class device, rather than a phone that happens to be
+ * sideways?
+ *
+ * `smallestScreenWidthDp`, NOT `screenWidthDp`, and the difference is the
+ * whole point: a Pixel in landscape reports 873dp wide and passes a width
+ * test, but it is only ~390dp TALL, so a two-pane layout left the grid 299px
+ * high — a worse phone layout wearing a tablet's clothes. The smallest
+ * dimension is the one that says "there is room in both directions", which
+ * is why `sw600dp` is the platform's own tablet qualifier.
+ *
+ * A foldable reports the folded width closed and the unfolded width open,
+ * and unfolding recreates the activity, so this lands on the right layout
+ * without a listener.
+ */
+ private val isWide get() = resources.configuration.smallestScreenWidthDp >= 600
private lateinit var empty: TextView
- private var entries: List<Recents.Entry> = emptyList()
+ private lateinit var search: EditText
+ private lateinit var status: TextView
+
+ /** One list, two sources. A document opened through "Open…" lives outside
+ * any granted folder and would otherwise vanish from a library-only list —
+ * so recents that the library does not already know about are folded in. */
+ private class Row(
+ val uri: Uri, val label: String, val sub: String, val encrypted: Boolean,
+ val app: String?, val modified: Long, val hasPreview: Boolean,
+ )
+
+ private var rows: List<Row> = emptyList()
override fun onCreate(savedInstanceState: Bundle?) {
+ // Before super, and before any view exists: dynamic colour rewrites the
+ // theme's colour roles from the user's wallpaper, so anything already
+ // inflated would keep the fallback palette.
+ DynamicColors.applyToActivityIfAvailable(this)
super.onCreate(savedInstanceState)
- setContentView(buildUi())
+ gridMode = prefs.getString("view", "grid") == "grid"
+ applyNightMode(prefs.getString("night", "system")!!)
+ // The thumbnail renderer needs a real window, so it gets a host added
+ // FIRST — behind the content, which therefore takes every touch.
+ val stack = android.widget.FrameLayout(this)
+ val renderHost = android.widget.FrameLayout(this)
+ stack.addView(renderHost, ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT))
+ stack.addView(buildUi(), ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
+ setContentView(stack)
+ Thumbnails.attach(renderHost)
}
override fun onResume() {
super.onResume()
refresh()
+ // A folder's contents change behind our back — a deck saved on the
+ // desktop and synced down, a file deleted. Rescanning on resume keeps
+ // the list honest, and an unchanged folder costs one listing and no
+ // reads because the index is keyed by size and timestamp.
+ if (Library.grants(this).isNotEmpty()) rescan(quiet = true)
}
+ // ------------------------------------------------------------------ state
+
private fun refresh() {
- entries = Recents.prune(this)
- (list.adapter as RecentsAdapter).notifyDataSetChanged()
- empty.visibility = if (entries.isEmpty()) View.VISIBLE else View.GONE
- list.visibility = if (entries.isEmpty()) View.GONE else View.VISIBLE
+ val q = search.text.toString().trim()
+ val known = HashSet<String>()
+ val out = ArrayList<Row>()
+
+ for (d in Library.search(this, q)) {
+ known += identity(d.uri)
+ val where = if (d.folder.isBlank()) "" else " · ${d.folder}"
+ out += Row(d.uri, d.label, describeApp(d.app) + where, d.encrypted, d.app,
+ d.modified, d.hasPreview)
+ }
+ for (e in Recents.prune(this)) {
+ if (identity(e.uri) in known) continue
+ if (q.isNotEmpty() && !e.name.contains(q, ignoreCase = true)) continue
+ val ago = DateUtils.getRelativeTimeSpanString(e.openedAt, System.currentTimeMillis(), 0)
+ // A recent that the library does not know about has no index row and
+ // therefore no preview — it was opened one-off, not through a folder.
+ out += Row(e.uri, e.name, "opened $ago", false, null, e.openedAt, false)
+ }
+
+ rows = out
+ (list.adapter as RowAdapter).notifyDataSetChanged()
+
+ val grants = Library.grants(this).size
+ val indexed = Library.count(this)
+ status.text = when {
+ grants == 0 -> getString(R.string.status_no_folders)
+ else -> resources.getQuantityString(R.plurals.status_indexed, indexed, indexed, grants)
+ }
+ empty.text = when {
+ q.isNotEmpty() -> getString(R.string.empty_search, q)
+ grants == 0 -> getString(R.string.empty_hint)
+ else -> getString(R.string.empty_library)
+ }
+ empty.visibility = if (rows.isEmpty()) View.VISIBLE else View.GONE
+ list.visibility = if (rows.isEmpty()) View.GONE else View.VISIBLE
}
- // MARK: - getting documents in
+ /**
+ * The wordmark, written the way every other Bento surface writes it.
+ *
+ * `bento` + a PEACH slash + the app: lowercase, one weight, the slash the
+ * only thing carrying colour. `tray/webext` does it as
+ * `<b>bento<i>/</i>home</b>` and the slides editor as
+ * `bento<span style="color:#FF9E8A">/</span>slides`; this is the same mark
+ * in a SpannableString.
+ *
+ * The peach is LITERAL and stays out of the theme's colour roles on purpose:
+ * dynamic colour rewrites the chrome from the user's wallpaper, and a
+ * wordmark that changes colour with the wallpaper is not a wordmark. It is
+ * the same reasoning that keeps the launcher icon's palette fixed.
+ */
+ private fun wordmark(): CharSequence {
+ val text = "bento/home"
+ val slash = text.indexOf('/')
+ return SpannableString(text).apply {
+ setSpan(ForegroundColorSpan(getColor(R.color.tray_peach)),
+ slash, slash + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+ }
+ }
/**
- * ACTION_OPEN_DOCUMENT, not ACTION_GET_CONTENT.
+ * What makes two URIs the same document.
*
- * GET_CONTENT hands back a COPY, which is the whole problem this app exists
- * to solve — every save would land somewhere other than the file the user
- * opened. OPEN_DOCUMENT returns a durable, writable reference to the document
- * itself, and it is the only Android API that does.
+ * NOT the URI string. The same file reached two ways has two different
+ * URIs: a document picked with ACTION_CREATE_DOCUMENT comes back as
+ * `…/document/primary%3ADocuments%2FDecks%2FQ3.bento.html`, while the same
+ * file found by walking a granted tree is `…/tree/<tree>/document/<same id>`.
+ * Comparing the strings therefore never matched, and every document created
+ * or opened inside a granted folder appeared TWICE — once from the library
+ * and once from recents.
+ *
+ * The provider's document id is the same for both, so that is the identity.
+ * Falls back to the URI for anything that is not a document URI at all.
*/
+ private fun identity(uri: Uri): String = try {
+ DocumentsContract.getDocumentId(uri) ?: uri.toString()
+ } catch (_: Exception) {
+ uri.toString()
+ }
+
+ private fun describeApp(app: String?) = when (app) {
+ "slides" -> "Slides"; "spaces" -> "Spaces"; "dash" -> "Dash"
+ "enc" -> "Encrypted"; null -> "Document"; else -> app.replaceFirstChar { it.uppercase() }
+ }
+
+ private fun rescan(quiet: Boolean) {
+ Thread {
+ val r = try { Library.scan(this) } catch (e: Exception) {
+ Log.w(TAG, "scan failed", e); null
+ }
+ runOnUiThread {
+ if (isFinishing || isDestroyed) return@runOnUiThread
+ refresh()
+ if (r == null && !quiet) notify(getString(R.string.err_scan))
+ // A ceiling that is hit is reported. A library that quietly stops
+ // at N is a library that lies about what it holds.
+ else if (r != null && r.truncated && !quiet) {
+ notify(getString(R.string.warn_scan_truncated, r.examined))
+ }
+ }
+ }.start()
+ }
+
+ // ----------------------------------------------------------- getting in
+
+ /** `ACTION_OPEN_DOCUMENT`, never `ACTION_GET_CONTENT`: the latter hands back
+ * a COPY, which is the whole problem this app exists to solve. */
private fun openDocument() {
- val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
+ startActivityForResult(Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
- // Permissive on type, deliberate about it: providers disagree about
- // what a .bento.html is, and several report octet-stream. A filter
- // that hides the user's own document is worse than one that shows
- // too much.
+ // Permissive on type, deliberately: providers disagree about what a
+ // .bento.html is and several report octet-stream. A filter that hides
+ // the user's own document is worse than one that shows too much.
type = "*/*"
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("text/html", "application/octet-stream"))
addFlags(
@@ -91,107 +265,227 @@ class DocumentsActivity : Activity() {
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
)
- }
- startActivityForResult(intent, REQ_OPEN)
+ }, REQ_OPEN)
}
+ private fun addFolder() = startActivityForResult(Library.intentToGrantFolder(), REQ_FOLDER)
+
/**
- * A new document is seeded from the bundled starter shell.
+ * A new document, of whichever Bento the user wants.
*
- * The user chooses where it goes, which is not a compromise: it means the new
- * document is a real file in the user's own storage from its first byte, with
- * a persistable write grant already attached. There is no app-private staging
- * copy to migrate later, and no file the user cannot find.
+ * The shell is NOT bundled — it is fetched from the signed release channel
+ * (`Releases`), so a document created here is the version everyone else has
+ * today rather than whatever the app was built against. That also makes
+ * "which app?" a real question worth asking, since there are three of them.
*/
private fun newDocument() {
- if (!hasSeed()) {
- AlertDialog.Builder(this)
- .setMessage(getString(R.string.err_no_seed))
- .setPositiveButton(android.R.string.ok, null)
- .show()
- return
- }
- val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
- addCategory(Intent.CATEGORY_OPENABLE)
- type = "text/html"
- putExtra(Intent.EXTRA_TITLE, "Untitled.bento.html")
- addFlags(
- Intent.FLAG_GRANT_READ_URI_PERMISSION or
- Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
- Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
- )
- }
- startActivityForResult(intent, REQ_NEW)
+ val apps = Releases.APPS
+ AlertDialog.Builder(this)
+ .setTitle(R.string.new_document_title)
+ .setItems(apps.map { "${it.label} — ${it.blurb}" }.toTypedArray()) { _, i ->
+ pendingApp = apps[i]
+ startActivityForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
+ addCategory(Intent.CATEGORY_OPENABLE)
+ type = "text/html"
+ putExtra(Intent.EXTRA_TITLE, "Untitled.bento.html")
+ addFlags(
+ Intent.FLAG_GRANT_READ_URI_PERMISSION or
+ Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
+ Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
+ )
+ }, REQ_NEW)
+ }
+ .setNegativeButton(android.R.string.cancel, null)
+ .show()
}
- private fun hasSeed() = try {
- assets.list("")?.contains(SEED) == true
- } catch (_: Exception) { false }
+ private var pendingApp: Releases.App? = null
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val uri = data?.data
if (resultCode != RESULT_OK || uri == null) {
return super.onActivityResult(requestCode, resultCode, data)
}
- Recents.persist(contentResolver, uri, data.flags)
-
when (requestCode) {
- REQ_OPEN -> open(uri)
- REQ_NEW -> seedThenOpen(uri)
+ REQ_FOLDER -> {
+ Library.keepGrant(this, uri, data.flags)
+ rescan(quiet = false)
+ }
+ REQ_OPEN -> { Recents.persist(contentResolver, uri, data.flags); open(uri) }
+ REQ_NEW -> { Recents.persist(contentResolver, uri, data.flags); seedThenOpen(uri) }
else -> super.onActivityResult(requestCode, resultCode, data)
}
}
+ /**
+ * Fetch the signed shell, verify it, and write it into the file the user
+ * just named.
+ *
+ * The fetch is the ONLY network request this app makes on its own account.
+ * It is verified twice over — manifest signature, then the shell's pinned
+ * sha256 — because these bytes become an executable document the user will
+ * afterwards trust. A cached shell from a previous "New" is used when the
+ * server cannot be reached, so this keeps working on a plane.
+ */
private fun seedThenOpen(uri: Uri) {
+ val app = pendingApp ?: Releases.APPS[0]
+ pendingApp = null
Thread {
- val ok = try {
- assets.open(SEED).use { input ->
- contentResolver.openOutputStream(uri, "wt")?.use { input.copyTo(it) }
- ?: throw IllegalStateException("no output stream")
- }
- true
+ var error: String? = null
+ val bytes = try {
+ Releases.seedFor(this, app)
} catch (e: Exception) {
- Log.w(TAG, "seed failed", e); false
+ Log.w(TAG, "could not fetch a seed", e)
+ error = e.message
+ // Offline, or the server is down. A shell cached by an earlier
+ // "New" is still a signed release — it was verified when it was
+ // cached — so it is a sound fallback rather than a guess.
+ Releases.anyCached(this, app)
}
+
+ val ok = bytes != null && try {
+ contentResolver.openOutputStream(uri, "wt")?.use { it.write(bytes) } != null
+ } catch (e: Exception) { Log.w(TAG, "could not write the new document", e); false }
+
+ // ACTION_CREATE_DOCUMENT has already made the file by the time we
+ // get here, so a failed fetch leaves an EMPTY document behind — which
+ // then shows up in the folder and indexes as nothing. Take it back.
+ if (!ok) try { DocumentsContract.deleteDocument(contentResolver, uri) }
+ catch (e: Exception) { Log.w(TAG, "could not remove the empty file", e) }
+
runOnUiThread {
if (isFinishing || isDestroyed) return@runOnUiThread
- if (ok) open(uri) else AlertDialog.Builder(this)
- .setMessage(getString(R.string.err_create))
- .setPositiveButton(android.R.string.ok, null)
- .show()
+ if (ok) open(uri)
+ else notify(getString(R.string.err_create_fetch, error ?: getString(R.string.err_offline)))
}
}.start()
}
- private fun open(uri: Uri) {
+ private fun open(uri: Uri) =
startActivity(Intent(this, EditorActivity::class.java).putExtra(EditorActivity.EXTRA_URI, uri))
+
+ private fun manageFolders() {
+ val grants = Library.grants(this)
+ if (grants.isEmpty()) { addFolder(); return }
+ val labels = grants.map { Library.folderLabel(it) }.toTypedArray()
+ AlertDialog.Builder(this)
+ .setTitle(R.string.folders_title)
+ .setItems(labels) { _, i ->
+ AlertDialog.Builder(this)
+ .setTitle(labels[i])
+ // Emphatically not "delete": the app hands back its key and
+ // forgets what it indexed. The documents do not move.
+ .setMessage(R.string.folder_forget_explain)
+ .setPositiveButton(R.string.forget) { _, _ ->
+ Library.dropGrant(this, grants[i]); refresh()
+ }
+ .setNegativeButton(android.R.string.cancel, null)
+ .show()
+ }
+ .setPositiveButton(R.string.add_folder) { _, _ -> addFolder() }
+ .setNegativeButton(android.R.string.cancel, null)
+ .show()
+ }
+
+ private fun notify(message: String) = AlertDialog.Builder(this)
+ .setMessage(message).setPositiveButton(android.R.string.ok, null).show()
+
+ /** Grid or list. Rebuilds the adapter rather than reusing it: the two modes
+ * produce different view shapes, and GridView recycles by position with no
+ * notion of a view type, so a reused card would be re-fed as a row. */
+ /** How many columns fit. A phone gets 2, a tablet 4 or 5 — a fixed 2 on a
+ * 10" screen wastes most of it, which is the commonest way an Android app
+ * signals it was only ever designed for a phone. */
+ private fun columns(): Int {
+ if (!gridMode) return 1
+ // The grid's share of the window, not the window. With a detail pane the
+ // grid is 1.6 of 2.6, so counting against the full width gave six
+ // columns in a space that comfortably holds four — and the cards came
+ // out too narrow to read their own subtitles.
+ val usable = resources.configuration.screenWidthDp * (if (isWide) 1.6f / 2.6f else 1f)
+ return (usable / 190).toInt().coerceIn(2, 6)
+ }
+
+ private fun applyViewMode() {
+ list.numColumns = columns()
+ viewToggle.text = if (gridMode) "☰" else "▦"
+ viewToggle.contentDescription =
+ getString(if (gridMode) R.string.view_as_list else R.string.view_as_grid)
+ list.adapter = RowAdapter()
+ }
+
+ /**
+ * The theme override, defaulting to the system.
+ *
+ * Deliberately API 31+ only. `setApplicationNightMode` is the sole way to
+ * override the system theme per-app without AndroidX, so below it the app
+ * follows the system and the control is not offered at all — a button that
+ * silently does nothing is worse than no button.
+ */
+ private fun applyNightMode(mode: String) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return
+ getSystemService(UiModeManager::class.java)?.setApplicationNightMode(
+ when (mode) {
+ "light" -> UiModeManager.MODE_NIGHT_NO
+ "dark" -> UiModeManager.MODE_NIGHT_YES
+ else -> UiModeManager.MODE_NIGHT_AUTO
+ }
+ )
+ }
+
+ private fun cycleNightMode() {
+ val next = when (prefs.getString("night", "system")) {
+ "system" -> "light"
+ "light" -> "dark"
+ else -> "system"
+ }
+ prefs.edit().putString("night", next).apply()
+ // Named, because "system" and "light" look identical on a device that is
+ // already light — the screen alone cannot tell you which you picked.
+ Toast.makeText(this, getString(when (next) {
+ "light" -> R.string.theme_light
+ "dark" -> R.string.theme_dark
+ else -> R.string.theme_system
+ }), Toast.LENGTH_SHORT).show()
+ applyNightMode(next)
+ }
+
+ /**
+ * A colour from the theme's roles rather than a fixed resource.
+ *
+ * This is what makes dynamic colour actually apply: `@color/ink` is a
+ * constant and would survive DynamicColors untouched, whereas
+ * `colorOnSurface` is rewritten from the wallpaper on Android 12+ and falls
+ * back to the Bento palette below it.
+ */
+ private fun themed(attr: Int): Int {
+ val tv = android.util.TypedValue()
+ theme.resolveAttribute(attr, tv, true)
+ return if (tv.resourceId != 0) getColor(tv.resourceId) else tv.data
}
- // MARK: - a plain UI, built in code
+ private val inkColor get() = themed(com.google.android.material.R.attr.colorOnSurface)
+ private val dimColor get() = themed(com.google.android.material.R.attr.colorOnSurfaceVariant)
+
+ // ------------------------------------------------- a plain UI, in code
//
- // No layout XML and no AndroidX UI libraries: this screen is a title, two
- // buttons and a list. Every dependency it does not have is one that cannot
- // drift out of step with the WebView work, which is where all the difficulty
- // in this app actually lives.
+ // No layout XML and no AndroidX UI libraries: a title, three buttons, a
+ // search box and a list. Every dependency this screen does not have is one
+ // that cannot drift out of step with the WebView work, which is where all
+ // the difficulty in this app actually lives.
private fun buildUi(): View {
val dp = { v: Int -> (v * resources.displayMetrics.density).toInt() }
- val root = LinearLayout(this).apply {
- orientation = LinearLayout.VERTICAL
- setBackgroundColor(Color.parseColor("#F0EBE0"))
- }
+ // No setBackgroundColor here: Theme.Tray's windowBackground is the
+ // ground, and it follows the system theme. A view that paints its own
+ // is a view that cannot.
+ val root = LinearLayout(this).apply { orientation = LinearLayout.VERTICAL }
- // Insets are applied by hand, and both halves of that are deliberate.
- //
- // `fitsSystemWindows = true` was the first attempt and it is a trap: it
- // does not ADD the system insets to a view's padding, it REPLACES the
- // padding outright. The screen lost its 20dp side margin and the title
- // sat flush against the edge of the display.
- //
- // Doing nothing is not an option either — from targetSdk 35 an app draws
- // edge to edge whether it asks to or not, so the header would sit under
- // the status bar. This is the only way to have both.
- val pad = intArrayOf(dp(20), dp(28), dp(20), dp(12))
+ // Insets by hand. `fitsSystemWindows = true` REPLACES a view's padding
+ // rather than adding to it — the screen lost its side margin that way —
+ // and from targetSdk 35 the app draws edge to edge whether it asks to or
+ // not, so doing nothing puts the header under the status bar.
+ val pad = intArrayOf(dp(20), dp(24), dp(20), dp(8))
root.setOnApplyWindowInsetsListener { v, insets ->
val l: Int; val t: Int; val r: Int; val b: Int
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
@@ -208,100 +502,379 @@ class DocumentsActivity : Activity() {
insets
}
- root.addView(TextView(this).apply {
- text = getString(R.string.app_name)
- setTextSize(TypedValue.COMPLEX_UNIT_SP, 26f)
- setTypeface(typeface, Typeface.BOLD)
- setTextColor(Color.parseColor("#16273E"))
+ val header = LinearLayout(this).apply {
+ orientation = LinearLayout.HORIZONTAL
+ gravity = Gravity.CENTER_VERTICAL
+ }
+ header.addView(ImageView(this).apply {
+ setImageResource(R.drawable.ic_tray_mark)
+ // 24dp with a 9dp gap, matching the extension's `.brand`.
+ layoutParams = LinearLayout.LayoutParams(dp(26), dp(26))
+ .also { it.rightMargin = dp(9) }
+ contentDescription = null // decorative; the wordmark beside it says the name
})
- root.addView(TextView(this).apply {
- text = getString(R.string.tagline)
- setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
- setTextColor(Color.parseColor("#5E7699"))
- setPadding(0, dp(4), 0, dp(20))
+ header.addView(TextView(this).apply {
+ text = wordmark()
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 21f)
+ setTypeface(typeface, Typeface.BOLD)
+ setTextColor(inkColor)
+ // -.01em on the wordmark, from `.brand b`. Android's letterSpacing
+ // is already in ems, so the number transfers unchanged.
+ letterSpacing = -0.01f
+ layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
})
+ viewToggle = TextView(this, null, 0, R.style.IconBtn).apply {
+ setOnClickListener {
+ gridMode = !gridMode
+ prefs.edit().putString("view", if (gridMode) "grid" else "list").apply()
+ applyViewMode()
+ }
+ }
+ header.addView(viewToggle)
+ // Only offered where it can be honoured: setApplicationNightMode is API
+ // 31+, and without AndroidX there is no way to override the system
+ // theme below it. A control that silently does nothing is worse than no
+ // control, so older devices simply follow the system.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ header.addView(TextView(this, null, 0, R.style.IconBtn).apply {
+ text = "◐"
+ contentDescription = getString(R.string.theme_toggle)
+ setOnClickListener { cycleNightMode() }
+ })
+ }
+ root.addView(header)
+
+ // Everything below the header belongs to the LIST, so on a wide screen
+ // it sits in the left column and the detail pane gets full height.
+ // Spanning them across both panes left the grid 299px tall in
+ // landscape, which is not a layout so much as a leftover.
+ val col = LinearLayout(this).apply { orientation = LinearLayout.VERTICAL }
+
+ // TextInputLayout rather than a bare EditText: it carries M3's outlined
+ // box, the focus and error states, and — the reason it matters here —
+ // the colour roles dynamic colour rewrites.
+ val searchBox = TextInputLayout(
+ this, null, com.google.android.material.R.attr.textInputOutlinedStyle
+ ).apply {
+ hint = getString(R.string.search_hint)
+ isHintEnabled = true
+ layoutParams = LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
+ ).also { it.topMargin = dp(10) }
+ }
+ search = TextInputEditText(searchBox.context).apply {
+ setSingleLine()
+ imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_SEARCH
+ addTextChangedListener(object : TextWatcher {
+ override fun afterTextChanged(s: Editable?) = refresh()
+ override fun beforeTextChanged(s: CharSequence?, a: Int, b: Int, c: Int) {}
+ override fun onTextChanged(s: CharSequence?, a: Int, b: Int, c: Int) {}
+ })
+ }
+ searchBox.addView(search)
+ col.addView(searchBox)
+
+ status = TextView(this).apply {
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f)
+ setTextColor(dimColor)
+ setPadding(dp(2), dp(8), dp(2), dp(12))
+ }
+ col.addView(status)
val buttons = LinearLayout(this).apply {
orientation = LinearLayout.HORIZONTAL
- val lp = LinearLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
- lp.bottomMargin = dp(16)
- layoutParams = lp
+ layoutParams = LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
+ ).also { it.bottomMargin = dp(10) }
}
- val half = { LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f) }
- buttons.addView(Button(this).apply {
+ val third = { LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f) }
+ // Styled through R.style.Btn rather than themed, because this screen
+ // builds its views in code — the 4-arg View constructor applies a style
+ // exactly as an XML layout would, with no library involved.
+ // Filled for the primary action, outlined for the rest — M3's own
+ // hierarchy, rather than a hand-rolled one.
+ buttons.addView(MaterialButton(this).apply {
text = getString(R.string.open_document)
- layoutParams = half().also { it.rightMargin = dp(8) }
+ layoutParams = third().also { it.rightMargin = dp(8) }
setOnClickListener { openDocument() }
})
- buttons.addView(Button(this).apply {
+ buttons.addView(MaterialButton(this, null,
+ com.google.android.material.R.attr.materialButtonOutlinedStyle).apply {
text = getString(R.string.new_document)
- layoutParams = half()
+ layoutParams = third().also { it.rightMargin = dp(8) }
setOnClickListener { newDocument() }
})
- root.addView(buttons)
+ buttons.addView(MaterialButton(this, null,
+ com.google.android.material.R.attr.materialButtonOutlinedStyle).apply {
+ text = getString(R.string.folders)
+ layoutParams = third()
+ setOnClickListener { manageFolders() }
+ })
+ col.addView(buttons)
empty = TextView(this).apply {
- text = getString(R.string.empty_hint)
- setTextColor(Color.parseColor("#5E7699"))
+ setTextColor(dimColor)
setTextSize(TypedValue.COMPLEX_UNIT_SP, 15f)
gravity = Gravity.CENTER
- setPadding(dp(8), dp(48), dp(8), dp(8))
+ setPadding(dp(8), dp(40), dp(8), dp(8))
visibility = View.GONE
}
- root.addView(empty)
+ col.addView(empty)
- list = ListView(this).apply {
- divider = null
- adapter = RecentsAdapter()
- layoutParams = LinearLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
- setOnItemClickListener { _, _, i, _ -> open(entries[i].uri) }
+ list = GridView(this).apply {
+ adapter = RowAdapter()
+ horizontalSpacing = dp(10)
+ verticalSpacing = dp(10)
+ layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
+ // On a phone a tap opens, because there is nowhere else for it to
+ // go. With a detail pane, a tap selects — and the pane's button
+ // opens — which is what makes the pane worth having.
+ setOnItemClickListener { _, _, i, _ ->
+ if (isWide) showDetail(rows[i]) else open(rows[i].uri)
+ }
setOnItemLongClickListener { _, _, i, _ ->
- val e = entries[i]
+ val r = rows[i]
AlertDialog.Builder(this@DocumentsActivity)
- .setTitle(e.name)
- // "Remove" is emphatically not "delete". The app hands back
- // its key; the document stays exactly where it is.
+ .setTitle(r.label)
.setMessage(getString(R.string.forget_explain))
.setPositiveButton(R.string.forget) { _, _ ->
- Recents.forget(this@DocumentsActivity, e.uri); refresh()
+ Recents.forget(this@DocumentsActivity, r.uri); refresh()
}
.setNegativeButton(android.R.string.cancel, null)
.show()
true
}
}
- root.addView(list)
+ // On a wide screen the list shares the window with a detail pane; on a
+ // phone it simply fills it. Same views either way — only the container
+ // differs, so there is no second layout to keep in step.
+ col.addView(list, LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f))
+
+ if (!isWide) {
+ root.addView(col, LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f))
+ applyViewMode()
+ return root
+ }
+
+ val split = LinearLayout(this).apply {
+ orientation = LinearLayout.HORIZONTAL
+ layoutParams = LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
+ }
+ split.addView(col, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1.6f))
+ split.addView(buildDetail(), LinearLayout.LayoutParams(
+ 0, ViewGroup.LayoutParams.MATCH_PARENT, 1f
+ ).also { it.leftMargin = dp(16) })
+ root.addView(split)
+ applyViewMode()
return root
}
- private inner class RecentsAdapter : BaseAdapter() {
- override fun getCount() = entries.size
- override fun getItem(i: Int) = entries[i]
+ /**
+ * What a wide screen does with the room a phone does not have: the document
+ * you are pointing at, big enough to recognise, with what is known about it.
+ *
+ * A thumbnail at this size is the whole argument for rendering one — at
+ * 64x36 in a list row it is a hint, at 400px it is the document.
+ */
+ private fun buildDetail(): View {
+ val dp = { v: Int -> (v * resources.displayMetrics.density).toInt() }
+ val pane = LinearLayout(this).apply {
+ orientation = LinearLayout.VERTICAL
+ setPadding(dp(4), dp(4), dp(4), dp(4))
+ }
+ pane.addView(ImageView(this).apply {
+ id = 10
+ layoutParams = LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
+ .also { it.bottomMargin = dp(14) }
+ adjustViewBounds = true
+ scaleType = ImageView.ScaleType.FIT_CENTER
+ })
+ pane.addView(TextView(this).apply {
+ id = 11
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f)
+ setTextColor(inkColor)
+ letterSpacing = -0.015f
+ setPadding(0, 0, 0, dp(6))
+ })
+ pane.addView(TextView(this).apply {
+ id = 12
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f)
+ setTextColor(dimColor)
+ setPadding(0, 0, 0, dp(16))
+ })
+ pane.addView(MaterialButton(this).apply {
+ id = 13
+ text = getString(R.string.open_selected)
+ setOnClickListener { selected?.let { open(it.uri) } }
+ })
+ detail = pane
+ showDetail(null)
+ return pane
+ }
+
+ private fun showDetail(r: Row?) {
+ val pane = detail ?: return
+ selected = r
+ val thumb = pane.findViewById<ImageView>(10)
+ val title = pane.findViewById<TextView>(11)
+ val sub = pane.findViewById<TextView>(12)
+ val open = pane.findViewById<MaterialButton>(13)
+
+ if (r == null) {
+ // GONE, not just empty: an ImageView with adjustViewBounds and no
+ // drawable still claims height, which pushed the empty-state line
+ // into the middle of the pane.
+ thumb.visibility = View.GONE
+ thumb.setImageBitmap(null)
+ thumb.background = null
+ title.text = getString(R.string.detail_none)
+ title.setTextColor(dimColor)
+ sub.text = ""
+ open.visibility = View.GONE
+ return
+ }
+ thumb.visibility = View.VISIBLE
+ title.text = if (r.encrypted) "🔒 ${r.label}" else r.label
+ title.setTextColor(inkColor)
+ sub.text = "${r.sub}\n${DateUtils.getRelativeTimeSpanString(
+ r.modified, System.currentTimeMillis(), 0)}"
+ open.visibility = View.VISIBLE
+ thumb.setImageBitmap(null)
+ thumb.background = getDrawable(R.drawable.bg_thumb)
+ if (r.hasPreview) {
+ val key = "${r.uri}|${r.modified}"
+ thumb.tag = key
+ Thumbnails.request(this, r.uri, r.modified) { bmp ->
+ if (bmp != null && thumb.tag == key) thumb.setImageBitmap(bmp)
+ }
+ }
+ }
+
+ private inner class RowAdapter : BaseAdapter() {
+ override fun getCount() = rows.size
+ override fun getItem(i: Int) = rows[i]
override fun getItemId(i: Int) = i.toLong()
override fun getView(i: Int, convert: View?, parent: ViewGroup): View {
- val dp = { v: Int -> (v * resources.displayMetrics.density).toInt() }
- val row = (convert as? LinearLayout) ?: LinearLayout(this@DocumentsActivity).apply {
+ val r = rows[i]
+ val row = (convert as? ViewGroup) ?: if (gridMode) buildCard(parent) else buildRow()
+
+ row.findViewById<TextView>(1).text = if (r.encrypted) "🔒 ${r.label}" else r.label
+ row.findViewById<TextView>(2).text = r.sub
+
+ val thumb = row.findViewById<ImageView>(3)
+ // The KEY, not the position: the collection recycles views, so a
+ // thumbnail that finishes after its cell scrolled away would
+ // otherwise be drawn onto whatever document now occupies it.
+ val key = "${r.uri}|${r.modified}"
+ thumb.tag = key
+ thumb.setImageBitmap(null)
+ thumb.background = getDrawable(R.drawable.bg_thumb)
+ if (r.hasPreview) {
+ Thumbnails.request(this@DocumentsActivity, r.uri, r.modified) { bmp ->
+ if (bmp != null && thumb.tag == key) thumb.setImageBitmap(bmp)
+ }
+ }
+ return row
+ }
+
+ private fun dp(v: Int) = (v * resources.displayMetrics.density).toInt()
+
+ /** A card: the thumbnail carries the row, which is the point of having
+ * rendered one. Matches how tray/webext presents a folder. */
+ private fun buildCard(parent: ViewGroup): ViewGroup {
+ // GridView cells size to content, so a card's thumbnail needs an
+ // explicit height to hold 16:9.
+ //
+ // Measured from the GRID, not estimated from the screen. The screen
+ // is the wrong number twice over: a hardcoded column count sized
+ // every card for a phone, and once there is a detail pane the grid
+ // is only part of the width anyway. By the time getView runs the
+ // grid has been measured, so ask it — and keep the estimate only for
+ // the first pass, before it has a width to report.
+ val cols = columns()
+ val gridW = if (parent.width > 0) parent.width.toFloat()
+ else resources.displayMetrics.widthPixels * (if (isWide) 1.6f / 2.6f else 1f)
+ val cellW = (gridW / cols).toInt() - dp(10) - dp(16)
+ // A MaterialCardView rather than a padded box: it carries M3's
+ // surface role, shape and outline, so it follows dynamic colour and
+ // the dark set without any of them being restated here.
+ return MaterialCardView(this@DocumentsActivity).apply {
+ radius = dp(12).toFloat()
+ cardElevation = 0f
+ strokeWidth = dp(1)
+ strokeColor = themed(com.google.android.material.R.attr.colorOutlineVariant)
+ setCardBackgroundColor(themed(com.google.android.material.R.attr.colorSurfaceContainerLow))
+ isClickable = true
+ isFocusable = true
+ addView(LinearLayout(context).apply {
+ orientation = LinearLayout.VERTICAL
+ setPadding(dp(8), dp(8), dp(8), dp(10))
+ addView(ImageView(context).apply {
+ id = 3
+ layoutParams = LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, cellW * 9 / 16)
+ scaleType = ImageView.ScaleType.CENTER_CROP
+ clipToOutline = true
+ })
+ addView(TextView(context).apply {
+ id = 1
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
+ setTextColor(inkColor)
+ typeface = emphasis()
+ maxLines = 2
+ ellipsize = android.text.TextUtils.TruncateAt.END
+ setPadding(dp(2), dp(8), dp(2), 0)
+ })
+ addView(TextView(context).apply {
+ id = 2
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f)
+ setTextColor(dimColor)
+ maxLines = 1
+ ellipsize = android.text.TextUtils.TruncateAt.END
+ setPadding(dp(2), dp(2), dp(2), 0)
+ })
+ })
+ }
+ }
+
+ private fun buildRow(): LinearLayout = LinearLayout(this@DocumentsActivity).apply {
+ orientation = LinearLayout.HORIZONTAL
+ gravity = Gravity.CENTER_VERTICAL
+ setPadding(dp(10), dp(12), dp(10), dp(12))
+ background = getDrawable(R.drawable.bg_row)
+ addView(ImageView(context).apply {
+ id = 3
+ layoutParams = LinearLayout.LayoutParams(dp(64), dp(36))
+ .also { it.rightMargin = dp(14) }
+ scaleType = ImageView.ScaleType.FIT_CENTER
+ clipToOutline = true
+ })
+ addView(LinearLayout(context).apply {
orientation = LinearLayout.VERTICAL
- setPadding(dp(14), dp(14), dp(14), dp(14))
+ layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
addView(TextView(context).apply {
id = 1
setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
- setTextColor(Color.parseColor("#16273E"))
+ setTextColor(inkColor)
})
addView(TextView(context).apply {
id = 2
setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f)
- setTextColor(Color.parseColor("#5E7699"))
+ setTextColor(dimColor)
})
- }
- val e = entries[i]
- row.findViewById<TextView>(1).text = e.name
- row.findViewById<TextView>(2).text =
- DateUtils.getRelativeTimeSpanString(e.openedAt, System.currentTimeMillis(), 0)
- return row
+ })
}
+
+ /** `font-weight: 600` in the extension. Real 600 exists from API 28;
+ * below it the nearest the framework offers is bold. */
+ private fun emphasis(): Typeface =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
+ Typeface.create(Typeface.DEFAULT, 600, false)
+ else Typeface.DEFAULT_BOLD
}
}
diff --git a/tray/android/app/src/main/java/page/bento/tray/Library.kt b/tray/android/app/src/main/java/page/bento/tray/Library.kt
new file mode 100644
index 00000000..67470473
--- /dev/null
+++ b/tray/android/app/src/main/java/page/bento/tray/Library.kt
@@ -0,0 +1,325 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+
+package page.bento.tray
+
+import android.content.ContentValues
+import android.content.Context
+import android.content.Intent
+import android.database.sqlite.SQLiteDatabase
+import android.database.sqlite.SQLiteOpenHelper
+import android.net.Uri
+import android.provider.DocumentsContract
+import android.util.Log
+
+/**
+ * The documents this app can reach, and what is inside them.
+ *
+ * `Recents` is a keyring — the documents you have opened. This is a LIBRARY: a
+ * folder you grant once, walked and indexed, so a document is findable by a
+ * phrase on one of its slides rather than only by what you happened to call the
+ * file. That is what `tray/webext` has had and neither native host did.
+ *
+ * The grant is `ACTION_OPEN_DOCUMENT_TREE` plus a persistable permission — the
+ * Android analogue of the extension's `showDirectoryPicker` and of a
+ * security-scoped bookmark on iOS. Nothing is copied: the index holds text and
+ * a preview, the documents stay where the user put them.
+ *
+ * SQLite rather than a JSON file, because search has to scan the prose of every
+ * document and the budget is 40KB EACH. A few hundred documents is megabytes,
+ * which is fine on disk and ruinous to parse into memory on every launch.
+ */
+object Library {
+
+ private const val TAG = "BentoTray"
+
+ /** Depth cap for the walk. A granted folder can be a whole home directory,
+ * and a symlinked or pathological tree should cost a bounded amount. */
+ private const val MAX_DEPTH = 8
+
+ /** Files examined per scan. A ceiling, not a target — reported to the user
+ * when hit rather than silently truncating, because a library that quietly
+ * stops at N is a library that lies about what it holds. */
+ private const val MAX_FILES = 5000
+
+ data class Doc(
+ val uri: Uri, val name: String, val folder: String, val title: String?,
+ val app: String?, val encrypted: Boolean, val modified: Long, val hasPreview: Boolean,
+ ) {
+ /** What to show: the document's own title when it has one. Documents are
+ * called `Q3-board.bento.html`; the document knows it is "Q3 Board
+ * Review". Showing the filename when the title is right there is the
+ * difference between a file list and a document list. */
+ val label: String get() = title?.takeIf { it.isNotBlank() } ?: name
+ }
+
+ // ------------------------------------------------------------------ store
+
+ private class Db(context: Context) : SQLiteOpenHelper(context, "library.db", null, 1) {
+ override fun onCreate(db: SQLiteDatabase) {
+ db.execSQL(
+ """CREATE TABLE docs(
+ uri TEXT PRIMARY KEY, name TEXT, folder TEXT, title TEXT, app TEXT,
+ encrypted INTEGER, size INTEGER, modified INTEGER,
+ text TEXT, preview TEXT, seen INTEGER)"""
+ )
+ db.execSQL("CREATE INDEX docs_folder ON docs(folder)")
+ }
+
+ override fun onUpgrade(db: SQLiteDatabase, old: Int, new: Int) {
+ // The index is a CACHE, never the document. Dropping it costs one
+ // rescan and can never lose anything the user wrote.
+ db.execSQL("DROP TABLE IF EXISTS docs")
+ onCreate(db)
+ }
+ }
+
+ private var db: Db? = null
+ private fun db(c: Context) = db ?: Db(c.applicationContext).also { db = it }
+
+ // ----------------------------------------------------------------- grants
+
+ /** Folders the user has granted, as tree URIs. */
+ fun grants(c: Context): List<Uri> = c.contentResolver.persistedUriPermissions
+ .map { it.uri }
+ .filter { DocumentsContract.isTreeUri(it) }
+
+ fun intentToGrantFolder(): Intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
+ addFlags(
+ Intent.FLAG_GRANT_READ_URI_PERMISSION or
+ Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
+ Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
+ )
+ }
+
+ /** Take the durable grant. Write is requested as well as read: a document
+ * found through the library should be editable in place, not read-only —
+ * which is the whole difference this app exists to make. */
+ fun keepGrant(c: Context, tree: Uri, flags: Int) {
+ val wanted = flags and
+ (Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
+ try {
+ c.contentResolver.takePersistableUriPermission(tree, wanted)
+ } catch (e: SecurityException) {
+ Log.w(TAG, "folder grant is not persistable", e)
+ }
+ }
+
+ fun dropGrant(c: Context, tree: Uri) {
+ try {
+ c.contentResolver.releasePersistableUriPermission(
+ tree,
+ Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
+ )
+ } catch (_: SecurityException) { /* already gone; the system owns it */ }
+ db(c).writableDatabase.delete("docs", "folder = ?", arrayOf(folderLabel(tree)))
+ }
+
+ // ------------------------------------------------------------------- scan
+
+ data class ScanResult(val indexed: Int, val examined: Int, val truncated: Boolean)
+
+ /**
+ * Walk every granted folder and index what is ours.
+ *
+ * Re-reads a file only when its size or timestamp changed, so a rescan over
+ * an unchanged folder costs one directory listing per folder and no reads at
+ * all. That matters because the expensive step is not the walk, it is
+ * pulling 40KB of prose out of a megabyte of document.
+ *
+ * SYNCHRONIZED, and not defensively. Each pass stamps the rows it saw and
+ * then deletes everything it did not, so two overlapping scans delete each
+ * other's work: the newly-granted folder indexed 2 documents and the list
+ * showed 0. Granting a folder starts a scan and the resume that follows
+ * starts another, so the overlap is the ordinary path, not a rare one.
+ */
+ @Synchronized
+ fun scan(c: Context): ScanResult {
+ val w = db(c).writableDatabase
+ val stamp = System.currentTimeMillis()
+ var examined = 0
+ var indexed = 0
+ var truncated = false
+
+ for (tree in grants(c)) {
+ val folder = folderLabel(tree)
+ val root = try {
+ DocumentsContract.buildChildDocumentsUriUsingTree(
+ tree, DocumentsContract.getTreeDocumentId(tree)
+ )
+ } catch (e: Exception) {
+ Log.w(TAG, "unusable grant $tree", e); continue
+ }
+ val budget = MAX_FILES - examined
+ val r = walk(c, w, tree, root, folder, 0, budget, stamp)
+ examined += r.first
+ indexed += r.second
+ if (examined >= MAX_FILES) { truncated = true; break }
+ }
+
+ // Anything not seen this pass is gone from the granted folders — deleted,
+ // moved out, or its grant dropped. The row goes with it.
+ w.delete("docs", "seen != ?", arrayOf(stamp.toString()))
+ return ScanResult(indexed, examined, truncated)
+ }
+
+ /** @return examined to indexed */
+ private fun walk(
+ c: Context, w: SQLiteDatabase, tree: Uri, dir: Uri, folder: String,
+ depth: Int, budget: Int, stamp: Long,
+ ): Pair<Int, Int> {
+ if (depth > MAX_DEPTH || budget <= 0) return 0 to 0
+ var examined = 0
+ var indexed = 0
+
+ val cols = arrayOf(
+ DocumentsContract.Document.COLUMN_DOCUMENT_ID,
+ DocumentsContract.Document.COLUMN_DISPLAY_NAME,
+ DocumentsContract.Document.COLUMN_MIME_TYPE,
+ DocumentsContract.Document.COLUMN_SIZE,
+ DocumentsContract.Document.COLUMN_LAST_MODIFIED,
+ )
+ val cursor = try {
+ c.contentResolver.query(dir, cols, null, null, null)
+ } catch (e: Exception) {
+ Log.w(TAG, "cannot list $dir", e); null
+ } ?: return 0 to 0
+
+ cursor.use {
+ while (it.moveToNext()) {
+ if (examined >= budget) break
+ val id = it.getString(0) ?: continue
+ val name = it.getString(1) ?: continue
+ val mime = it.getString(2) ?: ""
+ val size = it.getLong(3)
+ val modified = it.getLong(4)
+
+ if (mime == DocumentsContract.Document.MIME_TYPE_DIR) {
+ val child = DocumentsContract.buildChildDocumentsUriUsingTree(tree, id)
+ val r = walk(c, w, tree, child, folder, depth + 1, budget - examined, stamp)
+ examined += r.first; indexed += r.second
+ continue
+ }
+
+ // Only plausible pages are opened at all. The name is a
+ // convention and conventions get broken by people — renamed to
+ // email it, saved with a browser's "(1)" — so `.html` counts as
+ // well as `.bento.html`, and what settles it is the marker
+ // inside. Everything else is skipped without a read.
+ if (!name.endsWith(".html", true) && !name.endsWith(".htm", true)) continue
+ examined++
+
+ val uri = DocumentsContract.buildDocumentUriUsingTree(tree, id)
+ if (indexOne(c, w, uri, name, folder, size, modified, stamp)) indexed++
+ }
+ }
+ return examined to indexed
+ }
+
+ /** @return whether this file is one of ours */
+ private fun indexOne(
+ c: Context, w: SQLiteDatabase, uri: Uri, name: String, folder: String,
+ size: Long, modified: Long, stamp: Long,
+ ): Boolean {
+ // Unchanged since last time? Touch it and read nothing.
+ w.rawQuery(
+ "SELECT size, modified FROM docs WHERE uri = ?", arrayOf(uri.toString())
+ ).use {
+ if (it.moveToFirst() && it.getLong(0) == size && it.getLong(1) == modified) {
+ w.execSQL("UPDATE docs SET seen = ? WHERE uri = ?", arrayOf<Any>(stamp, uri.toString()))
+ return true
+ }
+ }
+
+ val whole = try {
+ c.contentResolver.openInputStream(uri)?.use { it.readBytes().toString(Charsets.UTF_8) }
+ } catch (e: Exception) {
+ Log.w(TAG, "cannot read $name", e); null
+ } ?: return false
+
+ val meta = DocumentIndex.describe(whole)
+ if (!meta.isDocument) {
+ // Remember nothing about other people's HTML, but do not keep
+ // re-reading it either — the row would be a lie in a document list.
+ w.delete("docs", "uri = ?", arrayOf(uri.toString()))
+ return false
+ }
+
+ w.insertWithOnConflict("docs", null, ContentValues().apply {
+ put("uri", uri.toString()); put("name", name); put("folder", folder)
+ put("title", meta.title); put("app", meta.app)
+ put("encrypted", if (meta.encrypted) 1 else 0)
+ put("size", size); put("modified", modified)
+ put("text", meta.text); put("preview", meta.preview)
+ put("seen", stamp)
+ }, SQLiteDatabase.CONFLICT_REPLACE)
+ return true
+ }
+
+ // ----------------------------------------------------------------- search
+
+ /**
+ * Title, file name, folder — and the document's own words.
+ *
+ * The last one is the point. What you remember is a phrase ON a slide, not
+ * what you called the file, and the bytes to answer that were already read
+ * for the preview.
+ */
+ fun search(c: Context, query: String, limit: Int = 300): List<Doc> {
+ val q = query.trim()
+ val where: String
+ val args: Array<String>
+ if (q.isEmpty()) {
+ where = ""; args = emptyArray()
+ } else {
+ val like = "%" + q.replace("!", "!!").replace("%", "!%").replace("_", "!_") + "%"
+ where = """WHERE (title LIKE ? ESCAPE '!' OR name LIKE ? ESCAPE '!'
+ OR folder LIKE ? ESCAPE '!' OR text LIKE ? ESCAPE '!')"""
+ args = arrayOf(like, like, like, like)
+ }
+ val out = ArrayList<Doc>()
+ db(c).readableDatabase.rawQuery(
+ """SELECT uri, name, folder, title, app, encrypted, modified,
+ preview IS NOT NULL AND preview != ''
+ FROM docs $where ORDER BY modified DESC LIMIT $limit""", args
+ ).use {
+ while (it.moveToNext()) {
+ out += Doc(
+ uri = Uri.parse(it.getString(0)), name = it.getString(1),
+ folder = it.getString(2), title = it.getString(3), app = it.getString(4),
+ encrypted = it.getInt(5) == 1, modified = it.getLong(6),
+ hasPreview = it.getInt(7) == 1,
+ )
+ }
+ }
+ return out
+ }
+
+ /**
+ * One document's stored preview, fetched only when something is about to
+ * draw it.
+ *
+ * Deliberately NOT part of [search]: a preview block runs to tens of
+ * kilobytes, so selecting it for every row of a 300-document list would pull
+ * megabytes of markup into memory to show a handful of pictures.
+ */
+ fun previewFor(c: Context, uri: Uri): String? =
+ db(c).readableDatabase.rawQuery(
+ "SELECT preview FROM docs WHERE uri = ?", arrayOf(uri.toString())
+ ).use { if (it.moveToFirst()) it.getString(0) else null }
+
+ fun count(c: Context): Int =
+ db(c).readableDatabase.rawQuery("SELECT COUNT(*) FROM docs", null).use {
+ if (it.moveToFirst()) it.getInt(0) else 0
+ }
+
+ /** A readable name for a granted tree. The tree document id is the closest
+ * thing a provider offers to a path, and its last segment is what the user
+ * actually picked. */
+ fun folderLabel(tree: Uri): String = try {
+ DocumentsContract.getTreeDocumentId(tree).substringAfterLast(':')
+ .substringAfterLast('/').ifEmpty { tree.lastPathSegment ?: "folder" }
+ } catch (_: Exception) {
+ tree.lastPathSegment ?: "folder"
+ }
+}
diff --git a/tray/android/app/src/main/java/page/bento/tray/Releases.kt b/tray/android/app/src/main/java/page/bento/tray/Releases.kt
new file mode 100644
index 00000000..5f43b207
--- /dev/null
+++ b/tray/android/app/src/main/java/page/bento/tray/Releases.kt
@@ -0,0 +1,378 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+
+package page.bento.tray
+
+import android.content.Context
+import android.util.Log
+import org.json.JSONObject
+import java.io.File
+import java.math.BigInteger
+import java.net.HttpURLConnection
+import java.net.URL
+import java.security.AlgorithmParameters
+import java.security.KeyFactory
+import java.security.MessageDigest
+import java.security.Signature
+import java.security.spec.ECGenParameterSpec
+import java.security.spec.ECParameterSpec
+import java.security.spec.ECPoint
+import java.security.spec.ECPublicKeySpec
+import java.util.Base64
+
+/**
+ * Where a NEW document comes from.
+ *
+ * **Starter decks are never bundled.** They change often, and there are already
+ * three apps with more coming — so a bundled seed means either picking one
+ * arbitrarily or shipping several copies of Bento inside the app, each stale
+ * from the moment it was built. Measured before this changed: the single
+ * bundled slides seed was 517,161 bytes, **81% of a 630,851-byte release APK**.
+ *
+ * So the shell is fetched from the same signed release channel a document uses
+ * to update itself, which also means a document created here is the version
+ * everyone else has, the same day.
+ *
+ * THIS IS THE ONE THING THE HOST FETCHES. The app makes no other network request
+ * — no update check of its own, no telemetry. `docs/PLATFORM.md` §1 requires no
+ * network to OPEN, EDIT, PRESENT or SAVE, and none of those touch this; creating
+ * a document from a template is a different act, and `tray/webext` draws the
+ * line in the same place. The result is cached, so only the first "New" of a
+ * given release needs a connection.
+ *
+ * VERIFICATION IS NOT OPTIONAL HERE. The bytes become an executable HTML
+ * document on the user's own disk that they will afterwards trust, so an
+ * unverified download lets a network attacker choose what they create. Both
+ * halves are checked, exactly as `kernel/src/update.ts` does it: the manifest's
+ * ECDSA signature, and then the shell's sha256 as pinned by the signed payload.
+ * (`tray/webext`'s equivalent does neither — raised separately.)
+ */
+object Releases {
+
+ private const val TAG = "BentoTray"
+
+ /** The apps a new document can be. Mirrors `APPS` in
+ * `tray/webext/src/library.js`; adding one here is the whole integration,
+ * because nothing else in this app asks which Bento a document is. */
+ data class App(val id: String, val label: String, val blurb: String) {
+ val manifest get() = "https://bento.page/releases/$id/manifest.json"
+ /** What a manifest for this app must call itself. Compared against what
+ * the CALLER asked for, never against what the payload claims. */
+ val appId get() = "bento-$id"
+ }
+
+ val APPS = listOf(
+ App("slides", "Slides", "Presentations"),
+ App("spaces", "Spaces", "Notes and pages"),
+ App("dash", "Dash", "Data and sheets"),
+ )
+
+ /** Release signing PUBLIC key, copied from `kernel/src/update.ts`. The
+ * private half lives offline with the maintainer. Rotating it orphans every
+ * previously shipped file, so the key is guarded rather than rotated. */
+ private const val KEY_X = "GMHSKwWcAoJVq-Dz1ZxWZM6TXATWIKbaQBpjoTystH8"
+ private const val KEY_Y = "flFNzbdXCmJN8RQYCeG71rBZnnbN-MCEnp1EbCLFrj0"
+
+ private const val TIMEOUT = 20_000
+
+ class Failed(message: String) : Exception(message)
+
+ /**
+ * The current signed shell for [app], from cache when we already have it.
+ *
+ * Blocking — call it off the main thread.
+ */
+ fun seedFor(c: Context, app: App): ByteArray =
+ resolve(app, Deps(
+ get = ::get,
+ readFloor = { key -> floors(c).getString(key, null) },
+ writeFloor = { key, v -> floors(c).edit().putString(key, v).apply() },
+ cached = { v -> cached(c, app, v) },
+ store = { v, b -> put(c, app, v, b) },
+ ))
+
+ /**
+ * Everything the network can lie about, in the order it has to be checked.
+ *
+ * Dependencies are injected so the sequence can be tested on the JVM without
+ * a device — the two cases that matter (a high version whose bytes fail, and
+ * an equal version) are exactly the ones nobody exercises by hand.
+ */
+ internal class Deps(
+ val get: (String) -> ByteArray,
+ val readFloor: (String) -> String?,
+ val writeFloor: (String, String) -> Unit,
+ val cached: (String) -> ByteArray? = { null },
+ val store: (String, ByteArray) -> Unit = { _, _ -> },
+ )
+
+ internal fun resolve(app: App, d: Deps): ByteArray {
+ // Only slides has a published channel today; spaces and dash 404. Say so
+ // rather than surfacing an HTTP code — the app list is aspirational on
+ // purpose, so an unreleased one is an expected answer, not a fault.
+ val envelope = try { d.get(app.manifest) } catch (e: Failed) {
+ if (e.message?.contains("404") == true)
+ throw Failed("${app.label} has not been released yet")
+ throw e
+ }
+ // The signature is checked HERE, over the exact bytes that arrived, and
+ // everything after it works from the verified payload. Split so the
+ // ORDER of the remaining checks can be tested on the JVM without
+ // manufacturing a signing key — the sequence is what gets these wrong,
+ // not the crypto.
+ val payload = verify(String(envelope, Charsets.UTF_8))
+ return resolveVerified(app, parse(payload), d)
+ }
+
+ /**
+ * What a verified payload says, as data.
+ *
+ * The seam is a struct rather than a JSON string on purpose: `org.json` is
+ * an Android STUB on the JVM rig, so a seam that parses there would be
+ * testing the stub. Parsing happens once, on the device side of the line;
+ * the ORDER of the checks — which is what gets these wrong — is then pure.
+ */
+ internal data class Release(
+ val app: String?, val version: String, val url: String, val sha256: String,
+ )
+
+ private fun parse(payload: JSONObject): Release = Release(
+ // "" for an absent field, normalised to null so the identity check
+ // below compares a genuine absence rather than an empty string.
+ app = payload.optString("app").ifEmpty { null },
+ version = payload.optString("version").ifEmpty {
+ throw Failed("the release server did not name a version")
+ },
+ url = payload.optString("url").ifEmpty {
+ throw Failed("the release server did not offer a build")
+ },
+ sha256 = payload.optString("sha256").lowercase().ifEmpty {
+ throw Failed("the release is not pinned to a hash")
+ },
+ )
+
+ internal fun resolveVerified(app: App, r: Release, d: Deps): ByteArray {
+ // IDENTITY. A genuinely signed bento-slides manifest served on the dash
+ // channel passes the signature AND the digest — every byte authentic,
+ // just not what was asked for. Compared against the app the CALLER
+ // wanted, never against what the payload says about itself.
+ //
+ // An ABSENT field must not read as a match. `named` is null when the
+ // field is missing and `want` is never null, so the comparison already
+ // refuses it — tidying this to `if (named != null && named != want)`
+ // would silently turn a missing field into a pass, which is the hole
+ // tray/webext had.
+ val want = app.appId
+ val named = r.app
+ if (named != want) {
+ throw Failed("the release channel offered ${named ?: "an unnamed app"}, not $want — refusing it")
+ }
+
+ val version = r.version
+
+ // NO DOWNGRADES. Everything above passes for a replayed OLD release: it
+ // is genuinely signed, it names the right app, and its shell really does
+ // hash to its pin. Every byte authentic — just last month's. That is
+ // what survives an origin or CDN compromise where the attacker can
+ // re-serve but cannot forge, so remembering is the only thing that
+ // catches it. kernel/src/update.ts refuses to go backwards too, but it
+ // has its own build version to compare against; a host that CREATES
+ // documents has nothing to compare against but what it has seen.
+ val floor = readFloor(app, d)
+ if (floor != null && compareVersions(version, floor) < 0) {
+ throw Failed(
+ "the ${app.label} channel offered $version, older than the $floor " +
+ "already seen — refusing it"
+ )
+ }
+
+ d.cached(version)?.let { return it }
+
+ val shell = d.get(r.url)
+ val got = MessageDigest.getInstance("SHA-256").digest(shell)
+ .joinToString("") { "%02x".format(it) }
+ if (got != r.sha256) throw Failed("the downloaded app did not match its signed hash — refusing it")
+
+ // Raised only NOW, after the bytes passed their digest. Raising it on a
+ // merely-verified manifest would let one forged-but-unfetchable release
+ // naming 9.9.9 lock this device out of every real release below it —
+ // turning a failed attack into a permanent denial of service.
+ raiseFloor(app, version, floor, d)
+
+ d.store(version, shell)
+ return shell
+ }
+
+ // ------------------------------------------------------------------- floor
+
+ private fun floorKey(app: App) = "release-floor:${app.id}"
+
+ /** An unreadable store reads as NO FLOOR, not as a refusal. Private mode,
+ * quota, a migration mid-flight — being unable to remember must not mean
+ * being unable to create a document. */
+ private fun readFloor(app: App, d: Deps): String? =
+ try { d.readFloor(floorKey(app))?.ifEmpty { null } } catch (_: Exception) { null }
+
+ private fun raiseFloor(app: App, version: String, floor: String?, d: Deps) {
+ // EQUAL is not a downgrade. Re-fetching the version already seen is the
+ // normal case — the second document somebody creates — so treating it as
+ // a rollback would break the + button on its SECOND USE rather than at
+ // some exotic edge.
+ if (floor != null && compareVersions(version, floor) <= 0) return
+ // Best effort: a floor that cannot be written costs protection next
+ // time, not this document.
+ try { d.writeFloor(floorKey(app), version) } catch (_: Exception) { }
+ }
+
+ /**
+ * The kernel's comparison semantics, not a third set.
+ *
+ * Note what JavaScript's `(pa[i] || 0) - (pb[i] || 0)` actually does with a
+ * component that will not parse: `Number('1a')` is NaN, NaN is FALSY, so it
+ * coerces to 0 rather than propagating. A strange version can therefore fail
+ * to RAISE the floor but can never block a release. `toIntOrNull() ?: 0`
+ * reproduces that exactly.
+ */
+ internal fun compareVersions(a: String, b: String): Int {
+ val pa = a.split(".")
+ val pb = b.split(".")
+ for (i in 0 until maxOf(pa.size, pb.size)) {
+ val d = (pa.getOrNull(i)?.toIntOrNull() ?: 0) - (pb.getOrNull(i)?.toIntOrNull() ?: 0)
+ if (d != 0) return d
+ }
+ return 0
+ }
+
+ // ------------------------------------------------------------------ crypto
+
+ /**
+ * Verify the `{payload, sig}` envelope and return the parsed payload.
+ *
+ * The signature covers the EXACT payload string bytes — no canonicalisation,
+ * no re-serialisation. Parse it for reading only, never to re-encode and
+ * verify, or a byte-identical-looking round trip breaks the signature.
+ */
+ private fun verify(raw: String): JSONObject {
+ val env = try { JSONObject(raw) } catch (e: Exception) {
+ throw Failed("the release manifest is not valid JSON")
+ }
+ val payload = env.optString("payload")
+ val sig = env.optString("sig")
+ if (payload.isEmpty() || sig.isEmpty()) throw Failed("the release manifest is malformed")
+
+ val params = AlgorithmParameters.getInstance("EC").apply {
+ init(ECGenParameterSpec("secp256r1"))
+ }.getParameterSpec(ECParameterSpec::class.java)
+
+ val point = ECPoint(BigInteger(1, b64url(KEY_X)), BigInteger(1, b64url(KEY_Y)))
+ val key = KeyFactory.getInstance("EC").generatePublic(ECPublicKeySpec(point, params))
+
+ val ok = try {
+ Signature.getInstance("SHA256withECDSA").run {
+ initVerify(key)
+ update(payload.toByteArray(Charsets.UTF_8))
+ verify(derOf(Base64.getMimeDecoder().decode(sig)))
+ }
+ } catch (e: Exception) {
+ Log.w(TAG, "signature check errored", e); false
+ }
+ if (!ok) throw Failed("the release manifest signature is INVALID — refusing it")
+
+ return try { JSONObject(payload) } catch (e: Exception) {
+ throw Failed("the release payload is not valid JSON")
+ }
+ }
+
+ /**
+ * WebCrypto emits ECDSA signatures as RAW `r || s`; Java expects DER.
+ *
+ * This is the whole reason a correct-looking verification can fail: the
+ * manifest is signed by `scripts/sign-release.mjs` through WebCrypto, so its
+ * 64 bytes are two fixed-width integers, and handing those to
+ * `SHA256withECDSA` unconverted is simply a bad signature. Silent, and
+ * indistinguishable from tampering.
+ */
+ private fun derOf(raw: ByteArray): ByteArray {
+ if (raw.size != 64) return raw // already DER, or not something we made
+ fun int(b: ByteArray): ByteArray {
+ var i = 0
+ while (i < b.size - 1 && b[i] == 0.toByte()) i++ // drop leading zeros
+ var v = b.copyOfRange(i, b.size)
+ if (v[0].toInt() and 0x80 != 0) v = byteArrayOf(0) + v // keep it positive
+ return byteArrayOf(0x02, v.size.toByte()) + v
+ }
+ val body = int(raw.copyOfRange(0, 32)) + int(raw.copyOfRange(32, 64))
+ return byteArrayOf(0x30, body.size.toByte()) + body
+ }
+
+ /** java.util.Base64, not android.util.Base64: the Android one is a STUB in
+ * unit tests, and this routine is the part most worth testing. Available
+ * since API 26, which is minSdk. */
+ private fun b64url(s: String): ByteArray = Base64.getUrlDecoder().decode(s)
+
+ // ------------------------------------------------------------------- net
+
+ private fun get(url: String): ByteArray {
+ if (!url.startsWith("https://")) throw Failed("the release server offered a non-HTTPS build")
+ val c = URL(url).openConnection() as HttpURLConnection
+ c.connectTimeout = TIMEOUT
+ c.readTimeout = TIMEOUT
+ c.setRequestProperty("Cache-Control", "no-store")
+ // ASK FOR BYTES, NOT A PAGE. HttpURLConnection's default Accept is
+ // browser-shaped ("text/html, image/gif, …"), and bento.page sits behind
+ // a CDN that INJECTS a tracking beacon into anything it believes is a
+ // page being browsed. That made the download 359 bytes longer than the
+ // release the maintainer signed, and the hash check below refused it —
+ // correctly. `Accept: */*` asks for the artifact itself.
+ //
+ // The hash check is the actual defence and stays regardless: this header
+ // avoids a known rewrite, it does not make the bytes trustworthy.
+ c.setRequestProperty("Accept", "*/*")
+ try {
+ if (c.responseCode !in 200..299) throw Failed("the release server answered ${c.responseCode}")
+ return c.inputStream.use { it.readBytes() }
+ } finally {
+ c.disconnect()
+ }
+ }
+
+ // ----------------------------------------------------------------- cache
+
+ /** Kept in filesDir, not cacheDir: this is what makes "New" work offline
+ * after the first time, so it should not evaporate under storage pressure
+ * the way a thumbnail happily can. */
+ private fun floors(c: Context) =
+ c.getSharedPreferences("releases", Context.MODE_PRIVATE)
+
+ private fun cacheFile(c: Context, app: App, version: String) =
+ File(File(c.filesDir, "seeds"), "${app.id}-$version.html")
+
+ private fun cached(c: Context, app: App, version: String): ByteArray? {
+ val f = cacheFile(c, app, version)
+ return if (f.exists() && f.length() > 0) try { f.readBytes() } catch (_: Exception) { null }
+ else null
+ }
+
+ private fun put(c: Context, app: App, version: String, bytes: ByteArray) {
+ try {
+ val f = cacheFile(c, app, version)
+ f.parentFile?.mkdirs()
+ f.writeBytes(bytes)
+ // One release per app is enough to work offline; older ones are dead
+ // weight the moment a newer one is cached.
+ f.parentFile?.listFiles()
+ ?.filter { it.name.startsWith("${app.id}-") && it.name != f.name }
+ ?.forEach { it.delete() }
+ } catch (e: Exception) {
+ Log.w(TAG, "could not cache the seed", e)
+ }
+ }
+
+ /** The newest cached shell for [app], whatever its version — the offline
+ * fallback when the release server cannot be reached at all. */
+ fun anyCached(c: Context, app: App): ByteArray? =
+ File(c.filesDir, "seeds").listFiles()
+ ?.filter { it.name.startsWith("${app.id}-") }
+ ?.maxByOrNull { it.lastModified() }
+ ?.let { try { it.readBytes() } catch (_: Exception) { null } }
+}
diff --git a/tray/android/app/src/main/java/page/bento/tray/Thumbnails.kt b/tray/android/app/src/main/java/page/bento/tray/Thumbnails.kt
new file mode 100644
index 00000000..b060fa06
--- /dev/null
+++ b/tray/android/app/src/main/java/page/bento/tray/Thumbnails.kt
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+
+package page.bento.tray
+
+import android.content.Context
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import android.graphics.Canvas
+import android.graphics.Color
+import android.net.Uri
+import android.os.Build
+import android.os.Handler
+import android.os.Looper
+import android.util.Log
+import android.view.View
+import android.view.ViewGroup
+import android.webkit.WebView
+import android.webkit.WebViewClient
+import java.io.File
+import java.security.MessageDigest
+
+/**
+ * First-page thumbnails, rendered once and cached as bitmaps.
+ *
+ * The other two hosts get this free and in different ways, which is worth
+ * knowing before reading the code here:
+ *
+ * - **iOS renders nothing.** `UIDocumentBrowserViewController` asks the SYSTEM
+ * to thumbnail the `.bento.html`, and the iOS thumbnailer draws the embedded
+ * `[data-bento-preview]` block because it runs no JavaScript. That block
+ * exists precisely so file managers can do this (`kernel/src/preview.ts`).
+ * - **tray/webext** sets `iframe.srcdoc = preview`. It is a browser.
+ *
+ * Android has neither: no system HTML thumbnailer (`getDocumentThumbnail` asks
+ * the provider, and the downloads provider has nothing for an HTML file), and a
+ * native list is not a browser. So this host is the only one that renders the
+ * block itself.
+ *
+ * ONE WebView, OFFSCREEN, AT INDEX TIME — emphatically not one per row. A
+ * WebView per list row is the design rejected in `docs/DECISIONS.md` for cold
+ * start and accessibility, and for a while that ruled out thumbnails here
+ * altogether. It should not have: rendering each preview once into a cached
+ * bitmap costs nothing at launch, leaves the list plain `ImageView`s, and reuses
+ * a single WebView for every document.
+ *
+ * The bitmaps live in `cacheDir`, which Android empties under storage pressure —
+ * exactly right for something reconstructible from a document we still hold.
+ */
+object Thumbnails {
+
+ private const val TAG = "BentoTray"
+
+ /** Output size, at the deck's canonical 16:9. A deck with a different page
+ * size letterboxes inside this rather than distorting. */
+ private const val W = 384
+ private const val H = 216
+
+ /** WebView lays out and scales in DP, and the capture is in PIXELS. Ignoring
+ * that renders everything `density` times too large and captures a crop —
+ * the slide's text filled the frame with three letters of it. So the render
+ * box is W x H DP, which is W*density x H*density pixels, and the bitmap is
+ * scaled down afterwards. Rendering large and downscaling also gives
+ * noticeably crisper text than rendering at final size. */
+ private fun renderW(c: Context) = (W * c.resources.displayMetrics.density).toInt()
+ private fun renderH(c: Context) = (H * c.resources.displayMetrics.density).toInt()
+
+ private val main = Handler(Looper.getMainLooper())
+
+ /** Documents whose preview produced nothing. Without this the list retries
+ * the same failing render every time it scrolls past. */
+ private val barren = HashSet<String>()
+
+ private fun keyOf(uri: Uri, modified: Long): String {
+ val d = MessageDigest.getInstance("SHA-256")
+ .digest("$uri|$modified".toByteArray())
+ return d.joinToString("") { "%02x".format(it) }.take(24)
+ }
+
+ private fun fileFor(c: Context, key: String) = File(File(c.cacheDir, "thumbs"), "$key.webp")
+
+ /** The cached bitmap, or null. Cheap enough to call from a list adapter. */
+ fun cached(c: Context, uri: Uri, modified: Long): Bitmap? {
+ val f = fileFor(c, keyOf(uri, modified))
+ if (!f.exists()) return null
+ return try {
+ BitmapFactory.decodeFile(f.absolutePath)
+ } catch (e: Exception) {
+ Log.w(TAG, "unreadable thumb", e); null
+ }
+ }
+
+ /**
+ * Render one document's preview, then call back on the main thread.
+ *
+ * Serialised through a single WebView because a WebView may only be touched
+ * from the main thread, and because rendering several at once would buy
+ * nothing — each is a still frame that draws in milliseconds.
+ */
+ fun request(c: Context, uri: Uri, modified: Long, done: (Bitmap?) -> Unit) {
+ val key = keyOf(uri, modified)
+ if (key in barren) { done(null); return }
+ cached(c, uri, modified)?.let { done(it); return }
+ queue += Pending(c.applicationContext, uri, modified, key, done)
+ pump()
+ }
+
+ private class Pending(
+ val ctx: Context, val uri: Uri, val modified: Long, val key: String,
+ val done: (Bitmap?) -> Unit,
+ )
+
+ private val queue = ArrayDeque<Pending>()
+ private var busy = false
+ private var web: WebView? = null
+ private var host: ViewGroup? = null
+
+ /**
+ * Give the renderer a real window to live in.
+ *
+ * A detached WebView draws the wrong thing, not nothing: `measure`/`layout`
+ * on a view with no window never reaches the renderer, so the CSS viewport
+ * stays at WebView's default (~980px) while the capture box is a fraction of
+ * that — and the preview block, which sizes itself against 100vw, rendered
+ * at 980 and was captured as a magnified crop of its top-left corner.
+ *
+ * So the WebView is attached, sized exactly W x H, and made invisible with
+ * alpha rather than visibility: GONE and INVISIBLE both skip the layout or
+ * the draw this depends on.
+ */
+ fun attach(container: ViewGroup) { host = container }
+
+ private fun pump() {
+ if (busy || queue.isEmpty()) return
+ busy = true
+ val job = queue.removeFirst()
+
+ // The preview is fetched only now, and only for what is actually being
+ // drawn. Selecting it for every row of a 300-document list would pull
+ // megabytes of markup into memory to show a handful of pictures.
+ val html = Library.previewFor(job.ctx, job.uri)
+ if (html.isNullOrBlank()) {
+ barren += job.key
+ finish(job, null)
+ return
+ }
+
+ val parent = host
+ if (parent == null) { finish(job, null); return }
+
+ val v = web ?: WebView(parent.context).also {
+ it.settings.javaScriptEnabled = false // a still render; nothing to run
+ it.settings.blockNetworkLoads = true // self-contained, and stays that way
+ // Without BOTH of these WebView ignores the page's viewport and lays
+ // out at its default ~980 CSS px. The preview block sizes itself
+ // against 100vw, so it then scaled to 980 while the view was ~128 CSS
+ // px wide and the capture was a magnified crop of the top-left
+ // corner — dots and a stray curve, no slide.
+ it.settings.useWideViewPort = true
+ it.settings.loadWithOverviewMode = true
+ it.setBackgroundColor(Color.WHITE)
+ // Software layer, because the bitmap comes from draw(Canvas) and a
+ // hardware-accelerated layer has nothing for that canvas to copy.
+ it.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
+ it.alpha = 0f
+ it.isFocusable = false
+ parent.addView(it, ViewGroup.LayoutParams(renderW(parent.context), renderH(parent.context)))
+ web = it
+ }
+
+ v.webViewClient = object : WebViewClient() {
+ override fun onPageFinished(view: WebView, url: String?) {
+ // onPageFinished fires when LOADING is done, which is before the
+ // first frame is composited — capturing here gives a blank
+ // bitmap often enough to look like a bug in the preview itself.
+ // postVisualStateCallback is the API that actually means "the
+ // next draw will show this".
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ view.postVisualStateCallback(1L, object : WebView.VisualStateCallback() {
+ override fun onComplete(requestId: Long) = capture(job, view)
+ })
+ } else {
+ main.postDelayed({ capture(job, view) }, 120)
+ }
+ }
+ }
+
+ // The viewport is pinned to the deck's canonical width, NOT
+ // device-width, and that is the whole trick.
+ //
+ // The preview's outer element is `position:fixed; width:100%;
+ // height:100%` — it covers the VIEWPORT, by design, because a
+ // thumbnailer injects it into the real document. So the viewport has to
+ // be the capture box. `width=device-width` resolves to the SCREEN width
+ // in CSS px, not this view's width, and the mismatch rendered the block
+ // far wider than the box: the capture was a magnified crop of its
+ // top-left corner, all background dots and one stray curve.
+ //
+ // `width=1280` plus loadWithOverviewMode makes WebView lay out at 1280
+ // CSS px — the width Bento decks are authored at — and scale the whole
+ // thing down to fit, which is density-independent and needs no
+ // arithmetic here.
+ val page = """<!DOCTYPE html><html><head><meta name="viewport"
+ content="width=1280"><style>
+ html,body{margin:0;padding:0;width:100%;height:100%;overflow:hidden;background:#fff}
+ </style></head><body>$html</body></html>"""
+ v.loadDataWithBaseURL(null, page, "text/html", "utf-8", null)
+ }
+
+ private fun capture(job: Pending, v: WebView) {
+ val bmp = try {
+ val rw = renderW(job.ctx); val rh = renderH(job.ctx)
+ val full = Bitmap.createBitmap(rw, rh, Bitmap.Config.ARGB_8888)
+ full.eraseColor(Color.WHITE)
+ v.draw(Canvas(full))
+ Bitmap.createScaledBitmap(full, W, H, true).also { if (it !== full) full.recycle() }
+ } catch (e: Exception) {
+ Log.w(TAG, "thumb render failed", e); null
+ }
+ if (bmp != null) write(job, bmp) else barren += job.key
+ finish(job, bmp)
+ }
+
+ private fun write(job: Pending, bmp: Bitmap) {
+ try {
+ val f = fileFor(job.ctx, job.key)
+ f.parentFile?.mkdirs()
+ f.outputStream().use {
+ val fmt = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
+ Bitmap.CompressFormat.WEBP_LOSSY
+ else @Suppress("DEPRECATION") Bitmap.CompressFormat.WEBP
+ bmp.compress(fmt, 80, it)
+ }
+ } catch (e: Exception) {
+ // A thumbnail that cannot be cached costs a re-render, nothing more.
+ Log.w(TAG, "could not cache thumb", e)
+ }
+ }
+
+ private fun finish(job: Pending, bmp: Bitmap?) {
+ busy = false
+ main.post { job.done(bmp) }
+ main.post { pump() }
+ }
+}
diff --git a/tray/android/app/src/main/res/drawable/bg_button_ghost.xml b/tray/android/app/src/main/res/drawable/bg_button_ghost.xml
new file mode 100644
index 00000000..cc26e9ca
--- /dev/null
+++ b/tray/android/app/src/main/res/drawable/bg_button_ghost.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="@color/panel" />
+ <stroke android:width="1dp" android:color="@color/line" />
+ <corners android:radius="@dimen/radius" />
+ </shape>
+ </item>
+</ripple>
diff --git a/tray/android/app/src/main/res/drawable/bg_button_primary.xml b/tray/android/app/src/main/res/drawable/bg_button_primary.xml
new file mode 100644
index 00000000..47d6165a
--- /dev/null
+++ b/tray/android/app/src/main/res/drawable/bg_button_primary.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- A <ripple> rather than a plain shape: pressed and focus feedback is the
+ thing you lose first when you replace a framework background, and it is the
+ part users notice without being able to name. -->
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="@color/accent" />
+ <corners android:radius="@dimen/radius" />
+ </shape>
+ </item>
+</ripple>
diff --git a/tray/android/app/src/main/res/drawable/bg_field.xml b/tray/android/app/src/main/res/drawable/bg_field.xml
new file mode 100644
index 00000000..f5f2f030
--- /dev/null
+++ b/tray/android/app/src/main/res/drawable/bg_field.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The search box. A panel with a hairline, not the framework EditText's
+ underline — the underline is the single most "unstyled Android" element on
+ the screen and reads as a form field rather than a search surface. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="@color/panel" />
+ <stroke android:width="1dp" android:color="@color/line" />
+ <corners android:radius="@dimen/radius" />
+</shape>
diff --git a/tray/android/app/src/main/res/drawable/bg_row.xml b/tray/android/app/src/main/res/drawable/bg_row.xml
new file mode 100644
index 00000000..3bb9f937
--- /dev/null
+++ b/tray/android/app/src/main/res/drawable/bg_row.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Transparent until touched. A document list wants the ROWS to be quiet and
+ the thumbnails to carry the page, so the row earns its background only
+ while the finger is on it. -->
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="@android:color/transparent" />
+ <corners android:radius="@dimen/radius" />
+ </shape>
+ </item>
+</ripple>
diff --git a/tray/android/app/src/main/res/drawable/bg_thumb.xml b/tray/android/app/src/main/res/drawable/bg_thumb.xml
new file mode 100644
index 00000000..3c250adf
--- /dev/null
+++ b/tray/android/app/src/main/res/drawable/bg_thumb.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- What a row shows before its thumbnail has rendered, and for documents that
+ carry no preview at all — an encrypted one never will. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="@color/placeholder" />
+ <corners android:radius="@dimen/radius_small" />
+</shape>
diff --git a/tray/android/app/src/main/res/drawable/ic_tray_mark.xml b/tray/android/app/src/main/res/drawable/ic_tray_mark.xml
new file mode 100644
index 00000000..0a8038f9
--- /dev/null
+++ b/tray/android/app/src/main/res/drawable/ic_tray_mark.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ GENERATED from tray/assets/tray-logo.svg by tray/assets/make-icons.mjs.
+ Do not edit: run `node tray/assets/make-icons.mjs` instead.
+
+ The bento/home mark, for use inside the app. Same source as the launcher
+ icon, so the two cannot drift apart.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="32dp"
+ android:height="32dp"
+ android:viewportWidth="32"
+ android:viewportHeight="32">
+ <path
+ android:fillColor="#16273E"
+ android:pathData="M7,0 H25 A7,7 0 0 1 32,7 V25 A7,7 0 0 1 25,32 H7 A7,7 0 0 1 0,25 V7 A7,7 0 0 1 7,0 Z" />
+ <path
+ android:fillColor="#F0EBE0"
+ android:pathData="M8.6,3.6 H23.4 A5,5 0 0 1 28.4,8.6 V23.4 A5,5 0 0 1 23.4,28.4 H8.6 A5,5 0 0 1 3.6,23.4 V8.6 A5,5 0 0 1 8.6,3.6 Z" />
+ <path
+ android:fillColor="#5E7699"
+ android:pathData="M8.58,6.4 H10.33 A2.18,2.18 0 0 1 12.51,8.58 V23.42 A2.18,2.18 0 0 1 10.33,25.6 H8.58 A2.18,2.18 0 0 1 6.4,23.42 V8.58 A2.18,2.18 0 0 1 8.58,6.4 Z" />
+ <path
+ android:fillColor="#FF9E8A"
+ android:pathData="M16.44,6.4 H23.42 A2.18,2.18 0 0 1 25.6,8.58 V12.95 A2.18,2.18 0 0 1 23.42,15.13 H16.44 A2.18,2.18 0 0 1 14.26,12.95 V8.58 A2.18,2.18 0 0 1 16.44,6.4 Z" />
+ <path
+ android:fillColor="#16273E"
+ android:pathData="M16.44,16.87 H23.42 A2.18,2.18 0 0 1 25.6,19.05 V23.42 A2.18,2.18 0 0 1 23.42,25.6 H16.44 A2.18,2.18 0 0 1 14.26,23.42 V19.05 A2.18,2.18 0 0 1 16.44,16.87 Z" />
+</vector>
diff --git a/tray/android/app/src/main/res/values-night/colors.xml b/tray/android/app/src/main/res/values-night/colors.xml
new file mode 100644
index 00000000..27e2b5c5
--- /dev/null
+++ b/tray/android/app/src/main/res/values-night/colors.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ The DARK palette, from the same source as the light one — the
+ prefers-color-scheme block in tray/webext/src/ui.css.
+
+ Note `accent` inverts: in light it is the navy wordmark colour on white, in
+ dark it becomes the near-white and `on_accent` becomes the dark ground. A
+ primary button is dark-on-light in one theme and light-on-dark in the other,
+ which is why both halves are named rather than one being assumed.
+-->
+<resources>
+ <color name="bg">#0F1720</color>
+ <color name="panel">#16202B</color>
+ <color name="ink">#E7EDF4</color>
+ <color name="dim">#90A1B4</color>
+ <color name="line">#24313F</color>
+ <color name="accent">#E7EDF4</color>
+ <color name="on_accent">#0F1720</color>
+ <color name="placeholder">#24313F</color>
+</resources>
diff --git a/tray/android/app/src/main/res/values/colors.xml b/tray/android/app/src/main/res/values/colors.xml
index d1b4313a..50dbe6d7 100644
--- a/tray/android/app/src/main/res/values/colors.xml
+++ b/tray/android/app/src/main/res/values/colors.xml
@@ -1,6 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- The Bento palette, from tray/assets/tray-logo.svg. -->
+<!--
+ The LIGHT palette. Names and values are taken from tray/webext/src/ui.css so
+ the two surfaces we design ourselves actually look related — the extension is
+ the house style, and it is a cool near-white, not the cream of the logo. (The
+ logo palette lives below and is used only by the launcher icon.)
+
+ values-night/colors.xml redefines every one of these. Anything hardcoded in
+ Kotlin instead of named here is a colour that cannot follow the system theme.
+-->
<resources>
+ <color name="bg">#F6F8FA</color>
+ <color name="panel">#FFFFFF</color>
+ <color name="ink">#17222F</color>
+ <color name="dim">#6B7A8D</color>
+ <color name="line">#E4E9EF</color>
+ <color name="accent">#16273E</color>
+ <color name="on_accent">#FFFFFF</color>
+ <color name="placeholder">#E4E9EF</color>
+
+ <!-- The mark's own colours, for the launcher icon only. These do NOT change
+ with the system theme: the icon is the icon. -->
<color name="tray_navy">#16273E</color>
<color name="tray_cream">#F0EBE0</color>
<color name="tray_steel">#5E7699</color>
diff --git a/tray/android/app/src/main/res/values/dimens.xml b/tray/android/app/src/main/res/values/dimens.xml
new file mode 100644
index 00000000..400108c6
--- /dev/null
+++ b/tray/android/app/src/main/res/values/dimens.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!-- `the r token: 9px` in tray/webext/src/ui.css. Radii are a big part of why two
+ surfaces read as the same family, so it is shared rather than guessed
+ per widget. -->
+ <dimen name="radius">9dp</dimen>
+ <dimen name="radius_small">5dp</dimen>
+ <!-- 48dp is the platform's minimum comfortable touch target. Framework
+ Buttons do not enforce it once you replace their background. -->
+ <dimen name="touch_min">48dp</dimen>
+</resources>
diff --git a/tray/android/app/src/main/res/values/strings.xml b/tray/android/app/src/main/res/values/strings.xml
index b569b9de..8f4b288a 100644
--- a/tray/android/app/src/main/res/values/strings.xml
+++ b/tray/android/app/src/main/res/values/strings.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">Bento Tray</string>
+ <string name="app_name">bento/home</string>
<string name="tagline">Documents that save themselves</string>
- <string name="open_with_label">Edit with Bento Tray</string>
+ <string name="open_with_label">Edit with bento/home</string>
<string name="open_document">Open…</string>
<string name="new_document">New</string>
@@ -15,8 +15,33 @@
<string name="err_create">The new document could not be written.</string>
<string name="err_export">That copy could not be saved.</string>
<string name="err_download">That download could not be saved.</string>
- <string name="err_no_seed">This build has no starter document. Run “npm run build:single” in slides/ and rebuild the app.</string>
<string name="err_webview_old">This device’s WebView is too old to save documents. Update Android System WebView from the Play Store.</string>
- <string name="notice_read_only">This document was opened read-only, so saves will ask where to put a copy. To edit it in place, open it from Bento Tray’s own “Open…” button instead.</string>
+ <string name="notice_read_only">This document was opened read-only, so saves will ask where to put a copy. To edit it in place, open it from bento/home’s own “Open…” button instead.</string>
+
+ <string name="search_hint">Search documents and their contents</string>
+ <string name="folders">Folders</string>
+ <string name="add_folder">Add folder…</string>
+ <string name="folders_title">Indexed folders</string>
+ <string name="folder_forget_explain">Stop indexing this folder? The documents are not deleted — this app just gives back its access and forgets what it found.</string>
+ <string name="status_no_folders">Add a folder to search inside your documents, not just their names.</string>
+ <plurals name="status_indexed">
+ <item quantity="one">%1$d document indexed across %2$d folder(s)</item>
+ <item quantity="other">%1$d documents indexed across %2$d folder(s)</item>
+ </plurals>
+ <string name="empty_search">Nothing matches “%1$s”.</string>
+ <string name="empty_library">No Bento documents found in the folders you added.</string>
+ <string name="err_scan">Those folders could not be read.</string>
+ <string name="warn_scan_truncated">Stopped after examining %1$d files. Some documents in these folders are not indexed — try adding a narrower folder.</string>
+ <string name="new_document_title">What kind of document?</string>
+ <string name="err_create_fetch">The new document could not be created: %1$s</string>
+ <string name="err_offline">the release server could not be reached, and nothing is cached yet</string>
+ <string name="view_as_grid">Show as grid</string>
+ <string name="view_as_list">Show as list</string>
+ <string name="theme_toggle">Change theme</string>
+ <string name="theme_system">Theme: follow the system</string>
+ <string name="theme_light">Theme: light</string>
+ <string name="theme_dark">Theme: dark</string>
+ <string name="open_selected">Open</string>
+ <string name="detail_none">Pick a document to see it here.</string>
</resources>
diff --git a/tray/android/app/src/main/res/values/themes.xml b/tray/android/app/src/main/res/values/themes.xml
index da83d2dc..37814c50 100644
--- a/tray/android/app/src/main/res/values/themes.xml
+++ b/tray/android/app/src/main/res/values/themes.xml
@@ -1,14 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <!-- The document owns the screen, so the app's own theme is only ever seen
- on the documents list. Light, because the editor a deck ships is light
- and a dark shell around it would flash on every open. -->
- <style name="Theme.Tray" parent="@android:style/Theme.Material.Light.NoActionBar">
- <item name="android:colorPrimary">@color/tray_navy</item>
- <item name="android:colorAccent">@color/tray_steel</item>
- <item name="android:statusBarColor">@color/tray_cream</item>
- <item name="android:windowLightStatusBar">true</item>
- <item name="android:navigationBarColor">@color/tray_cream</item>
- <item name="android:windowBackground">@color/tray_cream</item>
+ <!--
+ Material 3, so the app can have dynamic colour and adaptive behaviour.
+
+ The Bento palette below is the FALLBACK, not the intent: on Android 12+
+ DynamicColors overwrites these at runtime with the user's wallpaper
+ palette, which is the point. Below 12 there is no wallpaper palette to
+ adopt, so the house colours are what those devices get.
+
+ values-night/ no longer redefines colours — Material3.DayNight handles the
+ dark set, and dynamic colour supplies both. What survives from the
+ hand-rolled version is the mark, the thumbnails and the typographic
+ detail, which are brand rather than chrome.
+ -->
+ <style name="Theme.Tray" parent="Theme.Material3.DayNight.NoActionBar">
+ <item name="colorPrimary">@color/accent</item>
+ <item name="colorOnPrimary">@color/on_accent</item>
+ <item name="android:statusBarColor">@android:color/transparent</item>
+ <item name="android:navigationBarColor">@android:color/transparent</item>
+ </style>
+
+ <!--
+ The editor hosts one full-screen WebView and nothing else. It stays off
+ Material deliberately: it would inherit AppCompat's inflation
+ requirements and gain nothing, and the document supplies its own chrome.
+ -->
+ <style name="Theme.Tray.Editor" parent="@android:style/Theme.Material.Light.NoActionBar">
+ <item name="android:windowBackground">@android:color/white</item>
+ </style>
+
+ <!-- The two header toggles: one character each, so they inherit the theme's
+ colour and scale with the user's font size, which a drawable would not. -->
+ <style name="IconBtn">
+ <item name="android:textSize">19sp</item>
+ <item name="android:gravity">center</item>
+ <item name="android:minWidth">@dimen/touch_min</item>
+ <item name="android:minHeight">@dimen/touch_min</item>
+ <item name="android:clickable">true</item>
+ <item name="android:focusable">true</item>
+ <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
</style>
</resources>
diff --git a/tray/android/app/src/test/java/page/bento/tray/DocumentIndexTest.kt b/tray/android/app/src/test/java/page/bento/tray/DocumentIndexTest.kt
new file mode 100644
index 00000000..8ff9cb85
--- /dev/null
+++ b/tray/android/app/src/test/java/page/bento/tray/DocumentIndexTest.kt
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+
+package page.bento.tray
+
+import com.google.gson.JsonObject
+import com.google.gson.JsonParser
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import java.io.File
+import java.security.MessageDigest
+
+/**
+ * Holds the Kotlin indexer to the SHARED corpus in `tray/fixtures/`.
+ *
+ * This is the whole mechanism that keeps three implementations of one algorithm
+ * from drifting — see `tray/fixtures/README.md`. The reference is
+ * `tray/doc-index.mjs`; `node scripts/test-doc-index.mjs` runs it against the
+ * same cases and the same answer key. If this test and that rig disagree, one
+ * of the two hosts has diverged and the corpus says which.
+ *
+ * A plain JVM test on purpose: it needs no emulator, so there is no excuse not
+ * to run it, and `./gradlew :app:testDebugUnitTest` is cheap enough for CI.
+ *
+ * Gson rather than org.json, because Android's org.json is a STUB in unit tests
+ * whose methods throw — the real one on the test classpath may or may not
+ * shadow it, and a test that fails for that reason teaches nothing.
+ */
+class DocumentIndexTest {
+
+ /** Walk up from wherever Gradle rooted us until the corpus appears; the
+ * working directory differs between an IDE run and a command-line one. */
+ private val fixtures: File by lazy {
+ var dir: File? = File(System.getProperty("user.dir") ?: ".").absoluteFile
+ while (dir != null && !File(dir, "tray/fixtures/expected.json").exists()) dir = dir.parentFile
+ requireNotNull(dir) { "could not locate tray/fixtures from ${System.getProperty("user.dir")}" }
+ File(dir, "tray/fixtures")
+ }
+
+ private val expected: JsonObject by lazy {
+ JsonParser.parseString(File(fixtures, "expected.json").readText()).asJsonObject
+ }
+
+ private fun sha16(s: String): String =
+ MessageDigest.getInstance("SHA-256").digest(s.toByteArray(Charsets.UTF_8))
+ .joinToString("") { "%02x".format(it) }.take(16)
+
+ /** The constants are part of the contract. A port with a different budget
+ * passes every short case and diverges only on the large documents nobody
+ * checks by hand. */
+ @Test
+ fun constantsMatchTheContract() {
+ assertEquals(expected["textBudget"].asInt, DocumentIndex.TEXT_BUDGET)
+ assertEquals(expected["sniffBytes"].asInt, DocumentIndex.SNIFF_CHARS)
+ assertEquals(expected["headBytes"].asInt, DocumentIndex.HEAD_CHARS)
+ }
+
+ @Test
+ fun everyCaseInTheCorpusHasAnExpectation() {
+ val cases = expected.getAsJsonObject("cases").keySet()
+ val files = File(fixtures, "cases").listFiles()!!.map { it.name }.toSet()
+ assertEquals("corpus and answer key disagree — regenerate expected.json", files, cases)
+ }
+
+ @Test
+ fun matchesTheSharedCorpus() {
+ val cases = expected.getAsJsonObject("cases")
+ assertTrue("corpus is empty", cases.size() > 0)
+
+ for ((name, raw) in cases.entrySet()) {
+ val want = raw.asJsonObject
+ val got = DocumentIndex.describe(File(fixtures, "cases/$name").readText())
+ val why = { field: String -> "$name: $field" }
+
+ assertEquals(why("isDocument"), want["isDocument"].asBoolean, got.isDocument)
+ assertEquals(why("title"), want["title"].asStringOrNull(), got.title)
+ assertEquals(why("app"), want["app"].asStringOrNull(), got.app)
+ assertEquals(why("encrypted"), want["encrypted"].asBoolean, got.encrypted)
+ assertEquals(why("hasPreview"), want["hasPreview"].asBoolean, got.preview != null)
+
+ val wantLen = if (want["textLength"].isJsonNull) null else want["textLength"].asInt
+ assertEquals(why("textLength"), wantLen, got.text?.length)
+
+ val wantSha = want["textSha256_16"].asStringOrNull()
+ assertEquals(why("text digest"), wantSha, got.text?.let { sha16(it) })
+
+ // The short cases carry their text verbatim so a human can read the
+ // answer key; check it too, or it rots unnoticed behind the digest.
+ if (want.has("text")) assertEquals(why("text"), want["text"].asString, got.text)
+ }
+ }
+
+ private fun com.google.gson.JsonElement.asStringOrNull(): String? =
+ if (isJsonNull) null else asString
+}
diff --git a/tray/android/app/src/test/java/page/bento/tray/ReleasesTest.kt b/tray/android/app/src/test/java/page/bento/tray/ReleasesTest.kt
new file mode 100644
index 00000000..6cffcc23
--- /dev/null
+++ b/tray/android/app/src/test/java/page/bento/tray/ReleasesTest.kt
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+
+package page.bento.tray
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Assert.fail
+import org.junit.Test
+import java.security.MessageDigest
+
+/**
+ * The order in which a new document's shell is checked, which is the part that
+ * cannot be exercised by hand.
+ *
+ * Mirrors `tray/webext`'s two load-bearing cases (PR #318) and the reasoning
+ * `tray/ios` settled first (PR #315): a version high enough to lock the device
+ * out must not raise the floor unless its BYTES were good, and re-fetching the
+ * version already seen must be allowed. Both are cases where getting it
+ * backwards produces a denial of service rather than a visible bug — the first
+ * bricks the + button permanently, the second breaks it on its second use.
+ *
+ * A plain JVM test: no emulator, so there is no excuse not to run it.
+ */
+class ReleasesTest {
+
+ private val app = Releases.APPS.first { it.id == "slides" }
+
+ private fun sha(b: ByteArray) =
+ MessageDigest.getInstance("SHA-256").digest(b).joinToString("") { "%02x".format(it) }
+
+ /** A signed-looking envelope is not needed here: these tests drive
+ * [Releases.resolve] through its dependency seam, and the signature step is
+ * covered by the live manifest the app verifies on device. What is under
+ * test is the SEQUENCE — identity, floor, digest, raise. */
+ private fun deps(
+ shell: ByteArray,
+ floor: MutableMap<String, String>,
+ stored: MutableList<String> = mutableListOf(),
+ ) = Releases.Deps(
+ get = { shell },
+ readFloor = { k -> floor[k] },
+ writeFloor = { k, v -> floor[k] = v },
+ cached = { null },
+ store = { v, _ -> stored += v },
+ )
+
+ private fun release(version: String, shell: ByteArray, appId: String? = "bento-slides") =
+ Releases.Release(appId, version, "https://bento.page/x.html", sha(shell))
+
+ // ---------------------------------------------------------------- the floor
+
+ @Test
+ fun `a high version whose bytes fail their digest leaves the floor untouched`() {
+ val floor = mutableMapOf<String, String>()
+ val shell = "real".toByteArray()
+ // Names 9.9.9 and pins a hash the served bytes do not match.
+ val lying = Releases.Release(
+ "bento-slides", "9.9.9", "https://bento.page/x.html", sha("something else".toByteArray()))
+
+ try {
+ Releases.resolveVerified(app, lying, deps(shell, floor))
+ fail("a shell that fails its pinned digest must be refused")
+ } catch (e: Releases.Failed) {
+ assertTrue(e.message!!, e.message!!.contains("signed hash"))
+ }
+
+ // THE POINT: had the floor been raised on the merely-verified manifest,
+ // this device could never accept a real release below 9.9.9 again — a
+ // failed attack turned into a permanent one.
+ assertNull("the floor must not move for bytes that never passed", floor["release-floor:slides"])
+ }
+
+ @Test
+ fun `an equal version is accepted, not treated as a downgrade`() {
+ val floor = mutableMapOf("release-floor:slides" to "1.0.18")
+ val shell = "same release".toByteArray()
+ val got = Releases.resolveVerified(app, release("1.0.18", shell), deps(shell, floor))
+ assertEquals(String(shell), String(got))
+ assertEquals("1.0.18", floor["release-floor:slides"])
+ }
+
+ @Test
+ fun `an older version than the floor is refused`() {
+ val floor = mutableMapOf("release-floor:slides" to "1.0.18")
+ val shell = "old release".toByteArray()
+ try {
+ Releases.resolveVerified(app, release("1.0.17", shell), deps(shell, floor))
+ fail("a release older than the floor must be refused")
+ } catch (e: Releases.Failed) {
+ assertTrue(e.message!!, e.message!!.contains("older than"))
+ }
+ assertEquals("1.0.18", floor["release-floor:slides"])
+ }
+
+ @Test
+ fun `a newer version raises the floor, but only after the bytes pass`() {
+ val floor = mutableMapOf("release-floor:slides" to "1.0.18")
+ val shell = "new release".toByteArray()
+ Releases.resolveVerified(app, release("1.1.0", shell), deps(shell, floor))
+ assertEquals("1.1.0", floor["release-floor:slides"])
+ }
+
+ @Test
+ fun `an unreadable store reads as no floor rather than a refusal`() {
+ val shell = "release".toByteArray()
+ val d = Releases.Deps(
+ get = { shell },
+ readFloor = { throw IllegalStateException("private mode") },
+ writeFloor = { _, _ -> throw IllegalStateException("quota") },
+ )
+ // Being unable to remember must not mean being unable to create a
+ // document, and an unwritable floor must not fail the document either.
+ assertEquals(String(shell), String(Releases.resolveVerified(app, release("1.0.0", shell), d)))
+ }
+
+ // ------------------------------------------------------------- identity
+
+ @Test
+ fun `a manifest for another app is refused on the channel it was served from`() {
+ val floor = mutableMapOf<String, String>()
+ val shell = "dash release".toByteArray()
+ // Genuinely signed, genuinely hashes — just not the app that was asked for.
+ try {
+ Releases.resolveVerified(app, release("2.0.0", shell, "bento-dash"), deps(shell, floor))
+ fail("a manifest naming another app must be refused")
+ } catch (e: Releases.Failed) {
+ assertTrue(e.message!!, e.message!!.contains("bento-dash"))
+ }
+ }
+
+ @Test
+ fun `an absent app field is refused rather than passing by omission`() {
+ val floor = mutableMapOf<String, String>()
+ val shell = "unnamed".toByteArray()
+ try {
+ Releases.resolveVerified(app, release("2.0.0", shell, null), deps(shell, floor))
+ fail("a manifest with no app field must be refused")
+ } catch (e: Releases.Failed) {
+ assertTrue(e.message!!, e.message!!.contains("unnamed"))
+ }
+ }
+
+ // ------------------------------------------------------------- comparison
+
+ @Test
+ fun `version comparison matches the kernel, including unparsable components`() {
+ assertTrue(Releases.compareVersions("1.0.18", "1.0.17") > 0)
+ assertTrue(Releases.compareVersions("1.0.17", "1.0.18") < 0)
+ assertEquals(0, Releases.compareVersions("1.0.18", "1.0.18"))
+ // Shorter sorts as trailing zeros, as (pa[i] || 0) does.
+ assertEquals(0, Releases.compareVersions("1.0", "1.0.0"))
+ assertTrue(Releases.compareVersions("1.1", "1.0.9") > 0)
+ // NOT NaN: Number('1a') is NaN, NaN is falsy, so JS coerces it to 0.
+ // A strange version can fail to RAISE the floor, never block a release.
+ assertEquals(0, Releases.compareVersions("1.0.x", "1.0.0"))
+ assertTrue(Releases.compareVersions("2.0.0", "1.0.x") > 0)
+ }
+}
diff --git a/tray/assets/make-icons.mjs b/tray/assets/make-icons.mjs
index 16bb5f4c..0e990ef2 100644
--- a/tray/assets/make-icons.mjs
+++ b/tray/assets/make-icons.mjs
@@ -48,9 +48,9 @@ const roundRect = (x, y, w, h, r) =>
`H${f(x + r)} A${f(r)},${f(r)} 0 0 1 ${f(x)},${f(y + h - r)} ` +
`V${f(y + r)} A${f(r)},${f(r)} 0 0 1 ${f(x + r)},${f(y)} Z`
-/** Pull the <rect>s out of the source SVG, in document order. */
-function readMark() {
- const svg = readFileSync(join(here, 'tray-icon.svg'), 'utf8')
+/** Pull the <rect>s out of a source SVG, in document order. */
+function readMark(file = 'tray-icon.svg') {
+ const svg = readFileSync(join(here, file), 'utf8')
const rects = [...svg.matchAll(/<rect\b([^>]*)\/>/g)].map((m) => {
const attr = (name) => {
const hit = m[1].match(new RegExp(`\\b${name}="([^"]*)"`))
@@ -205,7 +205,41 @@ function ios({ ground, tray, cells }) {
return out
}
+/**
+ * The mark as an in-app drawable, from tray-logo.svg — the rounded-ground
+ * version, unlike the launcher icon which is full-bleed because iOS and Android
+ * both apply their own mask.
+ *
+ * Drawn on its own 32-unit grid rather than the 108 adaptive canvas: this one is
+ * an image in a header, not an icon under a mask, so it keeps the source's own
+ * proportions and needs none of the safe-zone arithmetic.
+ */
+function buildMark() {
+ const { ground, tray, cells } = readMark('tray-logo.svg')
+ const shapes = [ground, tray, ...cells].map((r) => ({
+ fill: r.fill,
+ d: roundRect(r.x, r.y, r.w, r.h, r.r),
+ }))
+ return `<?xml version="1.0" encoding="utf-8"?>
+<!--
+ GENERATED from tray/assets/tray-logo.svg by tray/assets/make-icons.mjs.
+ Do not edit: run \`node tray/assets/make-icons.mjs\` instead.
+
+ The bento/home mark, for use inside the app. Same source as the launcher
+ icon, so the two cannot drift apart.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="32dp"
+ android:height="32dp"
+ android:viewportWidth="32"
+ android:viewportHeight="32">
+${shapes.map((s) => ` <path\n android:fillColor="${s.fill}"\n android:pathData="${s.d}" />`).join('\n')}
+</vector>
+`
+}
+
const files = build()
+files[join(ANDROID_RES, 'ic_tray_mark.xml')] = buildMark()
const check = process.argv.includes('--check')
let stale = 0
diff --git a/tray/doc-index.mjs b/tray/doc-index.mjs
new file mode 100644
index 00000000..1eb81774
--- /dev/null
+++ b/tray/doc-index.mjs
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// THE REFERENCE INDEXER, and the executable half of a contract.
+//
+// Every bento/tray host has to answer the same questions about a file it did
+// not write: is this one of ours, what is it called, which app is it, is it
+// encrypted, what does its first page look like, and what words does it
+// contain. `tray/webext` answers them in JavaScript because it lives in a
+// browser; `tray/android` answers them in Kotlin and `tray/ios` in Swift,
+// because their list UIs are native and must stay that way (docs/DECISIONS.md,
+// 2026-08-16 — putting the extension's HTML library in a WebView costs ~0.5s of
+// cold start, iOS its system document browser, and both their accessibility).
+//
+// Three implementations of one algorithm is a drift problem. This file is the
+// reference, `tray/fixtures/` is the corpus, and `scripts/test-doc-index.mjs`
+// checks this implementation against it — the native ports run the SAME corpus
+// from their own test rigs. The guarantee is deliberately "cannot diverge
+// SILENTLY" rather than "cannot diverge": a divergence here makes search find
+// less, which is visible and recoverable, unlike the writable-stream semantics
+// in `tray/bridge.js` that are shared outright because a divergence there
+// wrote users' documents out as zero bytes.
+//
+// Ported from tray/webext/src/library.js. If you change the algorithm, change
+// it here, extend the corpus, and re-run every port.
+
+/** The splice contract's marker — docs/PLATFORM.md §2, frozen because old
+ * updaters depend on it. A Bento document is one because of what is INSIDE
+ * it, not what it is called: files get renamed to `deck.html` to email them,
+ * saved as `Q3(1).html`, downloaded without the compound extension. */
+export const MARKER = 'id="bento-doc"'
+
+/** How much to read before deciding a file is not ours. The marker sits ~5.8KB
+ * into a real shell, after the chrome and the notice, so this is generous —
+ * and it runs against every stray .html in a granted folder, most of which
+ * are not ours, so it is deliberately smaller than HEAD_BYTES. */
+export const SNIFF_BYTES = 64 * 1024
+
+/** Enough to reach the title, which lives inside the block. The block itself
+ * runs to megabytes when a document carries images — the trap an earlier
+ * metadata reader fell into by looking for the CLOSING tag and so finding
+ * nothing in any document with a picture in it. */
+export const HEAD_BYTES = 300 * 1024
+
+/** How much extracted prose to keep. Enough for any phrase somebody would
+ * search for; far short of storing the document twice. */
+export const TEXT_BUDGET = 40 * 1024
+
+export const isDocument = (head) => head.includes(MARKER)
+
+export const titleOf = (head) =>
+ head.match(/"title"\s*:\s*"((?:[^"\\]|\\.){0,200})"/)?.[1] ?? null
+
+/** Which Bento this is. A pristine shell has no document yet, so no format:
+ * that is not a failure, it is a document nobody has saved. */
+export const appOf = (head) =>
+ head.match(/"format"\s*:\s*"bento\/([a-z]+)"/)?.[1] ?? null
+
+/** An encrypted document gets NO text and NO preview. That is a privacy rule,
+ * not an optimisation: a plaintext title page beside the ciphertext is the
+ * leak the password exists to prevent. */
+export const isEncrypted = (head) =>
+ /"format"\s*:\s*"bento\/enc"/.test(head) || /data-bento-enc/.test(head)
+
+/** The still render of page one that every save writes into the shell
+ * (kernel/src/preview.ts) so file managers can thumbnail it. Self-contained
+ * and self-scaling, so it drops into a small sandboxed view with no work. */
+export function previewOf(whole) {
+ const start = whole.indexOf('<div data-bento-preview')
+ if (start === -1) return null
+ const end = whole.indexOf('<script data-bento-preview', start)
+ return end > start ? whole.slice(start, end) : null
+}
+
+/**
+ * The words a document actually contains.
+ *
+ * Deliberately NOT a JSON parse. The block runs to megabytes with images
+ * inline, every app shapes it differently (slides put prose in `element.html`,
+ * spaces in blocks, dash in cells), and a parser that has to know the format is
+ * a parser that breaks when the format moves. Pulling string VALUES out —
+ * `:"…"`, never keys — is format-agnostic and degrades to "finds less" rather
+ * than "throws".
+ *
+ * Data URIs go FIRST: one embedded image is bigger than every word in the
+ * document and would dominate both the work and the budget.
+ */
+export function extractText(html) {
+ const start = html.indexOf(MARKER)
+ if (start === -1) return null
+ const end = html.indexOf('</script>', start)
+ if (end === -1) return null
+
+ let block = html.slice(start, end)
+ block = block.replace(/data:[^"\\]{200,}/g, ' ') // embedded media
+ const out = []
+ let size = 0
+ for (const m of block.matchAll(/:"((?:[^"\\]|\\.){1,400})"/g)) {
+ const v = m[1]
+ if (!/[A-Za-z]{3,}/.test(v)) continue // ids, colours, numbers
+ out.push(v)
+ size += v.length
+ if (size > TEXT_BUDGET) break
+ }
+ return out.join(' ')
+ .replace(/<[^>]{1,200}>/g, ' ') // element html
+ .replace(/&[a-z]+;|&#\d+;/gi, ' ')
+ .replace(/\s+/g, ' ')
+ .trim()
+ .slice(0, TEXT_BUDGET) || null
+}
+
+/** Everything a host needs about one file, from the bytes it already read. */
+export function describe(whole) {
+ const head = whole.slice(0, HEAD_BYTES)
+ if (!isDocument(whole.slice(0, SNIFF_BYTES))) {
+ return { isDocument: false, title: null, app: null, encrypted: false, preview: null, text: null }
+ }
+ const encrypted = isEncrypted(head)
+ return {
+ isDocument: true,
+ title: titleOf(head),
+ app: appOf(head),
+ encrypted,
+ preview: encrypted ? null : previewOf(whole),
+ text: encrypted ? null : extractText(whole),
+ }
+}
diff --git a/tray/fixtures/README.md b/tray/fixtures/README.md
new file mode 100644
index 00000000..7e91f9c8
--- /dev/null
+++ b/tray/fixtures/README.md
@@ -0,0 +1,55 @@
+# tray/fixtures — the document-indexing contract
+
+Every bento/tray host answers the same questions about a file it did not write:
+is this one of ours, what is it called, which app is it, is it encrypted, what
+does its first page look like, and what words does it contain.
+
+Three hosts answer them in three languages — `tray/webext` in JavaScript,
+`tray/android` in Kotlin, `tray/ios` in Swift — because their list UIs are
+native and must stay that way (`docs/DECISIONS.md`, 2026-08-16: putting the
+extension's HTML library in a WebView costs ~0.5s of cold start, iOS its system
+document browser, and both their accessibility).
+
+Three implementations of one algorithm is a drift problem. **This directory is
+how they are held together.** `tray/doc-index.mjs` is the reference,
+`cases/` is the corpus, `expected.json` is the answer key, and every host runs
+the same corpus from its own test rig:
+
+| host | rig |
+|---|---|
+| reference (JS) | `node scripts/test-doc-index.mjs` |
+| `tray/android` | `./gradlew :app:testDebugUnitTest` (JVM, no device needed) |
+| `tray/ios` | not yet built |
+
+The guarantee is deliberately **"cannot diverge silently"**, not "cannot
+diverge". A divergence here makes search find less, which is visible and
+recoverable — unlike the writable-stream semantics in `tray/bridge.js`, which
+are shared outright because a divergence there wrote users' documents out as
+zero bytes.
+
+## Changing the algorithm
+
+Change `tray/doc-index.mjs`, extend `cases/`, regenerate `expected.json`, then
+re-run **every** rig. A host that cannot match the corpus is the one that is
+wrong.
+
+## What each case pins
+
+| case | the rule it holds in place |
+|---|---|
+| `plain.html` | an ordinary document — title, app, prose from element html |
+| `data-uri.html` | an embedded `data:` URI is stripped **before** extraction, so one image cannot swamp every word in the document |
+| `escaped.html` | `\"` inside a value does not terminate it |
+| `noise.html` | values with no run of 3+ letters are dropped: ids, hex colours, `12px` |
+| `markup.html` | element markup and HTML entities are stripped from the joined text |
+| `longvalue.html` | **a single string value over 400 characters is skipped entirely** |
+| `budget.html` | the total is truncated at `TEXT_BUDGET` (40 KiB) |
+| `encrypted.html` | an encrypted document yields **no text and no preview**, ever |
+| `preview.html` | the first-page preview block is found and sliced |
+| `nomarker.html` | a file without `id="bento-doc"` is not ours |
+
+`longvalue.html` is the one worth reading twice. The value regex is capped at
+`{1,400}`, so a paragraph longer than that — a long speaker note, a wordy text
+element — **is not indexed at all**. That is current behaviour, pinned here so a
+port cannot quietly "fix" it into divergence, and so a deliberate change to it
+has to be a deliberate change to all three.
diff --git a/tray/fixtures/cases/budget.html b/tray/fixtures/cases/budget.html
new file mode 100644
index 00000000..9f9267ca
--- /dev/null
+++ b/tray/fixtures/cases/budget.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/slides","title":"Long","n0":"sentence 0 holds several ordinary words for indexing","n1":"sentence 1 holds several ordinary words for indexing","n2":"sentence 2 holds several ordinary words for indexing","n3":"sentence 3 holds several ordinary words for indexing","n4":"sentence 4 holds several ordinary words for indexing","n5":"sentence 5 holds several ordinary words for indexing","n6":"sentence 6 holds several ordinary words for indexing","n7":"sentence 7 holds several ordinary words for indexing","n8":"sentence 8 holds several ordinary words for indexing","n9":"sentence 9 holds several ordinary words for indexing","n10":"sentence 10 holds several ordinary words for indexing","n11":"sentence 11 holds several ordinary words for indexing","n12":"sentence 12 holds several ordinary words for indexing","n13":"sentence 13 holds several ordinary words for indexing","n14":"sentence 14 holds several ordinary words for indexing","n15":"sentence 15 holds several ordinary words for indexing","n16":"sentence 16 holds several ordinary words for indexing","n17":"sentence 17 holds several ordinary words for indexing","n18":"sentence 18 holds several ordinary words for indexing","n19":"sentence 19 holds several ordinary words for indexing","n20":"sentence 20 holds several ordinary words for indexing","n21":"sentence 21 holds several ordinary words for indexing","n22":"sentence 22 holds several ordinary words for indexing","n23":"sentence 23 holds several ordinary words for indexing","n24":"sentence 24 holds several ordinary words for indexing","n25":"sentence 25 holds several ordinary words for indexing","n26":"sentence 26 holds several ordinary words for indexing","n27":"sentence 27 holds several ordinary words for indexing","n28":"sentence 28 holds several ordinary words for indexing","n29":"sentence 29 holds several ordinary words for indexing","n30":"sentence 30 holds several ordinary words for indexing","n31":"sentence 31 holds several ordinary words for indexing","n32":"sentence 32 holds several ordinary words for indexing","n33":"sentence 33 holds several ordinary words for indexing","n34":"sentence 34 holds several ordinary words for indexing","n35":"sentence 35 holds several ordinary words for indexing","n36":"sentence 36 holds several ordinary words for indexing","n37":"sentence 37 holds several ordinary words for indexing","n38":"sentence 38 holds several ordinary words for indexing","n39":"sentence 39 holds several ordinary words for indexing","n40":"sentence 40 holds several ordinary words for indexing","n41":"sentence 41 holds several ordinary words for indexing","n42":"sentence 42 holds several ordinary words for indexing","n43":"sentence 43 holds several ordinary words for indexing","n44":"sentence 44 holds several ordinary words for indexing","n45":"sentence 45 holds several ordinary words for indexing","n46":"sentence 46 holds several ordinary words for indexing","n47":"sentence 47 holds several ordinary words for indexing","n48":"sentence 48 holds several ordinary words for indexing","n49":"sentence 49 holds several ordinary words for indexing","n50":"sentence 50 holds several ordinary words for indexing","n51":"sentence 51 holds several ordinary words for indexing","n52":"sentence 52 holds several ordinary words for indexing","n53":"sentence 53 holds several ordinary words for indexing","n54":"sentence 54 holds several ordinary words for indexing","n55":"sentence 55 holds several ordinary words for indexing","n56":"sentence 56 holds several ordinary words for indexing","n57":"sentence 57 holds several ordinary words for indexing","n58":"sentence 58 holds several ordinary words for indexing","n59":"sentence 59 holds several ordinary words for indexing","n60":"sentence 60 holds several ordinary words for indexing","n61":"sentence 61 holds several ordinary words for indexing","n62":"sentence 62 holds several ordinary words for indexing","n63":"sentence 63 holds several ordinary words for indexing","n64":"sentence 64 holds several ordinary words for indexing","n65":"sentence 65 holds several ordinary words for indexing","n66":"sentence 66 holds several ordinary words for indexing","n67":"sentence 67 holds several ordinary words for indexing","n68":"sentence 68 holds several ordinary words for indexing","n69":"sentence 69 holds several ordinary words for indexing","n70":"sentence 70 holds several ordinary words for indexing","n71":"sentence 71 holds several ordinary words for indexing","n72":"sentence 72 holds several ordinary words for indexing","n73":"sentence 73 holds several ordinary words for indexing","n74":"sentence 74 holds several ordinary words for indexing","n75":"sentence 75 holds several ordinary words for indexing","n76":"sentence 76 holds several ordinary words for indexing","n77":"sentence 77 holds several ordinary words for indexing","n78":"sentence 78 holds several ordinary words for indexing","n79":"sentence 79 holds several ordinary words for indexing","n80":"sentence 80 holds several ordinary words for indexing","n81":"sentence 81 holds several ordinary words for indexing","n82":"sentence 82 holds several ordinary words for indexing","n83":"sentence 83 holds several ordinary words for indexing","n84":"sentence 84 holds several ordinary words for indexing","n85":"sentence 85 holds several ordinary words for indexing","n86":"sentence 86 holds several ordinary words for indexing","n87":"sentence 87 holds several ordinary words for indexing","n88":"sentence 88 holds several ordinary words for indexing","n89":"sentence 89 holds several ordinary words for indexing","n90":"sentence 90 holds several ordinary words for indexing","n91":"sentence 91 holds several ordinary words for indexing","n92":"sentence 92 holds several ordinary words for indexing","n93":"sentence 93 holds several ordinary words for indexing","n94":"sentence 94 holds several ordinary words for indexing","n95":"sentence 95 holds several ordinary words for indexing","n96":"sentence 96 holds several ordinary words for indexing","n97":"sentence 97 holds several ordinary words for indexing","n98":"sentence 98 holds several ordinary words for indexing","n99":"sentence 99 holds several ordinary words for indexing","n100":"sentence 100 holds several ordinary words for indexing","n101":"sentence 101 holds several ordinary words for indexing","n102":"sentence 102 holds several ordinary words for indexing","n103":"sentence 103 holds several ordinary words for indexing","n104":"sentence 104 holds several ordinary words for indexing","n105":"sentence 105 holds several ordinary words for indexing","n106":"sentence 106 holds several ordinary words for indexing","n107":"sentence 107 holds several ordinary words for indexing","n108":"sentence 108 holds several ordinary words for indexing","n109":"sentence 109 holds several ordinary words for indexing","n110":"sentence 110 holds several ordinary words for indexing","n111":"sentence 111 holds several ordinary words for indexing","n112":"sentence 112 holds several ordinary words for indexing","n113":"sentence 113 holds several ordinary words for indexing","n114":"sentence 114 holds several ordinary words for indexing","n115":"sentence 115 holds several ordinary words for indexing","n116":"sentence 116 holds several ordinary words for indexing","n117":"sentence 117 holds several ordinary words for indexing","n118":"sentence 118 holds several ordinary words for indexing","n119":"sentence 119 holds several ordinary words for indexing","n120":"sentence 120 holds several ordinary words for indexing","n121":"sentence 121 holds several ordinary words for indexing","n122":"sentence 122 holds several ordinary words for indexing","n123":"sentence 123 holds several ordinary words for indexing","n124":"sentence 124 holds several ordinary words for indexing","n125":"sentence 125 holds several ordinary words for indexing","n126":"sentence 126 holds several ordinary words for indexing","n127":"sentence 127 holds several ordinary words for indexing","n128":"sentence 128 holds several ordinary words for indexing","n129":"sentence 129 holds several ordinary words for indexing","n130":"sentence 130 holds several ordinary words for indexing","n131":"sentence 131 holds several ordinary words for indexing","n132":"sentence 132 holds several ordinary words for indexing","n133":"sentence 133 holds several ordinary words for indexing","n134":"sentence 134 holds several ordinary words for indexing","n135":"sentence 135 holds several ordinary words for indexing","n136":"sentence 136 holds several ordinary words for indexing","n137":"sentence 137 holds several ordinary words for indexing","n138":"sentence 138 holds several ordinary words for indexing","n139":"sentence 139 holds several ordinary words for indexing","n140":"sentence 140 holds several ordinary words for indexing","n141":"sentence 141 holds several ordinary words for indexing","n142":"sentence 142 holds several ordinary words for indexing","n143":"sentence 143 holds several ordinary words for indexing","n144":"sentence 144 holds several ordinary words for indexing","n145":"sentence 145 holds several ordinary words for indexing","n146":"sentence 146 holds several ordinary words for indexing","n147":"sentence 147 holds several ordinary words for indexing","n148":"sentence 148 holds several ordinary words for indexing","n149":"sentence 149 holds several ordinary words for indexing","n150":"sentence 150 holds several ordinary words for indexing","n151":"sentence 151 holds several ordinary words for indexing","n152":"sentence 152 holds several ordinary words for indexing","n153":"sentence 153 holds several ordinary words for indexing","n154":"sentence 154 holds several ordinary words for indexing","n155":"sentence 155 holds several ordinary words for indexing","n156":"sentence 156 holds several ordinary words for indexing","n157":"sentence 157 holds several ordinary words for indexing","n158":"sentence 158 holds several ordinary words for indexing","n159":"sentence 159 holds several ordinary words for indexing","n160":"sentence 160 holds several ordinary words for indexing","n161":"sentence 161 holds several ordinary words for indexing","n162":"sentence 162 holds several ordinary words for indexing","n163":"sentence 163 holds several ordinary words for indexing","n164":"sentence 164 holds several ordinary words for indexing","n165":"sentence 165 holds several ordinary words for indexing","n166":"sentence 166 holds several ordinary words for indexing","n167":"sentence 167 holds several ordinary words for indexing","n168":"sentence 168 holds several ordinary words for indexing","n169":"sentence 169 holds several ordinary words for indexing","n170":"sentence 170 holds several ordinary words for indexing","n171":"sentence 171 holds several ordinary words for indexing","n172":"sentence 172 holds several ordinary words for indexing","n173":"sentence 173 holds several ordinary words for indexing","n174":"sentence 174 holds several ordinary words for indexing","n175":"sentence 175 holds several ordinary words for indexing","n176":"sentence 176 holds several ordinary words for indexing","n177":"sentence 177 holds several ordinary words for indexing","n178":"sentence 178 holds several ordinary words for indexing","n179":"sentence 179 holds several ordinary words for indexing","n180":"sentence 180 holds several ordinary words for indexing","n181":"sentence 181 holds several ordinary words for indexing","n182":"sentence 182 holds several ordinary words for indexing","n183":"sentence 183 holds several ordinary words for indexing","n184":"sentence 184 holds several ordinary words for indexing","n185":"sentence 185 holds several ordinary words for indexing","n186":"sentence 186 holds several ordinary words for indexing","n187":"sentence 187 holds several ordinary words for indexing","n188":"sentence 188 holds several ordinary words for indexing","n189":"sentence 189 holds several ordinary words for indexing","n190":"sentence 190 holds several ordinary words for indexing","n191":"sentence 191 holds several ordinary words for indexing","n192":"sentence 192 holds several ordinary words for indexing","n193":"sentence 193 holds several ordinary words for indexing","n194":"sentence 194 holds several ordinary words for indexing","n195":"sentence 195 holds several ordinary words for indexing","n196":"sentence 196 holds several ordinary words for indexing","n197":"sentence 197 holds several ordinary words for indexing","n198":"sentence 198 holds several ordinary words for indexing","n199":"sentence 199 holds several ordinary words for indexing","n200":"sentence 200 holds several ordinary words for indexing","n201":"sentence 201 holds several ordinary words for indexing","n202":"sentence 202 holds several ordinary words for indexing","n203":"sentence 203 holds several ordinary words for indexing","n204":"sentence 204 holds several ordinary words for indexing","n205":"sentence 205 holds several ordinary words for indexing","n206":"sentence 206 holds several ordinary words for indexing","n207":"sentence 207 holds several ordinary words for indexing","n208":"sentence 208 holds several ordinary words for indexing","n209":"sentence 209 holds several ordinary words for indexing","n210":"sentence 210 holds several ordinary words for indexing","n211":"sentence 211 holds several ordinary words for indexing","n212":"sentence 212 holds several ordinary words for indexing","n213":"sentence 213 holds several ordinary words for indexing","n214":"sentence 214 holds several ordinary words for indexing","n215":"sentence 215 holds several ordinary words for indexing","n216":"sentence 216 holds several ordinary words for indexing","n217":"sentence 217 holds several ordinary words for indexing","n218":"sentence 218 holds several ordinary words for indexing","n219":"sentence 219 holds several ordinary words for indexing","n220":"sentence 220 holds several ordinary words for indexing","n221":"sentence 221 holds several ordinary words for indexing","n222":"sentence 222 holds several ordinary words for indexing","n223":"sentence 223 holds several ordinary words for indexing","n224":"sentence 224 holds several ordinary words for indexing","n225":"sentence 225 holds several ordinary words for indexing","n226":"sentence 226 holds several ordinary words for indexing","n227":"sentence 227 holds several ordinary words for indexing","n228":"sentence 228 holds several ordinary words for indexing","n229":"sentence 229 holds several ordinary words for indexing","n230":"sentence 230 holds several ordinary words for indexing","n231":"sentence 231 holds several ordinary words for indexing","n232":"sentence 232 holds several ordinary words for indexing","n233":"sentence 233 holds several ordinary words for indexing","n234":"sentence 234 holds several ordinary words for indexing","n235":"sentence 235 holds several ordinary words for indexing","n236":"sentence 236 holds several ordinary words for indexing","n237":"sentence 237 holds several ordinary words for indexing","n238":"sentence 238 holds several ordinary words for indexing","n239":"sentence 239 holds several ordinary words for indexing","n240":"sentence 240 holds several ordinary words for indexing","n241":"sentence 241 holds several ordinary words for indexing","n242":"sentence 242 holds several ordinary words for indexing","n243":"sentence 243 holds several ordinary words for indexing","n244":"sentence 244 holds several ordinary words for indexing","n245":"sentence 245 holds several ordinary words for indexing","n246":"sentence 246 holds several ordinary words for indexing","n247":"sentence 247 holds several ordinary words for indexing","n248":"sentence 248 holds several ordinary words for indexing","n249":"sentence 249 holds several ordinary words for indexing","n250":"sentence 250 holds several ordinary words for indexing","n251":"sentence 251 holds several ordinary words for indexing","n252":"sentence 252 holds several ordinary words for indexing","n253":"sentence 253 holds several ordinary words for indexing","n254":"sentence 254 holds several ordinary words for indexing","n255":"sentence 255 holds several ordinary words for indexing","n256":"sentence 256 holds several ordinary words for indexing","n257":"sentence 257 holds several ordinary words for indexing","n258":"sentence 258 holds several ordinary words for indexing","n259":"sentence 259 holds several ordinary words for indexing","n260":"sentence 260 holds several ordinary words for indexing","n261":"sentence 261 holds several ordinary words for indexing","n262":"sentence 262 holds several ordinary words for indexing","n263":"sentence 263 holds several ordinary words for indexing","n264":"sentence 264 holds several ordinary words for indexing","n265":"sentence 265 holds several ordinary words for indexing","n266":"sentence 266 holds several ordinary words for indexing","n267":"sentence 267 holds several ordinary words for indexing","n268":"sentence 268 holds several ordinary words for indexing","n269":"sentence 269 holds several ordinary words for indexing","n270":"sentence 270 holds several ordinary words for indexing","n271":"sentence 271 holds several ordinary words for indexing","n272":"sentence 272 holds several ordinary words for indexing","n273":"sentence 273 holds several ordinary words for indexing","n274":"sentence 274 holds several ordinary words for indexing","n275":"sentence 275 holds several ordinary words for indexing","n276":"sentence 276 holds several ordinary words for indexing","n277":"sentence 277 holds several ordinary words for indexing","n278":"sentence 278 holds several ordinary words for indexing","n279":"sentence 279 holds several ordinary words for indexing","n280":"sentence 280 holds several ordinary words for indexing","n281":"sentence 281 holds several ordinary words for indexing","n282":"sentence 282 holds several ordinary words for indexing","n283":"sentence 283 holds several ordinary words for indexing","n284":"sentence 284 holds several ordinary words for indexing","n285":"sentence 285 holds several ordinary words for indexing","n286":"sentence 286 holds several ordinary words for indexing","n287":"sentence 287 holds several ordinary words for indexing","n288":"sentence 288 holds several ordinary words for indexing","n289":"sentence 289 holds several ordinary words for indexing","n290":"sentence 290 holds several ordinary words for indexing","n291":"sentence 291 holds several ordinary words for indexing","n292":"sentence 292 holds several ordinary words for indexing","n293":"sentence 293 holds several ordinary words for indexing","n294":"sentence 294 holds several ordinary words for indexing","n295":"sentence 295 holds several ordinary words for indexing","n296":"sentence 296 holds several ordinary words for indexing","n297":"sentence 297 holds several ordinary words for indexing","n298":"sentence 298 holds several ordinary words for indexing","n299":"sentence 299 holds several ordinary words for indexing","n300":"sentence 300 holds several ordinary words for indexing","n301":"sentence 301 holds several ordinary words for indexing","n302":"sentence 302 holds several ordinary words for indexing","n303":"sentence 303 holds several ordinary words for indexing","n304":"sentence 304 holds several ordinary words for indexing","n305":"sentence 305 holds several ordinary words for indexing","n306":"sentence 306 holds several ordinary words for indexing","n307":"sentence 307 holds several ordinary words for indexing","n308":"sentence 308 holds several ordinary words for indexing","n309":"sentence 309 holds several ordinary words for indexing","n310":"sentence 310 holds several ordinary words for indexing","n311":"sentence 311 holds several ordinary words for indexing","n312":"sentence 312 holds several ordinary words for indexing","n313":"sentence 313 holds several ordinary words for indexing","n314":"sentence 314 holds several ordinary words for indexing","n315":"sentence 315 holds several ordinary words for indexing","n316":"sentence 316 holds several ordinary words for indexing","n317":"sentence 317 holds several ordinary words for indexing","n318":"sentence 318 holds several ordinary words for indexing","n319":"sentence 319 holds several ordinary words for indexing","n320":"sentence 320 holds several ordinary words for indexing","n321":"sentence 321 holds several ordinary words for indexing","n322":"sentence 322 holds several ordinary words for indexing","n323":"sentence 323 holds several ordinary words for indexing","n324":"sentence 324 holds several ordinary words for indexing","n325":"sentence 325 holds several ordinary words for indexing","n326":"sentence 326 holds several ordinary words for indexing","n327":"sentence 327 holds several ordinary words for indexing","n328":"sentence 328 holds several ordinary words for indexing","n329":"sentence 329 holds several ordinary words for indexing","n330":"sentence 330 holds several ordinary words for indexing","n331":"sentence 331 holds several ordinary words for indexing","n332":"sentence 332 holds several ordinary words for indexing","n333":"sentence 333 holds several ordinary words for indexing","n334":"sentence 334 holds several ordinary words for indexing","n335":"sentence 335 holds several ordinary words for indexing","n336":"sentence 336 holds several ordinary words for indexing","n337":"sentence 337 holds several ordinary words for indexing","n338":"sentence 338 holds several ordinary words for indexing","n339":"sentence 339 holds several ordinary words for indexing","n340":"sentence 340 holds several ordinary words for indexing","n341":"sentence 341 holds several ordinary words for indexing","n342":"sentence 342 holds several ordinary words for indexing","n343":"sentence 343 holds several ordinary words for indexing","n344":"sentence 344 holds several ordinary words for indexing","n345":"sentence 345 holds several ordinary words for indexing","n346":"sentence 346 holds several ordinary words for indexing","n347":"sentence 347 holds several ordinary words for indexing","n348":"sentence 348 holds several ordinary words for indexing","n349":"sentence 349 holds several ordinary words for indexing","n350":"sentence 350 holds several ordinary words for indexing","n351":"sentence 351 holds several ordinary words for indexing","n352":"sentence 352 holds several ordinary words for indexing","n353":"sentence 353 holds several ordinary words for indexing","n354":"sentence 354 holds several ordinary words for indexing","n355":"sentence 355 holds several ordinary words for indexing","n356":"sentence 356 holds several ordinary words for indexing","n357":"sentence 357 holds several ordinary words for indexing","n358":"sentence 358 holds several ordinary words for indexing","n359":"sentence 359 holds several ordinary words for indexing","n360":"sentence 360 holds several ordinary words for indexing","n361":"sentence 361 holds several ordinary words for indexing","n362":"sentence 362 holds several ordinary words for indexing","n363":"sentence 363 holds several ordinary words for indexing","n364":"sentence 364 holds several ordinary words for indexing","n365":"sentence 365 holds several ordinary words for indexing","n366":"sentence 366 holds several ordinary words for indexing","n367":"sentence 367 holds several ordinary words for indexing","n368":"sentence 368 holds several ordinary words for indexing","n369":"sentence 369 holds several ordinary words for indexing","n370":"sentence 370 holds several ordinary words for indexing","n371":"sentence 371 holds several ordinary words for indexing","n372":"sentence 372 holds several ordinary words for indexing","n373":"sentence 373 holds several ordinary words for indexing","n374":"sentence 374 holds several ordinary words for indexing","n375":"sentence 375 holds several ordinary words for indexing","n376":"sentence 376 holds several ordinary words for indexing","n377":"sentence 377 holds several ordinary words for indexing","n378":"sentence 378 holds several ordinary words for indexing","n379":"sentence 379 holds several ordinary words for indexing","n380":"sentence 380 holds several ordinary words for indexing","n381":"sentence 381 holds several ordinary words for indexing","n382":"sentence 382 holds several ordinary words for indexing","n383":"sentence 383 holds several ordinary words for indexing","n384":"sentence 384 holds several ordinary words for indexing","n385":"sentence 385 holds several ordinary words for indexing","n386":"sentence 386 holds several ordinary words for indexing","n387":"sentence 387 holds several ordinary words for indexing","n388":"sentence 388 holds several ordinary words for indexing","n389":"sentence 389 holds several ordinary words for indexing","n390":"sentence 390 holds several ordinary words for indexing","n391":"sentence 391 holds several ordinary words for indexing","n392":"sentence 392 holds several ordinary words for indexing","n393":"sentence 393 holds several ordinary words for indexing","n394":"sentence 394 holds several ordinary words for indexing","n395":"sentence 395 holds several ordinary words for indexing","n396":"sentence 396 holds several ordinary words for indexing","n397":"sentence 397 holds several ordinary words for indexing","n398":"sentence 398 holds several ordinary words for indexing","n399":"sentence 399 holds several ordinary words for indexing","n400":"sentence 400 holds several ordinary words for indexing","n401":"sentence 401 holds several ordinary words for indexing","n402":"sentence 402 holds several ordinary words for indexing","n403":"sentence 403 holds several ordinary words for indexing","n404":"sentence 404 holds several ordinary words for indexing","n405":"sentence 405 holds several ordinary words for indexing","n406":"sentence 406 holds several ordinary words for indexing","n407":"sentence 407 holds several ordinary words for indexing","n408":"sentence 408 holds several ordinary words for indexing","n409":"sentence 409 holds several ordinary words for indexing","n410":"sentence 410 holds several ordinary words for indexing","n411":"sentence 411 holds several ordinary words for indexing","n412":"sentence 412 holds several ordinary words for indexing","n413":"sentence 413 holds several ordinary words for indexing","n414":"sentence 414 holds several ordinary words for indexing","n415":"sentence 415 holds several ordinary words for indexing","n416":"sentence 416 holds several ordinary words for indexing","n417":"sentence 417 holds several ordinary words for indexing","n418":"sentence 418 holds several ordinary words for indexing","n419":"sentence 419 holds several ordinary words for indexing","n420":"sentence 420 holds several ordinary words for indexing","n421":"sentence 421 holds several ordinary words for indexing","n422":"sentence 422 holds several ordinary words for indexing","n423":"sentence 423 holds several ordinary words for indexing","n424":"sentence 424 holds several ordinary words for indexing","n425":"sentence 425 holds several ordinary words for indexing","n426":"sentence 426 holds several ordinary words for indexing","n427":"sentence 427 holds several ordinary words for indexing","n428":"sentence 428 holds several ordinary words for indexing","n429":"sentence 429 holds several ordinary words for indexing","n430":"sentence 430 holds several ordinary words for indexing","n431":"sentence 431 holds several ordinary words for indexing","n432":"sentence 432 holds several ordinary words for indexing","n433":"sentence 433 holds several ordinary words for indexing","n434":"sentence 434 holds several ordinary words for indexing","n435":"sentence 435 holds several ordinary words for indexing","n436":"sentence 436 holds several ordinary words for indexing","n437":"sentence 437 holds several ordinary words for indexing","n438":"sentence 438 holds several ordinary words for indexing","n439":"sentence 439 holds several ordinary words for indexing","n440":"sentence 440 holds several ordinary words for indexing","n441":"sentence 441 holds several ordinary words for indexing","n442":"sentence 442 holds several ordinary words for indexing","n443":"sentence 443 holds several ordinary words for indexing","n444":"sentence 444 holds several ordinary words for indexing","n445":"sentence 445 holds several ordinary words for indexing","n446":"sentence 446 holds several ordinary words for indexing","n447":"sentence 447 holds several ordinary words for indexing","n448":"sentence 448 holds several ordinary words for indexing","n449":"sentence 449 holds several ordinary words for indexing","n450":"sentence 450 holds several ordinary words for indexing","n451":"sentence 451 holds several ordinary words for indexing","n452":"sentence 452 holds several ordinary words for indexing","n453":"sentence 453 holds several ordinary words for indexing","n454":"sentence 454 holds several ordinary words for indexing","n455":"sentence 455 holds several ordinary words for indexing","n456":"sentence 456 holds several ordinary words for indexing","n457":"sentence 457 holds several ordinary words for indexing","n458":"sentence 458 holds several ordinary words for indexing","n459":"sentence 459 holds several ordinary words for indexing","n460":"sentence 460 holds several ordinary words for indexing","n461":"sentence 461 holds several ordinary words for indexing","n462":"sentence 462 holds several ordinary words for indexing","n463":"sentence 463 holds several ordinary words for indexing","n464":"sentence 464 holds several ordinary words for indexing","n465":"sentence 465 holds several ordinary words for indexing","n466":"sentence 466 holds several ordinary words for indexing","n467":"sentence 467 holds several ordinary words for indexing","n468":"sentence 468 holds several ordinary words for indexing","n469":"sentence 469 holds several ordinary words for indexing","n470":"sentence 470 holds several ordinary words for indexing","n471":"sentence 471 holds several ordinary words for indexing","n472":"sentence 472 holds several ordinary words for indexing","n473":"sentence 473 holds several ordinary words for indexing","n474":"sentence 474 holds several ordinary words for indexing","n475":"sentence 475 holds several ordinary words for indexing","n476":"sentence 476 holds several ordinary words for indexing","n477":"sentence 477 holds several ordinary words for indexing","n478":"sentence 478 holds several ordinary words for indexing","n479":"sentence 479 holds several ordinary words for indexing","n480":"sentence 480 holds several ordinary words for indexing","n481":"sentence 481 holds several ordinary words for indexing","n482":"sentence 482 holds several ordinary words for indexing","n483":"sentence 483 holds several ordinary words for indexing","n484":"sentence 484 holds several ordinary words for indexing","n485":"sentence 485 holds several ordinary words for indexing","n486":"sentence 486 holds several ordinary words for indexing","n487":"sentence 487 holds several ordinary words for indexing","n488":"sentence 488 holds several ordinary words for indexing","n489":"sentence 489 holds several ordinary words for indexing","n490":"sentence 490 holds several ordinary words for indexing","n491":"sentence 491 holds several ordinary words for indexing","n492":"sentence 492 holds several ordinary words for indexing","n493":"sentence 493 holds several ordinary words for indexing","n494":"sentence 494 holds several ordinary words for indexing","n495":"sentence 495 holds several ordinary words for indexing","n496":"sentence 496 holds several ordinary words for indexing","n497":"sentence 497 holds several ordinary words for indexing","n498":"sentence 498 holds several ordinary words for indexing","n499":"sentence 499 holds several ordinary words for indexing","n500":"sentence 500 holds several ordinary words for indexing","n501":"sentence 501 holds several ordinary words for indexing","n502":"sentence 502 holds several ordinary words for indexing","n503":"sentence 503 holds several ordinary words for indexing","n504":"sentence 504 holds several ordinary words for indexing","n505":"sentence 505 holds several ordinary words for indexing","n506":"sentence 506 holds several ordinary words for indexing","n507":"sentence 507 holds several ordinary words for indexing","n508":"sentence 508 holds several ordinary words for indexing","n509":"sentence 509 holds several ordinary words for indexing","n510":"sentence 510 holds several ordinary words for indexing","n511":"sentence 511 holds several ordinary words for indexing","n512":"sentence 512 holds several ordinary words for indexing","n513":"sentence 513 holds several ordinary words for indexing","n514":"sentence 514 holds several ordinary words for indexing","n515":"sentence 515 holds several ordinary words for indexing","n516":"sentence 516 holds several ordinary words for indexing","n517":"sentence 517 holds several ordinary words for indexing","n518":"sentence 518 holds several ordinary words for indexing","n519":"sentence 519 holds several ordinary words for indexing","n520":"sentence 520 holds several ordinary words for indexing","n521":"sentence 521 holds several ordinary words for indexing","n522":"sentence 522 holds several ordinary words for indexing","n523":"sentence 523 holds several ordinary words for indexing","n524":"sentence 524 holds several ordinary words for indexing","n525":"sentence 525 holds several ordinary words for indexing","n526":"sentence 526 holds several ordinary words for indexing","n527":"sentence 527 holds several ordinary words for indexing","n528":"sentence 528 holds several ordinary words for indexing","n529":"sentence 529 holds several ordinary words for indexing","n530":"sentence 530 holds several ordinary words for indexing","n531":"sentence 531 holds several ordinary words for indexing","n532":"sentence 532 holds several ordinary words for indexing","n533":"sentence 533 holds several ordinary words for indexing","n534":"sentence 534 holds several ordinary words for indexing","n535":"sentence 535 holds several ordinary words for indexing","n536":"sentence 536 holds several ordinary words for indexing","n537":"sentence 537 holds several ordinary words for indexing","n538":"sentence 538 holds several ordinary words for indexing","n539":"sentence 539 holds several ordinary words for indexing","n540":"sentence 540 holds several ordinary words for indexing","n541":"sentence 541 holds several ordinary words for indexing","n542":"sentence 542 holds several ordinary words for indexing","n543":"sentence 543 holds several ordinary words for indexing","n544":"sentence 544 holds several ordinary words for indexing","n545":"sentence 545 holds several ordinary words for indexing","n546":"sentence 546 holds several ordinary words for indexing","n547":"sentence 547 holds several ordinary words for indexing","n548":"sentence 548 holds several ordinary words for indexing","n549":"sentence 549 holds several ordinary words for indexing","n550":"sentence 550 holds several ordinary words for indexing","n551":"sentence 551 holds several ordinary words for indexing","n552":"sentence 552 holds several ordinary words for indexing","n553":"sentence 553 holds several ordinary words for indexing","n554":"sentence 554 holds several ordinary words for indexing","n555":"sentence 555 holds several ordinary words for indexing","n556":"sentence 556 holds several ordinary words for indexing","n557":"sentence 557 holds several ordinary words for indexing","n558":"sentence 558 holds several ordinary words for indexing","n559":"sentence 559 holds several ordinary words for indexing","n560":"sentence 560 holds several ordinary words for indexing","n561":"sentence 561 holds several ordinary words for indexing","n562":"sentence 562 holds several ordinary words for indexing","n563":"sentence 563 holds several ordinary words for indexing","n564":"sentence 564 holds several ordinary words for indexing","n565":"sentence 565 holds several ordinary words for indexing","n566":"sentence 566 holds several ordinary words for indexing","n567":"sentence 567 holds several ordinary words for indexing","n568":"sentence 568 holds several ordinary words for indexing","n569":"sentence 569 holds several ordinary words for indexing","n570":"sentence 570 holds several ordinary words for indexing","n571":"sentence 571 holds several ordinary words for indexing","n572":"sentence 572 holds several ordinary words for indexing","n573":"sentence 573 holds several ordinary words for indexing","n574":"sentence 574 holds several ordinary words for indexing","n575":"sentence 575 holds several ordinary words for indexing","n576":"sentence 576 holds several ordinary words for indexing","n577":"sentence 577 holds several ordinary words for indexing","n578":"sentence 578 holds several ordinary words for indexing","n579":"sentence 579 holds several ordinary words for indexing","n580":"sentence 580 holds several ordinary words for indexing","n581":"sentence 581 holds several ordinary words for indexing","n582":"sentence 582 holds several ordinary words for indexing","n583":"sentence 583 holds several ordinary words for indexing","n584":"sentence 584 holds several ordinary words for indexing","n585":"sentence 585 holds several ordinary words for indexing","n586":"sentence 586 holds several ordinary words for indexing","n587":"sentence 587 holds several ordinary words for indexing","n588":"sentence 588 holds several ordinary words for indexing","n589":"sentence 589 holds several ordinary words for indexing","n590":"sentence 590 holds several ordinary words for indexing","n591":"sentence 591 holds several ordinary words for indexing","n592":"sentence 592 holds several ordinary words for indexing","n593":"sentence 593 holds several ordinary words for indexing","n594":"sentence 594 holds several ordinary words for indexing","n595":"sentence 595 holds several ordinary words for indexing","n596":"sentence 596 holds several ordinary words for indexing","n597":"sentence 597 holds several ordinary words for indexing","n598":"sentence 598 holds several ordinary words for indexing","n599":"sentence 599 holds several ordinary words for indexing","n600":"sentence 600 holds several ordinary words for indexing","n601":"sentence 601 holds several ordinary words for indexing","n602":"sentence 602 holds several ordinary words for indexing","n603":"sentence 603 holds several ordinary words for indexing","n604":"sentence 604 holds several ordinary words for indexing","n605":"sentence 605 holds several ordinary words for indexing","n606":"sentence 606 holds several ordinary words for indexing","n607":"sentence 607 holds several ordinary words for indexing","n608":"sentence 608 holds several ordinary words for indexing","n609":"sentence 609 holds several ordinary words for indexing","n610":"sentence 610 holds several ordinary words for indexing","n611":"sentence 611 holds several ordinary words for indexing","n612":"sentence 612 holds several ordinary words for indexing","n613":"sentence 613 holds several ordinary words for indexing","n614":"sentence 614 holds several ordinary words for indexing","n615":"sentence 615 holds several ordinary words for indexing","n616":"sentence 616 holds several ordinary words for indexing","n617":"sentence 617 holds several ordinary words for indexing","n618":"sentence 618 holds several ordinary words for indexing","n619":"sentence 619 holds several ordinary words for indexing","n620":"sentence 620 holds several ordinary words for indexing","n621":"sentence 621 holds several ordinary words for indexing","n622":"sentence 622 holds several ordinary words for indexing","n623":"sentence 623 holds several ordinary words for indexing","n624":"sentence 624 holds several ordinary words for indexing","n625":"sentence 625 holds several ordinary words for indexing","n626":"sentence 626 holds several ordinary words for indexing","n627":"sentence 627 holds several ordinary words for indexing","n628":"sentence 628 holds several ordinary words for indexing","n629":"sentence 629 holds several ordinary words for indexing","n630":"sentence 630 holds several ordinary words for indexing","n631":"sentence 631 holds several ordinary words for indexing","n632":"sentence 632 holds several ordinary words for indexing","n633":"sentence 633 holds several ordinary words for indexing","n634":"sentence 634 holds several ordinary words for indexing","n635":"sentence 635 holds several ordinary words for indexing","n636":"sentence 636 holds several ordinary words for indexing","n637":"sentence 637 holds several ordinary words for indexing","n638":"sentence 638 holds several ordinary words for indexing","n639":"sentence 639 holds several ordinary words for indexing","n640":"sentence 640 holds several ordinary words for indexing","n641":"sentence 641 holds several ordinary words for indexing","n642":"sentence 642 holds several ordinary words for indexing","n643":"sentence 643 holds several ordinary words for indexing","n644":"sentence 644 holds several ordinary words for indexing","n645":"sentence 645 holds several ordinary words for indexing","n646":"sentence 646 holds several ordinary words for indexing","n647":"sentence 647 holds several ordinary words for indexing","n648":"sentence 648 holds several ordinary words for indexing","n649":"sentence 649 holds several ordinary words for indexing","n650":"sentence 650 holds several ordinary words for indexing","n651":"sentence 651 holds several ordinary words for indexing","n652":"sentence 652 holds several ordinary words for indexing","n653":"sentence 653 holds several ordinary words for indexing","n654":"sentence 654 holds several ordinary words for indexing","n655":"sentence 655 holds several ordinary words for indexing","n656":"sentence 656 holds several ordinary words for indexing","n657":"sentence 657 holds several ordinary words for indexing","n658":"sentence 658 holds several ordinary words for indexing","n659":"sentence 659 holds several ordinary words for indexing","n660":"sentence 660 holds several ordinary words for indexing","n661":"sentence 661 holds several ordinary words for indexing","n662":"sentence 662 holds several ordinary words for indexing","n663":"sentence 663 holds several ordinary words for indexing","n664":"sentence 664 holds several ordinary words for indexing","n665":"sentence 665 holds several ordinary words for indexing","n666":"sentence 666 holds several ordinary words for indexing","n667":"sentence 667 holds several ordinary words for indexing","n668":"sentence 668 holds several ordinary words for indexing","n669":"sentence 669 holds several ordinary words for indexing","n670":"sentence 670 holds several ordinary words for indexing","n671":"sentence 671 holds several ordinary words for indexing","n672":"sentence 672 holds several ordinary words for indexing","n673":"sentence 673 holds several ordinary words for indexing","n674":"sentence 674 holds several ordinary words for indexing","n675":"sentence 675 holds several ordinary words for indexing","n676":"sentence 676 holds several ordinary words for indexing","n677":"sentence 677 holds several ordinary words for indexing","n678":"sentence 678 holds several ordinary words for indexing","n679":"sentence 679 holds several ordinary words for indexing","n680":"sentence 680 holds several ordinary words for indexing","n681":"sentence 681 holds several ordinary words for indexing","n682":"sentence 682 holds several ordinary words for indexing","n683":"sentence 683 holds several ordinary words for indexing","n684":"sentence 684 holds several ordinary words for indexing","n685":"sentence 685 holds several ordinary words for indexing","n686":"sentence 686 holds several ordinary words for indexing","n687":"sentence 687 holds several ordinary words for indexing","n688":"sentence 688 holds several ordinary words for indexing","n689":"sentence 689 holds several ordinary words for indexing","n690":"sentence 690 holds several ordinary words for indexing","n691":"sentence 691 holds several ordinary words for indexing","n692":"sentence 692 holds several ordinary words for indexing","n693":"sentence 693 holds several ordinary words for indexing","n694":"sentence 694 holds several ordinary words for indexing","n695":"sentence 695 holds several ordinary words for indexing","n696":"sentence 696 holds several ordinary words for indexing","n697":"sentence 697 holds several ordinary words for indexing","n698":"sentence 698 holds several ordinary words for indexing","n699":"sentence 699 holds several ordinary words for indexing","n700":"sentence 700 holds several ordinary words for indexing","n701":"sentence 701 holds several ordinary words for indexing","n702":"sentence 702 holds several ordinary words for indexing","n703":"sentence 703 holds several ordinary words for indexing","n704":"sentence 704 holds several ordinary words for indexing","n705":"sentence 705 holds several ordinary words for indexing","n706":"sentence 706 holds several ordinary words for indexing","n707":"sentence 707 holds several ordinary words for indexing","n708":"sentence 708 holds several ordinary words for indexing","n709":"sentence 709 holds several ordinary words for indexing","n710":"sentence 710 holds several ordinary words for indexing","n711":"sentence 711 holds several ordinary words for indexing","n712":"sentence 712 holds several ordinary words for indexing","n713":"sentence 713 holds several ordinary words for indexing","n714":"sentence 714 holds several ordinary words for indexing","n715":"sentence 715 holds several ordinary words for indexing","n716":"sentence 716 holds several ordinary words for indexing","n717":"sentence 717 holds several ordinary words for indexing","n718":"sentence 718 holds several ordinary words for indexing","n719":"sentence 719 holds several ordinary words for indexing","n720":"sentence 720 holds several ordinary words for indexing","n721":"sentence 721 holds several ordinary words for indexing","n722":"sentence 722 holds several ordinary words for indexing","n723":"sentence 723 holds several ordinary words for indexing","n724":"sentence 724 holds several ordinary words for indexing","n725":"sentence 725 holds several ordinary words for indexing","n726":"sentence 726 holds several ordinary words for indexing","n727":"sentence 727 holds several ordinary words for indexing","n728":"sentence 728 holds several ordinary words for indexing","n729":"sentence 729 holds several ordinary words for indexing","n730":"sentence 730 holds several ordinary words for indexing","n731":"sentence 731 holds several ordinary words for indexing","n732":"sentence 732 holds several ordinary words for indexing","n733":"sentence 733 holds several ordinary words for indexing","n734":"sentence 734 holds several ordinary words for indexing","n735":"sentence 735 holds several ordinary words for indexing","n736":"sentence 736 holds several ordinary words for indexing","n737":"sentence 737 holds several ordinary words for indexing","n738":"sentence 738 holds several ordinary words for indexing","n739":"sentence 739 holds several ordinary words for indexing","n740":"sentence 740 holds several ordinary words for indexing","n741":"sentence 741 holds several ordinary words for indexing","n742":"sentence 742 holds several ordinary words for indexing","n743":"sentence 743 holds several ordinary words for indexing","n744":"sentence 744 holds several ordinary words for indexing","n745":"sentence 745 holds several ordinary words for indexing","n746":"sentence 746 holds several ordinary words for indexing","n747":"sentence 747 holds several ordinary words for indexing","n748":"sentence 748 holds several ordinary words for indexing","n749":"sentence 749 holds several ordinary words for indexing","n750":"sentence 750 holds several ordinary words for indexing","n751":"sentence 751 holds several ordinary words for indexing","n752":"sentence 752 holds several ordinary words for indexing","n753":"sentence 753 holds several ordinary words for indexing","n754":"sentence 754 holds several ordinary words for indexing","n755":"sentence 755 holds several ordinary words for indexing","n756":"sentence 756 holds several ordinary words for indexing","n757":"sentence 757 holds several ordinary words for indexing","n758":"sentence 758 holds several ordinary words for indexing","n759":"sentence 759 holds several ordinary words for indexing","n760":"sentence 760 holds several ordinary words for indexing","n761":"sentence 761 holds several ordinary words for indexing","n762":"sentence 762 holds several ordinary words for indexing","n763":"sentence 763 holds several ordinary words for indexing","n764":"sentence 764 holds several ordinary words for indexing","n765":"sentence 765 holds several ordinary words for indexing","n766":"sentence 766 holds several ordinary words for indexing","n767":"sentence 767 holds several ordinary words for indexing","n768":"sentence 768 holds several ordinary words for indexing","n769":"sentence 769 holds several ordinary words for indexing","n770":"sentence 770 holds several ordinary words for indexing","n771":"sentence 771 holds several ordinary words for indexing","n772":"sentence 772 holds several ordinary words for indexing","n773":"sentence 773 holds several ordinary words for indexing","n774":"sentence 774 holds several ordinary words for indexing","n775":"sentence 775 holds several ordinary words for indexing","n776":"sentence 776 holds several ordinary words for indexing","n777":"sentence 777 holds several ordinary words for indexing","n778":"sentence 778 holds several ordinary words for indexing","n779":"sentence 779 holds several ordinary words for indexing","n780":"sentence 780 holds several ordinary words for indexing","n781":"sentence 781 holds several ordinary words for indexing","n782":"sentence 782 holds several ordinary words for indexing","n783":"sentence 783 holds several ordinary words for indexing","n784":"sentence 784 holds several ordinary words for indexing","n785":"sentence 785 holds several ordinary words for indexing","n786":"sentence 786 holds several ordinary words for indexing","n787":"sentence 787 holds several ordinary words for indexing","n788":"sentence 788 holds several ordinary words for indexing","n789":"sentence 789 holds several ordinary words for indexing","n790":"sentence 790 holds several ordinary words for indexing","n791":"sentence 791 holds several ordinary words for indexing","n792":"sentence 792 holds several ordinary words for indexing","n793":"sentence 793 holds several ordinary words for indexing","n794":"sentence 794 holds several ordinary words for indexing","n795":"sentence 795 holds several ordinary words for indexing","n796":"sentence 796 holds several ordinary words for indexing","n797":"sentence 797 holds several ordinary words for indexing","n798":"sentence 798 holds several ordinary words for indexing","n799":"sentence 799 holds several ordinary words for indexing","n800":"sentence 800 holds several ordinary words for indexing","n801":"sentence 801 holds several ordinary words for indexing","n802":"sentence 802 holds several ordinary words for indexing","n803":"sentence 803 holds several ordinary words for indexing","n804":"sentence 804 holds several ordinary words for indexing","n805":"sentence 805 holds several ordinary words for indexing","n806":"sentence 806 holds several ordinary words for indexing","n807":"sentence 807 holds several ordinary words for indexing","n808":"sentence 808 holds several ordinary words for indexing","n809":"sentence 809 holds several ordinary words for indexing","n810":"sentence 810 holds several ordinary words for indexing","n811":"sentence 811 holds several ordinary words for indexing","n812":"sentence 812 holds several ordinary words for indexing","n813":"sentence 813 holds several ordinary words for indexing","n814":"sentence 814 holds several ordinary words for indexing","n815":"sentence 815 holds several ordinary words for indexing","n816":"sentence 816 holds several ordinary words for indexing","n817":"sentence 817 holds several ordinary words for indexing","n818":"sentence 818 holds several ordinary words for indexing","n819":"sentence 819 holds several ordinary words for indexing","n820":"sentence 820 holds several ordinary words for indexing","n821":"sentence 821 holds several ordinary words for indexing","n822":"sentence 822 holds several ordinary words for indexing","n823":"sentence 823 holds several ordinary words for indexing","n824":"sentence 824 holds several ordinary words for indexing","n825":"sentence 825 holds several ordinary words for indexing","n826":"sentence 826 holds several ordinary words for indexing","n827":"sentence 827 holds several ordinary words for indexing","n828":"sentence 828 holds several ordinary words for indexing","n829":"sentence 829 holds several ordinary words for indexing","n830":"sentence 830 holds several ordinary words for indexing","n831":"sentence 831 holds several ordinary words for indexing","n832":"sentence 832 holds several ordinary words for indexing","n833":"sentence 833 holds several ordinary words for indexing","n834":"sentence 834 holds several ordinary words for indexing","n835":"sentence 835 holds several ordinary words for indexing","n836":"sentence 836 holds several ordinary words for indexing","n837":"sentence 837 holds several ordinary words for indexing","n838":"sentence 838 holds several ordinary words for indexing","n839":"sentence 839 holds several ordinary words for indexing","n840":"sentence 840 holds several ordinary words for indexing","n841":"sentence 841 holds several ordinary words for indexing","n842":"sentence 842 holds several ordinary words for indexing","n843":"sentence 843 holds several ordinary words for indexing","n844":"sentence 844 holds several ordinary words for indexing","n845":"sentence 845 holds several ordinary words for indexing","n846":"sentence 846 holds several ordinary words for indexing","n847":"sentence 847 holds several ordinary words for indexing","n848":"sentence 848 holds several ordinary words for indexing","n849":"sentence 849 holds several ordinary words for indexing","n850":"sentence 850 holds several ordinary words for indexing","n851":"sentence 851 holds several ordinary words for indexing","n852":"sentence 852 holds several ordinary words for indexing","n853":"sentence 853 holds several ordinary words for indexing","n854":"sentence 854 holds several ordinary words for indexing","n855":"sentence 855 holds several ordinary words for indexing","n856":"sentence 856 holds several ordinary words for indexing","n857":"sentence 857 holds several ordinary words for indexing","n858":"sentence 858 holds several ordinary words for indexing","n859":"sentence 859 holds several ordinary words for indexing","n860":"sentence 860 holds several ordinary words for indexing","n861":"sentence 861 holds several ordinary words for indexing","n862":"sentence 862 holds several ordinary words for indexing","n863":"sentence 863 holds several ordinary words for indexing","n864":"sentence 864 holds several ordinary words for indexing","n865":"sentence 865 holds several ordinary words for indexing","n866":"sentence 866 holds several ordinary words for indexing","n867":"sentence 867 holds several ordinary words for indexing","n868":"sentence 868 holds several ordinary words for indexing","n869":"sentence 869 holds several ordinary words for indexing","n870":"sentence 870 holds several ordinary words for indexing","n871":"sentence 871 holds several ordinary words for indexing","n872":"sentence 872 holds several ordinary words for indexing","n873":"sentence 873 holds several ordinary words for indexing","n874":"sentence 874 holds several ordinary words for indexing","n875":"sentence 875 holds several ordinary words for indexing","n876":"sentence 876 holds several ordinary words for indexing","n877":"sentence 877 holds several ordinary words for indexing","n878":"sentence 878 holds several ordinary words for indexing","n879":"sentence 879 holds several ordinary words for indexing","n880":"sentence 880 holds several ordinary words for indexing","n881":"sentence 881 holds several ordinary words for indexing","n882":"sentence 882 holds several ordinary words for indexing","n883":"sentence 883 holds several ordinary words for indexing","n884":"sentence 884 holds several ordinary words for indexing","n885":"sentence 885 holds several ordinary words for indexing","n886":"sentence 886 holds several ordinary words for indexing","n887":"sentence 887 holds several ordinary words for indexing","n888":"sentence 888 holds several ordinary words for indexing","n889":"sentence 889 holds several ordinary words for indexing","n890":"sentence 890 holds several ordinary words for indexing","n891":"sentence 891 holds several ordinary words for indexing","n892":"sentence 892 holds several ordinary words for indexing","n893":"sentence 893 holds several ordinary words for indexing","n894":"sentence 894 holds several ordinary words for indexing","n895":"sentence 895 holds several ordinary words for indexing","n896":"sentence 896 holds several ordinary words for indexing","n897":"sentence 897 holds several ordinary words for indexing","n898":"sentence 898 holds several ordinary words for indexing","n899":"sentence 899 holds several ordinary words for indexing","n900":"sentence 900 holds several ordinary words for indexing","n901":"sentence 901 holds several ordinary words for indexing","n902":"sentence 902 holds several ordinary words for indexing","n903":"sentence 903 holds several ordinary words for indexing","n904":"sentence 904 holds several ordinary words for indexing","n905":"sentence 905 holds several ordinary words for indexing","n906":"sentence 906 holds several ordinary words for indexing","n907":"sentence 907 holds several ordinary words for indexing","n908":"sentence 908 holds several ordinary words for indexing","n909":"sentence 909 holds several ordinary words for indexing","n910":"sentence 910 holds several ordinary words for indexing","n911":"sentence 911 holds several ordinary words for indexing","n912":"sentence 912 holds several ordinary words for indexing","n913":"sentence 913 holds several ordinary words for indexing","n914":"sentence 914 holds several ordinary words for indexing","n915":"sentence 915 holds several ordinary words for indexing","n916":"sentence 916 holds several ordinary words for indexing","n917":"sentence 917 holds several ordinary words for indexing","n918":"sentence 918 holds several ordinary words for indexing","n919":"sentence 919 holds several ordinary words for indexing","n920":"sentence 920 holds several ordinary words for indexing","n921":"sentence 921 holds several ordinary words for indexing","n922":"sentence 922 holds several ordinary words for indexing","n923":"sentence 923 holds several ordinary words for indexing","n924":"sentence 924 holds several ordinary words for indexing","n925":"sentence 925 holds several ordinary words for indexing","n926":"sentence 926 holds several ordinary words for indexing","n927":"sentence 927 holds several ordinary words for indexing","n928":"sentence 928 holds several ordinary words for indexing","n929":"sentence 929 holds several ordinary words for indexing","n930":"sentence 930 holds several ordinary words for indexing","n931":"sentence 931 holds several ordinary words for indexing","n932":"sentence 932 holds several ordinary words for indexing","n933":"sentence 933 holds several ordinary words for indexing","n934":"sentence 934 holds several ordinary words for indexing","n935":"sentence 935 holds several ordinary words for indexing","n936":"sentence 936 holds several ordinary words for indexing","n937":"sentence 937 holds several ordinary words for indexing","n938":"sentence 938 holds several ordinary words for indexing","n939":"sentence 939 holds several ordinary words for indexing","n940":"sentence 940 holds several ordinary words for indexing","n941":"sentence 941 holds several ordinary words for indexing","n942":"sentence 942 holds several ordinary words for indexing","n943":"sentence 943 holds several ordinary words for indexing","n944":"sentence 944 holds several ordinary words for indexing","n945":"sentence 945 holds several ordinary words for indexing","n946":"sentence 946 holds several ordinary words for indexing","n947":"sentence 947 holds several ordinary words for indexing","n948":"sentence 948 holds several ordinary words for indexing","n949":"sentence 949 holds several ordinary words for indexing","n950":"sentence 950 holds several ordinary words for indexing","n951":"sentence 951 holds several ordinary words for indexing","n952":"sentence 952 holds several ordinary words for indexing","n953":"sentence 953 holds several ordinary words for indexing","n954":"sentence 954 holds several ordinary words for indexing","n955":"sentence 955 holds several ordinary words for indexing","n956":"sentence 956 holds several ordinary words for indexing","n957":"sentence 957 holds several ordinary words for indexing","n958":"sentence 958 holds several ordinary words for indexing","n959":"sentence 959 holds several ordinary words for indexing","n960":"sentence 960 holds several ordinary words for indexing","n961":"sentence 961 holds several ordinary words for indexing","n962":"sentence 962 holds several ordinary words for indexing","n963":"sentence 963 holds several ordinary words for indexing","n964":"sentence 964 holds several ordinary words for indexing","n965":"sentence 965 holds several ordinary words for indexing","n966":"sentence 966 holds several ordinary words for indexing","n967":"sentence 967 holds several ordinary words for indexing","n968":"sentence 968 holds several ordinary words for indexing","n969":"sentence 969 holds several ordinary words for indexing","n970":"sentence 970 holds several ordinary words for indexing","n971":"sentence 971 holds several ordinary words for indexing","n972":"sentence 972 holds several ordinary words for indexing","n973":"sentence 973 holds several ordinary words for indexing","n974":"sentence 974 holds several ordinary words for indexing","n975":"sentence 975 holds several ordinary words for indexing","n976":"sentence 976 holds several ordinary words for indexing","n977":"sentence 977 holds several ordinary words for indexing","n978":"sentence 978 holds several ordinary words for indexing","n979":"sentence 979 holds several ordinary words for indexing","n980":"sentence 980 holds several ordinary words for indexing","n981":"sentence 981 holds several ordinary words for indexing","n982":"sentence 982 holds several ordinary words for indexing","n983":"sentence 983 holds several ordinary words for indexing","n984":"sentence 984 holds several ordinary words for indexing","n985":"sentence 985 holds several ordinary words for indexing","n986":"sentence 986 holds several ordinary words for indexing","n987":"sentence 987 holds several ordinary words for indexing","n988":"sentence 988 holds several ordinary words for indexing","n989":"sentence 989 holds several ordinary words for indexing","n990":"sentence 990 holds several ordinary words for indexing","n991":"sentence 991 holds several ordinary words for indexing","n992":"sentence 992 holds several ordinary words for indexing","n993":"sentence 993 holds several ordinary words for indexing","n994":"sentence 994 holds several ordinary words for indexing","n995":"sentence 995 holds several ordinary words for indexing","n996":"sentence 996 holds several ordinary words for indexing","n997":"sentence 997 holds several ordinary words for indexing","n998":"sentence 998 holds several ordinary words for indexing","n999":"sentence 999 holds several ordinary words for indexing","n1000":"sentence 1000 holds several ordinary words for indexing","n1001":"sentence 1001 holds several ordinary words for indexing","n1002":"sentence 1002 holds several ordinary words for indexing","n1003":"sentence 1003 holds several ordinary words for indexing","n1004":"sentence 1004 holds several ordinary words for indexing","n1005":"sentence 1005 holds several ordinary words for indexing","n1006":"sentence 1006 holds several ordinary words for indexing","n1007":"sentence 1007 holds several ordinary words for indexing","n1008":"sentence 1008 holds several ordinary words for indexing","n1009":"sentence 1009 holds several ordinary words for indexing","n1010":"sentence 1010 holds several ordinary words for indexing","n1011":"sentence 1011 holds several ordinary words for indexing","n1012":"sentence 1012 holds several ordinary words for indexing","n1013":"sentence 1013 holds several ordinary words for indexing","n1014":"sentence 1014 holds several ordinary words for indexing","n1015":"sentence 1015 holds several ordinary words for indexing","n1016":"sentence 1016 holds several ordinary words for indexing","n1017":"sentence 1017 holds several ordinary words for indexing","n1018":"sentence 1018 holds several ordinary words for indexing","n1019":"sentence 1019 holds several ordinary words for indexing","n1020":"sentence 1020 holds several ordinary words for indexing","n1021":"sentence 1021 holds several ordinary words for indexing","n1022":"sentence 1022 holds several ordinary words for indexing","n1023":"sentence 1023 holds several ordinary words for indexing","n1024":"sentence 1024 holds several ordinary words for indexing","n1025":"sentence 1025 holds several ordinary words for indexing","n1026":"sentence 1026 holds several ordinary words for indexing","n1027":"sentence 1027 holds several ordinary words for indexing","n1028":"sentence 1028 holds several ordinary words for indexing","n1029":"sentence 1029 holds several ordinary words for indexing","n1030":"sentence 1030 holds several ordinary words for indexing","n1031":"sentence 1031 holds several ordinary words for indexing","n1032":"sentence 1032 holds several ordinary words for indexing","n1033":"sentence 1033 holds several ordinary words for indexing","n1034":"sentence 1034 holds several ordinary words for indexing","n1035":"sentence 1035 holds several ordinary words for indexing","n1036":"sentence 1036 holds several ordinary words for indexing","n1037":"sentence 1037 holds several ordinary words for indexing","n1038":"sentence 1038 holds several ordinary words for indexing","n1039":"sentence 1039 holds several ordinary words for indexing","n1040":"sentence 1040 holds several ordinary words for indexing","n1041":"sentence 1041 holds several ordinary words for indexing","n1042":"sentence 1042 holds several ordinary words for indexing","n1043":"sentence 1043 holds several ordinary words for indexing","n1044":"sentence 1044 holds several ordinary words for indexing","n1045":"sentence 1045 holds several ordinary words for indexing","n1046":"sentence 1046 holds several ordinary words for indexing","n1047":"sentence 1047 holds several ordinary words for indexing","n1048":"sentence 1048 holds several ordinary words for indexing","n1049":"sentence 1049 holds several ordinary words for indexing","n1050":"sentence 1050 holds several ordinary words for indexing","n1051":"sentence 1051 holds several ordinary words for indexing","n1052":"sentence 1052 holds several ordinary words for indexing","n1053":"sentence 1053 holds several ordinary words for indexing","n1054":"sentence 1054 holds several ordinary words for indexing","n1055":"sentence 1055 holds several ordinary words for indexing","n1056":"sentence 1056 holds several ordinary words for indexing","n1057":"sentence 1057 holds several ordinary words for indexing","n1058":"sentence 1058 holds several ordinary words for indexing","n1059":"sentence 1059 holds several ordinary words for indexing","n1060":"sentence 1060 holds several ordinary words for indexing","n1061":"sentence 1061 holds several ordinary words for indexing","n1062":"sentence 1062 holds several ordinary words for indexing","n1063":"sentence 1063 holds several ordinary words for indexing","n1064":"sentence 1064 holds several ordinary words for indexing","n1065":"sentence 1065 holds several ordinary words for indexing","n1066":"sentence 1066 holds several ordinary words for indexing","n1067":"sentence 1067 holds several ordinary words for indexing","n1068":"sentence 1068 holds several ordinary words for indexing","n1069":"sentence 1069 holds several ordinary words for indexing","n1070":"sentence 1070 holds several ordinary words for indexing","n1071":"sentence 1071 holds several ordinary words for indexing","n1072":"sentence 1072 holds several ordinary words for indexing","n1073":"sentence 1073 holds several ordinary words for indexing","n1074":"sentence 1074 holds several ordinary words for indexing","n1075":"sentence 1075 holds several ordinary words for indexing","n1076":"sentence 1076 holds several ordinary words for indexing","n1077":"sentence 1077 holds several ordinary words for indexing","n1078":"sentence 1078 holds several ordinary words for indexing","n1079":"sentence 1079 holds several ordinary words for indexing","n1080":"sentence 1080 holds several ordinary words for indexing","n1081":"sentence 1081 holds several ordinary words for indexing","n1082":"sentence 1082 holds several ordinary words for indexing","n1083":"sentence 1083 holds several ordinary words for indexing","n1084":"sentence 1084 holds several ordinary words for indexing","n1085":"sentence 1085 holds several ordinary words for indexing","n1086":"sentence 1086 holds several ordinary words for indexing","n1087":"sentence 1087 holds several ordinary words for indexing","n1088":"sentence 1088 holds several ordinary words for indexing","n1089":"sentence 1089 holds several ordinary words for indexing","n1090":"sentence 1090 holds several ordinary words for indexing","n1091":"sentence 1091 holds several ordinary words for indexing","n1092":"sentence 1092 holds several ordinary words for indexing","n1093":"sentence 1093 holds several ordinary words for indexing","n1094":"sentence 1094 holds several ordinary words for indexing","n1095":"sentence 1095 holds several ordinary words for indexing","n1096":"sentence 1096 holds several ordinary words for indexing","n1097":"sentence 1097 holds several ordinary words for indexing","n1098":"sentence 1098 holds several ordinary words for indexing","n1099":"sentence 1099 holds several ordinary words for indexing","n1100":"sentence 1100 holds several ordinary words for indexing","n1101":"sentence 1101 holds several ordinary words for indexing","n1102":"sentence 1102 holds several ordinary words for indexing","n1103":"sentence 1103 holds several ordinary words for indexing","n1104":"sentence 1104 holds several ordinary words for indexing","n1105":"sentence 1105 holds several ordinary words for indexing","n1106":"sentence 1106 holds several ordinary words for indexing","n1107":"sentence 1107 holds several ordinary words for indexing","n1108":"sentence 1108 holds several ordinary words for indexing","n1109":"sentence 1109 holds several ordinary words for indexing","n1110":"sentence 1110 holds several ordinary words for indexing","n1111":"sentence 1111 holds several ordinary words for indexing","n1112":"sentence 1112 holds several ordinary words for indexing","n1113":"sentence 1113 holds several ordinary words for indexing","n1114":"sentence 1114 holds several ordinary words for indexing","n1115":"sentence 1115 holds several ordinary words for indexing","n1116":"sentence 1116 holds several ordinary words for indexing","n1117":"sentence 1117 holds several ordinary words for indexing","n1118":"sentence 1118 holds several ordinary words for indexing","n1119":"sentence 1119 holds several ordinary words for indexing","n1120":"sentence 1120 holds several ordinary words for indexing","n1121":"sentence 1121 holds several ordinary words for indexing","n1122":"sentence 1122 holds several ordinary words for indexing","n1123":"sentence 1123 holds several ordinary words for indexing","n1124":"sentence 1124 holds several ordinary words for indexing","n1125":"sentence 1125 holds several ordinary words for indexing","n1126":"sentence 1126 holds several ordinary words for indexing","n1127":"sentence 1127 holds several ordinary words for indexing","n1128":"sentence 1128 holds several ordinary words for indexing","n1129":"sentence 1129 holds several ordinary words for indexing","n1130":"sentence 1130 holds several ordinary words for indexing","n1131":"sentence 1131 holds several ordinary words for indexing","n1132":"sentence 1132 holds several ordinary words for indexing","n1133":"sentence 1133 holds several ordinary words for indexing","n1134":"sentence 1134 holds several ordinary words for indexing","n1135":"sentence 1135 holds several ordinary words for indexing","n1136":"sentence 1136 holds several ordinary words for indexing","n1137":"sentence 1137 holds several ordinary words for indexing","n1138":"sentence 1138 holds several ordinary words for indexing","n1139":"sentence 1139 holds several ordinary words for indexing","n1140":"sentence 1140 holds several ordinary words for indexing","n1141":"sentence 1141 holds several ordinary words for indexing","n1142":"sentence 1142 holds several ordinary words for indexing","n1143":"sentence 1143 holds several ordinary words for indexing","n1144":"sentence 1144 holds several ordinary words for indexing","n1145":"sentence 1145 holds several ordinary words for indexing","n1146":"sentence 1146 holds several ordinary words for indexing","n1147":"sentence 1147 holds several ordinary words for indexing","n1148":"sentence 1148 holds several ordinary words for indexing","n1149":"sentence 1149 holds several ordinary words for indexing","n1150":"sentence 1150 holds several ordinary words for indexing","n1151":"sentence 1151 holds several ordinary words for indexing","n1152":"sentence 1152 holds several ordinary words for indexing","n1153":"sentence 1153 holds several ordinary words for indexing","n1154":"sentence 1154 holds several ordinary words for indexing","n1155":"sentence 1155 holds several ordinary words for indexing","n1156":"sentence 1156 holds several ordinary words for indexing","n1157":"sentence 1157 holds several ordinary words for indexing","n1158":"sentence 1158 holds several ordinary words for indexing","n1159":"sentence 1159 holds several ordinary words for indexing","n1160":"sentence 1160 holds several ordinary words for indexing","n1161":"sentence 1161 holds several ordinary words for indexing","n1162":"sentence 1162 holds several ordinary words for indexing","n1163":"sentence 1163 holds several ordinary words for indexing","n1164":"sentence 1164 holds several ordinary words for indexing","n1165":"sentence 1165 holds several ordinary words for indexing","n1166":"sentence 1166 holds several ordinary words for indexing","n1167":"sentence 1167 holds several ordinary words for indexing","n1168":"sentence 1168 holds several ordinary words for indexing","n1169":"sentence 1169 holds several ordinary words for indexing","n1170":"sentence 1170 holds several ordinary words for indexing","n1171":"sentence 1171 holds several ordinary words for indexing","n1172":"sentence 1172 holds several ordinary words for indexing","n1173":"sentence 1173 holds several ordinary words for indexing","n1174":"sentence 1174 holds several ordinary words for indexing","n1175":"sentence 1175 holds several ordinary words for indexing","n1176":"sentence 1176 holds several ordinary words for indexing","n1177":"sentence 1177 holds several ordinary words for indexing","n1178":"sentence 1178 holds several ordinary words for indexing","n1179":"sentence 1179 holds several ordinary words for indexing","n1180":"sentence 1180 holds several ordinary words for indexing","n1181":"sentence 1181 holds several ordinary words for indexing","n1182":"sentence 1182 holds several ordinary words for indexing","n1183":"sentence 1183 holds several ordinary words for indexing","n1184":"sentence 1184 holds several ordinary words for indexing","n1185":"sentence 1185 holds several ordinary words for indexing","n1186":"sentence 1186 holds several ordinary words for indexing","n1187":"sentence 1187 holds several ordinary words for indexing","n1188":"sentence 1188 holds several ordinary words for indexing","n1189":"sentence 1189 holds several ordinary words for indexing","n1190":"sentence 1190 holds several ordinary words for indexing","n1191":"sentence 1191 holds several ordinary words for indexing","n1192":"sentence 1192 holds several ordinary words for indexing","n1193":"sentence 1193 holds several ordinary words for indexing","n1194":"sentence 1194 holds several ordinary words for indexing","n1195":"sentence 1195 holds several ordinary words for indexing","n1196":"sentence 1196 holds several ordinary words for indexing","n1197":"sentence 1197 holds several ordinary words for indexing","n1198":"sentence 1198 holds several ordinary words for indexing","n1199":"sentence 1199 holds several ordinary words for indexing"}</script>
+</body></html>
diff --git a/tray/fixtures/cases/data-uri.html b/tray/fixtures/cases/data-uri.html
new file mode 100644
index 00000000..01a7fd8c
--- /dev/null
+++ b/tray/fixtures/cases/data-uri.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/slides","title":"Has Picture","src":"data:image/png;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","caption":"Harbour at dawn"}</script>
+</body></html>
diff --git a/tray/fixtures/cases/encrypted.html b/tray/fixtures/cases/encrypted.html
new file mode 100644
index 00000000..6a79c178
--- /dev/null
+++ b/tray/fixtures/cases/encrypted.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/enc","title":"Secret","ct":"BASE64CIPHERTEXTHERE"}</script>
+</body></html>
diff --git a/tray/fixtures/cases/escaped.html b/tray/fixtures/cases/escaped.html
new file mode 100644
index 00000000..a12f0cdc
--- /dev/null
+++ b/tray/fixtures/cases/escaped.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/spaces","title":"Quoting","note":"she said \"hello there\" twice"}</script>
+</body></html>
diff --git a/tray/fixtures/cases/longvalue.html b/tray/fixtures/cases/longvalue.html
new file mode 100644
index 00000000..c5f71768
--- /dev/null
+++ b/tray/fixtures/cases/longvalue.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/slides","title":"Cap","kept":"alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha","dropped":"omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega omega"}</script>
+</body></html>
diff --git a/tray/fixtures/cases/markup.html b/tray/fixtures/cases/markup.html
new file mode 100644
index 00000000..77dd8944
--- /dev/null
+++ b/tray/fixtures/cases/markup.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/slides","title":"Markup","html":"<b>Bold</b> and&nbsp;more&#39;s here"}</script>
+</body></html>
diff --git a/tray/fixtures/cases/noise.html b/tray/fixtures/cases/noise.html
new file mode 100644
index 00000000..51d22ed2
--- /dev/null
+++ b/tray/fixtures/cases/noise.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/dash","title":"Noise","fill":"#16273E","id":"e7","w":"12px","ok":"ab","keep":"Quarterly"}</script>
+</body></html>
diff --git a/tray/fixtures/cases/nomarker.html b/tray/fixtures/cases/nomarker.html
new file mode 100644
index 00000000..6ad39a01
--- /dev/null
+++ b/tray/fixtures/cases/nomarker.html
@@ -0,0 +1 @@
+<!DOCTYPE html><html><body><h1>Just a web page</h1><p>Nothing to index here.</p></body></html>
diff --git a/tray/fixtures/cases/plain.html b/tray/fixtures/cases/plain.html
new file mode 100644
index 00000000..e65570a6
--- /dev/null
+++ b/tray/fixtures/cases/plain.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><head><title>Bento</title></head><body>
+<script type="application/json" id="bento-doc">{"format":"bento/slides","docId":"a1b2","title":"Q3 Board Review","slides":[{"id":"s1","elements":[{"id":"e1","html":"Revenue grew steadily"},{"id":"e2","html":"Margins held"}]}]}</script>
+</body></html>
diff --git a/tray/fixtures/cases/preview.html b/tray/fixtures/cases/preview.html
new file mode 100644
index 00000000..2db2a641
--- /dev/null
+++ b/tray/fixtures/cases/preview.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/slides","title":"Thumbed","html":"Opening slide"}</script>
+<div data-bento-preview><svg xmlns="http://www.w3.org/2000/svg"><rect fill="#16273E"/></svg></div>
+<script data-bento-preview>(function(){})()</script>
+</body></html>
diff --git a/tray/fixtures/cases/whitespace.html b/tray/fixtures/cases/whitespace.html
new file mode 100644
index 00000000..98306168
--- /dev/null
+++ b/tray/fixtures/cases/whitespace.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><html><body>
+<script type="application/json" id="bento-doc">{"format":"bento/slides","title":"Spaces","body":"alpha beta gamma
delta epsilonzeta"}</script>
+</body></html>
diff --git a/tray/fixtures/expected.json b/tray/fixtures/expected.json
new file mode 100644
index 00000000..25e1dbb5
--- /dev/null
+++ b/tray/fixtures/expected.json
@@ -0,0 +1,114 @@
+{
+ "note": "GENERATED by scripts/gen-doc-index-expected.mjs from tray/doc-index.mjs. See README.md here.",
+ "textBudget": 40960,
+ "sniffBytes": 65536,
+ "headBytes": 307200,
+ "cases": {
+ "budget.html": {
+ "isDocument": true,
+ "title": "Long",
+ "app": "slides",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 40960,
+ "textSha256_16": "fed8158a27ba670b"
+ },
+ "data-uri.html": {
+ "isDocument": true,
+ "title": "Has Picture",
+ "app": "slides",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 40,
+ "textSha256_16": "1a3bf96e246185d9",
+ "text": "bento/slides Has Picture Harbour at dawn"
+ },
+ "encrypted.html": {
+ "isDocument": true,
+ "title": "Secret",
+ "app": "enc",
+ "encrypted": true,
+ "hasPreview": false,
+ "textLength": null,
+ "textSha256_16": null
+ },
+ "escaped.html": {
+ "isDocument": true,
+ "title": "Quoting",
+ "app": "spaces",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 51,
+ "textSha256_16": "68ff32d0682bfa29",
+ "text": "bento/spaces Quoting she said \\\"hello there\\\" twice"
+ },
+ "longvalue.html": {
+ "isDocument": true,
+ "title": "Cap",
+ "app": "slides",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 376,
+ "textSha256_16": "188df0f96aee75f2"
+ },
+ "markup.html": {
+ "isDocument": true,
+ "title": "Markup",
+ "app": "slides",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 40,
+ "textSha256_16": "3161ee14f2eef9b1",
+ "text": "bento/slides Markup Bold and more s here"
+ },
+ "noise.html": {
+ "isDocument": true,
+ "title": "Noise",
+ "app": "dash",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 26,
+ "textSha256_16": "5e4975596c282e78",
+ "text": "bento/dash Noise Quarterly"
+ },
+ "nomarker.html": {
+ "isDocument": false,
+ "title": null,
+ "app": null,
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": null,
+ "textSha256_16": null
+ },
+ "plain.html": {
+ "isDocument": true,
+ "title": "Q3 Board Review",
+ "app": "slides",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 63,
+ "textSha256_16": "d3717bf91feb8f8c",
+ "text": "bento/slides Q3 Board Review Revenue grew steadily Margins held"
+ },
+ "preview.html": {
+ "isDocument": true,
+ "title": "Thumbed",
+ "app": "slides",
+ "encrypted": false,
+ "hasPreview": true,
+ "textLength": 34,
+ "textSha256_16": "71bb9ed1139f531f",
+ "text": "bento/slides Thumbed Opening slide"
+ },
+ "whitespace.html": {
+ "isDocument": true,
+ "title": "Spaces",
+ "app": "slides",
+ "encrypted": false,
+ "hasPreview": false,
+ "textLength": 55,
+ "textSha256_16": "26c8a458ce19a08e",
+ "text": "bento/slides Spaces alpha beta gamma delta epsilon zeta"
+ }
+ }
+}