GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Maps, GIS and field navigation / gridatlas / atlas/modules

Technology Coverage and 2 more files

A JavaScript module in the atlas folder of GridAtlas that works with named offshore and wider fleet names, covering grid substations, the Renewable Energy Planning Database (REPD) register and wind.

487 lines of JavaScript from gridatlas, in 3 files. Topic: Maps, GIS and field navigation. Section 528 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Corridor Estimate render · gridatlas / atlas/modules/202609030205-corridor-estimate.js lines 1–114
  2. Technology Coverage render · gridatlas / atlas/modules/202609031310-technology-coverage.js lines 1–279
  3. Arrival Tidy interaction · gridatlas / atlas/modules/202609032220-arrival-tidy.js lines 1–94

Corridor Estimate

A JavaScript file in the atlas folder of GridAtlas covering cables and overhead lines (OHL). It is built from the for cable helper (`forCable`).

rendergridatlas / atlas/modules/202609030205-corridor-estimate.js · lines 1–114 of 114 · version 2026-09-03 02:05 · pattern forCable (shared by 10 files)

What it does
Defines forCable. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage hv_procurement (path word 'estimate'): HV materials procurement, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables, overhead lines (OHL).
Downstream impact
Used directly by 2 files: Build Graph (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/); Ventus Grid Engine — Genome Page (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/). Reached from 1 other entry point, including Genome Workflow (ventus-grid-engine).
What it achieves
Corridor-estimate - a straight line is not a route, and this says how far off.
Why it matters
Loaded by the Genome page in Ventus Grid Engine at https://ventusltd.github.io/ventus-grid-engine/genome/. Also imported by Build Graph, from Ventus Grid Engine.
Application
gridatlas · atlas/modules · script
Uses
none found
Used by
named by URL in Build Graph (estate URL), named by URL in Ventus Grid Engine — Genome Page (estate URL)
Produces
forCable
Defines here
forCable
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/modules/202609030205-corridor-estimate.js:1-114 · blob ac69a75d9f6dc948067d691fc535e83eda5101ad · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: production_core
/* ══════════════════════════════════════════════════════════════════════
   corridor-estimate - a straight line is not a route, and this says how far off
   ══════════════════════════════════════════════════════════════════════

   Every distance this Atlas prints is a great-circle distance between two
   points. No cable is ever laid that way. The question a reader actually has
   is how much longer the built thing would be, and until now the card said
   nothing at all about it.

   THE SCALAR, AND WHAT IT WAS MEASURED ON.

   Route factor 1.245, calibrated against the published built lengths of GB
   transmission CABLE circuits in the operator's own node/branch model:

     median absolute error   8.45%
     within 15%              73% of circuits
     sample                  95 circuits spanning 59 DISTINCT SITE PAIRS

   The sample is 59, not 95. Parallel circuits between the same two sites
   duplicate the geometry exactly, so quoting 95 would be counting the same
   measurement up to four times and claiming a precision the data has not got.

   WHAT IT IS NOT FOR.

   Not overhead line. The measured OHL factor is 1.13, and it is a different
   number for a physical reason rather than a statistical one: a tower line
   crosses open country in long straight spans, while a cable follows the
   highway network, its bends and its wayleaves. Applying a cable factor to an
   overhead question would overstate the route by about ten per cent and would
   be the wrong model regardless of the error.

   Not below about a kilometre. Where the two ends are under 1 km apart the
   site-centroid resolution dominates the geometry: in that band the median
   published length is 0.59 km against a median error of 52.5%, which is not
   the route factor being wrong, it is the straight line not being a
   measurement of anything at that scale. Those separations are refused rather
   than scaled.

   It is a screening estimate for a corridor. It is not a connection offer, a
   constructability assessment or a consenting design, and the caveat below
   travels with every number this module produces.
   ══════════════════════════════════════════════════════════════════════ */
