@plasmicapp/loader-edge 1.0.19 → 1.0.21
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.
|
@@ -8,10 +8,9 @@ const getSeededRandomFunction = strSeed => {
|
|
|
8
8
|
// https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
|
|
9
9
|
function cyrb128(str) {
|
|
10
10
|
let h1 = 1779033703,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
h2 = 3144134277,
|
|
12
|
+
h3 = 1013904242,
|
|
13
|
+
h4 = 2773480762;
|
|
15
14
|
for (let i = 0, k; i < str.length; i++) {
|
|
16
15
|
k = str.charCodeAt(i);
|
|
17
16
|
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
|
|
@@ -19,14 +18,12 @@ const getSeededRandomFunction = strSeed => {
|
|
|
19
18
|
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
|
|
20
19
|
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
h1 = Math.imul(h3 ^ h1 >>> 18, 597399067);
|
|
24
22
|
h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233);
|
|
25
23
|
h3 = Math.imul(h1 ^ h3 >>> 17, 951274213);
|
|
26
24
|
h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179);
|
|
27
25
|
return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
function sfc32(a, b, c, d) {
|
|
31
28
|
return function () {
|
|
32
29
|
a >>>= 0;
|
|
@@ -43,7 +40,6 @@ const getSeededRandomFunction = strSeed => {
|
|
|
43
40
|
return (t >>> 0) / 4294967296;
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
|
-
|
|
47
43
|
const seed = cyrb128(strSeed);
|
|
48
44
|
const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);
|
|
49
45
|
return rand;
|
|
@@ -52,16 +48,15 @@ const getSeededRandomFunction = strSeed => {
|
|
|
52
48
|
const DELIMITER = '__pm__';
|
|
53
49
|
const PLASMIC_SEED = 'plasmic_seed';
|
|
54
50
|
const SEED_RANGE = 16;
|
|
55
|
-
|
|
56
51
|
const getSeed = () => {
|
|
57
52
|
return `${Math.floor(Math.random() * SEED_RANGE)}`;
|
|
58
53
|
};
|
|
59
|
-
|
|
60
54
|
const rewriteWithoutTraits = url => {
|
|
61
55
|
const [path, ...traitssArr] = url.split(DELIMITER);
|
|
62
56
|
const traits = traitssArr.reduce((acc, elem) => {
|
|
63
57
|
const [key, value] = elem.split('=');
|
|
64
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
...acc,
|
|
65
60
|
[key]: value
|
|
66
61
|
};
|
|
67
62
|
}, {});
|
|
@@ -70,15 +65,12 @@ const rewriteWithoutTraits = url => {
|
|
|
70
65
|
traits
|
|
71
66
|
};
|
|
72
67
|
};
|
|
73
|
-
|
|
74
68
|
const expandTraits = traits => {
|
|
75
69
|
const cmp = (a, b) => {
|
|
76
70
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
77
71
|
};
|
|
78
|
-
|
|
79
72
|
return Object.keys(traits).sort(cmp).map(key => `${DELIMITER}${key}=${traits[key]}`).join('');
|
|
80
73
|
};
|
|
81
|
-
|
|
82
74
|
const rewriteWithTraits = (path, traits) => {
|
|
83
75
|
return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;
|
|
84
76
|
};
|
|
@@ -89,14 +81,12 @@ const generateAllPaths = path => {
|
|
|
89
81
|
const getMiddlewareResponse = opts => {
|
|
90
82
|
const newCookies = [];
|
|
91
83
|
const seed = opts.cookies[PLASMIC_SEED] || getSeed();
|
|
92
|
-
|
|
93
84
|
if (!opts.cookies[PLASMIC_SEED]) {
|
|
94
85
|
newCookies.push({
|
|
95
86
|
key: PLASMIC_SEED,
|
|
96
87
|
value: seed
|
|
97
88
|
});
|
|
98
89
|
}
|
|
99
|
-
|
|
100
90
|
return {
|
|
101
91
|
pathname: rewriteWithTraits(opts.path, {
|
|
102
92
|
[PLASMIC_SEED]: seed,
|
|
@@ -121,7 +111,6 @@ const getActiveVariation = opts => {
|
|
|
121
111
|
updateKnownValue: () => null,
|
|
122
112
|
getRandomValue: key => {
|
|
123
113
|
var _traits$PLASMIC_SEED;
|
|
124
|
-
|
|
125
114
|
const rand = getSeededRandomFunction(((_traits$PLASMIC_SEED = traits[PLASMIC_SEED]) != null ? _traits$PLASMIC_SEED : '') + key);
|
|
126
115
|
return rand();
|
|
127
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-edge.cjs.development.js","sources":["../src/random.ts","../src/variation.ts"],"sourcesContent":["export const getSeededRandomFunction = (strSeed: string) => {\n // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript\n function cyrb128(str) {\n let h1 = 1779033703,\n h2 = 3144134277,\n h3 = 1013904242,\n h4 = 2773480762;\n for (let i = 0, k; i < str.length; i++) {\n k = str.charCodeAt(i);\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n }\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n return [\n (h1 ^ h2 ^ h3 ^ h4) >>> 0,\n (h2 ^ h1) >>> 0,\n (h3 ^ h1) >>> 0,\n (h4 ^ h1) >>> 0,\n ];\n }\n function sfc32(a, b, c, d) {\n return function () {\n a >>>= 0;\n b >>>= 0;\n c >>>= 0;\n d >>>= 0;\n var t = (a + b) | 0;\n a = b ^ (b >>> 9);\n b = (c + (c << 3)) | 0;\n c = (c << 21) | (c >>> 11);\n d = (d + 1) | 0;\n t = (t + d) | 0;\n c = (c + t) | 0;\n return (t >>> 0) / 4294967296;\n };\n }\n const seed = cyrb128(strSeed);\n const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);\n return rand;\n};\n","import { Split } from '@plasmicapp/loader-fetcher';\nimport { getActiveVariation as getActiveVariationSplits } from '@plasmicapp/loader-splits';\nimport { getSeededRandomFunction } from './random';\n\nconst DELIMITER = '__pm__';\nconst PLASMIC_SEED = 'plasmic_seed';\nconst SEED_RANGE = 16;\n\ntype Traits = Record<string, string | number | boolean>;\n\nconst getSeed = () => {\n return `${Math.floor(Math.random() * SEED_RANGE)}`;\n};\n\nexport const rewriteWithoutTraits = (url: string) => {\n const [path, ...traitssArr] = url.split(DELIMITER);\n const traits = traitssArr.reduce((acc, elem) => {\n const [key, value] = elem.split('=');\n return {\n ...acc,\n [key]: value,\n };\n }, {});\n return {\n path:\n path === '/'\n ? path\n : path.endsWith('/')\n ? path.substring(0, path.length - 1)\n : path,\n traits,\n };\n};\n\nconst expandTraits = (traits: Traits) => {\n const cmp = (a: string, b: string) => {\n return a < b ? -1 : a > b ? 1 : 0;\n };\n return Object.keys(traits)\n .sort(cmp)\n .map((key) => `${DELIMITER}${key}=${traits[key]}`)\n .join('');\n};\n\nexport const rewriteWithTraits = (path: string, traits: Traits) => {\n return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;\n};\n\nexport const generateAllPaths = (path: string) => {\n const paths = [\n path,\n ...Array(SEED_RANGE)\n .fill(0)\n .map(\n (_, idx) =>\n `${path}${path.endsWith('/') ? '' : '/'}__pm__${PLASMIC_SEED}=${idx}`\n ),\n ];\n return paths;\n};\n\nexport const getMiddlewareResponse = (opts: {\n path: string;\n traits: Traits;\n cookies: Record<string, string>;\n}) => {\n const newCookies: { key: string; value: string }[] = [];\n const seed = opts.cookies[PLASMIC_SEED] || getSeed();\n if (!opts.cookies[PLASMIC_SEED]) {\n newCookies.push({\n key: PLASMIC_SEED,\n value: seed,\n });\n }\n return {\n pathname: rewriteWithTraits(opts.path, {\n [PLASMIC_SEED]: seed,\n ...opts.traits,\n }),\n cookies: newCookies,\n };\n};\n\nexport const getActiveVariation = (opts: {\n splits: Split[];\n traits: Record<string, string | number | boolean>;\n path: string;\n}) => {\n const { splits, traits, path } = opts;\n return getActiveVariationSplits({\n splits,\n traits: {\n pageUrl: path,\n ...traits,\n },\n getKnownValue: () => undefined,\n updateKnownValue: () => null,\n getRandomValue: (key) => {\n const rand = getSeededRandomFunction((traits[PLASMIC_SEED] ?? '') + key);\n return rand();\n },\n });\n};\n"],"names":["getSeededRandomFunction","strSeed","cyrb128","str","h1","h2","h3","h4","i","k","length","charCodeAt","Math","imul","sfc32","a","b","c","d","t","seed","rand","DELIMITER","PLASMIC_SEED","SEED_RANGE","getSeed","floor","random","rewriteWithoutTraits","url","path","traitssArr","split","traits","reduce","acc","elem","key","value","endsWith","substring","expandTraits","cmp","Object","keys","sort","map","join","rewriteWithTraits","generateAllPaths","paths","Array","fill","_","idx","getMiddlewareResponse","opts","newCookies","cookies","push","pathname","getActiveVariation","splits","getActiveVariationSplits","pageUrl","getKnownValue","undefined","updateKnownValue","getRandomValue"],"mappings":";;;;;;AAAO,MAAMA,uBAAuB,GAAIC,
|
|
1
|
+
{"version":3,"file":"loader-edge.cjs.development.js","sources":["../src/random.ts","../src/variation.ts"],"sourcesContent":["export const getSeededRandomFunction = (strSeed: string) => {\n // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript\n function cyrb128(str) {\n let h1 = 1779033703,\n h2 = 3144134277,\n h3 = 1013904242,\n h4 = 2773480762;\n for (let i = 0, k; i < str.length; i++) {\n k = str.charCodeAt(i);\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n }\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n return [\n (h1 ^ h2 ^ h3 ^ h4) >>> 0,\n (h2 ^ h1) >>> 0,\n (h3 ^ h1) >>> 0,\n (h4 ^ h1) >>> 0,\n ];\n }\n function sfc32(a, b, c, d) {\n return function () {\n a >>>= 0;\n b >>>= 0;\n c >>>= 0;\n d >>>= 0;\n var t = (a + b) | 0;\n a = b ^ (b >>> 9);\n b = (c + (c << 3)) | 0;\n c = (c << 21) | (c >>> 11);\n d = (d + 1) | 0;\n t = (t + d) | 0;\n c = (c + t) | 0;\n return (t >>> 0) / 4294967296;\n };\n }\n const seed = cyrb128(strSeed);\n const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);\n return rand;\n};\n","import { Split } from '@plasmicapp/loader-fetcher';\nimport { getActiveVariation as getActiveVariationSplits } from '@plasmicapp/loader-splits';\nimport { getSeededRandomFunction } from './random';\n\nconst DELIMITER = '__pm__';\nconst PLASMIC_SEED = 'plasmic_seed';\nconst SEED_RANGE = 16;\n\ntype Traits = Record<string, string | number | boolean>;\n\nconst getSeed = () => {\n return `${Math.floor(Math.random() * SEED_RANGE)}`;\n};\n\nexport const rewriteWithoutTraits = (url: string) => {\n const [path, ...traitssArr] = url.split(DELIMITER);\n const traits = traitssArr.reduce((acc, elem) => {\n const [key, value] = elem.split('=');\n return {\n ...acc,\n [key]: value,\n };\n }, {});\n return {\n path:\n path === '/'\n ? path\n : path.endsWith('/')\n ? path.substring(0, path.length - 1)\n : path,\n traits,\n };\n};\n\nconst expandTraits = (traits: Traits) => {\n const cmp = (a: string, b: string) => {\n return a < b ? -1 : a > b ? 1 : 0;\n };\n return Object.keys(traits)\n .sort(cmp)\n .map((key) => `${DELIMITER}${key}=${traits[key]}`)\n .join('');\n};\n\nexport const rewriteWithTraits = (path: string, traits: Traits) => {\n return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;\n};\n\nexport const generateAllPaths = (path: string) => {\n const paths = [\n path,\n ...Array(SEED_RANGE)\n .fill(0)\n .map(\n (_, idx) =>\n `${path}${path.endsWith('/') ? '' : '/'}__pm__${PLASMIC_SEED}=${idx}`\n ),\n ];\n return paths;\n};\n\nexport const getMiddlewareResponse = (opts: {\n path: string;\n traits: Traits;\n cookies: Record<string, string>;\n}) => {\n const newCookies: { key: string; value: string }[] = [];\n const seed = opts.cookies[PLASMIC_SEED] || getSeed();\n if (!opts.cookies[PLASMIC_SEED]) {\n newCookies.push({\n key: PLASMIC_SEED,\n value: seed,\n });\n }\n return {\n pathname: rewriteWithTraits(opts.path, {\n [PLASMIC_SEED]: seed,\n ...opts.traits,\n }),\n cookies: newCookies,\n };\n};\n\nexport const getActiveVariation = (opts: {\n splits: Split[];\n traits: Record<string, string | number | boolean>;\n path: string;\n}) => {\n const { splits, traits, path } = opts;\n return getActiveVariationSplits({\n splits,\n traits: {\n pageUrl: path,\n ...traits,\n },\n getKnownValue: () => undefined,\n updateKnownValue: () => null,\n getRandomValue: (key) => {\n const rand = getSeededRandomFunction((traits[PLASMIC_SEED] ?? '') + key);\n return rand();\n },\n });\n};\n"],"names":["getSeededRandomFunction","strSeed","cyrb128","str","h1","h2","h3","h4","i","k","length","charCodeAt","Math","imul","sfc32","a","b","c","d","t","seed","rand","DELIMITER","PLASMIC_SEED","SEED_RANGE","getSeed","floor","random","rewriteWithoutTraits","url","path","traitssArr","split","traits","reduce","acc","elem","key","value","endsWith","substring","expandTraits","cmp","Object","keys","sort","map","join","rewriteWithTraits","generateAllPaths","paths","Array","fill","_","idx","getMiddlewareResponse","opts","newCookies","cookies","push","pathname","getActiveVariation","splits","getActiveVariationSplits","pageUrl","getKnownValue","undefined","updateKnownValue","getRandomValue"],"mappings":";;;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cjs.production.min.js","sources":["../src/random.ts","../src/variation.ts"],"sourcesContent":["export const getSeededRandomFunction = (strSeed: string) => {\n // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript\n function cyrb128(str) {\n let h1 = 1779033703,\n h2 = 3144134277,\n h3 = 1013904242,\n h4 = 2773480762;\n for (let i = 0, k; i < str.length; i++) {\n k = str.charCodeAt(i);\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n }\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n return [\n (h1 ^ h2 ^ h3 ^ h4) >>> 0,\n (h2 ^ h1) >>> 0,\n (h3 ^ h1) >>> 0,\n (h4 ^ h1) >>> 0,\n ];\n }\n function sfc32(a, b, c, d) {\n return function () {\n a >>>= 0;\n b >>>= 0;\n c >>>= 0;\n d >>>= 0;\n var t = (a + b) | 0;\n a = b ^ (b >>> 9);\n b = (c + (c << 3)) | 0;\n c = (c << 21) | (c >>> 11);\n d = (d + 1) | 0;\n t = (t + d) | 0;\n c = (c + t) | 0;\n return (t >>> 0) / 4294967296;\n };\n }\n const seed = cyrb128(strSeed);\n const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);\n return rand;\n};\n","import { Split } from '@plasmicapp/loader-fetcher';\nimport { getActiveVariation as getActiveVariationSplits } from '@plasmicapp/loader-splits';\nimport { getSeededRandomFunction } from './random';\n\nconst DELIMITER = '__pm__';\nconst PLASMIC_SEED = 'plasmic_seed';\nconst SEED_RANGE = 16;\n\ntype Traits = Record<string, string | number | boolean>;\n\nconst getSeed = () => {\n return `${Math.floor(Math.random() * SEED_RANGE)}`;\n};\n\nexport const rewriteWithoutTraits = (url: string) => {\n const [path, ...traitssArr] = url.split(DELIMITER);\n const traits = traitssArr.reduce((acc, elem) => {\n const [key, value] = elem.split('=');\n return {\n ...acc,\n [key]: value,\n };\n }, {});\n return {\n path:\n path === '/'\n ? path\n : path.endsWith('/')\n ? path.substring(0, path.length - 1)\n : path,\n traits,\n };\n};\n\nconst expandTraits = (traits: Traits) => {\n const cmp = (a: string, b: string) => {\n return a < b ? -1 : a > b ? 1 : 0;\n };\n return Object.keys(traits)\n .sort(cmp)\n .map((key) => `${DELIMITER}${key}=${traits[key]}`)\n .join('');\n};\n\nexport const rewriteWithTraits = (path: string, traits: Traits) => {\n return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;\n};\n\nexport const generateAllPaths = (path: string) => {\n const paths = [\n path,\n ...Array(SEED_RANGE)\n .fill(0)\n .map(\n (_, idx) =>\n `${path}${path.endsWith('/') ? '' : '/'}__pm__${PLASMIC_SEED}=${idx}`\n ),\n ];\n return paths;\n};\n\nexport const getMiddlewareResponse = (opts: {\n path: string;\n traits: Traits;\n cookies: Record<string, string>;\n}) => {\n const newCookies: { key: string; value: string }[] = [];\n const seed = opts.cookies[PLASMIC_SEED] || getSeed();\n if (!opts.cookies[PLASMIC_SEED]) {\n newCookies.push({\n key: PLASMIC_SEED,\n value: seed,\n });\n }\n return {\n pathname: rewriteWithTraits(opts.path, {\n [PLASMIC_SEED]: seed,\n ...opts.traits,\n }),\n cookies: newCookies,\n };\n};\n\nexport const getActiveVariation = (opts: {\n splits: Split[];\n traits: Record<string, string | number | boolean>;\n path: string;\n}) => {\n const { splits, traits, path } = opts;\n return getActiveVariationSplits({\n splits,\n traits: {\n pageUrl: path,\n ...traits,\n },\n getKnownValue: () => undefined,\n updateKnownValue: () => null,\n getRandomValue: (key) => {\n const rand = getSeededRandomFunction((traits[PLASMIC_SEED] ?? '') + key);\n return rand();\n },\n });\n};\n"],"names":["rewriteWithTraits","path","traits","endsWith","Object","keys","sort","a","b","map","key","join","expandTraits","Array","fill","_","idx","opts","splits","getActiveVariationSplits","pageUrl","getKnownValue","updateKnownValue","getRandomValue","strSeed","seed","str","h1","h2","h3","h4","k","i","length","charCodeAt","Math","imul","cyrb128","c","d","t","getSeededRandomFunction","rand","newCookies","cookies","floor","random","push","value","pathname","url","traitssArr","split","reduce","acc","elem","substring"],"mappings":"+GAAO,MC4CMA,EAAoB,CAACC,EAAcC,OACpCD,IAAOA,EAAKE,SAAS,KAAO,GAAK,MAXvBD,CAAAA,GAIbE,OAAOC,KAAKH,GAChBI,KAJS,CAACC,EAAWC,IACfD,EAAIC,GAAK,EAAID,EAAIC,EAAI,EAAI,GAI/BC,IAAKC,YAAuBA,KAAOR,EAAOQ,MAC1CC,KAAK,IAIyCC,CAAaV,8BAG/BD,GACjB,CACZA,KACGY,MA7CY,IA8CZC,KAAK,GACLL,IACC,CAACM,EAAGC,OACCf,IAAOA,EAAKE,SAAS,KAAO,GAAK,yBAA4Ba,iCA4BvCC,
|
|
1
|
+
{"version":3,"file":"loader-edge.cjs.production.min.js","sources":["../src/random.ts","../src/variation.ts"],"sourcesContent":["export const getSeededRandomFunction = (strSeed: string) => {\n // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript\n function cyrb128(str) {\n let h1 = 1779033703,\n h2 = 3144134277,\n h3 = 1013904242,\n h4 = 2773480762;\n for (let i = 0, k; i < str.length; i++) {\n k = str.charCodeAt(i);\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n }\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n return [\n (h1 ^ h2 ^ h3 ^ h4) >>> 0,\n (h2 ^ h1) >>> 0,\n (h3 ^ h1) >>> 0,\n (h4 ^ h1) >>> 0,\n ];\n }\n function sfc32(a, b, c, d) {\n return function () {\n a >>>= 0;\n b >>>= 0;\n c >>>= 0;\n d >>>= 0;\n var t = (a + b) | 0;\n a = b ^ (b >>> 9);\n b = (c + (c << 3)) | 0;\n c = (c << 21) | (c >>> 11);\n d = (d + 1) | 0;\n t = (t + d) | 0;\n c = (c + t) | 0;\n return (t >>> 0) / 4294967296;\n };\n }\n const seed = cyrb128(strSeed);\n const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);\n return rand;\n};\n","import { Split } from '@plasmicapp/loader-fetcher';\nimport { getActiveVariation as getActiveVariationSplits } from '@plasmicapp/loader-splits';\nimport { getSeededRandomFunction } from './random';\n\nconst DELIMITER = '__pm__';\nconst PLASMIC_SEED = 'plasmic_seed';\nconst SEED_RANGE = 16;\n\ntype Traits = Record<string, string | number | boolean>;\n\nconst getSeed = () => {\n return `${Math.floor(Math.random() * SEED_RANGE)}`;\n};\n\nexport const rewriteWithoutTraits = (url: string) => {\n const [path, ...traitssArr] = url.split(DELIMITER);\n const traits = traitssArr.reduce((acc, elem) => {\n const [key, value] = elem.split('=');\n return {\n ...acc,\n [key]: value,\n };\n }, {});\n return {\n path:\n path === '/'\n ? path\n : path.endsWith('/')\n ? path.substring(0, path.length - 1)\n : path,\n traits,\n };\n};\n\nconst expandTraits = (traits: Traits) => {\n const cmp = (a: string, b: string) => {\n return a < b ? -1 : a > b ? 1 : 0;\n };\n return Object.keys(traits)\n .sort(cmp)\n .map((key) => `${DELIMITER}${key}=${traits[key]}`)\n .join('');\n};\n\nexport const rewriteWithTraits = (path: string, traits: Traits) => {\n return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;\n};\n\nexport const generateAllPaths = (path: string) => {\n const paths = [\n path,\n ...Array(SEED_RANGE)\n .fill(0)\n .map(\n (_, idx) =>\n `${path}${path.endsWith('/') ? '' : '/'}__pm__${PLASMIC_SEED}=${idx}`\n ),\n ];\n return paths;\n};\n\nexport const getMiddlewareResponse = (opts: {\n path: string;\n traits: Traits;\n cookies: Record<string, string>;\n}) => {\n const newCookies: { key: string; value: string }[] = [];\n const seed = opts.cookies[PLASMIC_SEED] || getSeed();\n if (!opts.cookies[PLASMIC_SEED]) {\n newCookies.push({\n key: PLASMIC_SEED,\n value: seed,\n });\n }\n return {\n pathname: rewriteWithTraits(opts.path, {\n [PLASMIC_SEED]: seed,\n ...opts.traits,\n }),\n cookies: newCookies,\n };\n};\n\nexport const getActiveVariation = (opts: {\n splits: Split[];\n traits: Record<string, string | number | boolean>;\n path: string;\n}) => {\n const { splits, traits, path } = opts;\n return getActiveVariationSplits({\n splits,\n traits: {\n pageUrl: path,\n ...traits,\n },\n getKnownValue: () => undefined,\n updateKnownValue: () => null,\n getRandomValue: (key) => {\n const rand = getSeededRandomFunction((traits[PLASMIC_SEED] ?? '') + key);\n return rand();\n },\n });\n};\n"],"names":["rewriteWithTraits","path","traits","endsWith","Object","keys","sort","a","b","map","key","join","expandTraits","Array","fill","_","idx","opts","splits","getActiveVariationSplits","pageUrl","getKnownValue","updateKnownValue","getRandomValue","strSeed","seed","str","h1","h2","h3","h4","k","i","length","charCodeAt","Math","imul","cyrb128","c","d","t","getSeededRandomFunction","rand","newCookies","cookies","floor","random","push","value","pathname","plasmic_seed","url","traitssArr","split","reduce","acc","elem","[object Object]","substring"],"mappings":"+GAAO,MC4CMA,EAAoB,CAACC,EAAcC,OACpCD,IAAOA,EAAKE,SAAS,KAAO,GAAK,MAXvBD,CAAAA,GAIbE,OAAOC,KAAKH,GAChBI,KAJS,CAACC,EAAWC,IACfD,EAAIC,GAAK,EAAID,EAAIC,EAAI,EAAI,GAI/BC,IAAKC,YAAuBA,KAAOR,EAAOQ,MAC1CC,KAAK,IAIyCC,CAAaV,8BAG/BD,GACjB,CACZA,KACGY,MA7CY,IA8CZC,KAAK,GACLL,IACC,CAACM,EAAGC,O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,EAIrBA,GAHAA,EAAKA,GAAK,GAAOA,IAAM,KAEvBE,EAAKA,GADLD,EAAS,GALTA,KAAO,GAKO,GACA,GACA,GACNC,IAAM,GAAK,aC4DNC,WAAyBvC,EAAmB,gBAAK,IAAMQ,EAC7DgC,qCAtCyBzB,IAKpC,MAAM0B,EAA+C,GAC/ClB,EAAOR,EAAK2B,QAAoB,iBAxD5BT,KAAKU,MALE,GAKIV,KAAKW,UA+D1B,OANK7B,EAAK2B,QAAoB,cAC5BD,EAAWI,KAAK,CACdrC,IAjEe,eAkEfsC,MAAOvB,IAGJ,CACLwB,SAAUjD,EAAkBiB,EAAKhB,KAAM,CACrCiD,aAAgBzB,KACbR,EAAKf,SAEV0C,QAASD,6DAjEwBQ,IACnC,MAAOlD,KAASmD,GAAcD,EAAIE,MAXlB,UAYVnD,EAASkD,EAAWE,OAAO,CAACC,EAAKC,KACrC,MAAO9C,EAAKsC,GAASQ,EAAKH,MAAM,KAChC,MAAO,IACFE,EACHE,CAAC/C,GAAMsC,IAER,IACH,MAAO,CACL/C,KACW,MAATA,EACIA,EACAA,EAAKE,SAAS,KACdF,EAAKyD,UAAU,EAAGzD,EAAKgC,OAAS,GAChChC,EACNC,OAAAA"}
|
package/dist/loader-edge.esm.js
CHANGED
|
@@ -4,10 +4,9 @@ const getSeededRandomFunction = strSeed => {
|
|
|
4
4
|
// https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
|
|
5
5
|
function cyrb128(str) {
|
|
6
6
|
let h1 = 1779033703,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
h2 = 3144134277,
|
|
8
|
+
h3 = 1013904242,
|
|
9
|
+
h4 = 2773480762;
|
|
11
10
|
for (let i = 0, k; i < str.length; i++) {
|
|
12
11
|
k = str.charCodeAt(i);
|
|
13
12
|
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
|
|
@@ -15,14 +14,12 @@ const getSeededRandomFunction = strSeed => {
|
|
|
15
14
|
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
|
|
16
15
|
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
h1 = Math.imul(h3 ^ h1 >>> 18, 597399067);
|
|
20
18
|
h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233);
|
|
21
19
|
h3 = Math.imul(h1 ^ h3 >>> 17, 951274213);
|
|
22
20
|
h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179);
|
|
23
21
|
return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
function sfc32(a, b, c, d) {
|
|
27
24
|
return function () {
|
|
28
25
|
a >>>= 0;
|
|
@@ -39,7 +36,6 @@ const getSeededRandomFunction = strSeed => {
|
|
|
39
36
|
return (t >>> 0) / 4294967296;
|
|
40
37
|
};
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
const seed = cyrb128(strSeed);
|
|
44
40
|
const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);
|
|
45
41
|
return rand;
|
|
@@ -48,16 +44,15 @@ const getSeededRandomFunction = strSeed => {
|
|
|
48
44
|
const DELIMITER = '__pm__';
|
|
49
45
|
const PLASMIC_SEED = 'plasmic_seed';
|
|
50
46
|
const SEED_RANGE = 16;
|
|
51
|
-
|
|
52
47
|
const getSeed = () => {
|
|
53
48
|
return `${Math.floor(Math.random() * SEED_RANGE)}`;
|
|
54
49
|
};
|
|
55
|
-
|
|
56
50
|
const rewriteWithoutTraits = url => {
|
|
57
51
|
const [path, ...traitssArr] = url.split(DELIMITER);
|
|
58
52
|
const traits = traitssArr.reduce((acc, elem) => {
|
|
59
53
|
const [key, value] = elem.split('=');
|
|
60
|
-
return {
|
|
54
|
+
return {
|
|
55
|
+
...acc,
|
|
61
56
|
[key]: value
|
|
62
57
|
};
|
|
63
58
|
}, {});
|
|
@@ -66,15 +61,12 @@ const rewriteWithoutTraits = url => {
|
|
|
66
61
|
traits
|
|
67
62
|
};
|
|
68
63
|
};
|
|
69
|
-
|
|
70
64
|
const expandTraits = traits => {
|
|
71
65
|
const cmp = (a, b) => {
|
|
72
66
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
73
67
|
};
|
|
74
|
-
|
|
75
68
|
return Object.keys(traits).sort(cmp).map(key => `${DELIMITER}${key}=${traits[key]}`).join('');
|
|
76
69
|
};
|
|
77
|
-
|
|
78
70
|
const rewriteWithTraits = (path, traits) => {
|
|
79
71
|
return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;
|
|
80
72
|
};
|
|
@@ -85,14 +77,12 @@ const generateAllPaths = path => {
|
|
|
85
77
|
const getMiddlewareResponse = opts => {
|
|
86
78
|
const newCookies = [];
|
|
87
79
|
const seed = opts.cookies[PLASMIC_SEED] || getSeed();
|
|
88
|
-
|
|
89
80
|
if (!opts.cookies[PLASMIC_SEED]) {
|
|
90
81
|
newCookies.push({
|
|
91
82
|
key: PLASMIC_SEED,
|
|
92
83
|
value: seed
|
|
93
84
|
});
|
|
94
85
|
}
|
|
95
|
-
|
|
96
86
|
return {
|
|
97
87
|
pathname: rewriteWithTraits(opts.path, {
|
|
98
88
|
[PLASMIC_SEED]: seed,
|
|
@@ -117,7 +107,6 @@ const getActiveVariation = opts => {
|
|
|
117
107
|
updateKnownValue: () => null,
|
|
118
108
|
getRandomValue: key => {
|
|
119
109
|
var _traits$PLASMIC_SEED;
|
|
120
|
-
|
|
121
110
|
const rand = getSeededRandomFunction(((_traits$PLASMIC_SEED = traits[PLASMIC_SEED]) != null ? _traits$PLASMIC_SEED : '') + key);
|
|
122
111
|
return rand();
|
|
123
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-edge.esm.js","sources":["../src/random.ts","../src/variation.ts"],"sourcesContent":["export const getSeededRandomFunction = (strSeed: string) => {\n // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript\n function cyrb128(str) {\n let h1 = 1779033703,\n h2 = 3144134277,\n h3 = 1013904242,\n h4 = 2773480762;\n for (let i = 0, k; i < str.length; i++) {\n k = str.charCodeAt(i);\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n }\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n return [\n (h1 ^ h2 ^ h3 ^ h4) >>> 0,\n (h2 ^ h1) >>> 0,\n (h3 ^ h1) >>> 0,\n (h4 ^ h1) >>> 0,\n ];\n }\n function sfc32(a, b, c, d) {\n return function () {\n a >>>= 0;\n b >>>= 0;\n c >>>= 0;\n d >>>= 0;\n var t = (a + b) | 0;\n a = b ^ (b >>> 9);\n b = (c + (c << 3)) | 0;\n c = (c << 21) | (c >>> 11);\n d = (d + 1) | 0;\n t = (t + d) | 0;\n c = (c + t) | 0;\n return (t >>> 0) / 4294967296;\n };\n }\n const seed = cyrb128(strSeed);\n const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);\n return rand;\n};\n","import { Split } from '@plasmicapp/loader-fetcher';\nimport { getActiveVariation as getActiveVariationSplits } from '@plasmicapp/loader-splits';\nimport { getSeededRandomFunction } from './random';\n\nconst DELIMITER = '__pm__';\nconst PLASMIC_SEED = 'plasmic_seed';\nconst SEED_RANGE = 16;\n\ntype Traits = Record<string, string | number | boolean>;\n\nconst getSeed = () => {\n return `${Math.floor(Math.random() * SEED_RANGE)}`;\n};\n\nexport const rewriteWithoutTraits = (url: string) => {\n const [path, ...traitssArr] = url.split(DELIMITER);\n const traits = traitssArr.reduce((acc, elem) => {\n const [key, value] = elem.split('=');\n return {\n ...acc,\n [key]: value,\n };\n }, {});\n return {\n path:\n path === '/'\n ? path\n : path.endsWith('/')\n ? path.substring(0, path.length - 1)\n : path,\n traits,\n };\n};\n\nconst expandTraits = (traits: Traits) => {\n const cmp = (a: string, b: string) => {\n return a < b ? -1 : a > b ? 1 : 0;\n };\n return Object.keys(traits)\n .sort(cmp)\n .map((key) => `${DELIMITER}${key}=${traits[key]}`)\n .join('');\n};\n\nexport const rewriteWithTraits = (path: string, traits: Traits) => {\n return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;\n};\n\nexport const generateAllPaths = (path: string) => {\n const paths = [\n path,\n ...Array(SEED_RANGE)\n .fill(0)\n .map(\n (_, idx) =>\n `${path}${path.endsWith('/') ? '' : '/'}__pm__${PLASMIC_SEED}=${idx}`\n ),\n ];\n return paths;\n};\n\nexport const getMiddlewareResponse = (opts: {\n path: string;\n traits: Traits;\n cookies: Record<string, string>;\n}) => {\n const newCookies: { key: string; value: string }[] = [];\n const seed = opts.cookies[PLASMIC_SEED] || getSeed();\n if (!opts.cookies[PLASMIC_SEED]) {\n newCookies.push({\n key: PLASMIC_SEED,\n value: seed,\n });\n }\n return {\n pathname: rewriteWithTraits(opts.path, {\n [PLASMIC_SEED]: seed,\n ...opts.traits,\n }),\n cookies: newCookies,\n };\n};\n\nexport const getActiveVariation = (opts: {\n splits: Split[];\n traits: Record<string, string | number | boolean>;\n path: string;\n}) => {\n const { splits, traits, path } = opts;\n return getActiveVariationSplits({\n splits,\n traits: {\n pageUrl: path,\n ...traits,\n },\n getKnownValue: () => undefined,\n updateKnownValue: () => null,\n getRandomValue: (key) => {\n const rand = getSeededRandomFunction((traits[PLASMIC_SEED] ?? '') + key);\n return rand();\n },\n });\n};\n"],"names":["getSeededRandomFunction","strSeed","cyrb128","str","h1","h2","h3","h4","i","k","length","charCodeAt","Math","imul","sfc32","a","b","c","d","t","seed","rand","DELIMITER","PLASMIC_SEED","SEED_RANGE","getSeed","floor","random","rewriteWithoutTraits","url","path","traitssArr","split","traits","reduce","acc","elem","key","value","endsWith","substring","expandTraits","cmp","Object","keys","sort","map","join","rewriteWithTraits","generateAllPaths","paths","Array","fill","_","idx","getMiddlewareResponse","opts","newCookies","cookies","push","pathname","getActiveVariation","splits","getActiveVariationSplits","pageUrl","getKnownValue","undefined","updateKnownValue","getRandomValue"],"mappings":";;AAAO,MAAMA,uBAAuB,GAAIC,
|
|
1
|
+
{"version":3,"file":"loader-edge.esm.js","sources":["../src/random.ts","../src/variation.ts"],"sourcesContent":["export const getSeededRandomFunction = (strSeed: string) => {\n // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript\n function cyrb128(str) {\n let h1 = 1779033703,\n h2 = 3144134277,\n h3 = 1013904242,\n h4 = 2773480762;\n for (let i = 0, k; i < str.length; i++) {\n k = str.charCodeAt(i);\n h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n }\n h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n return [\n (h1 ^ h2 ^ h3 ^ h4) >>> 0,\n (h2 ^ h1) >>> 0,\n (h3 ^ h1) >>> 0,\n (h4 ^ h1) >>> 0,\n ];\n }\n function sfc32(a, b, c, d) {\n return function () {\n a >>>= 0;\n b >>>= 0;\n c >>>= 0;\n d >>>= 0;\n var t = (a + b) | 0;\n a = b ^ (b >>> 9);\n b = (c + (c << 3)) | 0;\n c = (c << 21) | (c >>> 11);\n d = (d + 1) | 0;\n t = (t + d) | 0;\n c = (c + t) | 0;\n return (t >>> 0) / 4294967296;\n };\n }\n const seed = cyrb128(strSeed);\n const rand = sfc32(seed[0], seed[1], seed[2], seed[3]);\n return rand;\n};\n","import { Split } from '@plasmicapp/loader-fetcher';\nimport { getActiveVariation as getActiveVariationSplits } from '@plasmicapp/loader-splits';\nimport { getSeededRandomFunction } from './random';\n\nconst DELIMITER = '__pm__';\nconst PLASMIC_SEED = 'plasmic_seed';\nconst SEED_RANGE = 16;\n\ntype Traits = Record<string, string | number | boolean>;\n\nconst getSeed = () => {\n return `${Math.floor(Math.random() * SEED_RANGE)}`;\n};\n\nexport const rewriteWithoutTraits = (url: string) => {\n const [path, ...traitssArr] = url.split(DELIMITER);\n const traits = traitssArr.reduce((acc, elem) => {\n const [key, value] = elem.split('=');\n return {\n ...acc,\n [key]: value,\n };\n }, {});\n return {\n path:\n path === '/'\n ? path\n : path.endsWith('/')\n ? path.substring(0, path.length - 1)\n : path,\n traits,\n };\n};\n\nconst expandTraits = (traits: Traits) => {\n const cmp = (a: string, b: string) => {\n return a < b ? -1 : a > b ? 1 : 0;\n };\n return Object.keys(traits)\n .sort(cmp)\n .map((key) => `${DELIMITER}${key}=${traits[key]}`)\n .join('');\n};\n\nexport const rewriteWithTraits = (path: string, traits: Traits) => {\n return `${path}${path.endsWith('/') ? '' : '/'}${expandTraits(traits)}`;\n};\n\nexport const generateAllPaths = (path: string) => {\n const paths = [\n path,\n ...Array(SEED_RANGE)\n .fill(0)\n .map(\n (_, idx) =>\n `${path}${path.endsWith('/') ? '' : '/'}__pm__${PLASMIC_SEED}=${idx}`\n ),\n ];\n return paths;\n};\n\nexport const getMiddlewareResponse = (opts: {\n path: string;\n traits: Traits;\n cookies: Record<string, string>;\n}) => {\n const newCookies: { key: string; value: string }[] = [];\n const seed = opts.cookies[PLASMIC_SEED] || getSeed();\n if (!opts.cookies[PLASMIC_SEED]) {\n newCookies.push({\n key: PLASMIC_SEED,\n value: seed,\n });\n }\n return {\n pathname: rewriteWithTraits(opts.path, {\n [PLASMIC_SEED]: seed,\n ...opts.traits,\n }),\n cookies: newCookies,\n };\n};\n\nexport const getActiveVariation = (opts: {\n splits: Split[];\n traits: Record<string, string | number | boolean>;\n path: string;\n}) => {\n const { splits, traits, path } = opts;\n return getActiveVariationSplits({\n splits,\n traits: {\n pageUrl: path,\n ...traits,\n },\n getKnownValue: () => undefined,\n updateKnownValue: () => null,\n getRandomValue: (key) => {\n const rand = getSeededRandomFunction((traits[PLASMIC_SEED] ?? '') + key);\n return rand();\n },\n });\n};\n"],"names":["getSeededRandomFunction","strSeed","cyrb128","str","h1","h2","h3","h4","i","k","length","charCodeAt","Math","imul","sfc32","a","b","c","d","t","seed","rand","DELIMITER","PLASMIC_SEED","SEED_RANGE","getSeed","floor","random","rewriteWithoutTraits","url","path","traitssArr","split","traits","reduce","acc","elem","key","value","endsWith","substring","expandTraits","cmp","Object","keys","sort","map","join","rewriteWithTraits","generateAllPaths","paths","Array","fill","_","idx","getMiddlewareResponse","opts","newCookies","cookies","push","pathname","getActiveVariation","splits","getActiveVariationSplits","pageUrl","getKnownValue","undefined","updateKnownValue","getRandomValue"],"mappings":";;AAAO,MAAMA,uBAAuB,GAAIC,OAAe;;EAErD,SAASC,OAAO,CAACC,GAAG;IAClB,IAAIC,EAAE,GAAG,UAAU;MACjBC,EAAE,GAAG,UAAU;MACfC,EAAE,GAAG,UAAU;MACfC,EAAE,GAAG,UAAU;IACjB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEC,CAAC,EAAED,CAAC,GAAGL,GAAG,CAACO,MAAM,EAAEF,CAAC,EAAE,EAAE;MACtCC,CAAC,GAAGN,GAAG,CAACQ,UAAU,CAACH,CAAC,CAAC;MACrBJ,EAAE,GAAGC,EAAE,GAAGO,IAAI,CAACC,IAAI,CAACT,EAAE,GAAGK,CAAC,EAAE,SAAS,CAAC;MACtCJ,EAAE,GAAGC,EAAE,GAAGM,IAAI,CAACC,IAAI,CAACR,EAAE,GAAGI,CAAC,EAAE,UAAU,CAAC;MACvCH,EAAE,GAAGC,EAAE,GAAGK,IAAI,CA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C1B,IAAI,EAAE;MACrC,CAACP,YAAY,GAAGH,IAAI;MACpB,GAAGoC,IAAI,CAACvB;KACT,CAAC;IACFyB,OAAO,EAAED;GACV;AACH,CAAC;AAED,MAAaI,kBAAkB,GAAIL,IAIlC;EACC,MAAM;IAAEM,MAAM;IAAE7B,MAAM;IAAEH;GAAM,GAAG0B,IAAI;EACrC,OAAOO,oBAAwB,CAAC;IAC9BD,MAAM;IACN7B,MAAM,EAAE;MACN+B,OAAO,EAAElC,IAAI;MACb,GAAGG;KACJ;IACDgC,aAAa,EAAE,MAAMC,SAAS;IAC9BC,gBAAgB,EAAE,MAAM,IAAI;IAC5BC,cAAc,EAAG/B,GAAG;;MAClB,MAAMhB,IAAI,GAAGrB,uBAAuB,CAAC,yBAACiC,MAAM,CAACV,YAAY,CAAC,mCAAI,EAAE,IAAIc,GAAG,CAAC;MACxE,OAAOhB,IAAI,EAAE;;GAEhB,CAAC;AACJ,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.21",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"typescript": "^4.3.2"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@plasmicapp/loader-fetcher": "1.0.
|
|
57
|
-
"@plasmicapp/loader-splits": "1.0.
|
|
56
|
+
"@plasmicapp/loader-fetcher": "1.0.15",
|
|
57
|
+
"@plasmicapp/loader-splits": "1.0.20"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "e282c9cca3a168a822b34a1a5e6de3a6a072c00f"
|
|
63
63
|
}
|