This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {htmlTagNames} = require('html-tag-names') | |
// get a list of all known html tag names and convert it into a map example: | |
// {body: true, head: true, li: true, h1: true, p: true} and so on | |
const tags = htmlTagNames.reduce((res, tag) => { | |
res[tag] = true | |
return res | |
}, {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cache = {} | |
const Obj = function (js, css, nonAtomic) { | |
this.__isAtomic = true | |
this.js = js | |
this.css = css | |
this.nonAtomic = nonAtomic | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inspired from https://github.com/callstack/linaria/blob/master/packages/server/src/collect.ts | |
const postcss = require('postcss') | |
const htmlTagNames = require('./htmlTagNames') | |
module.exports = function collect (css) { | |
const basic = postcss.root() | |
const map = {} | |
const stylesheet = postcss.parse(css) | |
const getClassNameRoot = rule => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /(style|Style|Style.jsx|style.jsx)$/ | |
function plugin1 (state) { | |
const { variables, modules, nodes, moduleVsImport } = state | |
return { | |
Program (path) { | |
state.programPath = path | |
}, | |
ImportDeclaration (path) { | |
if (regex.test(path.node.source.value)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parser = require('@babel/parser') | |
const { default: traverse } = require('@babel/traverse') | |
const { plugin1, plugin2 } = require('./find-cx-babel-plugin') | |
const t = require('@babel/types') | |
const cx = require('./cx.cjs') | |
const { default: generate } = require('@babel/generator') | |
const parse = (code, traverser) => { | |
let ast = parser.parse(code, { | |
sourceType: 'module', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// read this: https://github.com/reactwg/react-18/discussions/110 | |
import React, { useMemo, useInsertionEffect, forwardRef } from 'react' | |
const insertedRules = | |
typeof window !== 'undefined' && window.__SSR_STYLES__ | |
? window.__SSR_STYLES__ | |
: {} | |
function getStyleForRule (url, content) { | |
if (content) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext, forwardRef, useContext } from 'react' | |
import { useStream } from 'react-streaming' | |
export const StylesContext = createContext({ set: new Set() }) | |
function assetToStyleString (asset) { | |
const { url, content } = asset | |
if (content) { | |
return `<style data-href="${url}">${content}</style>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const { default: generate } = require('@babel/generator') | |
module.exports = function ({ types: t }) { | |
let programPath | |
function getUniqueName (key = '__style') { | |
return programPath.scope.generateUidIdentifier(key).name | |
} | |
function getStyles (body, _this) { | |
let namedImports = [] | |
let unnamedImports = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// utils/requestContext.js | |
import { createNamespace } from 'cls-hooked' | |
// context variable here may be global, but the data stored is | |
// not shared among different requests | |
const context = createNamespace(`app:requestData`) | |
// use this middleware in your express middleware chain, as early as possible | |
export function expressMiddleware (req, res, next) { | |
context.run(function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// output: component.linaria.css | |
.some_unique_classname { | |
font-size: 14px; | |
} |
NewerOlder