tungsten 0.2.24 → 0.2.25

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 +1 @@
1
- {"version":3,"file":"getFetchCompatibleHeaders.d.ts","sourceRoot":"","sources":["../../src/helpers/getFetchCompatibleHeaders.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAKtC,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,WAYrD"}
1
+ {"version":3,"file":"getFetchCompatibleHeaders.d.ts","sourceRoot":"","sources":["../../src/helpers/getFetchCompatibleHeaders.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAKtC,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAY/D"}
@@ -1,2 +1,15 @@
1
- export declare const TransformCssNames: any;
1
+ import type { Root } from 'postcss';
2
+ import type { CssNames } from '../CssNames.js';
3
+ type Opts = {
4
+ moduleName: string;
5
+ outNames: CssNames;
6
+ };
7
+ export declare const TransformCssNames: {
8
+ (opts: Opts): {
9
+ postcssPlugin: string;
10
+ Once(root: Root): void;
11
+ };
12
+ postcss: boolean;
13
+ };
14
+ export {};
2
15
  //# sourceMappingURL=TransformCssNames.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TransformCssNames.d.ts","sourceRoot":"","sources":["../../src/postcssPlugins/TransformCssNames.ts"],"names":[],"mappings":"AAsFA,eAAO,MAAM,iBAAiB,KA6H5B,CAAA"}
1
+ {"version":3,"file":"TransformCssNames.d.ts","sourceRoot":"","sources":["../../src/postcssPlugins/TransformCssNames.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,IAAI,EAAQ,MAAM,SAAS,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAyD9C,KAAK,IAAI,GAAG;IACR,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,QAAQ,CAAA;CACrB,CAAA;AAKD,eAAO,MAAM,iBAAiB;WAAU,IAAI;;mBAezB,IAAI;;;CAoHtB,CAAA"}
@@ -9,8 +9,6 @@ extract classes -> localise
9
9
  .navItem -> NavItem_navItemf
10
10
  .span -> NavItem_span
11
11
  */
12
- //const path = require('path')
13
- import postcss from 'postcss';
14
12
  import { parseSelectorsRich } from "./parseSelectorsRich.js";
15
13
  import { componentBumpClass } from "../componentClassName.js";
16
14
  import { throwError } from "../throwError.js";
@@ -45,13 +43,13 @@ function transformTag(moduleName, tag) {
45
43
  };
46
44
  }
47
45
  //Page-poll#_div
46
+ // why is this unused?
48
47
  function separatePseudo(selector) {
49
48
  const colonIndex = selector.indexOf(':');
50
49
  if (colonIndex === -1) return [selector, ''];else return [selector.slice(0, colonIndex), selector.slice(colonIndex)];
51
50
  }
52
51
  const bump = '.' + componentBumpClass + '.' + componentBumpClass + '.' + componentBumpClass;
53
- // !!! DEPRECATED
54
- export const TransformCssNames = postcss.plugin('postcss-transform-names', opts => {
52
+ export const TransformCssNames = opts => {
55
53
  //console.log('TransformCssNames')
56
54
  if (!('moduleName' in opts)) {
57
55
  throw new Error(`PostcssTransformNames error - pass a moduleName prop to the` + ` plugin to receive transformed names map`);
@@ -59,100 +57,104 @@ export const TransformCssNames = postcss.plugin('postcss-transform-names', opts
59
57
  if (!('outNames' in opts)) {
60
58
  throw new Error(`PostcssTransformNames error - pass an outNames object to the` + ` plugin to receive transformed names map`);
61
59
  }
62
- return root => {
63
- const moduleName = opts.moduleName;
64
- const names = opts.outNames;
65
- names.moduleName = moduleName;
66
- names.tags = {};
67
- names.classes = {};
68
- // Transform CSS AST here
69
- root.walkRules(rule => {
70
- const selectorLine = rule.selector;
71
- const selectorGroups = selectorLine.split(',').map(x => x.trim());
72
- const newSelectorGroups = [];
73
- for (const selectorGroup of selectorGroups) {
74
- debug('selectorGroup', selectorGroup);
75
- //// Always explain your regex's
76
- //// Split the string before a space, after a space, before a . or # within a sequence (e.g. foo.bar)
77
- //// This splits the string into tags (foo), classes (.foo), IDs (#foo), and spaces ( )
78
- //// The spaces are retained so that we can rebuild the string with the spaces as they were found
79
- //const selectors = selectorGroup.split(/(?= )|(?<= )|(?<=\S)(?=[.#]\S)/)
80
- // replace the regex with a parser. Easier
81
- const selectors = parseSelectorsRich(selectorGroup);
82
- const newSelectors = [];
83
- for (const {
84
- type,
85
- content
86
- } of selectors) {
87
- debug('Sel: ', type + ':', content);
88
- if (type === 'whitespace') {
89
- newSelectors.push(' ');
90
- } else if (type === 'grammar') {
91
- newSelectors.push(content);
92
- } else if (type === 'id') {
93
- newSelectors.push(content);
94
- } else if (type === 'class') {
95
- const className = content.slice(1);
96
- const newClassName = transformClass(moduleName, className);
97
- newSelectors.push('.' + newClassName);
98
- names.classes[className] = newClassName;
99
- } else if (type === 'tag') {
100
- const newName = transformTag(moduleName, content);
101
- // newName.css === escaped version for css
102
- // newName.jsx === unescaped ver for jsx
103
- if (/^[A-Z]/.test(content)) {
104
- // starts with uppercase - React el
105
- newSelectors.push(bump + '.' + newName.css);
106
- } else {
107
- // lowercase - html el
108
- newSelectors.push('.' + newName.css);
109
- }
110
- names.tags[content] = newName.jsx;
111
- } else if (type === 'pseudo-class') {
112
- // // REGEX:
113
- // // :
114
- // // multiple letters/numbers/-/_ [match group 1]
115
- // // (
116
- // // any chars (greedy / as many as possible) [match group 2]
117
- // // )
118
- // // e.g. :Match1(Match2)
119
- // const pseudoClassRegex = /:([a-zA-Z0-9-_]+)\((.*)\)/
120
- // REGEX:
121
- // :
122
- // multiple letters/numbers/-/_ [match group 1]
123
- // optional section, non matching
124
- // (
125
- // any chars (greedy / as many as possible) [match group 2]
126
- // )
127
- // e.g. :Match1(Match2)
128
- const pseudoClassRegex = /:([a-zA-Z0-9-_]+)(?:\((.*)\))?/;
129
- const results = pseudoClassRegex.exec(content);
130
- if (results === null) throwError('TransformCssNames -> walkRules', 'pseudo-class selector did not match pseudo-class regex');
131
- const label = results[1]; // eslint-disable-line no-type-assertion/no-type-assertion -- typings are incorrect
132
- // if it is :i(xxx) or :ignore(xxx), pass through the internal part
133
- // otherwise pass all through unaffected
134
- if (label === 'i' || label === 'ignore') {
135
- const inner = results[2]; // eslint-disable-line no-type-assertion/no-type-assertion -- typings are incorrect
136
- if (inner !== undefined && inner !== '') {
137
- newSelectors.push(inner);
60
+ return {
61
+ postcssPlugin: 'postcss-transform-names',
62
+ Once(root) {
63
+ const moduleName = opts.moduleName;
64
+ const names = opts.outNames;
65
+ names.moduleName = moduleName;
66
+ names.tags = {};
67
+ names.classes = {};
68
+ // Transform CSS AST here
69
+ root.walkRules(rule => {
70
+ const selectorLine = rule.selector;
71
+ const selectorGroups = selectorLine.split(',').map(x => x.trim());
72
+ const newSelectorGroups = [];
73
+ for (const selectorGroup of selectorGroups) {
74
+ debug('selectorGroup', selectorGroup);
75
+ //// Always explain your regex's
76
+ //// Split the string before a space, after a space, before a . or # within a sequence (e.g. foo.bar)
77
+ //// This splits the string into tags (foo), classes (.foo), IDs (#foo), and spaces ( )
78
+ //// The spaces are retained so that we can rebuild the string with the spaces as they were found
79
+ //const selectors = selectorGroup.split(/(?= )|(?<= )|(?<=\S)(?=[.#]\S)/)
80
+ // replace the regex with a parser. Easier
81
+ const selectors = parseSelectorsRich(selectorGroup);
82
+ const newSelectors = [];
83
+ for (const {
84
+ type,
85
+ content
86
+ } of selectors) {
87
+ debug('Sel: ', type + ':', content);
88
+ if (type === 'whitespace') {
89
+ newSelectors.push(' ');
90
+ } else if (type === 'grammar') {
91
+ newSelectors.push(content);
92
+ } else if (type === 'id') {
93
+ newSelectors.push(content);
94
+ } else if (type === 'class') {
95
+ const className = content.slice(1);
96
+ const newClassName = transformClass(moduleName, className);
97
+ newSelectors.push('.' + newClassName);
98
+ names.classes[className] = newClassName;
99
+ } else if (type === 'tag') {
100
+ const newName = transformTag(moduleName, content);
101
+ // newName.css === escaped version for css
102
+ // newName.jsx === unescaped ver for jsx
103
+ if (/^[A-Z]/.test(content)) {
104
+ // starts with uppercase - React el
105
+ newSelectors.push(bump + '.' + newName.css);
106
+ } else {
107
+ // lowercase - html el
108
+ newSelectors.push('.' + newName.css);
109
+ }
110
+ names.tags[content] = newName.jsx;
111
+ } else if (type === 'pseudo-class') {
112
+ // // REGEX:
113
+ // // :
114
+ // // multiple letters/numbers/-/_ [match group 1]
115
+ // // (
116
+ // // any chars (greedy / as many as possible) [match group 2]
117
+ // // )
118
+ // // e.g. :Match1(Match2)
119
+ // const pseudoClassRegex = /:([a-zA-Z0-9-_]+)\((.*)\)/
120
+ // REGEX:
121
+ // :
122
+ // multiple letters/numbers/-/_ [match group 1]
123
+ // optional section, non matching
124
+ // (
125
+ // any chars (greedy / as many as possible) [match group 2]
126
+ // )
127
+ // e.g. :Match1(Match2)
128
+ const pseudoClassRegex = /:([a-zA-Z0-9-_]+)(?:\((.*)\))?/;
129
+ const results = pseudoClassRegex.exec(content);
130
+ if (results === null) throwError('TransformCssNames -> walkRules', 'pseudo-class selector did not match pseudo-class regex');
131
+ const label = results[1]; // eslint-disable-line no-type-assertion/no-type-assertion -- typings are incorrect
132
+ // if it is :i(xxx) or :ignore(xxx), pass through the internal part
133
+ // otherwise pass all through unaffected
134
+ if (label === 'i' || label === 'ignore') {
135
+ const inner = results[2]; // eslint-disable-line no-type-assertion/no-type-assertion -- typings are incorrect
136
+ if (inner !== undefined && inner !== '') {
137
+ newSelectors.push(inner);
138
+ }
139
+ } else {
140
+ newSelectors.push(content);
138
141
  }
139
- } else {
142
+ } else if (type === 'pseudo-element') {
143
+ newSelectors.push(content);
144
+ } else if (type === 'attribute') {
140
145
  newSelectors.push(content);
141
146
  }
142
- } else if (type === 'pseudo-element') {
143
- newSelectors.push(content);
144
- } else if (type === 'attribute') {
145
- newSelectors.push(content);
146
147
  }
148
+ newSelectorGroups.push(newSelectors.join(''));
147
149
  }
148
- newSelectorGroups.push(newSelectors.join(''));
149
- }
150
- const newSelectorLine = newSelectorGroups.join(', ');
151
- debug('new selector line', newSelectorLine);
152
- debug('name for above line', names);
153
- rule.selector = newSelectorLine;
154
- });
155
- //console.log("names", names)
156
- //opts.outNames = names
150
+ const newSelectorLine = newSelectorGroups.join(', ');
151
+ debug('new selector line', newSelectorLine);
152
+ debug('name for above line', names);
153
+ rule.selector = newSelectorLine;
154
+ });
155
+ //console.log("names", names)
156
+ //opts.outNames = names
157
+ }
157
158
  };
158
- });
159
+ };
160
+ TransformCssNames.postcss = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tungsten",
3
- "version": "0.2.24",
3
+ "version": "0.2.25",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {