@onlyworlds/sdk 4.112.0 → 4.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,43 @@
1
+ import {
2
+ AGENT_DOORS,
3
+ CHARTER_PAIRS,
4
+ ELEMENT_GROUPS,
5
+ ELEMENT_ICONS,
6
+ ELEMENT_SECTIONS,
7
+ ELEMENT_TYPES,
8
+ FIELD_SCHEMA,
9
+ GROUP_COLORS,
10
+ GROUP_ORDER,
11
+ MESSAGE_PAIR,
12
+ MESSAGE_READ_MARK,
13
+ NOTE_PAIR,
14
+ ONLYWORLDS_VERSION,
15
+ OwAddressError,
16
+ PUBLIC_FIELDS,
17
+ READING_AID_KEYS,
18
+ REVIEW_PROPOSED_LABEL,
19
+ ROOM_PAIRS,
20
+ SPATIAL_TYPES,
21
+ TOOLS,
22
+ doorWhere,
23
+ doorsOf,
24
+ elementAddress,
25
+ fold,
26
+ isAgentDoor,
27
+ isCharterElement,
28
+ isKnownOf,
29
+ isRoomElement,
30
+ openersFor,
31
+ parseOwLink,
32
+ readingAidKey,
33
+ readingAidOf,
34
+ refuseUnknownOptions,
35
+ simpleCaseFold,
36
+ trimWhiteSpace,
37
+ typeWord,
38
+ unknownKey
39
+ } from "./chunk-7E4HPNBS.js";
40
+
1
41
  // src/v2/keyed-id.ts
2
42
  var KEYED_IDS = "0199b6a0-6f0e-7c2a-9d1e-3b5c7a8e4f21";
