@supernova-studio/model 0.46.8 → 0.46.9
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.d.mts +59 -54
- package/dist/index.d.ts +59 -54
- package/dist/index.js +64 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dsm/elements/theme.ts +4 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/naming.ts +73 -0
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { DesignTokenOrigin, DesignTokenOriginPart, DesignTokenTypedData } from "./tokens";
|
|
3
|
-
import { DesignTokenType } from "./raw-element";
|
|
4
|
-
import { DesignElementBase, DesignElementBrandedPart } from "./base";
|
|
5
2
|
import { DbCreateInputOmit, DbUpdate } from "../../helpers";
|
|
6
3
|
import { OmitStrict } from "../../utils";
|
|
4
|
+
import { DesignElementBase, DesignElementBrandedPart } from "./base";
|
|
5
|
+
import { DesignTokenType } from "./raw-element";
|
|
6
|
+
import { DesignTokenOrigin, DesignTokenOriginPart, DesignTokenTypedData } from "./tokens";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
// Overrides
|
|
@@ -59,6 +59,7 @@ export const ThemeOrigin = z.object({
|
|
|
59
59
|
export const Theme = DesignElementBase.extend(DesignElementBrandedPart.shape).extend({
|
|
60
60
|
origin: ThemeOrigin.optional(),
|
|
61
61
|
overrides: z.array(ThemeOverride),
|
|
62
|
+
codeName: z.string(),
|
|
62
63
|
});
|
|
63
64
|
|
|
64
65
|
export type Theme = z.infer<typeof Theme>;
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// this has been ported from the Dart cloud app
|
|
2
|
+
export function getCodenameFromText(name: string): string {
|
|
3
|
+
// Turn all characters with diacritics into their simple form (ě -> e, ö -> o, etc.)
|
|
4
|
+
let codeName = removeDiacritics(name);
|
|
5
|
+
|
|
6
|
+
// Remove all invalid characters
|
|
7
|
+
codeName = codeName.replace(/[^a-zA-Z0-9$_ ]+/g, "");
|
|
8
|
+
// Remove all starting numbers
|
|
9
|
+
codeName = codeName.replace(/^[0-9 ]+/g, "");
|
|
10
|
+
// Change to CamelCase
|
|
11
|
+
codeName = toCamelCase(codeName.toLowerCase());
|
|
12
|
+
// Remove all spaces
|
|
13
|
+
codeName = codeName.replace(/ /g, "");
|
|
14
|
+
|
|
15
|
+
if (codeName) {
|
|
16
|
+
// Lowercase the first letter
|
|
17
|
+
codeName = codeName.charAt(0).toLowerCase() + codeName.slice(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return codeName;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toCamelCase(str: string): string {
|
|
24
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) {
|
|
25
|
+
if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
|
|
26
|
+
return index === 0 ? match.toLowerCase() : match.toUpperCase();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function removeDiacritics(str: string): string {
|
|
31
|
+
const diacriticsMap = [
|
|
32
|
+
{
|
|
33
|
+
base: "A",
|
|
34
|
+
letters:
|
|
35
|
+
/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g,
|
|
36
|
+
},
|
|
37
|
+
{ base: "AA", letters: /[\uA732]/g },
|
|
38
|
+
{ base: "AE", letters: /[\u00C6\u01FC\u01E2]/g },
|
|
39
|
+
{ base: "AO", letters: /[\uA734]/g },
|
|
40
|
+
{ base: "AU", letters: /[\uA736]/g },
|
|
41
|
+
{ base: "AV", letters: /[\uA738\uA73A]/g },
|
|
42
|
+
{ base: "AY", letters: /[\uA73C]/g },
|
|
43
|
+
{
|
|
44
|
+
base: "B",
|
|
45
|
+
letters: /[\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181]/g,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
base: "C",
|
|
49
|
+
letters: /[\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E]/g,
|
|
50
|
+
},
|
|
51
|
+
/* ... */
|
|
52
|
+
{
|
|
53
|
+
base: "Z",
|
|
54
|
+
letters: /[\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762]/g,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
base: "a",
|
|
58
|
+
letters:
|
|
59
|
+
/[\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250]/g,
|
|
60
|
+
},
|
|
61
|
+
/* ... */
|
|
62
|
+
{
|
|
63
|
+
base: "z",
|
|
64
|
+
letters: /[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763]/g,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
diacriticsMap.forEach(diacritic => {
|
|
69
|
+
str = str.replace(diacritic.letters, diacritic.base);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return str;
|
|
73
|
+
}
|