MCPcopy
hub / github.com/niklasvh/html2canvas / parse

Function parse

src/css/index.ts:287–321  ·  view source on GitHub ↗
(context: Context, descriptor: CSSPropertyDescriptor<any>, style?: string | null)

Source from the content-addressed store, hash-verified

285
286// eslint-disable-next-line @typescript-eslint/no-explicit-any
287const parse = (context: Context, descriptor: CSSPropertyDescriptor<any>, style?: string | null) => {
288 const tokenizer = new Tokenizer();
289 const value = style !== null && typeof style !== 'undefined' ? style.toString() : descriptor.initialValue;
290 tokenizer.write(value);
291 const parser = new Parser(tokenizer.read());
292 switch (descriptor.type) {
293 case PropertyDescriptorParsingType.IDENT_VALUE:
294 const token = parser.parseComponentValue();
295 return descriptor.parse(context, isIdentToken(token) ? token.value : descriptor.initialValue);
296 case PropertyDescriptorParsingType.VALUE:
297 return descriptor.parse(context, parser.parseComponentValue());
298 case PropertyDescriptorParsingType.LIST:
299 return descriptor.parse(context, parser.parseComponentValues());
300 case PropertyDescriptorParsingType.TOKEN_VALUE:
301 return parser.parseComponentValue();
302 case PropertyDescriptorParsingType.TYPE_VALUE:
303 switch (descriptor.format) {
304 case 'angle':
305 return angle.parse(context, parser.parseComponentValue());
306 case 'color':
307 return colorType.parse(context, parser.parseComponentValue());
308 case 'image':
309 return image.parse(context, parser.parseComponentValue());
310 case 'length':
311 const length = parser.parseComponentValue();
312 return isLength(length) ? length : ZERO_LENGTH;
313 case 'length-percentage':
314 const value = parser.parseComponentValue();
315 return isLengthPercentage(value) ? value : ZERO_LENGTH;
316 case 'time':
317 return time.parse(context, parser.parseComponentValue());
318 }
319 break;
320 }
321};

Callers 3

constructorMethod · 0.70
constructorMethod · 0.70
constructorMethod · 0.70

Calls 8

writeMethod · 0.95
readMethod · 0.95
parseComponentValueMethod · 0.95
parseComponentValuesMethod · 0.95
isIdentTokenFunction · 0.90
isLengthFunction · 0.90
isLengthPercentageFunction · 0.90
parseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…