3
43
  function sha1(msg) {
@@ -56,19 +96,6 @@ function keyedId(idempotencyKey, index) {
56
96
  ${index}`);
57
97
  }
58
98
 
59
- // src/options.ts
60
- function unknownKey(opts, keys) {
61
- if (!opts || typeof opts !== "object") return void 0;
62
- for (const k of Object.keys(opts)) if (!keys.includes(k)) return k;
63
- return void 0;
64
- }
65
- function refuseUnknownOptions(fn, opts, keys, after = "") {
66
- const k = unknownKey(opts, keys);
67
- if (k !== void 0) {
68
- throw new TypeError(`${fn}: unknown option '${k}'. The keys are ${keys.join(", ")}.${after ? ` ${after}` : ""}`);
69
- }
70
- }
71
-
72
99
  // src/v2/errors.ts
73
100
  var OwApiError = class extends Error {
74
101
  constructor(status, code, message, docUrl, detail, type = null, param = null, retryAfter = null) {
@@ -2219,17 +2246,17 @@ function xhrUpload(XHR, url, headers, body, total, onProgress) {
2219
2246
  last = loaded;
2220
2247
  onProgress(loaded, total);
2221
2248
  };
2222
- const fail3 = (why) => () => reject(new OwNetworkError(`OnlyWorlds file upload failed: POST ${url}`, new Error(why)));
2249
+ const fail = (why) => () => reject(new OwNetworkError(`OnlyWorlds file upload failed: POST ${url}`, new Error(why)));
2223
2250
  xhr.open("POST", url);
2224
2251
  for (const [k, v] of Object.entries(headers)) xhr.setRequestHeader(k, v);
2225
2252
  if (xhr.upload) xhr.upload.onprogress = (e) => report(Math.min(e.loaded, total));
2226
- xhr.onerror = fail3("network error");
2227
- xhr.onabort = fail3("aborted");
2228
- xhr.ontimeout = fail3("timed out");
2253
+ xhr.onerror = fail("network error");
2254
+ xhr.onabort = fail("aborted");
2255
+ xhr.ontimeout = fail("timed out");
2229
2256
  xhr.onload = () => {
2230
2257
  const status = xhr.status;
2231
2258
  if (!status) {
2232
- fail3("no answer")();
2259
+ fail("no answer")();
2233
2260
  return;
2234
2261
  }
2235
2262
  const ok = status >= 200 && status < 300;
@@ -2309,826 +2336,6 @@ function buildQuery(params, keepEmpty) {
2309
2336
  return q.toString();
2310
2337
  }
2311
2338
 
2312
- // src/v2/types.generated.ts
2313
- var ELEMENT_TYPES = ["ability", "character", "collective", "construct", "creature", "event", "family", "institution", "language", "law", "location", "map", "marker", "narrative", "object", "phenomenon", "pin", "relation", "species", "title", "trait", "zone"];
2314
- var ONLYWORLDS_VERSION = "00.33.00";
2315
- var ELEMENT_GROUPS = {
2316
- ability: "amber",
2317
- character: "blue",
2318
- collective: "blue",
2319
- construct: "pink",
2320
- creature: "blue",
2321
- event: "amber",
2322
- family: "blue",
2323
- institution: "blue",
2324
- language: "pink",
2325
- law: "pink",
2326
- location: "green",
2327
- map: "green",
2328
- marker: "green",
2329
- narrative: "amber",
2330
- object: "green",
2331
- phenomenon: "amber",
2332
- pin: "green",
2333
- relation: "amber",
2334
- species: "blue",
2335
- title: "pink",
2336
- trait: "pink",
2337
- zone: "green"
2338
- };
2339
- var GROUP_ORDER = ["blue", "green", "pink", "amber"];
2340
- var GROUP_COLORS = {
2341
- blue: { light: "#2a78d6", dark: "#3987e5" },
2342
- green: { light: "#008300", dark: "#008300" },
2343
- pink: { light: "#e87ba4", dark: "#d55181" },
2344
- amber: { light: "#eda100", dark: "#c98500" }
2345
- };
2346
- var ELEMENT_ICONS = {
2347
- ability: "auto_fix_normal",
2348
- character: "person",
2349
- collective: "groups_3",
2350
- construct: "api",
2351
- creature: "bug_report",
2352
- event: "saved_search",
2353
- family: "supervisor_account",
2354
- institution: "account_balance",
2355
- language: "edit_road",
2356
- law: "gpp_bad",
2357
- location: "castle",
2358
- map: "map",
2359
- marker: "polyline",
2360
- narrative: "menu_book",
2361
- object: "webhook",
2362
- phenomenon: "thunderstorm",
2363
- pin: "push_pin",
2364
- relation: "link",
2365
- species: "crib",
2366
- title: "military_tech",
2367
- trait: "flaky",
2368
- zone: "pentagon"
2369
- };
2370
- var PUBLIC_FIELDS = {
2371
- ability: [],
2372
- character: ["physicality", "height", "weight", "species", "reputation"],
2373
- collective: [],
2374
- construct: [],
2375
- creature: [],
2376
- event: [],
2377
- family: [],
2378
- institution: [],
2379
- language: [],
2380
- law: [],
2381
- location: [],
2382
- map: [],
2383
- marker: [],
2384
- narrative: [],
2385
- object: [],
2386
- phenomenon: [],
2387
- pin: [],
2388
- relation: [],
2389
- species: [],
2390
- title: [],
2391
- trait: [],
2392
- zone: []
2393
- };
2394
- var ELEMENT_SECTIONS = {
2395
- ability: [
2396
- { name: "Mechanics", order: 1, fields: ["activation", "duration", "potency", "range", "effects", "challenges", "talents", "requisites"] },
2397
- { name: "World", order: 2, fields: ["prevalence", "tradition", "source", "locus", "instruments", "systems"] }
2398
- ],
2399
- character: [
2400
- { name: "Constitution", order: 1, fields: ["physicality", "mentality", "height", "weight", "species", "traits", "abilities"] },
2401
- { name: "Origins", order: 2, fields: ["background", "motivations", "birth_date", "birthplace", "languages"] },
2402
- { name: "World", order: 3, fields: ["reputation", "location", "objects", "institutions"] },
2403
- { name: "Personality", order: 4, fields: ["charisma", "coercion", "competence", "compassion", "creativity", "courage"] },
2404
- { name: "Social", order: 5, fields: ["family", "friends", "rivals"] },
2405
- { name: "TTRPG", order: 6, fields: ["level", "hit_points", "STR", "DEX", "CON", "INT", "WIS", "CHA"] }
2406
- ],
2407
- collective: [
2408
- { name: "Formation", order: 1, fields: ["composition", "count", "formation_date", "operator", "equipment"] },
2409
- { name: "Dynamics", order: 2, fields: ["activity", "disposition", "state", "abilities", "symbolism"] },
2410
- { name: "World", order: 3, fields: ["species", "characters", "creatures", "phenomena"] }
2411
- ],
2412
- construct: [
2413
- { name: "Nature", order: 1, fields: ["rationale", "history", "status", "reach", "start_date", "end_date", "founder", "custodian"] },
2414
- { name: "Involves", order: 2, fields: ["characters", "objects", "locations", "species", "creatures", "institutions", "traits", "collectives", "zones", "abilities", "phenomena", "languages", "families", "relations", "titles", "constructs", "events", "narratives"] }
2415
- ],
2416
- creature: [
2417
- { name: "Biology", order: 1, fields: ["appearance", "weight", "height", "species"] },
2418
- { name: "Behavior", order: 2, fields: ["habits", "demeanor", "traits", "abilities", "languages"] },
2419
- { name: "World", order: 3, fields: ["status", "birth_date", "location", "zone"] },
2420
- { name: "TTRPG", order: 4, fields: ["challenge_rating", "hit_points", "armor_class", "speed", "actions"] }
2421
- ],
2422
- event: [
2423
- { name: "Nature", order: 1, fields: ["history", "challenges", "consequences", "start_date", "end_date", "triggers"] },
2424
- { name: "Involves", order: 2, fields: ["characters", "objects", "locations", "species", "creatures", "institutions", "traits", "collectives", "zones", "abilities", "phenomena", "languages", "families", "relations", "titles", "constructs"] }
2425
- ],
2426
- family: [
2427
- { name: "Identity", order: 1, fields: ["spirit", "history", "traditions", "traits", "abilities", "languages", "ancestors"] },
2428
- { name: "World", order: 2, fields: ["reputation", "estates", "governs", "heirlooms", "creatures"] }
2429
- ],
2430
- institution: [
2431
- { name: "Foundation", order: 1, fields: ["doctrine", "founding_date", "parent_institution"] },
2432
- { name: "Claims", order: 2, fields: ["zones", "objects", "creatures"] },
2433
- { name: "World", order: 3, fields: ["status", "allies", "adversaries", "constructs"] }
2434
- ],
2435
- language: [
2436
- { name: "Structure", order: 1, fields: ["phonology", "grammar", "lexicon", "writing", "classification"] },
2437
- { name: "World", order: 2, fields: ["status", "spread", "dialects"] }
2438
- ],
2439
- law: [
2440
- { name: "Code", order: 1, fields: ["declaration", "purpose", "date", "parent_law", "penalties"] },
2441
- { name: "World", order: 2, fields: ["author", "locations", "zones", "prohibitions", "adjudicators", "enforcers"] }
2442
- ],
2443
- location: [
2444
- { name: "Setting", order: 1, fields: ["form", "function", "founding_date", "parent_location", "populations"] },
2445
- { name: "Politics", order: 2, fields: ["political_climate", "primary_power", "governing_title", "secondary_powers", "zone", "rival", "partner"] },
2446
- { name: "World", order: 3, fields: ["customs", "founders", "cults", "delicacies"] },
2447
- { name: "Production", order: 4, fields: ["extraction_methods", "extraction_goods", "industry_methods", "industry_goods"] },
2448
- { name: "Commerce", order: 5, fields: ["infrastructure", "extraction_markets", "industry_markets", "currencies"] },
2449
- { name: "Construction", order: 6, fields: ["architecture", "buildings", "building_methods"] },
2450
- { name: "Defense", order: 7, fields: ["defensibility", "elevation", "fighters", "defensive_objects"] }
2451
- ],
2452
- map: [
2453
- { name: "Details", order: 1, fields: ["background_color", "hierarchy", "width", "height", "depth", "parent_map", "location"] }
2454
- ],
2455
- marker: [
2456
- { name: "Details", order: 1, fields: ["map", "zone", "x", "y", "z", "order"] }
2457
- ],
2458
- narrative: [
2459
- { name: "Context", order: 1, fields: ["story", "consequences", "start_date", "end_date", "order", "parent_narrative", "protagonist", "antagonist", "narrator", "conservator"] },
2460
- { name: "Involves", order: 2, fields: ["events", "characters", "objects", "locations", "species", "creatures", "institutions", "traits", "collectives", "zones", "abilities", "phenomena", "languages", "families", "relations", "titles", "constructs", "laws"] }
2461
- ],
2462
- object: [
2463
- { name: "Form", order: 1, fields: ["aesthetics", "weight", "amount", "parent_object", "materials", "technology"] },
2464
- { name: "Function", order: 2, fields: ["utility", "effects", "abilities", "consumes"] },
2465
- { name: "World", order: 3, fields: ["origins", "location", "language", "affinities"] }
2466
- ],
2467
- phenomenon: [
2468
- { name: "Mechanics", order: 1, fields: ["expression", "effects", "duration", "catalysts", "empowerments"] },
2469
- { name: "World", order: 2, fields: ["mythology", "system", "triggers", "wielders", "environments"] }
2470
- ],
2471
- pin: [
2472
- { name: "Details", order: 1, fields: ["map", "element", "x", "y", "z"] }
2473
- ],
2474
- relation: [
2475
- { name: "Nature", order: 1, fields: ["background", "start_date", "end_date", "intensity", "actor", "events"] },
2476
- { name: "Involves", order: 2, fields: ["characters", "objects", "locations", "species", "creatures", "institutions", "traits", "collectives", "zones", "abilities", "phenomena", "languages", "families", "titles", "constructs", "narratives"] }
2477
- ],
2478
- species: [
2479
- { name: "Biology", order: 1, fields: ["appearance", "life_span", "weight", "nourishment", "reproduction", "adaptations"] },
2480
- { name: "Psychology", order: 2, fields: ["instincts", "sociality", "temperament", "communication", "aggression", "traits"] },
2481
- { name: "World", order: 3, fields: ["role", "parent_species", "locations", "zones", "affinities"] }
2482
- ],
2483
- title: [
2484
- { name: "Mandate", order: 1, fields: ["authority", "eligibility", "grant_date", "revoke_date", "issuer", "body", "superior_title", "holders", "symbols"] },
2485
- { name: "World", order: 2, fields: ["status", "history", "characters", "institutions", "families", "zones", "locations", "objects", "constructs", "laws", "collectives", "creatures", "phenomena", "species", "languages"] }
2486
- ],
2487
- trait: [
2488
- { name: "Qualitative", order: 1, fields: ["social_effects", "physical_effects", "functional_effects", "personality_effects", "behaviour_effects"] },
2489
- { name: "Quantitative", order: 2, fields: ["charisma", "coercion", "competence", "compassion", "creativity", "courage"] },
2490
- { name: "World", order: 3, fields: ["significance", "anti_trait", "empowered_abilities"] }
2491
- ],
2492
- zone: [
2493
- { name: "Scope", order: 1, fields: ["role", "shape", "start_date", "end_date", "phenomena", "linked_zones"] },
2494
- { name: "World", order: 2, fields: ["context", "populations", "titles", "principles"] }
2495
- ]
2496
- };
2497
- var ROOM_PAIRS = [
2498
- { type: "narrative", supertype: "Message" },
2499
- { type: "narrative", supertype: "Board" },
2500
- { type: "relation", supertype: "Work item" },
2501
- { type: "construct", supertype: "Spec" },
2502
- { type: "relation", supertype: "Heart" },
2503
- { type: "relation", supertype: "Take" },
2504
- { type: "relation", supertype: "Vote" },
2505
- { type: "event", supertype: "Sitting" },
2506
- { type: "character", supertype: "Member" }
2507
- ];
2508
- var ROOM_MARK = "x_room_of";
2509
- var READING_AID_PAIRS = [
2510
- { type: "law", supertype: "charter" },
2511
- { type: "construct", supertype: "guide" },
2512
- { type: "construct", supertype: "domain" }
2513
- ];
2514
- var READING_AID_MARK = "x_charter_of";
2515
- var CHARTER_PAIRS = [
2516
- { type: "law", supertype: "Charter", aid: "charter" },
2517
- { type: "construct", supertype: "Guide", aid: "guide" },
2518
- { type: "construct", supertype: "Domain", aid: "domain" }
2519
- ];
2520
- var REVIEW_PROPOSED_LABEL = "proposed, not yet reviewed";
2521
- var MESSAGE_PAIR = { type: "narrative", supertype: "Message" };
2522
- var MESSAGE_READ_MARK = {
2523
- type: "relation",
2524
- supertype: "Read",
2525
- readerField: "actor",
2526
- messagesField: "narratives"
2527
- };
2528
- var NOTE_PAIR = { type: "narrative", supertype: "Note" };
2529
- var FIELD_SCHEMA = {
2530
- ability: {
2531
- // Base fields (shared by all elements)
2532
- name: { type: "text", required: true },
2533
- description: { type: "text", required: false },
2534
- supertype: { type: "text", required: false },
2535
- subtype: { type: "text", required: false },
2536
- image_url: { type: "text", required: false },
2537
- // Mechanics
2538
- activation: { type: "text" },
2539
- duration: { type: "integer" },
2540
- potency: { type: "integer" },
2541
- range: { type: "integer" },
2542
- effects: { type: "multi_link", target: "phenomenon" },
2543
- challenges: { type: "text" },
2544
- talents: { type: "multi_link", target: "trait" },
2545
- requisites: { type: "multi_link", target: "construct" },
2546
- // World
2547
- prevalence: { type: "text" },
2548
- tradition: { type: "single_link", target: "construct" },
2549
- source: { type: "single_link", target: "phenomenon" },
2550
- locus: { type: "single_link", target: "location" },
2551
- instruments: { type: "multi_link", target: "object" },
2552
- systems: { type: "multi_link", target: "construct" }
2553
- },
2554
- character: {
2555
- // Base fields (shared by all elements)
2556
- name: { type: "text", required: true },
2557
- description: { type: "text", required: false },
2558
- supertype: { type: "text", required: false },
2559
- subtype: { type: "text", required: false },
2560
- image_url: { type: "text", required: false },
2561
- // Constitution
2562
- physicality: { type: "text" },
2563
- mentality: { type: "text" },
2564
- height: { type: "integer" },
2565
- weight: { type: "integer" },
2566
- species: { type: "multi_link", target: "species" },
2567
- traits: { type: "multi_link", target: "trait" },
2568
- abilities: { type: "multi_link", target: "ability" },
2569
- // Origins
2570
- background: { type: "text" },
2571
- motivations: { type: "text" },
2572
- birth_date: { type: "integer" },
2573
- birthplace: { type: "single_link", target: "location" },
2574
- languages: { type: "multi_link", target: "language" },
2575
- // World
2576
- reputation: { type: "text" },
2577
- location: { type: "single_link", target: "location" },
2578
- objects: { type: "multi_link", target: "object" },
2579
- institutions: { type: "multi_link", target: "institution" },
2580
- // Personality
2581
- charisma: { type: "integer" },
2582
- coercion: { type: "integer" },
2583
- competence: { type: "integer" },
2584
- compassion: { type: "integer" },
2585
- creativity: { type: "integer" },
2586
- courage: { type: "integer" },
2587
- // Social
2588
- family: { type: "multi_link", target: "family" },
2589
- friends: { type: "multi_link", target: "character" },
2590
- rivals: { type: "multi_link", target: "character" },
2591
- // TTRPG
2592
- level: { type: "integer" },
2593
- hit_points: { type: "integer" },
2594
- STR: { type: "integer" },
2595
- DEX: { type: "integer" },
2596
- CON: { type: "integer" },
2597
- INT: { type: "integer" },
2598
- WIS: { type: "integer" },
2599
- CHA: { type: "integer" }
2600
- },
2601
- collective: {
2602
- // Base fields (shared by all elements)
2603
- name: { type: "text", required: true },
2604
- description: { type: "text", required: false },
2605
- supertype: { type: "text", required: false },
2606
- subtype: { type: "text", required: false },
2607
- image_url: { type: "text", required: false },
2608
- // Formation
2609
- composition: { type: "text" },
2610
- count: { type: "integer" },
2611
- formation_date: { type: "integer" },
2612
- operator: { type: "single_link", target: "institution" },
2613
- equipment: { type: "multi_link", target: "object" },
2614
- // Dynamics
2615
- activity: { type: "text" },
2616
- disposition: { type: "text" },
2617
- state: { type: "text" },
2618
- abilities: { type: "multi_link", target: "ability" },
2619
- symbolism: { type: "multi_link", target: "construct" },
2620
- // World
2621
- species: { type: "multi_link", target: "species" },
2622
- characters: { type: "multi_link", target: "character" },
2623
- creatures: { type: "multi_link", target: "creature" },
2624
- phenomena: { type: "multi_link", target: "phenomenon" }
2625
- },
2626
- construct: {
2627
- // Base fields (shared by all elements)
2628
- name: { type: "text", required: true },
2629
- description: { type: "text", required: false },
2630
- supertype: { type: "text", required: false },
2631
- subtype: { type: "text", required: false },
2632
- image_url: { type: "text", required: false },
2633
- // Nature
2634
- rationale: { type: "text" },
2635
- history: { type: "text" },
2636
- status: { type: "text" },
2637
- reach: { type: "text" },
2638
- start_date: { type: "integer" },
2639
- end_date: { type: "integer" },
2640
- founder: { type: "single_link", target: "character" },
2641
- custodian: { type: "single_link", target: "institution" },
2642
- // Involves
2643
- characters: { type: "multi_link", target: "character" },
2644
- objects: { type: "multi_link", target: "object" },
2645
- locations: { type: "multi_link", target: "location" },
2646
- species: { type: "multi_link", target: "species" },
2647
- creatures: { type: "multi_link", target: "creature" },
2648
- institutions: { type: "multi_link", target: "institution" },
2649
- traits: { type: "multi_link", target: "trait" },
2650
- collectives: { type: "multi_link", target: "collective" },
2651
- zones: { type: "multi_link", target: "zone" },
2652
- abilities: { type: "multi_link", target: "ability" },
2653
- phenomena: { type: "multi_link", target: "phenomenon" },
2654
- languages: { type: "multi_link", target: "language" },
2655
- families: { type: "multi_link", target: "family" },
2656
- relations: { type: "multi_link", target: "relation" },
2657
- titles: { type: "multi_link", target: "title" },
2658
- constructs: { type: "multi_link", target: "construct" },
2659
- events: { type: "multi_link", target: "event" },
2660
- narratives: { type: "multi_link", target: "narrative" }
2661
- },
2662
- creature: {
2663
- // Base fields (shared by all elements)
2664
- name: { type: "text", required: true },
2665
- description: { type: "text", required: false },
2666
- supertype: { type: "text", required: false },
2667
- subtype: { type: "text", required: false },
2668
- image_url: { type: "text", required: false },
2669
- // Biology
2670
- appearance: { type: "text" },
2671
- weight: { type: "integer" },
2672
- height: { type: "integer" },
2673
- species: { type: "multi_link", target: "species" },
2674
- // Behavior
2675
- habits: { type: "text" },
2676
- demeanor: { type: "text" },
2677
- traits: { type: "multi_link", target: "trait" },
2678
- abilities: { type: "multi_link", target: "ability" },
2679
- languages: { type: "multi_link", target: "language" },
2680
- // World
2681
- status: { type: "text" },
2682
- birth_date: { type: "integer" },
2683
- location: { type: "single_link", target: "location" },
2684
- zone: { type: "single_link", target: "zone" },
2685
- // TTRPG
2686
- challenge_rating: { type: "integer" },
2687
- hit_points: { type: "integer" },
2688
- armor_class: { type: "integer" },
2689
- speed: { type: "integer" },
2690
- actions: { type: "multi_link", target: "ability" }
2691
- },
2692
- event: {
2693
- // Base fields (shared by all elements)
2694
- name: { type: "text", required: true },
2695
- description: { type: "text", required: false },
2696
- supertype: { type: "text", required: false },
2697
- subtype: { type: "text", required: false },
2698
- image_url: { type: "text", required: false },
2699
- // Nature
2700
- history: { type: "text" },
2701
- challenges: { type: "text" },
2702
- consequences: { type: "text" },
2703
- start_date: { type: "integer" },
2704
- end_date: { type: "integer" },
2705
- triggers: { type: "multi_link", target: "event" },
2706
- // Involves
2707
- characters: { type: "multi_link", target: "character" },
2708
- objects: { type: "multi_link", target: "object" },
2709
- locations: { type: "multi_link", target: "location" },
2710
- species: { type: "multi_link", target: "species" },
2711
- creatures: { type: "multi_link", target: "creature" },
2712
- institutions: { type: "multi_link", target: "institution" },
2713
- traits: { type: "multi_link", target: "trait" },
2714
- collectives: { type: "multi_link", target: "collective" },
2715
- zones: { type: "multi_link", target: "zone" },
2716
- abilities: { type: "multi_link", target: "ability" },
2717
- phenomena: { type: "multi_link", target: "phenomenon" },
2718
- languages: { type: "multi_link", target: "language" },
2719
- families: { type: "multi_link", target: "family" },
2720
- relations: { type: "multi_link", target: "relation" },
2721
- titles: { type: "multi_link", target: "title" },
2722
- constructs: { type: "multi_link", target: "construct" }
2723
- },
2724
- family: {
2725
- // Base fields (shared by all elements)
2726
- name: { type: "text", required: true },
2727
- description: { type: "text", required: false },
2728
- supertype: { type: "text", required: false },
2729
- subtype: { type: "text", required: false },
2730
- image_url: { type: "text", required: false },
2731
- // Identity
2732
- spirit: { type: "text" },
2733
- history: { type: "text" },
2734
- traditions: { type: "multi_link", target: "construct" },
2735
- traits: { type: "multi_link", target: "trait" },
2736
- abilities: { type: "multi_link", target: "ability" },
2737
- languages: { type: "multi_link", target: "language" },
2738
- ancestors: { type: "multi_link", target: "character" },
2739
- // World
2740
- reputation: { type: "text" },
2741
- estates: { type: "multi_link", target: "location" },
2742
- governs: { type: "multi_link", target: "institution" },
2743
- heirlooms: { type: "multi_link", target: "object" },
2744
- creatures: { type: "multi_link", target: "creature" }
2745
- },
2746
- institution: {
2747
- // Base fields (shared by all elements)
2748
- name: { type: "text", required: true },
2749
- description: { type: "text", required: false },
2750
- supertype: { type: "text", required: false },
2751
- subtype: { type: "text", required: false },
2752
- image_url: { type: "text", required: false },
2753
- // Foundation
2754
- doctrine: { type: "text" },
2755
- founding_date: { type: "integer" },
2756
- parent_institution: { type: "single_link", target: "institution" },
2757
- // Claims
2758
- zones: { type: "multi_link", target: "zone" },
2759
- objects: { type: "multi_link", target: "object" },
2760
- creatures: { type: "multi_link", target: "creature" },
2761
- // World
2762
- status: { type: "text" },
2763
- allies: { type: "multi_link", target: "institution" },
2764
- adversaries: { type: "multi_link", target: "institution" },
2765
- constructs: { type: "multi_link", target: "construct" }
2766
- },
2767
- language: {
2768
- // Base fields (shared by all elements)
2769
- name: { type: "text", required: true },
2770
- description: { type: "text", required: false },
2771
- supertype: { type: "text", required: false },
2772
- subtype: { type: "text", required: false },
2773
- image_url: { type: "text", required: false },
2774
- // Structure
2775
- phonology: { type: "text" },
2776
- grammar: { type: "text" },
2777
- lexicon: { type: "text" },
2778
- writing: { type: "text" },
2779
- classification: { type: "single_link", target: "construct" },
2780
- // World
2781
- status: { type: "text" },
2782
- spread: { type: "multi_link", target: "location" },
2783
- dialects: { type: "multi_link", target: "language" }
2784
- },
2785
- law: {
2786
- // Base fields (shared by all elements)
2787
- name: { type: "text", required: true },
2788
- description: { type: "text", required: false },
2789
- supertype: { type: "text", required: false },
2790
- subtype: { type: "text", required: false },
2791
- image_url: { type: "text", required: false },
2792
- // Code
2793
- declaration: { type: "text" },
2794
- purpose: { type: "text" },
2795
- date: { type: "integer" },
2796
- parent_law: { type: "single_link", target: "law" },
2797
- penalties: { type: "multi_link", target: "construct" },
2798
- // World
2799
- author: { type: "single_link", target: "institution" },
2800
- locations: { type: "multi_link", target: "location" },
2801
- zones: { type: "multi_link", target: "zone" },
2802
- prohibitions: { type: "multi_link", target: "construct" },
2803
- adjudicators: { type: "multi_link", target: "title" },
2804
- enforcers: { type: "multi_link", target: "title" }
2805
- },
2806
- location: {
2807
- // Base fields (shared by all elements)
2808
- name: { type: "text", required: true },
2809
- description: { type: "text", required: false },
2810
- supertype: { type: "text", required: false },
2811
- subtype: { type: "text", required: false },
2812
- image_url: { type: "text", required: false },
2813
- // Setting
2814
- form: { type: "text" },
2815
- function: { type: "text" },
2816
- founding_date: { type: "integer" },
2817
- parent_location: { type: "single_link", target: "location" },
2818
- populations: { type: "multi_link", target: "collective" },
2819
- // Politics
2820
- political_climate: { type: "text" },
2821
- primary_power: { type: "single_link", target: "institution" },
2822
- governing_title: { type: "single_link", target: "title" },
2823
- secondary_powers: { type: "multi_link", target: "institution" },
2824
- zone: { type: "single_link", target: "zone" },
2825
- rival: { type: "single_link", target: "location" },
2826
- partner: { type: "single_link", target: "location" },
2827
- // World
2828
- customs: { type: "text" },
2829
- founders: { type: "multi_link", target: "character" },
2830
- cults: { type: "multi_link", target: "construct" },
2831
- delicacies: { type: "multi_link", target: "species" },
2832
- // Production
2833
- extraction_methods: { type: "multi_link", target: "construct" },
2834
- extraction_goods: { type: "multi_link", target: "construct" },
2835
- industry_methods: { type: "multi_link", target: "construct" },
2836
- industry_goods: { type: "multi_link", target: "construct" },
2837
- // Commerce
2838
- infrastructure: { type: "text" },
2839
- extraction_markets: { type: "multi_link", target: "location" },
2840
- industry_markets: { type: "multi_link", target: "location" },
2841
- currencies: { type: "multi_link", target: "construct" },
2842
- // Construction
2843
- architecture: { type: "text" },
2844
- buildings: { type: "multi_link", target: "object" },
2845
- building_methods: { type: "multi_link", target: "construct" },
2846
- // Defense
2847
- defensibility: { type: "text" },
2848
- elevation: { type: "integer" },
2849
- fighters: { type: "multi_link", target: "construct" },
2850
- defensive_objects: { type: "multi_link", target: "object" }
2851
- },
2852
- map: {
2853
- // Base fields (shared by all elements)
2854
- name: { type: "text", required: true },
2855
- description: { type: "text", required: false },
2856
- supertype: { type: "text", required: false },
2857
- subtype: { type: "text", required: false },
2858
- image_url: { type: "text", required: false },
2859
- // Details
2860
- background_color: { type: "text" },
2861
- hierarchy: { type: "integer" },
2862
- width: { type: "integer" },
2863
- height: { type: "integer" },
2864
- depth: { type: "integer" },
2865
- parent_map: { type: "single_link", target: "map" },
2866
- location: { type: "single_link", target: "location" }
2867
- },
2868
- marker: {
2869
- // Base fields (shared by all elements)
2870
- name: { type: "text", required: true },
2871
- description: { type: "text", required: false },
2872
- supertype: { type: "text", required: false },
2873
- subtype: { type: "text", required: false },
2874
- image_url: { type: "text", required: false },
2875
- // Details
2876
- map: { type: "single_link", target: "map" },
2877
- zone: { type: "single_link", target: "zone" },
2878
- x: { type: "integer" },
2879
- y: { type: "integer" },
2880
- z: { type: "integer" },
2881
- order: { type: "integer" }
2882
- },
2883
- narrative: {
2884
- // Base fields (shared by all elements)
2885
- name: { type: "text", required: true },
2886
- description: { type: "text", required: false },
2887
- supertype: { type: "text", required: false },
2888
- subtype: { type: "text", required: false },
2889
- image_url: { type: "text", required: false },
2890
- // Context
2891
- story: { type: "text" },
2892
- consequences: { type: "text" },
2893
- start_date: { type: "integer" },
2894
- end_date: { type: "integer" },
2895
- order: { type: "integer" },
2896
- parent_narrative: { type: "single_link", target: "narrative" },
2897
- protagonist: { type: "single_link", target: "character" },
2898
- antagonist: { type: "single_link", target: "character" },
2899
- narrator: { type: "single_link", target: "character" },
2900
- conservator: { type: "single_link", target: "institution" },
2901
- // Involves
2902
- events: { type: "multi_link", target: "event" },
2903
- characters: { type: "multi_link", target: "character" },
2904
- objects: { type: "multi_link", target: "object" },
2905
- locations: { type: "multi_link", target: "location" },
2906
- species: { type: "multi_link", target: "species" },
2907
- creatures: { type: "multi_link", target: "creature" },
2908
- institutions: { type: "multi_link", target: "institution" },
2909
- traits: { type: "multi_link", target: "trait" },
2910
- collectives: { type: "multi_link", target: "collective" },
2911
- zones: { type: "multi_link", target: "zone" },
2912
- abilities: { type: "multi_link", target: "ability" },
2913
- phenomena: { type: "multi_link", target: "phenomenon" },
2914
- languages: { type: "multi_link", target: "language" },
2915
- families: { type: "multi_link", target: "family" },
2916
- relations: { type: "multi_link", target: "relation" },
2917
- titles: { type: "multi_link", target: "title" },
2918
- constructs: { type: "multi_link", target: "construct" },
2919
- laws: { type: "multi_link", target: "law" }
2920
- },
2921
- object: {
2922
- // Base fields (shared by all elements)
2923
- name: { type: "text", required: true },
2924
- description: { type: "text", required: false },
2925
- supertype: { type: "text", required: false },
2926
- subtype: { type: "text", required: false },
2927
- image_url: { type: "text", required: false },
2928
- // Form
2929
- aesthetics: { type: "text" },
2930
- weight: { type: "integer" },
2931
- amount: { type: "integer" },
2932
- parent_object: { type: "single_link", target: "object" },
2933
- materials: { type: "multi_link", target: "construct" },
2934
- technology: { type: "multi_link", target: "construct" },
2935
- // Function
2936
- utility: { type: "text" },
2937
- effects: { type: "multi_link", target: "phenomenon" },
2938
- abilities: { type: "multi_link", target: "ability" },
2939
- consumes: { type: "multi_link", target: "construct" },
2940
- // World
2941
- origins: { type: "text" },
2942
- location: { type: "single_link", target: "location" },
2943
- language: { type: "single_link", target: "language" },
2944
- affinities: { type: "multi_link", target: "trait" }
2945
- },
2946
- phenomenon: {
2947
- // Base fields (shared by all elements)
2948
- name: { type: "text", required: true },
2949
- description: { type: "text", required: false },
2950
- supertype: { type: "text", required: false },
2951
- subtype: { type: "text", required: false },
2952
- image_url: { type: "text", required: false },
2953
- // Mechanics
2954
- expression: { type: "text" },
2955
- effects: { type: "text" },
2956
- duration: { type: "integer" },
2957
- catalysts: { type: "multi_link", target: "object" },
2958
- empowerments: { type: "multi_link", target: "ability" },
2959
- // World
2960
- mythology: { type: "text" },
2961
- system: { type: "single_link", target: "phenomenon" },
2962
- triggers: { type: "multi_link", target: "construct" },
2963
- wielders: { type: "multi_link", target: "character" },
2964
- environments: { type: "multi_link", target: "location" }
2965
- },
2966
- pin: {
2967
- // Base fields (shared by all elements)
2968
- name: { type: "text", required: true },
2969
- description: { type: "text", required: false },
2970
- supertype: { type: "text", required: false },
2971
- subtype: { type: "text", required: false },
2972
- image_url: { type: "text", required: false },
2973
- // Details
2974
- map: { type: "single_link", target: "map" },
2975
- element_type: { type: "text" },
2976
- element_id: { type: "single_link", target: "any" },
2977
- x: { type: "integer" },
2978
- y: { type: "integer" },
2979
- z: { type: "integer" }
2980
- },
2981
- relation: {
2982
- // Base fields (shared by all elements)
2983
- name: { type: "text", required: true },
2984
- description: { type: "text", required: false },
2985
- supertype: { type: "text", required: false },
2986
- subtype: { type: "text", required: false },
2987
- image_url: { type: "text", required: false },
2988
- // Nature
2989
- background: { type: "text" },
2990
- start_date: { type: "integer" },
2991
- end_date: { type: "integer" },
2992
- intensity: { type: "integer" },
2993
- actor: { type: "single_link", target: "character" },
2994
- events: { type: "multi_link", target: "event" },
2995
- // Involves
2996
- characters: { type: "multi_link", target: "character" },
2997
- objects: { type: "multi_link", target: "object" },
2998
- locations: { type: "multi_link", target: "location" },
2999
- species: { type: "multi_link", target: "species" },
3000
- creatures: { type: "multi_link", target: "creature" },
3001
- institutions: { type: "multi_link", target: "institution" },
3002
- traits: { type: "multi_link", target: "trait" },
3003
- collectives: { type: "multi_link", target: "collective" },
3004
- zones: { type: "multi_link", target: "zone" },
3005
- abilities: { type: "multi_link", target: "ability" },
3006
- phenomena: { type: "multi_link", target: "phenomenon" },
3007
- languages: { type: "multi_link", target: "language" },
3008
- families: { type: "multi_link", target: "family" },
3009
- titles: { type: "multi_link", target: "title" },
3010
- constructs: { type: "multi_link", target: "construct" },
3011
- narratives: { type: "multi_link", target: "narrative" }
3012
- },
3013
- species: {
3014
- // Base fields (shared by all elements)
3015
- name: { type: "text", required: true },
3016
- description: { type: "text", required: false },
3017
- supertype: { type: "text", required: false },
3018
- subtype: { type: "text", required: false },
3019
- image_url: { type: "text", required: false },
3020
- // Biology
3021
- appearance: { type: "text" },
3022
- life_span: { type: "integer" },
3023
- weight: { type: "integer" },
3024
- nourishment: { type: "multi_link", target: "species" },
3025
- reproduction: { type: "multi_link", target: "construct" },
3026
- adaptations: { type: "multi_link", target: "ability" },
3027
- // Psychology
3028
- instincts: { type: "text" },
3029
- sociality: { type: "text" },
3030
- temperament: { type: "text" },
3031
- communication: { type: "text" },
3032
- aggression: { type: "integer" },
3033
- traits: { type: "multi_link", target: "trait" },
3034
- // World
3035
- role: { type: "text" },
3036
- parent_species: { type: "single_link", target: "species" },
3037
- locations: { type: "multi_link", target: "location" },
3038
- zones: { type: "multi_link", target: "zone" },
3039
- affinities: { type: "multi_link", target: "phenomenon" }
3040
- },
3041
- title: {
3042
- // Base fields (shared by all elements)
3043
- name: { type: "text", required: true },
3044
- description: { type: "text", required: false },
3045
- supertype: { type: "text", required: false },
3046
- subtype: { type: "text", required: false },
3047
- image_url: { type: "text", required: false },
3048
- // Mandate
3049
- authority: { type: "text" },
3050
- eligibility: { type: "text" },
3051
- grant_date: { type: "integer" },
3052
- revoke_date: { type: "integer" },
3053
- issuer: { type: "single_link", target: "institution" },
3054
- body: { type: "single_link", target: "institution" },
3055
- superior_title: { type: "single_link", target: "title" },
3056
- holders: { type: "multi_link", target: "character" },
3057
- symbols: { type: "multi_link", target: "object" },
3058
- // World
3059
- status: { type: "text" },
3060
- history: { type: "text" },
3061
- characters: { type: "multi_link", target: "character" },
3062
- institutions: { type: "multi_link", target: "institution" },
3063
- families: { type: "multi_link", target: "family" },
3064
- zones: { type: "multi_link", target: "zone" },
3065
- locations: { type: "multi_link", target: "location" },
3066
- objects: { type: "multi_link", target: "object" },
3067
- constructs: { type: "multi_link", target: "construct" },
3068
- laws: { type: "multi_link", target: "law" },
3069
- collectives: { type: "multi_link", target: "collective" },
3070
- creatures: { type: "multi_link", target: "creature" },
3071
- phenomena: { type: "multi_link", target: "phenomenon" },
3072
- species: { type: "multi_link", target: "species" },
3073
- languages: { type: "multi_link", target: "language" }
3074
- },
3075
- trait: {
3076
- // Base fields (shared by all elements)
3077
- name: { type: "text", required: true },
3078
- description: { type: "text", required: false },
3079
- supertype: { type: "text", required: false },
3080
- subtype: { type: "text", required: false },
3081
- image_url: { type: "text", required: false },
3082
- // Qualitative
3083
- social_effects: { type: "text" },
3084
- physical_effects: { type: "text" },
3085
- functional_effects: { type: "text" },
3086
- personality_effects: { type: "text" },
3087
- behaviour_effects: { type: "text" },
3088
- // Quantitative
3089
- charisma: { type: "integer" },
3090
- coercion: { type: "integer" },
3091
- competence: { type: "integer" },
3092
- compassion: { type: "integer" },
3093
- creativity: { type: "integer" },
3094
- courage: { type: "integer" },
3095
- // World
3096
- significance: { type: "text" },
3097
- anti_trait: { type: "single_link", target: "trait" },
3098
- empowered_abilities: { type: "multi_link", target: "ability" }
3099
- },
3100
- zone: {
3101
- // Base fields (shared by all elements)
3102
- name: { type: "text", required: true },
3103
- description: { type: "text", required: false },
3104
- supertype: { type: "text", required: false },
3105
- subtype: { type: "text", required: false },
3106
- image_url: { type: "text", required: false },
3107
- // Scope
3108
- role: { type: "text" },
3109
- shape: { type: "text" },
3110
- start_date: { type: "integer" },
3111
- end_date: { type: "integer" },
3112
- phenomena: { type: "multi_link", target: "phenomenon" },
3113
- linked_zones: { type: "multi_link", target: "zone" },
3114
- // World
3115
- context: { type: "text" },
3116
- populations: { type: "multi_link", target: "collective" },
3117
- titles: { type: "multi_link", target: "title" },
3118
- principles: { type: "multi_link", target: "construct" }
3119
- }
3120
- };
3121
-
3122
- // src/v2/types.ts
3123
- var SPATIAL_TYPES = ["map", "pin", "marker", "zone"];
3124
- var AGENT_DOORS = ["seat", "mcp", "declared"];
3125
- function isAgentDoor(door) {
3126
- return door != null && AGENT_DOORS.includes(door);
3127
- }
3128
- function isKnownOf(element) {
3129
- return element != null && element.known_of === true;
3130
- }
3131
-
3132
2339
  // src/v2/palette.ts
3133
2340
  function groupOf(type) {
3134
2341
  return ELEMENT_GROUPS[type];
@@ -3167,10 +2374,10 @@ var FIELD_ACRONYMS = Object.freeze([
3167
2374
  ]);
3168
2375
  var ACRONYM_SET = new Set(FIELD_ACRONYMS);
3169
2376
  function fieldLabel(name) {
3170
- return name.split("_").map((word2, i) => {
3171
- const lower = word2.toLowerCase();
2377
+ return name.split("_").map((word, i) => {
2378
+ const lower = word.toLowerCase();
3172
2379
  if (ACRONYM_SET.has(lower)) return lower.toUpperCase();
3173
- if (/[A-Z]/.test(word2) && word2 === word2.toUpperCase()) return word2;
2380
+ if (/[A-Z]/.test(word) && word === word.toUpperCase()) return word;
3174
2381
  return i === 0 ? lower.charAt(0).toUpperCase() + lower.slice(1) : lower;
3175
2382
  }).join(" ");
3176
2383
  }
@@ -3241,1075 +2448,351 @@ function getElementLabel(elementType) {
3241
2448
  return ELEMENT_LABELS[elementType];
3242
2449
  }
3243
2450
 
3244
- // src/world-file.ts
3245
- import { Inflate, inflateSync, zipSync } from "fflate";
3246
-
3247
- // src/nfc-tables.generated.ts
3248
- var NFC_CLASS_RUNS = "lc.l.6e,lx..6g,ly.4.64,m2..6g,m3..60,m4.5.64,m9.2.5m,mb.4.64,mf.2.5m,mh.b.64,ms.5.1,mx.4.64,n1.8.6e,n9..6o,na..6e,nb.3.64,ne.3.6e,nh.2.64,nk.3.6e,nn.4.64,nr..6e,ns..6g,nt.2.64,nv..6e,nw..6h,nx.2.6i,nz..6h,o0.2.6i,o2..6h,o3.d.6e,w3.5.6e,13l..64,13m.4.6e,13q..64,13r.3.6e,13u..66,13v..64,13w.6.6e,142.6.64,148.2.6e,14a..64,14b.2.6e,14d..66,14e..6c,14f..6e,14g..a,14h..b,14i..c,14j..d,14k..e,14l..f,14m..g,14n..h,14o..i,14p.2.j,14r..k,14s..l,14t..m,14v..n,14x..o,14y..p,150..6e,151..64,153..i,174.8.6e,17c..u,17d..v,17e..w,18r..r,18s..s,18t..t,18u..u,18v..v,18w..w,18x..x,18y..y,18z.2.6e,191.2.64,193.5.6e,198..64,199.2.6e,19b..64,19s..z,1cm.7.6e,1cv.4.6e,1cz..64,1d0..6e,1d3.2.6e,1d6..64,1d7.2.6e,1d9..64,1e9..10,1f4..6e,1f5..64,1f6.2.6e,1f8..64,1f9.2.6e,1fb.3.64,1fe..6e,1ff.2.64,1fh..6e,1fi..64,1fj.3.6e,1fm..64,1fn..6e,1fo..64,1fp..6e,1fq..64,1fr..6e,1fs..64,1ft.2.6e,1kb.7.6e,1ki..64,1kj..6e,1kt..64,1li.4.6e,1ln.9.6e,1lx.3.6e,1m1.5.6e,1nd.3.64,1p4..6e,1p5.3.64,1p8.4.6e,1qi.5.6e,1qn.5.64,1qs.e.6e,1r7..64,1r8.2.6e,1ra..64,1rb.2.6e,1rd..64,1re.3.6e,1rh.3.64,1rk..r,1rl..s,1rm..t,1rn.3.6e,1rq..64,1rr.2.6e,1rt.2.64,1rv.5.6e,1to..7,1u5..9,1u9..6e,1ua..64,1ub.2.6e,1x8..7,1xp..9,1z2..6e,20s..7,219..9,24c..7,24t..9,27w..7,28d..9,2bx..9,2f0..7,2fh..9,2fp..2c,2fq..2j,2ik..7,2j1..9,2m3.2.9,2ml..9,2q2..9,2t4.2.2v,2t6..9,2tk.4.2z,2wo.2.3a,2wq..9,2x4.4.3e,2zc.2.64,305..64,307..64,309..60,31t..3l,31u..3m,31w..3o,322.4.3m,328..3m,32a.2.6e,32c..9,32e.2.6e,346..64,37b..7,37d.2.9,39p..64,3tp.3.6e,4k4.2.9,4l0..9,4pe..9,4pp..6e,4vd..6c,4zd..66,4ze..6e,4zf..64,55j..6e,55k..64,57k..9,585.8.6e,58f..64,59s.5.6e,59x.6.64,5a3.2.6e,5a5..64,5a7.2.64,5a9.2.6e,5ab.2.64,5ad.5.6e,5ai..64,5aj.4.6e,5dg..7,5dw..9,5ez..6e,5f0..64,5f1.7.6e,5gq.2.9,5ie..7,5iq.2.9,5kn..7,5ow.3.6e,5p0..1,5p1.5.64,5p6.2.6e,5p8.4.64,5pc..6e,5pe.7.1,5pp..64,5pw..6e,5q0.2.6e,5vk.2.6e,5vm..64,5vn.7.6e,5vu..64,5vv.2.6e,5vx..6i,5vy..5y,5vz..64,5w0..5m,5w1.11.6e,5x2..6g,5x3.2.6c,5x5..64,5x6..62,5x7..6e,5x8..6h,5x9..64,5xa..6e,5xb..64,6hc.2.6e,6he.2.1,6hg.4.6e,6hk.3.1,6hn.2.6e,6ht..6e,6hx.2.1,6hz..6e,6i0..64,6i1..6e,6i2.2.1,6i4.4.64,6i8..6e,8vj.3.6e,8zj..9,928.w.6e,9ii..62,9ij..6c,9ik..6g,9il..66,9im.2.68,9ll.2.8,wvj..6e,wvo.a.6e,wwu.2.6e,wz4.2.6e,x6u..9,x7w..9,xc4..9,xcw.i.6e,xez.3.64,xg3..9,xir..7,xj4..9,xps..6e,xpu.2.6e,xpw..64,xpz.2.6e,xq6.2.6e,xq9..6e,xrq..9,xyl..9,1dlq..q,1e74.7.6e,1e7b.7.64,1e7i.2.6e,1eyl..64,1f4w..64,1f92.5.6e,1gjx..64,1gjz..6e,1gl4..6e,1gl5..1,1gl6..64,1glb..9,1gpx..6e,1gpy..64,1h5w.4.6e,1hgr.2.6e,1hj1.3.64,1hl2.2.64,1hl4.3.6e,1hl7..64,1hl8..6e,1hl9.4.64,1hmq..6e,1hmr..64,1hms..6e,1hmt..64,1hs6..9,1htc..9,1htr..9,1hvd..9,1hve..7,1hxc.3.6e,1hyr.2.9,1i0j..7,1i2o..9,1i2y..7,1i5x..9,1i5y..7,1iax..7,1iay..9,1id7.2.7,1idp..9,1iee.7.6e,1ieo.5.6e,1iki..9,1ikm..7,1ila..6e,1io2..9,1io3..7,1iv3..9,1iv4..7,1iyn..9,1j1y..9,1j1z..7,1j57..9,1jcp..9,1jcq..7,1jjx.2.9,1jk3..7,1jog..9,1jqs..9,1jrb..9,1jtl..9,1k5b..9,1kci..7,1kck.2.9,1kev..9,1kqp.2.9,1zow.5.1,1zqo.7.6e,20og.2.6,2ftq..1,2jxh.2.60,2jxj.3.1,2jxp..6a,2jxq.5.60,2jy3.8.64,2jyd.5.6e,2jyi.2.64,2jze.4.6e,2k3m.3.6e,2mtc.7.6e,2mtk.h.6e,2mu3.7.6e,2mub.2.6e,2mue.5.6e,2mxb..6e,2n1s.7.6e,2nce..6e,2ne4.4.6e,2nsc.2.6g,2nse..64,2nsf..6e,2ok0.7.64,2on8.6.6e,2one..7";
3249
- var NFC_DECOMP = "5c.1t.lc,1.1t.ld,1.1t.le,1.1t.lf,1.1t.lk,1.1t.lm,2.1v.mf,1.1x.lc,1.1x.ld,1.1x.le,1.1x.lk,1.21.lc,1.21.ld,1.21.le,1.21.lk,2.26.lf,1.27.lc,1.27.ld,1.27.le,1.27.lf,1.27.lk,3.2d.lc,1.2d.ld,1.2d.le,1.2d.lk,1.2h.ld,3.2p.lc,1.2p.ld,1.2p.le,1.2p.lf,1.2p.lk,1.2p.lm,2.2r.mf,1.2t.lc,1.2t.ld,1.2t.le,1.2t.lk,1.2x.lc,1.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,1.tz.lk,3.t4.lg,1.u0.lg,1.t4.lk,1.u0.lk,1.ta.lk,1.u6.lk,3.yw.lk,1.yx.lk,1.tp.lk,1.ul.lk,1.tf.lg,1.ub.lg,1.tf.lk,1.ub.lk,1.tf.ln,1.ub.ln,1.tj.lk,1.uf.lk,3.tn.lk,1.uj.lk,89.17r.18z,1.17r.190,1.18o.190,1.17r.191,1.18q.190,4a.1cl.190,2.1c1.190,h.1ci.190,gm.1t4.1to,8.1tc.1to,3.1tf.1to,10.1sl.1to,1.1sm.1to,1.1sn.1to,1.1ss.1to,1.1sx.1to,1.1sy.1to,1.1t7.1to,1.1tb.1to,30.1xj.1xa,1.1xj.1xz,g.1wh.1x8,1.1wi.1x8,2.1wv.1x8,2c.20i.20s,3.20o.20s,z.1zq.20s,1.1zr.20s,1.1zw.20s,3.20b.20s,6i.287.28m,3.287.27y,1.287.28n,g.275.27w,1.276.27w,1j.2aa.2c7,1i.2bq.2bi,1.2br.2bi,1.2bq.2c7,3g.2fa.2fq,3c.2in.2j9,7.2iu.2j9,1.2iu.2ja,2.2iu.2iq,1.2iy.2j9,3j.2me.2m6,1.2mf.2m6,1.2me.2mv,3y.2qh.2q2,2.2qh.2q7,1.2qk.2q2,1.2qh.2qn,9x.30i.33r,a.30s.33r,5.30x.33r,5.312.33r,5.317.33r,d.30g.33p,a.31t.31u,2.31t.31w,1.33m.328,2.33n.328,9.31t.328,i.32q.33r,a.330.33r,5.335.33r,5.33a.33r,5.33f.33r,d.32o.33p,31.36t.372,25c.5c5.5dh,2.5c7.5dh,2.5c9.5dh,2.5cb.5dh,2.5cd.5dh,4.5ch.5dh,15.5dm.5dh,2.5do.5dh,3.5dq.5dh,1.5dr.5dh,2.5du.5dh,jh.1t.md,1.2p.md,1.1u.lj,1.2q.lj,1.1u.mb,1.2q.mb,1.1u.mp,1.2q.mp,1.5j.ld,1.6f.ld,1.1w.lj,1.2s.lj,1.1w.mb,1.2s.mb,1.1w.mp,1.2s.mp,1.1w.mf,1.2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c,1.65l.lc,1.65k.ld,1.65l.ld,1.65k.n6,1.65l.n6,1.qh.lv,1.qh.lw,1.65s.lc,1.65t.lc,1.65s.ld,1.65t.ld,1.65s.n6,1.65t.n6,1.pl.lv,1.pl.lw,1.660.lc,1.661.lc,1.660.ld,1.661.ld,1.660.n6,1.661.n6,1.qn.lv,1.qn.lw,1.668.lc,1.669.lc,1.668.ld,1.669.ld,3.pr.lv,1.pr.lw,1.66g.lc,1.66h.lc,1.66g.ld,1.66h.ld,3.qt.lv,1.qt.lw,1.66o.lc,1.66p.lc,1.66o.ld,1.66p.ld,1.66o.n6,1.66p.n6,2.px.lw,2.66x.lc,2.66x.ld,2.66x.n6,1.qx.lv,1.qx.lw,1.674.lc,1.675.lc,1.674.ld,1.675.ld,1.674.n6,1.675.n6,1.q1.lv,1.q1.lw,1.67c.lc,1.67d.lc,1.67c.ld,1.67d.ld,1.67c.n6,1.67d.n6,1.q9.lc,1.q4,1.qd.lc,1.q5,1.qf.lc,1.q6,1.qh.lc,1.q7,1.qn.lc,1.r0,1.qt.lc,1.r1,1.qx.lc,1.r2,3.64g.n9,1.64h.n9,1.64i.n9,1.64j.n9,1.64k.n9,1.64l.n9,1.64m.n9,1.64n.n9,1.64o.n9,1.64p.n9,1.64q.n9,1.64r.n9,1.64s.n9,1.64t.n9,1.64u.n9,1.64v.n9,1.65c.n9,1.65d.n9,1.65e.n9,1.65f.n9,1.65g.n9,1.65h.n9,1.65i.n9,1.65j.n9,1.65k.n9,1.65l.n9,1.65m.n9,1.65n.n9,1.65o.n9,1.65p.n9,1.65q.n9,1.65r.n9,1.674.n9,1.675.n9,1.676.n9,1.677.n9,1.678.n9,1.679.n9,1.67a.n9,1.67b.n9,1.67c.n9,1.67d.n9,1.67e.n9,1.67f.n9,1.67g.n9,1.67h.n9,1.67i.n9,1.67j.n9,1.q9.li,1.q9.lg,1.67k.n9,1.q9.n9,1.q4.n9,2.q9.n6,1.69i.n9,1.pd.li,1.pd.lg,1.pd.lc,1.p2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1.1dmx.14y,1.15c.14n,1.15c.14o,1.15c.14s,1.15d.14s,1.15e.14s,1.15f.14s,1.15g.14s,1.15h.14s,1.15i.14s,2.15k.14s,1.15l.14s,1.15m.14s,1.15n.14s,1.15o.14s,2.15q.14s,2.15s.14s,1.15t.14s,2.15v.14s,1.15w.14s,2.15y.14s,1.15z.14s,1.160.14s,1.161.14s,1.162.14s,1.15h.14p,1.15d.14v,1.15n.14v,1.15w.14v,47g.1huh.1hve,2.1huj.1hve,f.1hut.1hve,3n.1hyp.1hyf,1.1hyq.1hyf,f0.1idj.1ida,1.1idj.1idz,a7.1int.1inu,1.1int.1ink,2.1int.1inx,70.1iuw.1iun,1.1iux.1iun,ot.1jjp.1jjk,10di.2jx3.2jxh,1.2jx4.2jxh,1.2jxb.2jxq,1.2jxb.2jxr,1.2jxb.2jxs,1.2jxb.2jxt,1.2jxb.2jxu,2f.2jzt.2jxh,1.2jzu.2jxh,1.2jzv.2jxq,1.2jzw.2jxq,1.2jzv.2jxr,1.2jzw.2jxr,1m4g.fgd,1.fg8,1.fgh,1.2tcy,1.fog,1.fqm,1.fqz,1.fsy,1.fwa,1.fx5,1.fzb,1.fyn,1.ae6,1.2ud6,1.g25,1.g2c,1.g2s,1.g3b,1.2u58,1.aex,1.g2v,1.g3x,1.2u6j,1.g47,1.g4k,1.fkc,1.g4s,1.g51,1.3ly7,1.g6t,1.g77,1.afz,1.g8r,1.g92,1.gaa,1.gaf,1.ahh,1.gcn,1.gcp,1.gdg,1.ge2,1.ged,1.gee,1.gev,1.gg9,1.ggh,1.ggq,1.ghf,1.ghp,1.ghr,1.ghr,1.ghr,1.2v58,1.m7k,1.gju,1.gkf,1.2vdv,1.gkr,1.gkx,1.gli,1.gpq,1.gmw,1.gnc,1.go8,1.gpu,1.gs6,1.gsw,1.gur,1.gv7,1.gw4,1.gw4,1.gwp,1.gx7,1.gxf,1.gxu,1.h7a,1.gzq,1.h7b,1.h1t,1.h2s,1.g7b,1.hke,1.hce,1.hdg,1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t,1.qll,1.qko,1.qoe,1.qn6,1.qrd,1.qp4,1.qqz,1.qrq,1.dsn,1.qu9,1.qv5,1.dtl,1.qxs,1.qxv,1.3giv,1.r13,1.r1a,1.dv9,1.r22,1.aez,1.3gz2,1.3h46,1.dz2,1.dzb,1.rds,1.rfx,1.rka,1.rpx,1.3hrc,1.rsb,1.rsx,1.rvf,1.rxz,1.3i9b,1.2upw,1.s0b,1.rzw,1.s1c,1.2uvy,1.s7o,1.sag,1.3jki,1.3jl9,1.sk4,1.smp,1.snl,1.3ju6,1.snv,1.svs,1.t07,1.t08,1.sxo,1.t89,1.t91,1.3ksa,1.tjf,1.ej9,1.tkn,1.3l2v,1.eli,1.ts3,1.iia,1.tur,1.3ltx,1.3lzu,1.epa,1.epi,1.u00,1.3mdm,1.er6,1.3mhi,1.u17,1.u17,1.u21,1.3mpi,1.u76,1.eur,1.u95,1.ucn,1.ude,1.uf2,1.ez2,1.3nsg,1.umq,1.uv4,1.v0d,1.f66,1.f71,1.v3b,1.3owe,1.f7c,1.3oxx,1.3p5a,1.3p8x,1.vcr,1.f9y,1.veh,1.vem,1.vet,1.vf3,1.vfa,1.vgb,1.3pxc";
3250
- var NFC_EXCLUDED = "1ug,1uh,1ui,1uj,1uk,1ul,1um,1un,1y4,1y5,1y7,20j,20m,21l,21m,21n,21q,28s,28t,30j,30t,30y,313,318,31l,31y,320,32r,331,336,33b,33g,33t,1dlp,1dlr,1dm2,1dm3,1dm4,1dm5,1dm6,1dm7,1dm8,1dm9,1dma,1dmb,1dmc,1dmd,1dme,1dmg,1dmh,1dmi,1dmj,1dmk,1dmm,1dmo,1dmp,1dmr,1dms,1dmu,1dmv,1dmw,1dmx,1dmy,1dmz,1dn0,1dn1,1dn2,8gs,2jxa,2jxb,2jxc,2jxd,2jxe,2jxf,2jxg,2jzv,2jzw,2jzx,2jzy,2jzz,2k00";
3251
-
3252
- // src/nfc.ts
3253
- var S_BASE = 44032;
3254
- var L_BASE = 4352;
3255
- var V_BASE = 4449;
3256
- var T_BASE = 4519;
3257
- var L_COUNT = 19;
3258
- var V_COUNT = 21;
3259
- var T_COUNT = 28;
3260
- var N_COUNT = V_COUNT * T_COUNT;
3261
- var S_COUNT = L_COUNT * N_COUNT;
3262
- var tables = null;
3263
- function load() {
3264
- const ccc = /* @__PURE__ */ new Map();
3265
- for (const run of NFC_CLASS_RUNS.split(",")) {
3266
- const [start, count, cls] = run.split(".");
3267
- const s = parseInt(start, 36);
3268
- const n = count ? parseInt(count, 36) : 1;
3269
- const c = parseInt(cls, 36);
3270
- for (let k = 0; k < n; k++) ccc.set(s + k, c);
3271
- }
3272
- const raw = /* @__PURE__ */ new Map();
3273
- let cp = 0;
3274
- for (const entry of NFC_DECOMP.split(",")) {
3275
- const [gap, ...to] = entry.split(".");
3276
- cp += parseInt(gap, 36);
3277
- raw.set(cp, to.map((t) => parseInt(t, 36)));
3278
- }
3279
- const excluded = new Set(NFC_EXCLUDED.split(",").map((t) => parseInt(t, 36)));
3280
- const compose = /* @__PURE__ */ new Map();
3281
- for (const [c, to] of raw) {
3282
- if (to.length !== 2 || excluded.has(c) || ccc.has(c) || ccc.has(to[0])) continue;
3283
- compose.set(to[0] * 1114112 + to[1], c);
3284
- }
3285
- const decomp = /* @__PURE__ */ new Map();
3286
- const full = (c) => {
3287
- const done = decomp.get(c);
3288
- if (done) return done;
3289
- const to = raw.get(c);
3290
- if (!to) return [c];
3291
- const out = to.flatMap(full);
3292
- decomp.set(c, out);
3293
- return out;
3294
- };
3295
- for (const c of raw.keys()) full(c);
3296
- return { ccc, decomp, compose };
2451
+ // src/review.ts
2452
+ var PROPOSED_MARK = "x_review_proposed";
2453
+ var DAY = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
2454
+ function todayDay() {
2455
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
3297
2456
  }
3298
- function nfc(text2) {
3299
- let plain = true;
3300
- for (let i = 0; i < text2.length; i++) if (text2.charCodeAt(i) >= 192) {
3301
- plain = false;
3302
- break;
3303
- }
3304
- if (plain) return text2;
3305
- const t = tables ?? (tables = load());
3306
- const cls = (c) => t.ccc.get(c) ?? 0;
3307
- const cps = [];
3308
- for (const ch of text2) {
3309
- const c = ch.codePointAt(0);
3310
- const s = c - S_BASE;
3311
- if (s >= 0 && s < S_COUNT) {
3312
- cps.push(L_BASE + Math.floor(s / N_COUNT), V_BASE + Math.floor(s % N_COUNT / T_COUNT));
3313
- if (s % T_COUNT) cps.push(T_BASE + s % T_COUNT);
3314
- } else {
3315
- const d = t.decomp.get(c);
3316
- if (d) cps.push(...d);
3317
- else cps.push(c);
3318
- }
3319
- }
3320
- for (let i = 1; i < cps.length; i++) {
3321
- const c = cps[i];
3322
- const k = cls(c);
3323
- if (!k) continue;
3324
- let j = i;
3325
- while (j > 0 && cls(cps[j - 1]) > k) {
3326
- cps[j] = cps[j - 1];
3327
- j--;
3328
- }
3329
- cps[j] = c;
3330
- }
3331
- const out = [];
3332
- let starter = -1;
3333
- let last = 0;
3334
- for (const c of cps) {
3335
- const k = cls(c);
3336
- if (starter >= 0 && (out.length - 1 === starter || last !== 0 && last < k)) {
3337
- const a = out[starter];
3338
- let composed;
3339
- const l = a - L_BASE, v = c - V_BASE, s = a - S_BASE, tt = c - T_BASE;
3340
- if (l >= 0 && l < L_COUNT && v >= 0 && v < V_COUNT) composed = S_BASE + (l * V_COUNT + v) * T_COUNT;
3341
- else if (s >= 0 && s < S_COUNT && s % T_COUNT === 0 && tt > 0 && tt < T_COUNT) composed = a + tt;
3342
- else composed = t.compose.get(a * 1114112 + c);
3343
- if (composed !== void 0) {
3344
- out[starter] = composed;
3345
- continue;
3346
- }
3347
- }
3348
- if (k === 0) starter = out.length;
3349
- last = k;
3350
- out.push(c);
3351
- }
3352
- let r = "";
3353
- for (const c of out) r += String.fromCodePoint(c);
3354
- return r;
2457
+ function isPresent(v) {
2458
+ if (v === void 0 || v === null) return false;
2459
+ if (typeof v === "string") return trimWhiteSpace(v) !== "";
2460
+ if (Array.isArray(v)) return v.length > 0;
2461
+ if (typeof v === "object") return Object.keys(v).length > 0;
2462
+ return true;
3355
2463
  }
3356
-
3357
- // src/world-file.ts
3358
- var WORLD_FILE = "world.json";
3359
- var MARKER_NAME = "mimetype";
3360
- var WORLD_FILE_MEDIA_TYPE = "application/vnd.onlyworlds.world+zip";
3361
- var WORLD_FILE_MAX_BYTES = 2 * 1024 ** 3;
3362
- var WORLD_FILE_MAX_ENTRIES = 5e5;
3363
- var MESSAGES = {
3364
- unsafe_path: "The world file holds a path that cannot be written safely.",
3365
- too_big: "The world file is bigger than the budget allows, or a file in it is bigger than it says.",
3366
- too_many: "The world file holds more files than the budget allows.",
3367
- not_a_world: "The file is not a world: it has no readable world.json with an id.",
3368
- more_than_one: "The file holds more than one world.",
3369
- not_openable: "The file is not a zip that can be read.",
3370
- duplicate: "The world file holds two entries with the same name.",
3371
- collision: "The world file holds two names that differ only in case or in how an accent is written.",
3372
- link: "The world file holds a link or a special file.",
3373
- method: "The world file holds an encrypted entry, or one compressed other than stored or deflate.",
3374
- name: "The world file holds a name that some disk cannot hold.",
3375
- marker: "The world file's mimetype entry is not the OnlyWorlds media type."
3376
- };
3377
- var OwWorldFileError = class extends Error {
3378
- constructor(reason, message = MESSAGES[reason]) {
3379
- super(message);
3380
- this.name = "OwWorldFileError";
3381
- this.reason = reason;
2464
+ function proposedMarkOf(element, today) {
2465
+ if (today !== void 0 && (typeof today !== "string" || !DAY.test(today))) {
2466
+ throw new TypeError(`proposedMarkOf: today is a day as YYYY-MM-DD; got ${JSON.stringify(today) ?? String(today)}.`);
3382
2467
  }
3383
- };
3384
- var READ_OPTION_KEYS = ["maxBytes", "maxEntries", "skip"];
3385
- var refuse = (reason, message) => {
3386
- throw new OwWorldFileError(reason, message);
3387
- };
3388
- function pathFault(name) {
3389
- if (name.includes("\\")) return "holds a backslash";
3390
- if (name.startsWith("/")) return "is absolute";
3391
- if (/^[A-Za-z]:/.test(name)) return "names a drive";
3392
- if (name.split("/").some((seg) => seg === "" || seg === "." || seg === "..")) return "has an empty, . or .. segment";
3393
- return null;
2468
+ if (!element || typeof element !== "object") return null;
2469
+ const v = element[PROPOSED_MARK];
2470
+ if (!isPresent(v) || typeof v !== "object" || Array.isArray(v)) return null;
2471
+ const m = v;
2472
+ const by = typeof m.by === "string" && trimWhiteSpace(m.by) ? trimWhiteSpace(m.by) : null;
2473
+ const expires = typeof m.expires === "string" && DAY.test(trimWhiteSpace(m.expires)) ? trimWhiteSpace(m.expires) : null;
2474
+ return { by, expires, lapsed: expires !== null && expires <= (today ?? todayDay()) };
3394
2475
  }
3395
- var RESERVED = /* @__PURE__ */ new Set([
3396
- "CON",
3397
- "PRN",
3398
- "AUX",
3399
- "NUL",
3400
- ...[1, 2, 3, 4, 5, 6, 7, 8, 9].flatMap((i) => [`COM${i}`, `LPT${i}`])
3401
- ]);
3402
- var BAD_CHAR = /[<>:"|?*\p{Cc}]/u;
3403
- function nameFault(name) {
3404
- for (const seg of name.split("/")) {
3405
- if (BAD_CHAR.test(seg)) return `segment ${JSON.stringify(seg)} holds a reserved or control character`;
3406
- if (seg.endsWith(".") || seg.endsWith(" ")) return `segment ${JSON.stringify(seg)} ends in a dot or a space`;
3407
- if (RESERVED.has(seg.split(".")[0].toUpperCase())) return `segment ${JSON.stringify(seg)} is a Windows device name`;
3408
- }
3409
- return null;
2476
+ function handsOnAsProposed(element) {
2477
+ if (!element || typeof element !== "object") return false;
2478
+ return isPresent(element[PROPOSED_MARK]);
3410
2479
  }
3411
- function isJunk(path) {
3412
- return path.split("/").some((seg) => seg === "__MACOSX" || seg === ".DS_Store" || seg === "Thumbs.db");
2480
+
2481
+ // src/message.ts
2482
+ var ADDRESSING_KEYS = ["keyless"];
2483
+ var isBody = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2484
+ var idOf = (v) => v.id;
2485
+ var carries = (v, key) => Object.prototype.hasOwnProperty.call(v, key) && v[key] !== void 0;
2486
+ function matchesPair(el, pair) {
2487
+ if (!isBody(el) || typeof el.type !== "string" || typeof el.supertype !== "string") return false;
2488
+ return fold(el.type) === fold(pair.type) && fold(el.supertype) === fold(pair.supertype);
3413
2489
  }
3414
- var FOLD_RUNS = "1t.q..w,51...lj,5c.n..w,60.7..w,74.o.2.1,8i.3.2.1,8p.8.2.1,96.n.2.1,ag...-3d,ah.3.2.1,an...-7g,ap...5u,aq.2.2.1,au...5q,av...1,ax.2..5p,az...1,b2...27,b3...5m,b4...5n,b5...1,b7...5p,b8...5r,ba...5v,bb...5t,bc...1,bg...5v,bh...5x,bj...5y,bk.3.2.1,bq...62,br...1,bt...62,bw...1,by...62,bz...1,c1.2..61,c3.2.2.1,c7...63,c8...1,cc...1,ck...2,cl...1,cn...2,co...1,cq...2,cr.9.2.1,da.9.2.1,dt...2,du.2.2.1,dy...-2p,dz...-1k,e0.k.2.1,f4...-3m,f6.9.2.1,fu...8bv,fv...1,fx...-4j,fy...8bs,g1...1,g3...-5f,g4...1x,g5...1z,g6.5.2.1,n9...38,og.2.2.1,om...1,ov...38,p2...12,p4.3..11,p8...1s,pa.2..1r,pd.h..w,pv.9..w,qq...1,r3...8,r4...-u,r5...-p,r9...-f,ra...-m,rc.c.2.1,s0...-1i,s1...-1c,s4...-1o,s5...-1s,s7...1,s9...-7,sa...1,sd.3..-3m,sg.g..28,sw.w..w,v4.h.2.1,wa.r.2.1,xs...f,xt.7.2.1,y8.1c.2.1,10x.12..1c,3a8.12..5ls,3bb...5ls,3bh...5ls,3y0.6..-8,5mo...-4su,5mp...-4st,5mq...-4sk,5mr.2..-4si,5mt...-4sj,5mu...-4sc,5mv...-4ro,5mw...r7n,5n4.17..-2bk,5od.3..-2bk,5xc.23.2.1,61n...-1m,61q...-5vj,61s.1c.2.1,64o.8..-8,654.6..-8,65k.8..-8,660.8..-8,66g.6..-8,66x.4.2.-8,67c.8..-8,688.8..-8,68o.8..-8,694.8..-8,69k.2..-8,69m.2..-22,69o...-9,69q...-5j9,6a0.4..-2e,6a4...-9,6ab...-5kz,6ag.2..-8,6ai.2..-2s,6ar...-5kj,6aw.2..-8,6ay.2..-34,6b0...-7,6bc.2..-3k,6be.2..-3i,6bg...-9,6jq...-5st,6ju...-6gv,6jv...-6di,6k2...s,6lc.g..g,6mb...1,792.q..q,8ow.1c..1c,8rk...1,8rm...-8af,8rn...-2xy,8ro...-89z,8rr.3.2.1,8rx...-8bg,8ry...-8al,8rz...-8bj,8s0...-8bi,8s2...1,8s5...1,8se.2..-8cf,8sg.1e.2.1,8vf.2.2.1,8vm...1,wu8.n.2.1,ww0.e.2.1,x0i.7.2.1,x0y.v.2.1,x2x.2.2.1,x31...-r9g,x32.5.2.1,x3f...1,x3h...-wmg,x3k.2.2.1,x3q.a.2.1,x4a...-wn8,x4b...-wnj,x4c...-wnf,x4d...-wn5,x4e...-wn8,x4g...-wlu,x4h...-wmi,x4i...-wlx,x4j...ps,x4k.8.2.1,x50...-1c,x51...-wn7,x52...-raw,x53.2.2.1,x5c...1,x5i.2.2.1,x6d...1,xv4.28..-tzk,1dl1...1,1ee9.q..w,1fcw.14..14,1fhs.10..14,1fn4.b..13,1fng.f..13,1fnw.7..13,1fo4.2..13,1h1c.1f..1s,1jfk.w..w,20cg.w..w,2olc.y..y";
3415
- var foldTable = null;
3416
- function simpleCaseFold(text2) {
3417
- if (!foldTable) {
3418
- foldTable = /* @__PURE__ */ new Map();
3419
- for (const run of FOLD_RUNS.split(",")) {
3420
- const [start, count, stride, delta] = run.split(".");
3421
- const s = parseInt(start, 36);
3422
- const n = count ? parseInt(count, 36) : 1;
3423
- const step = stride ? parseInt(stride, 36) : 1;
3424
- const d = parseInt(delta, 36);
3425
- for (let k = 0; k < n; k++) foldTable.set(s + k * step, s + k * step + d);
3426
- }
2490
+ function keylessOf(fn, options) {
2491
+ if (options !== void 0 && options !== null && !isBody(options)) {
2492
+ throw new TypeError(`${fn}: options is an object, such as { keyless: true }; got ${JSON.stringify(options) ?? typeof options}.`);
3427
2493
  }
3428
- let out = "";
3429
- for (const c of text2) {
3430
- const to = foldTable.get(c.codePointAt(0));
3431
- out += to === void 0 ? c : String.fromCodePoint(to);
2494
+ refuseUnknownOptions(fn, options, ADDRESSING_KEYS);
2495
+ const keyless = isBody(options) ? options.keyless : void 0;
2496
+ if (keyless !== void 0 && typeof keyless !== "boolean") {
2497
+ throw new TypeError(`${fn}: keyless is true or false; got ${JSON.stringify(keyless) ?? typeof keyless}.`);
3432
2498
  }
3433
- return out;
2499
+ return keyless === true;
3434
2500
  }
3435
- function foldName(name) {
3436
- return simpleCaseFold(nfc(name));
2501
+ function characterOf(membership, members) {
2502
+ if (!Array.isArray(members)) return void 0;
2503
+ const row = members.find((m) => isBody(m) && m.id === membership);
2504
+ return row !== void 0 && typeof row.character === "string" && row.character !== "" ? row.character : void 0;
3437
2505
  }
3438
- function byCodePoint(a, b) {
3439
- const n = Math.min(a.length, b.length);
3440
- for (let i = 0; i < n; i++) {
3441
- const x = a.codePointAt(i);
3442
- const y = b.codePointAt(i);
3443
- if (x !== y) return x - y;
3444
- if (x > 65535) i++;
3445
- }
3446
- return a.length - b.length;
2506
+ function handOf(body, members) {
2507
+ return carries(body, "created_by") ? characterOf(body.created_by, members) : void 0;
3447
2508
  }
3448
- var u16 = (b, o) => b[o] | b[o + 1] << 8;
3449
- var u32 = (b, o) => (b[o] | b[o + 1] << 8 | b[o + 2] << 16) + b[o + 3] * 16777216;
3450
- var u64 = (b, o) => u32(b, o) + u32(b, o + 4) * 4294967296;
3451
- var SIG_LOCAL = 67324752;
3452
- var SIG_CENTRAL = 33639248;
3453
- var SIG_END = 101010256;
3454
- var SIG_END64 = 101075792;
3455
- var SIG_LOCATOR64 = 117853008;
3456
- var MAX32 = 4294967295;
3457
- var utf8 = new TextDecoder("utf-8", { fatal: true });
3458
- var latin1 = (b) => {
3459
- let s = "";
3460
- for (const x of b) s += String.fromCharCode(x);
3461
- return s;
3462
- };
3463
- function centralDirectory(bytes) {
3464
- const len = bytes.length;
3465
- let end = -1;
3466
- for (let i = len - 22; i >= Math.max(0, len - 22 - 65535); i--) {
3467
- if (u32(bytes, i) === SIG_END) {
3468
- end = i;
3469
- break;
3470
- }
3471
- }
3472
- if (end < 0) refuse("not_openable", "The file is not a zip: it has no end of central directory.");
3473
- const thisDisk = u16(bytes, end + 4);
3474
- const cdDisk = u16(bytes, end + 6);
3475
- if (!(thisDisk === 0 && cdDisk === 0 || thisDisk === 65535 && cdDisk === 65535)) {
3476
- refuse("not_openable", `The zip spans disks (its end record says disk ${thisDisk}, the directory on disk ${cdDisk}).`);
3477
- }
3478
- let cdSize = u32(bytes, end + 12);
3479
- let cdOffset = u32(bytes, end + 16);
3480
- const loc = end - 20;
3481
- if (loc >= 0 && u32(bytes, loc) === SIG_LOCATOR64) {
3482
- if (u32(bytes, loc + 4) !== 0 || u32(bytes, loc + 16) > 1) refuse("not_openable", "The zip spans disks (zip64).");
3483
- const rec = u64(bytes, loc + 8);
3484
- if (rec + 56 > len || u32(bytes, rec) !== SIG_END64) refuse("not_openable", "The zip64 end record is missing.");
3485
- if (u32(bytes, rec + 16) !== 0 || u32(bytes, rec + 20) !== 0) refuse("not_openable", "The zip spans disks (zip64).");
3486
- cdSize = u64(bytes, rec + 40);
3487
- cdOffset = u64(bytes, rec + 48);
3488
- }
3489
- const cdEnd = cdOffset + cdSize;
3490
- if (cdEnd > len) refuse("not_openable", "The central directory lies past the end of the file.");
3491
- const out = [];
3492
- let p = cdOffset;
3493
- while (p < cdEnd) {
3494
- if (p + 46 > cdEnd || u32(bytes, p) !== SIG_CENTRAL) refuse("not_openable", "The central directory is broken.");
3495
- const flags = u16(bytes, p + 8);
3496
- const nlen = u16(bytes, p + 28);
3497
- const elen = u16(bytes, p + 30);
3498
- const clen = u16(bytes, p + 32);
3499
- const nameBytes = bytes.subarray(p + 46, p + 46 + nlen);
3500
- const extra = bytes.subarray(p + 46 + nlen, p + 46 + nlen + elen);
3501
- let usize = u32(bytes, p + 24);
3502
- let csize = u32(bytes, p + 20);
3503
- let offset = u32(bytes, p + 42);
3504
- if (usize === MAX32 || csize === MAX32 || offset === MAX32) {
3505
- for (let q = 0; q + 4 <= extra.length; q += 4 + u16(extra, q + 2)) {
3506
- if (u16(extra, q) !== 1) continue;
3507
- let r = q + 4;
3508
- const stop = r + u16(extra, q + 2);
3509
- const next = () => {
3510
- if (r + 8 > stop) refuse("not_openable", "A zip64 extra field is short.");
3511
- const v = u64(extra, r);
3512
- r += 8;
3513
- return v;
3514
- };
3515
- if (usize === MAX32) usize = next();
3516
- if (csize === MAX32) csize = next();
3517
- if (offset === MAX32) offset = next();
3518
- break;
3519
- }
3520
- }
3521
- const nonAscii = nameBytes.some((x) => x > 127);
3522
- let name;
3523
- let badUtf8 = false;
3524
- if (flags & 2048) {
3525
- try {
3526
- name = utf8.decode(nameBytes);
3527
- } catch {
3528
- name = latin1(nameBytes);
3529
- badUtf8 = true;
3530
- }
3531
- } else {
3532
- name = latin1(nameBytes);
3533
- }
3534
- out.push({
3535
- name,
3536
- flags,
3537
- method: u16(bytes, p + 10),
3538
- crc: u32(bytes, p + 16),
3539
- csize,
3540
- usize,
3541
- offset,
3542
- external: u32(bytes, p + 38),
3543
- nonAscii,
3544
- badUtf8
3545
- });
3546
- p += 46 + nlen + elen + clen;
3547
- }
3548
- if (p !== cdEnd) refuse("not_openable", "The central directory is broken.");
3549
- return out;
2509
+ var DATE_TIME = /^([0-9]{4})-([0-9]{2})-([0-9]{2})[Tt]([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.([0-9]+))?(?:[Zz]|([+-])([0-9]{2}):([0-9]{2}))?$/;
2510
+ var floorDiv = (a, b) => Math.floor(a / b);
2511
+ var isLeap = (y) => y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0);
2512
+ var DAYS_IN = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2513
+ function daysFromCivil(y, m, d) {
2514
+ const yy = m <= 2 ? y - 1 : y;
2515
+ const era = floorDiv(yy, 400);
2516
+ const yoe = yy - era * 400;
2517
+ const doy = floorDiv(153 * (m + (m > 2 ? -3 : 9)) + 2, 5) + d - 1;
2518
+ const doe = yoe * 365 + floorDiv(yoe, 4) - floorDiv(yoe, 100) + doy;
2519
+ return era * 146097 + doe - 719468;
3550
2520
  }
3551
- var crcTable = null;
3552
- function crc32(data) {
3553
- if (!crcTable) {
3554
- crcTable = new Int32Array(256);
3555
- for (let n = 0; n < 256; n++) {
3556
- let c2 = n;
3557
- for (let k = 0; k < 8; k++) c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
3558
- crcTable[n] = c2;
3559
- }
2521
+ function timeKey(value) {
2522
+ if (typeof value !== "string") return null;
2523
+ const m = DATE_TIME.exec(value);
2524
+ if (m === null) return null;
2525
+ const [y, mo, d, h, mi, s] = m.slice(1, 7).map(Number);
2526
+ if (mo < 1 || mo > 12 || d < 1 || d > (mo === 2 && isLeap(y) ? 29 : DAYS_IN[mo - 1]) || h > 23 || mi > 59 || s > 59) return null;
2527
+ let offset = 0;
2528
+ if (m[8] !== void 0) {
2529
+ const oh = Number(m[9]), om = Number(m[10]);
2530
+ if (oh > 23 || om > 59) return null;
2531
+ offset = (oh * 3600 + om * 60) * (m[8] === "-" ? -1 : 1);
3560
2532
  }
3561
- let c = -1;
3562
- for (let i = 0; i < data.length; i++) c = crcTable[(c ^ data[i]) & 255] ^ c >>> 8;
3563
- return (c ^ -1) >>> 0;
2533
+ const seconds = daysFromCivil(y, mo, d) * 86400 + h * 3600 + mi * 60 + s - offset;
2534
+ return [seconds, Number(((m[7] ?? "") + "000000").slice(0, 6))];
3564
2535
  }
3565
- var CHUNK = 64 * 1024;
3566
- function endsEarly(payload) {
3567
- const short = payload.subarray(0, payload.length - 1);
3568
- try {
3569
- if (short.length <= CHUNK) {
3570
- inflateSync(short);
3571
- } else {
3572
- const inf = new Inflate(() => {
3573
- });
3574
- for (let i = 0; i < short.length; i += CHUNK) {
3575
- const stop = Math.min(i + CHUNK, short.length);
3576
- inf.push(short.subarray(i, stop), stop === short.length);
3577
- }
3578
- }
3579
- } catch {
3580
- return false;
3581
- }
3582
- return true;
2536
+ var compareKeys = (a, b) => a[0] - b[0] || a[1] - b[1];
2537
+ function inCreatedOrder(items) {
2538
+ return items.map((item, index) => ({ item, index, key: timeKey(item.created_at) })).sort((a, b) => {
2539
+ if (a.key && b.key) return compareKeys(a.key, b.key) || a.index - b.index;
2540
+ if (a.key) return -1;
2541
+ if (b.key) return 1;
2542
+ return a.index - b.index;
2543
+ }).map((e) => e.item);
3583
2544
  }
3584
- function inflateEntry(bytes, e) {
3585
- const off = e.offset;
3586
- if (off + 30 > bytes.length || u32(bytes, off) !== SIG_LOCAL) refuse("not_openable", `${e.name}: no local header at its offset.`);
3587
- const start = off + 30 + u16(bytes, off + 26) + u16(bytes, off + 28);
3588
- const payload = bytes.subarray(start, start + e.csize);
3589
- let data;
3590
- if (e.method === 0) {
3591
- data = payload;
3592
- } else if (payload.length <= CHUNK) {
3593
- try {
3594
- data = inflateSync(payload);
3595
- } catch {
3596
- return refuse("not_openable", `${e.name}: its deflate stream is broken.`);
3597
- }
3598
- } else {
3599
- const out = new Uint8Array(e.usize);
3600
- let n = 0;
3601
- let over = false;
3602
- const inf = new Inflate((chunk) => {
3603
- if (n + chunk.length > e.usize) {
3604
- over = true;
3605
- throw new Error("past its size");
3606
- }
3607
- out.set(chunk, n);
3608
- n += chunk.length;
3609
- });
3610
- try {
3611
- for (let i = 0; i < payload.length; i += CHUNK) {
3612
- const stop = Math.min(i + CHUNK, payload.length);
3613
- inf.push(payload.subarray(i, stop), stop === payload.length);
3614
- }
3615
- } catch {
3616
- if (!over) refuse("not_openable", `${e.name}: its deflate stream is broken.`);
3617
- }
3618
- data = over ? new Uint8Array(e.usize + 1) : out.subarray(0, n);
3619
- }
3620
- if (data.length > e.usize) refuse("too_big", `${e.name} holds more than the ${e.usize} bytes it declares.`);
3621
- if (data.length !== e.usize) refuse("not_openable", `${e.name} holds ${data.length} bytes and declares ${e.usize}.`);
3622
- if (e.method !== 0 && payload.length > 0 && endsEarly(payload)) {
3623
- refuse("not_openable", `${e.name}: its deflate stream ends before its declared compressed size.`);
3624
- }
3625
- if (crc32(data) !== e.crc) refuse("not_openable", `${e.name} fails its CRC.`);
3626
- return e.method === 0 ? data.slice() : data;
2545
+ function isMessage(element) {
2546
+ return matchesPair(element, MESSAGE_PAIR);
3627
2547
  }
3628
- function parseWorld(data) {
3629
- let meta;
3630
- try {
3631
- meta = JSON.parse(new TextDecoder().decode(data));
3632
- } catch {
3633
- throw new OwWorldFileError("not_a_world");
3634
- }
3635
- if (!meta || typeof meta !== "object" || Array.isArray(meta)) throw new OwWorldFileError("not_a_world");
3636
- const id = meta.id;
3637
- if (typeof id !== "string" || !id.trim()) throw new OwWorldFileError("not_a_world");
3638
- return meta;
2548
+ function isNote(element) {
2549
+ return matchesPair(element, NOTE_PAIR);
3639
2550
  }
3640
- function withoutLink(data, meta) {
3641
- if (!("api" in meta)) return { data, world: meta };
3642
- const { api: _link, ...rest } = meta;
3643
- return { data: new TextEncoder().encode(JSON.stringify(rest, null, 2) + "\n"), world: rest };
2551
+ function recipientsOf(message) {
2552
+ const list = isBody(message) && !isNote(message) ? message.characters : void 0;
2553
+ return Array.isArray(list) ? list.filter((c) => typeof c === "string" && c !== "") : [];
3644
2554
  }
3645
- function checkCollisions(names) {
3646
- const byFold = /* @__PURE__ */ new Map();
3647
- const segFold = /* @__PURE__ */ new Map();
3648
- const done = /* @__PURE__ */ new Set();
3649
- for (const raw of names) {
3650
- const segs = (raw.endsWith("/") ? raw.slice(0, -1) : raw).split("/");
3651
- let prefix = "";
3652
- let folded = "";
3653
- for (let i = 0; i < segs.length; i++) {
3654
- let f = segFold.get(segs[i]);
3655
- if (f === void 0) {
3656
- f = foldName(segs[i]);
3657
- segFold.set(segs[i], f);
3658
- }
3659
- prefix = i ? `${prefix}/${segs[i]}` : segs[i];
3660
- folded = i ? `${folded}/${f}` : f;
3661
- if (done.has(prefix)) continue;
3662
- done.add(prefix);
3663
- const other = byFold.get(folded);
3664
- if (other !== void 0) {
3665
- refuse("collision", `The names ${JSON.stringify(other)} and ${JSON.stringify(prefix)} are one name after NFC and case folding.`);
3666
- }
3667
- byFold.set(folded, prefix);
3668
- }
3669
- }
2555
+ function isAddressedTo(message, characterId) {
2556
+ if (!isBody(message) || isNote(message) || typeof characterId !== "string" || characterId === "") return false;
2557
+ if (isToEveryone(message)) return true;
2558
+ const list = message.characters;
2559
+ return Array.isArray(list) && list.includes(characterId);
3670
2560
  }
3671
- function checkFileAndFolder(files) {
3672
- const seen = /* @__PURE__ */ new Set();
3673
- for (const n of files) {
3674
- const segs = n.split("/");
3675
- let prefix = "";
3676
- for (let i = 0; i < segs.length - 1; i++) {
3677
- prefix = i ? `${prefix}/${segs[i]}` : segs[i];
3678
- if (seen.has(prefix)) continue;
3679
- seen.add(prefix);
3680
- if (files.has(prefix)) refuse("unsafe_path", `${JSON.stringify(prefix)} is a file and a folder.`);
3681
- }
3682
- }
2561
+ function isToEveryone(message, options) {
2562
+ const keyless = keylessOf("isToEveryone", options);
2563
+ if (!isBody(message) || isNote(message) || keyless || hasUnseenRecipients(message) === true) return false;
2564
+ const list = message.characters;
2565
+ return list === void 0 || list === null || Array.isArray(list) && list.length === 0;
3683
2566
  }
3684
- function readWorldFile(bytes, opts = {}) {
3685
- refuseUnknownOptions("readWorldFile", opts, READ_OPTION_KEYS, "Nothing was read.");
3686
- const maxBytes = opts.maxBytes ?? WORLD_FILE_MAX_BYTES;
3687
- const maxEntries = opts.maxEntries ?? WORLD_FILE_MAX_ENTRIES;
3688
- const entries = centralDirectory(bytes);
3689
- const seen = /* @__PURE__ */ new Set();
3690
- const files = [];
3691
- let declared = 0;
3692
- for (const e of entries) {
3693
- const name2 = e.name;
3694
- const isDir = name2.endsWith("/");
3695
- const bare = isDir ? name2.slice(0, -1) : name2;
3696
- const quoted = JSON.stringify(name2);
3697
- const fault = pathFault(bare);
3698
- if (fault) refuse("unsafe_path", `The entry ${quoted} ${fault}.`);
3699
- const kind = e.external >>> 16 & 61440;
3700
- if (kind !== 0 && kind !== 32768 && kind !== 16384) refuse("link", `The entry ${quoted} is a link or a special file.`);
3701
- if (e.flags & 65) refuse("method", `The entry ${quoted} is encrypted.`);
3702
- if (e.method !== 0 && e.method !== 8) refuse("method", `The entry ${quoted} uses method ${e.method} (only stored and deflate).`);
3703
- if (e.badUtf8) refuse("name", `The entry ${quoted} is flagged UTF-8 and is not.`);
3704
- if (e.nonAscii && !(e.flags & 2048)) refuse("name", `The entry ${quoted} is not ASCII and lacks the UTF-8 flag.`);
3705
- const bad = nameFault(bare);
3706
- if (bad) refuse("name", `The entry ${quoted}: ${bad}.`);
3707
- if (seen.has(name2)) refuse("duplicate", `The entry ${quoted} appears twice.`);
3708
- seen.add(name2);
3709
- if (isDir) continue;
3710
- files.push(e);
3711
- if (files.length > maxEntries) refuse("too_many", `The world file holds more than ${maxEntries} files.`);
3712
- declared += e.usize;
3713
- if (declared > maxBytes) refuse("too_big", `The world file declares more than ${maxBytes} bytes.`);
3714
- }
3715
- checkCollisions(seen);
3716
- const names = new Set(files.map((e) => e.name));
3717
- checkFileAndFolder(names);
3718
- const marker = files.find((e) => e.name === MARKER_NAME);
3719
- if (marker && new TextDecoder("utf-8", { ignoreBOM: true }).decode(inflateEntry(bytes, marker)) !== WORLD_FILE_MEDIA_TYPE) {
3720
- refuse("marker", "The mimetype entry holds other bytes than the OnlyWorlds media type.");
3721
- }
3722
- const candidates = [...names].filter((n) => n !== MARKER_NAME && !isJunk(n));
3723
- let prefix;
3724
- if (candidates.includes(WORLD_FILE)) {
3725
- prefix = "";
3726
- } else {
3727
- const roots = new Set(candidates.filter((n) => n.split("/").length === 2 && n.endsWith(`/${WORLD_FILE}`) && !n.startsWith(".")).map((n) => n.slice(0, -WORLD_FILE.length)));
3728
- if (roots.size === 0) refuse("not_a_world", "There is no world.json at the root or in one top-level folder.");
3729
- if (roots.size > 1) refuse("more_than_one", `The file holds worlds in ${[...roots].join(", ")}.`);
3730
- prefix = [...roots][0];
3731
- }
3732
- const inside = new Set(candidates.filter((n) => n.startsWith(prefix)));
3733
- for (const n of inside) {
3734
- const rel = n.slice(prefix.length);
3735
- if (rel !== WORLD_FILE && rel.endsWith(`/${WORLD_FILE}`) && !rel.startsWith("records/")) {
3736
- refuse("more_than_one", `A second world.json sits inside the world: ${n}.`);
3737
- }
3738
- }
3739
- const content = /* @__PURE__ */ new Map();
3740
- for (const e of files) {
3741
- const data = inflateEntry(bytes, e);
3742
- if (inside.has(e.name)) content.set(e.name, data);
3743
- }
3744
- const worldName = `${prefix}${WORLD_FILE}`;
3745
- const parsed = withoutLink(content.get(worldName), parseWorld(content.get(worldName)));
3746
- const out = [];
3747
- for (const [n, data] of content) {
3748
- const path = n.slice(prefix.length);
3749
- if (opts.skip?.(path)) continue;
3750
- out.push({ path, data: n === worldName ? parsed.data : data });
3751
- }
3752
- out.sort((a, b) => byCodePoint(a.path, b.path));
3753
- const name = parsed.world.name;
3754
- return {
3755
- worldId: parsed.world.id,
3756
- name: typeof name === "string" ? name : "",
3757
- world: parsed.world,
3758
- files: out
3759
- };
2567
+ function hasUnseenRecipients(message, options) {
2568
+ const keyless = keylessOf("hasUnseenRecipients", options);
2569
+ if (!isBody(message) || isNote(message)) return false;
2570
+ if (keyless) return null;
2571
+ const mark = message.x_served_trimmed;
2572
+ return Array.isArray(mark) && mark.includes("characters");
3760
2573
  }
3761
- var PARTS = /* @__PURE__ */ new Set(["elements", "spatial", "media", "records"]);
3762
- function carried(path) {
3763
- if (path === WORLD_FILE) return true;
3764
- const segs = path.split("/");
3765
- if (segs.length < 2) return false;
3766
- if (segs[0].startsWith(".")) return true;
3767
- if (!PARTS.has(segs[0])) return false;
3768
- if (segs[0] === "records") return true;
3769
- return !segs.some((s) => s.startsWith(".")) && !path.endsWith(".meta");
2574
+ function isSentBy(message, characterId) {
2575
+ return isBody(message) && typeof characterId === "string" && characterId !== "" && message.narrator === characterId;
3770
2576
  }
3771
- var STAMP = new Date(1980, 0, 1, 0, 0, 0);
3772
- var WRITE_OPTION_KEYS = ["includePrivateRecords", "includeHidden", "includeAuthorFields", "report"];
3773
- var RECORDS_MANIFEST = "records/RECORDS.json";
3774
- var AUTHOR_FIELDS = ["created_by", "changed_by", "changed_via", "changed_client", "doors"];
3775
- function writeOptions(opts) {
3776
- if (opts === void 0 || opts === null) return { includePrivate: false, includeHidden: true, includeAuthorFields: false };
3777
- if (typeof opts !== "object") throw new TypeError(`writeWorldFile: options must be an object, such as { includePrivateRecords: true }. Nothing was written.`);
3778
- refuseUnknownOptions("writeWorldFile", opts, WRITE_OPTION_KEYS, "Nothing was written.");
3779
- const o = opts;
3780
- for (const key of ["includePrivateRecords", "includeHidden", "includeAuthorFields"]) {
3781
- const asked = o[key];
3782
- if (asked !== void 0 && typeof asked !== "boolean") {
3783
- throw new TypeError(`writeWorldFile: ${key} must be true or false; got ${JSON.stringify(asked) ?? String(asked)}. Nothing was written.`);
2577
+ function senderStatus(message, members) {
2578
+ const narrator = isBody(message) ? message.narrator : void 0;
2579
+ const claimed = typeof narrator === "string" && narrator !== "" ? narrator : null;
2580
+ const mark = isBody(message) ? message.x_served_trimmed : void 0;
2581
+ if (claimed === null && Array.isArray(mark) && mark.includes("narrator")) return { status: "unseen", claimed, writtenBy: null };
2582
+ if (claimed === null || !isBody(message)) return { status: "unverifiable", claimed, writtenBy: null };
2583
+ const hand = handOf(message, members);
2584
+ if (hand === void 0) return { status: "unverifiable", claimed, writtenBy: null };
2585
+ return hand === claimed ? { status: "verified", claimed, writtenBy: null } : { status: "mismatch", claimed, writtenBy: hand };
2586
+ }
2587
+ function editedBy(message, members) {
2588
+ if (!isBody(message) || !carries(message, "changed_by")) return { edited: false, by: null };
2589
+ if (carries(message, "created_by") && message.changed_by === message.created_by) return { edited: false, by: null };
2590
+ return { edited: true, by: characterOf(message.changed_by, members) ?? null };
2591
+ }
2592
+ function readMarkOf(relations, characterId, members) {
2593
+ if (!Array.isArray(relations) || typeof characterId !== "string" || characterId === "") return null;
2594
+ let mark = null;
2595
+ let markKey = null;
2596
+ for (const rel of relations) {
2597
+ if (!matchesPair(rel, MESSAGE_READ_MARK) || rel[MESSAGE_READ_MARK.readerField] !== characterId) continue;
2598
+ const hasAuthor = carries(rel, "created_by");
2599
+ if (carries(rel, "changed_by") && (!hasAuthor || rel.changed_by !== rel.created_by)) continue;
2600
+ if (hasAuthor && handOf(rel, members) !== characterId) continue;
2601
+ const key = timeKey(rel.updated_at);
2602
+ if (mark === null || key !== null && (markKey === null || compareKeys(key, markKey) > 0)) {
2603
+ mark = rel;
2604
+ markKey = key;
3784
2605
  }
3785
2606
  }
3786
- if (o.report !== void 0 && typeof o.report !== "function") {
3787
- throw new TypeError(`writeWorldFile: report must be a function; got ${JSON.stringify(o.report) ?? String(o.report)}. Nothing was written.`);
2607
+ return mark;
2608
+ }
2609
+ function isOwnHand(body, characterId, members) {
2610
+ if (!carries(body, "created_by")) return body.narrator === characterId;
2611
+ const sender = senderStatus(body, members);
2612
+ return sender.status === "verified" && sender.claimed === characterId;
2613
+ }
2614
+ function unreadFor(messages, characterId, readMark, members) {
2615
+ if (!Array.isArray(messages)) return [];
2616
+ const onMark = isBody(readMark) ? readMark[MESSAGE_READ_MARK.messagesField] : void 0;
2617
+ const read = new Set(Array.isArray(onMark) ? onMark.filter((id) => typeof id === "string") : []);
2618
+ return inCreatedOrder(messages.filter((m) => {
2619
+ if (!isBody(m) || !isAddressedTo(m, characterId)) return false;
2620
+ return !isOwnHand(m, characterId, members) && !read.has(idOf(m));
2621
+ }));
2622
+ }
2623
+ function threadOf(messages, rootId) {
2624
+ if (!Array.isArray(messages) || typeof rootId !== "string" || rootId === "") return [];
2625
+ const byId = /* @__PURE__ */ new Map();
2626
+ for (const m of messages) {
2627
+ const id = isBody(m) ? idOf(m) : void 0;
2628
+ if (typeof id === "string" && !byId.has(id)) byId.set(id, m);
3788
2629
  }
3789
- return {
3790
- includePrivate: o.includePrivateRecords === true,
3791
- includeHidden: o.includeHidden !== false,
3792
- includeAuthorFields: o.includeAuthorFields === true,
3793
- report: o.report
2630
+ const reaches = (start) => {
2631
+ const seen = /* @__PURE__ */ new Set();
2632
+ let at = start;
2633
+ while (at !== void 0) {
2634
+ const id = idOf(at);
2635
+ if (id === rootId) return true;
2636
+ if (typeof id !== "string" || seen.has(id)) return false;
2637
+ seen.add(id);
2638
+ const parent = at.parent_narrative;
2639
+ if (parent === rootId) return true;
2640
+ at = typeof parent === "string" ? byId.get(parent) : void 0;
2641
+ }
2642
+ return false;
3794
2643
  };
2644
+ return inCreatedOrder(messages.filter((m) => isBody(m) && !isNote(m) && reaches(m)));
3795
2645
  }
3796
- function elementObject(f) {
3797
- const segs = f.path.split("/");
3798
- if (segs.length !== 3 || segs[0] !== "elements" && segs[0] !== "spatial" || !/\.json$/i.test(segs[2])) return null;
3799
- let doc;
3800
- try {
3801
- doc = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(f.data));
3802
- } catch {
3803
- return null;
2646
+ var isHiddenMark = (value) => value !== void 0 && value !== null && value !== false;
2647
+ function noteOf(narratives, characterId, members) {
2648
+ if (!Array.isArray(narratives) || typeof characterId !== "string" || characterId === "") return null;
2649
+ let line = null;
2650
+ let lineKey = null;
2651
+ for (const el of narratives) {
2652
+ if (!isNote(el)) continue;
2653
+ const note = el;
2654
+ const id = idOf(note);
2655
+ if (typeof id !== "string" || id === "" || note.narrator !== characterId) continue;
2656
+ if (isHiddenMark(note.hidden) || proposedMarkOf(note) !== null || !isOwnHand(note, characterId, members)) continue;
2657
+ const key = timeKey(note.created_at);
2658
+ if (line === null || (key !== null ? lineKey === null || compareKeys(key, lineKey) >= 0 : lineKey === null)) {
2659
+ line = id;
2660
+ lineKey = key;
2661
+ }
3804
2662
  }
3805
- if (doc === null || typeof doc !== "object" || Array.isArray(doc)) return null;
3806
- return doc;
3807
- }
3808
- function isHiddenElement(f) {
3809
- const doc = elementObject(f);
3810
- if (!doc) return false;
3811
- const mark = doc.hidden;
3812
- return mark !== void 0 && mark !== null && mark !== false;
3813
- }
3814
- function withoutAuthorFields(f) {
3815
- const doc = elementObject(f);
3816
- if (!doc) return null;
3817
- const present = AUTHOR_FIELDS.filter((k) => k in doc);
3818
- if (!present.length) return null;
3819
- for (const k of present) delete doc[k];
3820
- return new TextEncoder().encode(JSON.stringify(doc, null, 2) + "\n");
3821
- }
3822
- function privateProducers(files) {
3823
- const manifest = files.find((f) => f.path === RECORDS_MANIFEST);
3824
- if (!manifest) return [];
3825
- const unreadable = (why) => {
3826
- throw new TypeError(`writeWorldFile: ${RECORDS_MANIFEST} ${why}, so which records are private cannot be read and none is left out by guess (spec \xA74.7, OW-8). Fix the manifest, or pass { includePrivateRecords: true } to carry every record. Nothing was written.`);
3827
- };
3828
- let doc;
3829
- try {
3830
- doc = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(manifest.data));
3831
- } catch {
3832
- unreadable("is not JSON");
3833
- }
3834
- if (!Array.isArray(doc)) unreadable("is not a JSON array of entries");
3835
- const out = [];
3836
- for (const entry of doc) {
3837
- if (entry === null || typeof entry !== "object" || Array.isArray(entry)) unreadable("holds an entry that is not an object");
3838
- const { producer, private: isPrivate } = entry;
3839
- if (isPrivate !== true) continue;
3840
- if (typeof producer !== "string" || producer === "") unreadable("marks an entry private without a producer name");
3841
- out.push(producer);
3842
- }
3843
- return out;
3844
- }
3845
- function writeWorldFile(files, topDir, opts = {}) {
3846
- const { includePrivate, includeHidden, includeAuthorFields, report } = writeOptions(opts);
3847
- if (pathFault(topDir) || topDir.includes("/")) throw new OwWorldFileError("unsafe_path");
3848
- const seen = /* @__PURE__ */ new Set();
3849
- for (const f of files) {
3850
- if (pathFault(f.path)) throw new OwWorldFileError("unsafe_path");
3851
- if (seen.has(f.path)) throw new OwWorldFileError("unsafe_path", `The path ${f.path} is listed twice.`);
3852
- seen.add(f.path);
3853
- }
3854
- const left = new Set(includePrivate ? [] : privateProducers(files).map(foldName));
3855
- const inPrivate = (path) => {
3856
- const segs = path.split("/");
3857
- return segs.length > 2 && segs[0] === "records" && left.has(foldName(segs[1]));
3858
- };
3859
- let hiddenLeftOut = 0;
3860
- const kept = files.filter((f) => {
3861
- if (!carried(f.path) || inPrivate(f.path)) return false;
3862
- if (!includeHidden && isHiddenElement(f)) {
3863
- hiddenLeftOut++;
3864
- return false;
3865
- }
3866
- return true;
3867
- });
3868
- if (!kept.some((f) => f.path === WORLD_FILE)) throw new OwWorldFileError("not_a_world");
3869
- const keys = kept.map((f) => `${topDir}/${f.path}`);
3870
- for (const key of keys) {
3871
- const bad = nameFault(key);
3872
- if (bad) throw new OwWorldFileError("name", `The path ${key}: ${bad}.`);
3873
- }
3874
- checkCollisions([MARKER_NAME, ...keys]);
3875
- checkFileAndFolder(/* @__PURE__ */ new Set([MARKER_NAME, ...keys]));
3876
- const input = {
3877
- [MARKER_NAME]: [new TextEncoder().encode(WORLD_FILE_MEDIA_TYPE), { level: 0, mtime: STAMP }]
3878
- };
3879
- let authorFieldsLeftOut = 0;
3880
- for (const f of [...kept].sort((a, b) => byCodePoint(a.path, b.path))) {
3881
- let data = f.data;
3882
- if (f.path === WORLD_FILE) {
3883
- data = withoutLink(data, parseWorld(data)).data;
3884
- } else if (!includeAuthorFields) {
3885
- const bare = withoutAuthorFields(f);
3886
- if (bare) {
3887
- data = bare;
3888
- authorFieldsLeftOut++;
3889
- }
3890
- }
3891
- input[`${topDir}/${f.path}`] = [data, { level: /\.json$/i.test(f.path) ? 6 : 0, mtime: STAMP }];
3892
- }
3893
- const zip = zipSync(input);
3894
- report?.({ hiddenLeftOut, authorFieldsLeftOut });
3895
- return zip;
2663
+ return line;
3896
2664
  }
3897
2665
 
3898
- // src/room.ts
3899
- var WHITE_SPACE = /* @__PURE__ */ new Set([
3900
- 9,
3901
- 10,
3902
- 11,
3903
- 12,
3904
- 13,
3905
- 32,
3906
- 133,
3907
- 160,
3908
- 5760,
3909
- 8192,
3910
- 8193,
3911
- 8194,
3912
- 8195,
3913
- 8196,
3914
- 8197,
3915
- 8198,
3916
- 8199,
3917
- 8200,
3918
- 8201,
3919
- 8202,
3920
- 8232,
3921
- 8233,
3922
- 8239,
3923
- 8287,
3924
- 12288
3925
- ]);
3926
- function trimWhiteSpace(text2) {
3927
- let start = 0;
3928
- let end = text2.length;
3929
- while (start < end && WHITE_SPACE.has(text2.charCodeAt(start))) start++;
3930
- while (end > start && WHITE_SPACE.has(text2.charCodeAt(end - 1))) end--;
3931
- return text2.slice(start, end);
3932
- }
3933
- var fold = (text2) => simpleCaseFold(trimWhiteSpace(text2));
3934
- function hasMark(el, field) {
3935
- const mark = Object.prototype.hasOwnProperty.call(el, field) ? el[field] : void 0;
3936
- if (mark === void 0 || mark === null) return false;
3937
- return typeof mark !== "string" || trimWhiteSpace(mark) !== "";
3938
- }
3939
- function isRoomElement(el) {
3940
- if (el == null || typeof el !== "object" || typeof el.type !== "string" || typeof el.supertype !== "string") return false;
3941
- if (!hasMark(el, ROOM_MARK)) return false;
3942
- const type = fold(el.type);
3943
- const supertype = fold(el.supertype);
3944
- return ROOM_PAIRS.some((p) => fold(p.type) === type && fold(p.supertype) === supertype);
3945
- }
3946
- var READING_AID_KEYS = new Set(READING_AID_PAIRS.map((p) => `${fold(p.type)}/${fold(p.supertype)}`));
3947
- function readingAidKey(element) {
3948
- if (element === null || typeof element !== "object" || Array.isArray(element)) return null;
3949
- const el = element;
3950
- if (typeof el.type !== "string" || typeof el.supertype !== "string") return null;
3951
- const key = `${fold(el.type)}/${fold(el.supertype)}`;
3952
- if (!READING_AID_KEYS.has(key)) return null;
3953
- return hasMark(el, READING_AID_MARK) ? key : null;
3954
- }
3955
- function isCharterElement(element) {
3956
- return readingAidKey(element) !== null;
3957
- }
3958
- var AID_BY_KEY = new Map(
3959
- CHARTER_PAIRS.map((p) => [`${fold(p.type)}/${fold(p.supertype)}`, p.aid])
2666
+ // src/lens.ts
2667
+ var LENS_OPTION_KEYS = ["asOf", "clock"];
2668
+ var ANCHOR_FIELDS = [
2669
+ "characters",
2670
+ "objects",
2671
+ "locations",
2672
+ "species",
2673
+ "creatures",
2674
+ "institutions",
2675
+ "traits",
2676
+ "collectives",
2677
+ "zones",
2678
+ "abilities",
2679
+ "phenomena",
2680
+ "languages",
2681
+ "families",
2682
+ "relations",
2683
+ "constructs",
2684
+ "events",
2685
+ "narratives"
2686
+ ];
2687
+ var TYPE_ORDER = [
2688
+ "ability",
2689
+ "collective",
2690
+ "character",
2691
+ "construct",
2692
+ "creature",
2693
+ "event",
2694
+ "family",
2695
+ "institution",
2696
+ "language",
2697
+ "law",
2698
+ "location",
2699
+ "map",
2700
+ "marker",
2701
+ "narrative",
2702
+ "object",
2703
+ "phenomenon",
2704
+ "pin",
2705
+ "relation",
2706
+ "species",
2707
+ "title",
2708
+ "trait",
2709
+ "zone"
2710
+ ];
2711
+ var TYPE_RANK = new Map(TYPE_ORDER.map((t, i) => [t, i]));
2712
+ var DATE_FIELD = Object.freeze({
2713
+ character: "birth_date",
2714
+ creature: "birth_date",
2715
+ institution: "founding_date",
2716
+ location: "founding_date",
2717
+ collective: "formation_date",
2718
+ law: "date",
2719
+ title: "grant_date",
2720
+ construct: "start_date",
2721
+ event: "start_date",
2722
+ narrative: "start_date",
2723
+ relation: "start_date",
2724
+ zone: "start_date"
2725
+ });
2726
+ var CUT_REASONS = [
2727
+ "budget",
2728
+ "types",
2729
+ "window",
2730
+ "stale",
2731
+ "undated",
2732
+ "after_as_of",
2733
+ "anchor_not_visible",
2734
+ "not_visible",
2735
+ "hops_not_served"
2736
+ ];
2737
+ var OWNER_ONLY = /* @__PURE__ */ new Set(["anchor_not_visible", "not_visible"]);
2738
+ var ROOM_KEYS = new Set(ROOM_PAIRS.map((p) => `${fold(p.type)}/${fold(p.supertype)}`));
2739
+ var MAIL_SECONDS = 30 * 86400;
2740
+ var MESSAGE_ADDRESSING = ["characters", "narrator"];
2741
+ var STUB_FIELDS = ["id", "type", "name", "description", "supertype", "subtype", "image_url", "created_at", "updated_at", "change_seq"];
2742
+ var STUB_NULLED = ["created_by", "changed_by", "changed_via", "changed_client"];
2743
+ var UNSET = { text: "", integer: null, single_link: null, multi_link: [] };
2744
+ var LINK_FIELDS = new Map(
2745
+ Object.entries(FIELD_SCHEMA).map(([type, fields]) => [
2746
+ type,
2747
+ Object.entries(fields).filter(([, f]) => f.type === "single_link" || f.type === "multi_link").map(([name, f]) => [name, f.type === "multi_link", f.target ?? "any"])
2748
+ ])
3960
2749
  );
3961
- function readingAidOf(element) {
3962
- if (element === null || typeof element !== "object" || Array.isArray(element)) return null;
3963
- const el = element;
3964
- if (typeof el.type !== "string" || typeof el.supertype !== "string") return null;
3965
- return AID_BY_KEY.get(`${fold(el.type)}/${fold(el.supertype)}`) ?? null;
2750
+ var ANCHOR_TARGET = new Map((LINK_FIELDS.get("construct") ?? []).map(([f, , t]) => [f, t]));
2751
+ function linkTarget(el, field, target) {
2752
+ if (target !== "any") return target;
2753
+ const key = el[`${field.slice(0, -3)}_type`];
2754
+ return typeof key === "string" && TYPE_RANK.has(key) ? key : "";
3966
2755
  }
3967
-
3968
- // src/review.ts
3969
- var PROPOSED_MARK = "x_review_proposed";
3970
- var DAY = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
3971
- function todayDay() {
3972
- return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
2756
+ var isBody2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2757
+ var own = (v, key) => Object.prototype.hasOwnProperty.call(v, key);
2758
+ var valueOf = (v, key) => own(v, key) && v[key] !== void 0 ? v[key] : null;
2759
+ var whole = (v) => typeof v === "number" && Number.isInteger(v) ? v : null;
2760
+ function dateOf(element) {
2761
+ if (!isBody2(element)) return null;
2762
+ const type = typeof element.type === "string" ? fold(element.type) : "";
2763
+ if (!own(DATE_FIELD, type)) return null;
2764
+ return whole(valueOf(element, DATE_FIELD[type]));
3973
2765
  }
3974
- function isPresent(v) {
3975
- if (v === void 0 || v === null) return false;
3976
- if (typeof v === "string") return trimWhiteSpace(v) !== "";
3977
- if (Array.isArray(v)) return v.length > 0;
3978
- if (typeof v === "object") return Object.keys(v).length > 0;
3979
- return true;
2766
+ function changedAt(el) {
2767
+ const stamps = [timeKey(valueOf(el, "server_updated_at")), timeKey(valueOf(el, "local_updated_at"))].filter((k) => k !== null);
2768
+ if (stamps.length === 0) return timeKey(valueOf(el, "updated_at"));
2769
+ return stamps.reduce((a, b) => compareKeys(a, b) >= 0 ? a : b);
3980
2770
  }
3981
- function proposedMarkOf(element, today) {
3982
- if (today !== void 0 && (typeof today !== "string" || !DAY.test(today))) {
3983
- throw new TypeError(`proposedMarkOf: today is a day as YYYY-MM-DD; got ${JSON.stringify(today) ?? String(today)}.`);
2771
+ function byCodePoint(a, b) {
2772
+ const x = Array.from(a);
2773
+ const y = Array.from(b);
2774
+ const n = Math.min(x.length, y.length);
2775
+ for (let i = 0; i < n; i++) {
2776
+ const d = x[i].codePointAt(0) - y[i].codePointAt(0);
2777
+ if (d !== 0) return d;
3984
2778
  }
3985
- if (!element || typeof element !== "object") return null;
3986
- const v = element[PROPOSED_MARK];
3987
- if (!isPresent(v) || typeof v !== "object" || Array.isArray(v)) return null;
3988
- const m = v;
3989
- const by = typeof m.by === "string" && trimWhiteSpace(m.by) ? trimWhiteSpace(m.by) : null;
3990
- const expires = typeof m.expires === "string" && DAY.test(trimWhiteSpace(m.expires)) ? trimWhiteSpace(m.expires) : null;
3991
- return { by, expires, lapsed: expires !== null && expires <= (today ?? todayDay()) };
3992
- }
3993
- function handsOnAsProposed(element) {
3994
- if (!element || typeof element !== "object") return false;
3995
- return isPresent(element[PROPOSED_MARK]);
3996
- }
3997
-
3998
- // src/message.ts
3999
- var ADDRESSING_KEYS = ["keyless"];
4000
- var isBody = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
4001
- var idOf = (v) => v.id;
4002
- var carries = (v, key) => Object.prototype.hasOwnProperty.call(v, key) && v[key] !== void 0;
4003
- function matchesPair(el, pair) {
4004
- if (!isBody(el) || typeof el.type !== "string" || typeof el.supertype !== "string") return false;
4005
- return fold(el.type) === fold(pair.type) && fold(el.supertype) === fold(pair.supertype);
2779
+ return x.length - y.length;
4006
2780
  }
4007
- function keylessOf(fn, options) {
4008
- if (options !== void 0 && options !== null && !isBody(options)) {
4009
- throw new TypeError(`${fn}: options is an object, such as { keyless: true }; got ${JSON.stringify(options) ?? typeof options}.`);
4010
- }
4011
- refuseUnknownOptions(fn, options, ADDRESSING_KEYS);
4012
- const keyless = isBody(options) ? options.keyless : void 0;
4013
- if (keyless !== void 0 && typeof keyless !== "boolean") {
4014
- throw new TypeError(`${fn}: keyless is true or false; got ${JSON.stringify(keyless) ?? typeof keyless}.`);
2781
+ function copy(v) {
2782
+ if (Array.isArray(v)) return v.map(copy);
2783
+ if (isBody2(v)) {
2784
+ const out = {};
2785
+ for (const k of Object.keys(v)) out[k] = copy(v[k]);
2786
+ return out;
4015
2787
  }
4016
- return keyless === true;
2788
+ return v;
4017
2789
  }
4018
- function characterOf(membership, members) {
4019
- if (!Array.isArray(members)) return void 0;
4020
- const row = members.find((m) => isBody(m) && m.id === membership);
4021
- return row !== void 0 && typeof row.character === "string" && row.character !== "" ? row.character : void 0;
2790
+ function isLens(element) {
2791
+ if (!isBody2(element) || typeof element.type !== "string" || typeof element.supertype !== "string") return false;
2792
+ return fold(element.type) === "construct" && fold(element.supertype) === fold("Lens");
4022
2793
  }
4023
- function handOf(body, members) {
4024
- return carries(body, "created_by") ? characterOf(body.created_by, members) : void 0;
4025
- }
4026
- var DATE_TIME = /^([0-9]{4})-([0-9]{2})-([0-9]{2})[Tt]([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.([0-9]+))?(?:[Zz]|([+-])([0-9]{2}):([0-9]{2}))?$/;
4027
- var floorDiv = (a, b) => Math.floor(a / b);
4028
- var isLeap = (y) => y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0);
4029
- var DAYS_IN = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
4030
- function daysFromCivil(y, m, d) {
4031
- const yy = m <= 2 ? y - 1 : y;
4032
- const era = floorDiv(yy, 400);
4033
- const yoe = yy - era * 400;
4034
- const doy = floorDiv(153 * (m + (m > 2 ? -3 : 9)) + 2, 5) + d - 1;
4035
- const doe = yoe * 365 + floorDiv(yoe, 4) - floorDiv(yoe, 100) + doy;
4036
- return era * 146097 + doe - 719468;
4037
- }
4038
- function timeKey(value) {
4039
- if (typeof value !== "string") return null;
4040
- const m = DATE_TIME.exec(value);
4041
- if (m === null) return null;
4042
- const [y, mo, d, h, mi, s] = m.slice(1, 7).map(Number);
4043
- if (mo < 1 || mo > 12 || d < 1 || d > (mo === 2 && isLeap(y) ? 29 : DAYS_IN[mo - 1]) || h > 23 || mi > 59 || s > 59) return null;
4044
- let offset = 0;
4045
- if (m[8] !== void 0) {
4046
- const oh = Number(m[9]), om = Number(m[10]);
4047
- if (oh > 23 || om > 59) return null;
4048
- offset = (oh * 3600 + om * 60) * (m[8] === "-" ? -1 : 1);
4049
- }
4050
- const seconds = daysFromCivil(y, mo, d) * 86400 + h * 3600 + mi * 60 + s - offset;
4051
- return [seconds, Number(((m[7] ?? "") + "000000").slice(0, 6))];
4052
- }
4053
- var compareKeys = (a, b) => a[0] - b[0] || a[1] - b[1];
4054
- function inCreatedOrder(items) {
4055
- return items.map((item, index) => ({ item, index, key: timeKey(item.created_at) })).sort((a, b) => {
4056
- if (a.key && b.key) return compareKeys(a.key, b.key) || a.index - b.index;
4057
- if (a.key) return -1;
4058
- if (b.key) return 1;
4059
- return a.index - b.index;
4060
- }).map((e) => e.item);
4061
- }
4062
- function isMessage(element) {
4063
- return matchesPair(element, MESSAGE_PAIR);
4064
- }
4065
- function isNote(element) {
4066
- return matchesPair(element, NOTE_PAIR);
4067
- }
4068
- function recipientsOf(message) {
4069
- const list = isBody(message) && !isNote(message) ? message.characters : void 0;
4070
- return Array.isArray(list) ? list.filter((c) => typeof c === "string" && c !== "") : [];
4071
- }
4072
- function isAddressedTo(message, characterId) {
4073
- if (!isBody(message) || isNote(message) || typeof characterId !== "string" || characterId === "") return false;
4074
- if (isToEveryone(message)) return true;
4075
- const list = message.characters;
4076
- return Array.isArray(list) && list.includes(characterId);
4077
- }
4078
- function isToEveryone(message, options) {
4079
- const keyless = keylessOf("isToEveryone", options);
4080
- if (!isBody(message) || isNote(message) || keyless || hasUnseenRecipients(message) === true) return false;
4081
- const list = message.characters;
4082
- return list === void 0 || list === null || Array.isArray(list) && list.length === 0;
4083
- }
4084
- function hasUnseenRecipients(message, options) {
4085
- const keyless = keylessOf("hasUnseenRecipients", options);
4086
- if (!isBody(message) || isNote(message)) return false;
4087
- if (keyless) return null;
4088
- const mark = message.x_served_trimmed;
4089
- return Array.isArray(mark) && mark.includes("characters");
4090
- }
4091
- function isSentBy(message, characterId) {
4092
- return isBody(message) && typeof characterId === "string" && characterId !== "" && message.narrator === characterId;
4093
- }
4094
- function senderStatus(message, members) {
4095
- const narrator = isBody(message) ? message.narrator : void 0;
4096
- const claimed = typeof narrator === "string" && narrator !== "" ? narrator : null;
4097
- const mark = isBody(message) ? message.x_served_trimmed : void 0;
4098
- if (claimed === null && Array.isArray(mark) && mark.includes("narrator")) return { status: "unseen", claimed, writtenBy: null };
4099
- if (claimed === null || !isBody(message)) return { status: "unverifiable", claimed, writtenBy: null };
4100
- const hand = handOf(message, members);
4101
- if (hand === void 0) return { status: "unverifiable", claimed, writtenBy: null };
4102
- return hand === claimed ? { status: "verified", claimed, writtenBy: null } : { status: "mismatch", claimed, writtenBy: hand };
4103
- }
4104
- function editedBy(message, members) {
4105
- if (!isBody(message) || !carries(message, "changed_by")) return { edited: false, by: null };
4106
- if (carries(message, "created_by") && message.changed_by === message.created_by) return { edited: false, by: null };
4107
- return { edited: true, by: characterOf(message.changed_by, members) ?? null };
4108
- }
4109
- function readMarkOf(relations, characterId, members) {
4110
- if (!Array.isArray(relations) || typeof characterId !== "string" || characterId === "") return null;
4111
- let mark = null;
4112
- let markKey = null;
4113
- for (const rel of relations) {
4114
- if (!matchesPair(rel, MESSAGE_READ_MARK) || rel[MESSAGE_READ_MARK.readerField] !== characterId) continue;
4115
- const hasAuthor = carries(rel, "created_by");
4116
- if (carries(rel, "changed_by") && (!hasAuthor || rel.changed_by !== rel.created_by)) continue;
4117
- if (hasAuthor && handOf(rel, members) !== characterId) continue;
4118
- const key = timeKey(rel.updated_at);
4119
- if (mark === null || key !== null && (markKey === null || compareKeys(key, markKey) > 0)) {
4120
- mark = rel;
4121
- markKey = key;
4122
- }
4123
- }
4124
- return mark;
4125
- }
4126
- function isOwnHand(body, characterId, members) {
4127
- if (!carries(body, "created_by")) return body.narrator === characterId;
4128
- const sender = senderStatus(body, members);
4129
- return sender.status === "verified" && sender.claimed === characterId;
4130
- }
4131
- function unreadFor(messages, characterId, readMark, members) {
4132
- if (!Array.isArray(messages)) return [];
4133
- const onMark = isBody(readMark) ? readMark[MESSAGE_READ_MARK.messagesField] : void 0;
4134
- const read = new Set(Array.isArray(onMark) ? onMark.filter((id) => typeof id === "string") : []);
4135
- return inCreatedOrder(messages.filter((m) => {
4136
- if (!isBody(m) || !isAddressedTo(m, characterId)) return false;
4137
- return !isOwnHand(m, characterId, members) && !read.has(idOf(m));
4138
- }));
4139
- }
4140
- function threadOf(messages, rootId) {
4141
- if (!Array.isArray(messages) || typeof rootId !== "string" || rootId === "") return [];
4142
- const byId = /* @__PURE__ */ new Map();
4143
- for (const m of messages) {
4144
- const id = isBody(m) ? idOf(m) : void 0;
4145
- if (typeof id === "string" && !byId.has(id)) byId.set(id, m);
4146
- }
4147
- const reaches = (start) => {
4148
- const seen = /* @__PURE__ */ new Set();
4149
- let at = start;
4150
- while (at !== void 0) {
4151
- const id = idOf(at);
4152
- if (id === rootId) return true;
4153
- if (typeof id !== "string" || seen.has(id)) return false;
4154
- seen.add(id);
4155
- const parent = at.parent_narrative;
4156
- if (parent === rootId) return true;
4157
- at = typeof parent === "string" ? byId.get(parent) : void 0;
4158
- }
4159
- return false;
4160
- };
4161
- return inCreatedOrder(messages.filter((m) => isBody(m) && !isNote(m) && reaches(m)));
4162
- }
4163
- var isHiddenMark = (value) => value !== void 0 && value !== null && value !== false;
4164
- function noteOf(narratives, characterId, members) {
4165
- if (!Array.isArray(narratives) || typeof characterId !== "string" || characterId === "") return null;
4166
- let line = null;
4167
- let lineKey = null;
4168
- for (const el of narratives) {
4169
- if (!isNote(el)) continue;
4170
- const note = el;
4171
- const id = idOf(note);
4172
- if (typeof id !== "string" || id === "" || note.narrator !== characterId) continue;
4173
- if (isHiddenMark(note.hidden) || proposedMarkOf(note) !== null || !isOwnHand(note, characterId, members)) continue;
4174
- const key = timeKey(note.created_at);
4175
- if (line === null || (key !== null ? lineKey === null || compareKeys(key, lineKey) >= 0 : lineKey === null)) {
4176
- line = id;
4177
- lineKey = key;
4178
- }
4179
- }
4180
- return line;
4181
- }
4182
-
4183
- // src/lens.ts
4184
- var LENS_OPTION_KEYS = ["asOf", "clock"];
4185
- var ANCHOR_FIELDS = [
4186
- "characters",
4187
- "objects",
4188
- "locations",
4189
- "species",
4190
- "creatures",
4191
- "institutions",
4192
- "traits",
4193
- "collectives",
4194
- "zones",
4195
- "abilities",
4196
- "phenomena",
4197
- "languages",
4198
- "families",
4199
- "relations",
4200
- "constructs",
4201
- "events",
4202
- "narratives"
4203
- ];
4204
- var TYPE_ORDER = [
4205
- "ability",
4206
- "collective",
4207
- "character",
4208
- "construct",
4209
- "creature",
4210
- "event",
4211
- "family",
4212
- "institution",
4213
- "language",
4214
- "law",
4215
- "location",
4216
- "map",
4217
- "marker",
4218
- "narrative",
4219
- "object",
4220
- "phenomenon",
4221
- "pin",
4222
- "relation",
4223
- "species",
4224
- "title",
4225
- "trait",
4226
- "zone"
4227
- ];
4228
- var TYPE_RANK = new Map(TYPE_ORDER.map((t, i) => [t, i]));
4229
- var DATE_FIELD = Object.freeze({
4230
- character: "birth_date",
4231
- creature: "birth_date",
4232
- institution: "founding_date",
4233
- location: "founding_date",
4234
- collective: "formation_date",
4235
- law: "date",
4236
- title: "grant_date",
4237
- construct: "start_date",
4238
- event: "start_date",
4239
- narrative: "start_date",
4240
- relation: "start_date",
4241
- zone: "start_date"
4242
- });
4243
- var CUT_REASONS = [
4244
- "budget",
4245
- "types",
4246
- "window",
4247
- "stale",
4248
- "undated",
4249
- "after_as_of",
4250
- "anchor_not_visible",
4251
- "not_visible",
4252
- "hops_not_served"
4253
- ];
4254
- var OWNER_ONLY = /* @__PURE__ */ new Set(["anchor_not_visible", "not_visible"]);
4255
- var ROOM_KEYS = new Set(ROOM_PAIRS.map((p) => `${fold(p.type)}/${fold(p.supertype)}`));
4256
- var MAIL_SECONDS = 30 * 86400;
4257
- var MESSAGE_ADDRESSING = ["characters", "narrator"];
4258
- var STUB_FIELDS = ["id", "type", "name", "description", "supertype", "subtype", "image_url", "created_at", "updated_at", "change_seq"];
4259
- var STUB_NULLED = ["created_by", "changed_by", "changed_via", "changed_client"];
4260
- var UNSET = { text: "", integer: null, single_link: null, multi_link: [] };
4261
- var LINK_FIELDS = new Map(
4262
- Object.entries(FIELD_SCHEMA).map(([type, fields]) => [
4263
- type,
4264
- Object.entries(fields).filter(([, f]) => f.type === "single_link" || f.type === "multi_link").map(([name, f]) => [name, f.type === "multi_link", f.target ?? "any"])
4265
- ])
4266
- );
4267
- var ANCHOR_TARGET = new Map((LINK_FIELDS.get("construct") ?? []).map(([f, , t]) => [f, t]));
4268
- function linkTarget(el, field, target) {
4269
- if (target !== "any") return target;
4270
- const key = el[`${field.slice(0, -3)}_type`];
4271
- return typeof key === "string" && TYPE_RANK.has(key) ? key : "";
4272
- }
4273
- var isBody2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
4274
- var own = (v, key) => Object.prototype.hasOwnProperty.call(v, key);
4275
- var valueOf = (v, key) => own(v, key) && v[key] !== void 0 ? v[key] : null;
4276
- var whole = (v) => typeof v === "number" && Number.isInteger(v) ? v : null;
4277
- function dateOf(element) {
4278
- if (!isBody2(element)) return null;
4279
- const type = typeof element.type === "string" ? fold(element.type) : "";
4280
- if (!own(DATE_FIELD, type)) return null;
4281
- return whole(valueOf(element, DATE_FIELD[type]));
4282
- }
4283
- function changedAt(el) {
4284
- const stamps = [timeKey(valueOf(el, "server_updated_at")), timeKey(valueOf(el, "local_updated_at"))].filter((k) => k !== null);
4285
- if (stamps.length === 0) return timeKey(valueOf(el, "updated_at"));
4286
- return stamps.reduce((a, b) => compareKeys(a, b) >= 0 ? a : b);
4287
- }
4288
- function byCodePoint2(a, b) {
4289
- const x = Array.from(a);
4290
- const y = Array.from(b);
4291
- const n = Math.min(x.length, y.length);
4292
- for (let i = 0; i < n; i++) {
4293
- const d = x[i].codePointAt(0) - y[i].codePointAt(0);
4294
- if (d !== 0) return d;
4295
- }
4296
- return x.length - y.length;
4297
- }
4298
- function copy(v) {
4299
- if (Array.isArray(v)) return v.map(copy);
4300
- if (isBody2(v)) {
4301
- const out = {};
4302
- for (const k of Object.keys(v)) out[k] = copy(v[k]);
4303
- return out;
4304
- }
4305
- return v;
4306
- }
4307
- function isLens(element) {
4308
- if (!isBody2(element) || typeof element.type !== "string" || typeof element.supertype !== "string") return false;
4309
- return fold(element.type) === "construct" && fold(element.supertype) === fold("Lens");
4310
- }
4311
- function isTemplate(element) {
4312
- return isLens(element) && typeof element.subtype === "string" && fold(element.subtype) === fold("Template");
2794
+ function isTemplate(element) {
2795
+ return isLens(element) && typeof element.subtype === "string" && fold(element.subtype) === fold("Template");
4313
2796
  }
4314
2797
  function lensesInUse(membership, xLensUses) {
4315
2798
  const list = Array.isArray(membership) ? membership : xLensUses;
@@ -4330,9 +2813,9 @@ function readRecipe(raw) {
4330
2813
  if (typesV !== null) {
4331
2814
  if (!Array.isArray(typesV)) return { bad: "types" };
4332
2815
  const set = /* @__PURE__ */ new Set();
4333
- for (const word2 of typesV) {
4334
- if (typeof word2 !== "string") return { bad: "types" };
4335
- const w = fold(word2);
2816
+ for (const word of typesV) {
2817
+ if (typeof word !== "string") return { bad: "types" };
2818
+ const w = fold(word);
4336
2819
  if (!(w.includes("/") ? ROOM_KEYS.has(w) || READING_AID_KEYS.has(w) : TYPE_RANK.has(w))) return { bad: "types" };
4337
2820
  set.add(w);
4338
2821
  }
@@ -4472,1013 +2955,1270 @@ var Reading = class {
4472
2955
  if (typeof t === "string" && this.typeOf.get(t) === to && !out.includes(t)) out.push(t);
4473
2956
  }
4474
2957
  }
4475
- return out;
4476
- }
4477
- /** The ids the element's served body links to: its links inside the view; a stub carries none. */
4478
- links(id) {
4479
- if (this.stubs.has(id)) return [];
4480
- return this.fullLinks(id).filter((t) => this.view.has(t));
2958
+ return out;
2959
+ }
2960
+ /** The ids the element's served body links to: its links inside the view; a stub carries none. */
2961
+ links(id) {
2962
+ if (this.stubs.has(id)) return [];
2963
+ return this.fullLinks(id).filter((t) => this.view.has(t));
2964
+ }
2965
+ /**
2966
+ * The body this reader is served: the owner's own view the body as stored; any other reader's with the links
2967
+ * it cannot see left out (`trim`); a known-of element's a stub made from that trimmed body: the base fields
2968
+ * and the type's public fields kept, every other field of the type it holds at its unset value (`UNSET`; the
2969
+ * server's who and door null), no extension key, and `known_of: true`. A body of an element under the hidden
2970
+ * mark (the world's `hidden` list or its own `hidden`) carries `hidden: true`, and no other body a `hidden` key:
2971
+ * only the owner's view holds a hidden element, unless a guest's own lists name one.
2972
+ */
2973
+ body(id) {
2974
+ let b = this.served.get(id);
2975
+ if (b !== void 0) return b;
2976
+ const el = this.byId.get(id);
2977
+ const type = this.typeOf.get(id);
2978
+ b = copy(el);
2979
+ delete b.x_served_trimmed;
2980
+ if (!this.stored) this.trim(type, b);
2981
+ if (this.stubs.has(id)) {
2982
+ const kinds = FIELD_SCHEMA[type] ?? {};
2983
+ const keep = /* @__PURE__ */ new Set([...STUB_FIELDS, ...PUBLIC_FIELDS[type] ?? []]);
2984
+ const full = b;
2985
+ b = {};
2986
+ for (const k of Object.keys(full)) {
2987
+ if (keep.has(k)) b[k] = full[k];
2988
+ else if (STUB_NULLED.includes(k)) b[k] = null;
2989
+ else if (own(kinds, k) && own(UNSET, kinds[k].type)) b[k] = copy(UNSET[kinds[k].type]);
2990
+ }
2991
+ b.known_of = true;
2992
+ }
2993
+ if (this.hidden.has(id)) b.hidden = true;
2994
+ else delete b.hidden;
2995
+ this.served.set(id, b);
2996
+ return b;
2997
+ }
2998
+ /**
2999
+ * A whole body as a reader below the owner is served it, as keel's `redact` and `serialize` serve it: every
3000
+ * link id the reader cannot see (or that names an element of another type than the field's) left out, a
3001
+ * single link to null, a generic pair (a Pin's `element_type` and `element_id`) to the empty pair, `""` and
3002
+ * null; a lens's `x_lens.notes` keeps the entries keyed to an anchor it is served or another element it
3003
+ * sees. `x_served_trimmed` names what was trimmed only where keel adds it: a Message's `characters` and
3004
+ * `narrator`, a lens's anchor fields and `notes` (when an anchor's note went with it), for a contributor
3005
+ * or a guest, never the public rung.
3006
+ */
3007
+ trim(type, b) {
3008
+ const sees = (t, target) => typeof t === "string" && this.linkable.has(t) && (target === "any" || this.typeOf.get(t) === target);
3009
+ const schema = FIELD_SCHEMA[type] ?? {};
3010
+ const isLensBody = isLens(b);
3011
+ const anchorsBefore = isLensBody ? new Set(ANCHOR_FIELDS.flatMap((f) => Array.isArray(b[f]) ? b[f] : [])) : null;
3012
+ const trimmed = [];
3013
+ for (const [field, many] of LINK_FIELDS.get(type) ?? []) {
3014
+ if (!own(b, field)) continue;
3015
+ const v = b[field];
3016
+ const target = schema[field]?.target ?? "any";
3017
+ if (many) {
3018
+ if (!Array.isArray(v) || v.length === 0) continue;
3019
+ const kept = v.filter((t) => sees(t, target));
3020
+ if (kept.length !== v.length) trimmed.push(field);
3021
+ b[field] = kept;
3022
+ } else if (target === "any" && field.endsWith("_id")) {
3023
+ const typeField = `${field.slice(0, -3)}_type`;
3024
+ if (typeof v !== "string" || v === "" || sees(v, typeof b[typeField] === "string" ? b[typeField] : "")) continue;
3025
+ if (own(b, typeField)) b[typeField] = "";
3026
+ b[field] = null;
3027
+ trimmed.push(field);
3028
+ } else if (typeof v === "string" && v !== "" && !sees(v, target)) {
3029
+ b[field] = null;
3030
+ trimmed.push(field);
3031
+ }
3032
+ }
3033
+ let notesGone = false;
3034
+ if (anchorsBefore !== null && isBody2(b.x_lens) && isBody2(b.x_lens.notes)) {
3035
+ const notes = b.x_lens.notes;
3036
+ const served = new Set(ANCHOR_FIELDS.flatMap((f) => Array.isArray(b[f]) ? b[f] : []));
3037
+ const kept = {};
3038
+ for (const k of Object.keys(notes)) {
3039
+ if (served.has(k) || !anchorsBefore.has(k) && this.linkable.has(k)) kept[k] = notes[k];
3040
+ else if (anchorsBefore.has(k)) notesGone = true;
3041
+ }
3042
+ if (Object.keys(kept).length !== Object.keys(notes).length) b.x_lens = { ...b.x_lens, notes: kept };
3043
+ }
3044
+ if (this.seenRung === "public") return;
3045
+ const named = isMessage(b) ? MESSAGE_ADDRESSING.filter((f) => trimmed.includes(f)) : isLensBody ? [...ANCHOR_FIELDS.filter((f) => trimmed.includes(f)), ...notesGone ? ["notes"] : []] : [];
3046
+ if (named.length > 0) b.x_served_trimmed = named;
3047
+ }
3048
+ /**
3049
+ * One hop from each element of `from`, both ways, and on through each Relation it lands on to that Relation's
3050
+ * parties. Nothing hops out of a stub or a room element, nor out of an element `stops` names.
3051
+ */
3052
+ reach(from, excluded, stops) {
3053
+ const landed = /* @__PURE__ */ new Set();
3054
+ for (const f of from) {
3055
+ if (this.stubs.has(f) || this.room.has(f) || stops !== void 0 && stops(f)) continue;
3056
+ for (const t of [...this.links(f), ...this.inView.get(f) ?? []]) if (!excluded(t)) landed.add(t);
3057
+ }
3058
+ const reached = new Set(landed);
3059
+ const edges = [];
3060
+ for (const r of landed) {
3061
+ if (this.typeOf.get(r) !== "relation" || this.stubs.has(r) || this.room.has(r)) continue;
3062
+ edges.push(r);
3063
+ for (const t of this.links(r)) if (!excluded(t)) reached.add(t);
3064
+ }
3065
+ return { reached, edges };
3066
+ }
3067
+ /** What one hop from `from` would reach in the owner's world that this reader's view leaves out (the owner's count). */
3068
+ unseen(from, landedRelations, excluded) {
3069
+ const out = /* @__PURE__ */ new Set();
3070
+ const consider = (t) => {
3071
+ if (this.byId.has(t) && !this.view.has(t) && !excluded(t)) out.add(t);
3072
+ };
3073
+ for (const f of from) {
3074
+ if (this.stubs.has(f) || this.room.has(f)) continue;
3075
+ for (const t of this.fullLinks(f)) consider(t);
3076
+ for (const t of this.inFull.get(f) ?? []) consider(t);
3077
+ }
3078
+ for (const r of landedRelations) for (const t of this.fullLinks(r)) consider(t);
3079
+ return out;
3080
+ }
3081
+ date(id) {
3082
+ const field = DATE_FIELD[this.typeOf.get(id)];
3083
+ if (field === void 0) return void 0;
3084
+ return whole(this.byId.get(id)[field]);
3085
+ }
3086
+ /** The fence (keel's `as_of`, on the element's own date) and `undated`. */
3087
+ fenceCut(id, recipe) {
3088
+ const d = this.date(id);
3089
+ if (d === void 0) return null;
3090
+ if (d === null) return recipe.undated === "exclude" ? "undated" : null;
3091
+ return this.asOf !== null && d > this.asOf ? "after_as_of" : null;
3092
+ }
3093
+ /**
3094
+ * `window`, or `from` and `to` (closed-open). A `to` after `as_of` is clipped: the fence stays the upper
3095
+ * edge, so an element dated `as_of` is kept, and every element such a `to` would cut is already cut by the
3096
+ * fence (`after_as_of`, counted first).
3097
+ */
3098
+ windowCut(id, recipe) {
3099
+ const d = this.date(id);
3100
+ if (d === void 0 || d === null) return null;
3101
+ if (recipe.window !== null && this.asOf !== null && d < this.asOf - recipe.window) return "window";
3102
+ if (recipe.from !== null && d < recipe.from) return "window";
3103
+ if (recipe.to !== null && d >= recipe.to) return "window";
3104
+ return null;
3105
+ }
3106
+ /**
3107
+ * `changed_within`: changed longer ago than that many days before the reading's wall clock. The time read is the
3108
+ * element's `updated_at`, or for a folder element (one carrying `server_updated_at` or `local_updated_at`) the
3109
+ * newer of those two; an element with no readable time is never cut.
3110
+ */
3111
+ staleCut(id, recipe, wall) {
3112
+ if (recipe.changedWithin === null) return null;
3113
+ const at = changedAt(this.byId.get(id));
3114
+ if (at === null) return null;
3115
+ return compareKeys(at, [wall[0] - recipe.changedWithin * 86400, wall[1]]) < 0 ? "stale" : null;
3116
+ }
3117
+ /** Whether `types` keeps the element: a room element or a reading aid only when its pair is named, any other by its type (or any type when `types` is empty). */
3118
+ kept(id, recipe) {
3119
+ if (this.room.has(id)) {
3120
+ const el = this.byId.get(id);
3121
+ return recipe.types !== null && recipe.types.has(`${fold(el.type)}/${fold(el.supertype)}`);
3122
+ }
3123
+ const aid = this.aid.get(id);
3124
+ if (aid !== void 0) return recipe.types !== null && recipe.types.has(aid);
3125
+ return recipe.types === null || recipe.types.has(this.typeOf.get(id));
3126
+ }
3127
+ /** Rule 4: a reading aid a hop reached is not hopped out of unless `types` names its pair. */
3128
+ stopsAt(id, recipe) {
3129
+ const aid = this.aid.get(id);
3130
+ return aid !== void 0 && !(recipe.types !== null && recipe.types.has(aid));
3131
+ }
3132
+ /** Rule 5's order past the anchors: the schema's type order, newest `updated_at` first (an unreadable time last), then by id. */
3133
+ sort(ids) {
3134
+ const keyed = [...ids].map((id) => ({ id, rank: TYPE_RANK.get(this.typeOf.get(id)), at: timeKey(this.byId.get(id).updated_at) }));
3135
+ keyed.sort((a, b) => {
3136
+ if (a.rank !== b.rank) return a.rank - b.rank;
3137
+ if (a.at && b.at) {
3138
+ const c = compareKeys(b.at, a.at);
3139
+ if (c !== 0) return c;
3140
+ } else if (a.at) return -1;
3141
+ else if (b.at) return 1;
3142
+ return byCodePoint(a.id, b.id);
3143
+ });
3144
+ return keyed.map((k) => k.id);
3145
+ }
3146
+ row(id, show, notes) {
3147
+ const b = this.body(id);
3148
+ let row;
3149
+ if (show === "full") row = copy(b);
3150
+ else {
3151
+ row = { id: b.id, type: b.type, name: b.name ?? null };
3152
+ if (show === "first_line" && typeof b.description === "string") {
3153
+ const cut2 = b.description.search(/[\r\n]/);
3154
+ row.description = cut2 < 0 ? b.description : b.description.slice(0, cut2);
3155
+ }
3156
+ }
3157
+ if (notes !== null && own(notes, id)) row.note = notes[id];
3158
+ return row;
3159
+ }
3160
+ };
3161
+ function anchorsOf(lens, r) {
3162
+ const anchors = [];
3163
+ const children = [];
3164
+ const unseen = /* @__PURE__ */ new Set();
3165
+ const seen = /* @__PURE__ */ new Set();
3166
+ for (const field of ANCHOR_FIELDS) {
3167
+ const v = valueOf(lens, field);
3168
+ if (!Array.isArray(v)) continue;
3169
+ for (const id of v) {
3170
+ if (typeof id !== "string" || trimWhiteSpace(id) === "" || seen.has(id)) continue;
3171
+ seen.add(id);
3172
+ if (r.typeOf.get(id) !== ANCHOR_TARGET.get(field)) unseen.add(id);
3173
+ else if (field === "constructs" && r.view.has(id) && isLens(r.byId.get(id))) {
3174
+ if (!r.stubs.has(id)) {
3175
+ children.push(id);
3176
+ continue;
3177
+ }
3178
+ unseen.add(id);
3179
+ }
3180
+ anchors.push(id);
3181
+ }
4481
3182
  }
4482
- /**
4483
- * The body this reader is served: the owner's own view the body as stored; any other reader's with the links
4484
- * it cannot see left out (`trim`); a known-of element's a stub made from that trimmed body: the base fields
4485
- * and the type's public fields kept, every other field of the type it holds at its unset value (`UNSET`; the
4486
- * server's who and door null), no extension key, and `known_of: true`.
4487
- */
4488
- body(id) {
4489
- let b = this.served.get(id);
4490
- if (b !== void 0) return b;
4491
- const el = this.byId.get(id);
4492
- const type = this.typeOf.get(id);
4493
- b = copy(el);
4494
- delete b.x_served_trimmed;
4495
- if (!this.stored) this.trim(type, b);
4496
- if (this.stubs.has(id)) {
4497
- const kinds = FIELD_SCHEMA[type] ?? {};
4498
- const keep = /* @__PURE__ */ new Set([...STUB_FIELDS, ...PUBLIC_FIELDS[type] ?? []]);
4499
- const full = b;
4500
- b = {};
4501
- for (const k of Object.keys(full)) {
4502
- if (keep.has(k)) b[k] = full[k];
4503
- else if (STUB_NULLED.includes(k)) b[k] = null;
4504
- else if (own(kinds, k) && own(UNSET, kinds[k].type)) b[k] = copy(UNSET[kinds[k].type]);
4505
- }
4506
- b.known_of = true;
3183
+ const mark = lens.x_served_trimmed;
3184
+ const trimmed = Array.isArray(mark) && mark.some((f) => typeof f === "string" && ANCHOR_FIELDS.includes(f));
3185
+ return { anchors, children, unseen, anchored: seen.size > 0 || trimmed };
3186
+ }
3187
+ function resolveOne(lens, recipe, r, visited, wall) {
3188
+ const cut2 = /* @__PURE__ */ new Map();
3189
+ const addCut = (id, why) => {
3190
+ if (!cut2.has(id)) cut2.set(id, why);
3191
+ };
3192
+ const { anchors, children, unseen, anchored } = anchorsOf(lens, r);
3193
+ const anchorSet = new Set(anchors);
3194
+ let list = [];
3195
+ const frontier = [];
3196
+ for (const id of anchors) {
3197
+ if (!r.view.has(id) || unseen.has(id)) {
3198
+ if (r.owner) addCut(id, "anchor_not_visible");
3199
+ continue;
4507
3200
  }
4508
- this.served.set(id, b);
4509
- return b;
3201
+ if (visited.has(id)) continue;
3202
+ const why = r.fenceCut(id, recipe);
3203
+ if (why !== "after_as_of") frontier.push(id);
3204
+ if (why !== null) addCut(id, why);
3205
+ else list.push(id);
4510
3206
  }
4511
- /**
4512
- * A whole body as a reader below the owner is served it, as keel's `redact` and `serialize` serve it: every
4513
- * link id the reader cannot see (or that names an element of another type than the field's) left out, a
4514
- * single link to null, a generic pair (a Pin's `element_type` and `element_id`) to the empty pair, `""` and
4515
- * null; a lens's `x_lens.notes` keeps the entries keyed to an anchor it is served or another element it
4516
- * sees. `x_served_trimmed` names what was trimmed only where keel adds it: a Message's `characters` and
4517
- * `narrator`, a lens's anchor fields and `notes` (when an anchor's note went with it), for a contributor
4518
- * or a guest, never the public rung.
4519
- */
4520
- trim(type, b) {
4521
- const sees = (t, target) => typeof t === "string" && this.linkable.has(t) && (target === "any" || this.typeOf.get(t) === target);
4522
- const schema = FIELD_SCHEMA[type] ?? {};
4523
- const isLensBody = isLens(b);
4524
- const anchorsBefore = isLensBody ? new Set(ANCHOR_FIELDS.flatMap((f) => Array.isArray(b[f]) ? b[f] : [])) : null;
4525
- const trimmed = [];
4526
- for (const [field, many] of LINK_FIELDS.get(type) ?? []) {
4527
- if (!own(b, field)) continue;
4528
- const v = b[field];
4529
- const target = schema[field]?.target ?? "any";
4530
- if (many) {
4531
- if (!Array.isArray(v) || v.length === 0) continue;
4532
- const kept = v.filter((t) => sees(t, target));
4533
- if (kept.length !== v.length) trimmed.push(field);
4534
- b[field] = kept;
4535
- } else if (target === "any" && field.endsWith("_id")) {
4536
- const typeField = `${field.slice(0, -3)}_type`;
4537
- if (typeof v !== "string" || v === "" || sees(v, typeof b[typeField] === "string" ? b[typeField] : "")) continue;
4538
- if (own(b, typeField)) b[typeField] = "";
4539
- b[field] = null;
4540
- trimmed.push(field);
4541
- } else if (typeof v === "string" && v !== "" && !sees(v, target)) {
4542
- b[field] = null;
4543
- trimmed.push(field);
3207
+ const passes = (id) => {
3208
+ const why = r.fenceCut(id, recipe) ?? (r.kept(id, recipe) ? null : "types") ?? r.windowCut(id, recipe) ?? r.staleCut(id, recipe, wall);
3209
+ if (why !== null) addCut(id, why);
3210
+ return why === null;
3211
+ };
3212
+ if (!anchored) {
3213
+ const selected = r.order.filter((id) => r.view.has(id) && !visited.has(id) && r.kept(id, recipe));
3214
+ list.push(...r.sort(selected.filter(passes)));
3215
+ } else if (recipe.depth >= 1) {
3216
+ const excluded = (id) => anchorSet.has(id) || visited.has(id);
3217
+ const { reached: hop, edges } = r.reach(frontier, excluded);
3218
+ list.push(...r.sort([...hop].filter(passes)));
3219
+ if (r.owner) for (const id of r.unseen(frontier, edges, excluded)) addCut(id, "not_visible");
3220
+ if (recipe.depth === 2) {
3221
+ const stops = (id) => r.stopsAt(id, recipe) || r.fenceCut(id, recipe) === "after_as_of";
3222
+ for (const id of r.reach(hop, (id2) => excluded(id2) || hop.has(id2), stops).reached) {
3223
+ if ((r.room.has(id) || r.aid.has(id)) && !r.kept(id, recipe)) continue;
3224
+ addCut(id, "hops_not_served");
4544
3225
  }
4545
3226
  }
4546
- let notesGone = false;
4547
- if (anchorsBefore !== null && isBody2(b.x_lens) && isBody2(b.x_lens.notes)) {
4548
- const notes = b.x_lens.notes;
4549
- const served = new Set(ANCHOR_FIELDS.flatMap((f) => Array.isArray(b[f]) ? b[f] : []));
4550
- const kept = {};
4551
- for (const k of Object.keys(notes)) {
4552
- if (served.has(k) || !anchorsBefore.has(k) && this.linkable.has(k)) kept[k] = notes[k];
4553
- else if (anchorsBefore.has(k)) notesGone = true;
4554
- }
4555
- if (Object.keys(kept).length !== Object.keys(notes).length) b.x_lens = { ...b.x_lens, notes: kept };
3227
+ }
3228
+ for (const child of children) {
3229
+ if (visited.has(child)) continue;
3230
+ visited.add(child);
3231
+ const body = r.byId.get(child);
3232
+ const read = readRecipe(body.x_lens);
3233
+ if (!("recipe" in read) || isTemplate(body)) continue;
3234
+ const sub = resolveOne(body, read.recipe, r, visited, wall);
3235
+ const have = new Set(list);
3236
+ list.push(...sub.list.filter((id) => !have.has(id)));
3237
+ for (const [id, why] of sub.cut) addCut(id, why);
3238
+ }
3239
+ const mail = recipe.mail === "none" ? null : mailPart(r, recipe.mail, recipe.budget, wall);
3240
+ if (mail !== null) {
3241
+ const inMail = /* @__PURE__ */ new Set([...mail.unread, ...mail.read]);
3242
+ list = list.filter((id) => !inMail.has(id));
3243
+ }
3244
+ for (const id of list.slice(recipe.budget)) cut2.set(id, "budget");
3245
+ list = list.slice(0, recipe.budget);
3246
+ for (const id of list) cut2.delete(id);
3247
+ return { list, cut: cut2, mail };
3248
+ }
3249
+ function mailPart(r, mode, budget, clock) {
3250
+ const empty = { unread: [], read: [], rows: [], cut: {}, totals: { unread: 0, read: 0 } };
3251
+ if (r.character === null || r.seenRung === "public") return empty;
3252
+ const inView = r.order.filter((id) => r.view.has(id));
3253
+ const messages = inView.filter((id) => !r.stubs.has(id)).map((id) => r.body(id)).filter((b) => isMessage(b));
3254
+ const relations = inView.filter((id) => r.typeOf.get(id) === "relation").map((id) => r.body(id));
3255
+ const mark = readMarkOf(relations, r.character, r.members);
3256
+ const mine = unreadFor(messages, r.character, null, r.members);
3257
+ const unread = new Set(unreadFor(messages, r.character, mark, r.members));
3258
+ const lower = [clock[0] - MAIL_SECONDS, clock[1]];
3259
+ const inWindow = mine.filter((m) => {
3260
+ const at = timeKey(m.created_at);
3261
+ return at !== null && compareKeys(at, lower) >= 0;
3262
+ });
3263
+ const keptMail = inWindow.slice(Math.max(0, inWindow.length - budget));
3264
+ const cut2 = {};
3265
+ if (inWindow.length > keptMail.length) cut2.budget = inWindow.length - keptMail.length;
3266
+ if (mine.length > inWindow.length) cut2.window = mine.length - inWindow.length;
3267
+ return {
3268
+ unread: keptMail.filter((m) => unread.has(m)).map((m) => m.id),
3269
+ read: keptMail.filter((m) => !unread.has(m)).map((m) => m.id),
3270
+ rows: keptMail.map((m) => mode === "all" || unread.has(m) ? copy(m) : { id: m.id, name: m.name ?? null, narrator: m.narrator ?? null, created_at: m.created_at ?? null }),
3271
+ cut: cut2,
3272
+ totals: { unread: unread.size, read: mine.length - unread.size }
3273
+ };
3274
+ }
3275
+ var NOTHING = () => ({ kept: [], rows: [], cut: {}, notesIgnored: 0, mail: null, unreadable: null });
3276
+ function checkReader(reader, where) {
3277
+ if (!isBody2(reader) || !["owner", "contributor", "guest", "public"].includes(reader.rung)) {
3278
+ throw new TypeError(`${where}: a reader is an object whose rung is owner, contributor, guest or public; got ${JSON.stringify(reader) ?? String(reader)}.`);
3279
+ }
3280
+ if (reader.as !== void 0 && reader.as !== null) checkReader(reader.as, `${where}.as`);
3281
+ }
3282
+ function resolveLens(world, lens, reader, options) {
3283
+ if (options !== void 0 && options !== null && !isBody2(options)) {
3284
+ throw new TypeError(`resolveLens: options is an object, such as { asOf: 1200 }; got ${JSON.stringify(options) ?? typeof options}.`);
3285
+ }
3286
+ refuseUnknownOptions("resolveLens", options, LENS_OPTION_KEYS);
3287
+ const opts = isBody2(options) ? options : {};
3288
+ if (!isBody2(world) || !Array.isArray(world.elements)) {
3289
+ throw new TypeError("resolveLens: world is an object with an elements list.");
3290
+ }
3291
+ checkReader(reader, "resolveLens: reader");
3292
+ const { asOf, clock } = readingDate("resolveLens", world, opts);
3293
+ if (typeof lens !== "string" && !isBody2(lens)) throw new TypeError("resolveLens: lens is a lens body or its id.");
3294
+ return lensReading(new Reading(world, reader, asOf), lens, clock).reading;
3295
+ }
3296
+ function readingDate(fn, world, opts) {
3297
+ const asOfV = valueOf(opts, "asOf");
3298
+ if (asOfV !== null && whole(asOfV) === null) throw new TypeError(`${fn}: asOf is a whole number; got ${JSON.stringify(asOfV)}.`);
3299
+ const clockV = valueOf(opts, "clock");
3300
+ if (clockV !== null && timeKey(clockV) === null) throw new TypeError(`${fn}: clock is a date-time; got ${JSON.stringify(clockV)}.`);
3301
+ const asOf = asOfV !== null ? asOfV : whole(world.now) ?? whole(world.time_current) ?? whole(world.time_range_current);
3302
+ return { asOf, clock: clockV };
3303
+ }
3304
+ function lensReading(r, lens, clockV) {
3305
+ const none = { reading: NOTHING(), cutById: /* @__PURE__ */ new Map() };
3306
+ let body;
3307
+ if (typeof lens === "string") body = r.view.has(lens) && !r.stubs.has(lens) ? r.byId.get(lens) : null;
3308
+ else body = lens;
3309
+ if (body === null || !isLens(body)) return none;
3310
+ const read = readRecipe(body.x_lens);
3311
+ if (!("recipe" in read)) return { ...none, reading: { ...NOTHING(), unreadable: read.bad } };
3312
+ if (isTemplate(body)) return none;
3313
+ const recipe = read.recipe;
3314
+ const wall = timeKey(clockV ?? (/* @__PURE__ */ new Date()).toISOString());
3315
+ const visited = /* @__PURE__ */ new Set();
3316
+ if (typeof body.id === "string") visited.add(body.id);
3317
+ const { list: keep, cut: cut2, mail } = resolveOne(body, recipe, r, visited, wall);
3318
+ const { anchors, unseen } = anchorsOf(body, r);
3319
+ const resolved = new Set(anchors.filter((id) => r.view.has(id) && !unseen.has(id)));
3320
+ const rows = keep.map((id) => r.row(id, recipe.show, resolved.has(id) ? recipe.notes : null));
3321
+ const counts = {};
3322
+ for (const why of CUT_REASONS) {
3323
+ if (OWNER_ONLY.has(why) && !r.owner) continue;
3324
+ let n = 0;
3325
+ for (const w of cut2.values()) if (w === why) n++;
3326
+ if (n > 0) counts[why] = n;
3327
+ }
3328
+ const notesIgnored = Object.keys(recipe.notes).filter((k) => !anchors.includes(k) && r.view.has(k)).length;
3329
+ return { reading: { kept: keep, rows, cut: counts, notesIgnored, mail, unreadable: null }, cutById: cut2 };
3330
+ }
3331
+
3332
+ // src/charter.ts
3333
+ var SKILL_MAX = 5;
3334
+ var ID = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/g;
3335
+ var BREAK = /\r\n|\r|\n/;
3336
+ function firstLine(text2) {
3337
+ if (typeof text2 !== "string") return "";
3338
+ return trimWhiteSpace(trimWhiteSpace(text2).split(BREAK, 1)[0]);
3339
+ }
3340
+ function newest(ids, r) {
3341
+ let best = null;
3342
+ let bestAt = null;
3343
+ for (const id of ids) {
3344
+ const at = timeKey(r.byId.get(id).created_at);
3345
+ if (best !== null) {
3346
+ const c = at && bestAt ? compareKeys(at, bestAt) : at ? 1 : bestAt ? -1 : 0;
3347
+ if (c < 0 || c === 0 && byCodePoint(id, best) < 0) continue;
4556
3348
  }
4557
- if (this.seenRung === "public") return;
4558
- const named = isMessage(b) ? MESSAGE_ADDRESSING.filter((f) => trimmed.includes(f)) : isLensBody ? [...ANCHOR_FIELDS.filter((f) => trimmed.includes(f)), ...notesGone ? ["notes"] : []] : [];
4559
- if (named.length > 0) b.x_served_trimmed = named;
3349
+ best = id;
3350
+ bestAt = at;
3351
+ }
3352
+ return best;
3353
+ }
3354
+ function idsIn(text2) {
3355
+ const out = [];
3356
+ if (typeof text2 !== "string") return out;
3357
+ for (const m of text2.matchAll(ID)) {
3358
+ const id = m[0].toLowerCase();
3359
+ if (!out.includes(id)) out.push(id);
4560
3360
  }
4561
- /**
4562
- * One hop from each element of `from`, both ways, and on through each Relation it lands on to that Relation's
4563
- * parties. Nothing hops out of a stub or a room element, nor out of an element `stops` names.
4564
- */
4565
- reach(from, excluded, stops) {
4566
- const landed = /* @__PURE__ */ new Set();
4567
- for (const f of from) {
4568
- if (this.stubs.has(f) || this.room.has(f) || stops !== void 0 && stops(f)) continue;
4569
- for (const t of [...this.links(f), ...this.inView.get(f) ?? []]) if (!excluded(t)) landed.add(t);
4570
- }
4571
- const reached = new Set(landed);
4572
- const edges = [];
4573
- for (const r of landed) {
4574
- if (this.typeOf.get(r) !== "relation" || this.stubs.has(r) || this.room.has(r)) continue;
4575
- edges.push(r);
4576
- for (const t of this.links(r)) if (!excluded(t)) reached.add(t);
3361
+ return out;
3362
+ }
3363
+ function hubsOf(id, r) {
3364
+ const body = r.body(id);
3365
+ if (body.known_of === true) return [];
3366
+ const schema = FIELD_SCHEMA.construct;
3367
+ const out = [];
3368
+ const seen = /* @__PURE__ */ new Set([`construct/${id}`]);
3369
+ for (const [field, many] of LINK_FIELDS.get("construct") ?? []) {
3370
+ const v = body[field];
3371
+ const target = schema[field]?.target ?? "";
3372
+ for (const t of many ? Array.isArray(v) ? v : [] : [v]) {
3373
+ if (typeof t !== "string" || t === "" || r.proposed.has(t) || seen.has(`${target}/${t}`)) continue;
3374
+ seen.add(`${target}/${t}`);
3375
+ out.push({ type: target, id: t });
4577
3376
  }
4578
- return { reached, edges };
4579
3377
  }
4580
- /** What one hop from `from` would reach in the owner's world that this reader's view leaves out (the owner's count). */
4581
- unseen(from, landedRelations, excluded) {
4582
- const out = /* @__PURE__ */ new Set();
4583
- const consider = (t) => {
4584
- if (this.byId.has(t) && !this.view.has(t) && !excluded(t)) out.add(t);
3378
+ return out;
3379
+ }
3380
+ var NONE = () => ({ charter: null, guide: null, domains: [] });
3381
+ function charterOf(world, reader) {
3382
+ if (!isBody2(world) || !Array.isArray(world.elements)) {
3383
+ throw new TypeError("charterOf: world is an object with an elements list.");
3384
+ }
3385
+ checkReader(reader, "charterOf: reader");
3386
+ const r = new Reading(world, reader, null);
3387
+ if (r.seenRung === "public" && world.open !== true) return NONE();
3388
+ const seen = (pair) => r.order.filter((id) => r.view.has(id) && r.aid.get(id) === pair);
3389
+ const out = NONE();
3390
+ const law = newest(seen("law/charter"), r);
3391
+ if (law !== null) {
3392
+ const el = r.byId.get(law);
3393
+ const rules = el.x_checks_rules;
3394
+ const skill = idsIn(el.description).filter((id) => r.view.has(id) && r.typeOf.get(id) === "object").slice(0, SKILL_MAX);
3395
+ out.charter = {
3396
+ id: law,
3397
+ name: typeof el.name === "string" ? el.name : "",
3398
+ rules: Array.isArray(rules) ? JSON.parse(JSON.stringify(rules)) : [],
3399
+ skill
4585
3400
  };
4586
- for (const f of from) {
4587
- if (this.stubs.has(f) || this.room.has(f)) continue;
4588
- for (const t of this.fullLinks(f)) consider(t);
4589
- for (const t of this.inFull.get(f) ?? []) consider(t);
4590
- }
4591
- for (const r of landedRelations) for (const t of this.fullLinks(r)) consider(t);
4592
- return out;
4593
3401
  }
4594
- date(id) {
4595
- const field = DATE_FIELD[this.typeOf.get(id)];
4596
- if (field === void 0) return void 0;
4597
- return whole(this.byId.get(id)[field]);
3402
+ const guide = newest(seen("construct/guide"), r);
3403
+ if (guide !== null) {
3404
+ const el = r.byId.get(guide);
3405
+ out.guide = { id: guide, name: typeof el.name === "string" ? el.name : "" };
4598
3406
  }
4599
- /** The fence (keel's `as_of`, on the element's own date) and `undated`. */
4600
- fenceCut(id, recipe) {
4601
- const d = this.date(id);
4602
- if (d === void 0) return null;
4603
- if (d === null) return recipe.undated === "exclude" ? "undated" : null;
4604
- return this.asOf !== null && d > this.asOf ? "after_as_of" : null;
3407
+ const domains = new Set(seen("construct/domain"));
3408
+ const order = [];
3409
+ const named = guide === null ? void 0 : r.body(guide).constructs;
3410
+ for (const id of Array.isArray(named) ? named : []) {
3411
+ if (typeof id === "string" && domains.has(id) && !order.includes(id)) order.push(id);
4605
3412
  }
4606
- /**
4607
- * `window`, or `from` and `to` (closed-open). A `to` after `as_of` is clipped: the fence stays the upper
4608
- * edge, so an element dated `as_of` is kept, and every element such a `to` would cut is already cut by the
4609
- * fence (`after_as_of`, counted first).
4610
- */
4611
- windowCut(id, recipe) {
4612
- const d = this.date(id);
4613
- if (d === void 0 || d === null) return null;
4614
- if (recipe.window !== null && this.asOf !== null && d < this.asOf - recipe.window) return "window";
4615
- if (recipe.from !== null && d < recipe.from) return "window";
4616
- if (recipe.to !== null && d >= recipe.to) return "window";
4617
- return null;
3413
+ const nameOf = (id) => {
3414
+ const name = r.body(id).name;
3415
+ return typeof name === "string" ? name : "";
3416
+ };
3417
+ const rest = [...domains].filter((id) => !order.includes(id)).sort((a, b) => byCodePoint(fold(nameOf(a)), fold(nameOf(b))) || byCodePoint(a, b));
3418
+ out.domains = [...order, ...rest].map((id) => ({
3419
+ id,
3420
+ name: nameOf(id),
3421
+ sentence: firstLine(r.body(id).description),
3422
+ hubs: hubsOf(id, r)
3423
+ }));
3424
+ return out;
3425
+ }
3426
+ function domainsOf(world, reader) {
3427
+ return charterOf(world, reader).domains;
3428
+ }
3429
+
3430
+ // src/graph.ts
3431
+ var GRAPH_OPTION_KEYS = ["lens", "asOf", "clock", "rooms", "hidden", "proposed", "mapSpace"];
3432
+ var DECLARED_LINKS = ["x_lens_leads_to", "x_spine_depends_on"];
3433
+ var MAP_SPACE = /* @__PURE__ */ new Set(["map", "pin", "marker"]);
3434
+ var GRAPH_REASONS = [...CUT_REASONS, "room", "hidden", "proposed", "map_space", "reading_aid", "outside_lens"];
3435
+ var GRAPH_OWNER_ONLY = /* @__PURE__ */ new Set([...OWNER_ONLY, "hidden", "proposed"]);
3436
+ function flag(opts, key) {
3437
+ const v = valueOf(opts, key);
3438
+ if (v !== null && typeof v !== "boolean") throw new TypeError(`worldGraph: ${key} is a boolean; got ${JSON.stringify(v)}.`);
3439
+ return v === true;
3440
+ }
3441
+ function worldGraph(world, reader, options) {
3442
+ if (options !== void 0 && options !== null && !isBody2(options)) {
3443
+ throw new TypeError(`worldGraph: options is an object, such as { rooms: true }; got ${JSON.stringify(options) ?? typeof options}.`);
4618
3444
  }
4619
- /**
4620
- * `changed_within`: changed longer ago than that many days before the reading's wall clock. The time read is the
4621
- * element's `updated_at`, or for a folder element (one carrying `server_updated_at` or `local_updated_at`) the
4622
- * newer of those two; an element with no readable time is never cut.
4623
- */
4624
- staleCut(id, recipe, wall) {
4625
- if (recipe.changedWithin === null) return null;
4626
- const at = changedAt(this.byId.get(id));
4627
- if (at === null) return null;
4628
- return compareKeys(at, [wall[0] - recipe.changedWithin * 86400, wall[1]]) < 0 ? "stale" : null;
3445
+ refuseUnknownOptions("worldGraph", options, GRAPH_OPTION_KEYS);
3446
+ const opts = isBody2(options) ? options : {};
3447
+ if (!isBody2(world) || !Array.isArray(world.elements)) {
3448
+ throw new TypeError("worldGraph: world is an object with an elements list.");
4629
3449
  }
4630
- /** Whether `types` keeps the element: a room element or a reading aid only when its pair is named, any other by its type (or any type when `types` is empty). */
4631
- kept(id, recipe) {
4632
- if (this.room.has(id)) {
4633
- const el = this.byId.get(id);
4634
- return recipe.types !== null && recipe.types.has(`${fold(el.type)}/${fold(el.supertype)}`);
4635
- }
4636
- const aid = this.aid.get(id);
4637
- if (aid !== void 0) return recipe.types !== null && recipe.types.has(aid);
4638
- return recipe.types === null || recipe.types.has(this.typeOf.get(id));
3450
+ checkReader(reader, "worldGraph: reader");
3451
+ const flags = {
3452
+ room: flag(opts, "rooms"),
3453
+ hidden: flag(opts, "hidden"),
3454
+ proposed: flag(opts, "proposed"),
3455
+ map_space: flag(opts, "mapSpace")
3456
+ };
3457
+ const seenRung = reader.rung === "owner" && reader.as != null ? reader.as.rung : reader.rung;
3458
+ for (const [kind, key] of [["hidden", "hidden"], ["proposed", "proposed"]]) {
3459
+ if (flags[kind] && seenRung !== "owner") throw new TypeError(`worldGraph: ${key} is the owner's alone; a ${seenRung} reader may not ask it.`);
4639
3460
  }
4640
- /** Rule 4: a reading aid a hop reached is not hopped out of unless `types` names its pair. */
4641
- stopsAt(id, recipe) {
4642
- const aid = this.aid.get(id);
4643
- return aid !== void 0 && !(recipe.types !== null && recipe.types.has(aid));
3461
+ if (seenRung === "public") {
3462
+ for (const [kind, key] of [["room", "rooms"], ["map_space", "mapSpace"]]) {
3463
+ if (flags[kind]) throw new TypeError(`worldGraph: a public reader takes no flag; it asked ${key}.`);
3464
+ }
4644
3465
  }
4645
- /** Rule 5's order past the anchors: the schema's type order, newest `updated_at` first (an unreadable time last), then by id. */
4646
- sort(ids) {
4647
- const keyed = [...ids].map((id) => ({ id, rank: TYPE_RANK.get(this.typeOf.get(id)), at: timeKey(this.byId.get(id).updated_at) }));
4648
- keyed.sort((a, b) => {
4649
- if (a.rank !== b.rank) return a.rank - b.rank;
4650
- if (a.at && b.at) {
4651
- const c = compareKeys(b.at, a.at);
4652
- if (c !== 0) return c;
4653
- } else if (a.at) return -1;
4654
- else if (b.at) return 1;
4655
- return byCodePoint2(a.id, b.id);
4656
- });
4657
- return keyed.map((k) => k.id);
3466
+ const { asOf, clock } = readingDate("worldGraph", world, opts);
3467
+ const lens = valueOf(opts, "lens");
3468
+ if (lens !== null && typeof lens !== "string" && !isBody2(lens)) throw new TypeError("worldGraph: lens is a lens body or its id.");
3469
+ const r = new Reading(world, reader, asOf);
3470
+ const seenOwner = r.seenRung === "owner";
3471
+ const kinds = (id) => {
3472
+ const out = [];
3473
+ if (r.room.has(id)) out.push("room");
3474
+ if (r.hidden.has(id)) out.push("hidden");
3475
+ if (r.proposed.has(id)) out.push("proposed");
3476
+ if (MAP_SPACE.has(r.typeOf.get(id))) out.push("map_space");
3477
+ if (r.aid.has(id)) out.push("reading_aid");
3478
+ return out;
3479
+ };
3480
+ const brought = (k) => k !== "reading_aid" && flags[k];
3481
+ const candidate = (id) => r.view.has(id) || seenOwner && r.proposed.has(id);
3482
+ const nodeIds = /* @__PURE__ */ new Set();
3483
+ let cut2;
3484
+ let reasonOf;
3485
+ let unreadable = null;
3486
+ if (lens !== null) {
3487
+ const { reading, cutById } = lensReading(r, lens, clock);
3488
+ for (const id of reading.kept) nodeIds.add(id);
3489
+ cut2 = { ...reading.cut };
3490
+ unreadable = reading.unreadable;
3491
+ reasonOf = (id) => cutById.get(id) ?? (r.view.has(id) ? "outside_lens" : "not_visible");
3492
+ } else {
3493
+ const outBy = (id) => kinds(id).find((k) => !brought(k)) ?? null;
3494
+ const counts = /* @__PURE__ */ new Map();
3495
+ for (const id of r.order) {
3496
+ if (!candidate(id)) continue;
3497
+ const why = outBy(id);
3498
+ if (why === null) nodeIds.add(id);
3499
+ else counts.set(why, (counts.get(why) ?? 0) + 1);
3500
+ }
3501
+ cut2 = tally(counts, r.owner);
3502
+ reasonOf = (id) => candidate(id) ? outBy(id) : "not_visible";
4658
3503
  }
4659
- row(id, show, notes) {
4660
- const b = this.body(id);
4661
- let row;
4662
- if (show === "full") row = copy(b);
4663
- else {
4664
- row = { id: b.id, type: b.type, name: b.name ?? null };
4665
- if (show === "first_line" && typeof b.description === "string") {
4666
- const cut2 = b.description.search(/[\r\n]/);
4667
- row.description = cut2 < 0 ? b.description : b.description.slice(0, cut2);
3504
+ const ids = [...nodeIds].sort(byCodePoint);
3505
+ const nodes = ids.map((id) => {
3506
+ const el = r.byId.get(id);
3507
+ const type = r.typeOf.get(id);
3508
+ const node = {
3509
+ id,
3510
+ type,
3511
+ name: valueOf(el, "name"),
3512
+ family: ELEMENT_GROUPS[type],
3513
+ icon: ELEMENT_ICONS[type]
3514
+ };
3515
+ const marks2 = kinds(id).filter((k) => k !== "map_space" && k !== "reading_aid");
3516
+ if (marks2.length > 0) node.marks = marks2;
3517
+ if (r.stubs.has(id)) node.known_of = true;
3518
+ return node;
3519
+ });
3520
+ const edges = [];
3521
+ const cutEdges = /* @__PURE__ */ new Map();
3522
+ const visit = (source, field, target, index) => {
3523
+ if (typeof target !== "string" || !r.byId.has(target)) return;
3524
+ if (nodeIds.has(target)) {
3525
+ edges.push({ source, field, target, index });
3526
+ return;
3527
+ }
3528
+ const why = reasonOf(target);
3529
+ if (why !== null) cutEdges.set(why, (cutEdges.get(why) ?? 0) + 1);
3530
+ };
3531
+ for (const source of ids) {
3532
+ if (r.stubs.has(source)) continue;
3533
+ const el = r.byId.get(source);
3534
+ for (const [field, many, target] of LINK_FIELDS.get(r.typeOf.get(source)) ?? []) {
3535
+ if (target === "any") continue;
3536
+ const v = el[field];
3537
+ const to = linkTarget(el, field, target);
3538
+ const list = many ? Array.isArray(v) ? v : [] : [v];
3539
+ let served = 0;
3540
+ for (let i = 0; i < list.length; i++) {
3541
+ const t = list[i];
3542
+ const typed = typeof t === "string" && r.typeOf.get(t) === to;
3543
+ if (typed) visit(source, field, t, seenOwner ? i : served);
3544
+ if (seenOwner || typed && r.linkable.has(t)) served++;
4668
3545
  }
4669
3546
  }
4670
- if (notes !== null && own(notes, id)) row.note = notes[id];
4671
- return row;
4672
- }
4673
- };
4674
- function anchorsOf(lens, r) {
4675
- const anchors = [];
4676
- const children = [];
4677
- const unseen = /* @__PURE__ */ new Set();
4678
- const seen = /* @__PURE__ */ new Set();
4679
- for (const field of ANCHOR_FIELDS) {
4680
- const v = valueOf(lens, field);
4681
- if (!Array.isArray(v)) continue;
4682
- for (const id of v) {
4683
- if (typeof id !== "string" || id === "" || seen.has(id)) continue;
4684
- seen.add(id);
4685
- if (r.typeOf.get(id) !== ANCHOR_TARGET.get(field)) unseen.add(id);
4686
- else if (field === "constructs" && r.view.has(id) && isLens(r.byId.get(id))) {
4687
- if (!r.stubs.has(id)) {
4688
- children.push(id);
4689
- continue;
4690
- }
4691
- unseen.add(id);
4692
- }
4693
- anchors.push(id);
3547
+ for (const field of DECLARED_LINKS) {
3548
+ const v = el[field];
3549
+ if (!Array.isArray(v)) continue;
3550
+ for (let i = 0; i < v.length; i++) visit(source, field, v[i], i);
4694
3551
  }
4695
3552
  }
4696
- const mark = lens.x_served_trimmed;
4697
- const trimmed = Array.isArray(mark) && mark.some((f) => typeof f === "string" && ANCHOR_FIELDS.includes(f));
4698
- return { anchors, children, unseen, anchored: seen.size > 0 || trimmed };
3553
+ edges.sort((a, b) => byCodePoint(a.source, b.source) || byCodePoint(a.field, b.field) || a.index - b.index);
3554
+ return { nodes, edges, edgesCut: tally(cutEdges, r.owner), cut: cut2, unreadable };
4699
3555
  }
4700
- function resolveOne(lens, recipe, r, visited, wall) {
4701
- const cut2 = /* @__PURE__ */ new Map();
4702
- const addCut = (id, why) => {
4703
- if (!cut2.has(id)) cut2.set(id, why);
4704
- };
4705
- const { anchors, children, unseen, anchored } = anchorsOf(lens, r);
4706
- const anchorSet = new Set(anchors);
4707
- let list = [];
4708
- const frontier = [];
4709
- for (const id of anchors) {
4710
- if (visited.has(id)) continue;
4711
- if (!r.view.has(id) || unseen.has(id)) {
4712
- addCut(id, "anchor_not_visible");
4713
- continue;
4714
- }
4715
- const why = r.fenceCut(id, recipe);
4716
- if (why !== "after_as_of") frontier.push(id);
4717
- if (why !== null) addCut(id, why);
4718
- else list.push(id);
3556
+ function tally(counts, owner) {
3557
+ const out = {};
3558
+ for (const why of GRAPH_REASONS) {
3559
+ if (GRAPH_OWNER_ONLY.has(why) && !owner) continue;
3560
+ const n = counts.get(why) ?? 0;
3561
+ if (n > 0) out[why] = n;
4719
3562
  }
4720
- const passes = (id) => {
4721
- const why = r.fenceCut(id, recipe) ?? (r.kept(id, recipe) ? null : "types") ?? r.windowCut(id, recipe) ?? r.staleCut(id, recipe, wall);
4722
- if (why !== null) addCut(id, why);
4723
- return why === null;
3563
+ return out;
3564
+ }
3565
+ function degreeOf(graph) {
3566
+ if (!isBody2(graph) || !Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
3567
+ throw new TypeError("degreeOf: graph is what worldGraph answers, an object with nodes and edges lists.");
3568
+ }
3569
+ const count = new Map(graph.nodes.map((n) => [n.id, 0]));
3570
+ const add = (id) => {
3571
+ const n = count.get(id);
3572
+ if (n !== void 0) count.set(id, n + 1);
4724
3573
  };
4725
- if (!anchored) {
4726
- const selected = r.order.filter((id) => r.view.has(id) && !visited.has(id) && r.kept(id, recipe));
4727
- list.push(...r.sort(selected.filter(passes)));
4728
- } else if (recipe.depth >= 1) {
4729
- const excluded = (id) => anchorSet.has(id) || visited.has(id);
4730
- const { reached: hop, edges } = r.reach(frontier, excluded);
4731
- list.push(...r.sort([...hop].filter(passes)));
4732
- if (r.owner) for (const id of r.unseen(frontier, edges, excluded)) addCut(id, "not_visible");
4733
- if (recipe.depth === 2) {
4734
- const stops = (id) => r.stopsAt(id, recipe) || r.fenceCut(id, recipe) === "after_as_of";
4735
- for (const id of r.reach(hop, (id2) => excluded(id2) || hop.has(id2), stops).reached) {
4736
- if ((r.room.has(id) || r.aid.has(id)) && !r.kept(id, recipe)) continue;
4737
- addCut(id, "hops_not_served");
4738
- }
4739
- }
3574
+ for (const e of graph.edges) {
3575
+ add(e.source);
3576
+ if (e.target !== e.source) add(e.target);
4740
3577
  }
4741
- for (const child of children) {
4742
- if (visited.has(child)) continue;
4743
- visited.add(child);
4744
- const body = r.byId.get(child);
4745
- const read = readRecipe(body.x_lens);
4746
- if (!("recipe" in read) || isTemplate(body)) continue;
4747
- const sub = resolveOne(body, read.recipe, r, visited, wall);
4748
- const have = new Set(list);
4749
- list.push(...sub.list.filter((id) => !have.has(id)));
4750
- for (const [id, why] of sub.cut) addCut(id, why);
3578
+ return Object.fromEntries(count);
3579
+ }
3580
+ function outDegreeOf(graph) {
3581
+ if (!isBody2(graph) || !Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
3582
+ throw new TypeError("outDegreeOf: graph is what worldGraph answers, an object with nodes and edges lists.");
4751
3583
  }
4752
- const mail = recipe.mail === "none" ? null : mailPart(r, recipe.mail, recipe.budget, wall);
4753
- if (mail !== null) {
4754
- const inMail = /* @__PURE__ */ new Set([...mail.unread, ...mail.read]);
4755
- list = list.filter((id) => !inMail.has(id));
3584
+ const targets = new Map(graph.nodes.map((n) => [n.id, /* @__PURE__ */ new Set()]));
3585
+ for (const e of graph.edges) {
3586
+ if (e.target !== e.source) targets.get(e.source)?.add(e.target);
4756
3587
  }
4757
- for (const id of list.slice(recipe.budget)) cut2.set(id, "budget");
4758
- list = list.slice(0, recipe.budget);
4759
- for (const id of list) cut2.delete(id);
4760
- return { list, cut: cut2, mail };
3588
+ return Object.fromEntries([...targets].map(([id, t]) => [id, t.size]));
4761
3589
  }
4762
- function mailPart(r, mode, budget, clock) {
4763
- const empty = { unread: [], read: [], rows: [], cut: {}, totals: { unread: 0, read: 0 } };
4764
- if (r.character === null || r.seenRung === "public") return empty;
4765
- const inView = r.order.filter((id) => r.view.has(id));
4766
- const messages = inView.filter((id) => !r.stubs.has(id)).map((id) => r.body(id)).filter((b) => isMessage(b));
4767
- const relations = inView.filter((id) => r.typeOf.get(id) === "relation").map((id) => r.body(id));
4768
- const mark = readMarkOf(relations, r.character, r.members);
4769
- const mine = unreadFor(messages, r.character, null, r.members);
4770
- const unread = new Set(unreadFor(messages, r.character, mark, r.members));
4771
- const lower = [clock[0] - MAIL_SECONDS, clock[1]];
4772
- const inWindow = mine.filter((m) => {
4773
- const at = timeKey(m.created_at);
4774
- return at !== null && compareKeys(at, lower) >= 0;
4775
- });
4776
- const keptMail = inWindow.slice(Math.max(0, inWindow.length - budget));
4777
- const cut2 = {};
4778
- if (inWindow.length > keptMail.length) cut2.budget = inWindow.length - keptMail.length;
4779
- if (mine.length > inWindow.length) cut2.window = mine.length - inWindow.length;
4780
- return {
4781
- unread: keptMail.filter((m) => unread.has(m)).map((m) => m.id),
4782
- read: keptMail.filter((m) => !unread.has(m)).map((m) => m.id),
4783
- rows: keptMail.map((m) => mode === "all" || unread.has(m) ? copy(m) : { id: m.id, name: m.name ?? null, narrator: m.narrator ?? null, created_at: m.created_at ?? null }),
4784
- cut: cut2,
4785
- totals: { unread: unread.size, read: mine.length - unread.size }
3590
+
3591
+ // src/world-file.ts
3592
+ import { Inflate, inflateSync, zipSync } from "fflate";
3593
+
3594
+ // src/nfc-tables.generated.ts
3595
+ var NFC_CLASS_RUNS = "lc.l.6e,lx..6g,ly.4.64,m2..6g,m3..60,m4.5.64,m9.2.5m,mb.4.64,mf.2.5m,mh.b.64,ms.5.1,mx.4.64,n1.8.6e,n9..6o,na..6e,nb.3.64,ne.3.6e,nh.2.64,nk.3.6e,nn.4.64,nr..6e,ns..6g,nt.2.64,nv..6e,nw..6h,nx.2.6i,nz..6h,o0.2.6i,o2..6h,o3.d.6e,w3.5.6e,13l..64,13m.4.6e,13q..64,13r.3.6e,13u..66,13v..64,13w.6.6e,142.6.64,148.2.6e,14a..64,14b.2.6e,14d..66,14e..6c,14f..6e,14g..a,14h..b,14i..c,14j..d,14k..e,14l..f,14m..g,14n..h,14o..i,14p.2.j,14r..k,14s..l,14t..m,14v..n,14x..o,14y..p,150..6e,151..64,153..i,174.8.6e,17c..u,17d..v,17e..w,18r..r,18s..s,18t..t,18u..u,18v..v,18w..w,18x..x,18y..y,18z.2.6e,191.2.64,193.5.6e,198..64,199.2.6e,19b..64,19s..z,1cm.7.6e,1cv.4.6e,1cz..64,1d0..6e,1d3.2.6e,1d6..64,1d7.2.6e,1d9..64,1e9..10,1f4..6e,1f5..64,1f6.2.6e,1f8..64,1f9.2.6e,1fb.3.64,1fe..6e,1ff.2.64,1fh..6e,1fi..64,1fj.3.6e,1fm..64,1fn..6e,1fo..64,1fp..6e,1fq..64,1fr..6e,1fs..64,1ft.2.6e,1kb.7.6e,1ki..64,1kj..6e,1kt..64,1li.4.6e,1ln.9.6e,1lx.3.6e,1m1.5.6e,1nd.3.64,1p4..6e,1p5.3.64,1p8.4.6e,1qi.5.6e,1qn.5.64,1qs.e.6e,1r7..64,1r8.2.6e,1ra..64,1rb.2.6e,1rd..64,1re.3.6e,1rh.3.64,1rk..r,1rl..s,1rm..t,1rn.3.6e,1rq..64,1rr.2.6e,1rt.2.64,1rv.5.6e,1to..7,1u5..9,1u9..6e,1ua..64,1ub.2.6e,1x8..7,1xp..9,1z2..6e,20s..7,219..9,24c..7,24t..9,27w..7,28d..9,2bx..9,2f0..7,2fh..9,2fp..2c,2fq..2j,2ik..7,2j1..9,2m3.2.9,2ml..9,2q2..9,2t4.2.2v,2t6..9,2tk.4.2z,2wo.2.3a,2wq..9,2x4.4.3e,2zc.2.64,305..64,307..64,309..60,31t..3l,31u..3m,31w..3o,322.4.3m,328..3m,32a.2.6e,32c..9,32e.2.6e,346..64,37b..7,37d.2.9,39p..64,3tp.3.6e,4k4.2.9,4l0..9,4pe..9,4pp..6e,4vd..6c,4zd..66,4ze..6e,4zf..64,55j..6e,55k..64,57k..9,585.8.6e,58f..64,59s.5.6e,59x.6.64,5a3.2.6e,5a5..64,5a7.2.64,5a9.2.6e,5ab.2.64,5ad.5.6e,5ai..64,5aj.4.6e,5dg..7,5dw..9,5ez..6e,5f0..64,5f1.7.6e,5gq.2.9,5ie..7,5iq.2.9,5kn..7,5ow.3.6e,5p0..1,5p1.5.64,5p6.2.6e,5p8.4.64,5pc..6e,5pe.7.1,5pp..64,5pw..6e,5q0.2.6e,5vk.2.6e,5vm..64,5vn.7.6e,5vu..64,5vv.2.6e,5vx..6i,5vy..5y,5vz..64,5w0..5m,5w1.11.6e,5x2..6g,5x3.2.6c,5x5..64,5x6..62,5x7..6e,5x8..6h,5x9..64,5xa..6e,5xb..64,6hc.2.6e,6he.2.1,6hg.4.6e,6hk.3.1,6hn.2.6e,6ht..6e,6hx.2.1,6hz..6e,6i0..64,6i1..6e,6i2.2.1,6i4.4.64,6i8..6e,8vj.3.6e,8zj..9,928.w.6e,9ii..62,9ij..6c,9ik..6g,9il..66,9im.2.68,9ll.2.8,wvj..6e,wvo.a.6e,wwu.2.6e,wz4.2.6e,x6u..9,x7w..9,xc4..9,xcw.i.6e,xez.3.64,xg3..9,xir..7,xj4..9,xps..6e,xpu.2.6e,xpw..64,xpz.2.6e,xq6.2.6e,xq9..6e,xrq..9,xyl..9,1dlq..q,1e74.7.6e,1e7b.7.64,1e7i.2.6e,1eyl..64,1f4w..64,1f92.5.6e,1gjx..64,1gjz..6e,1gl4..6e,1gl5..1,1gl6..64,1glb..9,1gpx..6e,1gpy..64,1h5w.4.6e,1hgr.2.6e,1hj1.3.64,1hl2.2.64,1hl4.3.6e,1hl7..64,1hl8..6e,1hl9.4.64,1hmq..6e,1hmr..64,1hms..6e,1hmt..64,1hs6..9,1htc..9,1htr..9,1hvd..9,1hve..7,1hxc.3.6e,1hyr.2.9,1i0j..7,1i2o..9,1i2y..7,1i5x..9,1i5y..7,1iax..7,1iay..9,1id7.2.7,1idp..9,1iee.7.6e,1ieo.5.6e,1iki..9,1ikm..7,1ila..6e,1io2..9,1io3..7,1iv3..9,1iv4..7,1iyn..9,1j1y..9,1j1z..7,1j57..9,1jcp..9,1jcq..7,1jjx.2.9,1jk3..7,1jog..9,1jqs..9,1jrb..9,1jtl..9,1k5b..9,1kci..7,1kck.2.9,1kev..9,1kqp.2.9,1zow.5.1,1zqo.7.6e,20og.2.6,2ftq..1,2jxh.2.60,2jxj.3.1,2jxp..6a,2jxq.5.60,2jy3.8.64,2jyd.5.6e,2jyi.2.64,2jze.4.6e,2k3m.3.6e,2mtc.7.6e,2mtk.h.6e,2mu3.7.6e,2mub.2.6e,2mue.5.6e,2mxb..6e,2n1s.7.6e,2nce..6e,2ne4.4.6e,2nsc.2.6g,2nse..64,2nsf..6e,2ok0.7.64,2on8.6.6e,2one..7";
3596
+ var NFC_DECOMP = "5c.1t.lc,1.1t.ld,1.1t.le,1.1t.lf,1.1t.lk,1.1t.lm,2.1v.mf,1.1x.lc,1.1x.ld,1.1x.le,1.1x.lk,1.21.lc,1.21.ld,1.21.le,1.21.lk,2.26.lf,1.27.lc,1.27.ld,1.27.le,1.27.lf,1.27.lk,3.2d.lc,1.2d.ld,1.2d.le,1.2d.lk,1.2h.ld,3.2p.lc,1.2p.ld,1.2p.le,1.2p.lf,1.2p.lk,1.2p.lm,2.2r.mf,1.2t.lc,1.2t.ld,1.2t.le,1.2t.lk,1.2x.lc,1.2x.ld,1.2x.le,1.2x.lk,2.32.lf,1.33.lc,1.33.ld,1.33.le,1.33.lf,1.33.lk,3.39.lc,1.39.ld,1.39.le,1.39.lk,1.3d.ld,2.3d.lk,1.1t.lg,1.2p.lg,1.1t.li,1.2p.li,1.1t.mg,1.2p.mg,1.1v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tn.lk,1.uj.lk,89.17r.18z,1.17r.190,1.18o.190,1.17r.191,1.18q.190,4a.1cl.190,2.1c1.190,h.1ci.190,gm.1t4.1to,8.1tc.1to,3.1tf.1to,10.1sl.1to,1.1sm.1to,1.1sn.1to,1.1ss.1to,1.1sx.1to,1.1sy.1to,1.1t7.1to,1.1tb.1to,30.1xj.1xa,1.1xj.1xz,g.1wh.1x8,1.1wi.1x8,2.1wv.1x8,2c.20i.20s,3.20o.20s,z.1zq.20s,1.1zr.20s,1.1zw.20s,3.20b.20s,6i.287.28m,3.287.27y,1.287.28n,g.275.27w,1.276.27w,1j.2aa.2c7,1i.2bq.2bi,1.2br.2bi,1.2bq.2c7,3g.2fa.2fq,3c.2in.2j9,7.2iu.2j9,1.2iu.2ja,2.2iu.2iq,1.2iy.2j9,3j.2me.2m6,1.2mf.2m6,1.2me.2mv,3y.2qh.2q2,2.2qh.2q7,1.2qk.2q2,1.2qh.2qn,9x.30i.33r,a.30s.33r,5.30x.33r,5.312.33r,5.317.33r,d.30g.33p,a.31t.31u,2.31t.31w,1.33m.328,2.33n.328,9.31t.328,i.32q.33r,a.330.33r,5.335.33r,5.33a.33r,5.33f.33r,d.32o.33p,31.36t.372,25c.5c5.5dh,2.5c7.5dh,2.5c9.5dh,2.5cb.5dh,2.5cd.5dh,4.5ch.5dh,15.5dm.5dh,2.5do.5dh,3.5dq.5dh,1.5dr.5dh,2.5du.5dh,jh.1t.md,1.2p.md,1.1u.lj,1.2q.lj,1.1u.mb,1.2q.mb,1.1u.mp,1.2q.mp,1.5j.ld,1.6f.ld,1.1w.lj,1.2s.lj,1.1w.mb,1.2s.mb,1.1w.mp,1.2s.mp,1.1w.mf,1.2s.mf,1.1w.ml,1.2s.ml,1.7m.lc,1.7n.lc,1.7m.ld,1.7n.ld,1.1x.ml,1.2t.ml,1.1x.mo,1.2t.mo,1.fc.li,1.fd.li,1.1y.lj,1.2u.lj,1.1z.lg,1.2v.lg,1.20.lj,1.2w.lj,1.20.mb,1.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6,1.661.n6,1.qn.lv,1.qn.lw,1.668.lc,1.669.lc,1.668.ld,1.669.ld,3.pr.lv,1.pr.lw,1.66g.lc,1.66h.lc,1.66g.ld,1.66h.ld,3.qt.lv,1.qt.lw,1.66o.lc,1.66p.lc,1.66o.ld,1.66p.ld,1.66o.n6,1.66p.n6,2.px.lw,2.66x.lc,2.66x.ld,2.66x.n6,1.qx.lv,1.qx.lw,1.674.lc,1.675.lc,1.674.ld,1.675.ld,1.674.n6,1.675.n6,1.q1.lv,1.q1.lw,1.67c.lc,1.67d.lc,1.67c.ld,1.67d.ld,1.67c.n6,1.67d.n6,1.q9.lc,1.q4,1.qd.lc,1.q5,1.qf.lc,1.q6,1.qh.lc,1.q7,1.qn.lc,1.r0,1.qt.lc,1.r1,1.qx.lc,1.r2,3.64g.n9,1.64h.n9,1.64i.n9,1.64j.n9,1.64k.n9,1.64l.n9,1.64m.n9,1.64n.n9,1.64o.n9,1.64p.n9,1.64q.n9,1.64r.n9,1.64s.n9,1.64t.n9,1.64u.n9,1.64v.n9,1.65c.n9,1.65d.n9,1.65e.n9,1.65f.n9,1.65g.n9,1.65h.n9,1.65i.n9,1.65j.n9,1.65k.n9,1.65l.n9,1.65m.n9,1.65n.n9,1.65o.n9,1.65p.n9,1.65q.n9,1.65r.n9,1.674.n9,1.675.n9,1.676.n9,1.677.n9,1.678.n9,1.679.n9,1.67a.n9,1.67b.n9,1.67c.n9,1.67d.n9,1.67e.n9,1.67f.n9,1.67g.n9,1.67h.n9,1.67i.n9,1.67j.n9,1.q9.li,1.q9.lg,1.67k.n9,1.q9.n9,1.q4.n9,2.q9.n6,1.69i.n9,1.pd.li,1.pd.lg,1.pd.lc,1.p2,1.pd.n9,2.qh,3.4o.n6,1.67o.n9,1.qf.n9,1.q6.n9,2.qf.n6,1.69y.n9,1.ph.lc,1.p4,1.pj.lc,1.p5,1.pj.n9,1.69r.lc,1.69r.ld,1.69r.n6,1.qh.li,1.qh.lg,1.qy.lc,1.pc,3.qh.n6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rka,1.rpx,1.3hrc,1.rsb,1.rsx,1.rvf,1.rxz,1.3i9b,1.2upw,1.s0b,1.rzw,1.s1c,1.2uvy,1.s7o,1.sag,1.3jki,1.3jl9,1.sk4,1.smp,1.snl,1.3ju6,1.snv,1.svs,1.t07,1.t08,1.sxo,1.t89,1.t91,1.3ksa,1.tjf,1.ej9,1.tkn,1.3l2v,1.eli,1.ts3,1.iia,1.tur,1.3ltx,1.3lzu,1.epa,1.epi,1.u00,1.3mdm,1.er6,1.3mhi,1.u17,1.u17,1.u21,1.3mpi,1.u76,1.eur,1.u95,1.ucn,1.ude,1.uf2,1.ez2,1.3nsg,1.umq,1.uv4,1.v0d,1.f66,1.f71,1.v3b,1.3owe,1.f7c,1.3oxx,1.3p5a,1.3p8x,1.vcr,1.f9y,1.veh,1.vem,1.vet,1.vf3,1.vfa,1.vgb,1.3pxc";
3597
+ var NFC_EXCLUDED = "1ug,1uh,1ui,1uj,1uk,1ul,1um,1un,1y4,1y5,1y7,20j,20m,21l,21m,21n,21q,28s,28t,30j,30t,30y,313,318,31l,31y,320,32r,331,336,33b,33g,33t,1dlp,1dlr,1dm2,1dm3,1dm4,1dm5,1dm6,1dm7,1dm8,1dm9,1dma,1dmb,1dmc,1dmd,1dme,1dmg,1dmh,1dmi,1dmj,1dmk,1dmm,1dmo,1dmp,1dmr,1dms,1dmu,1dmv,1dmw,1dmx,1dmy,1dmz,1dn0,1dn1,1dn2,8gs,2jxa,2jxb,2jxc,2jxd,2jxe,2jxf,2jxg,2jzv,2jzw,2jzx,2jzy,2jzz,2k00";
3598
+
3599
+ // src/nfc.ts
3600
+ var S_BASE = 44032;
3601
+ var L_BASE = 4352;
3602
+ var V_BASE = 4449;
3603
+ var T_BASE = 4519;
3604
+ var L_COUNT = 19;
3605
+ var V_COUNT = 21;
3606
+ var T_COUNT = 28;
3607
+ var N_COUNT = V_COUNT * T_COUNT;
3608
+ var S_COUNT = L_COUNT * N_COUNT;
3609
+ var tables = null;
3610
+ function load() {
3611
+ const ccc = /* @__PURE__ */ new Map();
3612
+ for (const run of NFC_CLASS_RUNS.split(",")) {
3613
+ const [start, count, cls] = run.split(".");
3614
+ const s = parseInt(start, 36);
3615
+ const n = count ? parseInt(count, 36) : 1;
3616
+ const c = parseInt(cls, 36);
3617
+ for (let k = 0; k < n; k++) ccc.set(s + k, c);
3618
+ }
3619
+ const raw = /* @__PURE__ */ new Map();
3620
+ let cp = 0;
3621
+ for (const entry of NFC_DECOMP.split(",")) {
3622
+ const [gap, ...to] = entry.split(".");
3623
+ cp += parseInt(gap, 36);
3624
+ raw.set(cp, to.map((t) => parseInt(t, 36)));
3625
+ }
3626
+ const excluded = new Set(NFC_EXCLUDED.split(",").map((t) => parseInt(t, 36)));
3627
+ const compose = /* @__PURE__ */ new Map();
3628
+ for (const [c, to] of raw) {
3629
+ if (to.length !== 2 || excluded.has(c) || ccc.has(c) || ccc.has(to[0])) continue;
3630
+ compose.set(to[0] * 1114112 + to[1], c);
3631
+ }
3632
+ const decomp = /* @__PURE__ */ new Map();
3633
+ const full = (c) => {
3634
+ const done = decomp.get(c);
3635
+ if (done) return done;
3636
+ const to = raw.get(c);
3637
+ if (!to) return [c];
3638
+ const out = to.flatMap(full);
3639
+ decomp.set(c, out);
3640
+ return out;
4786
3641
  };
3642
+ for (const c of raw.keys()) full(c);
3643
+ return { ccc, decomp, compose };
4787
3644
  }
4788
- var NOTHING = () => ({ kept: [], rows: [], cut: {}, notesIgnored: 0, mail: null, unreadable: null });
4789
- function checkReader(reader, where) {
4790
- if (!isBody2(reader) || !["owner", "contributor", "guest", "public"].includes(reader.rung)) {
4791
- throw new TypeError(`${where}: a reader is an object whose rung is owner, contributor, guest or public; got ${JSON.stringify(reader) ?? String(reader)}.`);
3645
+ function nfc(text2) {
3646
+ let plain = true;
3647
+ for (let i = 0; i < text2.length; i++) if (text2.charCodeAt(i) >= 192) {
3648
+ plain = false;
3649
+ break;
4792
3650
  }
4793
- if (reader.as !== void 0 && reader.as !== null) checkReader(reader.as, `${where}.as`);
4794
- }
4795
- function resolveLens(world, lens, reader, options) {
4796
- if (options !== void 0 && options !== null && !isBody2(options)) {
4797
- throw new TypeError(`resolveLens: options is an object, such as { asOf: 1200 }; got ${JSON.stringify(options) ?? typeof options}.`);
3651
+ if (plain) return text2;
3652
+ const t = tables ?? (tables = load());
3653
+ const cls = (c) => t.ccc.get(c) ?? 0;
3654
+ const cps = [];
3655
+ for (const ch of text2) {
3656
+ const c = ch.codePointAt(0);
3657
+ const s = c - S_BASE;
3658
+ if (s >= 0 && s < S_COUNT) {
3659
+ cps.push(L_BASE + Math.floor(s / N_COUNT), V_BASE + Math.floor(s % N_COUNT / T_COUNT));
3660
+ if (s % T_COUNT) cps.push(T_BASE + s % T_COUNT);
3661
+ } else {
3662
+ const d = t.decomp.get(c);
3663
+ if (d) cps.push(...d);
3664
+ else cps.push(c);
3665
+ }
4798
3666
  }
4799
- refuseUnknownOptions("resolveLens", options, LENS_OPTION_KEYS);
4800
- const opts = isBody2(options) ? options : {};
4801
- if (!isBody2(world) || !Array.isArray(world.elements)) {
4802
- throw new TypeError("resolveLens: world is an object with an elements list.");
3667
+ for (let i = 1; i < cps.length; i++) {
3668
+ const c = cps[i];
3669
+ const k = cls(c);
3670
+ if (!k) continue;
3671
+ let j = i;
3672
+ while (j > 0 && cls(cps[j - 1]) > k) {
3673
+ cps[j] = cps[j - 1];
3674
+ j--;
3675
+ }
3676
+ cps[j] = c;
3677
+ }
3678
+ const out = [];
3679
+ let starter = -1;
3680
+ let last = 0;
3681
+ for (const c of cps) {
3682
+ const k = cls(c);
3683
+ if (starter >= 0 && (out.length - 1 === starter || last !== 0 && last < k)) {
3684
+ const a = out[starter];
3685
+ let composed;
3686
+ const l = a - L_BASE, v = c - V_BASE, s = a - S_BASE, tt = c - T_BASE;
3687
+ if (l >= 0 && l < L_COUNT && v >= 0 && v < V_COUNT) composed = S_BASE + (l * V_COUNT + v) * T_COUNT;
3688
+ else if (s >= 0 && s < S_COUNT && s % T_COUNT === 0 && tt > 0 && tt < T_COUNT) composed = a + tt;
3689
+ else composed = t.compose.get(a * 1114112 + c);
3690
+ if (composed !== void 0) {
3691
+ out[starter] = composed;
3692
+ continue;
3693
+ }
3694
+ }
3695
+ if (k === 0) starter = out.length;
3696
+ last = k;
3697
+ out.push(c);
4803
3698
  }
4804
- checkReader(reader, "resolveLens: reader");
4805
- const { asOf, clock } = readingDate("resolveLens", world, opts);
4806
- if (typeof lens !== "string" && !isBody2(lens)) throw new TypeError("resolveLens: lens is a lens body or its id.");
4807
- return lensReading(new Reading(world, reader, asOf), lens, clock).reading;
3699
+ let r = "";
3700
+ for (const c of out) r += String.fromCodePoint(c);
3701
+ return r;
4808
3702
  }
4809
- function readingDate(fn, world, opts) {
4810
- const asOfV = valueOf(opts, "asOf");
4811
- if (asOfV !== null && whole(asOfV) === null) throw new TypeError(`${fn}: asOf is a whole number; got ${JSON.stringify(asOfV)}.`);
4812
- const clockV = valueOf(opts, "clock");
4813
- if (clockV !== null && timeKey(clockV) === null) throw new TypeError(`${fn}: clock is a date-time; got ${JSON.stringify(clockV)}.`);
4814
- const asOf = asOfV !== null ? asOfV : whole(world.now) ?? whole(world.time_current) ?? whole(world.time_range_current);
4815
- return { asOf, clock: clockV };
3703
+
3704
+ // src/world-file.ts
3705
+ var WORLD_FILE = "world.json";
3706
+ var MARKER_NAME = "mimetype";
3707
+ var WORLD_FILE_MEDIA_TYPE = "application/vnd.onlyworlds.world+zip";
3708
+ var WORLD_FILE_MAX_BYTES = 2 * 1024 ** 3;
3709
+ var WORLD_FILE_MAX_ENTRIES = 5e5;
3710
+ var MESSAGES = {
3711
+ unsafe_path: "The world file holds a path that cannot be written safely.",
3712
+ too_big: "The world file is bigger than the budget allows, or a file in it is bigger than it says.",
3713
+ too_many: "The world file holds more files than the budget allows.",
3714
+ not_a_world: "The file is not a world: it has no readable world.json with an id.",
3715
+ more_than_one: "The file holds more than one world.",
3716
+ not_openable: "The file is not a zip that can be read.",
3717
+ duplicate: "The world file holds two entries with the same name.",
3718
+ collision: "The world file holds two names that differ only in case or in how an accent is written.",
3719
+ link: "The world file holds a link or a special file.",
3720
+ method: "The world file holds an encrypted entry, or one compressed other than stored or deflate.",
3721
+ name: "The world file holds a name that some disk cannot hold.",
3722
+ marker: "The world file's mimetype entry is not the OnlyWorlds media type."
3723
+ };
3724
+ var OwWorldFileError = class extends Error {
3725
+ constructor(reason, message = MESSAGES[reason]) {
3726
+ super(message);
3727
+ this.name = "OwWorldFileError";
3728
+ this.reason = reason;
3729
+ }
3730
+ };
3731
+ var READ_OPTION_KEYS = ["maxBytes", "maxEntries", "skip"];
3732
+ var refuse = (reason, message) => {
3733
+ throw new OwWorldFileError(reason, message);
3734
+ };
3735
+ function pathFault(name) {
3736
+ if (name.includes("\\")) return "holds a backslash";
3737
+ if (name.startsWith("/")) return "is absolute";
3738
+ if (/^[A-Za-z]:/.test(name)) return "names a drive";
3739
+ if (name.split("/").some((seg) => seg === "" || seg === "." || seg === "..")) return "has an empty, . or .. segment";
3740
+ return null;
4816
3741
  }
4817
- function lensReading(r, lens, clockV) {
4818
- const none = { reading: NOTHING(), cutById: /* @__PURE__ */ new Map() };
4819
- let body;
4820
- if (typeof lens === "string") body = r.view.has(lens) && !r.stubs.has(lens) ? r.byId.get(lens) : null;
4821
- else body = lens;
4822
- if (body === null || !isLens(body)) return none;
4823
- const read = readRecipe(body.x_lens);
4824
- if (!("recipe" in read)) return { ...none, reading: { ...NOTHING(), unreadable: read.bad } };
4825
- if (isTemplate(body)) return none;
4826
- const recipe = read.recipe;
4827
- const wall = timeKey(clockV ?? (/* @__PURE__ */ new Date()).toISOString());
4828
- const visited = /* @__PURE__ */ new Set();
4829
- if (typeof body.id === "string") visited.add(body.id);
4830
- const { list: keep, cut: cut2, mail } = resolveOne(body, recipe, r, visited, wall);
4831
- const { anchors } = anchorsOf(body, r);
4832
- const rows = keep.map((id) => r.row(id, recipe.show, anchors.includes(id) ? recipe.notes : null));
4833
- const counts = {};
4834
- for (const why of CUT_REASONS) {
4835
- if (OWNER_ONLY.has(why) && !r.owner) continue;
4836
- let n = 0;
4837
- for (const w of cut2.values()) if (w === why) n++;
4838
- if (n > 0) counts[why] = n;
3742
+ var RESERVED = /* @__PURE__ */ new Set([
3743
+ "CON",
3744
+ "PRN",
3745
+ "AUX",
3746
+ "NUL",
3747
+ ...[1, 2, 3, 4, 5, 6, 7, 8, 9].flatMap((i) => [`COM${i}`, `LPT${i}`])
3748
+ ]);
3749
+ var BAD_CHAR = /[<>:"|?*\p{Cc}]/u;
3750
+ function nameFault(name) {
3751
+ for (const seg of name.split("/")) {
3752
+ if (BAD_CHAR.test(seg)) return `segment ${JSON.stringify(seg)} holds a reserved or control character`;
3753
+ if (seg.endsWith(".") || seg.endsWith(" ")) return `segment ${JSON.stringify(seg)} ends in a dot or a space`;
3754
+ if (RESERVED.has(seg.split(".")[0].toUpperCase())) return `segment ${JSON.stringify(seg)} is a Windows device name`;
4839
3755
  }
4840
- const notesIgnored = Object.keys(recipe.notes).filter((k) => !anchors.includes(k) && r.view.has(k)).length;
4841
- return { reading: { kept: keep, rows, cut: counts, notesIgnored, mail, unreadable: null }, cutById: cut2 };
3756
+ return null;
4842
3757
  }
4843
-
4844
- // src/charter.ts
4845
- var SKILL_MAX = 5;
4846
- var ID = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/g;
4847
- var BREAK = /\r\n|\r|\n/;
4848
- function firstLine(text2) {
4849
- if (typeof text2 !== "string") return "";
4850
- return trimWhiteSpace(trimWhiteSpace(text2).split(BREAK, 1)[0]);
3758
+ function isJunk(path) {
3759
+ return path.split("/").some((seg) => seg === "__MACOSX" || seg === ".DS_Store" || seg === "Thumbs.db");
4851
3760
  }
4852
- function newest(ids, r) {
4853
- let best = null;
4854
- let bestAt = null;
4855
- for (const id of ids) {
4856
- const at = timeKey(r.byId.get(id).created_at);
4857
- if (best !== null) {
4858
- const c = at && bestAt ? compareKeys(at, bestAt) : at ? 1 : bestAt ? -1 : 0;
4859
- if (c < 0 || c === 0 && byCodePoint2(id, best) < 0) continue;
4860
- }
4861
- best = id;
4862
- bestAt = at;
4863
- }
4864
- return best;
3761
+ function foldName(name) {
3762
+ return simpleCaseFold(nfc(name));
4865
3763
  }
4866
- function idsIn(text2) {
4867
- const out = [];
4868
- if (typeof text2 !== "string") return out;
4869
- for (const m of text2.matchAll(ID)) {
4870
- const id = m[0].toLowerCase();
4871
- if (!out.includes(id)) out.push(id);
3764
+ function byCodePoint2(a, b) {
3765
+ const n = Math.min(a.length, b.length);
3766
+ for (let i = 0; i < n; i++) {
3767
+ const x = a.codePointAt(i);
3768
+ const y = b.codePointAt(i);
3769
+ if (x !== y) return x - y;
3770
+ if (x > 65535) i++;
4872
3771
  }
4873
- return out;
3772
+ return a.length - b.length;
4874
3773
  }
4875
- function hubsOf(id, r) {
4876
- const body = r.body(id);
4877
- if (body.known_of === true) return [];
4878
- const schema = FIELD_SCHEMA.construct;
4879
- const out = [];
4880
- const seen = /* @__PURE__ */ new Set([`construct/${id}`]);
4881
- for (const [field, many] of LINK_FIELDS.get("construct") ?? []) {
4882
- const v = body[field];
4883
- const target = schema[field]?.target ?? "";
4884
- for (const t of many ? Array.isArray(v) ? v : [] : [v]) {
4885
- if (typeof t !== "string" || t === "" || seen.has(`${target}/${t}`)) continue;
4886
- seen.add(`${target}/${t}`);
4887
- out.push({ type: target, id: t });
3774
+ var u16 = (b, o) => b[o] | b[o + 1] << 8;
3775
+ var u32 = (b, o) => (b[o] | b[o + 1] << 8 | b[o + 2] << 16) + b[o + 3] * 16777216;
3776
+ var u64 = (b, o) => u32(b, o) + u32(b, o + 4) * 4294967296;
3777
+ var SIG_LOCAL = 67324752;
3778
+ var SIG_CENTRAL = 33639248;
3779
+ var SIG_END = 101010256;
3780
+ var SIG_END64 = 101075792;
3781
+ var SIG_LOCATOR64 = 117853008;
3782
+ var MAX32 = 4294967295;
3783
+ var utf8 = new TextDecoder("utf-8", { fatal: true });
3784
+ var latin1 = (b) => {
3785
+ let s = "";
3786
+ for (const x of b) s += String.fromCharCode(x);
3787
+ return s;
3788
+ };
3789
+ function centralDirectory(bytes) {
3790
+ const len = bytes.length;
3791
+ let end = -1;
3792
+ for (let i = len - 22; i >= Math.max(0, len - 22 - 65535); i--) {
3793
+ if (u32(bytes, i) === SIG_END) {
3794
+ end = i;
3795
+ break;
4888
3796
  }
4889
3797
  }
4890
- return out;
4891
- }
4892
- var NONE = () => ({ charter: null, guide: null, domains: [] });
4893
- function charterOf(world, reader) {
4894
- if (!isBody2(world) || !Array.isArray(world.elements)) {
4895
- throw new TypeError("charterOf: world is an object with an elements list.");
4896
- }
4897
- checkReader(reader, "charterOf: reader");
4898
- const r = new Reading(world, reader, null);
4899
- if (r.seenRung === "public" && world.open !== true) return NONE();
4900
- const seen = (pair) => r.order.filter((id) => r.view.has(id) && r.aid.get(id) === pair);
4901
- const out = NONE();
4902
- const law = newest(seen("law/charter"), r);
4903
- if (law !== null) {
4904
- const el = r.byId.get(law);
4905
- const rules = el.x_checks_rules;
4906
- const skill = idsIn(el.description).filter((id) => r.view.has(id) && r.typeOf.get(id) === "object").slice(0, SKILL_MAX);
4907
- out.charter = {
4908
- id: law,
4909
- name: typeof el.name === "string" ? el.name : "",
4910
- rules: Array.isArray(rules) ? JSON.parse(JSON.stringify(rules)) : [],
4911
- skill
4912
- };
3798
+ if (end < 0) refuse("not_openable", "The file is not a zip: it has no end of central directory.");
3799
+ const thisDisk = u16(bytes, end + 4);
3800
+ const cdDisk = u16(bytes, end + 6);
3801
+ if (!(thisDisk === 0 && cdDisk === 0 || thisDisk === 65535 && cdDisk === 65535)) {
3802
+ refuse("not_openable", `The zip spans disks (its end record says disk ${thisDisk}, the directory on disk ${cdDisk}).`);
4913
3803
  }
4914
- const guide = newest(seen("construct/guide"), r);
4915
- if (guide !== null) {
4916
- const el = r.byId.get(guide);
4917
- out.guide = { id: guide, name: typeof el.name === "string" ? el.name : "" };
3804
+ let cdSize = u32(bytes, end + 12);
3805
+ let cdOffset = u32(bytes, end + 16);
3806
+ const loc = end - 20;
3807
+ if (loc >= 0 && u32(bytes, loc) === SIG_LOCATOR64) {
3808
+ if (u32(bytes, loc + 4) !== 0 || u32(bytes, loc + 16) > 1) refuse("not_openable", "The zip spans disks (zip64).");
3809
+ const rec = u64(bytes, loc + 8);
3810
+ if (rec + 56 > len || u32(bytes, rec) !== SIG_END64) refuse("not_openable", "The zip64 end record is missing.");
3811
+ if (u32(bytes, rec + 16) !== 0 || u32(bytes, rec + 20) !== 0) refuse("not_openable", "The zip spans disks (zip64).");
3812
+ cdSize = u64(bytes, rec + 40);
3813
+ cdOffset = u64(bytes, rec + 48);
4918
3814
  }
4919
- const domains = new Set(seen("construct/domain"));
4920
- const order = [];
4921
- const named = guide === null ? void 0 : r.body(guide).constructs;
4922
- for (const id of Array.isArray(named) ? named : []) {
4923
- if (typeof id === "string" && domains.has(id) && !order.includes(id)) order.push(id);
3815
+ const cdEnd = cdOffset + cdSize;
3816
+ if (cdEnd > len) refuse("not_openable", "The central directory lies past the end of the file.");
3817
+ const out = [];
3818
+ let p = cdOffset;
3819
+ while (p < cdEnd) {
3820
+ if (p + 46 > cdEnd || u32(bytes, p) !== SIG_CENTRAL) refuse("not_openable", "The central directory is broken.");
3821
+ const flags = u16(bytes, p + 8);
3822
+ const nlen = u16(bytes, p + 28);
3823
+ const elen = u16(bytes, p + 30);
3824
+ const clen = u16(bytes, p + 32);
3825
+ const nameBytes = bytes.subarray(p + 46, p + 46 + nlen);
3826
+ const extra = bytes.subarray(p + 46 + nlen, p + 46 + nlen + elen);
3827
+ let usize = u32(bytes, p + 24);
3828
+ let csize = u32(bytes, p + 20);
3829
+ let offset = u32(bytes, p + 42);
3830
+ if (usize === MAX32 || csize === MAX32 || offset === MAX32) {
3831
+ for (let q = 0; q + 4 <= extra.length; q += 4 + u16(extra, q + 2)) {
3832
+ if (u16(extra, q) !== 1) continue;
3833
+ let r = q + 4;
3834
+ const stop = r + u16(extra, q + 2);
3835
+ const next = () => {
3836
+ if (r + 8 > stop) refuse("not_openable", "A zip64 extra field is short.");
3837
+ const v = u64(extra, r);
3838
+ r += 8;
3839
+ return v;
3840
+ };
3841
+ if (usize === MAX32) usize = next();
3842
+ if (csize === MAX32) csize = next();
3843
+ if (offset === MAX32) offset = next();
3844
+ break;
3845
+ }
3846
+ }
3847
+ const nonAscii = nameBytes.some((x) => x > 127);
3848
+ let name;
3849
+ let badUtf8 = false;
3850
+ if (flags & 2048) {
3851
+ try {
3852
+ name = utf8.decode(nameBytes);
3853
+ } catch {
3854
+ name = latin1(nameBytes);
3855
+ badUtf8 = true;
3856
+ }
3857
+ } else {
3858
+ name = latin1(nameBytes);
3859
+ }
3860
+ out.push({
3861
+ name,
3862
+ flags,
3863
+ method: u16(bytes, p + 10),
3864
+ crc: u32(bytes, p + 16),
3865
+ csize,
3866
+ usize,
3867
+ offset,
3868
+ external: u32(bytes, p + 38),
3869
+ nonAscii,
3870
+ badUtf8
3871
+ });
3872
+ p += 46 + nlen + elen + clen;
4924
3873
  }
4925
- const nameOf = (id) => {
4926
- const name = r.body(id).name;
4927
- return typeof name === "string" ? name : "";
4928
- };
4929
- const rest = [...domains].filter((id) => !order.includes(id)).sort((a, b) => byCodePoint2(fold(nameOf(a)), fold(nameOf(b))) || byCodePoint2(a, b));
4930
- out.domains = [...order, ...rest].map((id) => ({
4931
- id,
4932
- name: nameOf(id),
4933
- sentence: firstLine(r.body(id).description),
4934
- hubs: hubsOf(id, r)
4935
- }));
3874
+ if (p !== cdEnd) refuse("not_openable", "The central directory is broken.");
4936
3875
  return out;
4937
3876
  }
4938
- function domainsOf(world, reader) {
4939
- return charterOf(world, reader).domains;
4940
- }
4941
-
4942
- // src/graph.ts
4943
- var GRAPH_OPTION_KEYS = ["lens", "asOf", "clock", "rooms", "hidden", "proposed", "mapSpace"];
4944
- var DECLARED_LINKS = ["x_lens_leads_to", "x_spine_depends_on"];
4945
- var MAP_SPACE = /* @__PURE__ */ new Set(["map", "pin", "marker"]);
4946
- var GRAPH_REASONS = [...CUT_REASONS, "room", "hidden", "proposed", "map_space", "reading_aid", "outside_lens"];
4947
- var GRAPH_OWNER_ONLY = /* @__PURE__ */ new Set([...OWNER_ONLY, "hidden", "proposed"]);
4948
- function flag(opts, key) {
4949
- const v = valueOf(opts, key);
4950
- if (v !== null && typeof v !== "boolean") throw new TypeError(`worldGraph: ${key} is a boolean; got ${JSON.stringify(v)}.`);
4951
- return v === true;
4952
- }
4953
- function worldGraph(world, reader, options) {
4954
- if (options !== void 0 && options !== null && !isBody2(options)) {
4955
- throw new TypeError(`worldGraph: options is an object, such as { rooms: true }; got ${JSON.stringify(options) ?? typeof options}.`);
4956
- }
4957
- refuseUnknownOptions("worldGraph", options, GRAPH_OPTION_KEYS);
4958
- const opts = isBody2(options) ? options : {};
4959
- if (!isBody2(world) || !Array.isArray(world.elements)) {
4960
- throw new TypeError("worldGraph: world is an object with an elements list.");
4961
- }
4962
- checkReader(reader, "worldGraph: reader");
4963
- const flags = {
4964
- room: flag(opts, "rooms"),
4965
- hidden: flag(opts, "hidden"),
4966
- proposed: flag(opts, "proposed"),
4967
- map_space: flag(opts, "mapSpace")
4968
- };
4969
- const seenRung = reader.rung === "owner" && reader.as != null ? reader.as.rung : reader.rung;
4970
- for (const [kind, key] of [["hidden", "hidden"], ["proposed", "proposed"]]) {
4971
- if (flags[kind] && seenRung !== "owner") throw new TypeError(`worldGraph: ${key} is the owner's alone; a ${seenRung} reader may not ask it.`);
4972
- }
4973
- if (seenRung === "public") {
4974
- for (const [kind, key] of [["room", "rooms"], ["map_space", "mapSpace"]]) {
4975
- if (flags[kind]) throw new TypeError(`worldGraph: a public reader takes no flag; it asked ${key}.`);
3877
+ var crcTable = null;
3878
+ function crc32(data) {
3879
+ if (!crcTable) {
3880
+ crcTable = new Int32Array(256);
3881
+ for (let n = 0; n < 256; n++) {
3882
+ let c2 = n;
3883
+ for (let k = 0; k < 8; k++) c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
3884
+ crcTable[n] = c2;
4976
3885
  }
4977
3886
  }
4978
- const { asOf, clock } = readingDate("worldGraph", world, opts);
4979
- const lens = valueOf(opts, "lens");
4980
- if (lens !== null && typeof lens !== "string" && !isBody2(lens)) throw new TypeError("worldGraph: lens is a lens body or its id.");
4981
- const r = new Reading(world, reader, asOf);
4982
- const seenOwner = r.seenRung === "owner";
4983
- const kinds = (id) => {
4984
- const out = [];
4985
- if (r.room.has(id)) out.push("room");
4986
- if (r.hidden.has(id)) out.push("hidden");
4987
- if (r.proposed.has(id)) out.push("proposed");
4988
- if (MAP_SPACE.has(r.typeOf.get(id))) out.push("map_space");
4989
- if (r.aid.has(id)) out.push("reading_aid");
4990
- return out;
4991
- };
4992
- const brought = (k) => k !== "reading_aid" && flags[k];
4993
- const candidate = (id) => r.view.has(id) || seenOwner && r.proposed.has(id);
4994
- const nodeIds = /* @__PURE__ */ new Set();
4995
- let cut2;
4996
- let reasonOf;
4997
- let unreadable = null;
4998
- if (lens !== null) {
4999
- const { reading, cutById } = lensReading(r, lens, clock);
5000
- for (const id of reading.kept) nodeIds.add(id);
5001
- cut2 = { ...reading.cut };
5002
- unreadable = reading.unreadable;
5003
- reasonOf = (id) => cutById.get(id) ?? (r.view.has(id) ? "outside_lens" : "not_visible");
5004
- } else {
5005
- const outBy = (id) => kinds(id).find((k) => !brought(k)) ?? null;
5006
- const counts = /* @__PURE__ */ new Map();
5007
- for (const id of r.order) {
5008
- if (!candidate(id)) continue;
5009
- const why = outBy(id);
5010
- if (why === null) nodeIds.add(id);
5011
- else counts.set(why, (counts.get(why) ?? 0) + 1);
3887
+ let c = -1;
3888
+ for (let i = 0; i < data.length; i++) c = crcTable[(c ^ data[i]) & 255] ^ c >>> 8;
3889
+ return (c ^ -1) >>> 0;
3890
+ }
3891
+ var CHUNK = 64 * 1024;
3892
+ function endsEarly(payload) {
3893
+ const short = payload.subarray(0, payload.length - 1);
3894
+ try {
3895
+ if (short.length <= CHUNK) {
3896
+ inflateSync(short);
3897
+ } else {
3898
+ const inf = new Inflate(() => {
3899
+ });
3900
+ for (let i = 0; i < short.length; i += CHUNK) {
3901
+ const stop = Math.min(i + CHUNK, short.length);
3902
+ inf.push(short.subarray(i, stop), stop === short.length);
3903
+ }
5012
3904
  }
5013
- cut2 = tally(counts, r.owner);
5014
- reasonOf = (id) => candidate(id) ? outBy(id) : "not_visible";
3905
+ } catch {
3906
+ return false;
5015
3907
  }
5016
- const ids = [...nodeIds].sort(byCodePoint2);
5017
- const nodes = ids.map((id) => {
5018
- const el = r.byId.get(id);
5019
- const type = r.typeOf.get(id);
5020
- const node = {
5021
- id,
5022
- type,
5023
- name: valueOf(el, "name"),
5024
- family: ELEMENT_GROUPS[type],
5025
- icon: ELEMENT_ICONS[type]
5026
- };
5027
- const marks2 = kinds(id).filter((k) => k !== "map_space" && k !== "reading_aid");
5028
- if (marks2.length > 0) node.marks = marks2;
5029
- if (r.stubs.has(id)) node.known_of = true;
5030
- return node;
5031
- });
5032
- const edges = [];
5033
- const cutEdges = /* @__PURE__ */ new Map();
5034
- const visit = (source, field, target, index) => {
5035
- if (typeof target !== "string" || !r.byId.has(target)) return;
5036
- if (nodeIds.has(target)) {
5037
- edges.push({ source, field, target, index });
5038
- return;
3908
+ return true;
3909
+ }
3910
+ function inflateEntry(bytes, e) {
3911
+ const off = e.offset;
3912
+ if (off + 30 > bytes.length || u32(bytes, off) !== SIG_LOCAL) refuse("not_openable", `${e.name}: no local header at its offset.`);
3913
+ const start = off + 30 + u16(bytes, off + 26) + u16(bytes, off + 28);
3914
+ const payload = bytes.subarray(start, start + e.csize);
3915
+ let data;
3916
+ if (e.method === 0) {
3917
+ data = payload;
3918
+ } else if (payload.length <= CHUNK) {
3919
+ try {
3920
+ data = inflateSync(payload);
3921
+ } catch {
3922
+ return refuse("not_openable", `${e.name}: its deflate stream is broken.`);
5039
3923
  }
5040
- const why = reasonOf(target);
5041
- if (why !== null) cutEdges.set(why, (cutEdges.get(why) ?? 0) + 1);
5042
- };
5043
- for (const source of ids) {
5044
- if (r.stubs.has(source)) continue;
5045
- const el = r.byId.get(source);
5046
- for (const [field, many, target] of LINK_FIELDS.get(r.typeOf.get(source)) ?? []) {
5047
- if (target === "any") continue;
5048
- const v = el[field];
5049
- const to = linkTarget(el, field, target);
5050
- const list = many ? Array.isArray(v) ? v : [] : [v];
5051
- let served = 0;
5052
- for (let i = 0; i < list.length; i++) {
5053
- const t = list[i];
5054
- const typed = typeof t === "string" && r.typeOf.get(t) === to;
5055
- if (typed) visit(source, field, t, seenOwner ? i : served);
5056
- if (seenOwner || typed && r.linkable.has(t)) served++;
3924
+ } else {
3925
+ const out = new Uint8Array(e.usize);
3926
+ let n = 0;
3927
+ let over = false;
3928
+ const inf = new Inflate((chunk) => {
3929
+ if (n + chunk.length > e.usize) {
3930
+ over = true;
3931
+ throw new Error("past its size");
5057
3932
  }
3933
+ out.set(chunk, n);
3934
+ n += chunk.length;
3935
+ });
3936
+ try {
3937
+ for (let i = 0; i < payload.length; i += CHUNK) {
3938
+ const stop = Math.min(i + CHUNK, payload.length);
3939
+ inf.push(payload.subarray(i, stop), stop === payload.length);
3940
+ }
3941
+ } catch {
3942
+ if (!over) refuse("not_openable", `${e.name}: its deflate stream is broken.`);
5058
3943
  }
5059
- for (const field of DECLARED_LINKS) {
5060
- const v = el[field];
5061
- if (!Array.isArray(v)) continue;
5062
- for (let i = 0; i < v.length; i++) visit(source, field, v[i], i);
3944
+ data = over ? new Uint8Array(e.usize + 1) : out.subarray(0, n);
3945
+ }
3946
+ if (data.length > e.usize) refuse("too_big", `${e.name} holds more than the ${e.usize} bytes it declares.`);
3947
+ if (data.length !== e.usize) refuse("not_openable", `${e.name} holds ${data.length} bytes and declares ${e.usize}.`);
3948
+ if (e.method !== 0 && payload.length > 0 && endsEarly(payload)) {
3949
+ refuse("not_openable", `${e.name}: its deflate stream ends before its declared compressed size.`);
3950
+ }
3951
+ if (crc32(data) !== e.crc) refuse("not_openable", `${e.name} fails its CRC.`);
3952
+ return e.method === 0 ? data.slice() : data;
3953
+ }
3954
+ function parseWorld(data) {
3955
+ let meta;
3956
+ try {
3957
+ meta = JSON.parse(new TextDecoder().decode(data));
3958
+ } catch {
3959
+ throw new OwWorldFileError("not_a_world");
3960
+ }
3961
+ if (!meta || typeof meta !== "object" || Array.isArray(meta)) throw new OwWorldFileError("not_a_world");
3962
+ const id = meta.id;
3963
+ if (typeof id !== "string" || !id.trim()) throw new OwWorldFileError("not_a_world");
3964
+ return meta;
3965
+ }
3966
+ function withoutLink(data, meta) {
3967
+ if (!("api" in meta)) return { data, world: meta };
3968
+ const { api: _link, ...rest } = meta;
3969
+ return { data: new TextEncoder().encode(JSON.stringify(rest, null, 2) + "\n"), world: rest };
3970
+ }
3971
+ function checkCollisions(names) {
3972
+ const byFold = /* @__PURE__ */ new Map();
3973
+ const segFold = /* @__PURE__ */ new Map();
3974
+ const done = /* @__PURE__ */ new Set();
3975
+ for (const raw of names) {
3976
+ const segs = (raw.endsWith("/") ? raw.slice(0, -1) : raw).split("/");
3977
+ let prefix = "";
3978
+ let folded = "";
3979
+ for (let i = 0; i < segs.length; i++) {
3980
+ let f = segFold.get(segs[i]);
3981
+ if (f === void 0) {
3982
+ f = foldName(segs[i]);
3983
+ segFold.set(segs[i], f);
3984
+ }
3985
+ prefix = i ? `${prefix}/${segs[i]}` : segs[i];
3986
+ folded = i ? `${folded}/${f}` : f;
3987
+ if (done.has(prefix)) continue;
3988
+ done.add(prefix);
3989
+ const other = byFold.get(folded);
3990
+ if (other !== void 0) {
3991
+ refuse("collision", `The names ${JSON.stringify(other)} and ${JSON.stringify(prefix)} are one name after NFC and case folding.`);
3992
+ }
3993
+ byFold.set(folded, prefix);
5063
3994
  }
5064
3995
  }
5065
- edges.sort((a, b) => byCodePoint2(a.source, b.source) || byCodePoint2(a.field, b.field) || a.index - b.index);
5066
- return { nodes, edges, edgesCut: tally(cutEdges, r.owner), cut: cut2, unreadable };
5067
3996
  }
5068
- function tally(counts, owner) {
5069
- const out = {};
5070
- for (const why of GRAPH_REASONS) {
5071
- if (GRAPH_OWNER_ONLY.has(why) && !owner) continue;
5072
- const n = counts.get(why) ?? 0;
5073
- if (n > 0) out[why] = n;
3997
+ function checkFileAndFolder(files) {
3998
+ const seen = /* @__PURE__ */ new Set();
3999
+ for (const n of files) {
4000
+ const segs = n.split("/");
4001
+ let prefix = "";
4002
+ for (let i = 0; i < segs.length - 1; i++) {
4003
+ prefix = i ? `${prefix}/${segs[i]}` : segs[i];
4004
+ if (seen.has(prefix)) continue;
4005
+ seen.add(prefix);
4006
+ if (files.has(prefix)) refuse("unsafe_path", `${JSON.stringify(prefix)} is a file and a folder.`);
4007
+ }
5074
4008
  }
5075
- return out;
5076
4009
  }
5077
- function degreeOf(graph) {
5078
- if (!isBody2(graph) || !Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
5079
- throw new TypeError("degreeOf: graph is what worldGraph answers, an object with nodes and edges lists.");
4010
+ function readWorldFile(bytes, opts = {}) {
4011
+ refuseUnknownOptions("readWorldFile", opts, READ_OPTION_KEYS, "Nothing was read.");
4012
+ const maxBytes = opts.maxBytes ?? WORLD_FILE_MAX_BYTES;
4013
+ const maxEntries = opts.maxEntries ?? WORLD_FILE_MAX_ENTRIES;
4014
+ const entries = centralDirectory(bytes);
4015
+ const seen = /* @__PURE__ */ new Set();
4016
+ const files = [];
4017
+ let declared = 0;
4018
+ for (const e of entries) {
4019
+ const name2 = e.name;
4020
+ const isDir = name2.endsWith("/");
4021
+ const bare = isDir ? name2.slice(0, -1) : name2;
4022
+ const quoted = JSON.stringify(name2);
4023
+ const fault = pathFault(bare);
4024
+ if (fault) refuse("unsafe_path", `The entry ${quoted} ${fault}.`);
4025
+ const kind = e.external >>> 16 & 61440;
4026
+ if (kind !== 0 && kind !== 32768 && kind !== 16384) refuse("link", `The entry ${quoted} is a link or a special file.`);
4027
+ if (e.flags & 65) refuse("method", `The entry ${quoted} is encrypted.`);
4028
+ if (e.method !== 0 && e.method !== 8) refuse("method", `The entry ${quoted} uses method ${e.method} (only stored and deflate).`);
4029
+ if (e.badUtf8) refuse("name", `The entry ${quoted} is flagged UTF-8 and is not.`);
4030
+ if (e.nonAscii && !(e.flags & 2048)) refuse("name", `The entry ${quoted} is not ASCII and lacks the UTF-8 flag.`);
4031
+ const bad = nameFault(bare);
4032
+ if (bad) refuse("name", `The entry ${quoted}: ${bad}.`);
4033
+ if (seen.has(name2)) refuse("duplicate", `The entry ${quoted} appears twice.`);
4034
+ seen.add(name2);
4035
+ if (isDir) continue;
4036
+ files.push(e);
4037
+ if (files.length > maxEntries) refuse("too_many", `The world file holds more than ${maxEntries} files.`);
4038
+ declared += e.usize;
4039
+ if (declared > maxBytes) refuse("too_big", `The world file declares more than ${maxBytes} bytes.`);
5080
4040
  }
5081
- const count = new Map(graph.nodes.map((n) => [n.id, 0]));
5082
- const add = (id) => {
5083
- const n = count.get(id);
5084
- if (n !== void 0) count.set(id, n + 1);
5085
- };
5086
- for (const e of graph.edges) {
5087
- add(e.source);
5088
- if (e.target !== e.source) add(e.target);
4041
+ checkCollisions(seen);
4042
+ const names = new Set(files.map((e) => e.name));
4043
+ checkFileAndFolder(names);
4044
+ const marker = files.find((e) => e.name === MARKER_NAME);
4045
+ if (marker && new TextDecoder("utf-8", { ignoreBOM: true }).decode(inflateEntry(bytes, marker)) !== WORLD_FILE_MEDIA_TYPE) {
4046
+ refuse("marker", "The mimetype entry holds other bytes than the OnlyWorlds media type.");
5089
4047
  }
5090
- return Object.fromEntries(count);
5091
- }
5092
- function outDegreeOf(graph) {
5093
- if (!isBody2(graph) || !Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
5094
- throw new TypeError("outDegreeOf: graph is what worldGraph answers, an object with nodes and edges lists.");
4048
+ const candidates = [...names].filter((n) => n !== MARKER_NAME && !isJunk(n));
4049
+ let prefix;
4050
+ if (candidates.includes(WORLD_FILE)) {
4051
+ prefix = "";
4052
+ } else {
4053
+ const roots = new Set(candidates.filter((n) => n.split("/").length === 2 && n.endsWith(`/${WORLD_FILE}`) && !n.startsWith(".")).map((n) => n.slice(0, -WORLD_FILE.length)));
4054
+ if (roots.size === 0) refuse("not_a_world", "There is no world.json at the root or in one top-level folder.");
4055
+ if (roots.size > 1) refuse("more_than_one", `The file holds worlds in ${[...roots].join(", ")}.`);
4056
+ prefix = [...roots][0];
5095
4057
  }
5096
- const targets = new Map(graph.nodes.map((n) => [n.id, /* @__PURE__ */ new Set()]));
5097
- for (const e of graph.edges) {
5098
- if (e.target !== e.source) targets.get(e.source)?.add(e.target);
4058
+ const inside = new Set(candidates.filter((n) => n.startsWith(prefix)));
4059
+ for (const n of inside) {
4060
+ const rel = n.slice(prefix.length);
4061
+ if (rel !== WORLD_FILE && rel.endsWith(`/${WORLD_FILE}`) && !rel.startsWith("records/")) {
4062
+ refuse("more_than_one", `A second world.json sits inside the world: ${n}.`);
4063
+ }
5099
4064
  }
5100
- return Object.fromEntries([...targets].map(([id, t]) => [id, t.size]));
4065
+ const content = /* @__PURE__ */ new Map();
4066
+ for (const e of files) {
4067
+ const data = inflateEntry(bytes, e);
4068
+ if (inside.has(e.name)) content.set(e.name, data);
4069
+ }
4070
+ const worldName = `${prefix}${WORLD_FILE}`;
4071
+ const parsed = withoutLink(content.get(worldName), parseWorld(content.get(worldName)));
4072
+ const out = [];
4073
+ for (const [n, data] of content) {
4074
+ const path = n.slice(prefix.length);
4075
+ if (opts.skip?.(path)) continue;
4076
+ out.push({ path, data: n === worldName ? parsed.data : data });
4077
+ }
4078
+ out.sort((a, b) => byCodePoint2(a.path, b.path));
4079
+ const name = parsed.world.name;
4080
+ return {
4081
+ worldId: parsed.world.id,
4082
+ name: typeof name === "string" ? name : "",
4083
+ world: parsed.world,
4084
+ files: out
4085
+ };
5101
4086
  }
5102
-
5103
- // src/names.ts
5104
- var SLUGS = new Set(ELEMENT_TYPES);
5105
- var OPTION_KEYS = ["supertype", "many"];
5106
- var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
5107
- function word(pair, many) {
5108
- if (!isObject(pair) || typeof pair.one !== "string") return null;
5109
- const one = trimWhiteSpace(pair.one);
5110
- if (one === "") return null;
5111
- if (!many) return one;
5112
- const plural = typeof pair.many === "string" ? trimWhiteSpace(pair.many) : "";
5113
- return plural === "" ? one : plural;
5114
- }
5115
- function typeWord(world, type, opts = {}) {
5116
- refuseUnknownOptions("typeWord", opts, OPTION_KEYS);
5117
- const map = world?.x_names;
5118
- if (!isObject(map) || map.version !== 1) return null;
5119
- const { types, supertypes } = map;
5120
- if (types !== void 0 && !isObject(types)) return null;
5121
- if (supertypes !== void 0) {
5122
- if (!isObject(supertypes)) return null;
5123
- for (const inner of Object.values(supertypes)) if (!isObject(inner)) return null;
5124
- }
5125
- if (!SLUGS.has(type)) return null;
5126
- const many = opts.many === true;
5127
- const supertype = typeof opts.supertype === "string" ? fold(opts.supertype) : "";
5128
- if (supertype !== "" && isObject(supertypes) && isObject(supertypes[type])) {
5129
- for (const [key, pair] of Object.entries(supertypes[type])) {
5130
- if (fold(key) !== supertype) continue;
5131
- const w = word(pair, many);
5132
- if (w !== null) return w;
5133
- }
5134
- }
5135
- return isObject(types) ? word(types[type], many) : null;
4087
+ var PARTS = /* @__PURE__ */ new Set(["elements", "spatial", "media", "records"]);
4088
+ function carried(path) {
4089
+ if (path === WORLD_FILE) return true;
4090
+ const segs = path.split("/");
4091
+ if (segs.length < 2) return false;
4092
+ if (segs[0].startsWith(".")) return true;
4093
+ if (!PARTS.has(segs[0])) return false;
4094
+ if (segs[0] === "records") return true;
4095
+ return !segs.some((s) => s.startsWith(".")) && !path.endsWith(".meta");
5136
4096
  }
5137
-
5138
- // src/address.ts
5139
- var MESSAGES2 = {
5140
- not_an_address: "not an address: it starts with neither https://www.onlyworlds.com/w/ nor ow://",
5141
- uppercase: "an address is written in lowercase: the prefix or the type word is in another case",
5142
- segments: "the wrong number of path segments, or an empty one: a type needs an id and an id a type",
5143
- bad_world: "the world is not an id (or, in the site's address only, a slug)",
5144
- unknown_type: "the type word is not one of the 22",
5145
- bad_id: "the element id is not a UUID in the hyphenated 8-4-4-4-12 form",
5146
- bad_moment: "the moment is not a whole step in decimal within the 32-bit range",
5147
- bad_lens: "the lens is not one lowercase lens key holding an id",
5148
- no_world: "this address needs a world",
5149
- bad_form: "the form is neither human nor text"
5150
- };
5151
- var OwAddressError = class extends Error {
5152
- constructor(reason, message = MESSAGES2[reason]) {
5153
- super(message);
5154
- this.name = "OwAddressError";
5155
- this.reason = reason;
4097
+ var STAMP = new Date(1980, 0, 1, 0, 0, 0);
4098
+ var WRITE_OPTION_KEYS = ["includePrivateRecords", "includeHidden", "includeAuthorFields", "report"];
4099
+ var RECORDS_MANIFEST = "records/RECORDS.json";
4100
+ var AUTHOR_FIELDS = ["created_by", "changed_by", "changed_via", "changed_client", "doors"];
4101
+ function writeOptions(opts) {
4102
+ if (opts === void 0 || opts === null) return { includePrivate: false, includeHidden: true, includeAuthorFields: false };
4103
+ if (typeof opts !== "object") throw new TypeError(`writeWorldFile: options must be an object, such as { includePrivateRecords: true }. Nothing was written.`);
4104
+ refuseUnknownOptions("writeWorldFile", opts, WRITE_OPTION_KEYS, "Nothing was written.");
4105
+ const o = opts;
4106
+ for (const key of ["includePrivateRecords", "includeHidden", "includeAuthorFields"]) {
4107
+ const asked = o[key];
4108
+ if (asked !== void 0 && typeof asked !== "boolean") {
4109
+ throw new TypeError(`writeWorldFile: ${key} must be true or false; got ${JSON.stringify(asked) ?? String(asked)}. Nothing was written.`);
4110
+ }
5156
4111
  }
5157
- };
5158
- var refuse2 = (reason) => {
5159
- throw new OwAddressError(reason);
5160
- };
5161
- var HUMAN_PREFIX = "https://www.onlyworlds.com/w/";
5162
- var TEXT_PREFIX = "ow://";
5163
- var TYPES = new Set(ELEMENT_TYPES);
5164
- var UUID = /^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/;
5165
- var SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
5166
- var STEP = /^(?:0|-?[1-9][0-9]*)$/;
5167
- var STEP_MIN = -2147483648;
5168
- var STEP_MAX = 2147483647;
5169
- var ADDRESS_KEYS = ["form", "world", "type", "id", "lens", "moment", "worldIsSlug", "canonical"];
5170
- var asciiLower = (s) => s.replace(/[A-Z]/g, (c) => String.fromCharCode(c.charCodeAt(0) + 32));
5171
- var isUuid = (s) => UUID.test(s);
5172
- var isSlug = (s) => s.length >= 3 && s.length <= 40 && SLUG.test(s);
5173
- function checkType(word2) {
5174
- if (TYPES.has(word2)) return word2;
5175
- return refuse2(TYPES.has(asciiLower(word2)) ? "uppercase" : "unknown_type");
5176
- }
5177
- function write(form, world, type, id, moment, lens) {
5178
- const parts = [];
5179
- if (world !== null) parts.push(world);
5180
- if (type !== null && id !== null) parts.push(type, id);
5181
- let out = (form === "human" ? HUMAN_PREFIX : TEXT_PREFIX) + parts.join("/");
5182
- if (moment !== null) out += `@${moment}`;
5183
- if (lens !== null) out += `?lens=${lens}`;
5184
- return out;
4112
+ if (o.report !== void 0 && typeof o.report !== "function") {
4113
+ throw new TypeError(`writeWorldFile: report must be a function; got ${JSON.stringify(o.report) ?? String(o.report)}. Nothing was written.`);
4114
+ }
4115
+ return {
4116
+ includePrivate: o.includePrivateRecords === true,
4117
+ includeHidden: o.includeHidden !== false,
4118
+ includeAuthorFields: o.includeAuthorFields === true,
4119
+ report: o.report
4120
+ };
5185
4121
  }
5186
- var given = (v) => v !== void 0 && v !== null;
5187
- function elementAddress(address) {
5188
- if (address === null || typeof address !== "object" || Array.isArray(address)) {
5189
- throw new TypeError("elementAddress: the address is an object ({ form, world, type, id, lens, moment })");
5190
- }
5191
- refuseUnknownOptions("elementAddress", address, ADDRESS_KEYS);
5192
- const a = address;
5193
- const form = a.form;
5194
- if (form !== "human" && form !== "text") return refuse2("bad_form");
5195
- const hasType = given(a.type);
5196
- const hasId = given(a.id);
5197
- if (hasType !== hasId) return refuse2("segments");
5198
- const hasWorld = given(a.world);
5199
- if (!hasWorld && (form === "human" || !hasType)) return refuse2("no_world");
5200
- let world = null;
5201
- if (hasWorld) {
5202
- if (typeof a.world !== "string" || !isUuid(a.world)) return refuse2("bad_world");
5203
- world = a.world.toLowerCase();
5204
- }
5205
- let type = null;
5206
- let id = null;
5207
- if (hasType) {
5208
- type = typeof a.type === "string" ? checkType(a.type) : refuse2("unknown_type");
5209
- if (typeof a.id !== "string" || !isUuid(a.id)) return refuse2("bad_id");
5210
- id = a.id.toLowerCase();
5211
- }
5212
- let moment = null;
5213
- if (given(a.moment)) {
5214
- const m = a.moment;
5215
- if (typeof m !== "number" || !Number.isInteger(m) || m < STEP_MIN || m > STEP_MAX) return refuse2("bad_moment");
5216
- moment = m === 0 ? 0 : m;
5217
- }
5218
- let lens = null;
5219
- if (given(a.lens)) {
5220
- if (typeof a.lens !== "string" || !isUuid(a.lens)) return refuse2("bad_lens");
5221
- lens = a.lens.toLowerCase();
5222
- }
5223
- return write(form, world, type, id, moment, lens);
5224
- }
5225
- function readLens(query) {
5226
- let lens = null;
5227
- let seen = false;
5228
- for (const part of query.split("&")) {
5229
- const eq = part.indexOf("=");
5230
- const key = eq === -1 ? part : part.slice(0, eq);
5231
- if (asciiLower(key) !== "lens") continue;
5232
- if (key !== "lens" || seen) return refuse2("bad_lens");
5233
- seen = true;
5234
- const value = eq === -1 ? "" : part.slice(eq + 1);
5235
- if (!isUuid(value)) return refuse2("bad_lens");
5236
- lens = value.toLowerCase();
5237
- }
5238
- return lens;
5239
- }
5240
- function parseOwLink(text2) {
5241
- if (typeof text2 !== "string") return refuse2("not_an_address");
5242
- const s = trimWhiteSpace(text2);
5243
- let form;
5244
- let rest;
5245
- if (s.startsWith(HUMAN_PREFIX)) {
5246
- form = "human";
5247
- rest = s.slice(HUMAN_PREFIX.length);
5248
- } else if (s.startsWith(TEXT_PREFIX)) {
5249
- form = "text";
5250
- rest = s.slice(TEXT_PREFIX.length);
5251
- } else {
5252
- const lowered = asciiLower(s);
5253
- return refuse2(lowered.startsWith(HUMAN_PREFIX) || lowered.startsWith(TEXT_PREFIX) ? "uppercase" : "not_an_address");
5254
- }
5255
- const hash = rest.indexOf("#");
5256
- if (hash !== -1) rest = rest.slice(0, hash);
5257
- const q = rest.indexOf("?");
5258
- const query = q === -1 ? null : rest.slice(q + 1);
5259
- const segments = (q === -1 ? rest : rest.slice(0, q)).split("/");
5260
- const last = segments[segments.length - 1];
5261
- const at = last.indexOf("@");
5262
- const step = at === -1 ? null : last.slice(at + 1);
5263
- if (at !== -1) segments[segments.length - 1] = last.slice(0, at);
5264
- const n = segments.length;
5265
- if (form === "human" ? n !== 1 && n !== 3 : n < 1 || n > 3) return refuse2("segments");
5266
- if (segments.some((seg) => seg === "")) return refuse2("segments");
5267
- if (n === 1 && TYPES.has(segments[0])) return refuse2("segments");
5268
- let world = null;
5269
- let worldIsSlug = false;
5270
- if (n !== 2) {
5271
- const w = segments[0];
5272
- if (isUuid(w)) world = w.toLowerCase();
5273
- else if (form === "human" && isSlug(w) && !TYPES.has(w)) {
5274
- world = w;
5275
- worldIsSlug = true;
5276
- } else return refuse2("bad_world");
5277
- }
5278
- let type = null;
5279
- let id = null;
5280
- if (n !== 1) {
5281
- type = checkType(segments[n - 2]);
5282
- if (!isUuid(segments[n - 1])) return refuse2("bad_id");
5283
- id = segments[n - 1].toLowerCase();
5284
- }
5285
- let moment = null;
5286
- if (step !== null) {
5287
- if (!STEP.test(step) || step.length > 11) return refuse2("bad_moment");
5288
- const m = Number(step);
5289
- if (m < STEP_MIN || m > STEP_MAX) return refuse2("bad_moment");
5290
- moment = m;
5291
- }
5292
- const lens = query === null ? null : readLens(query);
5293
- const canonical = !worldIsSlug && text2 === write(form, world, type, id, moment, lens);
5294
- return { form, world, worldIsSlug, type, id, lens, moment, canonical };
4122
+ function elementObject(f) {
4123
+ const segs = f.path.split("/");
4124
+ if (segs.length !== 3 || segs[0] !== "elements" && segs[0] !== "spatial" || !/\.json$/i.test(segs[2])) return null;
4125
+ let doc;
4126
+ try {
4127
+ doc = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(f.data));
4128
+ } catch {
4129
+ return null;
4130
+ }
4131
+ if (doc === null || typeof doc !== "object" || Array.isArray(doc)) return null;
4132
+ return doc;
5295
4133
  }
5296
-
5297
- // src/openers.ts
5298
- var SURFACE_KEYS = ["tool", "audience", "signedIn", "browser", "phone"];
5299
- var NEEDS = ["account", "device", null];
5300
- var PLACEHOLDER = /\{(world|type|id)\}/g;
5301
- var fail = (what) => {
5302
- throw new TypeError(`openersFor: ${what}`);
5303
- };
5304
- function templateOf(row, key, v) {
5305
- if (v === void 0 || v === null) return null;
5306
- return typeof v === "string" ? v : fail(`tool ${row}: open.${key} is a link template or null`);
5307
- }
5308
- function openersFor(tools, kind, address, surface) {
5309
- if (!Array.isArray(tools)) fail("tools is the tools list's rows, an array");
5310
- if (kind !== "world" && kind !== "element") fail(`kind is 'world' or 'element'; got ${JSON.stringify(kind)}`);
5311
- if (address === null || typeof address !== "object" || Array.isArray(address)) {
5312
- fail("the address is an object ({ form, world, type, id }), as parseOwLink reads it");
5313
- }
5314
- refuseUnknownOptions("openersFor", address, ADDRESS_KEYS);
5315
- const a = address;
5316
- elementAddress({ ...a, form: a.form ?? "human" });
5317
- const page = elementAddress({ form: "human", world: a.world, type: a.type, id: a.id });
5318
- const world = a.world.toLowerCase();
5319
- const hasElement = a.type !== void 0 && a.type !== null;
5320
- if (kind === "element" && !hasElement) fail("an element's openers need an address with its type and id");
5321
- const type = hasElement ? a.type : "";
5322
- const id = hasElement ? a.id.toLowerCase() : "";
5323
- if (surface === null || typeof surface !== "object" || Array.isArray(surface)) fail("the surface is an object ({ audience, ... })");
5324
- refuseUnknownOptions("openersFor", surface, SURFACE_KEYS);
5325
- const { tool = null, audience, signedIn = null, browser = true, phone = false } = surface;
5326
- if (audience !== "member" && audience !== "public") fail(`surface.audience is 'member' or 'public'; got ${JSON.stringify(audience)}`);
5327
- if (tool !== null && typeof tool !== "string") fail("surface.tool is a client name or null");
5328
- if (signedIn !== null && typeof signedIn !== "boolean") fail("surface.signedIn is true, false or null");
5329
- if (typeof browser !== "boolean") fail("surface.browser is a boolean");
5330
- if (typeof phone !== "boolean") fail("surface.phone is a boolean");
5331
- const values = { world, type, id };
5332
- const fill = (template) => template.replace(PLACEHOLDER, (_, n) => values[n]);
5333
- const rows = [
5334
- { id: "onlyworlds", name: "onlyworlds.com", href: kind === "element" ? page : elementAddress({ form: "human", world }), state: null }
5335
- ];
5336
- for (const r of tools) {
5337
- if (r === null || typeof r !== "object" || typeof r.id !== "string" || typeof r.name !== "string") {
5338
- fail("each tools row is an object with an id and a name");
5339
- }
5340
- const open = r.open;
5341
- if (open === null || open === void 0) continue;
5342
- if (typeof open !== "object" || Array.isArray(open)) fail(`tool ${r.id}: open is an object or null`);
5343
- const o = open;
5344
- const worldDoor = templateOf(r.id, "world", o.world);
5345
- const elementDoor = templateOf(r.id, "element", o.element);
5346
- const needs = o.needs === void 0 ? null : o.needs;
5347
- if (!NEEDS.includes(needs)) fail(`tool ${r.id}: open.needs is 'account', 'device' or null; got ${JSON.stringify(needs)}`);
5348
- if (r.rung !== "listed") continue;
5349
- if (audience === "public" && needs !== null) continue;
5350
- const template = kind === "element" ? elementDoor ?? worldDoor : worldDoor;
5351
- if (template === null) continue;
5352
- let state = null;
5353
- if (tool !== null && r.client === tool) state = "You are here";
5354
- else if (needs === "account" && !browser) state = "Opens in your browser";
5355
- else if (needs === "account" && signedIn === false) state = `Sign in to ${r.name} first`;
5356
- else if (needs === "device" && phone) state = "Needs the world on this phone";
5357
- else if (kind === "element" && elementDoor === null) state = "Opens the world";
5358
- rows.push({ id: r.id, name: r.name, href: fill(template), state });
5359
- }
5360
- return rows;
4134
+ function isHiddenElement(f) {
4135
+ const doc = elementObject(f);
4136
+ if (!doc) return false;
4137
+ const mark = doc.hidden;
4138
+ return mark !== void 0 && mark !== null && mark !== false;
5361
4139
  }
5362
-
5363
- // src/tools.generated.ts
5364
- var TOOLS = [
5365
- {
5366
- "id": "atlas",
5367
- "name": "Atlas",
5368
- "url": "https://atlas.onlyworlds.com",
5369
- "client": "atlas",
5370
- "rung": "listed",
5371
- "open": {
5372
- "world": "https://atlas.onlyworlds.com/#/open/{world}",
5373
- "element": "https://atlas.onlyworlds.com/#/open/{world}/element/{id}",
5374
- "needs": "account"
5375
- }
5376
- },
5377
- {
5378
- "id": "lantern",
5379
- "name": "Lantern",
5380
- "url": "https://lantern.onlyworlds.com",
5381
- "client": "lantern",
5382
- "rung": "listed",
5383
- "open": {
5384
- "world": "https://lantern.onlyworlds.com/#/open/{world}",
5385
- "element": "https://lantern.onlyworlds.com/#/open/{world}/element/{id}",
5386
- "needs": "account"
5387
- }
4140
+ function withoutAuthorFields(f) {
4141
+ const doc = elementObject(f);
4142
+ if (!doc) return null;
4143
+ const present = AUTHOR_FIELDS.filter((k) => k in doc);
4144
+ if (!present.length) return null;
4145
+ for (const k of present) delete doc[k];
4146
+ return new TextEncoder().encode(JSON.stringify(doc, null, 2) + "\n");
4147
+ }
4148
+ function privateProducers(files) {
4149
+ const manifest = files.find((f) => f.path === RECORDS_MANIFEST);
4150
+ if (!manifest) return [];
4151
+ const unreadable = (why) => {
4152
+ throw new TypeError(`writeWorldFile: ${RECORDS_MANIFEST} ${why}, so which records are private cannot be read and none is left out by guess (spec \xA74.7, OW-8). Fix the manifest, or pass { includePrivateRecords: true } to carry every record. Nothing was written.`);
4153
+ };
4154
+ let doc;
4155
+ try {
4156
+ doc = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(manifest.data));
4157
+ } catch {
4158
+ unreadable("is not JSON");
5388
4159
  }
5389
- ];
5390
-
5391
- // src/doors.ts
5392
- var TIME = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.([0-9]+))?(Z|([+-])([0-9]{2}):([0-9]{2}))$/;
5393
- var MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
5394
- var fail2 = (what) => {
5395
- throw new TypeError(`doorsOf: ${what}`);
5396
- };
5397
- function daysFromCivil2(year, month, day) {
5398
- const y = month <= 2 ? year - 1 : year;
5399
- const era = Math.floor(y / 400);
5400
- const yoe = y - era * 400;
5401
- const doy = Math.floor((153 * (month > 2 ? month - 3 : month + 9) + 2) / 5) + day - 1;
5402
- const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
5403
- return era * 146097 + doe - 719468;
4160
+ if (!Array.isArray(doc)) unreadable("is not a JSON array of entries");
4161
+ const out = [];
4162
+ for (const entry of doc) {
4163
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) unreadable("holds an entry that is not an object");
4164
+ const { producer, private: isPrivate } = entry;
4165
+ if (isPrivate !== true) continue;
4166
+ if (typeof producer !== "string" || producer === "") unreadable("marks an entry private without a producer name");
4167
+ out.push(producer);
4168
+ }
4169
+ return out;
5404
4170
  }
5405
- function instantOf(value) {
5406
- if (typeof value !== "string") return null;
5407
- const m = TIME.exec(value);
5408
- if (m === null) return null;
5409
- const [year, month, day, hour, minute, second] = m.slice(1, 7).map(Number);
5410
- if (month < 1 || month > 12) return null;
5411
- const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
5412
- if (day < 1 || day > (month === 2 && leap ? 29 : MONTH_DAYS[month - 1])) return null;
5413
- if (hour > 23 || minute > 59 || second > 59) return null;
5414
- let offset = 0;
5415
- if (m[8] !== "Z") {
5416
- const oh = Number(m[10]);
5417
- const om = Number(m[11]);
5418
- if (oh > 23 || om > 59) return null;
5419
- offset = (m[9] === "-" ? -1 : 1) * (oh * 3600 + om * 60);
5420
- }
5421
- const seconds = daysFromCivil2(year, month, day) * 86400 + hour * 3600 + minute * 60 + second - offset;
5422
- return { seconds, fraction: (m[7] ?? "").replace(/0+$/, "") };
5423
- }
5424
- function compareInstants(a, b) {
5425
- if (a.seconds !== b.seconds) return a.seconds < b.seconds ? -1 : 1;
5426
- const width = Math.max(a.fraction.length, b.fraction.length);
5427
- const fa = a.fraction.padEnd(width, "0");
5428
- const fb = b.fraction.padEnd(width, "0");
5429
- return fa === fb ? 0 : fa < fb ? -1 : 1;
5430
- }
5431
- function compareCodePoints(a, b) {
5432
- const ca = Array.from(a, (c) => c.codePointAt(0));
5433
- const cb = Array.from(b, (c) => c.codePointAt(0));
5434
- for (let i = 0; i < Math.min(ca.length, cb.length); i++) {
5435
- if (ca[i] !== cb[i]) return ca[i] < cb[i] ? -1 : 1;
5436
- }
5437
- return ca.length - cb.length;
5438
- }
5439
- var nonEmpty = (v) => typeof v === "string" && v.length > 0;
5440
- function doorsOf(element, tools = TOOLS) {
5441
- if (element === null || typeof element !== "object" || Array.isArray(element)) fail2("the element is an object, as the API serves it");
5442
- if (!Array.isArray(tools)) fail2("tools is the tools list's rows, an array");
5443
- const e = element;
5444
- const toolOf = (door) => {
5445
- const row = tools.find((r) => r !== null && typeof r === "object" && r.client === door);
5446
- return row === void 0 ? null : { id: row.id, name: row.name };
4171
+ function writeWorldFile(files, topDir, opts = {}) {
4172
+ const { includePrivate, includeHidden, includeAuthorFields, report } = writeOptions(opts);
4173
+ if (pathFault(topDir) || topDir.includes("/")) throw new OwWorldFileError("unsafe_path");
4174
+ const seen = /* @__PURE__ */ new Set();
4175
+ for (const f of files) {
4176
+ if (pathFault(f.path)) throw new OwWorldFileError("unsafe_path");
4177
+ if (seen.has(f.path)) throw new OwWorldFileError("unsafe_path", `The path ${f.path} is listed twice.`);
4178
+ seen.add(f.path);
4179
+ }
4180
+ const left = new Set(includePrivate ? [] : privateProducers(files).map(foldName));
4181
+ const inPrivate = (path) => {
4182
+ const segs = path.split("/");
4183
+ return segs.length > 2 && segs[0] === "records" && left.has(foldName(segs[1]));
5447
4184
  };
5448
- const found = [];
5449
- const doors = e.doors;
5450
- if (doors !== null && typeof doors === "object" && !Array.isArray(doors)) {
5451
- for (const [door, at] of Object.entries(doors)) {
5452
- const instant = instantOf(at);
5453
- if (door.length > 0 && instant !== null) found.push({ door, at, instant });
5454
- }
5455
- }
5456
- const updated = instantOf(e.updated_at);
5457
- if (found.length === 0) {
5458
- const door = nonEmpty(e.changed_client) ? e.changed_client : nonEmpty(e.changed_via) ? e.changed_via : null;
5459
- if (door === null || updated === null) return [];
5460
- return [{ door, at: e.updated_at, tool: toolOf(door), last: true, from: "last-write" }];
5461
- }
5462
- found.sort((a, b) => compareInstants(b.instant, a.instant) || compareCodePoints(a.door, b.door));
5463
- let lastSeen = false;
5464
- return found.map(({ door, at, instant }) => {
5465
- const last = !lastSeen && updated !== null && compareInstants(instant, updated) === 0;
5466
- if (last) lastSeen = true;
5467
- return { door, at, tool: toolOf(door), last, from: "doors" };
4185
+ let hiddenLeftOut = 0;
4186
+ const kept = files.filter((f) => {
4187
+ if (!carried(f.path) || inPrivate(f.path)) return false;
4188
+ if (!includeHidden && isHiddenElement(f)) {
4189
+ hiddenLeftOut++;
4190
+ return false;
4191
+ }
4192
+ return true;
5468
4193
  });
5469
- }
5470
- function doorWhere(door) {
5471
- if (door === null || typeof door !== "object" || Array.isArray(door)) throw new TypeError("doorWhere: the door is an entry of doorsOf, an object");
5472
- if (typeof door.door !== "string") throw new TypeError("doorWhere: the entry's door is a string");
5473
- const tool = door.tool;
5474
- if (tool != null) {
5475
- if (typeof tool !== "object" || typeof tool.name !== "string") throw new TypeError("doorWhere: the entry's tool is null or { id, name }");
5476
- return `in ${tool.name}`;
4194
+ if (!kept.some((f) => f.path === WORLD_FILE)) throw new OwWorldFileError("not_a_world");
4195
+ const keys = kept.map((f) => `${topDir}/${f.path}`);
4196
+ for (const key of keys) {
4197
+ const bad = nameFault(key);
4198
+ if (bad) throw new OwWorldFileError("name", `The path ${key}: ${bad}.`);
4199
+ }
4200
+ checkCollisions([MARKER_NAME, ...keys]);
4201
+ checkFileAndFolder(/* @__PURE__ */ new Set([MARKER_NAME, ...keys]));
4202
+ const input = {
4203
+ [MARKER_NAME]: [new TextEncoder().encode(WORLD_FILE_MEDIA_TYPE), { level: 0, mtime: STAMP }]
4204
+ };
4205
+ let authorFieldsLeftOut = 0;
4206
+ for (const f of [...kept].sort((a, b) => byCodePoint2(a.path, b.path))) {
4207
+ let data = f.data;
4208
+ if (f.path === WORLD_FILE) {
4209
+ data = withoutLink(data, parseWorld(data)).data;
4210
+ } else if (!includeAuthorFields) {
4211
+ const bare = withoutAuthorFields(f);
4212
+ if (bare) {
4213
+ data = bare;
4214
+ authorFieldsLeftOut++;
4215
+ }
4216
+ }
4217
+ input[`${topDir}/${f.path}`] = [data, { level: /\.json$/i.test(f.path) ? 6 : 0, mtime: STAMP }];
5477
4218
  }
5478
- if (door.door === "site") return "on onlyworlds.com";
5479
- if (isAgentDoor(door.door)) return "with an AI";
5480
- if (door.door === "server") return "by OnlyWorlds";
5481
- return "in code";
4219
+ const zip = zipSync(input);
4220
+ report?.({ hiddenLeftOut, authorFieldsLeftOut });
4221
+ return zip;
5482
4222
  }
5483
4223
 
5484
4224
  // src/lookup.ts
@@ -6663,7 +5403,7 @@ function approxYearLength(cfg) {
6663
5403
  function formatDuration(cfg, steps) {
6664
5404
  const n = Math.abs(steps);
6665
5405
  const unit = (cfg.step_name ?? cfg.grain ?? "step").trim() || "step";
6666
- const plural = (word2, v) => v === 1 ? word2 : `${word2}s`;
5406
+ const plural = (word, v) => v === 1 ? word : `${word}s`;
6667
5407
  const yearLen = cfg.bundles?.months ? cfg.bundles.months.lengths.reduce((a, b) => a + b, 0) + (cfg.intercalary ?? []).filter((i) => i.every_years == null).length : cfg.bundles?.year?.steps ?? (unit.toLowerCase() === "year" ? 1 : null);
6668
5408
  if (yearLen != null && yearLen > 1 && n >= yearLen) {
6669
5409
  const years = n / yearLen;