(() => {
  'use strict';

  const SCHEMA = 'gridatlas.module.corridor-estimate.v1';

  const CABLE_FACTOR = 1.245;
  const OHL_FACTOR = 1.13;
  const MINIMUM_KM = 1;

  const BASIS = Object.freeze({
    factor: CABLE_FACTOR,
    median_absolute_error_pct: 8.45,
    within_15_pct: 73,
    circuits: 95,
    distinct_site_pairs: 59,
    source: 'published built lengths of GB transmission cable circuits',
    sample_note: 'parallel circuits between the same two sites duplicate the '
      + 'geometry, so the sample is 59 distinct site pairs and not 95 circuits',
    minimum_separation_km: MINIMUM_KM,
    below_minimum: 'under about a kilometre the site-centroid resolution '
      + 'dominates: median published length 0.59 km against a median error of '
      + '52.5%, so a straight line between centroids is not measuring route '
      + 'factor and no estimate is offered'
  });

  const CAVEAT = 'Indicative highway-corridor screening only. Not a connection '
    + 'offer, not a constructability assessment and not a consenting design.';

  const NOT_FOR_OVERHEAD = 'Calibrated on cable circuits, which follow the '
    + 'highway network. Overhead line crosses open country and measures 1.13; '
    + 'this factor is not applied to an overhead-line question.';

  /**
   * The corridor estimate for a CABLE route of `km` straight-line distance.
   * @returns null when there is nothing honest to say - no distance, or a
   *   separation short enough that the straight line is not measuring
   *   route factor. Null is the answer, not zero.
   */
  function forCable(km) {
    const straight = Number(km);
    if (!Number.isFinite(straight) || straight <= 0) return null;
    if (straight < MINIMUM_KM) {
      return { km: null, factor: CABLE_FACTOR, straight_km: straight,
        withheld: BASIS.below_minimum };
    }
    return {
      km: straight * CABLE_FACTOR,
      factor: CABLE_FACTOR,
      straight_km: straight,
      withheld: null
    };
  }

  /* Deliberately no forOverhead(). A module that offered one would be used,
     and the 1.13 above is published here so a reader can see WHY the cable
     factor is not the answer to that question - not so that this cartridge
     can start answering it. */

  const NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
  NS.corridorEstimate = Object.freeze({
    schema: SCHEMA,
    factor: CABLE_FACTOR,
    overhead_factor: OHL_FACTOR,
    minimum_km: MINIMUM_KM,
    basis: BASIS,
    caveat: CAVEAT,
    not_for_overhead: NOT_FOR_OVERHEAD,
    forCable,
    not_an_assessment: 'An estimated corridor length says nothing about '
      + 'whether a connection is available, consentable or affordable.'
  });
})();

Technology Coverage

A JavaScript module in the atlas folder of GridAtlas that works with named offshore and wider fleet names, covering grid substations, the Renewable Energy Planning Database (REPD) register and wind.

rendergridatlas / atlas/modules/202609031310-technology-coverage.js · lines 1–279 of 279 · version 2026-09-03 13:10 · Not reached from any entry point (candidate for review) · pattern widerFleetBuckets (shared by 6 files)

