react-outline 1.7.2 → 2.0.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.
Files changed (84) hide show
  1. package/README.md +151 -116
  2. package/dist/Styles.js +34 -35
  3. package/dist/element.js +69 -88
  4. package/dist/main.js +22 -35
  5. package/dist/reactOutline.js +241 -0
  6. package/dist/reactOutline.js.map +7 -0
  7. package/dist/styleItem.js +105 -91
  8. package/dist/utils/buildCssString.js +2 -2
  9. package/dist/utils/genCss.js +21 -32
  10. package/dist/utils/genStyles.js +13 -26
  11. package/dist/utils/hasKids.js +2 -4
  12. package/dist/utils/index.js +81 -61
  13. package/dist/utils/makeid.js +3 -6
  14. package/dist/utils/object2css.js +10 -22
  15. package/dist/utils/pubsub.js +10 -24
  16. package/dist/utils/replaceColors.js +3 -4
  17. package/dist/utils/replacedStyleFn.js +5 -10
  18. package/dist/utils/sanitizeOutlineInput.js +8 -24
  19. package/dist/utils/separateCssStyle.js +5 -8
  20. package/dist/wrapStyles.js +18 -14
  21. package/package.json +36 -24
  22. package/.babelrc +0 -6
  23. package/.npmignore +0 -30
  24. package/.travis.yml +0 -7
  25. package/__snapshots__/cornerCases.test.js.snap +0 -139
  26. package/__snapshots__/example.test.js.snap +0 -408
  27. package/cornerCases.test.js +0 -367
  28. package/dist/utils/sanitizeStyleObj.js +0 -22
  29. package/empty-module.js +0 -1
  30. package/example/.babelrc +0 -4
  31. package/example/.storybook/config.js +0 -7
  32. package/example/.storybook/webpack.config.js +0 -14
  33. package/example/README.md +0 -11
  34. package/example/package.json +0 -55
  35. package/example/stories/Animate/basic.js +0 -73
  36. package/example/stories/Basics/CreatingAndApplyingAStyle.js +0 -12
  37. package/example/stories/Basics/Form.js +0 -24
  38. package/example/stories/Basics/ImpliedTags.js +0 -40
  39. package/example/stories/Basics/PassingStyleAndFuntion.js +0 -13
  40. package/example/stories/Basics/PassingStyleAndFuntionAsArray.js +0 -13
  41. package/example/stories/Basics/ReusingElements.js +0 -13
  42. package/example/stories/Basics/Share.js +0 -19
  43. package/example/stories/Basics/UsingTheTagCreater.js +0 -13
  44. package/example/stories/Basics/WrappingAnExistingElement.js +0 -19
  45. package/example/stories/Button.js +0 -27
  46. package/example/stories/CSSHelpers/CssSelector.js +0 -24
  47. package/example/stories/CSSHelpers/CssSource.js +0 -18
  48. package/example/stories/CSSHelpers/DynamicCssSelectors.js +0 -24
  49. package/example/stories/CSSHelpers/Hover.js +0 -20
  50. package/example/stories/CSSHelpers/MediaQuery.js +0 -22
  51. package/example/stories/CSSHelpers/VendorPrefix.js +0 -19
  52. package/example/stories/CombineStyles/CreatingAndApplyingAStyle.js +0 -16
  53. package/example/stories/CombineStyles/LogicFnWithGenerateElement.js +0 -16
  54. package/example/stories/CombineStyles/PassStyleObjToGenerateElement.js +0 -9
  55. package/example/stories/CombineStyles/UsingAPropFlag.js +0 -16
  56. package/example/stories/CombineStyles/UsingTheTagCreater.js +0 -16
  57. package/example/stories/Ref/byFn.js +0 -51
  58. package/example/stories/Ref/onEvent.js +0 -43
  59. package/example/stories/RuntimeFunctions/DynamicStyles.js +0 -32
  60. package/example/stories/RuntimeFunctions/FunctionWithOutStyle.js +0 -31
  61. package/example/stories/RuntimeFunctions/ModifyingStyles.js +0 -36
  62. package/example/stories/RuntimeFunctions/WithGeneratedElements.js +0 -38
  63. package/example/stories/Welcome.js +0 -90
  64. package/example/stories/index.js +0 -88
  65. package/example/stories/load.js +0 -229
  66. package/example.test.js +0 -16
  67. package/source/Styles.js +0 -23
  68. package/source/element.js +0 -100
  69. package/source/main.js +0 -56
  70. package/source/styleItem.js +0 -105
  71. package/source/utils/buildCssString.js +0 -6
  72. package/source/utils/genCss.js +0 -30
  73. package/source/utils/genStyles.js +0 -19
  74. package/source/utils/hasKids.js +0 -6
  75. package/source/utils/index.js +0 -33
  76. package/source/utils/makeid.js +0 -9
  77. package/source/utils/object2css.js +0 -20
  78. package/source/utils/pubsub.js +0 -22
  79. package/source/utils/replaceColors.js +0 -11
  80. package/source/utils/replacedStyleFn.js +0 -30
  81. package/source/utils/sanitizeOutlineInput.js +0 -72
  82. package/source/utils/sanitizeStyleObj.js +0 -13
  83. package/source/utils/separateCssStyle.js +0 -25
  84. package/source/wrapStyles.js +0 -30
