@constela/runtime 0.14.0 → 0.15.1
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/index.js +36 -3
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -177,6 +177,7 @@ function createComputed(getter) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// src/state/store.ts
|
|
180
|
+
import { isCookieInitialExpr } from "@constela/core";
|
|
180
181
|
function normalizePath(path) {
|
|
181
182
|
if (typeof path === "string") {
|
|
182
183
|
return path.split(".").map((segment) => {
|
|
@@ -213,10 +214,33 @@ function setValueAtPath(obj, path, value) {
|
|
|
213
214
|
);
|
|
214
215
|
return clone3;
|
|
215
216
|
}
|
|
217
|
+
function getCookieValue(key2) {
|
|
218
|
+
if (typeof document === "undefined") return void 0;
|
|
219
|
+
for (const cookie of document.cookie.split(";")) {
|
|
220
|
+
const eqIndex = cookie.indexOf("=");
|
|
221
|
+
if (eqIndex === -1) continue;
|
|
222
|
+
const name = cookie.slice(0, eqIndex).trim();
|
|
223
|
+
if (name === key2) {
|
|
224
|
+
const value = cookie.slice(eqIndex + 1);
|
|
225
|
+
try {
|
|
226
|
+
return decodeURIComponent(value);
|
|
227
|
+
} catch {
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return void 0;
|
|
233
|
+
}
|
|
216
234
|
function createStateStore(definitions) {
|
|
217
235
|
const signals = /* @__PURE__ */ new Map();
|
|
218
236
|
for (const [name, def] of Object.entries(definitions)) {
|
|
219
|
-
let initialValue
|
|
237
|
+
let initialValue;
|
|
238
|
+
if (isCookieInitialExpr(def.initial)) {
|
|
239
|
+
const cookieValue = getCookieValue(def.initial.key);
|
|
240
|
+
initialValue = cookieValue !== void 0 ? cookieValue : def.initial.default;
|
|
241
|
+
} else {
|
|
242
|
+
initialValue = def.initial;
|
|
243
|
+
}
|
|
220
244
|
if (name === "theme" && typeof window !== "undefined") {
|
|
221
245
|
try {
|
|
222
246
|
const stored = localStorage.getItem("theme");
|
|
@@ -245,6 +269,15 @@ function createStateStore(definitions) {
|
|
|
245
269
|
if (!signal) {
|
|
246
270
|
throw new Error(`State field "${name}" does not exist`);
|
|
247
271
|
}
|
|
272
|
+
if (name === "theme" && typeof document !== "undefined") {
|
|
273
|
+
try {
|
|
274
|
+
const valueStr = typeof value === "string" ? value : JSON.stringify(value);
|
|
275
|
+
const oneYear = 365 * 24 * 60 * 60;
|
|
276
|
+
const secure = typeof location !== "undefined" && location.protocol === "https:" ? "; Secure" : "";
|
|
277
|
+
document.cookie = `theme=${encodeURIComponent(valueStr)}; path=/; max-age=${oneYear}; SameSite=Lax${secure}`;
|
|
278
|
+
} catch {
|
|
279
|
+
}
|
|
280
|
+
}
|
|
248
281
|
signal.set(value);
|
|
249
282
|
},
|
|
250
283
|
subscribe(name, fn) {
|
|
@@ -4633,8 +4666,8 @@ var Rule = class {
|
|
|
4633
4666
|
this._contentNameIsCapturing = RegexSource.hasCaptures(this._contentName);
|
|
4634
4667
|
}
|
|
4635
4668
|
get debugName() {
|
|
4636
|
-
const
|
|
4637
|
-
return `${this.constructor.name}#${this.id} @ ${
|
|
4669
|
+
const location2 = this.$location ? `${basename(this.$location.filename)}:${this.$location.line}` : "unknown";
|
|
4670
|
+
return `${this.constructor.name}#${this.id} @ ${location2}`;
|
|
4638
4671
|
}
|
|
4639
4672
|
getName(lineText, captureIndices) {
|
|
4640
4673
|
if (!this._nameIsCapturing || this._name === null || lineText === null || captureIndices === null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "Runtime DOM renderer for Constela UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dompurify": "^3.3.1",
|
|
19
19
|
"marked": "^17.0.1",
|
|
20
20
|
"shiki": "^3.20.0",
|
|
21
|
-
"@constela/compiler": "0.11.
|
|
22
|
-
"@constela/core": "0.
|
|
21
|
+
"@constela/compiler": "0.11.1",
|
|
22
|
+
"@constela/core": "0.12.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/dompurify": "^3.2.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"tsup": "^8.0.0",
|
|
30
30
|
"typescript": "^5.3.0",
|
|
31
31
|
"vitest": "^2.0.0",
|
|
32
|
-
"@constela/server": "
|
|
32
|
+
"@constela/server": "8.0.0"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=20.0.0"
|