Sketch check
The rules the mockup compiler applies to a sketch's HTML and CSS, and the checkSketch function that runs the same check in another process.
A sketch is static HTML and CSS that the viewer draws in a sandboxed frame. The frame's Content Security Policy stops the sketch from loading anything, but it does not stop a link out of the frame. The check on this page closes that gap. The only link out it lets through is a mockup's link to one of its own pages.
The mockup compiler runs this check. A refused sketch is drawn empty, and each refusal is an issue.
Markup rules
The compiler parses html as the body of a document with scripting off, as the sandboxed frame reads it. It then checks the parsed tree against these lists.
| What | Allowed | Refused |
|---|---|---|
| Elements | Text and layout HTML, such as headings, paragraphs, lists, tables, div, span, img, figure, details, button, input, textarea and style. An SVG subset for drawings, and a MathML subset for formulas. | Any other element, such as <script>, <iframe>, <object>, <embed>, <link>, <base>, <meta>, <form>, <template>, <noscript>, <foreignObject>, <set> and <animate>. |
| Attributes | id, class, style, title, lang, dir, role, hidden, tabindex, aria-* and data-* on any element. The SVG presentation and geometry attributes. The few each HTML element needs, such as alt on <img> or colspan on a cell. | Any other attribute, including every on* handler and target. |
| Link URLs | An #anchor in href on <a>, SVG <a> and <use>. In a mockup, also href="page:<id>" on an HTML <a>. | Any other URL. |
| Image URLs | A data:image/ URL in src on <img> and href on SVG <image>. | Any other URL. |
The size limits are:
- 524,288 characters in each of
htmlandcss. - 4,096 tags, and 64 attributes on one tag.
- 8,195 elements built by the parser, and 256 levels of nesting.
A css that holds </style is refused before it is parsed.
Style sheet rules
The check reads CSS from css, from <style> elements, from style attributes and from every SVG and MathML attribute. It tokenizes the CSS as the CSS Syntax spec does, with escapes and comments.
| What | Allowed |
|---|---|
| At-rules | @media, @supports, @container, @layer, @keyframes, @font-face, @page, @scope and @starting-style. None of them loads anything. |
| Value functions | Colours such as rgb(), oklch() and color-mix(). Math such as calc(), clamp() and the trigonometric functions. Gradients, transforms and filters. counter(), repeat(), minmax(), fit-content(), easing functions and shapes such as polygon(). Selector functions such as :not(), :has() and :nth-child(). These hold no string. |
| Text functions | var(), env(), attr() unless typed as a URL, counters(), format(), local(), tech(), :lang() and path(). These may hold strings. |
| Loaders | url() and src() with a quoted #anchor or data:image/ URL. image(), image-set() and cross-fade() whose strings are such URLs. A loader holds no var(), env() or attr(). |
| Strings | Strings outside any function, such as in content or font-family. |
Function names are compared after unescaping and after removing a vendor prefix such as -webkit-. CSS holds at most 64 nested brackets and functions.
Everything else is refused. Examples are @import, @property, a dashed call such as --u(), if(), an image() with a remote URL, a string or url() a browser reads as broken, and markup such as </style> in css.
Output
A sketch that passes is drawn with its html written back from the parsed tree, without comments, so the frame draws what was checked. The written-back markup can differ from the source in quotes and in elements the parser closed or reopened. Markup that the parser would read differently once written back is refused.
Run the check in another process
@antelopejs/dms/sketch exports the check. It needs only zod, parse5 and @csstools/css-tokenizer, loads without the AntelopeJS runtime, and runs on Node ^20.19.0 || >=22.12.0.
import { checkSketch } from "@antelopejs/dms/sketch";
const checked = checkSketch({
html: '<p class="note">Packed</p>',
css: ".note{color:var(--sketch-accent)}",
});
if (!checked.ok) {
throw new Error(checked.refusals.map(({ what }) => what).join("; "));
}
const drawn = checked.sketch;
| Function | Answer |
|---|---|
checkSketch(sketch, options?) | { ok: true, sketch } with the markup to draw, or { ok: false, refusals } with one { field, what } per refusal. |
sketchRefusals(sketch) | The refusals as strings. An empty list means the sketch may be drawn. |
checkSketch takes { pageLink } as its second argument. With it, an HTML <a href="page:<id>"> passes, and pageLink(id) answers the URL it goes to, or undefined to refuse the id. The link is written <a href="<url>" target="_top">. Without pageLink, as in sketchRefusals, a page: link is refused.
import { checkSketch } from "@antelopejs/dms/sketch";
const checked = checkSketch(
{ html: '<a href="page:orders">Orders</a>' },
{ pageLink: (id) => `/mockup?name=shop&page=${id}` },
);
// checked.sketch.html: <a href="/mockup?name=shop&page=orders" target="_top">Orders</a>