@gnawbit/tabretake 0.4.2 → 0.5.1

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.
@@ -1,74 +1,148 @@
1
- import { parseArgs } from "node:util";
2
-
3
- export const commandOptions = {
4
- setup: { "with-deps": { type: "boolean", default: false } },
5
- init: {
6
- json: { type: "boolean", default: false },
7
- url: { type: "string" },
8
- out: { type: "string", default: "demo.json" },
9
- auto: { type: "boolean", default: false },
10
- browser: { type: "string", default: "auto" },
11
- preset: { type: "string" },
12
- },
13
- plan: {
14
- json: { type: "boolean", default: false },
15
- url: { type: "string" },
16
- out: { type: "string", default: "plan.json" },
17
- login: { type: "boolean", default: false },
18
- "storage-state": { type: "string" },
19
- proxy: { type: "string" },
20
- viewport: { type: "string" },
21
- headless: { type: "boolean", default: true },
22
- browser: { type: "string", default: "auto" },
23
- },
24
- record: {
25
- json: { type: "boolean", default: false },
26
- config: { type: "string" },
27
- url: { type: "string" },
28
- out: { type: "string" },
29
- login: { type: "boolean", default: false },
30
- "storage-state": { type: "string" },
31
- "save-state": { type: "string" },
32
- proxy: { type: "string" },
33
- viewport: { type: "string" },
34
- headed: { type: "boolean", default: false },
35
- browser: { type: "string", default: "auto" },
36
- },
37
- render: {
38
- json: { type: "boolean", default: false },
39
- config: { type: "string" },
40
- video: { type: "string" },
41
- out: { type: "string" },
42
- "no-gif": { type: "boolean", default: false },
43
- "no-captions": { type: "boolean", default: false },
44
- vertical: { type: "boolean", default: false },
45
- zoom: { type: "string", default: "1.28" },
46
- "vertical-zoom": { type: "string" },
47
- "zoom-duration": { type: "string" },
48
- "poster-at": { type: "string" },
49
- preset: { type: "string" },
50
- },
51
- serve: {
52
- port: { type: "string", default: "4173" },
53
- dir: { type: "string", default: "examples/site" },
54
- },
55
- demo: {
56
- out: { type: "string", default: "demo" },
57
- port: { type: "string", default: "4173" },
58
- story: { type: "string", default: "onboarding" },
59
- browser: { type: "string", default: "auto" },
60
- preset: { type: "string" },
61
- },
62
- doctor: { json: { type: "boolean", default: false } },
63
- capabilities: { json: { type: "boolean", default: false } },
64
- validate: { config: { type: "string" }, json: { type: "boolean", default: false } },
65
- };
66
-
67
- commandOptions.preview = {
68
- ...commandOptions.record,
69
- headless: { type: "boolean", default: false },
70
- };
71
-
72
- export function parseCommand(command, argv) {
73
- return parseArgs({ args: argv, options: commandOptions[command], strict: true, allowPositionals: false });
74
- }
1
+ import { parseArgs } from "node:util";
2
+ import { commandError } from "./report.mjs";
3
+
4
+ const authOptions = {
5
+ login: { type: "boolean", default: false },
6
+ "storage-state": { type: "string" },
7
+ "save-state": { type: "string" },
8
+ };
9
+
10
+ const browserOptions = {
11
+ proxy: { type: "string" },
12
+ viewport: { type: "string" },
13
+ browser: { type: "string", default: "auto" },
14
+ };
15
+
16
+ const renderStyleOptions = {
17
+ "no-gif": { type: "boolean", default: false },
18
+ "no-captions": { type: "boolean", default: false },
19
+ vertical: { type: "boolean", default: false },
20
+ zoom: { type: "string", default: "1.28" },
21
+ "vertical-zoom": { type: "string" },
22
+ "zoom-duration": { type: "string" },
23
+ "poster-at": { type: "string" },
24
+ preset: { type: "string" },
25
+ };
26
+
27
+ const recordOptions = {
28
+ json: { type: "boolean", default: false },
29
+ config: { type: "string" },
30
+ url: { type: "string" },
31
+ out: { type: "string" },
32
+ ...authOptions,
33
+ ...browserOptions,
34
+ headed: { type: "boolean", default: false },
35
+ scale: { type: "string" },
36
+ };
37
+
38
+ export const commandOptions = {
39
+ setup: { "with-deps": { type: "boolean", default: false } },
40
+ init: {
41
+ json: { type: "boolean", default: false },
42
+ url: { type: "string" },
43
+ out: { type: "string", default: "demo.json" },
44
+ auto: { type: "boolean", default: false },
45
+ browser: { type: "string", default: "auto" },
46
+ preset: { type: "string" },
47
+ },
48
+ plan: {
49
+ json: { type: "boolean", default: false },
50
+ url: { type: "string" },
51
+ out: { type: "string", default: "plan.json" },
52
+ login: { type: "boolean", default: false },
53
+ "storage-state": { type: "string" },
54
+ ...browserOptions,
55
+ headless: { type: "boolean", default: true },
56
+ },
57
+ record: recordOptions,
58
+ run: {
59
+ ...recordOptions,
60
+ ...renderStyleOptions,
61
+ },
62
+ capture: {
63
+ json: { type: "boolean", default: false },
64
+ url: { type: "string" },
65
+ out: { type: "string", default: "demo.json" },
66
+ ...authOptions,
67
+ ...browserOptions,
68
+ scale: { type: "string" },
69
+ force: { type: "boolean", default: false },
70
+ run: { type: "boolean", default: false },
71
+ "media-out": { type: "string" },
72
+ ...renderStyleOptions,
73
+ },
74
+ mark: {
75
+ json: { type: "boolean", default: false },
76
+ video: { type: "string" },
77
+ out: { type: "string", default: "story-video.json" },
78
+ preset: { type: "string" },
79
+ port: { type: "string", default: "0" },
80
+ "media-out": { type: "string" },
81
+ "no-open": { type: "boolean", default: false },
82
+ },
83
+ render: {
84
+ json: { type: "boolean", default: false },
85
+ config: { type: "string" },
86
+ video: { type: "string" },
87
+ out: { type: "string" },
88
+ ...renderStyleOptions,
89
+ },
90
+ serve: {
91
+ port: { type: "string", default: "4173" },
92
+ dir: { type: "string", default: "examples/site" },
93
+ },
94
+ demo: {
95
+ out: { type: "string", default: "demo" },
96
+ port: { type: "string", default: "4173" },
97
+ story: { type: "string", default: "onboarding" },
98
+ browser: { type: "string", default: "auto" },
99
+ preset: { type: "string" },
100
+ },
101
+ doctor: { json: { type: "boolean", default: false } },
102
+ capabilities: { json: { type: "boolean", default: false } },
103
+ validate: { config: { type: "string" }, json: { type: "boolean", default: false } },
104
+ };
105
+
106
+ commandOptions.preview = {
107
+ ...commandOptions.record,
108
+ headless: { type: "boolean", default: false },
109
+ };
110
+
111
+ export function parseCommand(command, argv) {
112
+ return parseArgs({ args: argv, options: commandOptions[command], strict: true, allowPositionals: false });
113
+ }
114
+
115
+ export function parseViewport(value, fallback = { width: 1440, height: 810 }) {
116
+ if (value === undefined) return fallback;
117
+ if (!/^[1-9]\d*x[1-9]\d*$/.test(value)) {
118
+ throw new Error("--viewport must be WIDTHxHEIGHT with positive integers");
119
+ }
120
+ const [width, height] = value.split("x").map(Number);
121
+ return { width, height };
122
+ }
123
+
124
+ export function parseHttpUrl(raw, missingMessage = "Provide --url https://your-app.com") {
125
+ if (!raw) throw new Error(missingMessage);
126
+ let url;
127
+ try {
128
+ url = new URL(raw);
129
+ } catch {
130
+ throw new Error("Use a complete http:// or https:// URL");
131
+ }
132
+ if (!["http:", "https:"].includes(url.protocol)) {
133
+ throw new Error("Use a complete http:// or https:// URL");
134
+ }
135
+ return url;
136
+ }
137
+
138
+ export function parseScale(cliValue, fallback = 1) {
139
+ const scale = cliValue === undefined
140
+ ? fallback
141
+ : (String(cliValue).trim() === "" ? NaN : Number(cliValue));
142
+ if (scale !== 1 && scale !== 2) {
143
+ throw commandError("INVALID_CONFIG", "scale / --scale must be 1 or 2", {
144
+ hint: "Choose 1 (standard) or 2 (HiDPI Retina).",
145
+ });
146
+ }
147
+ return scale;
148
+ }
@@ -17,6 +17,7 @@ export function requireInteractiveLogin(values) {
17
17
  export function createReporter(command, json) {
18
18
  return {
19
19
  log: (...args) => (json ? console.error : console.log)(...args),
20
+ warn: (...args) => console.error(...args),
20
21
  async success({ artifacts, ...details }) {
21
22
  if (!json) return;
22
23
  const files = await Promise.all(artifacts.map(async (artifact) => {
@@ -111,6 +111,17 @@ export const BRAND_PRESETS = {
111
111
 
112
112
  export const PRESET_NAMES = Object.keys(BRAND_PRESETS);
113
113
 
114
+ export function hexToRgb(hex, fallback = "#070a12") {
115
+ const parse = (value) => {
116
+ const clean = String(value || "").replace("#", "");
117
+ const full = clean.length === 3 ? clean.split("").map((c) => c + c).join("") : clean;
118
+ if (!/^[0-9a-fA-F]{6}$/.test(full)) return null;
119
+ const n = Number.parseInt(full, 16);
120
+ return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
121
+ };
122
+ return parse(hex) || parse(fallback) || { r: 7, g: 10, b: 18 };
123
+ }
124
+
114
125
  export function resolveTheme(brand = {}, overridePreset) {
115
126
  const presetName = overridePreset || brand?.preset || "midnight";
116
127
  const base = BRAND_PRESETS[presetName];