@live-codes/browser-compilers 0.6.3 → 0.6.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-codes/browser-compilers",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Compilers that run in the browser, for use in livecodes.io",
5
5
  "author": "Hatem Hosny",
6
6
  "license": "MIT",
@@ -64,11 +64,14 @@
64
64
  "postcss": "8.4.6",
65
65
  "postcss-modules": "6.0.0",
66
66
  "postcss-preset-env": "7.3.1",
67
+ "posthtml": "0.16.6",
68
+ "posthtml-css-modules": "0.1.3",
67
69
  "react": "18.2.0",
68
70
  "react-dom": "18.2.0",
69
71
  "react-native-web": "0.19.1",
70
72
  "remark-gfm": "3.0.1",
71
73
  "sass": "1.49.7",
74
+ "sucrase": "3.32.0",
72
75
  "svelte": "3.44.1",
73
76
  "windicss": "3.2.1"
74
77
  },
@@ -381,3 +381,11 @@ esbuild.build({
381
381
  globalName: 'flowRemoveTypes',
382
382
  plugins: nodePolyfills,
383
383
  });
384
+
385
+ // sucrase
386
+ esbuild.build({
387
+ ...baseOptions,
388
+ entryPoints: ['vendor_modules/imports/sucrase.js'],
389
+ outfile: 'dist/sucrase/sucrase.js',
390
+ globalName: 'sucrase',
391
+ });
@@ -44,6 +44,14 @@ PostCSS: [MIT License](https://github.com/postcss/postcss/blob/af8311a9c4c940c3e
44
44
 
45
45
  PostCSS Preset Env: [CC0-1.0 License](https://github.com/csstools/postcss-preset-env/blob/d7652b1e6196e8f55bf3f0aac4ac090fec7ed54e/LICENSE.md)
46
46
 
47
+ postcss-modules: [MIT License](https://github.com/madyankin/postcss-modules/blob/325f0b33f1b746eae7aa827504a5efd0949022ef/LICENSE)
48
+
49
+ PostHTML: [MIT License](https://github.com/posthtml/posthtml/blob/9feb13c4c05c40519ba56279920aacd3523100cb/license)
50
+
51
+ posthtml-class-to-css-module: [MIT License](https://github.com/posthtml/posthtml-class-to-css-module/blob/d53bd08c9aa375cde63d9fe86021ee887bc07b9b/license)
52
+
53
+ posthtml-css-modules: [MIT License](https://github.com/posthtml/posthtml-css-modules/blob/47d2ffa908a9085265fe2a60ef608feed33ebdbd/LICENSE.txt)
54
+
47
55
  prelude<span>.ls</span>: [MIT License](https://github.com/gkz/prelude-ls/blob/41d048799bdd063e0592c1413d238ad95ceda1d9/LICENSE)
48
56
 
49
57
  Prettier Pug Plugin: [MIT License](https://github.com/prettier/plugin-pug/blob/27ab92b27a062bb187fc33f82b2fad436ec31c25/LICENSE)
@@ -1,3 +1,44 @@
1
1
  import postcssModules from 'postcss-modules';
2
+ import posthtml from 'posthtml';
3
+ import posthtmlCSSModules from 'posthtml-css-modules';
2
4
 
3
- export { postcssModules };
5
+ // based on https://github.com/posthtml/posthtml-class-to-css-module
6
+ const cloneClasses = (options = {}) => (tree) =>
7
+ tree.match({ attrs: { class: /.+/ } }, (node) => {
8
+ const className =
9
+ typeof options.cssModules === 'object'
10
+ ? node.attrs.class
11
+ .split(' ')
12
+ .filter(
13
+ (name) =>
14
+ Object.keys(options.cssModules).includes(name) && options.cssModules[name] !== name,
15
+ )
16
+ .join(' ')
17
+ : node.attrs.class;
18
+
19
+ if (className.trim()) {
20
+ node.attrs = Object.assign(node.attrs, { 'css-module': className });
21
+ }
22
+
23
+ if (options.removeOriginalClasses) {
24
+ delete node.attrs.class;
25
+ }
26
+
27
+ return node;
28
+ });
29
+
30
+ /**
31
+ *
32
+ * @param {string} html
33
+ * @param {Record<String, any>} cssModules
34
+ * @param {boolean} removeOriginalClasses
35
+ * @returns {string}
36
+ */
37
+ const addClassesToHtml = (html, cssModules, removeOriginalClasses = false) =>
38
+ posthtml()
39
+ // @ts-ignore
40
+ .use(cloneClasses({ cssModules, removeOriginalClasses }), posthtmlCSSModules(cssModules))
41
+ // @ts-ignore
42
+ .process(html, { sync: true }).html;
43
+
44
+ export { postcssModules, addClassesToHtml };
@@ -0,0 +1 @@
1
+ export { transform } from 'sucrase';