@social-mail/social-mail-client 1.9.115 → 1.9.116

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/css-for-email.js CHANGED
@@ -1,83 +1,121 @@
1
- const { currentScript } = document;
2
-
3
- async function flattenStyleSheets() {
4
- const styleSheets = document.querySelectorAll(`link[rel="stylesheet"]`);
5
- const tasks = [];
6
- for(let i=0;i<styleSheets.length;i++) {
7
- const styleSheet = styleSheets[i];
8
- const href = styleSheet.getAttribute("href");
9
- tasks.push(fetch(href)
10
- .then((x) => x.text())
11
- .then((text) => ({ styleSheet, text }))
12
- )
1
+ (function(){
2
+ const { currentScript } = document;
3
+
4
+ let id = Date.now();
5
+
6
+ async function flattenStyleSheets() {
7
+ const styleSheets = document.querySelectorAll(`link[rel="stylesheet"]`);
8
+ const tasks = [];
9
+ for(let i=0;i<styleSheets.length;i++) {
10
+ const styleSheet = styleSheets[i];
11
+ const href = styleSheet.getAttribute("href");
12
+ tasks.push(fetch(href)
13
+ .then((x) => x.text())
14
+ .then((text) => ({ styleSheet, text }))
15
+ )
16
+ }
17
+
18
+ const remove = [];
19
+
20
+ const results = await Promise.all(tasks);
21
+ for(const { styleSheet, text} of results) {
22
+ const style = document.createElement("style");
23
+ style.textContent = text;
24
+ document.head.appendChild(style);
25
+ remove.push(styleSheet);
26
+ remove.push(style);
27
+ }
28
+
29
+ return () => remove.forEach((x)=>x.remove());
13
30
  }
14
31
 
15
- const results = await Promise.all(tasks);
16
- for(const { styleSheet, text} of results) {
17
- const style = document.createElement("style");
18
- style.textContent = text;
19
- document.head.appendChild(style);
20
- styleSheet.remove();
32
+ function css(el) {
33
+ const cs = window.getComputedStyle(el);
34
+ var sheets = document.styleSheets, ret = [];
35
+ el.matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector
36
+ || el.msMatchesSelector || el.oMatchesSelector;
37
+ for (var i in sheets) {
38
+ const sheet = sheets[i];
39
+ try {
40
+ var rules = sheet.cssRules;
41
+ for (var r in rules) {
42
+ const rule = rules[r];
43
+ if (el.matches(rule.selectorText)) {
44
+ const { style } = rule;
45
+ const properties = [];
46
+ for(let n=0;n<style.length;n++) {
47
+ const key = style[n];
48
+ if (key === "box-sizing") {
49
+ continue;
50
+ }
51
+ let value = style[key];
52
+ if (value) {
53
+ // we need to evaluate every var(--)
54
+ value = value.replace(/(var\(([^\)]+)\))/gm, (m, p1, p2) => {
55
+ const cssValue = cs.getPropertyValue(p2.split(",")[0]);
56
+ return p1 ? cssValue : m;
57
+ });
58
+ properties.push({ key, value });
59
+ }
60
+ }
61
+ ret.push(...properties);
62
+ }
63
+ }
64
+ } catch {
65
+
66
+ }
67
+ }
68
+ return ret;
21
69
  }
22
- }
23
70
 
24
- const te = new TextEncoder();
71
+ async function flattenStyler(rules) {
25
72
 
26
- function encodeTo36(text) {
27
- const c = window.btoa(text);
28
- return "c_" + c.replaceAll("=", "_");
29
- }
73
+ const replaceList = [];
30
74
 
31
- async function flattenStyler() {
75
+ const all = document.querySelectorAll(":not(head) > *:not(style,head)");
76
+ for(let i=0;i<all.length;i++) {
77
+ const e = all[i];
32
78
 
33
- const replaceList = [];
79
+ const remove = [];
34
80
 
35
- const all = document.body.querySelectorAll("*:not(style)");
36
- for(let i=0;i<all.length;i++) {
37
- const e = all[i];
81
+ for(const name of e.getAttributeNames()) {
82
+ if (!name.startsWith("styler-")) {
83
+ continue;
84
+ }
85
+ remove.push(name);
86
+ }
38
87
 
39
- const remove = [];
88
+ const styles = css(e);
40
89
 
41
- for(const name of e.getAttributeNames()) {
42
- if (!name.startsWith("styler-")) {
43
- continue;
44
- }
45
- const value = e.getAttribute(name);
46
- const cssValue = CSS.escape(value);
47
- const rule = `[${name}=${cssValue}]`;
48
- const className = encodeTo36(rule);
90
+ const className = "c-" + (id++).toString(36);
49
91
  e.classList.add(className);
50
- replaceList.push({ rules: [rule, `[${name}="${cssValue}"]`], className: "." + className});
51
- remove.push(name);
52
- }
53
92
 
54
- for(const n of remove) {
55
- e.removeAttribute(n);
56
- }
57
- }
93
+ rules.push(`.${className} {
94
+ ${styles.map((s) => s.key + ":" + s.value).join(";\n")};
95
+ }`)
58
96
 
59
- const styles = document.querySelectorAll("style");
60
- for(let i=0;i<styles.length;i++) {
61
- const style = styles[i];
62
- const { textContent } = style;
63
- for (const { rules, className } of replaceList) {
64
- let replaced = textContent;
65
- for(const rule of rules) {
66
- replaced = replaced.replaceAll(rule, className);
67
- }
68
- if (replaced !== textContent) {
69
- style.textContent = replaced;
97
+ for(const n of remove) {
98
+ e.removeAttribute(n);
70
99
  }
71
100
  }
72
101
  }
73
- }
74
102
 
75
- (async function() {
103
+ (async function() {
76
104
 
77
- await flattenStyleSheets();
105
+ const defer = await flattenStyleSheets();
78
106
 
79
- await flattenStyler();
107
+ const rules = [];
108
+ await flattenStyler(rules);
109
+
110
+ const style = document.createElement("style");
111
+ document.head.appendChild(style);
112
+ style.textContent = `* { box-sizing: border-box; }\n${rules.join("\n")}`;
113
+
114
+ if (currentScript) {
115
+ currentScript.remove();
116
+ }
80
117
 
81
- currentScript.remove();
118
+ defer();
82
119
 
83
- })().catch(console.error);
120
+ })().catch(console.error);
121
+ })();
@@ -60977,7 +60977,7 @@ System.register(["tslib", "@web-atoms/core/dist/core/InjectProperty", "@web-atom
60977
60977
  icon: "fad fa-globe-pointer",
60978
60978
  text: "View Site"
60979
60979
  }), XNode.create("a", {
60980
- href: Bind.oneWay(() => apiPath(`${this.root.url}${this.cloudFileService.getFilePath(this.root, this.selectedFile)}${this.selectedFile.name}`)),
60980
+ href: Bind.oneWay(() => apiPath(`/social-mail/site/draft-url/${this.root.appFileID}/${this.cloudFileService.getFilePath(this.root, this.selectedFile)}${this.selectedFile.name}`)),
60981
60981
  target: "_blank"
60982
60982
  }, XNode.create(EditIconTextButton, {
60983
60983
  icon: "fad fa-globe-pointer",