@cloudcare/browser-rum 3.0.1 → 3.0.2

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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildEnv = void 0;
7
7
  var buildEnv = {
8
- sdkVersion: '3.0.1',
8
+ sdkVersion: '3.0.2',
9
9
  sdkName: 'df_web_rum_sdk'
10
10
  };
11
11
  exports.buildEnv = buildEnv;
@@ -173,11 +173,9 @@ var censorText = function censorText(text) {
173
173
  exports.censorText = censorText;
174
174
 
175
175
  function getTextContent(textNode, ignoreWhiteSpace, parentNodePrivacyLevel) {
176
- var _textNode$parentEleme;
177
-
178
176
  // The parent node may not be a html element which has a tagName attribute.
179
177
  // So just let it be undefined which is ok in this use case.
180
- var parentTagName = (_textNode$parentEleme = textNode.parentElement) === null || _textNode$parentEleme === void 0 ? void 0 : _textNode$parentEleme.tagName;
178
+ var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
181
179
  var textContent = textNode.textContent || '';
182
180
 
183
181
  if (ignoreWhiteSpace && !textContent.trim()) {
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.URL_IN_CSS_REF = exports.DATA_URI = exports.ABSOLUTE_URL = void 0;
7
+ exports.absoluteToDoc = absoluteToDoc;
8
+ exports.getAbsoluteSrcsetString = getAbsoluteSrcsetString;
7
9
  exports.getElementInputValue = getElementInputValue;
8
10
  exports.getSerializedNodeId = getSerializedNodeId;
9
11
  exports.hasSerializedNode = hasSerializedNode;
@@ -89,6 +91,19 @@ function getElementInputValue(element, nodePrivacyLevel) {
89
91
  return value;
90
92
  }
91
93
 
94
+ function extractOrigin(url) {
95
+ var origin = '';
96
+
97
+ if (url.indexOf('//') > -1) {
98
+ origin = url.split('/').slice(0, 3).join('/');
99
+ } else {
100
+ origin = url.split('/')[0];
101
+ }
102
+
103
+ origin = origin.split('?')[0];
104
+ return origin;
105
+ }
106
+
92
107
  var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
93
108
  exports.URL_IN_CSS_REF = URL_IN_CSS_REF;
94
109
  var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//;
@@ -104,6 +119,10 @@ function switchToAbsoluteUrl(cssText, cssHref) {
104
119
  return matchingSubstring;
105
120
  }
106
121
 
122
+ if (url[0] === '/') {
123
+ return 'url('.concat(quote).concat(extractOrigin(cssHref) + url).concat(quote, ')');
124
+ }
125
+
107
126
  var quote = singleQuote || doubleQuote || '';
108
127
  return "url(".concat(quote).concat(makeUrlAbsolute(url, cssHref)).concat(quote, ")");
109
128
  });
@@ -134,4 +153,85 @@ function serializeStyleSheets(cssStyleSheets) {
134
153
  };
135
154
  return styleSheet;
136
155
  });
