@social-mail/social-mail-web-server 1.7.480 → 1.7.481
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/dist/server/seed/ui/seed-ui.js +2 -2
- package/dist/server/services/files/web-content/DynamicStyles.d.ts +12 -0
- package/dist/server/services/files/web-content/DynamicStyles.d.ts.map +1 -0
- package/dist/server/services/files/web-content/DynamicStyles.js +102 -0
- package/dist/server/services/files/web-content/DynamicStyles.js.map +1 -0
- package/dist/server/services/files/web-content/WebContentTranspileService.d.ts.map +1 -1
- package/dist/server/services/files/web-content/WebContentTranspileService.js +3 -3
- package/dist/server/services/files/web-content/WebContentTranspileService.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/server/seed/ui/seed-ui.ts +2 -2
- package/src/server/services/files/web-content/DynamicStyles.ts +117 -0
- package/src/server/services/files/web-content/WebContentTranspileService.ts +4 -3
package/package.json
CHANGED
|
@@ -5,13 +5,13 @@ export default async function seedUI(config: DBConfig) {
|
|
|
5
5
|
await config.saveVersion(UIPackageConfig, {
|
|
6
6
|
package: "@social-mail/social-mail-client",
|
|
7
7
|
view: "dist/web/AppIndex",
|
|
8
|
-
version: "1.8.
|
|
8
|
+
version: "1.8.50"
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
await config.saveVersion(WebComponentsPackageConfig, {
|
|
12
12
|
package: "@social-mail/web-components",
|
|
13
13
|
view: "dist/index.js",
|
|
14
|
-
version: "1.0.
|
|
14
|
+
version: "1.0.258"
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
await config.saveVersion(FAFreePackageConfig, {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-base-to-string */
|
|
2
|
+
import { DOMWindow } from "jsdom";
|
|
3
|
+
|
|
4
|
+
const keyFrameAttributes = [
|
|
5
|
+
'styler-on-enter',
|
|
6
|
+
'styler-on-enter-effect-1',
|
|
7
|
+
'styler-on-enter-effect-2',
|
|
8
|
+
'styler-on-hover',
|
|
9
|
+
'styler-on-hover-effect-1',
|
|
10
|
+
'styler-on-hover-effect-2',
|
|
11
|
+
'styler-on-leave',
|
|
12
|
+
'styler-on-leave-effect-1',
|
|
13
|
+
'styler-on-leave-effect-2',
|
|
14
|
+
'styler-on-scroll',
|
|
15
|
+
'styler-on-scroll-effect-1',
|
|
16
|
+
'styler-on-scroll-effect-2',
|
|
17
|
+
'styler-on-scroll-above',
|
|
18
|
+
'styler-on-scroll-above-effect-1',
|
|
19
|
+
'styler-on-scroll-above-effect-2',
|
|
20
|
+
'styler-on-scroll-top-half',
|
|
21
|
+
'styler-on-scroll-top-half-effect-1',
|
|
22
|
+
'styler-on-scroll-top-half-effect-2',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export default class DynamicStyles {
|
|
26
|
+
|
|
27
|
+
private added: Set<string>;
|
|
28
|
+
private readonly style: HTMLStyleElement;
|
|
29
|
+
private aId: number;
|
|
30
|
+
private animations = new Map<string, { id: string, defaults: [string,string][] }>();
|
|
31
|
+
|
|
32
|
+
constructor(private readonly win: DOMWindow) {
|
|
33
|
+
|
|
34
|
+
this.style = win.document.createElement("style");
|
|
35
|
+
this.added = new Set<string>();
|
|
36
|
+
win.document.head.appendChild(this.style);
|
|
37
|
+
this.aId = 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setAttribute(e: Element, a, value: string) {
|
|
41
|
+
if (!value) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
value = value.trim();
|
|
45
|
+
const key = `[${a}=${this.win.CSS.escape(value)}]`;
|
|
46
|
+
if (keyFrameAttributes.includes(a)) {
|
|
47
|
+
|
|
48
|
+
// replace with animation...
|
|
49
|
+
if (/[\{]/.test(value)) {
|
|
50
|
+
value = this.setAnimation(e, a, value);
|
|
51
|
+
if (!value) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (value === "custom") {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (this.added.has(key)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.added.add(key);
|
|
63
|
+
this.style.append(`
|
|
64
|
+
[${key}] {
|
|
65
|
+
--${a}: ${value};
|
|
66
|
+
}
|
|
67
|
+
`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setAnimation(e: Element, a: any, value: string) {
|
|
71
|
+
try {
|
|
72
|
+
const animationObj = JSON.parse(value);
|
|
73
|
+
|
|
74
|
+
const minJson = JSON.stringify(animationObj);
|
|
75
|
+
|
|
76
|
+
let v = this.animations.get(minJson);
|
|
77
|
+
if (!v) {
|
|
78
|
+
|
|
79
|
+
const frames = animationObj.keyframes ?? animationObj.keyFrames;
|
|
80
|
+
if (!frames || !Array.isArray(frames)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const total = frames.length;
|
|
84
|
+
let i = 0;
|
|
85
|
+
for (const frame of frames) {
|
|
86
|
+
frame.attributes = { ... frame };
|
|
87
|
+
delete frame.attributes.offset;
|
|
88
|
+
frame.offset ??= i === 0 ? 0 : i === total - 1 ? 1 : i / (total - 1);
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
const defaults = Object.entries(frames[0].attributes) as [string,string][];
|
|
92
|
+
v = { id: `internal-style-generated-${animationObj.title}-${this.aId++}`, defaults };
|
|
93
|
+
this.animations.set(minJson, v);
|
|
94
|
+
let styleText = `@keyframes ${v.id} {
|
|
95
|
+
${frames.map((f) => `${Math.floor(f.offset * 100)}% {
|
|
96
|
+
${Object.entries(f.attributes).map(([k,v1]) => `${k}: ${v1};`).join("\n")}
|
|
97
|
+
}`).join("\n")}
|
|
98
|
+
}`;
|
|
99
|
+
|
|
100
|
+
this.style.append(styleText);
|
|
101
|
+
|
|
102
|
+
if (a.startsWith("styler-on-enter")) {
|
|
103
|
+
// set defaults...
|
|
104
|
+
styleText = `:not(animated-text):not([styler-entered])[${a}=${CSS.escape(value)}],
|
|
105
|
+
animated-text:not([styler-entered])[${a}=${CSS.escape(value)}] > * {
|
|
106
|
+
${defaults.map(([k,v1]) => `${k}: ${v1};`).join("\t\n")}
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
this.style.append(styleText);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return v.id;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error(error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -13,6 +13,7 @@ import { globalEnv } from "../../../../common/globalEnv.js";
|
|
|
13
13
|
import EncryptionService from "../../encryption/EncryptionService.js";
|
|
14
14
|
import { ISiteFolder } from "../ISiteFolder.js";
|
|
15
15
|
import WebUrl from "./WebUrl.js";
|
|
16
|
+
import DynamicStyles from "./DynamicStyles.js";
|
|
16
17
|
|
|
17
18
|
const updateAttribute = (root: string, name: string, element: Element) => {
|
|
18
19
|
const value = element.getAttribute(name);
|
|
@@ -61,6 +62,8 @@ export default class WebContentTranspileService
|
|
|
61
62
|
await this.injectFragment(siteFolder, e as HTMLElement, document, currentPath);
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
const ds = new DynamicStyles(browser.window);
|
|
66
|
+
|
|
64
67
|
for (const node of descendentElementIterator(document.documentElement)) {
|
|
65
68
|
switch(node.nodeName) {
|
|
66
69
|
case "SCRIPT":
|
|
@@ -86,9 +89,7 @@ export default class WebContentTranspileService
|
|
|
86
89
|
for(const attributeName of node.getAttributeNames()) {
|
|
87
90
|
if(attributeName.startsWith("styler-")) {
|
|
88
91
|
const av = node.getAttribute(attributeName);
|
|
89
|
-
|
|
90
|
-
style.setProperty(`--${attributeName}`, node.getAttribute(attributeName));
|
|
91
|
-
}
|
|
92
|
+
ds.setAttribute(node, attributeName, av);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
}
|