@@ -1,88 +0,0 @@
1
-
2
-
3
- import React from 'react';
4
- import ReactDOMServer from 'react-dom/server';
5
-
6
- import { storiesOf, action, linkTo, setAddon } from "@kadira/storybook";
7
- import { withInfo, setDefaults } from '@storybook/addon-info';
8
-
9
- import { html } from 'js-beautify'
10
-
11
- function htmlEscape(str) {
12
- return str
13
- .replace(/&/g, '&')
14
- .replace(/"/g, '"')
15
- .replace(/'/g, ''')
16
- .replace(/</g, '&lt;')
17
- .replace(/>/g, '&gt;');
18
- }
19
-
20
- // addon-info
21
- setDefaults({
22
- inline: true
23
- });
24
-
25
- import tree from './load';
26
-
27
- //import Button from './Button';
28
- import Welcome from './Welcome';
29
-
30
- storiesOf('Welcome', module)
31
- .add('to Storybook', () => (
32
- <Welcome showApp={linkTo('Button')}/>
33
- ));
34
-
35
- const allElemes = [];
36
-
37
- for(const dir in tree){
38
- const files = tree[dir];
39
- const story = storiesOf(dir, module);
40
- files.forEach( data =>{
41
- const options = data.options || {}
42
- options.text = (data.info)?`**${data.info}**
43
-
44
- ---
45
- ` : ""
46
-
47
- options.text += `
48
- ~~~js
49
- ${htmlEscape(data.source)}
50
- ~~~`
51
-
52
- if(data.note){
53
- options.text += `
54
- ---
55
- ${data.note}
56
-
57
- `
58
- }
59
-
60
- // TODO: KEEP this to SHOW REAL render source <<<<<<<<
61
- /*
62
- options.text += `
63
- ---
64
-
65
- ~~~html
66
- ${htmlEscape(html(ReactDOMServer.renderToStaticMarkup(data.element)))}
67
- ~~~
68
- `*/
69
- story.add(data.title,withInfo(options)( () => data.element ))
70
- allElemes.push(data.element)
71
- })
72
- }
73
-
74
- if (location.hostname === "localhost" || location.hostname === "127.0.0.1")
75
- storiesOf('All', module)
76
- .add('all elements', () => (
77
- <div>{
78
- allElemes
79
- }</div>
80
- ));
81
-
82
-
83
- /*
84
- storiesOf('Button', module)
85
- .add('with some emoji',
86
- withInfo('happy happy joy joy')(() => <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>,{ source: true, inline: true } ))
87
- .add('foo bar',() => <Button onClick={action('bar')}>foo</Button> )
88
- */
@@ -1,229 +0,0 @@
1
-
2
- import sourceBasic from 'raw-loader!./Basics/CreatingAndApplyingAStyle.js?sourceMap';
3
- import Basic from './Basics/CreatingAndApplyingAStyle';
4
-
5
- import sourceBasic2 from 'raw-loader!./Basics/UsingTheTagCreater.js?sourceMap';
6
- import Basic2 from './Basics/UsingTheTagCreater';
7
-
8
- import sourceBasic3 from 'raw-loader!./Basics/ImpliedTags.js?sourceMap';
9
- import Basic3 from './Basics/ImpliedTags';
10
-
11
- import sourceBasic4 from 'raw-loader!./Basics/WrappingAnExistingElement.js?sourceMap';
12
- import Basic4 from './Basics/WrappingAnExistingElement';
13
-
14
- import sourceBasic5 from 'raw-loader!./Basics/ReusingElements.js?sourceMap';
15
- import Basic5 from './Basics/ReusingElements';
16
-
17
- import sourceBasic6 from 'raw-loader!./Basics/PassingStyleAndFuntion.js?sourceMap';
18
- import Basic6 from './Basics/PassingStyleAndFuntion';
19
-
20
- import sourceBasic7 from 'raw-loader!./Basics/PassingStyleAndFuntionAsArray.js?sourceMap';
21
- import Basic7 from './Basics/PassingStyleAndFuntionAsArray';
22
-
23
- import sourceBasic8 from 'raw-loader!./Basics/Share.js?sourceMap';
24
- import Basic8 from './Basics/Share';
25
-
26
- import sourceCombine from 'raw-loader!./CombineStyles/CreatingAndApplyingAStyle.js?sourceMap';
27
- import Combine from './CombineStyles/CreatingAndApplyingAStyle';
28
-
29
- import sourceCombine2 from 'raw-loader!./CombineStyles/UsingTheTagCreater.js?sourceMap';
30
- import Combine2 from './CombineStyles/UsingTheTagCreater';
31
-
32
- import sourceCombine3 from 'raw-loader!./CombineStyles/UsingAPropFlag.js?sourceMap';
33
- import Combine3 from './CombineStyles/UsingAPropFlag';
34
-
35
- import sourceCombine4 from 'raw-loader!./CombineStyles/PassStyleObjToGenerateElement.js?sourceMap';
36
- import Combine4 from './CombineStyles/PassStyleObjToGenerateElement';
37
-
38
- import sourceCombine5 from 'raw-loader!./CombineStyles/LogicFnWithGenerateElement.js?sourceMap';
39
- import Combine5 from './CombineStyles/LogicFnWithGenerateElement';
40
-
41
- import sourceLogic from 'raw-loader!./RuntimeFunctions/DynamicStyles.js?sourceMap';
42
- import Logic from './RuntimeFunctions/DynamicStyles';
43
-
44
- import sourceLogic2 from 'raw-loader!./RuntimeFunctions/ModifyingStyles.js?sourceMap';
45
- import Logic2 from './RuntimeFunctions/ModifyingStyles';
46
-
47
- import sourceLogic3 from 'raw-loader!./RuntimeFunctions/FunctionWithOutStyle.js?sourceMap';
48
- import Logic3 from './RuntimeFunctions/FunctionWithOutStyle';
49
-
50
- import sourceLogic4 from 'raw-loader!./RuntimeFunctions/WithGeneratedElements.js?sourceMap';
51
- import Logic4 from './RuntimeFunctions/WithGeneratedElements';
52
-
53
- import sourceCss from 'raw-loader!./CSSHelpers/Hover.js?sourceMap';
54
- import Css from './CSSHelpers/Hover';
55
-
56
- import sourceCss2 from 'raw-loader!./CSSHelpers/MediaQuery.js?sourceMap';
57
- import Css2 from './CSSHelpers/MediaQuery';
58
-
59
- import sourceCss3 from 'raw-loader!./CSSHelpers/CssSource.js?sourceMap';
60
- import Css3 from './CSSHelpers/CssSource';
61
-
62
- import sourceCss4 from 'raw-loader!./CSSHelpers/VendorPrefix.js?sourceMap';
63
- import Css4 from './CSSHelpers/VendorPrefix';
64
-
65
- import sourceCss5 from 'raw-loader!./CSSHelpers/CssSelector.js?sourceMap';
66
- import Css5 from './CSSHelpers/CssSelector';
67
-
68
- import sourceCss6 from 'raw-loader!./CSSHelpers/DynamicCssSelectors.js?sourceMap';
69
- import Css6 from './CSSHelpers/DynamicCssSelectors';
70
-
71
-
72
- import sourceRef1 from 'raw-loader!./Ref/byFn.js?sourceMap';
73
- import Ref1 from './Ref/byFn';
74
-
75
- import sourceRef2 from 'raw-loader!./Ref/onEvent.js?sourceMap';
76
- import Ref2 from './Ref/onEvent';
77
-
78
- import sourceAnimate from 'raw-loader!./Animate/basic.js?sourceMap';
79
- import Animate from './Animate/basic';
80
-
81
- const tree = {
82
- Basics:[
83
- {
84
- title:'Creating and applying a style',
85
- source:sourceBasic, element:Basic
86
- },
87
- {
88
- title:'Generate a element from a style',
89
- source:sourceBasic2, element:Basic2,
90
- options: {propTables: false, source: false }
91
- },
92
- {
93
- title:'Wrapping an existing element',
94
- source:sourceBasic4, element:Basic4,
95
- options: {propTables: false, source: false }
96
- },
97
- {
98
- title:'Generate an implied named element',
99
- source:sourceBasic3, element:Basic3,
100
- options: {propTables: false, source: false }
101
- },
102
- {
103
- title:'Reusing elements',
104
- source:sourceBasic5, element:Basic5,
105
- options: {propTables: false, source: false }
106
- },
107
- {
108
- title:'Passing Style and Funtion as arguments',
109
- source:sourceBasic6, element:Basic6,
110
- options: {propTables: false, source: false }
111
- },
112
- {
113
- title:'Sharing Style',
114
- source:sourceBasic8, element:Basic8,
115
- options: {propTables: false, source: false }
116
- },
117
- {
118
- title:'⚠ Passing Style and Funtion as Array',
119
- info:'⚠ This feature is deprecated and will be removed in a later version ⚠',
120
- source:sourceBasic7, element:Basic7,
121
- options: {propTables: false, source: false }
122
- }
123
-
124
- ],
125
- "Combine styles":[
126
- {
127
- title:'Using the style function',
128
- source:sourceCombine, element:Combine
129
- },
130
- {
131
- title:'In a generated element',
132
- source:sourceCombine2, element:Combine2,
133
- options: {propTables: false, source: false }
134
- },
135
- {
136
- title:'Using a prop flag',
137
- source:sourceCombine3, element:Combine3,
138
- options: {propTables: false, source: false }
139
- },
140
- {
141
- title:'Logic function With Generate Element',
142
- source:sourceCombine5, element:Combine5,
143
- options: { propTables: false, source: false }
144
- }, // A work in progress
145
- {
146
- title:'Passing a Style objct to a generated element',
147
- source:sourceCombine4, element:Combine4,
148
- options: { propTables: false, source: false }
149
- }
150
- ],
151
- "Style Functions":[
152
- {
153
- title:'Run-time control over your styles.',
154
- source:sourceLogic, element:Logic
155
- },
156
- {
157
- title:'Modify existing styles',
158
- note:'If your funtion have 1 argument, it will be passed only the incoming arguments. With 2 arguments. The first will be the corresponding style and the second will be the incoming arguments.',
159
- source:sourceLogic2, element:Logic2
160
- },
161
- {
162
- title:'Function dont need a style',
163
- source:sourceLogic3, element:Logic3
164
- },
165
- {
166
- title:'Function with generated elements',
167
- source:sourceLogic4, element:Logic4,
168
- options: {propTables: false, source: false }
169
- }
170
- ],
171
- "CSS Helpers":[
172
- {
173
- title:'Media Query',
174
- info: 'Resize your screen to less then 600px',
175
- source:sourceCss2, element:Css2,
176
- options: {propTables: false, source: false }
177
- },
178
- {
179
- title:'Mouse hover',
180
- info: 'You need to include a react-outline Style tag at the top to your page',
181
- source:sourceCss, element:Css,
182
- options: {propTables: false, source: false }
183
- },
184
- {
185
- title:'Css Source',
186
- source:sourceCss3, element:Css3,
187
- options: {propTables: false }
188
- },
189
- {
190
- title:'Css Selector',
191
- source:sourceCss5, element:Css5,
192
- options: {propTables: false , source: false }
193
- },
194
- {
195
- title:'Dynamic Css Selector',
196
- source:sourceCss6, element:Css6,
197
- options: {propTables: false , source: false }
198
- },
199
- {
200
- title:'Vendor Auto-Prefix',
201
- info:"CSS vendor prefixes, also sometime known as or CSS browser prefixes, are a way for browser makers to add support for new CSS features before those features are fully supported in all browsers. It will only add prefixes if a property still needs them",
202
- source:sourceCss4, element:Css4
203
- }
204
- ]
205
- ,"Reference dom element":[
206
- {
207
- title:'function with Dom Events',
208
- source:sourceRef2, element:Ref2,
209
- info:"Any easy way to map 'event' names to functions",
210
- note:"**You pass an Object(mapping 'event' names to functions) as the 'onDomEvent' prop**",
211
- options: {propTables: false , source: false, test:false }
212
- },
213
- {
214
- title:'ref by function',
215
- source:sourceRef1, element:Ref1,
216
- options: {propTables: false , source: false, test:false }
217
- }
218
- ]
219
- ,"Animate":[
220
- {
221
- title:'Animate.css',
222
- info: "Using [ReactCSSTransitionGroup](https://www.npmjs.com/package/react-addons-css-transition-group) and daneden's [animate.css](https://daneden.github.io/animate.css/)",
223
- source:sourceAnimate, element:Animate,
224
- options: {propTables: false, source: false, test:false }
225
- },
226
- ]
227
- }
228
-
229
- export default tree
package/example.test.js DELETED
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import renderer from 'react-test-renderer';
3
- import load from './example/stories/load'
4
-
5
- for(const groupName in load ){
6
- const groupArray = load[groupName];
7
- describe(groupName, () => {
8
- for(const item of groupArray ){
9
- if(item.options && (item.options.test === undefined || item.options.test))
10
- test(item.title, () => {
11
- const elem = renderer.create(item.element);
12
- expect(elem.toJSON()).toMatchSnapshot();
13
- }) // END test
14
- } // END for
15
- }) // END describe
16
- } // END for
package/source/Styles.js DELETED
@@ -1,23 +0,0 @@
1
-
2
- import React from 'react'
3
- import { pubsub, buildCssString } from './utils'
4
-
5
- // TODO: make Styles a "ref" and manual set the content
6
-
7
- export default function Styles(props){
8
- //class StylesElem extends React.Component {
9
- const StylesElem = React.createClass({
10
- displayName: "Styles",
11
- getInitialState: function getInitialState() {
12
- // setTimeout to fix: Warning: setState(...): Cannot update during an existing state transition
13
- pubsub.subscribe(()=> setTimeout(()=>this.setState({cssString:buildCssString(pubsub.get(),props)}), 0) )
14
- return { cssString : buildCssString(pubsub.get(),props)};
15
- },
16
- render: function render() {
17
- return <style>{this.state.cssString}</style>;
18
- }
19
- })
20
- return React.createElement(StylesElem)
21
- }
22
-
23
- Styles.toString = ()=>buildCssString(pubsub.get())
package/source/element.js DELETED
@@ -1,100 +0,0 @@
1
-
2
- import React from 'react'
3
- import { findDOMNode } from 'react-dom'
4
- import { genCss, pubsub } from './utils'
5
-
6
- export default function({elemName, css,styleCSS,inlineStyle,style,styleName, colors, randomClassName, options,replacedStyle}){
7
-
8
- class C2 extends React.Component {
9
-
10
- componentDidMount() {
11
- const onDomEvent = this.props.onDomEvent
12
- for (const listen in onDomEvent) {
13
- this.domElem.addEventListener(listen, event => onDomEvent[listen](this.domElem,event));
14
- }
15
- }
16
-
17
- componentWillUnmount() {
18
- const onDomEvent = this.props.onDomEvent
19
- for (const listen in onDomEvent) {
20
- this.domElem.removeEventListener(listen, event => onDomEvent[listen](this.domElem,event));
21
- }
22
- }
23
-
24
- render(){
25
-
26
- const props = this.props
27
-
28
- if("css" in props){
29
-
30
- const updatedCss = Object.assign({},css)
31
-
32
- for(const selectorRule in props.css){
33
- updatedCss[selectorRule] = Object.assign({},css[selectorRule], "function" === typeof props.css[selectorRule] ? props.css[selectorRule]() : props.css[selectorRule])
34
- }
35
- pubsub.publish(randomClassName, genCss({randomClassName, css:updatedCss,styleCSS, colors,style,styleName}))
36
- }
37
-
38
- const elemProps = Object.assign({},props);
39
-
40
- let passedTrueProps = Object.keys(props)
41
- .filter( name => props[name] === true && styleCSS[styleName] && name in styleCSS[styleName] )
42
- // console.log("passedTrueProps",passedTrueProps)
43
- if(0 < passedTrueProps.length){
44
- passedTrueProps = passedTrueProps.reduce((styleProps, name) => {
45
- // If elem is a HTML type = Removed it Unknown prop `...` on <...> tag. Remove this prop from the element.
46
- if("function" !== typeof elemName && "disabled" !== name){
47
- delete elemProps[name]
48
- }
49
- return Object.assign(styleProps,{[name]:true})
50
- },{})
51
- } else {
52
- passedTrueProps = null
53
- }
54
-
55
- if(passedTrueProps || props.hasOwnProperty("style")){
56
- //if(props.style instanceof Object)
57
- // passedTrueProps = Object.assign({},props.style,passedTrueProps);
58
- if(randomClassName)
59
- elemProps.style = props.style
60
- else
61
- elemProps.style = replacedStyle[styleName](props.style,passedTrueProps);
62
-
63
- } else {
64
- elemProps.style = inlineStyle || replacedStyle[styleName]();
65
- }
66
- //TODO: write a test for this
67
- // For some reason in prod!
68
- // a custom element in a perfect storm can have style undefined
69
- //SEE: test - should generated an element with css selector
70
- // thss is the same prod code.. BUT this is not catching this case :(
71
- if(elemProps.style &&
72
- Object.keys(elemProps.style).length === 0){
73
- delete elemProps.style;
74
- }
75
-
76
- if(options.named){
77
- elemProps.name = elemProps.name || styleName;
78
- }
79
-
80
- elemProps.className = elemProps.className || ""
81
- if(elemProps.className && randomClassName){
82
- elemProps.className += " "
83
- }
84
- elemProps.className += randomClassName || ""
85
- if("" === elemProps.className)
86
- delete elemProps.className;
87
-
88
- if(props.onDomEvent){
89
- elemProps.ref = reatElem => this.domElem = findDOMNode(reatElem)
90
- }
91
-
92
- return React.createElement(elemName||styleName,elemProps,elemProps && elemProps.children)
93
-
94
- }
95
- }
96
-
97
- Object.defineProperty (C2, 'name', {value: styleName||elemName});
98
-
99
- return C2
100
- }
package/source/main.js DELETED
@@ -1,56 +0,0 @@
1
-
2
- import React from 'react'
3
- import { pubsub, sanitizeOutlineInput } from './utils'
4
-
5
- import wrapStylesFactory from './wrapStyles'
6
- import Styles from './Styles'
7
-
8
- const userSetOptions = { named:true/* prefix:getVendorPrefix()*/ }
9
-
10
- const wrapStyles = wrapStylesFactory(userSetOptions)
11
-
12
- //=====================================================
13
- //============================= top Level - Wrap Styles
14
- //=====================================================
15
-
16
- function outline(_styles,options={}){
17
- return sanitizeOutline(sanitizeOutlineInput(_styles,options),options)
18
- }
19
-
20
- function sanitizeOutline(_styles,options){
21
-
22
- const wrappedStyles = wrapStyles(_styles,options);
23
- wrappedStyles.colors = wrappedStyles.colors
24
- || options && options.colors
25
- || userSetOptions && userSetOptions.colors;
26
- return wrappedStyles;
27
- }
28
-
29
- //=====================================================
30
- //============================================= Options
31
- //=====================================================
32
-
33
- function withOptions(options){
34
- if(!options) throw new Error("Bad options values for react-outline:"+JSON.stringify(options))
35
-
36
- const tempOutlineFn = (_styles,optionsOrLogic)=>sanitizeOutline(sanitizeOutlineInput(_styles,optionsOrLogic),options)
37
- if(options.colors){
38
- tempOutlineFn.colors = options.colors
39
- }
40
- return tempOutlineFn;
41
- }
42
-
43
- function setOptions(options){
44
- if(!options) throw new Error("Bad options values for react-outline:"+JSON.stringify(options))
45
- if(options.colors){
46
- outline.colors = options.colors
47
- }
48
- Object.assign(userSetOptions,options)
49
- }
50
-
51
- const testing = {
52
- resetCSS: pubsub.clear
53
- }
54
-
55
- export default outline
56
- export { withOptions, setOptions, Styles, testing }
@@ -1,105 +0,0 @@
1
-
2
- import { hasKids, specialCharacters, specialInnerCharacters, separateCssStyle, makeid, genCss, genStyles, pubsub, sanitizeStyleObj } from './utils'
3
- import element from './element'
4
-
5
- //=====================================================
6
- //========================================== build Elem
7
- //=====================================================
8
-
9
- function buildElem({elemName,args,styleCSS,styleName,options,replacedStyle,colors}){
10
-
11
- elemName = elemName[0] || args[1];
12
- let inlineStyle = null;//replacedStyle[styleName]();
13
-
14
- const baseStyle = styleCSS[styleName] && styleCSS[styleName].base || {}
15
- for(const propN in styleCSS[styleName]){
16
- //if(specialCharacters.includes(propN[0]) || !!propN.match(new RegExp(`[${specialInnerCharacters}]`, "gi"))){
17
- if (/^[a-zA-Z0-9-]+$/.test(propN) === false) {
18
- baseStyle[propN] = styleCSS[styleName][propN]
19
- }
20
- }
21
- //splict ":" and "@" from all over styles
22
- const { css, style } = separateCssStyle(baseStyle);
23
- /*
24
- const cssPropNames = Object.keys(styleCSS[styleName])
25
- .filter(stylePropName => stylePropName[0] === "@" || stylePropName[0] === ":");
26
- */
27
- let randomClassName = "";
28
-
29
- //if(0 < cssPropNames.length){
30
- if(css){
31
- randomClassName = "react-outline-"
32
- if(!global.__TEST__) randomClassName += makeid();
33
- pubsub.publish(randomClassName,genCss({randomClassName, css,styleCSS, colors,style,styleName}))
34
- inlineStyle = {};
35
- }
36
-
37
- return element({elemName, css,styleCSS,inlineStyle,style,styleName, colors, randomClassName, options,randomClassName,replacedStyle})
38
- }
39
-
40
- //=====================================================
41
- //===================================== build Style Obj
42
- //=====================================================
43
-
44
- function buildStyleObj({styleStuff,genStyles,args,colors,caching,cached}){
45
-
46
- if(!caching){
47
- return genStyles(styleStuff,args,colors);
48
- }
49
- // quick test
50
- if(cached.value && cached.source[0] === args[0] && cached.source[0] === args[1]){
51
- return cached.value;
52
- }
53
- // deep test
54
- const key = ""+JSON.stringify(args[0])+JSON.stringify(args[1])
55
- if(key === cached.key){
56
- return cached.value;
57
- }
58
-
59
- cached.key = key;
60
- cached.source[0] = args[0];
61
- cached.source[1] = args[1];
62
- cached.value = genStyles(styleStuff,args,colors);
63
- return cached.value;
64
-
65
- }
66
-
67
- //=====================================================
68
- //========================================== style Item
69
- //=====================================================
70
-
71
- export default function({_styles,replacedStyle,styleCSS, colors, options,caching, wrapStyles}){
72
-
73
- //+++++++++++++++++++++++++++++++++++++ style function
74
- //++++++++++++++++++++++++++++++++++++++++++++++++++++
75
- return (styleName)=>{
76
-
77
- const styleFn = _styles[styleName]||(()=>{});
78
-
79
- const cached = { key:null, value:null, source:[] }
80
- replacedStyle[styleName] = function(...args) {
81
- let elemName = args[0];
82
-
83
- //+++++++++++++++++++++++++++++++++++ build an element
84
- //++++++++++++++++++++++++++++++++++++++++++++++++++++
85
-
86
- if(Array.isArray(elemName) && elemName.hasOwnProperty("raw")){
87
- return buildElem({elemName,args,styleCSS,styleName,options,replacedStyle,colors})
88
- } // elem gen
89
-
90
- //++++++++++++++++++++++++++++++++++++++ generat style
91
- //++++++++++++++++++++++++++++++++++++++++++++++++++++
92
-
93
- const styleStuff = { styleCSS:styleCSS[styleName],styleFn:("object" === typeof args && !_styles[styleName] )?x=>sanitizeStyleObj(x):styleFn };
94
-
95
- return buildStyleObj({styleStuff,genStyles,args,colors,caching,cached})
96
- } // END replacedStyle[styleName] = function(...args)
97
-
98
- //+++++++++++++++++++++++++++++++++ step down the tree
99
- //++++++++++++++++++++++++++++++++++++++++++++++++++++
100
-
101
- if(0 < Object.keys(styleFn).length || hasKids(styleCSS[styleName])){
102
- Object.assign(replacedStyle[styleName], wrapStyles(styleFn,options,styleCSS[styleName]))
103
- }
104
- }
105
- }
@@ -1,6 +0,0 @@
1
- export default function buildCssString(classesValues,props){
2
- let css = Object.keys(classesValues).map(className => classesValues[className] ).join(" ");
3
- css += props.children || "";
4
- css = css.replace(/\n/g, ' ').replace(/\s+/g, ' ');
5
- return css
6
- }
@@ -1,30 +0,0 @@
1
-
2
- import object2css from './object2css'
3
-
4
- export default function genCss({randomClassName, css,styleCSS, colors,style,styleName}){
5
-
6
- let newStyle = (style)?`.${randomClassName}{${ object2css(colors,style) }}`:""
7
-
8
- newStyle = Object.keys(css).reduce( (cssString,propName) => {
9
-
10
-
11
-
12
- const styleContent = object2css(colors,css[propName]
13
- /* || styleCSS[styleName].base
14
- && styleCSS[styleName].base[propName]
15
- || styleCSS[styleName][propName]*/);
16
-
17
-
18
-
19
- if(propName[0] === "@")
20
- return cssString + ` ${propName}{ .${randomClassName}{ ${ styleContent } } } `
21
- else if(propName[0] === ":")
22
- return ` .${randomClassName}${propName}{ ${ styleContent } } ` + cssString
23
- else
24
- return ` .${randomClassName} ${propName}{ ${ styleContent } } ` + cssString
25
- // else // skip unknown prop
26
- // return cssString
27
- } ,newStyle )
28
-
29
- return newStyle;
30
- }
@@ -1,19 +0,0 @@
1
- import Prefixer from 'inline-style-prefixer'
2
-
3
- import replacedStyleFn from './replacedStyleFn'
4
- import replaceColors from './replaceColors'
5
- import {specialCharacters} from './index'
6
-
7
- const prefixer = new Prefixer();
8
-
9
- export default function genStyles(styleStuff, args,colors){
10
- const userResult = replacedStyleFn(styleStuff,args);
11
-
12
- const swapedColor = replaceColors(colors,userResult);
13
- for(const name in swapedColor){
14
- //if(!specialCharacters.includes(name[0]))
15
- swapedColor[name] = prefixer.prefix({a:swapedColor[name]}).a;
16
- }
17
-
18
- return swapedColor;
19
- }
@@ -1,6 +0,0 @@
1
- export default function hasKids(obj){
2
- for(const name in obj){
3
- if("base" !== name && "object" === typeof obj[name])
4
- return true
5
- }
6
- }