dsh-web-fetch-playwright 0.1.0

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/lib/client.js ADDED
@@ -0,0 +1,854 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-web-fetch-playwright",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ //#region \0@oxc-project+runtime@0.146.0/helpers/esm/typeof.js
10
+ function _typeof(o) {
11
+ "@babel/helpers - typeof";
12
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
13
+ return typeof o;
14
+ } : function(o) {
15
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
16
+ }, _typeof(o);
17
+ }
18
+ //#endregion
19
+ //#region \0@oxc-project+runtime@0.146.0/helpers/esm/toPrimitive.js
20
+ function toPrimitive(t, r) {
21
+ if ("object" != _typeof(t) || !t) return t;
22
+ var e = t[Symbol.toPrimitive];
23
+ if (void 0 !== e) {
24
+ var i = e.call(t, r || "default");
25
+ if ("object" != _typeof(i)) return i;
26
+ throw new TypeError("@@toPrimitive must return a primitive value.");
27
+ }
28
+ return ("string" === r ? String : Number)(t);
29
+ }
30
+ //#endregion
31
+ //#region \0@oxc-project+runtime@0.146.0/helpers/esm/toPropertyKey.js
32
+ function toPropertyKey(t) {
33
+ var i = toPrimitive(t, "string");
34
+ return "symbol" == _typeof(i) ? i : i + "";
35
+ }
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.146.0/helpers/esm/defineProperty.js
38
+ function _defineProperty(e, r, t) {
39
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
40
+ value: t,
41
+ enumerable: !0,
42
+ configurable: !0,
43
+ writable: !0
44
+ }) : e[r] = t, e;
45
+ }
46
+ //#endregion
47
+ //#region src/client/form.ts
48
+ /**
49
+ * A free-text field. An empty draft clears the field, so emptying the control
50
+ * and saving is the same gesture as resetting it.
51
+ * @param field - field name inside the namespace section.
52
+ * @returns the field's conversion spec.
53
+ */
54
+ function textField(field) {
55
+ return {
56
+ field,
57
+ format: (value) => typeof value === "string" ? value : "",
58
+ parse: (text) => {
59
+ const trimmed = text.trim();
60
+ return trimmed === "" ? { kind: "clear" } : {
61
+ kind: "set",
62
+ value: trimmed
63
+ };
64
+ }
65
+ };
66
+ }
67
+ /**
68
+ * A radio-group field over a fixed option set.
69
+ * @param field - field name inside the namespace section.
70
+ * @param values - the accepted option values.
71
+ * @returns the field's conversion spec.
72
+ */
73
+ function radioField(field, values) {
74
+ const set = new Set(values);
75
+ return {
76
+ field,
77
+ format: (value) => typeof value === "string" && set.has(value) ? value : "",
78
+ parse: (text) => set.has(text) ? {
79
+ kind: "set",
80
+ value: text
81
+ } : void 0
82
+ };
83
+ }
84
+ /**
85
+ * A checkbox field. The draft carries 'true'/'false'; an absent stored value
86
+ * formats as '' so the control can fall back to the schema default.
87
+ * @param field - field name inside the namespace section.
88
+ * @returns the field's conversion spec.
89
+ */
90
+ function checkboxField(field) {
91
+ return {
92
+ field,
93
+ format: (value) => typeof value === "boolean" ? value ? "true" : "false" : "",
94
+ parse: (text) => text === "true" ? {
95
+ kind: "set",
96
+ value: true
97
+ } : text === "false" ? {
98
+ kind: "set",
99
+ value: false
100
+ } : void 0
101
+ };
102
+ }
103
+ /**
104
+ * Stages the Playwright card's edits over one settings namespace and writes
105
+ * them on save. Publishes through a snapshot store because slot components
106
+ * read through a selector while both the scope and the drafts change below.
107
+ */
108
+ var CardForm = class {
109
+ /**
110
+ * @param scope - the bound settings scope for this card's namespace.
111
+ * @param specs - the section fields this card edits.
112
+ */
113
+ constructor(scope, specs) {
114
+ this.scope = scope;
115
+ _defineProperty(this, "specs", void 0);
116
+ _defineProperty(this, "staged", /* @__PURE__ */ new Map());
117
+ _defineProperty(this, "listeners", /* @__PURE__ */ new Set());
118
+ _defineProperty(this, "saving", false);
119
+ _defineProperty(this, "failed", false);
120
+ this.specs = new Map(specs.map((spec) => [spec.field, spec]));
121
+ scope.subscribe(() => {
122
+ this.publish();
123
+ });
124
+ }
125
+ /**
126
+ * Publish a projection of this form, rebuilt whenever the scope or a draft
127
+ * changes.
128
+ * @param project - build the card's state from the form's current reads.
129
+ * @returns the store the card's component reads through its bound selector.
130
+ */
131
+ bind(project) {
132
+ let last = project();
133
+ const listeners = /* @__PURE__ */ new Set();
134
+ const store = {
135
+ getSnapshot: () => last,
136
+ subscribe: (listener) => {
137
+ listeners.add(listener);
138
+ return () => {
139
+ listeners.delete(listener);
140
+ };
141
+ },
142
+ set: (next) => {
143
+ last = next;
144
+ for (const listener of listeners) listener();
145
+ }
146
+ };
147
+ this.listeners.add(() => {
148
+ store.set(project());
149
+ });
150
+ return store;
151
+ }
152
+ /**
153
+ * Read the card-level state: what the Host serves, and what a save would do.
154
+ * @returns the form state every card shares.
155
+ */
156
+ shell() {
157
+ const snapshot = this.scope.getSnapshot();
158
+ const plan = this.plan();
159
+ return {
160
+ available: snapshot.status === "ready",
161
+ writable: snapshot.writable,
162
+ dirty: plan.length > 0,
163
+ invalid: plan.some((item) => item.run === void 0),
164
+ saving: this.saving,
165
+ failed: this.failed
166
+ };
167
+ }
168
+ /**
169
+ * Read one control's state.
170
+ * @param field - field name of a section field.
171
+ * @returns the draft string, whether a save would leave an override, and whether it is invalid.
172
+ */
173
+ field(field) {
174
+ const staged = this.staged.get(field);
175
+ const spec = this.spec(field);
176
+ if (staged === void 0) return {
177
+ text: spec.format(this.sectionValue(field)),
178
+ overridden: this.stored(field),
179
+ invalid: false
180
+ };
181
+ const write = staged.clear ? { kind: "clear" } : spec.parse(staged.text);
182
+ return {
183
+ text: staged.text,
184
+ overridden: write?.kind === "set",
185
+ invalid: write === void 0
186
+ };
187
+ }
188
+ /**
189
+ * Build the edit, reset, save, and discard actions bound to this form.
190
+ * @returns the actions the card's slot entry injects.
191
+ */
192
+ actions() {
193
+ return {
194
+ edit: (field, text) => {
195
+ this.stage(field, {
196
+ text,
197
+ clear: false
198
+ });
199
+ },
200
+ resetField: (field) => {
201
+ this.stage(field, {
202
+ text: this.spec(field).format(this.baseValue(field)),
203
+ clear: true
204
+ });
205
+ },
206
+ save: () => {
207
+ this.save();
208
+ },
209
+ discard: () => {
210
+ if (this.staged.size === 0 && !this.failed) return;
211
+ this.staged.clear();
212
+ this.failed = false;
213
+ this.publish();
214
+ }
215
+ };
216
+ }
217
+ /**
218
+ * Write every staged edit, then re-seed from what the Host accepted. A save
219
+ * that did not land keeps its drafts, so the user corrects them instead of
220
+ * retyping.
221
+ */
222
+ async save() {
223
+ const plan = this.plan();
224
+ const writes = plan.flatMap((item) => item.run === void 0 ? [] : [item.run]);
225
+ if (plan.length === 0 || this.saving || writes.length !== plan.length) return;
226
+ this.saving = true;
227
+ this.failed = false;
228
+ this.publish();
229
+ let landed = true;
230
+ for (const write of writes) landed = await write() && landed;
231
+ if (landed) this.staged.clear();
232
+ this.saving = false;
233
+ this.failed = !landed;
234
+ this.publish();
235
+ }
236
+ /**
237
+ * Every staged edit a save would write. An entry whose draft is not a value
238
+ * its field accepts carries no write: the form stays dirty and the save
239
+ * refuses rather than dropping the edit.
240
+ */
241
+ plan() {
242
+ const plan = [];
243
+ for (const [field, staged] of this.staged) {
244
+ const spec = this.spec(field);
245
+ if (staged.clear) {
246
+ if (this.stored(field)) plan.push({
247
+ field,
248
+ run: () => this.clear(field)
249
+ });
250
+ continue;
251
+ }
252
+ if (staged.text === spec.format(this.sectionValue(field))) continue;
253
+ const write = spec.parse(staged.text);
254
+ if (write === void 0) plan.push({
255
+ field,
256
+ run: void 0
257
+ });
258
+ else if (write.kind === "clear") plan.push({
259
+ field,
260
+ run: () => this.clear(field)
261
+ });
262
+ else plan.push({
263
+ field,
264
+ run: () => this.store(field, write.value)
265
+ });
266
+ }
267
+ return plan;
268
+ }
269
+ async clear(field) {
270
+ await this.scope.unset(field);
271
+ return !this.stored(field);
272
+ }
273
+ async store(field, value) {
274
+ await this.scope.set(field, value);
275
+ return this.userLayer()?.[field] === value;
276
+ }
277
+ stage(field, edit) {
278
+ this.staged.set(field, edit);
279
+ this.failed = false;
280
+ this.publish();
281
+ }
282
+ spec(field) {
283
+ const spec = this.specs.get(field);
284
+ if (spec === void 0) throw new Error(`plugin card has no field ${field}`);
285
+ return spec;
286
+ }
287
+ snapshotOf() {
288
+ return this.scope.getSnapshot();
289
+ }
290
+ sectionValue(field) {
291
+ return this.snapshotOf().value?.[field];
292
+ }
293
+ baseValue(field) {
294
+ return this.snapshotOf().base?.[field];
295
+ }
296
+ userLayer() {
297
+ return this.snapshotOf().user;
298
+ }
299
+ stored(field) {
300
+ const user = this.userLayer();
301
+ return user !== void 0 && Object.hasOwn(user, field);
302
+ }
303
+ publish() {
304
+ for (const listener of this.listeners) listener();
305
+ }
306
+ };
307
+ //#endregion
308
+ //#region src/client/controller.ts
309
+ /**
310
+ * Settings namespace this card edits. Spelled here rather than imported: a
311
+ * client package must not depend on a Host package.
312
+ */
313
+ const WEB_FETCH_PLAYWRIGHT_NS = "web-fetch-playwright";
314
+ /** Bridges the `web-fetch-playwright` settings scope onto the card. */
315
+ var PlaywrightCardController = class {
316
+ /**
317
+ * @param scope - the bound settings scope for the `web-fetch-playwright` namespace.
318
+ */
319
+ constructor(scope) {
320
+ _defineProperty(this, "form", void 0);
321
+ _defineProperty(this, "store", void 0);
322
+ this.form = new CardForm(scope, [
323
+ radioField("backend", ["local", "cdp"]),
324
+ textField("playwrightPath"),
325
+ textField("cdpEndpoint"),
326
+ checkboxField("denoise")
327
+ ]);
328
+ this.store = this.form.bind(() => this.projection());
329
+ }
330
+ projection() {
331
+ return {
332
+ ...this.form.shell(),
333
+ backend: this.form.field("backend"),
334
+ playwrightPath: this.form.field("playwrightPath"),
335
+ cdpEndpoint: this.form.field("cdpEndpoint"),
336
+ denoise: this.form.field("denoise")
337
+ };
338
+ }
339
+ /**
340
+ * Build the face the card's slot registration injects.
341
+ * @returns the card's snapshot and its form actions.
342
+ */
343
+ inject() {
344
+ return {
345
+ hooks: { playwrightCard: this.store },
346
+ ...this.form.actions()
347
+ };
348
+ }
349
+ };
350
+ //#endregion
351
+ //#region \0dsh-web-fetch-playwright-css:/opt/dsh/plugins/dsh-web-fetch-playwright/src/client/PluginCard.module.css.mjs
352
+ const css$1 = ".UM8-Rq_card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}.UM8-Rq_card:hover{border-color:var(--dsw-alias-label-dimmed)}.UM8-Rq_cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}.UM8-Rq_header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}.UM8-Rq_header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}.UM8-Rq_headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}.UM8-Rq_name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}.UM8-Rq_description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}.UM8-Rq_chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}.UM8-Rq_chevronOpen{transform:rotate(180deg)}.UM8-Rq_body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}.UM8-Rq_readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}.UM8-Rq_pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}.UM8-Rq_footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 4px;display:flex}.UM8-Rq_failed{min-width:0;color:var(--dsw-alias-label-error);flex:1;margin:0;font-size:12px;line-height:1.5}.UM8-Rq_discard,.UM8-Rq_save{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}.UM8-Rq_discard{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}.UM8-Rq_discard:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}.UM8-Rq_save{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}.UM8-Rq_discard:disabled,.UM8-Rq_save:disabled{opacity:.4;cursor:default}.UM8-Rq_discard:focus-visible,.UM8-Rq_save:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}";
353
+ const tagId$1 = "dsh-web-fetch-playwright/PluginCard.module.css";
354
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
355
+ const tag = document.createElement("style");
356
+ tag.dataset.plugin = "dsh-web-fetch-playwright";
357
+ tag.dataset.pluginCss = tagId$1;
358
+ tag.textContent = css$1;
359
+ document.head.appendChild(tag);
360
+ }
361
+ var PluginCard_module_css_default = {
362
+ "chevronOpen": "UM8-Rq_chevronOpen",
363
+ "failed": "UM8-Rq_failed",
364
+ "name": "UM8-Rq_name",
365
+ "readOnly": "UM8-Rq_readOnly",
366
+ "headText": "UM8-Rq_headText",
367
+ "discard": "UM8-Rq_discard",
368
+ "cardOpen": "UM8-Rq_cardOpen",
369
+ "footer": "UM8-Rq_footer",
370
+ "card": "UM8-Rq_card",
371
+ "header": "UM8-Rq_header",
372
+ "body": "UM8-Rq_body",
373
+ "pending": "UM8-Rq_pending",
374
+ "save": "UM8-Rq_save",
375
+ "description": "UM8-Rq_description",
376
+ "chevron": "UM8-Rq_chevron"
377
+ };
378
+ //#endregion
379
+ //#region src/client/PluginCard.tsx
380
+ /**
381
+ * The card chrome — a faithful local copy of the shipped `ui-settings-plugins`
382
+ * PluginCard (disclosure header, unsaved marker, save/discard footer), with
383
+ * the chevron inlined so the bundle stays self-contained.
384
+ *
385
+ * @module dsh-web-fetch-playwright/client/PluginCard
386
+ */
387
+ function cx(...parts) {
388
+ return parts.filter((part) => typeof part === "string").join(" ");
389
+ }
390
+ function ChevronDown({ className }) {
391
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
392
+ className,
393
+ width: "14",
394
+ height: "14",
395
+ viewBox: "0 0 16 16",
396
+ fill: "none",
397
+ "aria-hidden": "true",
398
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
399
+ d: "M4 6l4 4 4-4",
400
+ stroke: "currentColor",
401
+ strokeWidth: "1.5",
402
+ strokeLinecap: "round",
403
+ strokeLinejoin: "round"
404
+ })
405
+ });
406
+ }
407
+ /**
408
+ * Render the Playwright card's chrome.
409
+ * @param props - the card's copy, name, form state, and controls.
410
+ * @returns the card, or nothing when the namespace is unavailable.
411
+ */
412
+ function PluginCard(props) {
413
+ const [open, setOpen] = (0, react.useState)(false);
414
+ const { state, copy } = props;
415
+ if (!state.available) return null;
416
+ const blocked = !state.dirty || state.invalid || state.saving;
417
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
418
+ className: cx(PluginCard_module_css_default.card, open && PluginCard_module_css_default.cardOpen),
419
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
420
+ type: "button",
421
+ className: PluginCard_module_css_default.header,
422
+ "aria-expanded": open,
423
+ "aria-label": `${open ? copy.collapse : copy.expand}: ${props.title}`,
424
+ onClick: () => {
425
+ setOpen(!open);
426
+ },
427
+ children: [
428
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
429
+ className: PluginCard_module_css_default.headText,
430
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
431
+ className: PluginCard_module_css_default.name,
432
+ children: props.title
433
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
434
+ className: PluginCard_module_css_default.description,
435
+ children: props.description
436
+ })]
437
+ }),
438
+ state.dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
439
+ className: PluginCard_module_css_default.pending,
440
+ children: copy.unsaved
441
+ }) : null,
442
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronDown, { className: cx(PluginCard_module_css_default.chevron, open && PluginCard_module_css_default.chevronOpen) })
443
+ ]
444
+ }), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
445
+ className: PluginCard_module_css_default.body,
446
+ children: [
447
+ !state.writable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
448
+ className: PluginCard_module_css_default.readOnly,
449
+ role: "status",
450
+ children: copy.readOnly
451
+ }) : null,
452
+ props.children,
453
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
454
+ className: PluginCard_module_css_default.footer,
455
+ children: [
456
+ state.failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
457
+ className: PluginCard_module_css_default.failed,
458
+ role: "status",
459
+ children: copy.saveFailed
460
+ }) : null,
461
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
462
+ type: "button",
463
+ className: PluginCard_module_css_default.discard,
464
+ disabled: !state.dirty || state.saving,
465
+ onClick: props.onDiscard,
466
+ children: copy.discard
467
+ }),
468
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
469
+ type: "button",
470
+ className: PluginCard_module_css_default.save,
471
+ disabled: blocked,
472
+ onClick: props.onSave,
473
+ children: state.saving ? copy.saving : copy.save
474
+ })
475
+ ]
476
+ })
477
+ ]
478
+ }) : null]
479
+ });
480
+ }
481
+ //#endregion
482
+ //#region \0dsh-web-fetch-playwright-css:/opt/dsh/plugins/dsh-web-fetch-playwright/src/client/fields.module.css.mjs
483
+ const css = ".CFSaVG_field{border:0;border-top:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:6px;margin:0;padding:12px 0;display:flex}.CFSaVG_field:first-child{border-top:0}.CFSaVG_fieldEmbedded{border:0;flex-direction:column;gap:6px;margin:0;padding:0;display:flex}.CFSaVG_head{align-items:center;gap:8px;display:flex}.CFSaVG_label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}.CFSaVG_badges{align-items:center;gap:8px;display:inline-flex}.CFSaVG_badge{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}.CFSaVG_reset{font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;padding:0;font-size:12px;line-height:1.5}.CFSaVG_reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}.CFSaVG_reset:disabled{cursor:default}.CFSaVG_input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}.CFSaVG_input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}.CFSaVG_input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}.CFSaVG_inputInvalid{border:1px solid var(--dsw-alias-label-error);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}.CFSaVG_invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}.CFSaVG_hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}.CFSaVG_radioGroup{flex-direction:column;gap:8px;display:flex}.CFSaVG_radioOption{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:8px;flex-direction:column;gap:8px;padding:10px 12px;display:flex}.CFSaVG_radioOption:has(input[type=radio]:checked){border-color:var(--dsw-alias-brand-primary)}.CFSaVG_radioPick{cursor:pointer;align-items:flex-start;gap:10px;display:flex}.CFSaVG_radioPick input[type=radio]{width:14px;height:14px;accent-color:var(--dsw-alias-brand-primary);flex:none;margin-top:2px}.CFSaVG_radioPick input[type=radio]:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}.CFSaVG_radioText{flex-direction:column;gap:2px;min-width:0;display:flex}.CFSaVG_radioLabel{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:1.5}.CFSaVG_radioHint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1.5}.CFSaVG_radioContent{margin-left:24px}.CFSaVG_radioContent input[type=text]:enabled{cursor:text}.CFSaVG_checkboxRow{align-items:center;gap:10px;display:flex}.CFSaVG_checkboxRow input[type=checkbox]{width:16px;height:16px;accent-color:var(--dsw-alias-brand-primary);flex:none;margin:0}.CFSaVG_checkboxRow input[type=checkbox]:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}";
484
+ const tagId = "dsh-web-fetch-playwright/fields.module.css";
485
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
486
+ const tag = document.createElement("style");
487
+ tag.dataset.plugin = "dsh-web-fetch-playwright";
488
+ tag.dataset.pluginCss = tagId;
489
+ tag.textContent = css;
490
+ document.head.appendChild(tag);
491
+ }
492
+ var fields_module_css_default = {
493
+ "invalid": "CFSaVG_invalid",
494
+ "badge": "CFSaVG_badge",
495
+ "reset": "CFSaVG_reset",
496
+ "input": "CFSaVG_input",
497
+ "radioHint": "CFSaVG_radioHint",
498
+ "checkboxRow": "CFSaVG_checkboxRow",
499
+ "field": "CFSaVG_field",
500
+ "badges": "CFSaVG_badges",
501
+ "radioOption": "CFSaVG_radioOption",
502
+ "head": "CFSaVG_head",
503
+ "radioGroup": "CFSaVG_radioGroup",
504
+ "radioPick": "CFSaVG_radioPick",
505
+ "hint": "CFSaVG_hint",
506
+ "radioContent": "CFSaVG_radioContent",
507
+ "fieldEmbedded": "CFSaVG_fieldEmbedded",
508
+ "inputInvalid": "CFSaVG_inputInvalid",
509
+ "radioLabel": "CFSaVG_radioLabel",
510
+ "label": "CFSaVG_label",
511
+ "radioText": "CFSaVG_radioText"
512
+ };
513
+ //#endregion
514
+ //#region src/client/fields.tsx
515
+ /** A staged text field (copy of the shipped ValueField). */
516
+ function ValueField(props) {
517
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
518
+ className: props.embedded ? fields_module_css_default.fieldEmbedded : fields_module_css_default.field,
519
+ children: [
520
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
521
+ className: fields_module_css_default.head,
522
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
523
+ className: fields_module_css_default.label,
524
+ htmlFor: props.id,
525
+ children: props.label
526
+ }), props.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
527
+ className: fields_module_css_default.badges,
528
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
529
+ className: fields_module_css_default.badge,
530
+ children: props.overriddenLabel
531
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
532
+ type: "button",
533
+ className: fields_module_css_default.reset,
534
+ disabled: props.disabled,
535
+ onClick: props.onReset,
536
+ children: props.resetLabel
537
+ })]
538
+ }) : null]
539
+ }),
540
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
541
+ id: props.id,
542
+ className: props.invalid ? fields_module_css_default.inputInvalid : fields_module_css_default.input,
543
+ type: "text",
544
+ ...props.invalid ? { "aria-invalid": true } : {},
545
+ value: props.text,
546
+ placeholder: props.placeholder ?? "",
547
+ disabled: props.disabled,
548
+ spellCheck: false,
549
+ onChange: (event) => {
550
+ props.onEdit(event.target.value);
551
+ }
552
+ }),
553
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
554
+ className: props.invalid ? fields_module_css_default.invalid : fields_module_css_default.hint,
555
+ children: props.invalid ? props.invalidLabel : props.hint
556
+ })
557
+ ]
558
+ });
559
+ }
560
+ /** A staged radio group: the backend selector. */
561
+ function RadioGroupField(props) {
562
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
563
+ className: fields_module_css_default.field,
564
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
565
+ className: fields_module_css_default.head,
566
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
567
+ className: fields_module_css_default.label,
568
+ children: props.label
569
+ }), props.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
570
+ className: fields_module_css_default.badges,
571
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
572
+ className: fields_module_css_default.badge,
573
+ children: props.overriddenLabel
574
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
575
+ type: "button",
576
+ className: fields_module_css_default.reset,
577
+ disabled: props.disabled,
578
+ onClick: props.onReset,
579
+ children: props.resetLabel
580
+ })]
581
+ }) : null]
582
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
583
+ className: fields_module_css_default.radioGroup,
584
+ role: "radiogroup",
585
+ "aria-label": props.label,
586
+ children: props.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
587
+ className: fields_module_css_default.radioOption,
588
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
589
+ className: fields_module_css_default.radioPick,
590
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
591
+ type: "radio",
592
+ name: "playwright-backend",
593
+ value: option.value,
594
+ checked: props.text === option.value,
595
+ disabled: props.disabled,
596
+ onChange: () => {
597
+ props.onEdit(option.value);
598
+ }
599
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
600
+ className: fields_module_css_default.radioText,
601
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
602
+ className: fields_module_css_default.radioLabel,
603
+ children: option.label
604
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
605
+ className: fields_module_css_default.radioHint,
606
+ children: option.hint
607
+ })]
608
+ })]
609
+ }), option.content === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
610
+ className: fields_module_css_default.radioContent,
611
+ children: option.content
612
+ })]
613
+ }, option.value))
614
+ })]
615
+ });
616
+ }
617
+ /** A staged checkbox: the denoise toggle. An absent stored value defaults to on. */
618
+ function CheckboxField(props) {
619
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
620
+ className: fields_module_css_default.field,
621
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
622
+ className: fields_module_css_default.checkboxRow,
623
+ children: [
624
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
625
+ id: props.id,
626
+ type: "checkbox",
627
+ checked: props.checked,
628
+ disabled: props.disabled,
629
+ onChange: (event) => {
630
+ props.onEdit(event.target.checked ? "true" : "false");
631
+ }
632
+ }),
633
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
634
+ className: fields_module_css_default.label,
635
+ htmlFor: props.id,
636
+ children: props.label
637
+ }),
638
+ props.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
639
+ className: fields_module_css_default.badges,
640
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
641
+ className: fields_module_css_default.badge,
642
+ children: props.overriddenLabel
643
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
644
+ type: "button",
645
+ className: fields_module_css_default.reset,
646
+ disabled: props.disabled,
647
+ onClick: props.onReset,
648
+ children: props.resetLabel
649
+ })]
650
+ }) : null
651
+ ]
652
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
653
+ className: fields_module_css_default.hint,
654
+ children: props.hint
655
+ })]
656
+ });
657
+ }
658
+ //#endregion
659
+ //#region src/client/card.tsx
660
+ /**
661
+ * Render the Playwright card.
662
+ * @param props - locale copy, the card snapshot, and its form actions.
663
+ * @returns the card.
664
+ */
665
+ function PlaywrightCard(props) {
666
+ const { t } = props;
667
+ const state = props.usePlaywrightCard((snapshot) => snapshot);
668
+ const disabled = !state.writable;
669
+ const backend = state.backend.text === "cdp" ? "cdp" : "local";
670
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(PluginCard, {
671
+ copy: {
672
+ expand: t("expand"),
673
+ collapse: t("collapse"),
674
+ unsaved: t("unsaved"),
675
+ readOnly: t("readOnly"),
676
+ saveFailed: t("saveFailed"),
677
+ discard: t("discard"),
678
+ save: t("save"),
679
+ saving: t("saving")
680
+ },
681
+ title: t("title"),
682
+ description: t("description"),
683
+ state,
684
+ onSave: props.save,
685
+ onDiscard: props.discard,
686
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RadioGroupField, {
687
+ label: t("backendLabel"),
688
+ options: [{
689
+ value: "local",
690
+ label: t("backendLocal"),
691
+ hint: t("backendLocalHint"),
692
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ValueField, {
693
+ embedded: true,
694
+ id: "plugin-config-playwright-path",
695
+ label: t("playwrightPath"),
696
+ hint: t("playwrightPathHint"),
697
+ placeholder: t("playwrightPathPlaceholder"),
698
+ overriddenLabel: t("overridden"),
699
+ resetLabel: t("reset"),
700
+ invalidLabel: t("invalidText"),
701
+ disabled: disabled || backend !== "local",
702
+ ...state.playwrightPath,
703
+ onEdit: (text) => {
704
+ props.edit("playwrightPath", text);
705
+ },
706
+ onReset: () => {
707
+ props.resetField("playwrightPath");
708
+ }
709
+ })
710
+ }, {
711
+ value: "cdp",
712
+ label: t("backendCdp"),
713
+ hint: t("backendCdpHint"),
714
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ValueField, {
715
+ embedded: true,
716
+ id: "plugin-config-playwright-cdp",
717
+ label: t("cdpEndpoint"),
718
+ hint: t("cdpEndpointHint"),
719
+ placeholder: "127.0.0.1:9222",
720
+ overriddenLabel: t("overridden"),
721
+ resetLabel: t("reset"),
722
+ invalidLabel: t("invalidText"),
723
+ disabled: disabled || backend !== "cdp",
724
+ ...state.cdpEndpoint,
725
+ onEdit: (text) => {
726
+ props.edit("cdpEndpoint", text);
727
+ },
728
+ onReset: () => {
729
+ props.resetField("cdpEndpoint");
730
+ }
731
+ })
732
+ }],
733
+ text: state.backend.text,
734
+ overridden: state.backend.overridden,
735
+ overriddenLabel: t("overridden"),
736
+ resetLabel: t("reset"),
737
+ disabled,
738
+ onEdit: (text) => {
739
+ props.edit("backend", text);
740
+ },
741
+ onReset: () => {
742
+ props.resetField("backend");
743
+ }
744
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckboxField, {
745
+ id: "plugin-config-playwright-denoise",
746
+ label: t("denoise"),
747
+ hint: t("denoiseHint"),
748
+ checked: state.denoise.text !== "false",
749
+ overridden: state.denoise.overridden,
750
+ overriddenLabel: t("overridden"),
751
+ resetLabel: t("reset"),
752
+ disabled,
753
+ onEdit: (text) => {
754
+ props.edit("denoise", text);
755
+ },
756
+ onReset: () => {
757
+ props.resetField("denoise");
758
+ }
759
+ })]
760
+ });
761
+ }
762
+ //#endregion
763
+ //#region src/client/locales.ts
764
+ /** English copy. */
765
+ const en = {
766
+ title: "Playwright web fetch",
767
+ description: "Fetches pages with a real browser (local Playwright or CDP) and returns denoised markdown.",
768
+ backendLabel: "Playwright backend",
769
+ backendLocal: "Local Playwright",
770
+ backendLocalHint: "Launch a browser through the local playwright installation.",
771
+ backendCdp: "Remote CDP endpoint",
772
+ backendCdpHint: "Drive an already-running browser over its DevTools Protocol port.",
773
+ playwrightPath: "Playwright executable path",
774
+ playwrightPathHint: "Leave blank to find playwright on $PATH; a browser executable path also works.",
775
+ playwrightPathPlaceholder: "(auto: playwright from $PATH)",
776
+ cdpEndpoint: "CDP endpoint",
777
+ cdpEndpointHint: "host:port or http(s)/ws URL. Leave blank for 127.0.0.1:9222.",
778
+ denoise: "Enable the denoise algorithm",
779
+ denoiseHint: "Readability + DOMPurify strip nav bars, sidebars, footers, and ads before converting to markdown.",
780
+ overridden: "Overridden",
781
+ reset: "Reset to default",
782
+ readOnly: "This deployment stores settings read-only.",
783
+ expand: "Show settings",
784
+ collapse: "Hide settings",
785
+ save: "Save",
786
+ saving: "Saving…",
787
+ discard: "Discard",
788
+ unsaved: "Unsaved",
789
+ saveFailed: "The deployment did not accept these values; they were left for you to correct.",
790
+ invalidText: "This value is not accepted here."
791
+ };
792
+ /** Simplified Chinese copy. */
793
+ const zh = {
794
+ title: "Playwright 网页爬取",
795
+ description: "用真实浏览器(本地 Playwright 或 CDP)抓取网页,降噪后转为 Markdown。",
796
+ backendLabel: "Playwright 后端",
797
+ backendLocal: "本地 Playwright",
798
+ backendLocalHint: "通过本机的 playwright 安装启动浏览器。",
799
+ backendCdp: "远端 CDP 地址",
800
+ backendCdpHint: "连接一个已在运行的浏览器的 DevTools 协议端口。",
801
+ playwrightPath: "Playwright 可执行文件路径",
802
+ playwrightPathHint: "留空则按系统 $PATH 查找 playwright;也支持填浏览器可执行文件路径。",
803
+ playwrightPathPlaceholder: "(自动:按 $PATH 查找 playwright)",
804
+ cdpEndpoint: "CDP 地址",
805
+ cdpEndpointHint: "host:port 或 http(s)/ws 地址;留空默认 127.0.0.1:9222。",
806
+ denoise: "启用降噪算法",
807
+ denoiseHint: "使用 Readability + DOMPurify 清洗导航栏、侧边栏、页脚与贴片广告后再转为 Markdown。",
808
+ overridden: "已覆盖",
809
+ reset: "恢复默认",
810
+ readOnly: "本部署的设置为只读。",
811
+ expand: "展开设置",
812
+ collapse: "收起设置",
813
+ save: "保存",
814
+ saving: "保存中…",
815
+ discard: "放弃修改",
816
+ unsaved: "未保存",
817
+ saveFailed: "本部署没有接受这些值,已保留供你修改。",
818
+ invalidText: "该值不被此设置项接受。"
819
+ };
820
+ //#endregion
821
+ //#region src/client/index.ts
822
+ /** Dictionary namespace owned by this plugin. */
823
+ const NS = "web-fetch-playwright";
824
+ /** Required services (cordis fiber inject). */
825
+ const inject = [
826
+ "slots",
827
+ "locale",
828
+ "settingsScope"
829
+ ];
830
+ /**
831
+ * Mount the Playwright plugin-configuration card.
832
+ * @param ctx - the browser plugin context.
833
+ */
834
+ function apply(ctx) {
835
+ ctx.effect(() => ctx.locale.register(NS, {
836
+ zh,
837
+ en
838
+ }), "web-fetch-playwright: card dictionary");
839
+ const controller = new PlaywrightCardController(ctx.settingsScope.bind({ namespace: WEB_FETCH_PLAYWRIGHT_NS }));
840
+ ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
841
+ name: "settings.plugin.item",
842
+ key: WEB_FETCH_PLAYWRIGHT_NS,
843
+ locale: NS,
844
+ inject: () => controller.inject()
845
+ }, PlaywrightCard));
846
+ }
847
+ //#endregion
848
+ exports.apply = apply;
849
+ exports.inject = inject;
850
+ return module.exports;
851
+ }
852
+ });
853
+
854
+ //# sourceMappingURL=client.js.map