catom 2.1.0 → 2.5.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.
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emitCSS = exports.createValueHash = void 0;
4
- const constants_1 = require("./constants");
5
- const hash_1 = require("./hash");
6
- const CSS_PROPERTY_MAP = new Map();
7
- const MEDIA_QUERY_MAP = new Map();
8
- const PSEUDO_SELECTOR_MAP = new Map();
9
- // function clearMaps(): void {
10
- // CSS_PROPERTY_MAP.clear();
11
- // MEDIA_QUERY_MAP.clear();
12
- // PSEUDO_SELECTOR_MAP.clear();
13
- // }
14
- function toCSSProp(prop) {
15
- return prop.replace(constants_1.KEBAB_CASE_REGEXP, "$1-$2").toLowerCase();
16
- }
17
- function makeCSSCompat(str) {
18
- if (constants_1.PREFIX_WITH_UNDERSCORE.indexOf(str[0]) > -1)
19
- return `_${str}`;
20
- return str;
21
- }
22
- const sanitizeRegExp = /([^\w]|_)/g;
23
- function createValueHash(key, unparsed, hashable) {
24
- key = key.trim();
25
- const value = String(unparsed).trim();
26
- const MEDIA_QUERY = hashable && hashable.media;
27
- const PSEUDO_SELECTOR = hashable && hashable.pseudo;
28
- const isSpec = MEDIA_QUERY || PSEUDO_SELECTOR;
29
- // example: const rawCSSRule = "margin:auto;"
30
- const rawCSSRule = `${toCSSProp(key)}:${value};`;
31
- // a unique rule will be one with a different media/pseudo rule + key&value
32
- const identity = ((hashable && (MEDIA_QUERY || PSEUDO_SELECTOR)) || "").trim() + rawCSSRule;
33
- let cache;
34
- const $map = isSpec && MEDIA_QUERY ? MEDIA_QUERY_MAP : PSEUDO_SELECTOR_MAP;
35
- let fetchMap;
36
- if ($map) {
37
- fetchMap = $map.get(isSpec);
38
- if (!fetchMap) {
39
- fetchMap = new Map();
40
- $map.set(isSpec, fetchMap);
41
- }
42
- }
43
- if (isSpec) {
44
- cache = fetchMap.get(identity);
45
- }
46
- else {
47
- cache = CSS_PROPERTY_MAP.get(identity);
48
- }
49
- if (cache)
50
- return cache.class;
51
- const hash = makeCSSCompat((0, hash_1.murmur2)(identity));
52
- const obj = { class: hash, cssRule: rawCSSRule };
53
- if (isSpec) {
54
- fetchMap.set(identity, obj);
55
- }
56
- else {
57
- CSS_PROPERTY_MAP.set(identity, obj);
58
- }
59
- return hash;
60
- }
61
- exports.createValueHash = createValueHash;
62
- const toCSS = (m) => Array.from(m.values())
63
- .map((v) => `.${v.class} { ${v.cssRule} }`)
64
- .sort()
65
- .join("\n");
66
- function mergeDuplicateRules(value, dedupedPropMap, suffix = "") {
67
- const cls = `.${value.class}${suffix}`;
68
- const rule = value.cssRule;
69
- let arr = dedupedPropMap.get(rule);
70
- if (!arr) {
71
- arr = new Set();
72
- dedupedPropMap.set(rule, arr);
73
- }
74
- arr.add(cls);
75
- }
76
- function emitCSS() {
77
- const dedupedPropMap = new Map();
78
- Array.from(CSS_PROPERTY_MAP.values()).forEach((v) => mergeDuplicateRules(v, dedupedPropMap));
79
- Array.from(PSEUDO_SELECTOR_MAP.entries()).forEach(([k, v]) => Array.from(v.values())
80
- .sort()
81
- .forEach((prop) => mergeDuplicateRules(prop, dedupedPropMap, k)));
82
- const mediaQueries = Array.from(MEDIA_QUERY_MAP.entries())
83
- .map(([k, v]) => `@media ${k} {\n${toCSS(v)}\n}\n`)
84
- .sort()
85
- .join("\n");
86
- const cssProps = Array.from(dedupedPropMap.entries())
87
- .map(([rule, classNames]) => `${Array.from(classNames).join(",\n")}{ ${rule} }`)
88
- .sort()
89
- .join("\n");
90
- return [cssProps, mediaQueries].join("\n");
91
- }
92
- exports.emitCSS = emitCSS;
@@ -1 +0,0 @@
1
- export declare function murmur2(str: string): string;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- // from https://github.com/emotion-js/emotion/blob/master/packages/hash/src/index.js
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.murmur2 = void 0;
5
- function murmur2(str) {
6
- // 'm' and 'r' are mixing constants generated offline.
7
- // They're not really 'magic', they just happen to work well.
8
- // const m = 0x5bd1e995;
9
- // const r = 24;
10
- // Initialize the hash
11
- var h = 0;
12
- // Mix 4 bytes at a time into the hash
13
- var k, i = 0, len = str.length;
14
- for (; len >= 4; ++i, len -= 4) {
15
- k =
16
- (str.charCodeAt(i) & 0xff) |
17
- ((str.charCodeAt(++i) & 0xff) << 8) |
18
- ((str.charCodeAt(++i) & 0xff) << 16) |
19
- ((str.charCodeAt(++i) & 0xff) << 24);
20
- k =
21
- /* Math.imul(k, m): */
22
- (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0xe995) << 16);
23
- k ^= /* k >>> r: */ k >>> 24;
24
- h =
25
- /* Math.imul(k, m): */
26
- ((k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0xe995) << 16)) ^
27
- /* Math.imul(h, m): */
28
- ((h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16));
29
- }
30
- // Handle the last few bytes of the input array
31
- switch (len) {
32
- case 3:
33
- h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
34
- case 2:
35
- h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
36
- case 1:
37
- h ^= str.charCodeAt(i) & 0xff;
38
- h =
39
- /* Math.imul(h, m): */
40
- (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16);
41
- }
42
- // Do a few final mixes of the hash to ensure the last few
43
- // bytes are well-incorporated.
44
- h ^= h >>> 13;
45
- h =
46
- /* Math.imul(h, m): */
47
- (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16);
48
- return ((h ^ (h >>> 15)) >>> 0).toString(36);
49
- }
50
- exports.murmur2 = murmur2;
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "CommonJS",
4
- "alwaysStrict": true,
5
- "declaration": true,
6
- "incremental": true,
7
- "target": "ESNext",
8
- "outDir": "dist/",
9
- "moduleResolution": "Node",
10
- "esModuleInterop": true
11
- },
12
- "exclude": ["dist/", "./css.js", "./babelPlugin.js"],
13
- "include": ["./src/**/*.ts"]
14
- }