156
+ }
157
+
158
+ function absoluteToDoc(doc, attributeValue) {
159
+ if (!attributeValue || attributeValue.trim() === '') {
160
+ return attributeValue;
161
+ }
162
+
163
+ var a = doc.createElement('a');
164
+ a.href = attributeValue;
165
+ return a.href;
166
+ }
167
+
168
+ var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
169
+ var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
170
+
171
+ function getAbsoluteSrcsetString(doc, attributeValue) {
172
+ if (attributeValue.trim() === '') {
173
+ return attributeValue;
174
+ }
175
+
176
+ var pos = 0;
177
+
178
+ function collectCharacters(regEx) {
179
+ var chars;
180
+ var match = regEx.exec(attributeValue.substring(pos));
181
+
182
+ if (match) {
183
+ chars = match[0];
184
+ pos += chars.length;
185
+ return chars;
186
+ }
187
+
188
+ return '';
189
+ }
190
+
191
+ var output = [];
192
+
193
+ while (true) {
194
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
195
+
196
+ if (pos >= attributeValue.length) {
197
+ break;
198
+ }
199
+
200
+ var url = collectCharacters(SRCSET_NOT_SPACES);
201
+
202
+ if (url.slice(-1) === ',') {
203
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
204
+ output.push(url);
205
+ } else {
206
+ var descriptorsStr = '';
207
+ url = absoluteToDoc(doc, url);
208
+ var inParens = false;
209
+
210
+ while (true) {
211
+ var c = attributeValue.charAt(pos);
212
+
213
+ if (c === '') {
214
+ output.push((url + descriptorsStr).trim());
215
+ break;
216
+ } else if (!inParens) {
217
+ if (c === ',') {
218
+ pos += 1;
219
+ output.push((url + descriptorsStr).trim());
220
+ break;
221
+ } else if (c === '(') {
222
+ inParens = true;
223
+ }
224
+ } else {
225
+ if (c === ')') {
226
+ inParens = false;
227
+ }
228
+ }
229
+
230
+ descriptorsStr += c;
231
+ pos += 1;
232
+ }
233
+ }
234
+ }
235
+
236
+ return output.join(', ');
137
237
  }
