MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / parseBackgroundPosition

Function parseBackgroundPosition

packages/core/css/parser.ts:284–401  ·  view source on GitHub ↗
(text: string, start = 0, keyword = parseKeyword(text, start))

Source from the content-addressed store, hash-verified

282 bottom: 'y',
283};
284export function parseBackgroundPosition(text: string, start = 0, keyword = parseKeyword(text, start)): Parsed<BackgroundPosition> {
285 function formatH(align: Parsed<HorizontalAlign>, offset: Parsed<LengthPercentage>) {
286 if (align.value === 'center') {
287 return 'center';
288 }
289 if (offset && offset.value.value !== 0) {
290 return { align: align.value, offset: offset.value };
291 }
292
293 return align.value;
294 }
295 function formatV(align: Parsed<VerticalAlign>, offset: Parsed<LengthPercentage>) {
296 if (align.value === 'center') {
297 return 'center';
298 }
299 if (offset && offset.value.value !== 0) {
300 return { align: align.value, offset: offset.value };
301 }
302
303 return align.value;
304 }
305 let end = start;
306 if (keyword && backgroundPositionKeywords.has(keyword.value)) {
307 end = keyword.end;
308 const firstDirection = backgroundPositionKeywordsDirection[keyword.value];
309
310 const firstLength = firstDirection !== 'center' && parsePercentageOrLength(text, end);
311 if (firstLength) {
312 end = firstLength.end;
313 }
314
315 const secondKeyword = parseKeyword(text, end);
316 if (secondKeyword && backgroundPositionKeywords.has(secondKeyword.value)) {
317 end = secondKeyword.end;
318 const secondDirection = backgroundPositionKeywordsDirection[secondKeyword.end];
319
320 if (firstDirection === secondDirection && firstDirection !== 'center') {
321 return null; // Reject pair of both horizontal or both vertical alignments.
322 }
323
324 const secondLength = secondDirection !== 'center' && parsePercentageOrLength(text, end);
325 if (secondLength) {
326 end = secondLength.end;
327 }
328
329 if ((firstDirection === secondDirection && secondDirection === 'center') || firstDirection === 'x' || secondDirection === 'y') {
330 return {
331 start,
332 end,
333 value: {
334 x: formatH(<Parsed<HorizontalAlign>>keyword, firstLength),
335 y: formatV(<Parsed<VerticalAlign>>secondKeyword, secondLength),
336 },
337 };
338 } else {
339 return {
340 start,
341 end,

Callers 1

parseBackgroundFunction · 0.85

Calls 4

parseKeywordFunction · 0.85
parsePercentageOrLengthFunction · 0.85
formatHFunction · 0.85
formatVFunction · 0.85

Tested by

no test coverage detected