What it does
It lists and searches grid substations, the REPD register, wind and cables. Defines 6 functions or classes, including bucketOf, policy, namedOffshore, widerFleetNames, widerFleetBuckets. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'atlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: the REPD register, wind, cables, 400kV, 275kV, 220kV.
Inputs & outputs
Voltage levels named: 400kV, 275kV, 220kV, 132kV, 33kV.
What it achieves
It is built from the bucket of helper (`bucketOf`), the named offshore helper (`namedOffshore`) and the wider fleet names helper (`widerFleetNames`). Defines `bucketOf`, `policy`, `namedOffshore` and 3 more. Its code works with 220 kV, 33 kV and 132 kV.
Why it matters
No other file in the estate was found to import it.
Application
gridatlas · atlas/modules · JavaScript module
Uses
none found
Used by
none found
Produces
bucketOf, policy, namedOffshore, widerFleetNames, widerFleetBuckets, measuredCount
Defines here
bucketOf, policy, namedOffshore, widerFleetNames, widerFleetBuckets, measuredCount
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/modules/202609031310-technology-coverage.js:1-279 · blob 7438874579e0f6f93741651a4ec41d1549fad818 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
/* ══════════════════════════════════════════════════════════════════════
   technology-coverage - which technologies the measurement runs for, and
   what each measurement is a measurement OF
   ══════════════════════════════════════════════════════════════════════

   WHAT WAS MEASURED BEFORE THIS MODULE WAS WRITTEN.

   The request was to extend the nearest-substation computation to the twenty
   wider-fleet REPD technologies, on the report that it ran only for the
   spine. Driven in Chrome against the live composition (v9.88, generation
   202609030234) on the wider fleet's own MAP link:

     ?repd_ref=8795 ... &technology=biomass   Caledon Green, Landfill Gas
     ?repd_ref=626  ... &technology=biomass   Pitsea Tipp,   Landfill Gas

   Both arrived, flew, opened the card, ticked the Subs control and DREW THE
   LINKS. Caledon Green measured 1.74 km at 132 kV, 2.98 km at 275 kV and
   5.70 km at 33 kV; Pitsea Tipp named Coryton South Substation at 7.70 km
   and printed its 400 kV scope sentence with the denominator in it. So the
   wider fleet was ALREADY computing, and a change that claimed to enable it
   would have been a change that did nothing while saying it did something.

   There IS a four-member technology allow-list in this estate:

     const allowedTechnologies = new Set(['solar','bess','wind_onshore','wind_offshore']);

   It lives at line 805 of the IMMUTABLE SHELL, atlas/releases/
   202608300453-atlas-v9/ventus-corev8engine.js, inside the shell's own
   focusCanonicalProjectDeepLink(). It rejects every value the wider fleet
   can send, because those four are exactly the four types the wider fleet is
   DEFINED as excluding. Its rejection is caught, and its only effects are a
   console line and a flyTo the arrival lane in this cartridge has already
   performed - which is why the measurement runs anyway. The shell is carried
   forward verbatim by contract and this module does not reach into it.

   WHAT THIS MODULE ACTUALLY CHANGES.

   One thing: OFFSHORE WIND NOW MEASURES. It used to open a card and withhold
   the distance, on the reasoning that a turbine in the North Sea does not
   reach the nearest onshore substation by a straight line. The reasoning
   about routes was right and is kept in full below; the conclusion was
   over-cautious. An offshore project's export cable does land at an onshore
   substation, so the distance to the nearest mapped substation is a real
   measurement of a real thing, provided the card says what it measured.

   WHAT "NEAREST" CANNOT BE MADE TO MEAN HERE, MEASURED RATHER THAN ASSUMED.

   The coordinator asked for an onshore-only filter, so that "nearest onshore
   substation" would mean onshore. The pinned substation product cannot carry
   one. Counted over all 5,800 features of

     atlas/releases/202608300453-atlas-v9/data/grid_substations.geojson

   the only properties present are voltage (5,800), name (4,460), operator
   (3,264), brand (1,310), source (684), type (72), capacity (15) and colour
   (3). The OSM `location` tag - the field that would say offshore, platform
   or underwater - is present on ZERO of them.

   That leaves the name, and the name does not separate them either. Fourteen
   features carry "offshore" in their name; read against their coordinates, at
   least four are ONSHORE substations serving an offshore wind farm, which is
   precisely what an offshore project should be measured to - Hornsea
   (-0.2598, 53.6582) and Hornsea Two (-0.2604, 53.6568) at 400/220 kV,
   Thanet's explicitly-named onshore substation (1.3459, 51.3089), and the
   European Offshore Wind Deployment Centre (-2.0650, 57.2158). The rest are
   genuinely platforms at sea: Neart na Gaoithe North and South, Sheringham
   Shoal 1 and 2, Humber Gateway, Westermost Rough, Rampion, Burbo Bank 2.

   So a name filter would drop Hornsea - a landfall connection - from the very
   search it was supposed to sharpen. No onshore filter is applied, and this
   module says so on the card instead of pretending to one. An offshore
   project is measured against the SAME 5,800 features, at the SAME >=33 kV
   floor, by the SAME straight line as every other technology, and the card
   carries two extra sentences: that the line crosses water and is not the
   export cable, and that the set searched contains substations that are
   themselves offshore - named where one is returned, so the reader can see
   which. A stated limit, rather than a hidden one. A filter whose predicate
   is wrong four times in fourteen is worse than no filter, because it looks
   like precision.

   WHAT DOES NOT CHANGE, AND MUST NOT.

     - The straight line stays. It is the measurement, it is first, and the
       corridor-estimate module still sits beside it saying how far off a
       built route typically is. Nothing here replaces it.
     - Every superlative keeps carrying its sample. This module supplies the
       sample LABEL for each policy so the card cannot print "nearest"
       without printing what it searched.
     - The coordinate denominator stays. The operator publishes connection
       points and only a fraction carry coordinates; that count is computed
       at render time by nearestScope() and is not restated here, because a
       literal would go quietly false the day the pinned product moves.
     - Nothing here grades anything. No verdict word appears anywhere in this
       module, not even to disown one: the sandbox proof greps the served
       bytes for them and cannot tell a comment from a card, which is the
       right way round. A distance and a voltage, stated, and the things a
       distance cannot answer named rather than implied.

   THE ROSTER IS BY NAME ON PURPOSE.

   The Atlas never receives a raw REPD technology. Pipeline News' MAP link
   sends `technology=<t>`, the COLOUR BUCKET - so twenty raw types arrive as
   nine bucket values, and "Landfill Gas" reaches this cartridge as
   "biomass". Every one of the twenty is listed below against its bucket, so
   a proof can assert coverage by REPD name rather than by bucket, and so
   anyone reading this can see that the twenty are accounted for rather than
   assumed.
   ══════════════════════════════════════════════════════════════════════ */

