@knapsack/types 4.68.5 → 4.68.6--canary.4475.83293df.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +29 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.mjs
CHANGED
@@ -20,8 +20,7 @@ import {
|
|
20
20
|
import colorString from "color-string";
|
21
21
|
import { define, literal, string, type, union } from "superstruct";
|
22
22
|
function isColor(color) {
|
23
|
-
if (typeof color !== "string")
|
24
|
-
return false;
|
23
|
+
if (typeof color !== "string") return false;
|
25
24
|
try {
|
26
25
|
return !!colorString.get(color);
|
27
26
|
} catch (e) {
|
@@ -410,8 +409,7 @@ var strokeStyleValues = [
|
|
410
409
|
"inset"
|
411
410
|
];
|
412
411
|
function isTokenReference(val) {
|
413
|
-
if (typeof val !== "string")
|
414
|
-
return false;
|
412
|
+
if (typeof val !== "string") return false;
|
415
413
|
const totalOpenBrackets = val.split("{").length - 1;
|
416
414
|
return totalOpenBrackets === 1 && val.startsWith("{") && val.endsWith("}");
|
417
415
|
}
|
@@ -427,8 +425,7 @@ __name(isNotTokenReference, "isNotTokenReference");
|
|
427
425
|
var TokenReferenceStruct = s.define(
|
428
426
|
"Token Reference",
|
429
427
|
(value) => {
|
430
|
-
if (typeof value !== "string")
|
431
|
-
return false;
|
428
|
+
if (typeof value !== "string") return false;
|
432
429
|
if (isNotTokenReference(value)) {
|
433
430
|
return "Must start and end with curly braces";
|
434
431
|
}
|
@@ -841,8 +838,7 @@ __name(isTokenValueShadow, "isTokenValueShadow");
|
|
841
838
|
var TokenValueShadowStruct = s2.define(
|
842
839
|
"Shadow Value",
|
843
840
|
(value) => {
|
844
|
-
if (isTokenValueShadow(value))
|
845
|
-
return true;
|
841
|
+
if (isTokenValueShadow(value)) return true;
|
846
842
|
return `Expected a shadow value, got ${JSON.stringify(value)}`;
|
847
843
|
}
|
848
844
|
);
|
@@ -1141,8 +1137,7 @@ var assertTokenData = /* @__PURE__ */ __name((data) => {
|
|
1141
1137
|
}
|
1142
1138
|
}
|
1143
1139
|
} catch (error) {
|
1144
|
-
if (!(error instanceof s2.StructError))
|
1145
|
-
throw error;
|
1140
|
+
if (!(error instanceof s2.StructError)) throw error;
|
1146
1141
|
throw new Error(
|
1147
1142
|
`Invalid token data for type "${type9}": ${error.message}. Received this data: "${JSON.stringify(data)}"`
|
1148
1143
|
);
|
@@ -1309,8 +1304,7 @@ expectType3([
|
|
1309
1304
|
}
|
1310
1305
|
]);
|
1311
1306
|
function isTokenSrc(tokenObject) {
|
1312
|
-
if (isObject3(tokenObject) && isObjKey3("$value", tokenObject))
|
1313
|
-
return true;
|
1307
|
+
if (isObject3(tokenObject) && isObjKey3("$value", tokenObject)) return true;
|
1314
1308
|
return false;
|
1315
1309
|
}
|
1316
1310
|
__name(isTokenSrc, "isTokenSrc");
|
@@ -1393,8 +1387,7 @@ var PageHeaderSizes = /* @__PURE__ */ ((PageHeaderSizes2) => {
|
|
1393
1387
|
|
1394
1388
|
// src/app-client-data/index.ts
|
1395
1389
|
function isKsAppClientDataNoMeta(data) {
|
1396
|
-
if (!isObject(data))
|
1397
|
-
return false;
|
1390
|
+
if (!isObject(data)) return false;
|
1398
1391
|
const requiredKeys = [
|
1399
1392
|
"assetSetsState",
|
1400
1393
|
"customPagesState",
|
@@ -1403,10 +1396,8 @@ function isKsAppClientDataNoMeta(data) {
|
|
1403
1396
|
"tokensSrc",
|
1404
1397
|
"db"
|
1405
1398
|
];
|
1406
|
-
if (!requiredKeys.every((key) => isObjKey(key, data)))
|
1407
|
-
|
1408
|
-
if (!isObjKey("metaState", data))
|
1409
|
-
return true;
|
1399
|
+
if (!requiredKeys.every((key) => isObjKey(key, data))) return false;
|
1400
|
+
if (!isObjKey("metaState", data)) return true;
|
1410
1401
|
return false;
|
1411
1402
|
}
|
1412
1403
|
__name(isKsAppClientDataNoMeta, "isKsAppClientDataNoMeta");
|
@@ -1415,8 +1406,7 @@ var KsAppClientDataNoMetaStruct = define4(
|
|
1415
1406
|
isKsAppClientDataNoMeta
|
1416
1407
|
);
|
1417
1408
|
function isKsAppClientDataAndMeta(data) {
|
1418
|
-
if (!isObject(data))
|
1419
|
-
return false;
|
1409
|
+
if (!isObject(data)) return false;
|
1420
1410
|
const requiredKeys = [
|
1421
1411
|
"assetSetsState",
|
1422
1412
|
"customPagesState",
|
@@ -1471,8 +1461,7 @@ import {
|
|
1471
1461
|
define as define5
|
1472
1462
|
} from "superstruct";
|
1473
1463
|
function isKsAppClientDataNoMetaV3(data) {
|
1474
|
-
if (!isObject(data))
|
1475
|
-
return false;
|
1464
|
+
if (!isObject(data)) return false;
|
1476
1465
|
const requiredKeys = [
|
1477
1466
|
"assetSetsState",
|
1478
1467
|
"customPagesState",
|
@@ -1481,10 +1470,8 @@ function isKsAppClientDataNoMetaV3(data) {
|
|
1481
1470
|
"settingsState",
|
1482
1471
|
"tokensState"
|
1483
1472
|
];
|
1484
|
-
if (!requiredKeys.every((key) => isObjKey(key, data)))
|
1485
|
-
|
1486
|
-
if (!isObjKey("metaState", data))
|
1487
|
-
return true;
|
1473
|
+
if (!requiredKeys.every((key) => isObjKey(key, data))) return false;
|
1474
|
+
if (!isObjKey("metaState", data)) return true;
|
1488
1475
|
return false;
|
1489
1476
|
}
|
1490
1477
|
__name(isKsAppClientDataNoMetaV3, "isKsAppClientDataNoMetaV3");
|
@@ -1493,8 +1480,7 @@ var KsAppClientDataNoMetaStructV3 = define5(
|
|
1493
1480
|
isKsAppClientDataNoMetaV3
|
1494
1481
|
);
|
1495
1482
|
function isKsAppClientDataAndMetaV3(data) {
|
1496
|
-
if (!isObject(data))
|
1497
|
-
return false;
|
1483
|
+
if (!isObject(data)) return false;
|
1498
1484
|
const requiredKeys = [
|
1499
1485
|
"assetSetsState",
|
1500
1486
|
"customPagesState",
|
@@ -1542,11 +1528,11 @@ var isKsMetaStateV3 = KsMetaStateStructV3.is;
|
|
1542
1528
|
import { isDraft } from "immer";
|
1543
1529
|
var migration417Demos = {
|
1544
1530
|
version: "4.1.7",
|
1545
|
-
checkIfNeeded: (appClientData) => {
|
1531
|
+
checkIfNeeded: /* @__PURE__ */ __name((appClientData) => {
|
1546
1532
|
return true;
|
1547
|
-
},
|
1533
|
+
}, "checkIfNeeded"),
|
1548
1534
|
// note that `appClientData` is mutable since we're already in Immer
|
1549
|
-
migrate: (appClientData) => {
|
1535
|
+
migrate: /* @__PURE__ */ __name((appClientData) => {
|
1550
1536
|
if (!isDraft(appClientData)) {
|
1551
1537
|
throw new Error(
|
1552
1538
|
`Tried to run migrations on appClientData but it is not an Immer Draft`
|
@@ -1558,8 +1544,7 @@ var migration417Demos = {
|
|
1558
1544
|
}
|
1559
1545
|
);
|
1560
1546
|
Object.values(appClientData.db.demos.byId).forEach((demo) => {
|
1561
|
-
if (demo.type !== "data")
|
1562
|
-
return;
|
1547
|
+
if (demo.type !== "data") return;
|
1563
1548
|
Object.entries(demo.data.slots ?? {}).forEach(([slotName, slotData]) => {
|
1564
1549
|
demo.data.slots[slotName] = slotData.map(
|
1565
1550
|
(slottedData) => {
|
@@ -1581,8 +1566,7 @@ var migration417Demos = {
|
|
1581
1566
|
}
|
1582
1567
|
);
|
1583
1568
|
});
|
1584
|
-
if (demo.patternId && demo.templateId)
|
1585
|
-
return;
|
1569
|
+
if (demo.patternId && demo.templateId) return;
|
1586
1570
|
(() => {
|
1587
1571
|
for (const { id: pId, templates = [] } of Object.values(
|
1588
1572
|
appClientData.patternsState.patterns
|
@@ -1597,7 +1581,7 @@ var migration417Demos = {
|
|
1597
1581
|
}
|
1598
1582
|
})();
|
1599
1583
|
});
|
1600
|
-
}
|
1584
|
+
}, "migrate")
|
1601
1585
|
};
|
1602
1586
|
|
1603
1587
|
// src/app-client-data-migrations/index.ts
|
@@ -1665,10 +1649,8 @@ var rendererIds = {
|
|
1665
1649
|
html: "html"
|
1666
1650
|
};
|
1667
1651
|
function isKsJsImports(imports) {
|
1668
|
-
if (!Array.isArray(imports))
|
1669
|
-
|
1670
|
-
if (imports.length === 0)
|
1671
|
-
return true;
|
1652
|
+
if (!Array.isArray(imports)) return false;
|
1653
|
+
if (imports.length === 0) return true;
|
1672
1654
|
const [anImport] = imports;
|
1673
1655
|
if (anImport.type === "pattern-template" && typeof anImport.patternId !== "string")
|
1674
1656
|
return false;
|
@@ -1687,8 +1669,7 @@ function isKsJsImports(imports) {
|
|
1687
1669
|
if (anImport.type === "extra" && typeof anImport.importInfo.path !== "string")
|
1688
1670
|
return false;
|
1689
1671
|
if (anImport.type === "extra" && typeof anImport.importInfo.names !== "undefined") {
|
1690
|
-
if (!Array.isArray(anImport.importInfo.names))
|
1691
|
-
return false;
|
1672
|
+
if (!Array.isArray(anImport.importInfo.names)) return false;
|
1692
1673
|
if (anImport.importInfo.names.some((name) => typeof name !== "string"))
|
1693
1674
|
return false;
|
1694
1675
|
}
|
@@ -1696,24 +1677,18 @@ function isKsJsImports(imports) {
|
|
1696
1677
|
}
|
1697
1678
|
__name(isKsJsImports, "isKsJsImports");
|
1698
1679
|
function isKsRendererClientGlobalImportedModules(mods) {
|
1699
|
-
if (!isObject(mods))
|
1700
|
-
return false;
|
1680
|
+
if (!isObject(mods)) return false;
|
1701
1681
|
for (const key in mods) {
|
1702
|
-
if (typeof mods[key] !== "function")
|
1703
|
-
return false;
|
1682
|
+
if (typeof mods[key] !== "function") return false;
|
1704
1683
|
}
|
1705
1684
|
return true;
|
1706
1685
|
}
|
1707
1686
|
__name(isKsRendererClientGlobalImportedModules, "isKsRendererClientGlobalImportedModules");
|
1708
1687
|
function isKsRendererClientGlobal(knapsack) {
|
1709
|
-
if (!isObject(knapsack))
|
1710
|
-
|
1711
|
-
if (knapsack.
|
1712
|
-
|
1713
|
-
if (typeof knapsack.getImport !== "function")
|
1714
|
-
return false;
|
1715
|
-
if (!Array.isArray(knapsack.allAvailableImports))
|
1716
|
-
return false;
|
1688
|
+
if (!isObject(knapsack)) return false;
|
1689
|
+
if (knapsack.typeName !== "KsRendererClientGlobal") return false;
|
1690
|
+
if (typeof knapsack.getImport !== "function") return false;
|
1691
|
+
if (!Array.isArray(knapsack.allAvailableImports)) return false;
|
1717
1692
|
if (!isKsRendererClientGlobalImportedModules(knapsack.importedModules)) {
|
1718
1693
|
return false;
|
1719
1694
|
}
|