@merkur/plugin-css-scrambler 0.38.0 → 0.39.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.
package/lib/index.cjs CHANGED
@@ -3,15 +3,8 @@
3
3
  var core = require('@merkur/core');
4
4
  var classnames = require('classnames');
5
5
 
6
- const CLASSNAME_CHARS = (
7
- 'abcdefghijklmnopqrstuvwxyz' +
8
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
9
- '-'
10
- ).split('');
11
- const EXTENDED_CLASSNAME_CHARS = (
12
- CLASSNAME_CHARS.join('') + '0123456789'
13
- ).split('');
14
-
6
+ const CLASSNAME_CHARS = ('abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '-').split('');
7
+ const EXTENDED_CLASSNAME_CHARS = (CLASSNAME_CHARS.join('') + '0123456789').split('');
15
8
  function numberToCssClass(number) {
16
9
  if (number < CLASSNAME_CHARS.length) {
17
10
  return CLASSNAME_CHARS[number];
@@ -20,21 +13,16 @@ function numberToCssClass(number) {
20
13
  // we have to "shift" the number to adjust for the gap between base53 and
21
14
  // base64 encoding
22
15
  number += EXTENDED_CLASSNAME_CHARS.length - CLASSNAME_CHARS.length;
23
-
24
16
  let className = '';
25
17
  while (number >= CLASSNAME_CHARS.length) {
26
- className =
27
- EXTENDED_CLASSNAME_CHARS[number % EXTENDED_CLASSNAME_CHARS.length] +
28
- className;
18
+ className = EXTENDED_CLASSNAME_CHARS[number % EXTENDED_CLASSNAME_CHARS.length] + className;
29
19
  number = Math.floor(number / EXTENDED_CLASSNAME_CHARS.length);
30
20
  }
31
-
32
21
  if (number) {
33
22
  className = CLASSNAME_CHARS[number - 1] + className;
34
23
  } else {
35
24
  className = '_' + className;
36
25
  }
37
-
38
26
  return className;
39
27
  }
40
28
 
@@ -46,7 +34,6 @@ function scramblerFactory(hashingTable) {
46
34
  let uniqueHash, prefixes, mainParts;
47
35
  const prefixTable = hashingTable && new Map();
48
36
  const mainPartTable = hashingTable && new Map();
49
-
50
37
  if (hashingTable) {
51
38
  [uniqueHash, prefixes, mainParts] = hashingTable;
52
39
  for (let i = 0; i < prefixes.length; i++) {
@@ -56,34 +43,25 @@ function scramblerFactory(hashingTable) {
56
43
  mainPartTable.set(mainParts[i], numberToCssClass(i));
57
44
  }
58
45
  }
59
-
60
46
  return (widget, ...args) => {
61
47
  const classNamesSource = classnames(...args);
62
48
  if (!hashingTable) {
63
49
  return {
64
- className: classNamesSource,
50
+ className: classNamesSource
65
51
  };
66
52
  }
67
-
68
- const processedClasses = classNamesSource
69
- .split(/\s+/)
70
- .map((className) => {
71
- const parts = className.split('-');
72
- const prefix = parts[0];
73
- const mainPart = parts.slice(1).join('-');
74
- if (!prefixTable.has(prefix) || !mainPartTable.has(mainPart)) {
75
- return className;
76
- }
77
-
78
- return `${prefixTable.get(prefix)}_${mainPartTable.get(
79
- mainPart,
80
- )}_${uniqueHash}`;
81
- })
82
- .join(' ');
83
-
53
+ const processedClasses = classNamesSource.split(/\s+/).map(className => {
54
+ const parts = className.split('-');
55
+ const prefix = parts[0];
56
+ const mainPart = parts.slice(1).join('-');
57
+ if (!prefixTable.has(prefix) || !mainPartTable.has(mainPart)) {
58
+ return className;
59
+ }
60
+ return `${prefixTable.get(prefix)}_${mainPartTable.get(mainPart)}_${uniqueHash}`;
61
+ }).join(' ');
84
62
  return {
85
63
  className: processedClasses,
86
- 'data-class': classNamesSource,
64
+ 'data-class': classNamesSource
87
65
  };
88
66
  };
89
67
  }
@@ -91,27 +69,24 @@ function scramblerFactory(hashingTable) {
91
69
  function cssScramblePlugin() {
92
70
  return {
93
71
  async setup(widget, widgetDefinition) {
94
- const { classnameHashtable } = widgetDefinition;
72
+ const {
73
+ classnameHashtable
74
+ } = widgetDefinition;
95
75
  widget.$in.classNameScrambler = scramblerFactory(classnameHashtable);
96
-
97
76
  widget.cn = (...args) => widget.$in.classNameScrambler(...args).className;
98
-
99
77
  return widget;
100
78
  },
101
79
  async create(widget) {
102
80
  core.hookMethod(widget, 'info', infoHook);
103
-
104
81
  return widget;
105
- },
82
+ }
106
83
  };
107
84
  }
108
-
109
85
  async function infoHook(widget, originalInfo, ...rest) {
110
86
  const result = await originalInfo(...rest);
111
-
112
87
  return {
113
88
  classnameHashtable: widget.classnameHashtable,
114
- ...result,
89
+ ...result
115
90
  };
116
91
  }
117
92
 
package/lib/index.js CHANGED
@@ -3,15 +3,8 @@
3
3
  var core = require('@merkur/core');
4
4
  var classnames = require('classnames');
5
5
 
6
- const CLASSNAME_CHARS = (
7
- 'abcdefghijklmnopqrstuvwxyz' +
8
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
9
- '-'
10
- ).split('');
11
- const EXTENDED_CLASSNAME_CHARS = (
12
- CLASSNAME_CHARS.join('') + '0123456789'
13
- ).split('');
14
-
6
+ const CLASSNAME_CHARS = ('abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '-').split('');
7
+ const EXTENDED_CLASSNAME_CHARS = (CLASSNAME_CHARS.join('') + '0123456789').split('');
15
8
  function numberToCssClass(number) {
16
9
  if (number < CLASSNAME_CHARS.length) {
17
10
  return CLASSNAME_CHARS[number];
@@ -20,21 +13,16 @@ function numberToCssClass(number) {
20
13
  // we have to "shift" the number to adjust for the gap between base53 and
21
14
  // base64 encoding
22
15
  number += EXTENDED_CLASSNAME_CHARS.length - CLASSNAME_CHARS.length;
23
-
24
16
  let className = '';
25
17
  while (number >= CLASSNAME_CHARS.length) {
26
- className =
27
- EXTENDED_CLASSNAME_CHARS[number % EXTENDED_CLASSNAME_CHARS.length] +
28
- className;
18
+ className = EXTENDED_CLASSNAME_CHARS[number % EXTENDED_CLASSNAME_CHARS.length] + className;
29
19
  number = Math.floor(number / EXTENDED_CLASSNAME_CHARS.length);
30
20
  }
31
-
32
21
  if (number) {
33
22
  className = CLASSNAME_CHARS[number - 1] + className;
34
23
  } else {
35
24
  className = '_' + className;
36
25
  }
37
-
38
26
  return className;
39
27
  }
40
28
 
@@ -46,7 +34,6 @@ function scramblerFactory(hashingTable) {
46
34
  let uniqueHash, prefixes, mainParts;
47
35
  const prefixTable = hashingTable && new Map();
48
36
  const mainPartTable = hashingTable && new Map();
49
-
50
37
  if (hashingTable) {
51
38
  [uniqueHash, prefixes, mainParts] = hashingTable;
52
39
  for (let i = 0; i < prefixes.length; i++) {
@@ -56,34 +43,25 @@ function scramblerFactory(hashingTable) {
56
43
  mainPartTable.set(mainParts[i], numberToCssClass(i));
57
44
  }
58
45
  }
59
-
60
46
  return (widget, ...args) => {
61
47
  const classNamesSource = classnames(...args);
62
48
  if (!hashingTable) {
63
49
  return {
64
- className: classNamesSource,
50
+ className: classNamesSource
65
51
  };
66
52
  }
67
-
68
- const processedClasses = classNamesSource
69
- .split(/\s+/)
70
- .map((className) => {
71
- const parts = className.split('-');
72
- const prefix = parts[0];
73
- const mainPart = parts.slice(1).join('-');
74
- if (!prefixTable.has(prefix) || !mainPartTable.has(mainPart)) {
75
- return className;
76
- }
77
-
78
- return `${prefixTable.get(prefix)}_${mainPartTable.get(
79
- mainPart,
80
- )}_${uniqueHash}`;
81
- })
82
- .join(' ');
83
-
53
+ const processedClasses = classNamesSource.split(/\s+/).map(className => {
54
+ const parts = className.split('-');
55
+ const prefix = parts[0];
56
+ const mainPart = parts.slice(1).join('-');
57
+ if (!prefixTable.has(prefix) || !mainPartTable.has(mainPart)) {
58
+ return className;
59
+ }
60
+ return `${prefixTable.get(prefix)}_${mainPartTable.get(mainPart)}_${uniqueHash}`;
61
+ }).join(' ');
84
62
  return {
85
63
  className: processedClasses,
86
- 'data-class': classNamesSource,
64
+ 'data-class': classNamesSource
87
65
  };
88
66
  };
89
67
  }
@@ -91,27 +69,24 @@ function scramblerFactory(hashingTable) {
91
69
  function cssScramblePlugin() {
92
70
  return {
93
71
  async setup(widget, widgetDefinition) {
94
- const { classnameHashtable } = widgetDefinition;
72
+ const {
73
+ classnameHashtable
74
+ } = widgetDefinition;
95
75
  widget.$in.classNameScrambler = scramblerFactory(classnameHashtable);
96
-
97
76
  widget.cn = (...args) => widget.$in.classNameScrambler(...args).className;
98
-
99
77
  return widget;
100
78
  },
101
79
  async create(widget) {
102
80
  core.hookMethod(widget, 'info', infoHook);
103
-
104
81
  return widget;
105
- },
82
+ }
106
83
  };
107
84
  }
108
-
109
85
  async function infoHook(widget, originalInfo, ...rest) {
110
86
  const result = await originalInfo(...rest);
111
-
112
87
  return {
113
88
  classnameHashtable: widget.classnameHashtable,
114
- ...result,
89
+ ...result
115
90
  };
116
91
  }
117
92
 
package/lib/index.mjs CHANGED
@@ -1,15 +1,8 @@
1
1
  import { hookMethod } from '@merkur/core';
2
2
  import classnames from 'classnames';
3
3
 
4
- const CLASSNAME_CHARS = (
5
- 'abcdefghijklmnopqrstuvwxyz' +
6
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
7
- '-'
8
- ).split('');
9
- const EXTENDED_CLASSNAME_CHARS = (
10
- CLASSNAME_CHARS.join('') + '0123456789'
11
- ).split('');
12
-
4
+ const CLASSNAME_CHARS = ('abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '-').split('');
5
+ const EXTENDED_CLASSNAME_CHARS = (CLASSNAME_CHARS.join('') + '0123456789').split('');
13
6
  function numberToCssClass(number) {
14
7
  if (number < CLASSNAME_CHARS.length) {
15
8
  return CLASSNAME_CHARS[number];
@@ -18,21 +11,16 @@ function numberToCssClass(number) {
18
11
  // we have to "shift" the number to adjust for the gap between base53 and
19
12
  // base64 encoding
20
13
  number += EXTENDED_CLASSNAME_CHARS.length - CLASSNAME_CHARS.length;
21
-
22
14
  let className = '';
23
15
  while (number >= CLASSNAME_CHARS.length) {
24
- className =
25
- EXTENDED_CLASSNAME_CHARS[number % EXTENDED_CLASSNAME_CHARS.length] +
26
- className;
16
+ className = EXTENDED_CLASSNAME_CHARS[number % EXTENDED_CLASSNAME_CHARS.length] + className;
27
17
  number = Math.floor(number / EXTENDED_CLASSNAME_CHARS.length);
28
18
  }
29
-
30
19
  if (number) {
31
20
  className = CLASSNAME_CHARS[number - 1] + className;
32
21
  } else {
33
22
  className = '_' + className;
34
23
  }
35
-
36
24
  return className;
37
25
  }
38
26
 
@@ -44,7 +32,6 @@ function scramblerFactory(hashingTable) {
44
32
  let uniqueHash, prefixes, mainParts;
45
33
  const prefixTable = hashingTable && new Map();
46
34
  const mainPartTable = hashingTable && new Map();
47
-
48
35
  if (hashingTable) {
49
36
  [uniqueHash, prefixes, mainParts] = hashingTable;
50
37
  for (let i = 0; i < prefixes.length; i++) {
@@ -54,34 +41,25 @@ function scramblerFactory(hashingTable) {
54
41
  mainPartTable.set(mainParts[i], numberToCssClass(i));
55
42
  }
56
43
  }
57
-
58
44
  return (widget, ...args) => {
59
45
  const classNamesSource = classnames(...args);
60
46
  if (!hashingTable) {
61
47
  return {
62
- className: classNamesSource,
48
+ className: classNamesSource
63
49
  };
64
50
  }
65
-
66
- const processedClasses = classNamesSource
67
- .split(/\s+/)
68
- .map((className) => {
69
- const parts = className.split('-');
70
- const prefix = parts[0];
71
- const mainPart = parts.slice(1).join('-');
72
- if (!prefixTable.has(prefix) || !mainPartTable.has(mainPart)) {
73
- return className;
74
- }
75
-
76
- return `${prefixTable.get(prefix)}_${mainPartTable.get(
77
- mainPart,
78
- )}_${uniqueHash}`;
79
- })
80
- .join(' ');
81
-
51
+ const processedClasses = classNamesSource.split(/\s+/).map(className => {
52
+ const parts = className.split('-');
53
+ const prefix = parts[0];
54
+ const mainPart = parts.slice(1).join('-');
55
+ if (!prefixTable.has(prefix) || !mainPartTable.has(mainPart)) {
56
+ return className;
57
+ }
58
+ return `${prefixTable.get(prefix)}_${mainPartTable.get(mainPart)}_${uniqueHash}`;
59
+ }).join(' ');
82
60
  return {
83
61
  className: processedClasses,
84
- 'data-class': classNamesSource,
62
+ 'data-class': classNamesSource
85
63
  };
86
64
  };
87
65
  }
@@ -89,27 +67,24 @@ function scramblerFactory(hashingTable) {
89
67
  function cssScramblePlugin() {
90
68
  return {
91
69
  async setup(widget, widgetDefinition) {
92
- const { classnameHashtable } = widgetDefinition;
70
+ const {
71
+ classnameHashtable
72
+ } = widgetDefinition;
93
73
  widget.$in.classNameScrambler = scramblerFactory(classnameHashtable);
94
-
95
74
  widget.cn = (...args) => widget.$in.classNameScrambler(...args).className;
96
-
97
75
  return widget;
98
76
  },
99
77
  async create(widget) {
100
78
  hookMethod(widget, 'info', infoHook);
101
-
102
79
  return widget;
103
- },
80
+ }
104
81
  };
105
82
  }
106
-
107
83
  async function infoHook(widget, originalInfo, ...rest) {
108
84
  const result = await originalInfo(...rest);
109
-
110
85
  return {
111
86
  classnameHashtable: widget.classnameHashtable,
112
- ...result,
87
+ ...result
113
88
  };
114
89
  }
115
90
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkur/plugin-css-scrambler",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "Merkur plugin for scrambling CSS classes.",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -30,8 +30,7 @@
30
30
  "preversion": "npm test",
31
31
  "test": "jest --no-watchman -c ./jest.config.js",
32
32
  "test:es:version": "es-check es11 ./lib/index.mjs --module && es-check es9 ./lib/index.es9.mjs --module && es-check es9 ./lib/index.es9.cjs --module",
33
- "build": "rollup -c rollup.config.mjs",
34
- "prepare": "npm run build"
33
+ "build": "rollup -c rollup.config.mjs"
35
34
  },
36
35
  "repository": {
37
36
  "type": "git",
@@ -65,5 +64,5 @@
65
64
  "classnames": "^2.3.2",
66
65
  "postcss-selector-parser": "^6.0.12"
67
66
  },
68
- "gitHead": "a6e379c0cb887898e34465dc3db9231feb68e6a5"
67
+ "gitHead": "8ad2c8b26246850ce6289502a8b05e882f80ce31"
69
68
  }