(function installTechnologyCoverage() {
  'use strict';

  const SCHEMA = 'gridatlas.technology-coverage.v1';

  /* The twenty wider-fleet REPD technologies, each against the bucket the
     MAP link actually sends. Counts are the live wider-fleet payload,
     202609030009, 1,104 rows - carried so a drift in either side is visible
     rather than silent. Every one of the 1,104 rows carries a usable
     coordinate pair; none is withheld for want of a location. */
  const WIDER_FLEET = Object.freeze([
    Object.freeze({ repd: 'Landfill Gas',                       bucket: 'biomass',    rows: 275 }),
    Object.freeze({ repd: 'Anaerobic Digestion',                bucket: 'biomass',    rows: 253 }),
    Object.freeze({ repd: 'Biomass (dedicated)',                bucket: 'biomass',    rows: 159 }),
    Object.freeze({ repd: 'EfW Incineration',                   bucket: 'biomass',    rows: 122 }),
    Object.freeze({ repd: 'Small Hydro',                        bucket: 'hydro',      rows: 108 }),
    Object.freeze({ repd: 'Hydrogen',                           bucket: 'hydrogen',   rows: 60 }),
    Object.freeze({ repd: 'Advanced Conversion Technologies',   bucket: 'act',        rows: 37 }),
    Object.freeze({ repd: 'Large Hydro',                        bucket: 'hydro',      rows: 28 }),
    Object.freeze({ repd: 'Pumped Storage Hydroelectricity',    bucket: 'hydro',      rows: 15 }),
    Object.freeze({ repd: 'Tidal Stream',                       bucket: 'tidal',      rows: 14 }),
    Object.freeze({ repd: 'Sewage Sludge Digestion',            bucket: 'biomass',    rows: 12 }),
    Object.freeze({ repd: 'Geothermal',                         bucket: 'geothermal', rows: 5 }),
    Object.freeze({ repd: 'Shoreline Wave',                     bucket: 'tidal',      rows: 4 }),
    Object.freeze({ repd: 'Liquid Air Energy Storage',          bucket: 'caes',       rows: 2 }),
    Object.freeze({ repd: 'Biomass (co-firing)',                bucket: 'biomass',    rows: 2 }),
    Object.freeze({ repd: 'Hot Dry Rocks (HDR)',                bucket: 'geothermal', rows: 2 }),
    Object.freeze({ repd: 'Compressed Air Energy Storage',      bucket: 'caes',       rows: 2 }),
    Object.freeze({ repd: 'Fuel Cell (Hydrogen)',               bucket: 'hydrogen',   rows: 2 }),
    Object.freeze({ repd: 'Flywheels',                          bucket: 'flywheel',   rows: 1 }),
    Object.freeze({ repd: 'Unknown',                            bucket: 'other',      rows: 1 })
  ]);

  /* The spine, for completeness: the four the wider fleet is defined as
     excluding, and the four the shell's allow-list accepts. */
  const SPINE = Object.freeze(['solar', 'bess', 'wind_onshore', 'wind_offshore']);

  /* Offshore wind, in every spelling the register and the engine use. This
     is no longer a withholding set - it selects a DIFFERENT NOTE, not a
     different answer. */
  const OFFSHORE_TECHS = Object.freeze([
    'wind_offshore', 'wind_offshore_operational'
  ]);
  const OFFSHORE = new Set(OFFSHORE_TECHS);

  /* Named as offshore in the substation product. Used only to LABEL a
     returned row, never to remove one - see the header for the four onshore
     substations this pattern also matches, which is exactly why it does not
     filter. */
  const OFFSHORE_NAMED = /\boffshore\b/i;
  const ONSHORE_NAMED = /\bonshore\b/i;

  const PRODUCT = Object.freeze({
    features: 5800,
    with_location_tag: 0,
    offshore_in_name: 14,
    of_those_onshore: 4,
    source: 'atlas/releases/202608300453-atlas-v9/data/grid_substations.geojson'
  });

  /* The sentence the card prints under an offshore project's distances. It
     keeps every word of the old withholding note that was ABOUT ROUTES,
     because none of that reasoning was wrong; it drops only the conclusion
     that therefore nothing should be measured. */
  const OFFSHORE_NOTE =
    'This is a straight line from the project to the nearest mapped '
    + 'substation, and for an offshore project that line crosses water. It is '
    + 'not the export cable and not its length. An offshore project reaches an '
    + 'offshore substation, an export cable and a landfall before anything '
    + 'onshore, and the route inland is then chosen for consent and ground '
    + 'conditions rather than for distance, so the built length is longer than '
    + 'this by an amount no distance can tell you.';

  const OFFSHORE_SET_NOTE =
    'The set searched is the same 5,800 mapped substations used for every '
    + 'other technology. It carries no field saying which of them are onshore: '
    + 'the OSM location tag is absent from all 5,800, and of the 14 whose name '
    + 'contains "offshore" at least 4 are onshore substations serving an '
    + 'offshore wind farm. No onshore filter is applied, because one built on '
    + 'the name would drop those 4 - including Hornsea at 400/220 kV, which is '
    + 'a landfall connection. Where a result is itself named as an offshore '
    + 'substation it is marked below.';

  /* The label under which a measurement is made. The card must never print
     the word "nearest" without one of these beside it. */
  const SAMPLE = Object.freeze({
    mapped_substations: 'nearest of the mapped substations at or above the '
      + 'voltage floor that this search could see'
  });

  function bucketOf(tech) {
    return String(tech == null ? '' : tech).trim();
  }

  /**
   * What the measurement is, for one technology id.
   *
   * There is no `measure: false` branch. Every technology the register or
   * the wider fleet can send is measured; what differs is the note that
   * goes with it. A technology this module has never heard of is measured
   * too - the arrival lane already continues past an unknown id, and
   * refusing arithmetic over two coordinates because a string was
   * unfamiliar is how 109 offshore projects got nothing at all.
   */
  function policy(tech) {
    const id = bucketOf(tech);
    const offshore = OFFSHORE.has(id);
    return Object.freeze({
      technology: id || null,
      measure: true,
      offshore,
      sample: SAMPLE.mapped_substations,
      /* Both notes, in order, for offshore; nothing extra for the rest.
         The generic straight-line-is-not-a-route caveat is the card's own
         and is printed for every technology either way. */
      notes: Object.freeze(offshore ? [OFFSHORE_NOTE, OFFSHORE_SET_NOTE] : [])
    });
  }

  /**
   * Is this substation NAME one of the ones the product calls offshore?
   * Labelling only. A true here marks a row; it never removes one.
   */
  function namedOffshore(name) {
    const text = String(name == null ? '' : name);
    return OFFSHORE_NAMED.test(text) && !ONSHORE_NAMED.test(text);
  }

  /** The roster, by REPD name, for a proof to assert against. */
  function widerFleetNames() {
    return WIDER_FLEET.map(entry => entry.repd);
  }

  /** The bucket values the wider fleet's MAP link can actually send. */
  function widerFleetBuckets() {
    return [...new Set(WIDER_FLEET.map(entry => entry.bucket))].sort();
  }

  /** Every wider-fleet technology measures. Stated as a function so a proof
      cannot pass by reading a literal that stopped being true. */
  function measuredCount() {
    return WIDER_FLEET.filter(entry => policy(entry.bucket).measure).length;
  }

  const NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
  NS.technologyCoverage = Object.freeze({
    schema: SCHEMA,
    wider_fleet: WIDER_FLEET,
    spine: SPINE,
    offshore_techs: OFFSHORE_TECHS,
    product: PRODUCT,
    offshore_note: OFFSHORE_NOTE,
    offshore_set_note: OFFSHORE_SET_NOTE,
    sample: SAMPLE,
    policy,
    namedOffshore,
    widerFleetNames,
    widerFleetBuckets,
    measuredCount,
    /* Said once, here, so no caller has to phrase it and none can soften it. */
    not_a_connection: 'A distance to a mapped substation is not a connection, '
      + 'a capacity, a queue position or an offer, for any technology on this '
      + 'list.',
    shell_allow_list_note: 'The four-member technology allow-list in the '
      + 'immutable shell rejects every wider-fleet value and is caught; the '
      + 'arrival lane in this cartridge has already flown and carded by then, '
      + 'so it costs a console line and nothing else. The shell is carried '
      + 'forward verbatim and is not edited here.'
  });
})();

