o

In the playground window, o is the output: the embedded <iframe id=o> that shows the page your source renders. The Playground API adds three members to it. o.input maps elements of the live output back to their authored source, o.pins is a PinList that points at elements and regions of the output, and o.getDimensions() measures the output frame.

Use them from the console of the playground tab or from io.eval.js. Code that runs inside the output, for example from o.eval.js, is on the other side of the frame: there, sync.input offers the same lookup for elements of that document. File evals describes both files.

Instance properties

o.input

An object with the authored-source lookups described in Instance methods. It exists only while Agent Folder Share is active, which needs Chrome or Edge on desktop and a top-level playground. Without a share, o.input is undefined, and calling one of its methods throws a TypeError.

o.pins

A PinList: a live array of pin handles with methods to add, update, capture and delete the pins of the output. It exists in browsers with the share stack, in a top-level playground, and its methods need an active Agent Folder Share.

Note: When you move the output into its own tab or popup (see Output windows), o becomes a plain relay Experimental. o.getDimensions(), o.input and o.pins then no longer apply.

Instance methods

Each o.input method takes one CSS selector string and returns a Promise. Anything else rejects with TypeError('o.input.<method>() expects a CSS selector string.'). Arrays line up with the matches, in order. A null means that the element has no authored source: it was created at runtime.

o.input.pos()

Resolves to an array with one item per matching element: { start, end }, or null. The offsets are zero-based UTF-16 offsets into the editor source, and end is exclusive.

o.input.sel()

Resolves to an array with one item per matching element: [sl, sc, el, ec, 0], or null. Lines and columns are 1-based. The array is ready to assign to sel, which ignores the null items.

o.input.inner()

Resolves to the authored inner HTML of the first matching element, as a string, or to null. For a void or self-closing element it is ''.

o.input.outer()

Resolves to the authored outer HTML of the first matching element, as a string, or to null.

o.input.innerAll()

Resolves to an array with the authored inner HTML of every matching element: strings and nulls.

o.input.outerAll()

Resolves to an array with the authored outer HTML of every matching element: strings and nulls.

o.input.innerAll.concat()

Resolves to the non-null inner strings of all matches, joined with one \n, like repeated textual o:= bodies. Empty strings are kept. With nothing left it resolves to ''.

o.input.outerAll.concat()

The same for the outer strings.

o.getDimensions()

Returns { aspectRatio: [w, h], x, y, width, height, top, right, bottom, left }, synchronously: the size and position of the output frame as it is displayed in the playground, in the playground's CSS pixels and including the zoom oz. It is not the size of the output's own viewport. getDimensions() describes the method, which every element of the playground window has.

Usage notes

Errors

RejectionWhen
InvalidStateError: IOSync source is unavailable or stale. or IOSync source map is unavailable or stale.The output has not synced the current editor text. Wait for the next sync and call again.
InvalidStateError: Input changed during input lookup.The source changed while the call was running.
Output is not ready.There is no embedded output, for example because it is in its own window.
Output returned an invalid o.input.<method>() result.The output answered with something that is not a result.
SyntaxErrorThe selector is not valid. The name of the error is reliable; its message may not be the browser's selector message.
TypeErroro.input is undefined because no share is active, or the argument is not a string.

Further InvalidStateError messages that start with IOSync mean that the source records of the output and the editor disagree. Call again after the next sync.

Examples

A page to look up

Open this page in the playground and start Agent Folder Share. The lookups below find its authored source.

html
<main>
  <h1>Gallery</h1>
  <section class=card>One</section>
  <section class=card>Two</section>
</main>

Looking up authored source

Each line is one command. Write it to io.eval.js and read io.eval.json before the next one.

js
await o.input.outer('main > h1')        // '<h1>Gallery</h1>'
await o.input.innerAll('.card')          // ['One', 'Two']
await o.input.pos('.card')               // [{ start, end }, { start, end }]
sel = await o.input.sel('.card')         // selects both cards in the editor

If nothing is mapped, because there is no match or the matches were created at runtime, sel receives [] or only nulls, and the cursor moves to line 1, column 1.

Measuring the output

js
o.getDimensions()   // { aspectRatio: [3, 2], x, y, width: 600, height: 400, … }

Specifications

Not part of any specification. o.input, o.pins and o.getDimensions() are RTCode.io playground features. o is an <iframe> element, and getDimensions() builds on getBoundingClientRect().

Availability

FeaturePlaygroundRTEdge.netNotes
o.inputYesNoNeeds Agent Folder Share (Chrome or Edge on desktop) and the embedded output.
o.pinsYesNoNeeds Agent Folder Share. Pin images also need Output screen capture.
o.getDimensions()YesNoNeeds the embedded output.

See also