@rettangoli/vt 0.0.14 → 1.0.0-rc12

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.
@@ -0,0 +1,99 @@
1
+ const VIEWPORT_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
2
+
3
+ export const DEFAULT_VIEWPORT = Object.freeze({
4
+ width: 1280,
5
+ height: 720,
6
+ });
7
+
8
+ function valueType(value) {
9
+ if (Array.isArray(value)) return "array";
10
+ if (value === null) return "null";
11
+ return typeof value;
12
+ }
13
+
14
+ function assert(condition, message) {
15
+ if (!condition) {
16
+ throw new Error(message);
17
+ }
18
+ }
19
+
20
+ function validateViewportEntry(entry, path) {
21
+ assert(
22
+ entry !== null && typeof entry === "object" && !Array.isArray(entry),
23
+ `"${path}" must be an object, got ${valueType(entry)}.`,
24
+ );
25
+
26
+ assert(
27
+ typeof entry.id === "string" && entry.id.trim().length > 0,
28
+ `"${path}.id" is required and must be a non-empty string.`,
29
+ );
30
+ assert(
31
+ VIEWPORT_ID_PATTERN.test(entry.id),
32
+ `"${path}.id" must contain only letters, numbers, "-" or "_".`,
33
+ );
34
+ assert(
35
+ typeof entry.width === "number" && Number.isInteger(entry.width) && entry.width >= 1,
36
+ `"${path}.width" must be an integer >= 1.`,
37
+ );
38
+ assert(
39
+ typeof entry.height === "number" && Number.isInteger(entry.height) && entry.height >= 1,
40
+ `"${path}.height" must be an integer >= 1.`,
41
+ );
42
+
43
+ return {
44
+ id: entry.id,
45
+ width: entry.width,
46
+ height: entry.height,
47
+ };
48
+ }
49
+
50
+ export function normalizeViewportField(rawViewport, path = "viewport") {
51
+ if (rawViewport === undefined || rawViewport === null) {
52
+ return undefined;
53
+ }
54
+
55
+ const rawEntries = Array.isArray(rawViewport) ? rawViewport : [rawViewport];
56
+ assert(rawEntries.length > 0, `"${path}" cannot be an empty array.`);
57
+
58
+ const entries = rawEntries.map((entry, index) =>
59
+ validateViewportEntry(entry, `${path}[${index}]`),
60
+ );
61
+
62
+ const seen = new Map();
63
+ entries.forEach((entry, index) => {
64
+ const canonicalId = entry.id.toLowerCase();
65
+ const existingIndex = seen.get(canonicalId);
66
+ assert(
67
+ existingIndex === undefined,
68
+ `"${path}[${index}].id" duplicates "${path}[${existingIndex}].id" (case-insensitive).`,
69
+ );
70
+ seen.set(canonicalId, index);
71
+ });
72
+
73
+ return entries;
74
+ }
75
+
76
+ export function resolveViewports(frontMatterViewport, configViewport) {
77
+ const selected = frontMatterViewport ?? configViewport;
78
+ if (selected === undefined || selected === null) {
79
+ return [
80
+ {
81
+ id: null,
82
+ width: DEFAULT_VIEWPORT.width,
83
+ height: DEFAULT_VIEWPORT.height,
84
+ },
85
+ ];
86
+ }
87
+ return normalizeViewportField(selected, "viewport");
88
+ }
89
+
90
+ export function appendViewportToBaseName(baseName, viewportId) {
91
+ if (!viewportId) {
92
+ return baseName;
93
+ }
94
+ return `${baseName}--${viewportId}`;
95
+ }
96
+
97
+ export function stripViewportSuffix(itemKey) {
98
+ return itemKey.replace(/--[A-Za-z0-9_-]+$/, "");
99
+ }
package/docker/Dockerfile DELETED
@@ -1,21 +0,0 @@
1
- FROM mcr.microsoft.com/playwright:v1.57.0-noble
2
-
3
- # Install dependencies for Bun
4
- RUN apt-get update && apt-get install -y unzip curl && rm -rf /var/lib/apt/lists/*
5
-
6
- # Install Bun to system location directly (latest version)
7
- RUN curl -fsSL https://bun.sh/install | BUN_INSTALL=/usr/local bash
8
-
9
- # Install rtgl globally
10
- RUN bun install -g rtgl@0.0.36
11
-
12
- # Copy bun global packages to /usr/local/lib/rtgl (accessible to all users)
13
- RUN mkdir -p /usr/local/lib/rtgl && \
14
- cp -r /root/.bun/install/global /usr/local/lib/rtgl/ && \
15
- chmod -R a+rx /usr/local/lib/rtgl/
16
-
17
- # Create wrapper script that uses copied packages
18
- RUN echo "#!/bin/sh" > /usr/local/bin/rtgl && \
19
- echo "BUN_INSTALL_LOCKFILE=/usr/local/lib/rtgl/bun/install/cache/bun-install.lock" >> /usr/local/bin/rtgl && \
20
- echo "exec bun /usr/local/lib/rtgl/global/node_modules/rtgl/cli.js \"\$@\"" >> /usr/local/bin/rtgl && \
21
- chmod +x /usr/local/bin/rtgl
@@ -1,16 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
- IMAGE_NAME="playwright-v1.57.0-rtgl-v0.0.36"
6
- REGISTRY="${REGISTRY:-docker.io}"
7
- REPO="${REPO:-han4wluc/rtgl}"
8
-
9
- FULL_TAG="$REGISTRY/$REPO:$IMAGE_NAME"
10
-
11
- docker build -t "$IMAGE_NAME" "$SCRIPT_DIR"
12
- echo "Built image: $IMAGE_NAME"
13
-
14
- docker tag "$IMAGE_NAME" "$FULL_TAG"
15
- docker push "$FULL_TAG"
16
- echo "Pushed: $FULL_TAG"