'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const core = require('@unocss/core'); const utils = require('@unocss/preset-mini/utils'); function handleInsetValue(v, { theme }) { if (!v) return 0; return theme.spacing?.[v] ?? utils.h.bracket.cssvar.global.auto.fraction.rem(v) ?? 0; } function safeAraMatcher({ propertyPrefix, propertyName, safeAreaPrefix, safeAreaName, mode, value }) { return [[`${propertyPrefix || ""}${propertyName}`, mode === "add" ? `calc(env(${safeAreaPrefix}${safeAreaName}) + ${value})` : `env(${safeAreaPrefix}${safeAreaName}, ${value})`]]; } const safeAreaMapping = { safe: "safe-area-inset", titlebar: "titlebar-area", keyboard: "keyboard-inset" }; const sizeMapping = { h: "height", w: "width" }; function getPropName(minmax, hw) { return `${minmax || ""}${sizeMapping[hw]}`; } const valueMapping = { l: "-left", r: "-right", t: "-top", b: "-bottom", x: "-x", y: "-y", w: "-width", h: "-height", top: "-top", left: "-left", right: "-right", bottom: "-bottom" }; const presetSafeArea = core.definePreset(() => { return { name: "unocss-preset-safe-area", rules: [ [ /^([p|m])-?([rltb])([\+|-])(?:(safe)(?:-([rltb]))?|(titlebar)(?:(?:-([xy])|(?:-([wh]))))|(keyboard)(?:(?:-([rltb]))?|(?:-([wh]))))(?:-(-?.+))?$/, ([, propertyPrefix, propName, mode, safeProperty0, safeValue0, safeProperty1, safeValue1, safeValue2, safeProperty2, safeValue3, safeValue4, value], ctx) => safeAraMatcher({ propertyPrefix: propertyPrefix === "p" ? "padding" : "margin", propertyName: utils.directionMap[propName][0], safeAreaPrefix: safeAreaMapping[safeProperty0 || safeProperty1 || safeProperty2], safeAreaName: valueMapping[safeValue0 || safeValue1 || safeValue2 || safeValue3 || safeValue4] || utils.directionMap[propName][0], mode: mode === "+" ? "add" : "fallback", value: handleInsetValue(value, ctx) }), { autocomplete: [ "(m|p)(r|l|t|b)(+|-)(safe|keyboard)-", "(m|p)(r|l|t|b)(+|-)safe-(r|l|t|b)-", "(m|p)(r|l|t|b)(+|-)titlebar-(x|y|w|h)-", "(m|p)(r|l|t|b)(+|-)keyboard-(r|l|t|b|w|h)-" ] } ], [ /^(?:size-)?(min-|max-)?([wh])([\+|-])(?:(safe)(?:-([rltb]))|(titlebar)(?:(?:-([xy])|(?:-([wh]))?))|(keyboard)(?:(?:-([rltb]))|(?:-([wh]))?))(?:-(-?.+))?$/, ([, minmax, wh, mode, safeProperty0, safeValue0, safeProperty1, safeValue1, safeValue2, safeProperty2, safeValue3, safeValue4, value], ctx) => safeAraMatcher({ propertyName: getPropName(minmax, wh), safeAreaPrefix: safeAreaMapping[safeProperty0 || safeProperty1 || safeProperty2], safeAreaName: valueMapping[safeValue0 || safeValue1 || safeValue2 || safeValue3 || safeValue4 || wh], mode: mode === "+" ? "add" : "fallback", value: handleInsetValue(value, ctx) }), { autocomplete: [ "(w|h)(+|-)safe-(r|l|t|b)-", "(min|max)-(w|h)(+|-)safe-(r|l|t|b)-", "(w|h)(+|-)(titlebar|keyboard)-", "(w|h)(+|-)titlebar-(x|y|w|h)-", "(min|max)-(w|h)(+|-)(titlebar|keyboard)-", "(min|max)-(w|h)(+|-)titlebar-(x|y|w|h)-", "(w|h)(+|-)keyboard-(r|l|t|b|w|h)-", "(min|max)-(w|h)(+|-)keyboard-(r|l|t|b|w|h)-" ] } ], [ /^(?:position-|pos-)?(top|left|right|bottom)([\+|-])(?:(safe)(?:-([rltb]))?|(titlebar)(?:(?:-([xy])|(?:-([wh]))))|(keyboard)(?:(?:-([rltb]))?|(?:-([wh]))))(?:-(-?.+))?$/, ([, propertyName, mode, safeProperty0, safeValue0, safeProperty1, safeValue1, safeValue2, safeProperty2, safeValue3, safeValue4, value], ctx) => safeAraMatcher({ propertyName, safeAreaPrefix: safeAreaMapping[safeProperty0 || safeProperty1 || safeProperty2], safeAreaName: valueMapping[safeValue0 || safeValue1 || safeValue2 || safeValue3 || safeValue4 || propertyName], mode: mode === "+" ? "add" : "fallback", value: handleInsetValue(value, ctx) }), { autocomplete: [ "(top|left|right|bottom)(+|-)(safe|keyboard)-", "(top|left|right|bottom)(+|-)safe-(r|l|t|b)-", "(top|left|right|bottom)(+|-)titlebar-(x|y|w|h)-", "(top|left|right|bottom)(+|-)keyboard-(r|l|t|b|w|h)-" ] } ] ] }; }); exports.default = presetSafeArea; exports.presetSafeArea = presetSafeArea;