@browserbasehq/sdk 1.4.1 → 1.4.3-next.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/dist/index.d.ts +114 -0
- package/dist/index.js +3 -1
- package/dist/integrations/ai-sdk.d.ts +18 -0
- package/dist/integrations/ai-sdk.js +19 -0
- package/dist/recorder/call-metadata.d.ts +66 -0
- package/dist/recorder/call-metadata.js +2 -0
- package/dist/recorder/crypto.d.ts +1 -0
- package/dist/recorder/crypto.js +10 -0
- package/dist/recorder/css-utils.d.ts +2 -0
- package/dist/recorder/css-utils.js +34 -0
- package/dist/recorder/generator.d.ts +31 -0
- package/dist/recorder/generator.js +154 -0
- package/dist/recorder/javascript-generator.d.ts +29 -0
- package/dist/recorder/javascript-generator.js +256 -0
- package/dist/recorder/language.d.ts +127 -0
- package/dist/recorder/language.js +21 -0
- package/dist/recorder/recorder-types.d.ts +108 -0
- package/dist/recorder/recorder-types.js +2 -0
- package/dist/recorder/recorder.d.ts +35 -0
- package/dist/recorder/recorder.js +333 -0
- package/dist/recorder/time.d.ts +1 -0
- package/dist/recorder/time.js +42 -0
- package/dist/recorder/timeout-runner.d.ts +6 -0
- package/dist/recorder/timeout-runner.js +19 -0
- package/dist/recorder/utils/isomorphic/css-parser.d.ts +41 -0
- package/dist/recorder/utils/isomorphic/css-parser.js +291 -0
- package/dist/recorder/utils/isomorphic/css-tokenizer.d.ts +171 -0
- package/dist/recorder/utils/isomorphic/css-tokenizer.js +986 -0
- package/dist/recorder/utils/isomorphic/locator-generators.d.ts +79 -0
- package/dist/recorder/utils/isomorphic/locator-generators.js +666 -0
- package/dist/recorder/utils/isomorphic/locator-parser.d.ts +17 -0
- package/dist/recorder/utils/isomorphic/locator-parser.js +244 -0
- package/dist/recorder/utils/isomorphic/locator-utils.d.ts +43 -0
- package/dist/recorder/utils/isomorphic/locator-utils.js +69 -0
- package/dist/recorder/utils/isomorphic/selector-parser.d.ts +48 -0
- package/dist/recorder/utils/isomorphic/selector-parser.js +483 -0
- package/dist/recorder/utils/isomorphic/string-utils.d.ts +28 -0
- package/dist/recorder/utils/isomorphic/string-utils.js +123 -0
- package/dist/recorder/utils.d.ts +20 -0
- package/dist/recorder/utils.js +32 -0
- package/package.json +7 -3
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserbaseCodeGenerator = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const generator_1 = require("./generator");
|
|
6
|
+
const time_1 = require("./time");
|
|
7
|
+
const timeout_runner_1 = require("./timeout-runner");
|
|
8
|
+
const css_utils_1 = require("./css-utils");
|
|
9
|
+
const crypto_1 = require("./crypto");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const javascript_generator_1 = require("./javascript-generator");
|
|
12
|
+
class BrowserbaseCodeGenerator extends events_1.EventEmitter {
|
|
13
|
+
_context;
|
|
14
|
+
// This is used in the playground to bypass the verification step since it doesnt work
|
|
15
|
+
// in the browser
|
|
16
|
+
_skipVerify = false;
|
|
17
|
+
_enabled;
|
|
18
|
+
_generator;
|
|
19
|
+
_pageAliases = new Map();
|
|
20
|
+
_lastPopupOrdinal = 0;
|
|
21
|
+
_lastDialogOrdinal = -1;
|
|
22
|
+
_lastDownloadOrdinal = -1;
|
|
23
|
+
_timers = new Set();
|
|
24
|
+
_javascriptGenerator;
|
|
25
|
+
constructor(context, options) {
|
|
26
|
+
super();
|
|
27
|
+
this._context = context;
|
|
28
|
+
this._enabled = options?.enabled ?? false;
|
|
29
|
+
this._generator = new generator_1.CodeGenerator('chromium', this._enabled, {}, {}, undefined, undefined);
|
|
30
|
+
this._javascriptGenerator = new javascript_generator_1.JavaScriptLanguageGenerator(false);
|
|
31
|
+
this._generator.on('change', () => {
|
|
32
|
+
const { header, footer, actions, text } = this._generator.generateStructure(this._javascriptGenerator);
|
|
33
|
+
this.emit('action', { actions });
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
static async init(context, options) {
|
|
37
|
+
const browserbaseCodeGenerator = new BrowserbaseCodeGenerator(context, options);
|
|
38
|
+
await browserbaseCodeGenerator.install();
|
|
39
|
+
return browserbaseCodeGenerator;
|
|
40
|
+
}
|
|
41
|
+
setEnabled(enabled) {
|
|
42
|
+
this._enabled = enabled;
|
|
43
|
+
this._generator.setEnabled(enabled);
|
|
44
|
+
}
|
|
45
|
+
async install() {
|
|
46
|
+
if (!this._skipVerify) {
|
|
47
|
+
const codegenMode = await this._ensureCodegenEnabled();
|
|
48
|
+
if (!codegenMode) {
|
|
49
|
+
throw new Error('Failed to install generator: codegenMode not enabled on this session');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this._context.on('page', (page) => {
|
|
53
|
+
this._onPage(page);
|
|
54
|
+
});
|
|
55
|
+
for (const page of this._context.pages()) {
|
|
56
|
+
this._onPage(page);
|
|
57
|
+
}
|
|
58
|
+
this._context.on('dialog', (dialog) => {
|
|
59
|
+
this._onDialog(dialog.page());
|
|
60
|
+
});
|
|
61
|
+
await this._context.exposeBinding('__bb_recorderPerformAction', (source, action) => this._performAction(source.frame, action));
|
|
62
|
+
await this._context.exposeBinding('__bb_recorderRecordAction', (source, action) => this._recordAction(source.frame, action));
|
|
63
|
+
await this._context.exposeBinding('__bb_recorderEnabled', (_source) => true);
|
|
64
|
+
}
|
|
65
|
+
_onDialog(page) {
|
|
66
|
+
const pageAlias = this._pageAliases.get(page);
|
|
67
|
+
++this._lastDialogOrdinal;
|
|
68
|
+
this._generator.signal(pageAlias, page.mainFrame(), {
|
|
69
|
+
name: 'dialog',
|
|
70
|
+
dialogAlias: this._lastDialogOrdinal
|
|
71
|
+
? String(this._lastDialogOrdinal)
|
|
72
|
+
: '',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// when a browser is created with record mode it will add a global variable to the page
|
|
76
|
+
// this function checks if the global variable is present and returns true if it is
|
|
77
|
+
async _ensureCodegenEnabled() {
|
|
78
|
+
const enabledState = this._enabled;
|
|
79
|
+
// disable generator so we dont capture these actions
|
|
80
|
+
if (enabledState) {
|
|
81
|
+
this.setEnabled(false);
|
|
82
|
+
}
|
|
83
|
+
const page = await this._context.newPage();
|
|
84
|
+
await page.waitForLoadState('domcontentloaded');
|
|
85
|
+
const codegenMode = await page.evaluate(() => {
|
|
86
|
+
// @ts-expect-error
|
|
87
|
+
if (window.__bb_codegenEnabled) {
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
return window.__bb_codegenEnabled();
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
});
|
|
93
|
+
await page.close();
|
|
94
|
+
// re-enable generator
|
|
95
|
+
if (enabledState) {
|
|
96
|
+
this.setEnabled(true);
|
|
97
|
+
}
|
|
98
|
+
return codegenMode;
|
|
99
|
+
}
|
|
100
|
+
async _onPage(page) {
|
|
101
|
+
const frame = page.mainFrame();
|
|
102
|
+
page.on('close', () => {
|
|
103
|
+
this._generator.addAction({
|
|
104
|
+
frame: this._describeMainFrame(page),
|
|
105
|
+
committed: true,
|
|
106
|
+
action: {
|
|
107
|
+
name: 'closePage',
|
|
108
|
+
signals: [],
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
this._pageAliases.delete(page);
|
|
112
|
+
});
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
frame._eventEmitter.on('navigated', (event) => {
|
|
115
|
+
this._onFrameNavigated(frame, page);
|
|
116
|
+
});
|
|
117
|
+
page.on('download', () => this._onDownload(page));
|
|
118
|
+
const suffix = this._pageAliases.size
|
|
119
|
+
? String(++this._lastPopupOrdinal)
|
|
120
|
+
: '';
|
|
121
|
+
const pageAlias = 'page' + suffix;
|
|
122
|
+
this._pageAliases.set(page, pageAlias);
|
|
123
|
+
const opener = await page.opener();
|
|
124
|
+
if (opener) {
|
|
125
|
+
this._onPopup(opener, page);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this._generator.addAction({
|
|
129
|
+
frame: this._describeMainFrame(page),
|
|
130
|
+
committed: true,
|
|
131
|
+
action: {
|
|
132
|
+
name: 'openPage',
|
|
133
|
+
url: page.mainFrame().url(),
|
|
134
|
+
signals: [],
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
_describeMainFrame(page) {
|
|
140
|
+
return {
|
|
141
|
+
pageAlias: this._pageAliases.get(page),
|
|
142
|
+
isMainFrame: true,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async _describeFrame(frame) {
|
|
146
|
+
// @ts-expect-error
|
|
147
|
+
const page = frame._page;
|
|
148
|
+
const pageAlias = this._pageAliases.get(page);
|
|
149
|
+
const chain = [];
|
|
150
|
+
for (let ancestor = frame; ancestor; ancestor = ancestor.parentFrame())
|
|
151
|
+
chain.push(ancestor);
|
|
152
|
+
chain.reverse();
|
|
153
|
+
if (chain.length === 1)
|
|
154
|
+
return this._describeMainFrame(page);
|
|
155
|
+
const selectorPromises = [];
|
|
156
|
+
for (let i = 0; i < chain.length - 1; i++)
|
|
157
|
+
selectorPromises.push(findFrameSelector(chain[i + 1]));
|
|
158
|
+
const result = await (0, timeout_runner_1.raceAgainstDeadline)(() => Promise.all(selectorPromises), (0, time_1.monotonicTime)() + 2000);
|
|
159
|
+
if (!result.timedOut &&
|
|
160
|
+
// @ts-expect-error
|
|
161
|
+
result.result.every((selector) => !!selector)) {
|
|
162
|
+
return {
|
|
163
|
+
pageAlias,
|
|
164
|
+
isMainFrame: false,
|
|
165
|
+
// @ts-expect-error
|
|
166
|
+
selectorsChain: result.result,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
// Best effort to find a selector for the frame.
|
|
170
|
+
const selectorsChain = [];
|
|
171
|
+
for (let i = 0; i < chain.length - 1; i++) {
|
|
172
|
+
if (chain[i].name())
|
|
173
|
+
selectorsChain.push(`iframe[name=${(0, css_utils_1.quoteCSSAttributeValue)(chain[i].name())}]`);
|
|
174
|
+
else
|
|
175
|
+
selectorsChain.push(`iframe[src=${(0, css_utils_1.quoteCSSAttributeValue)(chain[i].url())}]`);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
pageAlias,
|
|
179
|
+
isMainFrame: false,
|
|
180
|
+
selectorsChain,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
async _performAction(frame, action) {
|
|
184
|
+
// console.log('perform action', action)
|
|
185
|
+
// Commit last action so that no further signals are added to it.
|
|
186
|
+
this._generator.commitLastAction();
|
|
187
|
+
const frameDescription = await this._describeFrame(frame);
|
|
188
|
+
const actionInContext = {
|
|
189
|
+
frame: frameDescription,
|
|
190
|
+
action,
|
|
191
|
+
};
|
|
192
|
+
const perform = async (action, params, cb) => {
|
|
193
|
+
const callMetadata = {
|
|
194
|
+
id: `call@${(0, crypto_1.createGuid)()}`,
|
|
195
|
+
apiName: 'frame.' + action,
|
|
196
|
+
// @ts-expect-error
|
|
197
|
+
objectId: frame._guid,
|
|
198
|
+
// @ts-expect-error
|
|
199
|
+
pageId: frame._page._guid,
|
|
200
|
+
// @ts-expect-error
|
|
201
|
+
frameId: frame._guid,
|
|
202
|
+
startTime: (0, time_1.monotonicTime)(),
|
|
203
|
+
endTime: 0,
|
|
204
|
+
type: 'Frame',
|
|
205
|
+
method: action,
|
|
206
|
+
params,
|
|
207
|
+
log: [],
|
|
208
|
+
};
|
|
209
|
+
this._generator.willPerformAction(actionInContext);
|
|
210
|
+
//// console.log('will perform action', actionInContext)
|
|
211
|
+
try {
|
|
212
|
+
//await frame.instrumentation.onBeforeCall(frame, callMetadata)
|
|
213
|
+
await cb(callMetadata);
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
console.error('error performing action', e);
|
|
217
|
+
callMetadata.endTime = (0, time_1.monotonicTime)();
|
|
218
|
+
//await frame.instrumentation.onAfterCall(frame, callMetadata)
|
|
219
|
+
this._generator.performedActionFailed(actionInContext);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
callMetadata.endTime = (0, time_1.monotonicTime)();
|
|
223
|
+
//await frame.instrumentation.onAfterCall(frame, callMetadata)
|
|
224
|
+
this._setCommittedAfterTimeout(actionInContext);
|
|
225
|
+
this._generator.didPerformAction(actionInContext);
|
|
226
|
+
//console.log('did perform action', actionInContext)
|
|
227
|
+
};
|
|
228
|
+
const kActionTimeout = 5000;
|
|
229
|
+
if (action.name === 'click') {
|
|
230
|
+
const { options } = (0, utils_1.toClickOptions)(action);
|
|
231
|
+
await perform('click', { selector: action.selector }, (callMetadata) => {
|
|
232
|
+
return frame.click(action.selector, {
|
|
233
|
+
...options,
|
|
234
|
+
force: true,
|
|
235
|
+
timeout: kActionTimeout,
|
|
236
|
+
strict: true,
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
if (action.name === 'press') {
|
|
241
|
+
const modifiers = (0, utils_1.toModifiers)(action.modifiers);
|
|
242
|
+
const shortcut = [...modifiers, action.key].join('+');
|
|
243
|
+
await perform('press', { selector: action.selector, key: shortcut }, (callMetadata) => frame.press(action.selector, shortcut, {
|
|
244
|
+
timeout: kActionTimeout,
|
|
245
|
+
strict: true,
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
if (action.name === 'check')
|
|
249
|
+
await perform('check', { selector: action.selector }, (callMetadata) => frame.check(action.selector, {
|
|
250
|
+
timeout: kActionTimeout,
|
|
251
|
+
strict: true,
|
|
252
|
+
}));
|
|
253
|
+
if (action.name === 'uncheck')
|
|
254
|
+
await perform('uncheck', { selector: action.selector }, (callMetadata) => frame.uncheck(action.selector, {
|
|
255
|
+
timeout: kActionTimeout,
|
|
256
|
+
strict: true,
|
|
257
|
+
}));
|
|
258
|
+
if (action.name === 'select') {
|
|
259
|
+
const values = action.options.map((value) => ({ value }));
|
|
260
|
+
await perform('selectOption', { selector: action.selector, values }, (callMetadata) => frame.selectOption(action.selector, values, {
|
|
261
|
+
timeout: kActionTimeout,
|
|
262
|
+
strict: true,
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async _recordAction(frame, action) {
|
|
267
|
+
// console.log('record action', action)
|
|
268
|
+
// Commit last action so that no further signals are added to it.
|
|
269
|
+
this._generator.commitLastAction();
|
|
270
|
+
// console.log('committed action')
|
|
271
|
+
const frameDescription = await this._describeFrame(frame);
|
|
272
|
+
// console.log('described frame')
|
|
273
|
+
const actionInContext = {
|
|
274
|
+
frame: frameDescription,
|
|
275
|
+
action,
|
|
276
|
+
};
|
|
277
|
+
this._setCommittedAfterTimeout(actionInContext);
|
|
278
|
+
// console.log('committed after timeout')
|
|
279
|
+
this._generator.addAction(actionInContext);
|
|
280
|
+
// console.log('action added')
|
|
281
|
+
}
|
|
282
|
+
_setCommittedAfterTimeout(actionInContext) {
|
|
283
|
+
const timer = setTimeout(() => {
|
|
284
|
+
// Commit the action after 5 seconds so that no further signals are added to it.
|
|
285
|
+
actionInContext.committed = true;
|
|
286
|
+
this._timers.delete(timer);
|
|
287
|
+
}, 5000);
|
|
288
|
+
this._timers.add(timer);
|
|
289
|
+
}
|
|
290
|
+
_onFrameNavigated(frame, page) {
|
|
291
|
+
const pageAlias = this._pageAliases.get(page);
|
|
292
|
+
this._generator.signal(pageAlias, frame, {
|
|
293
|
+
name: 'navigation',
|
|
294
|
+
url: frame.url(),
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
_onPopup(page, popup) {
|
|
298
|
+
const pageAlias = this._pageAliases.get(page);
|
|
299
|
+
const popupAlias = this._pageAliases.get(popup);
|
|
300
|
+
this._generator.signal(pageAlias, page.mainFrame(), {
|
|
301
|
+
name: 'popup',
|
|
302
|
+
popupAlias,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
_onDownload(page) {
|
|
306
|
+
const pageAlias = this._pageAliases.get(page);
|
|
307
|
+
++this._lastDownloadOrdinal;
|
|
308
|
+
this._generator.signal(pageAlias, page.mainFrame(), {
|
|
309
|
+
name: 'download',
|
|
310
|
+
downloadAlias: this._lastDownloadOrdinal
|
|
311
|
+
? String(this._lastDownloadOrdinal)
|
|
312
|
+
: '',
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
exports.BrowserbaseCodeGenerator = BrowserbaseCodeGenerator;
|
|
317
|
+
async function findFrameSelector(frame) {
|
|
318
|
+
try {
|
|
319
|
+
const parent = frame.parentFrame();
|
|
320
|
+
const frameElement = await frame.frameElement();
|
|
321
|
+
if (!frameElement || !parent)
|
|
322
|
+
return;
|
|
323
|
+
const selector = await parent.evaluate((element) => {
|
|
324
|
+
//@ts-expect-error
|
|
325
|
+
return window.__bb_injectedScript.generateSelectorSimple(element, {
|
|
326
|
+
testIdAttributeName: '',
|
|
327
|
+
omitInternalEngines: true,
|
|
328
|
+
});
|
|
329
|
+
}, frameElement);
|
|
330
|
+
return selector;
|
|
331
|
+
}
|
|
332
|
+
catch (e) { }
|
|
333
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function monotonicTime(): number;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monotonicTime = monotonicTime;
|
|
4
|
+
// polyfil for window.performance.now
|
|
5
|
+
var performance = global.performance || {};
|
|
6
|
+
var performanceNow =
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
performance.now ||
|
|
9
|
+
// @ts-expect-error
|
|
10
|
+
performance.mozNow ||
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
performance.msNow ||
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
performance.oNow ||
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
performance.webkitNow ||
|
|
17
|
+
function () {
|
|
18
|
+
return new Date().getTime();
|
|
19
|
+
};
|
|
20
|
+
// generate timestamp or delta
|
|
21
|
+
// see http://nodejs.org/api/process.html#process_process_hrtime
|
|
22
|
+
function _hrtime(previousTimestamp) {
|
|
23
|
+
var clocktime = performanceNow.call(performance) * 1e-3;
|
|
24
|
+
var seconds = Math.floor(clocktime);
|
|
25
|
+
var nanoseconds = Math.floor((clocktime % 1) * 1e9);
|
|
26
|
+
if (previousTimestamp) {
|
|
27
|
+
seconds = seconds - previousTimestamp[0];
|
|
28
|
+
nanoseconds = nanoseconds - previousTimestamp[1];
|
|
29
|
+
if (nanoseconds < 0) {
|
|
30
|
+
seconds--;
|
|
31
|
+
nanoseconds += 1e9;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return [seconds, nanoseconds];
|
|
35
|
+
}
|
|
36
|
+
const hrtime = process.hrtime || _hrtime;
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
const initialTime = hrtime();
|
|
39
|
+
function monotonicTime() {
|
|
40
|
+
const [seconds, nanoseconds] = hrtime(initialTime);
|
|
41
|
+
return seconds * 1000 + ((nanoseconds / 1000) | 0) / 1000;
|
|
42
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.raceAgainstDeadline = raceAgainstDeadline;
|
|
4
|
+
const time_1 = require("./time");
|
|
5
|
+
async function raceAgainstDeadline(cb, deadline) {
|
|
6
|
+
let timer;
|
|
7
|
+
return Promise.race([
|
|
8
|
+
cb().then((result) => {
|
|
9
|
+
return { result, timedOut: false };
|
|
10
|
+
}),
|
|
11
|
+
new Promise((resolve) => {
|
|
12
|
+
const kMaxDeadline = 2147483647; // 2^31-1
|
|
13
|
+
const timeout = (deadline || kMaxDeadline) - (0, time_1.monotonicTime)();
|
|
14
|
+
timer = setTimeout(() => resolve({ timedOut: true }), timeout);
|
|
15
|
+
}),
|
|
16
|
+
]).finally(() => {
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare class InvalidSelectorError extends Error {
|
|
17
|
+
}
|
|
18
|
+
export declare function isInvalidSelectorError(error: Error): error is InvalidSelectorError;
|
|
19
|
+
type ClauseCombinator = '' | '>' | '+' | '~' | '>=';
|
|
20
|
+
export type CSSFunctionArgument = CSSComplexSelector | number | string;
|
|
21
|
+
export type CSSFunction = {
|
|
22
|
+
name: string;
|
|
23
|
+
args: CSSFunctionArgument[];
|
|
24
|
+
};
|
|
25
|
+
export type CSSSimpleSelector = {
|
|
26
|
+
css?: string;
|
|
27
|
+
functions: CSSFunction[];
|
|
28
|
+
};
|
|
29
|
+
export type CSSComplexSelector = {
|
|
30
|
+
simples: {
|
|
31
|
+
selector: CSSSimpleSelector;
|
|
32
|
+
combinator: ClauseCombinator;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
export type CSSComplexSelectorList = CSSComplexSelector[];
|
|
36
|
+
export declare function parseCSS(selector: string, customNames: Set<string>): {
|
|
37
|
+
selector: CSSComplexSelectorList;
|
|
38
|
+
names: string[];
|
|
39
|
+
};
|
|
40
|
+
export declare function serializeSelector(args: CSSFunctionArgument[]): string;
|
|
41
|
+
export {};
|