@tldraw/editor
Version:
tldraw infinite canvas SDK (editor).
99 lines (98 loc) • 3.71 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var parseCss_exports = {};
__export(parseCss_exports, {
parseCss: () => parseCss,
parseCssFontFaces: () => parseCssFontFaces,
parseCssFontFamilyValue: () => parseCssFontFamilyValue,
parseCssImports: () => parseCssImports,
parseCssValueUrls: () => parseCssValueUrls,
shouldIncludeCssProperty: () => shouldIncludeCssProperty
});
module.exports = __toCommonJS(parseCss_exports);
var import_utils = require("@tldraw/utils");
const importsRegex = /@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi;
const fontFaceRegex = /@font-face\s*{([^}]+)}/gi;
const urlsRegex = /url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi;
const fontFamilyRegex = /(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;
function parseCssImports(css) {
return Array.from(css.matchAll(importsRegex), (m) => ({
url: m[1] || m[2] || m[3] || m[4] || m[5],
extras: m[6]
}));
}
function parseCssFontFaces(css, baseUrl) {
return Array.from(css.matchAll(fontFaceRegex), (m) => {
const fontFace = m[1];
const urls = Array.from(fontFace.matchAll(urlsRegex), (m2) => {
const original = m2[1] || m2[2] || m2[3];
return {
original,
resolved: (0, import_utils.safeParseUrl)(original, baseUrl)?.href ?? null
};
});
const fontFamilies = new Set(
Array.from(fontFace.matchAll(fontFamilyRegex), (m2) => (m2[1] || m2[2] || m2[3]).toLowerCase())
);
return { fontFace, urls, fontFamilies };
});
}
function parseCssFontFamilyValue(value) {
const valueRegex = /\s*(?:([^'"][^;\n\s,]+)|"([^"]+)"|'([^']+)')\s*/gi;
const separatorRegex = /\s*,\s*/gi;
const fontFamilies = /* @__PURE__ */ new Set();
while (true) {
const valueMatch = valueRegex.exec(value);
if (!valueMatch) {
break;
}
const fontFamily = valueMatch[1] || valueMatch[2] || valueMatch[3];
fontFamilies.add(fontFamily.toLowerCase());
separatorRegex.lastIndex = valueRegex.lastIndex;
const separatorMatch = separatorRegex.exec(value);
if (!separatorMatch) {
break;
}
valueRegex.lastIndex = separatorRegex.lastIndex;
}
return fontFamilies;
}
function shouldIncludeCssProperty(property) {
if (property.startsWith("-")) return false;
if (property.startsWith("animation")) return false;
if (property.startsWith("transition")) return false;
if (property === "cursor") return false;
if (property === "pointer-events") return false;
if (property === "user-select") return false;
if (property === "touch-action") return false;
return true;
}
function parseCss(css, baseUrl) {
return {
imports: parseCssImports(css),
fontFaces: parseCssFontFaces(css, baseUrl)
};
}
function parseCssValueUrls(value) {
return Array.from(value.matchAll(urlsRegex), (m) => ({
original: m[0],
url: m[1] || m[2] || m[3]
}));
}
//# sourceMappingURL=parseCss.js.map