@symbo.ls/utils 3.2.3 → 3.14.0
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/LICENSE +25 -12
- package/README.md +106 -0
- package/array.js +162 -0
- package/cache.js +7 -0
- package/cdn.js +83 -0
- package/component.js +25 -0
- package/cookie.js +71 -0
- package/{src/detectHeight.js → detectHeight.js} +3 -3
- package/dist/cjs/array.js +168 -0
- package/dist/cjs/browser.js +0 -2
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/cdn.js +85 -0
- package/dist/cjs/component.js +45 -0
- package/dist/cjs/cookie.js +75 -0
- package/dist/cjs/date.js +1 -3
- package/dist/cjs/detectHeight.js +4 -6
- package/dist/cjs/element.js +136 -0
- package/dist/cjs/env.js +43 -0
- package/dist/cjs/events.js +39 -0
- package/dist/cjs/extends.js +434 -0
- package/dist/cjs/fibonacci.js +1 -3
- package/dist/cjs/files.js +1 -3
- package/dist/cjs/function.js +114 -0
- package/dist/cjs/globals.js +30 -0
- package/dist/cjs/if.js +48 -0
- package/dist/cjs/index.js +38 -425
- package/dist/cjs/key.js +38 -0
- package/dist/cjs/keys.js +201 -0
- package/dist/cjs/load.js +5 -7
- package/dist/cjs/log.js +34 -0
- package/dist/cjs/metadata.js +310 -0
- package/dist/cjs/methods.js +599 -0
- package/dist/cjs/node.js +35 -0
- package/dist/cjs/object.js +634 -0
- package/dist/cjs/projectKeys.js +35 -0
- package/dist/cjs/props.js +282 -0
- package/dist/cjs/scaling.js +5 -169
- package/dist/cjs/scope.js +44 -0
- package/dist/cjs/sharedLibraries.js +146 -0
- package/dist/cjs/state.js +173 -0
- package/dist/cjs/string-extra.js +72 -0
- package/dist/cjs/string.js +183 -0
- package/dist/cjs/style.js +1 -3
- package/dist/cjs/tags.js +220 -0
- package/dist/cjs/triggerEvent.js +112 -0
- package/dist/cjs/types.js +74 -0
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +148 -0
- package/dist/esm/browser.js +14 -0
- package/dist/esm/cache.js +6 -0
- package/dist/esm/cdn.js +65 -0
- package/dist/esm/component.js +25 -0
- package/dist/esm/cookie.js +55 -0
- package/dist/esm/date.js +11 -0
- package/dist/esm/detectHeight.js +42 -0
- package/dist/esm/element.js +116 -0
- package/dist/esm/env.js +23 -0
- package/dist/esm/events.js +19 -0
- package/dist/esm/extends.js +414 -0
- package/dist/esm/fibonacci.js +10 -0
- package/dist/esm/files.js +4 -0
- package/dist/esm/function.js +94 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/if.js +28 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/key.js +18 -0
- package/dist/esm/keys.js +181 -0
- package/dist/esm/load.js +151 -0
- package/dist/esm/log.js +14 -0
- package/dist/esm/metadata.js +290 -0
- package/dist/esm/methods.js +569 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +621 -0
- package/dist/esm/projectKeys.js +16 -0
- package/dist/esm/props.js +262 -0
- package/dist/esm/scaling.js +15 -0
- package/dist/esm/scope.js +24 -0
- package/dist/esm/sharedLibraries.js +126 -0
- package/dist/esm/state.js +163 -0
- package/dist/esm/string-extra.js +52 -0
- package/dist/esm/string.js +163 -0
- package/dist/esm/style.js +20 -0
- package/dist/esm/tags.js +200 -0
- package/dist/esm/triggerEvent.js +92 -0
- package/dist/esm/types.js +54 -0
- package/dist/esm/update.js +22 -0
- package/dist/iife/index.js +5818 -0
- package/element.js +148 -0
- package/env.js +15 -0
- package/events.js +19 -0
- package/extends.js +519 -0
- package/function.js +145 -0
- package/globals.js +8 -0
- package/if.js +30 -0
- package/index.js +41 -0
- package/key.js +20 -0
- package/keys.js +176 -0
- package/log.js +12 -0
- package/metadata.js +392 -0
- package/methods.js +636 -0
- package/node.js +37 -0
- package/object.js +803 -0
- package/package.json +38 -22
- package/projectKeys.js +30 -0
- package/props.js +327 -0
- package/{src/scaling.js → scaling.js} +1 -1
- package/scope.js +32 -0
- package/sharedLibraries.js +184 -0
- package/state.js +203 -0
- package/{src/index.js → string-extra.js} +11 -17
- package/string.js +206 -0
- package/tags.js +176 -0
- package/triggerEvent.js +102 -0
- package/types.js +55 -0
- package/update.js +27 -0
- package/dist/cjs/package.json +0 -4
- /package/{src/browser.js → browser.js} +0 -0
- /package/{src/date.js → date.js} +0 -0
- /package/{src/fibonacci.js → fibonacci.js} +0 -0
- /package/{src/files.js → files.js} +0 -0
- /package/{src/load.js → load.js} +0 -0
- /package/{src/style.js → style.js} +0 -0
package/dist/cjs/keys.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var keys_exports = {};
|
|
20
|
+
__export(keys_exports, {
|
|
21
|
+
DOMQL_EVENTS: () => DOMQL_EVENTS,
|
|
22
|
+
DOMQ_PROPERTIES: () => DOMQ_PROPERTIES,
|
|
23
|
+
METHODS: () => METHODS,
|
|
24
|
+
METHODS_EXL: () => METHODS_EXL,
|
|
25
|
+
PARSED_DOMQ_PROPERTIES: () => PARSED_DOMQ_PROPERTIES,
|
|
26
|
+
PROPS_METHODS: () => PROPS_METHODS,
|
|
27
|
+
STATE_METHODS: () => STATE_METHODS,
|
|
28
|
+
STATE_PROPERTIES: () => STATE_PROPERTIES
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(keys_exports);
|
|
31
|
+
const DOMQ_PROPERTIES = /* @__PURE__ */ new Set([
|
|
32
|
+
"attr",
|
|
33
|
+
"style",
|
|
34
|
+
"text",
|
|
35
|
+
"html",
|
|
36
|
+
"content",
|
|
37
|
+
"data",
|
|
38
|
+
"classlist",
|
|
39
|
+
"state",
|
|
40
|
+
"scope",
|
|
41
|
+
"root",
|
|
42
|
+
"deps",
|
|
43
|
+
"extend",
|
|
44
|
+
"extends",
|
|
45
|
+
"$router",
|
|
46
|
+
"routes",
|
|
47
|
+
"children",
|
|
48
|
+
"childExtend",
|
|
49
|
+
"childExtends",
|
|
50
|
+
"childExtendRecursive",
|
|
51
|
+
"childExtendsRecursive",
|
|
52
|
+
"props",
|
|
53
|
+
"if",
|
|
54
|
+
"define",
|
|
55
|
+
"__name",
|
|
56
|
+
"__ref",
|
|
57
|
+
"__hash",
|
|
58
|
+
"__text",
|
|
59
|
+
"key",
|
|
60
|
+
"tag",
|
|
61
|
+
"query",
|
|
62
|
+
"parent",
|
|
63
|
+
"node",
|
|
64
|
+
"variables",
|
|
65
|
+
"on",
|
|
66
|
+
"fetch",
|
|
67
|
+
"component",
|
|
68
|
+
"context",
|
|
69
|
+
"preventContentUpdate",
|
|
70
|
+
"preventContentRecreate"
|
|
71
|
+
]);
|
|
72
|
+
const PARSED_DOMQ_PROPERTIES = /* @__PURE__ */ new Set([
|
|
73
|
+
"attr",
|
|
74
|
+
"style",
|
|
75
|
+
"text",
|
|
76
|
+
"html",
|
|
77
|
+
"content",
|
|
78
|
+
"data",
|
|
79
|
+
"class",
|
|
80
|
+
"state",
|
|
81
|
+
"scope",
|
|
82
|
+
"children",
|
|
83
|
+
"props",
|
|
84
|
+
"if",
|
|
85
|
+
"key",
|
|
86
|
+
"tag",
|
|
87
|
+
"query",
|
|
88
|
+
"on",
|
|
89
|
+
"context"
|
|
90
|
+
]);
|
|
91
|
+
const STATE_PROPERTIES = [
|
|
92
|
+
"ref",
|
|
93
|
+
"parent",
|
|
94
|
+
"__element",
|
|
95
|
+
"__depends",
|
|
96
|
+
"__ref",
|
|
97
|
+
"__children",
|
|
98
|
+
"root"
|
|
99
|
+
];
|
|
100
|
+
const STATE_METHODS = /* @__PURE__ */ new Set([
|
|
101
|
+
"update",
|
|
102
|
+
"parse",
|
|
103
|
+
"clean",
|
|
104
|
+
"create",
|
|
105
|
+
"destroy",
|
|
106
|
+
"add",
|
|
107
|
+
"toggle",
|
|
108
|
+
"remove",
|
|
109
|
+
"apply",
|
|
110
|
+
"set",
|
|
111
|
+
"reset",
|
|
112
|
+
"replace",
|
|
113
|
+
"quietReplace",
|
|
114
|
+
"quietUpdate",
|
|
115
|
+
"applyReplace",
|
|
116
|
+
"applyFunction",
|
|
117
|
+
"keys",
|
|
118
|
+
"values",
|
|
119
|
+
"ref",
|
|
120
|
+
"rootUpdate",
|
|
121
|
+
"parentUpdate",
|
|
122
|
+
"parent",
|
|
123
|
+
"__element",
|
|
124
|
+
"__depends",
|
|
125
|
+
"__ref",
|
|
126
|
+
"__children",
|
|
127
|
+
"root",
|
|
128
|
+
"setByPath",
|
|
129
|
+
"setPathCollection",
|
|
130
|
+
"removeByPath",
|
|
131
|
+
"removePathCollection",
|
|
132
|
+
"getByPath"
|
|
133
|
+
]);
|
|
134
|
+
const PROPS_METHODS = /* @__PURE__ */ new Set(["update", "__element"]);
|
|
135
|
+
const METHODS = /* @__PURE__ */ new Set([
|
|
136
|
+
"set",
|
|
137
|
+
"reset",
|
|
138
|
+
"update",
|
|
139
|
+
"remove",
|
|
140
|
+
"updateContent",
|
|
141
|
+
"removeContent",
|
|
142
|
+
"lookup",
|
|
143
|
+
"lookdown",
|
|
144
|
+
"lookdownAll",
|
|
145
|
+
"getRef",
|
|
146
|
+
"getPath",
|
|
147
|
+
"setNodeStyles",
|
|
148
|
+
"spotByPath",
|
|
149
|
+
"keys",
|
|
150
|
+
"parse",
|
|
151
|
+
"setProps",
|
|
152
|
+
"parseDeep",
|
|
153
|
+
"variables",
|
|
154
|
+
"if",
|
|
155
|
+
"log",
|
|
156
|
+
"verbose",
|
|
157
|
+
"warn",
|
|
158
|
+
"error",
|
|
159
|
+
"call",
|
|
160
|
+
"nextElement",
|
|
161
|
+
"previousElement",
|
|
162
|
+
"getRootState",
|
|
163
|
+
"getRoot",
|
|
164
|
+
"getRootData",
|
|
165
|
+
"getRootContext",
|
|
166
|
+
"getContext",
|
|
167
|
+
"getQuery",
|
|
168
|
+
"getDB",
|
|
169
|
+
"getChildren",
|
|
170
|
+
"preventContentUpdate",
|
|
171
|
+
"preventContentRecreate"
|
|
172
|
+
]);
|
|
173
|
+
const METHODS_EXL = /* @__PURE__ */ new Set([
|
|
174
|
+
"node",
|
|
175
|
+
"context",
|
|
176
|
+
"extends",
|
|
177
|
+
"__element",
|
|
178
|
+
"__ref",
|
|
179
|
+
...METHODS,
|
|
180
|
+
...STATE_METHODS,
|
|
181
|
+
...PROPS_METHODS
|
|
182
|
+
]);
|
|
183
|
+
const DOMQL_EVENTS = /* @__PURE__ */ new Set([
|
|
184
|
+
"init",
|
|
185
|
+
"beforeClassAssign",
|
|
186
|
+
"render",
|
|
187
|
+
"renderRouter",
|
|
188
|
+
"attachNode",
|
|
189
|
+
"stateInit",
|
|
190
|
+
"stateCreated",
|
|
191
|
+
"beforeStateUpdate",
|
|
192
|
+
"stateUpdate",
|
|
193
|
+
"beforeUpdate",
|
|
194
|
+
"done",
|
|
195
|
+
"create",
|
|
196
|
+
"complete",
|
|
197
|
+
"frame",
|
|
198
|
+
"update",
|
|
199
|
+
"fetchError",
|
|
200
|
+
"fetchComplete"
|
|
201
|
+
]);
|
package/dist/cjs/load.js
CHANGED
|
@@ -16,8 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/load.js
|
|
21
19
|
var load_exports = {};
|
|
22
20
|
__export(load_exports, {
|
|
23
21
|
loadCssFile: () => loadCssFile,
|
|
@@ -29,7 +27,7 @@ __export(load_exports, {
|
|
|
29
27
|
loadRemoteScript: () => loadRemoteScript
|
|
30
28
|
});
|
|
31
29
|
module.exports = __toCommonJS(load_exports);
|
|
32
|
-
|
|
30
|
+
const loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
33
31
|
return new Promise((resolve, reject) => {
|
|
34
32
|
try {
|
|
35
33
|
const scriptEle = doc.createElement("script");
|
|
@@ -55,7 +53,7 @@ var loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/
|
|
|
55
53
|
}
|
|
56
54
|
});
|
|
57
55
|
};
|
|
58
|
-
|
|
56
|
+
const loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript") => {
|
|
59
57
|
return new Promise((resolve, reject) => {
|
|
60
58
|
const scriptEle = doc.createElement("script");
|
|
61
59
|
scriptEle.type = type;
|
|
@@ -75,7 +73,7 @@ var loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript")
|
|
|
75
73
|
doc.body.appendChild(scriptEle);
|
|
76
74
|
});
|
|
77
75
|
};
|
|
78
|
-
|
|
76
|
+
const loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "text/javascript") => {
|
|
79
77
|
const xhr = new window.XMLHttpRequest();
|
|
80
78
|
xhr.open("GET", FILE_URL, false);
|
|
81
79
|
xhr.send();
|
|
@@ -89,7 +87,7 @@ var loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "t
|
|
|
89
87
|
throw new Error(`Failed to load the script ${FILE_URL}`);
|
|
90
88
|
}
|
|
91
89
|
};
|
|
92
|
-
|
|
90
|
+
const loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
93
91
|
return new Promise((resolve, reject) => {
|
|
94
92
|
try {
|
|
95
93
|
const linkElem = doc.createElement("link");
|
|
@@ -106,7 +104,7 @@ var loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascr
|
|
|
106
104
|
}
|
|
107
105
|
});
|
|
108
106
|
};
|
|
109
|
-
|
|
107
|
+
const loadJavascript = (body, async = false, doc = document, type = "text/javascript", id = "smbls-script") => {
|
|
110
108
|
try {
|
|
111
109
|
const scriptEle = doc.createElement("script");
|
|
112
110
|
scriptEle.type = type;
|
package/dist/cjs/log.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var log_exports = {};
|
|
20
|
+
__export(log_exports, {
|
|
21
|
+
logGroupIf: () => logGroupIf,
|
|
22
|
+
logIf: () => logIf
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(log_exports);
|
|
25
|
+
const logIf = (bool, ...arg) => {
|
|
26
|
+
if (bool) arg.map((v) => console.log(v));
|
|
27
|
+
};
|
|
28
|
+
const logGroupIf = (bool, key, ...arg) => {
|
|
29
|
+
if (bool) {
|
|
30
|
+
console.group(key);
|
|
31
|
+
arg.map((v) => console.log(v));
|
|
32
|
+
console.groupEnd(key);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var metadata_exports = {};
|
|
20
|
+
__export(metadata_exports, {
|
|
21
|
+
generateMetaTags: () => generateMetaTags,
|
|
22
|
+
getPageMetadata: () => getPageMetadata
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(metadata_exports);
|
|
25
|
+
var import_types = require("./types.js");
|
|
26
|
+
const escapeHtml = (text) => {
|
|
27
|
+
if (text === null || text === void 0) return "";
|
|
28
|
+
const map = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
29
|
+
return text.toString().replace(/[&<>"']/g, (m) => map[m]);
|
|
30
|
+
};
|
|
31
|
+
const buildAttrs = (obj) => Object.entries(obj || {}).filter(([_, v]) => v !== void 0).map(([k, v]) => `${k}="${escapeHtml(v)}"`).join(" ");
|
|
32
|
+
const generateMetaTags = (metadata, isProduction) => {
|
|
33
|
+
if (!isProduction) {
|
|
34
|
+
metadata = { ...metadata, robots: "noindex" };
|
|
35
|
+
}
|
|
36
|
+
const tags = Object.entries(metadata).reduce(
|
|
37
|
+
(acc, [key, value]) => {
|
|
38
|
+
if (!value && value !== 0 && value !== false) return acc;
|
|
39
|
+
if (key === "title") {
|
|
40
|
+
acc.push(`<title>${escapeHtml(value)}</title>`);
|
|
41
|
+
return acc;
|
|
42
|
+
}
|
|
43
|
+
if (key === "canonical") {
|
|
44
|
+
acc.push(`<link rel="canonical" href="${escapeHtml(value)}">`);
|
|
45
|
+
return acc;
|
|
46
|
+
}
|
|
47
|
+
if (key === "manifest") {
|
|
48
|
+
acc.push(`<link rel="manifest" href="${escapeHtml(value)}">`);
|
|
49
|
+
return acc;
|
|
50
|
+
}
|
|
51
|
+
if (key === "favicon" || key === "favicons" || key === "icon" || key === "icons") {
|
|
52
|
+
const items = Array.isArray(value) ? value : [value];
|
|
53
|
+
items.forEach((item) => {
|
|
54
|
+
if (typeof item === "string") {
|
|
55
|
+
acc.push(`<link rel="icon" href="${escapeHtml(item)}">`);
|
|
56
|
+
} else if (typeof item === "object") {
|
|
57
|
+
const attrs = buildAttrs(item);
|
|
58
|
+
if (!/rel=/.test(attrs)) {
|
|
59
|
+
acc.push(`<link rel="icon" ${attrs}>`);
|
|
60
|
+
} else {
|
|
61
|
+
acc.push(`<link ${attrs}>`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return acc;
|
|
66
|
+
}
|
|
67
|
+
if (key === "alternate") {
|
|
68
|
+
const alternates = Array.isArray(value) ? value : [value];
|
|
69
|
+
alternates.forEach((alt) => {
|
|
70
|
+
if (typeof alt === "object") {
|
|
71
|
+
const attrs = Object.entries(alt).filter(([_, attrValue]) => attrValue !== void 0).map(([attrKey, attrValue]) => `${attrKey}="${escapeHtml(attrValue)}"`).join(" ");
|
|
72
|
+
acc.push(`<link rel="alternate" ${attrs}>`);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return acc;
|
|
76
|
+
}
|
|
77
|
+
const processMetaTag = (tagKey, tagValue, attrType = "name") => {
|
|
78
|
+
if (typeof tagValue === "string" || typeof tagValue === "number" || typeof tagValue === "boolean") {
|
|
79
|
+
acc.push(`<meta ${attrType}="${escapeHtml(tagKey)}" content="${escapeHtml(tagValue)}">`);
|
|
80
|
+
} else if (Array.isArray(tagValue)) {
|
|
81
|
+
tagValue.forEach((item) => {
|
|
82
|
+
if (typeof item === "string" || typeof item === "number" || typeof item === "boolean") {
|
|
83
|
+
acc.push(`<meta ${attrType}="${escapeHtml(tagKey)}" content="${escapeHtml(item)}">`);
|
|
84
|
+
} else if (typeof item === "object") {
|
|
85
|
+
const attrs = Object.entries(item).filter(([_, attrValue]) => attrValue !== void 0).map(([attrKey, attrValue]) => `${attrKey}="${escapeHtml(attrValue)}"`).join(" ");
|
|
86
|
+
acc.push(`<meta ${attrs}>`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} else if (typeof tagValue === "object") {
|
|
90
|
+
const attrs = Object.entries(tagValue).filter(([_, attrValue]) => attrValue !== void 0).map(([attrKey, attrValue]) => `${attrKey}="${escapeHtml(attrValue)}"`).join(" ");
|
|
91
|
+
acc.push(`<meta ${attrs}>`);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (key.startsWith("http-equiv:")) {
|
|
95
|
+
const httpEquivKey = key.replace("http-equiv:", "");
|
|
96
|
+
processMetaTag(httpEquivKey, value, "http-equiv");
|
|
97
|
+
return acc;
|
|
98
|
+
}
|
|
99
|
+
if (key.startsWith("itemprop:")) {
|
|
100
|
+
const itempropKey = key.replace("itemprop:", "");
|
|
101
|
+
processMetaTag(itempropKey, value, "itemprop");
|
|
102
|
+
return acc;
|
|
103
|
+
}
|
|
104
|
+
const prefixes = [
|
|
105
|
+
"og:",
|
|
106
|
+
"twitter:",
|
|
107
|
+
"fb:",
|
|
108
|
+
"article:",
|
|
109
|
+
"profile:",
|
|
110
|
+
"book:",
|
|
111
|
+
"business:",
|
|
112
|
+
"music:",
|
|
113
|
+
"product:",
|
|
114
|
+
"video:",
|
|
115
|
+
"DC:",
|
|
116
|
+
"DCTERMS:"
|
|
117
|
+
];
|
|
118
|
+
const prefix = prefixes.find((p) => key.startsWith(p));
|
|
119
|
+
if (prefix) {
|
|
120
|
+
const tagKey = key.replace(prefix, "");
|
|
121
|
+
processMetaTag(
|
|
122
|
+
`${prefix.replace(":", "")}:${tagKey}`,
|
|
123
|
+
value,
|
|
124
|
+
prefix === "twitter:" || prefix === "DC:" || prefix === "DCTERMS:" ? "name" : "property"
|
|
125
|
+
);
|
|
126
|
+
return acc;
|
|
127
|
+
}
|
|
128
|
+
if (key.startsWith("apple:") || key.startsWith("msapplication:")) {
|
|
129
|
+
const pfx = key.startsWith("apple:") ? "apple-" : "msapplication-";
|
|
130
|
+
const tagKey = key.replace(/^apple:|^msapplication:/, "");
|
|
131
|
+
processMetaTag(`${pfx}${tagKey}`, value, "name");
|
|
132
|
+
return acc;
|
|
133
|
+
}
|
|
134
|
+
processMetaTag(key, value);
|
|
135
|
+
return acc;
|
|
136
|
+
},
|
|
137
|
+
[
|
|
138
|
+
'<meta charset="UTF-8">',
|
|
139
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">'
|
|
140
|
+
]
|
|
141
|
+
);
|
|
142
|
+
return tags.join("\n");
|
|
143
|
+
};
|
|
144
|
+
const isBareFilename = (val) => typeof val === "string" && val.length > 0 && !val.startsWith("/") && !val.startsWith("http");
|
|
145
|
+
function resolveFileReferences(metadata, files) {
|
|
146
|
+
if (!files || typeof files !== "object") return metadata;
|
|
147
|
+
const resolve = (val) => {
|
|
148
|
+
if (!isBareFilename(val)) return val;
|
|
149
|
+
const fileEntry = files[val];
|
|
150
|
+
if (fileEntry?.src) return fileEntry.src;
|
|
151
|
+
return val;
|
|
152
|
+
};
|
|
153
|
+
const result = { ...metadata };
|
|
154
|
+
for (const [key, value] of Object.entries(result)) {
|
|
155
|
+
if (typeof value === "string") {
|
|
156
|
+
result[key] = resolve(value);
|
|
157
|
+
} else if (Array.isArray(value)) {
|
|
158
|
+
result[key] = value.map(
|
|
159
|
+
(item) => typeof item === "string" ? resolve(item) : item
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
function resolveDotPath(obj, path) {
|
|
166
|
+
if (!obj || !path) return void 0;
|
|
167
|
+
const parts = path.split(".");
|
|
168
|
+
let v = obj;
|
|
169
|
+
for (const p of parts) {
|
|
170
|
+
if (v == null || typeof v !== "object") return void 0;
|
|
171
|
+
v = v[p];
|
|
172
|
+
}
|
|
173
|
+
return v;
|
|
174
|
+
}
|
|
175
|
+
function resolveMetadataTemplates(metadata, data, ssrContext) {
|
|
176
|
+
const config = data.config || data.settings || {};
|
|
177
|
+
const polyglot = config.polyglot || data.polyglot;
|
|
178
|
+
const defaultLang = ssrContext?.lang || polyglot?.defaultLang || "en";
|
|
179
|
+
const translations = polyglot?.translations || {};
|
|
180
|
+
const langMap = translations[defaultLang] || {};
|
|
181
|
+
const state = ssrContext?.state || {};
|
|
182
|
+
const result = { ...metadata };
|
|
183
|
+
for (const [key, value] of Object.entries(result)) {
|
|
184
|
+
if (typeof value !== "string" || !value.includes("{{")) continue;
|
|
185
|
+
result[key] = value.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g, (match, k, filter) => {
|
|
186
|
+
const trimmed = k.trim();
|
|
187
|
+
if (filter === "polyglot") {
|
|
188
|
+
return langMap[trimmed] ?? resolveDotPath(langMap, trimmed) ?? match;
|
|
189
|
+
}
|
|
190
|
+
if (filter === "getLocalStateLang") {
|
|
191
|
+
const resolved = resolveDotPath(state, trimmed + defaultLang);
|
|
192
|
+
return resolved ?? match;
|
|
193
|
+
}
|
|
194
|
+
const fromState = resolveDotPath(state, trimmed);
|
|
195
|
+
if (fromState !== void 0) return fromState;
|
|
196
|
+
return langMap[trimmed] ?? resolveDotPath(langMap, trimmed) ?? match;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
function convertFunctionMetaToTemplates(metadata) {
|
|
202
|
+
const result = { ...metadata };
|
|
203
|
+
for (const [key, value] of Object.entries(result)) {
|
|
204
|
+
if (typeof value === "function") {
|
|
205
|
+
const src = value.toString();
|
|
206
|
+
const langMatch = src.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);
|
|
207
|
+
if (langMatch) {
|
|
208
|
+
result[key] = `{{ ${langMatch[1]} | getLocalStateLang }}`;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const polyMatch = src.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);
|
|
212
|
+
if (polyMatch) {
|
|
213
|
+
result[key] = `{{ ${polyMatch[1]} | polyglot }}`;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const stateMatch = src.match(/s\.(\w+(?:\.\w+)+)/);
|
|
217
|
+
if (stateMatch) {
|
|
218
|
+
result[key] = `{{ ${stateMatch[1]} }}`;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
delete result[key];
|
|
222
|
+
} else if (typeof value === "string") {
|
|
223
|
+
const langMatch = value.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);
|
|
224
|
+
if (langMatch) {
|
|
225
|
+
result[key] = `{{ ${langMatch[1]} | getLocalStateLang }}`;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const polyMatch = value.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);
|
|
229
|
+
if (polyMatch) {
|
|
230
|
+
result[key] = `{{ ${polyMatch[1]} | polyglot }}`;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (value.includes("=>") && value.includes("s.")) {
|
|
234
|
+
const stateMatch = value.match(/s\.(\w+(?:\.\w+)+)/);
|
|
235
|
+
if (stateMatch) {
|
|
236
|
+
result[key] = `{{ ${stateMatch[1]} }}`;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
function getPageMetadata(data, pathname, ssrContext, { isProduction = false, channel = "production" } = {}) {
|
|
245
|
+
const currentPage = data.pages?.[pathname];
|
|
246
|
+
const stateObject = (0, import_types.isObject)(currentPage?.state) && currentPage?.state;
|
|
247
|
+
const rawPageMeta = currentPage?.metadata || currentPage?.helmet || stateObject || {};
|
|
248
|
+
const pageMetadata = convertFunctionMetaToTemplates(rawPageMeta);
|
|
249
|
+
const pageExplicitKeys = new Set(Object.keys(pageMetadata));
|
|
250
|
+
const appMetadata = data.app?.metadata || {};
|
|
251
|
+
const cleanAppMeta = convertFunctionMetaToTemplates(appMetadata);
|
|
252
|
+
let merged = {};
|
|
253
|
+
if (data.integrations?.seo) {
|
|
254
|
+
merged = { ...data.integrations.seo, ...cleanAppMeta, ...pageMetadata };
|
|
255
|
+
} else if (Object.keys(cleanAppMeta).length) {
|
|
256
|
+
merged = { ...cleanAppMeta, ...pageMetadata };
|
|
257
|
+
} else {
|
|
258
|
+
merged = { ...pageMetadata };
|
|
259
|
+
}
|
|
260
|
+
if (!merged.title) {
|
|
261
|
+
const label = data.name || data.key;
|
|
262
|
+
if (label) {
|
|
263
|
+
if (isProduction) merged.title = label;
|
|
264
|
+
else if (channel === "development") merged.title = `${label} / dev:symbo.ls`;
|
|
265
|
+
else if (channel === "staging") merged.title = `${label} / staging:symbo.ls`;
|
|
266
|
+
else merged.title = `${label} / symbo.ls`;
|
|
267
|
+
} else {
|
|
268
|
+
merged.title = "Symbols demo";
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
merged = resolveMetadataTemplates(merged, data, ssrContext);
|
|
272
|
+
if (merged.title && (pageExplicitKeys.has("title") || !merged["og:title"])) {
|
|
273
|
+
if (!pageExplicitKeys.has("og:title")) {
|
|
274
|
+
merged["og:title"] = merged.title;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (merged.description && (pageExplicitKeys.has("description") || !merged["og:description"])) {
|
|
278
|
+
if (!pageExplicitKeys.has("og:description")) {
|
|
279
|
+
merged["og:description"] = merged.description;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (merged.title && !merged["twitter:title"]) {
|
|
283
|
+
merged["twitter:title"] = merged.title;
|
|
284
|
+
}
|
|
285
|
+
if (merged.description && !merged["twitter:description"]) {
|
|
286
|
+
merged["twitter:description"] = merged.description;
|
|
287
|
+
}
|
|
288
|
+
const routeForUrl = ssrContext?.actualPathname || pathname;
|
|
289
|
+
if (merged["og:url"] || merged.url) {
|
|
290
|
+
const baseUrl = (merged["og:url"] || merged.url || "").replace(/\/$/, "");
|
|
291
|
+
if (baseUrl && routeForUrl && routeForUrl !== "/") {
|
|
292
|
+
const cleanRoute = routeForUrl.startsWith("/") ? routeForUrl : "/" + routeForUrl;
|
|
293
|
+
merged["og:url"] = baseUrl + cleanRoute;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
merged = resolveFileReferences(merged, data.files);
|
|
297
|
+
const siteName = data.name || data.app?.metadata?.title || data.app?.name || "";
|
|
298
|
+
for (const [key, value] of Object.entries(merged)) {
|
|
299
|
+
if (typeof value === "string" && value.includes("{{")) {
|
|
300
|
+
const cleaned = value.replace(/\{\{[^}]*\}\}/g, "").trim();
|
|
301
|
+
if (!cleaned) {
|
|
302
|
+
if (key === "title") merged[key] = siteName;
|
|
303
|
+
else delete merged[key];
|
|
304
|
+
} else {
|
|
305
|
+
merged[key] = cleaned;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return merged;
|
|
310
|
+
}
|