@domql/emotion 2.1.0 → 2.3.72

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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/index.js +46 -22
  3. package/package.json +7 -8
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016 rackai
3
+ Copyright (c) 2016 symbo.ls
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/index.js CHANGED
@@ -1,34 +1,58 @@
1
1
  'use strict'
2
2
 
3
- import { isObjectLike, exec } from '@domql/utils'
4
- import { define } from '@domql/define'
5
- import { classList } from '@domql/mixins/classList'
3
+ // import DOM from '../../src'
4
+ import { isObjectLike, exec, isObject, isEqualDeep } from '@domql/utils'
5
+ import { isProduction } from '@domql/env'
6
+ import { applyClassListOnNode } from '@domql/classlist'
7
+ import createEmotion from '@emotion/css/create-instance'
6
8
 
7
- import { css } from '@emotion/css'
8
-
9
- const style = (params, element, node) => {
10
- const execPareams = exec(params, element)
11
- if (params) {
12
- if (isObjectLike(element.class)) element.class.style = execPareams
13
- else element.class = { style: execPareams }
9
+ export const transformEmotionStyle = (emotion) => {
10
+ return (params, element, state) => {
11
+ const execParams = exec(params, element)
12
+ if (params) {
13
+ if (isObjectLike(element.class)) element.class.elementStyle = execParams
14
+ else element.class = { elementStyle: execParams }
15
+ }
16
+ transformEmotionClass(emotion)(element.class, element, state, true)
14
17
  }
15
- classf(element.class, element, node)
16
18
  }
17
19
 
18
- const classf = (element, node) => {
19
- const params = element.class
20
- if (isObjectLike(params)) {
21
- const classObjHelper = {}
20
+ export const transformEmotionClass = (emotion) => {
21
+ return (params, element, state, flag) => {
22
+ if (element.style && !flag) return
23
+ const { __ref } = element
24
+ const { __class, __classNames } = __ref
25
+
26
+ if (!isObjectLike(params)) return
27
+
22
28
  for (const key in params) {
23
29
  const prop = exec(params[key], element)
24
- const CSSed = css(prop)
25
- classObjHelper[key] = CSSed
30
+
31
+ if (!prop) {
32
+ delete __class[key]
33
+ delete __classNames[key]
34
+ continue
35
+ }
36
+
37
+ const isEqual = isEqualDeep(__class[key], prop)
38
+ if (!isEqual) {
39
+ if (!isProduction() && isObject(prop)) prop.label = key || element.key
40
+
41
+ const CSSed = emotion.css(prop)
42
+ __class[key] = prop
43
+ __classNames[key] = CSSed
44
+ }
26
45
  }
27
- classList(classObjHelper, element, node)
46
+ applyClassListOnNode(__classNames, element, element.node)
47
+ // return element.class
28
48
  }
29
49
  }
30
50
 
31
- define({
32
- style,
33
- class: classf
34
- }, { overwrite: true })
51
+ export const transformDOMQLEmotion = (emotion, options) => {
52
+ if (!emotion) emotion = createEmotion(options || { key: 'smbls' })
53
+
54
+ return {
55
+ style: transformEmotionStyle(emotion),
56
+ class: transformEmotionClass(emotion)
57
+ }
58
+ }
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@domql/emotion",
3
- "version": "2.1.0",
3
+ "version": "2.3.72",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "@domql/define": "latest",
8
- "@domql/mixins": "latest",
9
- "@domql/utils": "latest",
10
- "@emotion/css": "^11.5.0"
7
+ "@domql/classlist": "latest",
8
+ "@domql/env": "latest",
9
+ "@domql/utils": "latest"
11
10
  },
12
- "scripts": {
13
- "vpatch": "npm version patch && npm publish --access public"
11
+ "peerDependencies": {
12
+ "@emotion/css": "latest"
14
13
  },
15
- "gitHead": "1e384e4a15f44201165f6bd54efb4a0e9c105745",
14
+ "gitHead": "f3a01922fb7e24ba65ecb8d2dc8f97bd7f142717",
16
15
  "source": "index.js"
17
16
  }