@@ -216,11 +216,9 @@ function serializeElementNode(element, options) {
216
216
 
217
217
 
218
218
  function serializeTextNode(textNode, options) {
219
- var _textNode$parentEleme;
220
-
221
219
  // The parent node may not be a html element which has a tagName attribute.
222
220
  // So just let it be undefined which is ok in this use case.
223
- var parentTagName = (_textNode$parentEleme = textNode.parentElement) === null || _textNode$parentEleme === void 0 ? void 0 : _textNode$parentEleme.tagName;
221
+ var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
224
222
  var textContent = (0, _privacy.getTextContent)(textNode, options.ignoreWhiteSpace || false, options.parentNodePrivacyLevel);
225
223
 
226
224
  if (!textContent) {
@@ -324,19 +322,24 @@ function getValidTagName(tagName) {
324
322
  return processedTagName;
325
323
  }
326
324
 
327
- function getCssRulesString(s) {
328
- try {
329
- var rules = s.rules || s.cssRules;
325
+ function getCssRulesString(cssStyleSheet) {
326
+ if (!cssStyleSheet) {
327
+ return null;
328
+ }
330
329
 
331
- if (rules) {
332
- var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
333
- return (0, _serializationUtils.switchToAbsoluteUrl)(styleSheetCssText, s.href);
334
- }
330
+ var rules;
335
331
 
336
- return null;
337
- } catch (error) {
332
+ try {
333
+ rules = cssStyleSheet.rules || cssStyleSheet.cssRules;
334
+ } catch (_unused) {// if css is protected by CORS we cannot access cssRules see: https://www.w3.org/TR/cssom-1/#the-cssstylesheet-interface
335
+ }
336
+
337
+ if (!rules) {
338
338
  return null;
339
339
  }
340
+
341
+ var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
342
+ return (0, _serializationUtils.switchToAbsoluteUrl)(styleSheetCssText, cssStyleSheet.href);
340
343
  }
341
344
 
342
345
  function getCssRuleString(rule) {
@@ -351,6 +354,30 @@ function isSVGElement(el) {
351
354
  return el.tagName === 'svg' || el instanceof SVGElement;
352
355
  }
353
356
 
357
+ function transformAttribute(doc, tagName, name, value) {
358
+ if (name === 'src' || name === 'href' && value && !(tagName === 'use' && value[0] === '#')) {
359
+ return (0, _serializationUtils.absoluteToDoc)(doc, value);
360
+ } else if (name === 'xlink:href' && value && value[0] !== '#') {
361
+ return (0, _serializationUtils.absoluteToDoc)(doc, value);
362
+ } else if (name === 'background' && value && (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
363
+ return (0, _serializationUtils.absoluteToDoc)(doc, value);
364
+ } else if (name === 'srcset' && value) {
365
+ return (0, _serializationUtils.getAbsoluteSrcsetString)(doc, value);
366
+ } else if (name === 'style' && value) {
367
+ return (0, _serializationUtils.switchToAbsoluteUrl)(value, getHref());
368
+ } else if (tagName === 'object' && name === 'data' && value) {
369
+ return (0, _serializationUtils.absoluteToDoc)(doc, value);
370
+ } else {
371
+ return value;
372
+ }
373
+ }
374
+
375
+ function getHref() {
376
+ var a = document.createElement('a');
377
+ a.href = '';
378
+ return a.href;
379
+ }
380
+
354
381
  function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
355
382
  if (nodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN) {
356
383
  return {};
@@ -366,7 +393,7 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
366
393
  var attributeValue = serializeAttribute(element, nodePrivacyLevel, attributeName, options.configuration);
367
394
 
368
395
  if (attributeValue !== null) {
369
- safeAttrs[attributeName] = attributeValue;
396
+ safeAttrs[attributeName] = transformAttribute(doc, tagName, attributeName, attributeValue);
370
397
  }
371
398
  }
372
399
 
@@ -75,7 +75,7 @@ function computeSessionState(configuration, rawTrackingType) {
75
75
 
76
76
  if (hasValidRumSession(rawTrackingType)) {
77
77
  trackingType = rawTrackingType;
78
- } else if (!(0, _browserCore.performDraw)(configuration.sampleRate)) {
78
+ } else if (!(0, _browserCore.performDraw)(configuration.sessionSampleRate)) {
79
79
  trackingType = RumTrackingType.NOT_TRACKED;
80
80
  } else if (!(0, _browserCore.performDraw)(configuration.sessionReplaySampleRate)) {
81
81
  trackingType = RumTrackingType.TRACKED_WITHOUT_SESSION_REPLAY;
@@ -1,4 +1,4 @@
1
1
  export var buildEnv = {
2
- sdkVersion: '3.0.1',
2
+ sdkVersion: '3.0.2',
3
3
  sdkName: 'df_web_rum_sdk'
4
4
  };
@@ -151,11 +151,9 @@ export var censorText = function censorText(text) {
151
151
  return text.replace(/\S/g, TEXT_MASKING_CHAR);
152
152
  };
153
153
  export function getTextContent(textNode, ignoreWhiteSpace, parentNodePrivacyLevel) {
154
- var _textNode$parentEleme;
155
-
156
154
  // The parent node may not be a html element which has a tagName attribute.
157
155
  // So just let it be undefined which is ok in this use case.
158
- var parentTagName = (_textNode$parentEleme = textNode.parentElement) === null || _textNode$parentEleme === void 0 ? void 0 : _textNode$parentEleme.tagName;
156
+ var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
159
157
  var textContent = textNode.textContent || '';
160
158
 
161
159
  if (ignoreWhiteSpace && !textContent.trim()) {
@@ -65,6 +65,20 @@ export function getElementInputValue(element, nodePrivacyLevel) {
65
65
 
66
66
  return value;
67
67
  }
68
+
69
+ function extractOrigin(url) {
70
+ var origin = '';
71
+
72
+ if (url.indexOf('//') > -1) {
73
+ origin = url.split('/').slice(0, 3).join('/');
74
+ } else {
75
+ origin = url.split('/')[0];
76
+ }
77
+
78
+ origin = origin.split('?')[0];
79
+ return origin;
80
+ }
81
+
68
82
  export var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
69
83
  export var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//;
70
84
  export var DATA_URI = /^data:.*,/i;
@@ -76,6 +90,10 @@ export function switchToAbsoluteUrl(cssText, cssHref) {
76
90
  return matchingSubstring;
77
91
  }
78
92
 
93
+ if (url[0] === '/') {
94
+ return 'url('.concat(quote).concat(extractOrigin(cssHref) + url).concat(quote, ')');
95
+ }
96
+
79
97
  var quote = singleQuote || doubleQuote || '';
80
98
  return "url(".concat(quote).concat(makeUrlAbsolute(url, cssHref)).concat(quote, ")");
81
99
  });
@@ -104,4 +122,82 @@ export function serializeStyleSheets(cssStyleSheets) {
104
122
  };
105
123
  return styleSheet;
106
124
  });
125
+ }
126
+ export function absoluteToDoc(doc, attributeValue) {
127
+ if (!attributeValue || attributeValue.trim() === '') {
128
+ return attributeValue;
129
+ }
130
+
131
+ var a = doc.createElement('a');
132
+ a.href = attributeValue;
133
+ return a.href;
134
+ }
135
+ var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
136
+ var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
137
+ export function getAbsoluteSrcsetString(doc, attributeValue) {
138
+ if (attributeValue.trim() === '') {
139
+ return attributeValue;
140
+ }
141
+
142
+ var pos = 0;
143
+
144
+ function collectCharacters(regEx) {
145
+ var chars;
146
+ var match = regEx.exec(attributeValue.substring(pos));
147
+
148
+ if (match) {
149
+ chars = match[0];
150
+ pos += chars.length;
151
+ return chars;
152
+ }
153
+
154
+ return '';
155
+ }
156
+
157
+ var output = [];
158
+
159
+ while (true) {
160
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
161
+
162
+ if (pos >= attributeValue.length) {
163
+ break;
164
+ }
165
+
166
+ var url = collectCharacters(SRCSET_NOT_SPACES);
167
+
168
+ if (url.slice(-1) === ',') {
169
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
170
+ output.push(url);
171
+ } else {
172
+ var descriptorsStr = '';
173
+ url = absoluteToDoc(doc, url);
174
+ var inParens = false;
175
+
176
+ while (true) {
177
+ var c = attributeValue.charAt(pos);
178
+
179
+ if (c === '') {
180
+ output.push((url + descriptorsStr).trim());
181
+ break;
182
+ } else if (!inParens) {
183
+ if (c === ',') {
184
+ pos += 1;
185
+ output.push((url + descriptorsStr).trim());
186
+ break;
187
+ } else if (c === '(') {
188
+ inParens = true;
189
+ }
190
+ } else {
191
+ if (c === ')') {
192
+ inParens = false;
193
+ }
194
+ }
195
+
196
+ descriptorsStr += c;
197
+ pos += 1;
198
+ }
199
+ }
200
+ }
201
+
202
+ return output.join(', ');
107
203
  }
@@ -3,7 +3,7 @@ import { STABLE_ATTRIBUTES } from '../../rumEventsCollection/actions/getSelector
3
3
  import { NodePrivacyLevel, PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_HIDDEN, CENSORED_STRING_MARK, CENSORED_IMG_MARK } from '../../../constants';
4
4
  import { NodeType } from '../../../types';
5
5
  import { getTextContent, shouldMaskNode, reducePrivacyLevel, getNodeSelfPrivacyLevel, MAX_ATTRIBUTE_VALUE_CHAR_LENGTH } from './privacy';
6
- import { getSerializedNodeId, setSerializedNodeId, getElementInputValue, switchToAbsoluteUrl, serializeStyleSheets } from './serializationUtils'; // Those values are the only one that can be used when inheriting privacy levels from parent to
6
+ import { getSerializedNodeId, setSerializedNodeId, getElementInputValue, switchToAbsoluteUrl, serializeStyleSheets, absoluteToDoc, getAbsoluteSrcsetString } from './serializationUtils'; // Those values are the only one that can be used when inheriting privacy levels from parent to
7
7
  // children during serialization, since HIDDEN and IGNORE shouldn't serialize their children. This
8
8
  // ensures that no children are serialized when they shouldn't.
9
9
 
@@ -192,11 +192,9 @@ export function serializeElementNode(element, options) {
192
192
  */
193
193
 
194
194
  function serializeTextNode(textNode, options) {
195
- var _textNode$parentEleme;
196
-
197
195
  // The parent node may not be a html element which has a tagName attribute.
198
196
  // So just let it be undefined which is ok in this use case.
199
- var parentTagName = (_textNode$parentEleme = textNode.parentElement) === null || _textNode$parentEleme === void 0 ? void 0 : _textNode$parentEleme.tagName;
197
+ var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
200
198
  var textContent = getTextContent(textNode, options.ignoreWhiteSpace || false, options.parentNodePrivacyLevel);
201
199
 
202
200
  if (!textContent) {
@@ -298,19 +296,24 @@ function getValidTagName(tagName) {
298
296
  return processedTagName;
299
297
  }
300
298
 
301
- function getCssRulesString(s) {
302
- try {
303
- var rules = s.rules || s.cssRules;
299
+ function getCssRulesString(cssStyleSheet) {
300
+ if (!cssStyleSheet) {
301
+ return null;
302
+ }
304
303
 
305
- if (rules) {
306
- var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
307
- return switchToAbsoluteUrl(styleSheetCssText, s.href);
308
- }
304
+ var rules;
309
305
 
310
- return null;
311
- } catch (error) {
306
+ try {
307
+ rules = cssStyleSheet.rules || cssStyleSheet.cssRules;
308
+ } catch (_unused) {// if css is protected by CORS we cannot access cssRules see: https://www.w3.org/TR/cssom-1/#the-cssstylesheet-interface
309
+ }
310
+
311
+ if (!rules) {
312
312
  return null;
313
313
  }
314
+
315
+ var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
316
+ return switchToAbsoluteUrl(styleSheetCssText, cssStyleSheet.href);
314
317
  }
315
318
 
316
319
  function getCssRuleString(rule) {
@@ -325,6 +328,30 @@ function isSVGElement(el) {
325
328
  return el.tagName === 'svg' || el instanceof SVGElement;
326
329
  }
327
330
 
331
+ function transformAttribute(doc, tagName, name, value) {
332
+ if (name === 'src' || name === 'href' && value && !(tagName === 'use' && value[0] === '#')) {
333
+ return absoluteToDoc(doc, value);
334
+ } else if (name === 'xlink:href' && value && value[0] !== '#') {
335
+ return absoluteToDoc(doc, value);
336
+ } else if (name === 'background' && value && (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
337
+ return absoluteToDoc(doc, value);
338
+ } else if (name === 'srcset' && value) {
339
+ return getAbsoluteSrcsetString(doc, value);
340
+ } else if (name === 'style' && value) {
341
+ return switchToAbsoluteUrl(value, getHref());
342
+ } else if (tagName === 'object' && name === 'data' && value) {
343
+ return absoluteToDoc(doc, value);
344
+ } else {
345
+ return value;
346
+ }
347
+ }
348
+
349
+ function getHref() {
350
+ var a = document.createElement('a');
351
+ a.href = '';
352
+ return a.href;
353
+ }
354
+
328
355
  function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
329
356
  if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
330
357
  return {};
@@ -340,7 +367,7 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
340
367
  var attributeValue = serializeAttribute(element, nodePrivacyLevel, attributeName, options.configuration);
341
368
 
342
369
  if (attributeValue !== null) {
343
- safeAttrs[attributeName] = attributeValue;
370
+ safeAttrs[attributeName] = transformAttribute(doc, tagName, attributeName, attributeValue);
344
371
  }
345
372
  }
346
373
 
@@ -60,7 +60,7 @@ function computeSessionState(configuration, rawTrackingType) {
60
60
 
61
61
  if (hasValidRumSession(rawTrackingType)) {
62
62
  trackingType = rawTrackingType;
63
- } else if (!performDraw(configuration.sampleRate)) {
63
+ } else if (!performDraw(configuration.sessionSampleRate)) {
64
64
  trackingType = RumTrackingType.NOT_TRACKED;
65
65
  } else if (!performDraw(configuration.sessionReplaySampleRate)) {
66
66
  trackingType = RumTrackingType.TRACKED_WITHOUT_SESSION_REPLAY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-rum",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "dependencies": {
@@ -29,5 +29,5 @@
29
29
  "license": "MIT",
30
30
  "homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
31
31
  "description": "DataFlux RUM Web 端数据指标监控",
32
- "gitHead": "4c9417de87768497d73bb0ce422e76c982ed69b7"
32
+ "gitHead": "84d23b733f540e749455013790782b475eb8b83d"
33
33
  }
@@ -187,7 +187,7 @@ export function getTextContent(
187
187
  ) {
188
188
  // The parent node may not be a html element which has a tagName attribute.
189
189
  // So just let it be undefined which is ok in this use case.
190
- var parentTagName = textNode.parentElement?.tagName
190
+ var parentTagName = textNode.parentElement && textNode.parentElement.tagName
191
191
  var textContent = textNode.textContent || ''
192
192
 
193
193
  if (ignoreWhiteSpace && !textContent.trim()) {
@@ -72,7 +72,16 @@ export function getElementInputValue(element, nodePrivacyLevel) {
72
72
 
73
73
  return value
74
74
  }
75
-
75
+ function extractOrigin(url) {
76
+ var origin = ''
77
+ if (url.indexOf('//') > -1) {
78
+ origin = url.split('/').slice(0, 3).join('/')
79
+ } else {
80
+ origin = url.split('/')[0]
81
+ }
82
+ origin = origin.split('?')[0]
83
+ return origin
84
+ }
76
85
  export var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm
77
86
  export var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//
78
87
  export var DATA_URI = /^data:.*,/i
@@ -96,7 +105,12 @@ export function switchToAbsoluteUrl(cssText, cssHref) {
96
105
  if (!cssHref || !url || ABSOLUTE_URL.test(url) || DATA_URI.test(url)) {
97
106
  return matchingSubstring
98
107
  }
99
-
108
+ if (url[0] === '/') {
109
+ return 'url('
110
+ .concat(quote)
111
+ .concat(extractOrigin(cssHref) + url)
112
+ .concat(quote, ')')
113
+ }
100
114
  var quote = singleQuote || doubleQuote || ''
101
115
  return `url(${quote}${makeUrlAbsolute(url, cssHref)}${quote})`
102
116
  }
@@ -132,3 +146,68 @@ export function serializeStyleSheets(cssStyleSheets) {
132
146
  return styleSheet
133
147
  })
134
148
  }
149
+ export function absoluteToDoc(doc, attributeValue) {
150
+ if (!attributeValue || attributeValue.trim() === '') {
151
+ return attributeValue
152
+ }
153
+ var a = doc.createElement('a')
154
+ a.href = attributeValue
155
+ return a.href
156
+ }
157
+
158
+ var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/
159
+ var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/
160
+ export function getAbsoluteSrcsetString(doc, attributeValue) {
161
+ if (attributeValue.trim() === '') {
162
+ return attributeValue
163
+ }
164
+ var pos = 0
165
+ function collectCharacters(regEx) {
166
+ var chars
167
+ var match = regEx.exec(attributeValue.substring(pos))
168
+ if (match) {
169
+ chars = match[0]
170
+ pos += chars.length
171
+ return chars
172
+ }
173
+ return ''
174
+ }
175
+ var output = []
176
+ while (true) {
177
+ collectCharacters(SRCSET_COMMAS_OR_SPACES)
178
+ if (pos >= attributeValue.length) {
179
+ break
180
+ }
181
+ var url = collectCharacters(SRCSET_NOT_SPACES)
182
+ if (url.slice(-1) === ',') {
183
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1))
184
+ output.push(url)
185
+ } else {
186
+ var descriptorsStr = ''
187
+ url = absoluteToDoc(doc, url)
188
+ var inParens = false
189
+ while (true) {
190
+ var c = attributeValue.charAt(pos)
191
+ if (c === '') {
192
+ output.push((url + descriptorsStr).trim())
193
+ break
194
+ } else if (!inParens) {
195
+ if (c === ',') {
196
+ pos += 1
197
+ output.push((url + descriptorsStr).trim())
198
+ break
199
+ } else if (c === '(') {
200
+ inParens = true
201
+ }
202
+ } else {
203
+ if (c === ')') {
204
+ inParens = false
205
+ }
206
+ }
207
+ descriptorsStr += c
208
+ pos += 1
209
+ }
210
+ }
211
+ }
212
+ return output.join(', ')
213
+ }