uiport 0.1.1 → 0.1.3
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/CHANGELOG.md +41 -0
- package/README.md +10 -7
- package/README.pt-BR.md +10 -7
- package/SECURITY.md +1 -1
- package/bin/cli.mjs +34 -8
- package/docs/architecture.md +1 -1
- package/docs/support.md +17 -3
- package/package.json +1 -1
- package/scripts/capture.mjs +171 -36
- package/scripts/contract.mjs +14 -0
- package/scripts/css-context.mjs +18 -10
- package/scripts/diff.mjs +149 -0
- package/scripts/dom.mjs +59 -94
- package/scripts/errors.mjs +53 -0
- package/scripts/examples.mjs +37 -0
- package/scripts/inspect.mjs +50 -0
- package/scripts/lib.mjs +20 -19
- package/scripts/options.mjs +52 -12
- package/scripts/report.mjs +119 -0
- package/scripts/resources.mjs +130 -70
- package/scripts/srcset.mjs +14 -0
- package/scripts/stdout.mjs +13 -0
- package/scripts/validate.mjs +73 -41
- package/skills/uiport/SKILL.md +39 -8
- package/uiport.md +13 -4
package/scripts/validate.mjs
CHANGED
|
@@ -3,6 +3,14 @@ import path from "node:path";
|
|
|
3
3
|
import pixelmatch from "pixelmatch";
|
|
4
4
|
import { PNG } from "pngjs";
|
|
5
5
|
import { chromium } from "playwright-core";
|
|
6
|
+
import { UiportError } from "./errors.mjs";
|
|
7
|
+
import {
|
|
8
|
+
BEHAVIOR,
|
|
9
|
+
LEGACY_ROOT_ATTR,
|
|
10
|
+
METADATA_ID,
|
|
11
|
+
ROOT_ATTR,
|
|
12
|
+
ROOT_VALUE,
|
|
13
|
+
} from "./contract.mjs";
|
|
6
14
|
import {
|
|
7
15
|
launchChromium,
|
|
8
16
|
lifecycle,
|
|
@@ -12,25 +20,23 @@ import {
|
|
|
12
20
|
startStaticServer,
|
|
13
21
|
waitForPageStable,
|
|
14
22
|
} from "./lib.mjs";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function copy(source, destination) {
|
|
23
|
+
// Copy a decoded PNG into a buffer of the comparison size, padding the rows
|
|
24
|
+
// that the source does not cover with transparent pixels. The copy happens one
|
|
25
|
+
// row at a time: a per-pixel copy costs one Buffer.copy call per pixel.
|
|
26
|
+
function copy(source, destination, width) {
|
|
27
|
+
const bytesPerPixel = 4;
|
|
28
|
+
const rowBytes = source.width * bytesPerPixel;
|
|
22
29
|
for (let y = 0; y < source.height; y += 1) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
32
|
-
}
|
|
30
|
+
const sourceStart = y * rowBytes;
|
|
31
|
+
const destinationStart = y * width * bytesPerPixel;
|
|
32
|
+
source.data.copy(
|
|
33
|
+
destination,
|
|
34
|
+
destinationStart,
|
|
35
|
+
sourceStart,
|
|
36
|
+
sourceStart + rowBytes,
|
|
37
|
+
);
|
|
33
38
|
}
|
|
39
|
+
return destination;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
export async function validate(options) {
|
|
@@ -71,11 +77,18 @@ export async function validate(options) {
|
|
|
71
77
|
await waitForPageStable(source, options.settleMs);
|
|
72
78
|
const root = source.locator(options.selector);
|
|
73
79
|
if ((await root.count()) !== 1)
|
|
74
|
-
throw new
|
|
80
|
+
throw new UiportError(
|
|
81
|
+
"SELECTOR_AMBIGUOUS",
|
|
82
|
+
"The source selector matched no element or more than one",
|
|
83
|
+
);
|
|
75
84
|
const box = await root.boundingBox();
|
|
76
|
-
if (!box || box.width
|
|
85
|
+
if (!box || box.width <= 0 || box.height <= 0)
|
|
86
|
+
throw new Error(
|
|
87
|
+
"The source selector does not render a visible box; choose a selector that matches a visible element",
|
|
88
|
+
);
|
|
89
|
+
if (box.width * box.height > 20_000_000)
|
|
77
90
|
throw new Error(
|
|
78
|
-
"Source section
|
|
91
|
+
"Source section exceeds the 20 megapixel screenshot limit",
|
|
79
92
|
);
|
|
80
93
|
const sourceBuffer = await root.screenshot({
|
|
81
94
|
animations: "disabled",
|
|
@@ -122,16 +135,30 @@ export async function validate(options) {
|
|
|
122
135
|
});
|
|
123
136
|
await waitForPageStable(local, options.settleMs);
|
|
124
137
|
// Legacy root markers remain supported for existing user exports.
|
|
125
|
-
const
|
|
126
|
-
.locator(
|
|
138
|
+
const isCurrent = (await local
|
|
139
|
+
.locator(`[${ROOT_ATTR}="${ROOT_VALUE}"]`)
|
|
127
140
|
.count())
|
|
128
|
-
?
|
|
129
|
-
:
|
|
141
|
+
? true
|
|
142
|
+
: false;
|
|
143
|
+
const rootSelector = isCurrent
|
|
144
|
+
? `[${ROOT_ATTR}="${ROOT_VALUE}"]`
|
|
145
|
+
: `[${LEGACY_ROOT_ATTR}="${ROOT_VALUE}"]`;
|
|
130
146
|
const localRoot = local.locator(rootSelector);
|
|
131
147
|
if ((await localRoot.count()) !== 1)
|
|
132
148
|
throw new Error("UIport extraction root is missing or ambiguous");
|
|
149
|
+
// An export of this version carries its metadata. Without it the
|
|
150
|
+
// artifact was changed after the capture, and the result would report
|
|
151
|
+
// no limitation at all.
|
|
152
|
+
if (isCurrent && !(await local.locator(`#${METADATA_ID}`).count()))
|
|
153
|
+
throw new Error(
|
|
154
|
+
"The exported section has no UIport metadata; it was modified after the capture",
|
|
155
|
+
);
|
|
133
156
|
const localBox = await localRoot.boundingBox();
|
|
134
|
-
if (!localBox || localBox.width
|
|
157
|
+
if (!localBox || localBox.width <= 0 || localBox.height <= 0)
|
|
158
|
+
throw new Error(
|
|
159
|
+
"The exported section does not render a visible box; the capture may have exported a hidden or empty root",
|
|
160
|
+
);
|
|
161
|
+
if (localBox.width * localBox.height > 20_000_000)
|
|
135
162
|
throw new Error("Exported section exceeds screenshot limit");
|
|
136
163
|
const localBuffer = await localRoot.screenshot({
|
|
137
164
|
animations: "disabled",
|
|
@@ -143,18 +170,23 @@ export async function validate(options) {
|
|
|
143
170
|
height = Math.max(sourcePng.height, localPng.height);
|
|
144
171
|
if (width * height > 20_000_000)
|
|
145
172
|
throw new Error("Comparison exceeds screenshot limit");
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
173
|
+
// When both sides have the same size their decoded pixels are already
|
|
174
|
+
// the comparison buffer: no padding copy is needed.
|
|
175
|
+
const sameSize =
|
|
176
|
+
sourcePng.width === localPng.width &&
|
|
177
|
+
sourcePng.height === localPng.height;
|
|
178
|
+
let left, right;
|
|
179
|
+
if (sameSize) {
|
|
180
|
+
left = sourcePng.data;
|
|
181
|
+
right = localPng.data;
|
|
182
|
+
} else {
|
|
183
|
+
left = copy(sourcePng, new Uint8Array(width * height * 4), width);
|
|
184
|
+
right = copy(localPng, new Uint8Array(width * height * 4), width);
|
|
185
|
+
}
|
|
186
|
+
const differentPixels = pixelmatch(left, right, null, width, height, {
|
|
187
|
+
threshold: 0.1,
|
|
188
|
+
includeAA: false,
|
|
189
|
+
});
|
|
158
190
|
const differenceRatio = differentPixels / (width * height);
|
|
159
191
|
const dimensionsMatch =
|
|
160
192
|
sourcePng.width === localPng.width &&
|
|
@@ -165,10 +197,10 @@ export async function validate(options) {
|
|
|
165
197
|
failedRequests.length === 0 &&
|
|
166
198
|
(options.allowExternal || externalRequests.length === 0);
|
|
167
199
|
const captureLimitations = (await local
|
|
168
|
-
.locator(
|
|
200
|
+
.locator(`#${METADATA_ID}`)
|
|
169
201
|
.count())
|
|
170
202
|
? await local
|
|
171
|
-
.locator(
|
|
203
|
+
.locator(`#${METADATA_ID}`)
|
|
172
204
|
.evaluate((el) => JSON.parse(el.textContent).limitations)
|
|
173
205
|
: [];
|
|
174
206
|
results.push({
|
|
@@ -188,7 +220,7 @@ export async function validate(options) {
|
|
|
188
220
|
failedRequests,
|
|
189
221
|
externalBlocked: !options.allowExternal,
|
|
190
222
|
},
|
|
191
|
-
behavior:
|
|
223
|
+
behavior: BEHAVIOR,
|
|
192
224
|
captureLimitations,
|
|
193
225
|
errors,
|
|
194
226
|
scrollLimited,
|
|
@@ -203,7 +235,7 @@ export async function validate(options) {
|
|
|
203
235
|
command: "validate",
|
|
204
236
|
status: results.every((r) => r.pass) ? "complete" : "failed",
|
|
205
237
|
browser: { selected, version: browser.version() },
|
|
206
|
-
behavior:
|
|
238
|
+
behavior: BEHAVIOR,
|
|
207
239
|
results,
|
|
208
240
|
};
|
|
209
241
|
} finally {
|
package/skills/uiport/SKILL.md
CHANGED
|
@@ -7,14 +7,45 @@ description: Capture a rendered web section as editable HTML, original CSS and l
|
|
|
7
7
|
|
|
8
8
|
Use for a request to extract an existing web section into local files. Use pages the user owns or has permission to reuse. Do not redesign or invent replacement effects.
|
|
9
9
|
|
|
10
|
-
1. Inspect the requested URL and choose one CSS selector matching a section container, or body/html for a full page. Include wrappers/decorations that belong to it; html also includes original head scripts.
|
|
11
|
-
2. Use the installed CLI or source checkout. `npx uiport@0.1.
|
|
10
|
+
1. Inspect the requested URL and choose one CSS selector matching a section container, or body/html for a full page. Include wrappers/decorations that belong to it; html also includes original head scripts. The selected root must render something at the captured viewport: a root that displays nothing is reported as a partial result.
|
|
11
|
+
2. Use the installed CLI or source checkout. `npx uiport@0.1.3` is the pinned form. When testing an unpublished version, use `node bin/cli.mjs` from its checkout.
|
|
12
12
|
3. If needed, install the matching browser with `uiport browser install`. No browser download is hidden inside capture.
|
|
13
|
-
4.
|
|
14
|
-
5.
|
|
15
|
-
6.
|
|
16
|
-
7.
|
|
17
|
-
8.
|
|
18
|
-
9.
|
|
13
|
+
4. Check the selector first with `uiport capture --url "URL" --selector "SELECTOR" --dry-run`. It reports whether the selector resolves to one visible element and writes nothing.
|
|
14
|
+
5. Run `uiport capture --url "URL" --selector "SELECTOR" --out "NEW_DIRECTORY" --json`. The default locale is pt-BR. Match locale/color scheme/viewports to the requested source. Never overwrite an existing nonempty directory.
|
|
15
|
+
6. Read the result. Exit 0 means no known reported limitations, not universal fidelity. Exit 2 means a partial artifact exists; inspect every limitation. Exit 1 means failure. With `--json` stdout carries one JSON document; without it, stdout carries a readable summary and progress goes to stderr.
|
|
16
|
+
7. Preview with `uiport serve --dir "DIRECTORY"` and compare with `uiport validate --url "URL" --selector "SELECTOR" --dir "DIRECTORY" --json`, using the same viewport/locale/color-scheme options. `uiport inspect --dir "DIRECTORY" --json` reads the limitations of an artifact without opening a browser.
|
|
17
|
+
8. Inspect hover/focus, animation and relevant interactions separately. Validation disables animation for screenshots and reports behavior as not tested. Source scripts inside the selection, inline handlers and recognized visual library scripts are retained by default. Use capture --omit-scripts to omit them explicitly. Outside initialization, listeners and framework dependencies are not generically recovered; inspect SOURCE_RUNTIME_UNVERIFIED.
|
|
18
|
+
9. If an effect cannot be isolated from original source, explain the limitation. Do not create a visually similar substitute and call it an extraction. Manual integration of necessary original runtime code is separate work requiring inspection and validation.
|
|
19
|
+
10. Deliver `index.html` and `assets/` only in the extraction folder. Put reports/screenshots outside it. State the path, verified behavior and remaining limitations.
|
|
20
|
+
|
|
21
|
+
## When the command fails
|
|
22
|
+
|
|
23
|
+
The error document carries a `code` and a `hint`.
|
|
24
|
+
|
|
25
|
+
| Code | What to do |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `USAGE_INVALID` | Fix the arguments; the hint names the option. |
|
|
28
|
+
| `BROWSER_NOT_FOUND` | Run `uiport browser install`, or set `UIPORT_BROWSER_PATH`. |
|
|
29
|
+
| `OUTPUT_NOT_EMPTY` | Choose a new directory, or empty the existing one. |
|
|
30
|
+
| `SELECTOR_NOT_FOUND` | The selector matched nothing: inspect the page, check whether the element needs an interaction first. |
|
|
31
|
+
| `SELECTOR_AMBIGUOUS` | Narrow the selector, or capture the whole page with `--selector body`. |
|
|
32
|
+
| `TIMEOUT` | Raise `--timeout` or reduce `--viewports`. |
|
|
33
|
+
| `CANCELLED` | The run was interrupted. |
|
|
34
|
+
|
|
35
|
+
## What each limitation asks for
|
|
36
|
+
|
|
37
|
+
| Limitation | What to do |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `SOURCE_RUNTIME_UNVERIFIED` | Test the interactions before delivering. |
|
|
40
|
+
| `SOURCE_RUNTIME_OMITTED` | The behavior of the section is not reproduced. |
|
|
41
|
+
| `RESOURCE_UNAVAILABLE` | A resource was not downloaded: check it in the output. |
|
|
42
|
+
| `SRCSET_INVALID` | A descriptor list was not parsed: check which image the browser picks. |
|
|
43
|
+
| `SCROLL_LIMIT` | The lazy loading was cut short: raise `--max-scroll-steps`. |
|
|
44
|
+
| `RESPONSIVE_DOM_CHANGED` | The structure changes across viewports; the first viewport was exported. |
|
|
45
|
+
| `SECTION_NOT_VISIBLE` / `SECTION_EMPTY_AREA` | The selected root displays nothing: choose an element that renders. |
|
|
46
|
+
| `CANVAS_STATIC` / `CANVAS_UNREADABLE` | A canvas was exported as a still image, or could not be read. |
|
|
47
|
+
| `EMBED_OMITTED` | An embedded document was disabled. |
|
|
48
|
+
| `ANIMATION_UNSUPPORTED` | An animation could not be replayed. |
|
|
49
|
+
| `CSS_IMPORT_CYCLE` / `CSS_IMPORT_UNSUPPORTED` | A stylesheet import was omitted. |
|
|
19
50
|
|
|
20
51
|
The tool does not generate React/Next components or clone application backends. The project license covers UIport, not third-party captured assets. Never publish customer extracts or credentials as fixtures.
|
package/uiport.md
CHANGED
|
@@ -37,7 +37,7 @@ O objetivo da revisão manual é manter somente os assets necessários à seçã
|
|
|
37
37
|
- Abra a URL em navegador com JavaScript habilitado.
|
|
38
38
|
- Aguarde DOM, rede, fontes e imagens estabilizarem dentro de um prazo limitado; não espere indefinidamente por páginas com atividade contínua.
|
|
39
39
|
- Role a página para ativar lazy loading e efeitos de entrada. Inspecione o diagnóstico se o limite de rolagem for atingido.
|
|
40
|
-
- Localize uma única raiz que contenha toda a seção, incluindo elementos decorativos, overlays e backgrounds. O seletor deve encontrar uma única raiz. Use um container para uma seção, `body` para a página visível inteira ou `html` para incluir também os scripts do head; não se trata de crawling de múltiplas páginas.
|
|
40
|
+
- Localize uma única raiz que contenha toda a seção, incluindo elementos decorativos, overlays e backgrounds. O seletor deve encontrar uma única raiz, e essa raiz precisa renderizar no viewport capturado. Use um container para uma seção, `body` para a página visível inteira ou `html` para incluir também os scripts do head; não se trata de crawling de múltiplas páginas.
|
|
41
41
|
- Observe o estado inicial e todas as interações relevantes: entrada, scroll, hover, foco, tabs, accordion, carousel e mousemove.
|
|
42
42
|
- Compare os tamanhos de tela necessários e mantenha viewport, idioma e tema consistentes entre captura e validação.
|
|
43
43
|
|
|
@@ -75,7 +75,7 @@ O objetivo da revisão manual é manter somente os assets necessários à seçã
|
|
|
75
75
|
|
|
76
76
|
Use a CLI como ponto de partida, não como autorização para entregar um clone quebrado.
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
Para usar o código-fonte deste repositório em vez do pacote publicado, execute na raiz do repositório:
|
|
79
79
|
|
|
80
80
|
```sh
|
|
81
81
|
npm ci
|
|
@@ -90,17 +90,26 @@ node bin/cli.mjs capture --url "<URL>" --selector "<SELETOR>" --out "./extractio
|
|
|
90
90
|
|
|
91
91
|
Ajuste `--locale`, `--color-scheme` e `--viewports` conforme a origem e use os mesmos valores na validação. A captura não sobrescreve uma pasta existente com conteúdo. `UIPORT_BROWSER_PATH` permite escolher o executável do navegador; a instalação do Chromium é explícita.
|
|
92
92
|
|
|
93
|
-
Os mesmos subcomandos podem ser executados com `npx uiport@0.1.
|
|
93
|
+
Os mesmos subcomandos podem ser executados com `npx uiport@0.1.3` no lugar de `node bin/cli.mjs`. Ao testar uma versão ainda não publicada, use o checkout local. Consulte os [comandos e opções](README.pt-BR.md) ou execute `node bin/cli.mjs --help`.
|
|
94
|
+
|
|
95
|
+
Confira o seletor antes de capturar, sem escrever nada:
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
node bin/cli.mjs capture --url "<URL>" --selector "<SELETOR>" --dry-run
|
|
99
|
+
```
|
|
94
100
|
|
|
95
101
|
Leia o diagnóstico antes de entregar:
|
|
96
102
|
|
|
97
103
|
- Capture com retorno **0**: artefato criado sem limitações conhecidas relatadas; não é prova de fidelidade universal.
|
|
98
104
|
- Capture com retorno **2**: artefato parcial criado; investigue cada item de `limitations`.
|
|
99
105
|
- Retorno **1**: falha operacional ou falha das verificações solicitadas no validate.
|
|
100
|
-
- `--json`:
|
|
106
|
+
- `--json`: um único documento JSON em stdout. Sem `--json`, o stdout traz um resumo legível e o progresso vai para stderr. Não confunda um artefato parcial com falha sem saída.
|
|
107
|
+
- `node bin/cli.mjs inspect --dir "<PASTA>"`: lê as limitações de um artefato já exportado, sem abrir navegador.
|
|
101
108
|
|
|
102
109
|
O idioma padrão permanece `pt-BR`. `capture --omit-scripts` desativa a cópia de scripts da origem e eventos inline; nesse modo, animações WAAPI observadas continuam podendo ser reproduzidas. Sem essa opção, `SOURCE_RUNTIME_UNVERIFIED` pede inspeção do código preservado.
|
|
103
110
|
|
|
111
|
+
A raiz escolhida precisa renderizar no viewport capturado. `SECTION_NOT_VISIBLE` e `SECTION_EMPTY_AREA` significam que o markup foi exportado, mas não exibe nada: corrija o seletor para um elemento visível ou capture a página inteira com `body`. `SRCSET_INVALID` significa que a lista de descritores do `srcset` não pôde ser interpretada; o valor original foi preservado, então confira qual imagem o navegador escolhe.
|
|
112
|
+
|
|
104
113
|
Se houver runtime omitido ou não verificado, recurso não localizado, mudança estrutural responsiva ou canvas dinâmico, investigue a origem antes de concluir.
|
|
105
114
|
|
|
106
115
|
## Validação obrigatória
|