Arrival Tidy

A JavaScript file in the atlas folder of GridAtlas. It is built from the tidy step (`tidy`), the retire step (`retire`) and the watch step (`watch`).

interactiongridatlas / atlas/modules/202609032220-arrival-tidy.js · lines 1–94 of 94 · version 2026-09-03 22:20 · Not reached from any entry point (candidate for review) · pattern retire (shared by 8 files)

What it does
Defines tidy, retire, watch. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'atlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
What it achieves
The search machinery gets out of the way once it has answered. It responds to focus, input and DOMContentLoaded events.
Why it matters
No other file in the estate was found to import it.
Application
gridatlas · atlas/modules · script
Uses
none found
Used by
none found
Produces
tidy, retire, watch
Defines here
tidy, retire, watch
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/modules/202609032220-arrival-tidy.js:1-94 · blob 67dc8a3457c7678214738c17ee41fe6ab4b89c47 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
/* Arrival tidy - the search machinery gets out of the way once it has answered.

   MEASURED, on v9.96 at 393x852, arriving at ?repd_ref=12588 the way a shared
   link arrives: the map canvas was topmost at 13 per cent of 3,200 sampled
   viewport points and the app's own controls at 87. Three of those controls
   were the SEARCH, not the answer - the results list still open at
   [40,136,302,92] holding the project the reader had already been taken to,
   the box holding "12588", a reference the reader never typed, and the
   identity repeated in the results row, the search bar and the card header.

   A deep link is not a search. The reader asked for one project by name and
   got it; the list of how it was found is scaffolding, and scaffolding left
   up is clutter. So on a RESOLVED arrival the list is dismissed and the box
   is emptied back to its placeholder.

   WHAT THIS DELIBERATELY DOES NOT DO

   - It does not touch a FAILED arrival. When the identity could not be
     resolved the results are the only thing on screen that explains why, and
     hiding them would leave a reader with a map and no account of it.
   - It does not clear a box the reader has touched. Focus or a keystroke
     retires this permanently, so a reader who starts typing while the
     arrival is still resolving never has their text taken away.
   - It does not clear a box holding something other than the ref, which is
     the same rule stated for the case where another lane wrote there first.
   - It hides with `style.display = 'none'`, which is what the shell's own
     Escape key and map click do. This is the product's mechanism, not a new
     one, so nothing has to be taught how to bring it back.

   It runs only where there is a MutationObserver. The cartridge proofs
   execute composed cartridges under node:vm against a window stub that has
   neither observers nor timers, and a module that throws there takes the
   whole cartridge down with it - which is exactly how v9.92 shipped a menu
   bar that broke the sandbox proof. Where there is no observer there is no
   arrival either, so doing nothing is the correct answer rather than a
   degraded one. */
