@web-widget/web-widget
Version:
Web front-end application container
49 lines (48 loc) • 1.65 kB
JavaScript
// src/utils/render.ts
var ASSET_PLACEHOLDER = "asset://";
var MODULE_REG = /\b(?:import|__vite_ssr_dynamic_import__)\(["']([^"']*)["']\)/;
function parseModuleId(loader) {
const match = String(loader).match(MODULE_REG);
const id = match == null ? void 0 : match[1];
if (!id) {
throw new Error(`The url for the module was not found: ${loader}`);
}
return id;
}
function unsafePropsToAttrs(props) {
return Object.entries(props).reduce(
(attrs, [key, value]) => {
if (typeof value === "string") {
attrs[key.toLowerCase()] = value;
} else if (typeof value === "number") {
attrs[key.toLowerCase()] = String(value);
} else if (value === true) {
attrs[key.toLowerCase()] = "";
}
return attrs;
},
{}
);
}
function getClientModuleId(loader, options) {
var _a;
const isAssetPlaceholder = (_a = options.import) == null ? void 0 : _a.startsWith(ASSET_PLACEHOLDER);
if (isAssetPlaceholder) {
console.warn(
`The ${JSON.stringify(
options.import
)} protocol is not recognized, please check if the module is built correctly.`
);
}
return options.import && !isAssetPlaceholder ? options.import : options.base && !options.base.startsWith("file://") ? options.base + parseModuleId(loader) : parseModuleId(loader);
}
function getDisplayModuleId(loader, options) {
var _a;
return ((_a = options.base) == null ? void 0 : _a.startsWith("file://")) ? new URL(parseModuleId(loader), options.base).href : parseModuleId(loader);
}
export {
unsafePropsToAttrs,
getClientModuleId,
getDisplayModuleId
};
//# sourceMappingURL=chunk-L7YKSBOA.js.map