Compare commits
6 Commits
v10.0.0-rc
...
v10.0.0-rc
Author | SHA1 | Date | |
---|---|---|---|
a578b86715 | |||
b6b384854e | |||
c628183773 | |||
eaacaa6966 | |||
9a09e280c9 | |||
70ac07d861 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "10.0.0-rc.113",
|
||||
"version": "10.0.0-rc.116",
|
||||
"description": "Create Keycloak themes using React",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -18,35 +18,49 @@ export function replaceImportsInCssCode(params: {
|
||||
} {
|
||||
const { cssCode, cssFileRelativeDirPath, buildContext } = params;
|
||||
|
||||
const fixedCssCode = cssCode.replace(
|
||||
/url\(["']?(\/[^/][^)"']+)["']?\)/g,
|
||||
(match, assetFileAbsoluteUrlPathname) => {
|
||||
if (buildContext.urlPathname !== undefined) {
|
||||
if (!assetFileAbsoluteUrlPathname.startsWith(buildContext.urlPathname)) {
|
||||
// NOTE: Should never happen
|
||||
return match;
|
||||
let fixedCssCode = cssCode;
|
||||
|
||||
[
|
||||
/url\("(\/[^/][^"]+)"\)/g,
|
||||
/url\('(\/[^/][^']+)'\)/g,
|
||||
/url\((\/[^/][^)]+)\)/g
|
||||
].forEach(
|
||||
regex =>
|
||||
(fixedCssCode = fixedCssCode.replace(
|
||||
regex,
|
||||
(match, assetFileAbsoluteUrlPathname) => {
|
||||
if (buildContext.urlPathname !== undefined) {
|
||||
if (
|
||||
!assetFileAbsoluteUrlPathname.startsWith(
|
||||
buildContext.urlPathname
|
||||
)
|
||||
) {
|
||||
// NOTE: Should never happen
|
||||
return match;
|
||||
}
|
||||
assetFileAbsoluteUrlPathname =
|
||||
assetFileAbsoluteUrlPathname.replace(
|
||||
buildContext.urlPathname,
|
||||
"/"
|
||||
);
|
||||
}
|
||||
|
||||
inline_style_in_html: {
|
||||
if (cssFileRelativeDirPath !== undefined) {
|
||||
break inline_style_in_html;
|
||||
}
|
||||
|
||||
return `url("\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}${assetFileAbsoluteUrlPathname}")`;
|
||||
}
|
||||
|
||||
const assetFileRelativeUrlPathname = posix.relative(
|
||||
cssFileRelativeDirPath.replace(/\\/g, "/"),
|
||||
assetFileAbsoluteUrlPathname.replace(/^\//, "")
|
||||
);
|
||||
|
||||
return `url("${assetFileRelativeUrlPathname}")`;
|
||||
}
|
||||
assetFileAbsoluteUrlPathname = assetFileAbsoluteUrlPathname.replace(
|
||||
buildContext.urlPathname,
|
||||
"/"
|
||||
);
|
||||
}
|
||||
|
||||
inline_style_in_html: {
|
||||
if (cssFileRelativeDirPath !== undefined) {
|
||||
break inline_style_in_html;
|
||||
}
|
||||
|
||||
return `url("\${xKeycloakify.resourcesPath}/${BASENAME_OF_KEYCLOAKIFY_RESOURCES_DIR}${assetFileAbsoluteUrlPathname}")`;
|
||||
}
|
||||
|
||||
const assetFileRelativeUrlPathname = posix.relative(
|
||||
cssFileRelativeDirPath.replace(/\\/g, "/"),
|
||||
assetFileAbsoluteUrlPathname.replace(/^\//, "")
|
||||
);
|
||||
|
||||
return `url("${assetFileRelativeUrlPathname}")`;
|
||||
}
|
||||
))
|
||||
);
|
||||
|
||||
return { fixedCssCode };
|
||||
|
@ -71,14 +71,10 @@ export function createGetKcClsx<ClassKey extends string>(params: {
|
||||
transform: classKey => {
|
||||
assert(is<ClassKey>(classKey));
|
||||
|
||||
const className = classes?.[classKey];
|
||||
|
||||
return clsx(
|
||||
classKey,
|
||||
doUseDefaultCss && !className?.split(" ").includes("CLEAR")
|
||||
? defaultClasses[classKey]
|
||||
: undefined,
|
||||
className
|
||||
classes?.[classKey] ??
|
||||
(doUseDefaultCss ? defaultClasses[classKey] : undefined)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useEffect, useReducer, Fragment } from "react";
|
||||
import { assert } from "tsafe/assert";
|
||||
import { assert } from "keycloakify/tools/assert";
|
||||
import type { KcClsx } from "keycloakify/login/lib/kcClsx";
|
||||
import {
|
||||
useUserProfileForm,
|
||||
|
@ -394,6 +394,14 @@ describe("css replacer", () => {
|
||||
.my-div3 {
|
||||
background-image: url(/assets/media/something.svg);
|
||||
}
|
||||
|
||||
.my-div4 {
|
||||
background-image: url("/assets/media/something(cool).svg");
|
||||
}
|
||||
|
||||
.my-div5 {
|
||||
background-image: url('/assets/media/something(cool).svg');
|
||||
}
|
||||
`,
|
||||
cssFileRelativeDirPath: "assets/",
|
||||
buildContext: {
|
||||
@ -413,6 +421,14 @@ describe("css replacer", () => {
|
||||
.my-div3 {
|
||||
background-image: url("media/something.svg");
|
||||
}
|
||||
|
||||
.my-div4 {
|
||||
background-image: url("media/something(cool).svg");
|
||||
}
|
||||
|
||||
.my-div5 {
|
||||
background-image: url("media/something(cool).svg");
|
||||
}
|
||||
`;
|
||||
|
||||
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||
|
Reference in New Issue
Block a user