1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.convertLightningCssToReactNativeWebStyleSheet = convertLightningCssToReactNativeWebStyleSheet;
7exports.matchCssModule = matchCssModule;
8exports.transformCssModuleWeb = transformCssModuleWeb;
9function _css() {
10  const data = require("./css");
11  _css = function () {
12    return data;
13  };
14  return data;
15}
16function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18const RNW_CSS_CLASS_ID = '_';
19async function transformCssModuleWeb(props) {
20  const {
21    transform
22  } = await Promise.resolve().then(() => _interopRequireWildcard(require('lightningcss')));
23
24  // TODO: Add bundling to resolve imports
25  // https://lightningcss.dev/bundling.html#bundling-order
26
27  const cssResults = transform({
28    filename: props.filename,
29    code: Buffer.from(props.src),
30    sourceMap: props.options.sourceMap,
31    cssModules: {
32      // Prevent renaming CSS variables to ensure
33      // variables created in global files are available.
34      dashedIdents: false
35    },
36    // cssModules: true,
37    projectRoot: props.options.projectRoot,
38    minify: props.options.minify
39  });
40  const codeAsString = cssResults.code.toString();
41  const {
42    styles,
43    reactNativeWeb,
44    variables
45  } = convertLightningCssToReactNativeWebStyleSheet(cssResults.exports);
46  let outputModule = `module.exports=Object.assign(${JSON.stringify(styles)},{unstable_styles:${JSON.stringify(reactNativeWeb)}},${JSON.stringify(variables)});`;
47  if (props.options.dev) {
48    const runtimeCss = (0, _css().wrapDevelopmentCSS)({
49      ...props,
50      src: codeAsString
51    });
52    outputModule += '\n' + runtimeCss;
53  }
54  return {
55    output: outputModule,
56    css: cssResults.code,
57    map: cssResults.map
58  };
59}
60function convertLightningCssToReactNativeWebStyleSheet(input) {
61  const styles = {};
62  const reactNativeWeb = {};
63  const variables = {};
64  // e.g. { container: { name: 'ahs8IW_container', composes: [], isReferenced: false }, }
65  Object.entries(input).map(([key, value]) => {
66    // order matters here
67    let className = value.name;
68    if (value.composes.length) {
69      className += ' ' + value.composes.map(value => value.name).join(' ');
70    }
71
72    // CSS Variables will be `{string: string}`
73    if (key.startsWith('--')) {
74      variables[key] = className;
75    }
76    styles[key] = className;
77    reactNativeWeb[key] = {
78      $$css: true,
79      [RNW_CSS_CLASS_ID]: className
80    };
81    return {
82      [key]: {
83        $$css: true,
84        [RNW_CSS_CLASS_ID]: className
85      }
86    };
87  });
88  return {
89    styles,
90    reactNativeWeb,
91    variables
92  };
93}
94function matchCssModule(filePath) {
95  return !!/\.module(\.(native|ios|android|web))?\.(css|s[ac]ss)$/.test(filePath);
96}
97//# sourceMappingURL=css-modules.js.map