@teleporthq/teleport-plugin-css 0.36.0-alpha.0 → 0.36.0
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/__tests__/component-scoped.ts +4 -2
- package/__tests__/style-sheet.ts +3 -3
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +27 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/style-sheet.d.ts +1 -0
- package/dist/cjs/style-sheet.d.ts.map +1 -1
- package/dist/cjs/style-sheet.js +40 -9
- package/dist/cjs/style-sheet.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +27 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/style-sheet.d.ts +1 -0
- package/dist/esm/style-sheet.d.ts.map +1 -1
- package/dist/esm/style-sheet.js +40 -9
- package/dist/esm/style-sheet.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/index.ts +37 -28
- package/src/style-sheet.ts +57 -11
package/src/style-sheet.ts
CHANGED
|
@@ -5,22 +5,42 @@ import {
|
|
|
5
5
|
ChunkType,
|
|
6
6
|
FileType,
|
|
7
7
|
} from '@teleporthq/teleport-types'
|
|
8
|
+
import { join, relative } from 'path'
|
|
8
9
|
|
|
9
10
|
interface StyleSheetPlugin {
|
|
10
11
|
fileName?: string
|
|
12
|
+
/*
|
|
13
|
+
Frameworks with dev servers don't need relative path mapping.
|
|
14
|
+
*/
|
|
15
|
+
relativeFontPath?: boolean
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export const createStyleSheetPlugin: ComponentPluginFactory<StyleSheetPlugin> = (config) => {
|
|
14
|
-
const { fileName } = config || {
|
|
19
|
+
const { fileName = 'style', relativeFontPath = false } = config || {
|
|
20
|
+
fileName: 'style',
|
|
21
|
+
relativeFontPath: false,
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
const styleSheetPlugin: ComponentPlugin = async (structure) => {
|
|
16
|
-
const {
|
|
25
|
+
const {
|
|
26
|
+
uidl,
|
|
27
|
+
chunks,
|
|
28
|
+
options: { assets },
|
|
29
|
+
} = structure
|
|
17
30
|
const { styleSetDefinitions = {}, designLanguage: { tokens = {} } = {} } = uidl
|
|
31
|
+
const {
|
|
32
|
+
localFonts = [],
|
|
33
|
+
fontsFolder,
|
|
34
|
+
identifier: assetIdentifier,
|
|
35
|
+
} = assets || { localFonts: [] }
|
|
18
36
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
const canSkipThePlugin =
|
|
38
|
+
localFonts?.length === 0 &&
|
|
39
|
+
Object.keys(styleSetDefinitions).length === 0 &&
|
|
40
|
+
Object.keys(tokens).length === 0
|
|
41
|
+
|
|
42
|
+
if (canSkipThePlugin) {
|
|
43
|
+
return structure
|
|
24
44
|
}
|
|
25
45
|
|
|
26
46
|
const cssMap: string[] = []
|
|
@@ -29,6 +49,35 @@ export const createStyleSheetPlugin: ComponentPluginFactory<StyleSheetPlugin> =
|
|
|
29
49
|
Array<{ [x: string]: Record<string, string | number> }>
|
|
30
50
|
> = {}
|
|
31
51
|
|
|
52
|
+
uidl.outputOptions = uidl.outputOptions || {}
|
|
53
|
+
uidl.outputOptions.styleFileName = fileName
|
|
54
|
+
|
|
55
|
+
if (localFonts.length > 0) {
|
|
56
|
+
localFonts.forEach((font) => {
|
|
57
|
+
const properties = StyleUtils.getContentOfStyleObject(font.properties) as Record<
|
|
58
|
+
string,
|
|
59
|
+
string | number
|
|
60
|
+
>
|
|
61
|
+
const format = properties?.format ? `format('${properties.format}')` : ''
|
|
62
|
+
/* tslint:disable:no-string-literal */
|
|
63
|
+
delete properties['format']
|
|
64
|
+
|
|
65
|
+
const fontPath = relativeFontPath
|
|
66
|
+
? join(
|
|
67
|
+
relative(join(...(uidl.outputOptions?.folderPath || [])), './'),
|
|
68
|
+
join(fontsFolder || '', font.path)
|
|
69
|
+
)
|
|
70
|
+
: join('/', assetIdentifier || '', 'fonts', font.path)
|
|
71
|
+
|
|
72
|
+
cssMap.push(
|
|
73
|
+
StyleBuilders.createFontDecleration({
|
|
74
|
+
...properties,
|
|
75
|
+
src: `url("${fontPath}") ${format}`,
|
|
76
|
+
})
|
|
77
|
+
)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
32
81
|
if (Object.keys(tokens).length > 0) {
|
|
33
82
|
cssMap.push(
|
|
34
83
|
StyleBuilders.createCSSClassWithSelector(
|
|
@@ -44,7 +93,7 @@ export const createStyleSheetPlugin: ComponentPluginFactory<StyleSheetPlugin> =
|
|
|
44
93
|
styleSetDefinitions,
|
|
45
94
|
cssMap,
|
|
46
95
|
mediaStylesMap,
|
|
47
|
-
(styleName
|
|
96
|
+
(styleName) => styleName
|
|
48
97
|
)
|
|
49
98
|
}
|
|
50
99
|
|
|
@@ -54,9 +103,6 @@ export const createStyleSheetPlugin: ComponentPluginFactory<StyleSheetPlugin> =
|
|
|
54
103
|
return structure
|
|
55
104
|
}
|
|
56
105
|
|
|
57
|
-
uidl.outputOptions = uidl.outputOptions || {}
|
|
58
|
-
uidl.outputOptions.styleFileName = fileName
|
|
59
|
-
|
|
60
106
|
chunks.push({
|
|
61
107
|
name: fileName,
|
|
62
108
|
type: ChunkType.STRING,
|