(function arrivalTidy() {
  if (typeof document === 'undefined' || typeof window === 'undefined') return;
  if (typeof MutationObserver !== 'function') return;

  var ref = '';
  try {
    ref = String(new URLSearchParams(window.location.search).get('repd_ref') || '').trim();
  } catch (_) { return; }
  if (!ref) return;

  var typed = false;
  var done = false;

  function tidy() {
    if (done) return true;
    var state = document.body && document.body.dataset
      ? document.body.dataset.gridatlasRepdDeepLink : '';
    if (state !== 'resolved') return state === 'failed';   /* failed: stop watching, change nothing */
    var results = document.getElementById('search-results');
    var input = document.getElementById('search-input');
    if (!results || !input) return false;
    if (!typed) {
      results.style.display = 'none';
      if (input.value === ref) input.value = '';
    }
    done = true;
    return true;
  }

  function retire() { typed = true; }

  function watch() {
    var input = document.getElementById('search-input');
    if (input) {
      input.addEventListener('focus', retire, { once: true });
      input.addEventListener('input', retire, { once: true });
    }
    if (tidy()) return;
    var observer = new MutationObserver(function () {
      if (tidy()) observer.disconnect();
    });
    observer.observe(document.body, {
      attributes: true, attributeFilter: ['data-gridatlas-repd-deep-link']
    });
    window.__GRIDATLAS_ARRIVAL_TIDY__ = {
      installed: true,
      repd_ref: ref,
      get dismissed() { return done; },
      get retired_by_reader() { return typed; }
    };
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', watch, { once: true });
  } else {
    watch();
  }
}());