@ui5/webcomponents-base 0.0.0-11d529e8a → 0.0.0-1e08ebdef
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -1
- package/CHANGELOG.md +42 -0
- package/README.md +2 -3
- package/bundle.esm.js +1 -2
- package/dist/CSP.js +59 -0
- package/dist/Device.js +11 -0
- package/dist/FontFace.js +7 -95
- package/dist/InitialConfiguration.js +11 -0
- package/dist/ManagedStyles.js +83 -0
- package/dist/Render.js +3 -1
- package/dist/StaticAreaItem.js +0 -9
- package/dist/SystemCSSVars.js +4 -25
- package/dist/UI5Element.js +14 -21
- package/dist/UI5ElementMetadata.js +8 -0
- package/dist/asset-registries/Icons.js +25 -14
- package/dist/asset-registries/LocaleData.js +11 -2
- package/dist/assets-meta/IconCollectionsAlias.js +18 -0
- package/dist/config/Theme.js +14 -0
- package/dist/css/FontFace.css +45 -0
- package/dist/css/OverrideFontFace.css +32 -0
- package/dist/css/SystemCSSVars.css +17 -0
- package/dist/generated/AssetParameters.js +1 -1
- package/dist/generated/css/FontFace.css.js +5 -0
- package/dist/generated/css/OverrideFontFace.css.js +5 -0
- package/dist/generated/css/SystemCSSVars.css.js +5 -0
- package/dist/i18nBundle.js +32 -2
- package/dist/renderer/LitRenderer.js +6 -4
- package/dist/renderer/directives/style-map.js +72 -0
- package/dist/resources/bundle.esm.js +8 -8
- package/dist/resources/bundle.esm.js.map +1 -1
- package/dist/sap/base/security/encodeCSS.js +14 -0
- package/dist/sap/base/security/encodeXML.js +23 -0
- package/dist/sap/base/strings/toHex.js +8 -0
- package/dist/test-resources/pages/i18n.html +1 -3
- package/dist/test-resources/specs/CustomTheme.spec.js +2 -2
- package/dist/test-resources/specs/Theming.spec.js +4 -4
- package/dist/theming/CustomStyle.js +23 -3
- package/dist/theming/applyTheme.js +11 -10
- package/dist/theming/getEffectiveLinksHrefs.js +20 -0
- package/dist/theming/getStylesString.js +4 -2
- package/dist/theming/getThemeDesignerTheme.js +25 -5
- package/dist/theming/preloadLinks.js +23 -0
- package/dist/updateShadowRoot.js +8 -4
- package/dist/util/createLinkInHead.js +19 -0
- package/dist/util/escapeRegex.js +10 -0
- package/dist/util/generateHighlightedMarkup.js +42 -0
- package/hash.txt +1 -1
- package/lib/generate-asset-parameters/index.js +0 -1
- package/lib/generate-styles/index.js +18 -0
- package/package-scripts.js +6 -3
- package/package.json +8 -9
- package/src/CSP.js +59 -0
- package/src/Device.js +11 -0
- package/src/FontFace.js +7 -95
- package/src/InitialConfiguration.js +11 -0
- package/src/ManagedStyles.js +83 -0
- package/src/Render.js +3 -1
- package/src/StaticAreaItem.js +0 -9
- package/src/SystemCSSVars.js +4 -25
- package/src/UI5Element.js +14 -21
- package/src/UI5ElementMetadata.js +8 -0
- package/src/asset-registries/Icons.js +25 -14
- package/src/asset-registries/LocaleData.js +11 -2
- package/src/assets-meta/IconCollectionsAlias.js +18 -0
- package/src/config/Theme.js +14 -0
- package/src/css/FontFace.css +45 -0
- package/src/css/OverrideFontFace.css +32 -0
- package/src/css/SystemCSSVars.css +17 -0
- package/src/i18nBundle.js +32 -2
- package/src/renderer/LitRenderer.js +6 -4
- package/src/renderer/directives/style-map.js +72 -0
- package/src/theming/CustomStyle.js +23 -3
- package/src/theming/applyTheme.js +11 -10
- package/src/theming/getEffectiveLinksHrefs.js +20 -0
- package/src/theming/getStylesString.js +4 -2
- package/src/theming/getThemeDesignerTheme.js +25 -5
- package/src/theming/preloadLinks.js +23 -0
- package/src/updateShadowRoot.js +8 -4
- package/src/util/createLinkInHead.js +19 -0
- package/src/util/escapeRegex.js +10 -0
- package/src/util/generateHighlightedMarkup.js +42 -0
- package/used-modules.txt +4 -1
- package/dist/theming/createThemePropertiesStyleTag.js +0 -20
- package/dist/util/encodeCSS.js +0 -24
- package/src/theming/createThemePropertiesStyleTag.js +0 -20
- package/src/util/encodeCSS.js +0 -24
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import toHex from '../strings/toHex.js';
|
|
2
|
+
var rCSS = /[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff\u2028\u2029][0-9A-Fa-f]?/g;
|
|
3
|
+
var fnCSS = function (sChar) {
|
|
4
|
+
var iChar = sChar.charCodeAt(0);
|
|
5
|
+
if (sChar.length === 1) {
|
|
6
|
+
return '\\' + toHex(iChar);
|
|
7
|
+
} else {
|
|
8
|
+
return '\\' + toHex(iChar) + ' ' + sChar.substr(1);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var fnEncodeCSS = function (sString) {
|
|
12
|
+
return sString.replace(rCSS, fnCSS);
|
|
13
|
+
};
|
|
14
|
+
export default fnEncodeCSS;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import toHex from '../strings/toHex.js';
|
|
2
|
+
var rHtml = /[\x00-\x2b\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\xff\u2028\u2029]/g, rHtmlReplace = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]/, mHtmlLookup = {
|
|
3
|
+
'<': '<',
|
|
4
|
+
'>': '>',
|
|
5
|
+
'&': '&',
|
|
6
|
+
'"': '"'
|
|
7
|
+
};
|
|
8
|
+
var fnHtml = function (sChar) {
|
|
9
|
+
var sEncoded = mHtmlLookup[sChar];
|
|
10
|
+
if (!sEncoded) {
|
|
11
|
+
if (rHtmlReplace.test(sChar)) {
|
|
12
|
+
sEncoded = '�';
|
|
13
|
+
} else {
|
|
14
|
+
sEncoded = '&#x' + toHex(sChar.charCodeAt(0)) + ';';
|
|
15
|
+
}
|
|
16
|
+
mHtmlLookup[sChar] = sEncoded;
|
|
17
|
+
}
|
|
18
|
+
return sEncoded;
|
|
19
|
+
};
|
|
20
|
+
var fnEncodeXML = function (sString) {
|
|
21
|
+
return sString.replace(rHtml, fnHtml);
|
|
22
|
+
};
|
|
23
|
+
export default fnEncodeXML;
|
|
@@ -17,9 +17,7 @@
|
|
|
17
17
|
const demo = async () => {
|
|
18
18
|
["de", "es", "fr", "en"].forEach(localeId => registerI18nLoader("myApp", localeId, () => `./assets/messagebundle_${localeId}.properties`));
|
|
19
19
|
|
|
20
|
-
await
|
|
21
|
-
|
|
22
|
-
const bundle = getI18nBundle("myApp");
|
|
20
|
+
const bundle = await getI18nBundle("myApp");
|
|
23
21
|
|
|
24
22
|
const pleaseWait = bundle.getText("PLEASE_WAIT");
|
|
25
23
|
console.log("Please wait in the current language is: ", pleaseWait);
|
|
@@ -16,8 +16,8 @@ describe("Custom themes can be registered", () => {
|
|
|
16
16
|
const config = window['sap-ui-webcomponents-bundle'].configuration;
|
|
17
17
|
await config.setTheme(newTheme);
|
|
18
18
|
|
|
19
|
-
const style = document.
|
|
20
|
-
const varsFound = style && style.
|
|
19
|
+
const style = document.adoptedStyleSheets.find(sh => sh._ui5StyleId === "data-ui5-theme-properties|@ui5/webcomponents-base-test").cssRules[0].cssText;
|
|
20
|
+
const varsFound = style && style.includes(var1);
|
|
21
21
|
done(varsFound);
|
|
22
22
|
}, newTheme);
|
|
23
23
|
|
|
@@ -8,8 +8,8 @@ describe("Theming works", () => {
|
|
|
8
8
|
it("Tests that the parameters for the default theme are embedded on boot", async () => {
|
|
9
9
|
|
|
10
10
|
const res = await browser.executeAsync(done => {
|
|
11
|
-
const style = document.
|
|
12
|
-
done(style && style.
|
|
11
|
+
const style = document.adoptedStyleSheets.find(sh => sh._ui5StyleId === "data-ui5-theme-properties|@ui5/webcomponents-base-test").cssRules[0].cssText
|
|
12
|
+
done(style && style.includes("--var1: red")); // see test/assets/Themes.js
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
assert.strictEqual(res, true, "The fiori3 vars are found");
|
|
@@ -22,8 +22,8 @@ describe("Theming works", () => {
|
|
|
22
22
|
const config = window['sap-ui-webcomponents-bundle'].configuration;
|
|
23
23
|
await config.setTheme(newTheme);
|
|
24
24
|
|
|
25
|
-
const style = document.
|
|
26
|
-
const varsFound = style && style.
|
|
25
|
+
const style = document.adoptedStyleSheets.find(sh => sh._ui5StyleId === "data-ui5-theme-properties|@ui5/webcomponents-base-test").cssRules[0].cssText
|
|
26
|
+
const varsFound = style && style.includes("--var1: orange"); // see test/assets/Themes.js
|
|
27
27
|
done(varsFound);
|
|
28
28
|
}, newTheme);
|
|
29
29
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { reRenderAllUI5Elements } from "../Render.js";
|
|
2
|
+
import getSharedResource from "../getSharedResource.js";
|
|
2
3
|
import EventProvider from "../EventProvider.js";
|
|
3
4
|
|
|
4
|
-
const eventProvider = new EventProvider();
|
|
5
|
+
const eventProvider = getSharedResource("CustomStyle.eventProvider", new EventProvider());
|
|
5
6
|
const CUSTOM_CSS_CHANGE = "CustomCSSChange";
|
|
6
7
|
|
|
7
8
|
const attachCustomCSSChange = listener => {
|
|
@@ -16,14 +17,33 @@ const fireCustomCSSChange = tag => {
|
|
|
16
17
|
return eventProvider.fireEvent(CUSTOM_CSS_CHANGE, tag);
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
const customCSSFor = {};
|
|
20
|
+
const customCSSFor = getSharedResource("CustomStyle.customCSSFor", {});
|
|
21
|
+
|
|
22
|
+
// Listen to the eventProvider, in case other copies of this CustomStyle module fire this
|
|
23
|
+
// event, and this copy would therefore need to reRender the ui5 webcomponents; but
|
|
24
|
+
// don't reRender if it was this copy that fired the event to begin with.
|
|
25
|
+
let skipRerender;
|
|
26
|
+
attachCustomCSSChange(tag => {
|
|
27
|
+
if (!skipRerender) {
|
|
28
|
+
reRenderAllUI5Elements({ tag });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
20
31
|
|
|
21
32
|
const addCustomCSS = (tag, css) => {
|
|
22
33
|
if (!customCSSFor[tag]) {
|
|
23
34
|
customCSSFor[tag] = [];
|
|
24
35
|
}
|
|
25
36
|
customCSSFor[tag].push(css);
|
|
26
|
-
|
|
37
|
+
|
|
38
|
+
skipRerender = true;
|
|
39
|
+
try {
|
|
40
|
+
// The event is fired and the attached event listeners are all called synchronously
|
|
41
|
+
// The skipRerender flag will be used to avoid calling reRenderAllUI5Elements twice when it is this copy
|
|
42
|
+
// of CustomStyle.js which is firing the `CustomCSSChange` event.
|
|
43
|
+
fireCustomCSSChange(tag);
|
|
44
|
+
} finally {
|
|
45
|
+
skipRerender = false;
|
|
46
|
+
}
|
|
27
47
|
|
|
28
48
|
return reRenderAllUI5Elements({ tag });
|
|
29
49
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getThemeProperties, getRegisteredPackages, isThemeRegistered } from "../asset-registries/Themes.js";
|
|
2
|
-
import
|
|
2
|
+
import { removeStyle, createOrUpdateStyle } from "../ManagedStyles.js";
|
|
3
3
|
import getThemeDesignerTheme from "./getThemeDesignerTheme.js";
|
|
4
4
|
import { fireThemeLoaded } from "./ThemeLoaded.js";
|
|
5
5
|
import { getFeature } from "../FeaturesRegistry.js";
|
|
6
6
|
|
|
7
|
-
const BASE_THEME_PACKAGE = "@ui5/webcomponents-
|
|
7
|
+
const BASE_THEME_PACKAGE = "@ui5/webcomponents-theming";
|
|
8
8
|
|
|
9
9
|
const isThemeBaseRegistered = () => {
|
|
10
10
|
const registeredPackages = getRegisteredPackages();
|
|
@@ -16,15 +16,14 @@ const loadThemeBase = async theme => {
|
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const cssData = await getThemeProperties(BASE_THEME_PACKAGE, theme);
|
|
20
|
+
if (cssData) {
|
|
21
|
+
createOrUpdateStyle(cssData, "data-ui5-theme-properties", BASE_THEME_PACKAGE);
|
|
22
|
+
}
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
const deleteThemeBase = () => {
|
|
24
|
-
|
|
25
|
-
if (styleElement) {
|
|
26
|
-
styleElement.parentElement.removeChild(styleElement);
|
|
27
|
-
}
|
|
26
|
+
removeStyle("data-ui5-theme-properties", BASE_THEME_PACKAGE);
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
const loadComponentPackages = async theme => {
|
|
@@ -34,8 +33,10 @@ const loadComponentPackages = async theme => {
|
|
|
34
33
|
return;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
const
|
|
38
|
-
|
|
36
|
+
const cssData = await getThemeProperties(packageName, theme);
|
|
37
|
+
if (cssData) {
|
|
38
|
+
createOrUpdateStyle(cssData, "data-ui5-theme-properties", packageName);
|
|
39
|
+
}
|
|
39
40
|
});
|
|
40
41
|
};
|
|
41
42
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getUrl } from "../CSP.js";
|
|
2
|
+
|
|
3
|
+
const flatten = arr => {
|
|
4
|
+
return arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), []);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const getEffectiveLinksHrefs = (ElementClass, forStaticArea = false) => {
|
|
8
|
+
let stylesData = ElementClass[forStaticArea ? "staticAreaStyles" : "styles"];
|
|
9
|
+
if (!stylesData) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!Array.isArray(stylesData)) {
|
|
14
|
+
stylesData = [stylesData];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return flatten(stylesData).filter(data => !!data).map(data => getUrl(data.packageName, data.fileName));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default getEffectiveLinksHrefs;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const getStylesString = styles => {
|
|
2
2
|
if (Array.isArray(styles)) {
|
|
3
|
-
return flatten(styles.filter(style => !!style)).
|
|
3
|
+
return flatten(styles.filter(style => !!style)).map(style => {
|
|
4
|
+
return typeof style === "string" ? style : style.content;
|
|
5
|
+
}).join(" ");
|
|
4
6
|
}
|
|
5
7
|
|
|
6
|
-
return styles;
|
|
8
|
+
return typeof styles === "string" ? styles : styles.content;
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
const flatten = arr => {
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
+
const warnings = new Set();
|
|
2
|
+
|
|
1
3
|
const getThemeMetadata = () => {
|
|
2
4
|
// Check if the class was already applied, most commonly to the link/style tag with the CSS Variables
|
|
3
|
-
let el = document.querySelector(".sapThemeMetaData-Base-baseLib");
|
|
5
|
+
let el = document.querySelector(".sapThemeMetaData-Base-baseLib") || document.querySelector(".sapThemeMetaData-UI5-sap-ui-core");
|
|
4
6
|
if (el) {
|
|
5
7
|
return getComputedStyle(el).backgroundImage;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
el = document.createElement("span");
|
|
9
11
|
el.style.display = "none";
|
|
12
|
+
|
|
13
|
+
// Try with sapThemeMetaData-Base-baseLib first
|
|
10
14
|
el.classList.add("sapThemeMetaData-Base-baseLib");
|
|
11
15
|
document.body.appendChild(el);
|
|
12
|
-
|
|
16
|
+
let metadata = getComputedStyle(el).backgroundImage;
|
|
17
|
+
|
|
18
|
+
// Try with sapThemeMetaData-UI5-sap-ui-core only if the previous selector was not found
|
|
19
|
+
if (metadata === "none") {
|
|
20
|
+
el.classList.add("sapThemeMetaData-UI5-sap-ui-core");
|
|
21
|
+
metadata = getComputedStyle(el).backgroundImage;
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
document.body.removeChild(el);
|
|
14
25
|
|
|
15
26
|
return metadata;
|
|
@@ -24,14 +35,20 @@ const parseThemeMetadata = metadataString => {
|
|
|
24
35
|
try {
|
|
25
36
|
paramsString = decodeURIComponent(paramsString);
|
|
26
37
|
} catch (ex) {
|
|
27
|
-
|
|
38
|
+
if (!warnings.has("decode")) {
|
|
39
|
+
console.warn("Malformed theme metadata string, unable to decodeURIComponent"); // eslint-disable-line
|
|
40
|
+
warnings.add("decode");
|
|
41
|
+
}
|
|
28
42
|
return;
|
|
29
43
|
}
|
|
30
44
|
}
|
|
31
45
|
try {
|
|
32
46
|
return JSON.parse(paramsString);
|
|
33
47
|
} catch (ex) {
|
|
34
|
-
|
|
48
|
+
if (!warnings.has("parse")) {
|
|
49
|
+
console.warn("Malformed theme metadata string, unable to parse JSON"); // eslint-disable-line
|
|
50
|
+
warnings.add("parse");
|
|
51
|
+
}
|
|
35
52
|
}
|
|
36
53
|
}
|
|
37
54
|
};
|
|
@@ -44,7 +61,10 @@ const processThemeMetadata = metadata => {
|
|
|
44
61
|
themeName = metadata.Path.match(/\.([^.]+)\.css_variables$/)[1];
|
|
45
62
|
baseThemeName = metadata.Extends[0];
|
|
46
63
|
} catch (ex) {
|
|
47
|
-
|
|
64
|
+
if (!warnings.has("object")) {
|
|
65
|
+
console.warn("Malformed theme metadata Object", metadata); // eslint-disable-line
|
|
66
|
+
warnings.add("object");
|
|
67
|
+
}
|
|
48
68
|
return;
|
|
49
69
|
}
|
|
50
70
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import getEffectiveLinksHrefs from "./getEffectiveLinksHrefs.js";
|
|
2
|
+
import createLinkInHead from "../util/createLinkInHead.js";
|
|
3
|
+
import { shouldUseLinks, shouldPreloadLinks } from "../CSP.js";
|
|
4
|
+
|
|
5
|
+
const preloaded = new Set();
|
|
6
|
+
|
|
7
|
+
const preloadLinks = ElementClass => {
|
|
8
|
+
if (!shouldUseLinks() || !shouldPreloadLinks()) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const linksHrefs = getEffectiveLinksHrefs(ElementClass, false) || [];
|
|
13
|
+
const staticAreaLinksHrefs = getEffectiveLinksHrefs(ElementClass, true) || [];
|
|
14
|
+
|
|
15
|
+
[...linksHrefs, ...staticAreaLinksHrefs].forEach(href => {
|
|
16
|
+
if (!preloaded.has(href)) {
|
|
17
|
+
createLinkInHead(href, { rel: "preload", as: "style" });
|
|
18
|
+
preloaded.add(href);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default preloadLinks;
|
package/dist/updateShadowRoot.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import executeTemplate from "./renderer/executeTemplate.js";
|
|
2
2
|
import getConstructableStyle from "./theming/getConstructableStyle.js";
|
|
3
3
|
import getEffectiveStyle from "./theming/getEffectiveStyle.js";
|
|
4
|
+
import getEffectiveLinksHrefs from "./theming/getEffectiveLinksHrefs.js";
|
|
4
5
|
import isLegacyBrowser from "./isLegacyBrowser.js";
|
|
6
|
+
import { shouldUseLinks } from "./CSP.js";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Updates the shadow root of a UI5Element or its static area item
|
|
@@ -9,18 +11,20 @@ import isLegacyBrowser from "./isLegacyBrowser.js";
|
|
|
9
11
|
* @param forStaticArea
|
|
10
12
|
*/
|
|
11
13
|
const updateShadowRoot = (element, forStaticArea = false) => {
|
|
12
|
-
let
|
|
14
|
+
let styleStrOrHrefsArr;
|
|
13
15
|
const template = forStaticArea ? "staticAreaTemplate" : "template";
|
|
14
16
|
const shadowRoot = forStaticArea ? element.staticAreaItem.shadowRoot : element.shadowRoot;
|
|
15
17
|
const renderResult = executeTemplate(element.constructor[template], element);
|
|
16
18
|
|
|
17
|
-
if (
|
|
19
|
+
if (shouldUseLinks()) {
|
|
20
|
+
styleStrOrHrefsArr = getEffectiveLinksHrefs(element.constructor, forStaticArea);
|
|
21
|
+
} else if (document.adoptedStyleSheets) { // Chrome
|
|
18
22
|
shadowRoot.adoptedStyleSheets = getConstructableStyle(element.constructor, forStaticArea);
|
|
19
23
|
} else if (!isLegacyBrowser()) { // FF, Safari
|
|
20
|
-
|
|
24
|
+
styleStrOrHrefsArr = getEffectiveStyle(element.constructor, forStaticArea);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
element.constructor.render(renderResult, shadowRoot,
|
|
27
|
+
element.constructor.render(renderResult, shadowRoot, styleStrOrHrefsArr, { host: element });
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
export default updateShadowRoot;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a <link> tag in the <head> tag
|
|
3
|
+
* @param href - the CSS
|
|
4
|
+
* @param attributes - optional attributes to add to the tag
|
|
5
|
+
* @returns {HTMLElement}
|
|
6
|
+
*/
|
|
7
|
+
const createLinkInHead = (href, attributes = {}) => {
|
|
8
|
+
const link = document.createElement("link");
|
|
9
|
+
link.type = "text/css";
|
|
10
|
+
link.rel = "stylesheet";
|
|
11
|
+
|
|
12
|
+
Object.entries(attributes).forEach(pair => link.setAttribute(...pair));
|
|
13
|
+
|
|
14
|
+
link.href = href;
|
|
15
|
+
document.head.appendChild(link);
|
|
16
|
+
return link;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default createLinkInHead;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape a regular expression text so that it can be used in a regular expression.
|
|
3
|
+
* @param {string} text The string to be interpreted literally
|
|
4
|
+
* @returns Regular expression string to pass to regex
|
|
5
|
+
*/
|
|
6
|
+
function escapeRegex(text) {
|
|
7
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default escapeRegex;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import escapeRegex from "./escapeRegex.js";
|
|
2
|
+
import encodeXML from "../sap/base/security/encodeXML.js";
|
|
3
|
+
|
|
4
|
+
// utility to replace all occurances of a string
|
|
5
|
+
function replaceAll(text, find, replace, caseInsensitive) {
|
|
6
|
+
return text.replace(new RegExp(escapeRegex(find), `${caseInsensitive ? "i" : ""}g`), replace);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generate markup for a raw string where a particular text is wrapped with some tag, by default `<b>` (bold) tag.
|
|
11
|
+
* All inputs to this function are considered literal text, and special characters will always be escaped.
|
|
12
|
+
* @param {string} text The text to add highlighting to
|
|
13
|
+
* @param {string} textToHighlight The text which should be highlighted
|
|
14
|
+
* @return {string} the markup HTML which contains all occurrances of the input text surrounded with a `<b>` tag.
|
|
15
|
+
*/
|
|
16
|
+
function generateHighlightedMarkup(text, textToHighlight) {
|
|
17
|
+
if (!text || !textToHighlight) {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
// a token is some string that does not appear in either of the input strings
|
|
21
|
+
// repeat the token until it does not appear in the string
|
|
22
|
+
const makeToken = t => {
|
|
23
|
+
const [s, e] = t.split("");
|
|
24
|
+
while (text.indexOf(t) >= 0 || textToHighlight.indexOf(t) >= 0) {
|
|
25
|
+
t = `${s}${t}${e}`;
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
};
|
|
29
|
+
// It doesn't matter what characters are used as long as all 4 of them are unique
|
|
30
|
+
// And also that encodeXML will not change these characters
|
|
31
|
+
const openToken = makeToken("12");
|
|
32
|
+
const closeToken = makeToken("34");
|
|
33
|
+
// wrap every occurance of the textToHighlight using the open/close tokens (instead of markup at this point)
|
|
34
|
+
let result = encodeXML(replaceAll(text, textToHighlight, match => `${openToken}${match}${closeToken}`, true));
|
|
35
|
+
// now replace the open and close tokens with the markup that we expect
|
|
36
|
+
[[openToken, "<b>"], [closeToken, "</b>"]].forEach(([find, replace]) => {
|
|
37
|
+
result = replaceAll(result, find, replace);
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default generateHighlightedMarkup;
|
package/hash.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
aKxGk3Y/6U1RbreNR+5xid2EcC0=
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const mkdirp = require('mkdirp');
|
|
4
|
+
const CleanCSS = require('clean-css');
|
|
5
|
+
|
|
6
|
+
mkdirp.sync("dist/generated/css/");
|
|
7
|
+
fs.readdirSync("src/css/").filter(file => file.endsWith(".css")).forEach(file => {
|
|
8
|
+
let content = fs.readFileSync(path.join("src/css/", file));
|
|
9
|
+
const res = new CleanCSS().minify(`${content}`);
|
|
10
|
+
content = `export default {
|
|
11
|
+
packageName: "@ui5/webcomponents-base",
|
|
12
|
+
fileName: "${file}",
|
|
13
|
+
content: \`${res.styles}\`
|
|
14
|
+
};`;
|
|
15
|
+
|
|
16
|
+
fs.writeFileSync(path.join("dist/generated/css/", `${file}.js`), content);
|
|
17
|
+
});
|
|
18
|
+
|
package/package-scripts.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const resolve = require("resolve");
|
|
2
2
|
|
|
3
3
|
const assetParametersScript = resolve.sync("@ui5/webcomponents-base/lib/generate-asset-parameters/index.js");
|
|
4
|
+
const stylesScript = resolve.sync("@ui5/webcomponents-base/lib/generate-styles/index.js");
|
|
4
5
|
const serve = resolve.sync("@ui5/webcomponents-tools/lib/serve/index.js");
|
|
5
6
|
const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
|
|
6
7
|
const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
|
|
@@ -12,7 +13,7 @@ const UP_TO_DATE = `node "${hashIsUpToDate}" dist/ hash.txt && echo "Up to date.
|
|
|
12
13
|
const scripts = {
|
|
13
14
|
clean: "rimraf dist && rimraf .port",
|
|
14
15
|
lint: "eslint . --config config/.eslintrc.js",
|
|
15
|
-
prepare: "nps clean integrate copy generateAssetParameters",
|
|
16
|
+
prepare: "nps clean integrate copy generateAssetParameters generateStyles",
|
|
16
17
|
integrate: {
|
|
17
18
|
default: "nps integrate.copy-used-modules integrate.copy-overlay integrate.replace-amd integrate.replace-export-true integrate.replace-export-false integrate.amd-to-es6 integrate.replace-global-core-usage integrate.esm-abs-to-rel integrate.third-party",
|
|
18
19
|
"copy-used-modules": `node "${copyUsedModules}" ./used-modules.txt dist/`,
|
|
@@ -35,15 +36,17 @@ const scripts = {
|
|
|
35
36
|
},
|
|
36
37
|
copy: {
|
|
37
38
|
default: "nps copy.src copy.test",
|
|
38
|
-
src: `copy-and-watch "src/**/*.js" dist/`,
|
|
39
|
+
src: `copy-and-watch "src/**/*.{js,css}" dist/`,
|
|
39
40
|
test: `copy-and-watch "test/**/*.*" dist/test-resources`,
|
|
40
41
|
},
|
|
41
42
|
generateAssetParameters: `node "${assetParametersScript}"`,
|
|
43
|
+
generateStyles: `node "${stylesScript}"`,
|
|
42
44
|
watch: {
|
|
43
|
-
default: 'concurrently "nps watch.test" "nps watch.src" "nps watch.bundle"',
|
|
45
|
+
default: 'concurrently "nps watch.test" "nps watch.src" "nps watch.bundle" "nps watch.styles"',
|
|
44
46
|
src: 'nps "copy.src --watch --skip-initial-copy"',
|
|
45
47
|
test: 'nps "copy.test --watch --skip-initial-copy"',
|
|
46
48
|
bundle: "rollup --config config/rollup.config.js -w --environment DEV",
|
|
49
|
+
styles: 'chokidar "src/css/*.css" -c "nps generateStyles"'
|
|
47
50
|
},
|
|
48
51
|
dev: 'concurrently "nps serve" "nps watch"',
|
|
49
52
|
start: "nps prepare dev",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/webcomponents-base",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-1e08ebdef",
|
|
4
4
|
"description": "UI5 Web Components: webcomponents.base",
|
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,19 +32,18 @@
|
|
|
32
32
|
"prepublishOnly": "npm run clean && npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"
|
|
35
|
+
"focus-visible": "^5.2.0",
|
|
36
|
+
"lit-html": "2.0.1"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@buxlabs/amd-to-es6": "0.16.1",
|
|
39
40
|
"@openui5/sap.ui.core": "1.94.0",
|
|
40
|
-
"@ui5/webcomponents-tools": "0.0.0-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"@ui5/webcomponents-tools": "0.0.0-1e08ebdef",
|
|
42
|
+
"chromedriver": "96.0.0",
|
|
43
|
+
"clean-css": "^5.2.2",
|
|
43
44
|
"copy-and-watch": "^0.1.5",
|
|
44
45
|
"eslint": "^7.22.0",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"path-exists-cli": "^2.0.0",
|
|
48
|
-
"replace-in-file": "^6.2.0"
|
|
46
|
+
"mkdirp": "^1.0.4",
|
|
47
|
+
"resolve": "^1.20.0"
|
|
49
48
|
}
|
|
50
49
|
}
|
package/src/CSP.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const roots = new Map();
|
|
2
|
+
let useLinks = false;
|
|
3
|
+
let preloadLinks = true;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use this function to provide the path to the directory where the css resources for the given package will be served from
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
* @param packageName name of the package that is being configured
|
|
10
|
+
* @param root path, accessible by the server that will serve the css resources
|
|
11
|
+
*/
|
|
12
|
+
const setPackageCSSRoot = (packageName, root) => {
|
|
13
|
+
roots.set(packageName, root);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getUrl = (packageName, path) => {
|
|
17
|
+
return `${roots.get(packageName)}${path}`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Call this function to enable or disable the usage of <link> tags instead of <style> tags to achieve CSP compliance
|
|
22
|
+
* Example: "setUseLinks(true)" will unconditionally use <link> tags for all browsers;
|
|
23
|
+
* Example: "setUseLinks(!document.adoptedStyleSheets) will only enable the usage of <link> tags for browsers that do not support constructable stylesheets.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
* @param use whether links will be used
|
|
27
|
+
*/
|
|
28
|
+
const setUseLinks = use => {
|
|
29
|
+
useLinks = use;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Call this function to enable or disable the preloading of <link> tags.
|
|
34
|
+
* Note: only taken into account when <link> tags are being used.
|
|
35
|
+
* Note: links are being preloaded by default, so call "setPreloadLinks(false)" to opt out of this.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
* @param preload
|
|
39
|
+
*/
|
|
40
|
+
const setPreloadLinks = preload => {
|
|
41
|
+
preloadLinks = preload;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const shouldUseLinks = () => {
|
|
45
|
+
return useLinks;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const shouldPreloadLinks = () => {
|
|
49
|
+
return preloadLinks;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
setPackageCSSRoot,
|
|
54
|
+
getUrl,
|
|
55
|
+
setUseLinks,
|
|
56
|
+
setPreloadLinks,
|
|
57
|
+
shouldUseLinks,
|
|
58
|
+
shouldPreloadLinks,
|
|
59
|
+
};
|
package/src/Device.js
CHANGED
|
@@ -5,6 +5,7 @@ const chrome = !ie && /(Chrome|CriOS)/.test(ua);
|
|
|
5
5
|
const safari = !ie && !chrome && /(Version|PhantomJS)\/(\d+\.\d+).*Safari/.test(ua);
|
|
6
6
|
const webkit = !ie && /webkit/.test(ua);
|
|
7
7
|
const windows = navigator.platform.indexOf("Win") !== -1;
|
|
8
|
+
const iOS = navigator.platform.match(/iPhone|iPad|iPod/) || (navigator.userAgent.match(/Mac/) && "ontouchend" in document);
|
|
8
9
|
const android = !windows && /Android/.test(ua);
|
|
9
10
|
const androidPhone = android && /(?=android)(?=.*mobile)/i.test(ua);
|
|
10
11
|
const ipad = /ipad/i.test(ua);
|
|
@@ -91,6 +92,14 @@ const isDesktop = () => {
|
|
|
91
92
|
return (!isTablet() && !isPhone()) || isWindows8OrAbove();
|
|
92
93
|
};
|
|
93
94
|
|
|
95
|
+
const isCombi = () => {
|
|
96
|
+
return isTablet() && isDesktop();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const isIOS = () => {
|
|
100
|
+
return iOS;
|
|
101
|
+
};
|
|
102
|
+
|
|
94
103
|
export {
|
|
95
104
|
supportsTouch,
|
|
96
105
|
isIE,
|
|
@@ -99,4 +108,6 @@ export {
|
|
|
99
108
|
isPhone,
|
|
100
109
|
isTablet,
|
|
101
110
|
isDesktop,
|
|
111
|
+
isCombi,
|
|
112
|
+
isIOS,
|
|
102
113
|
};
|