This component is a lightweight, simple line style component.
9 | 10 | ## 📄 API Documents 11 | * [API documentation](https://daybrush.com/css-styled/release/latest/doc/) 12 | 13 | ## ⚙️ Installation 14 | ### npm 15 | ```bash 16 | $ npm install css-styled 17 | ``` 18 | 19 | ### scripts 20 | 21 | ```html 22 | 23 | ``` 24 | 25 | ## 🚀 How to use 26 | ```ts 27 | 28 | import styled from "css-styled"; 29 | 30 | const cssStyled = styled(` 31 | { 32 | display: block; 33 | } 34 | .a { 35 | display: none; 36 | } 37 | `); 38 | 39 | const result = cssStyled.inject(document.body); 40 | 41 | result.destroy(); 42 | ``` 43 | 44 | ## ⭐️ Show Your Support 45 | Please give a ⭐️ if this project helped you! 46 | 47 | ## 👏 Contributing 48 | 49 | If you have any questions or requests or want to contribute to `css-styled` or other packages, please write the [issue](https://github.com/daybrush/css-styled/issues) or give me a Pull Request freely. 50 | 51 | ## 🐞 Bug Report 52 | 53 | If you find a bug, please report to us opening a new [Issue](https://github.com/daybrush/css-styled/issues) on GitHub. 54 | 55 | 56 | ## 📝 License 57 | 58 | This project is [MIT](https://github.com/daybrush/css-styled/blob/master/LICENSE) licensed. 59 | 60 | ``` 61 | MIT License 62 | 63 | Copyright (c) 2019 Daybrush 64 | 65 | Permission is hereby granted, free of charge, to any person obtaining a copy 66 | of this software and associated documentation files (the "Software"), to deal 67 | in the Software without restriction, including without limitation the rights 68 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 69 | copies of the Software, and to permit persons to whom the Software is 70 | furnished to do so, subject to the following conditions: 71 | 72 | The above copyright notice and this permission notice shall be included in all 73 | copies or substantial portions of the Software. 74 | 75 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 76 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 77 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 78 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 79 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 80 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 81 | SOFTWARE. 82 | ``` -------------------------------------------------------------------------------- /packages/css-styled/README.md: -------------------------------------------------------------------------------- 1 | 2 |This component is a lightweight, simple line style component.
9 | 10 | ## 📄 API Documents 11 | * [API documentation](https://daybrush.com/css-styled/release/latest/doc/) 12 | 13 | ## ⚙️ Installation 14 | ### npm 15 | ```bash 16 | $ npm install css-styled 17 | ``` 18 | 19 | ### scripts 20 | 21 | ```html 22 | 23 | ``` 24 | 25 | ## 🚀 How to use 26 | ```ts 27 | 28 | import styled from "css-styled"; 29 | 30 | const cssStyled = styled(` 31 | { 32 | display: block; 33 | } 34 | .a { 35 | display: none; 36 | } 37 | `); 38 | 39 | const result = cssStyled.inject(document.body); 40 | 41 | result.destroy(); 42 | ``` 43 | 44 | ## ⭐️ Show Your Support 45 | Please give a ⭐️ if this project helped you! 46 | 47 | ## 👏 Contributing 48 | 49 | If you have any questions or requests or want to contribute to `css-styled` or other packages, please write the [issue](https://github.com/daybrush/css-styled/issues) or give me a Pull Request freely. 50 | 51 | ## 🐞 Bug Report 52 | 53 | If you find a bug, please report to us opening a new [Issue](https://github.com/daybrush/css-styled/issues) on GitHub. 54 | 55 | 56 | ## 📝 License 57 | 58 | This project is [MIT](https://github.com/daybrush/css-styled/blob/master/LICENSE) licensed. 59 | 60 | ``` 61 | MIT License 62 | 63 | Copyright (c) 2019 Daybrush 64 | 65 | Permission is hereby granted, free of charge, to any person obtaining a copy 66 | of this software and associated documentation files (the "Software"), to deal 67 | in the Software without restriction, including without limitation the rights 68 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 69 | copies of the Software, and to permit persons to whom the Software is 70 | furnished to do so, subject to the following conditions: 71 | 72 | The above copyright notice and this permission notice shall be included in all 73 | copies or substantial portions of the Software. 74 | 75 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 76 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 77 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 78 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 79 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 80 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 81 | SOFTWARE. 82 | ``` -------------------------------------------------------------------------------- /packages/react-css-styled/src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | (process as { env: { [key: string]: string } }).env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl) 112 | .then(response => { 113 | // Ensure service worker exists, and that we really are getting a JS file. 114 | const contentType = response.headers.get('content-type'); 115 | if ( 116 | response.status === 404 || 117 | (contentType != null && contentType.indexOf('javascript') === -1) 118 | ) { 119 | // No service worker found. Probably a different app. Reload the page. 120 | navigator.serviceWorker.ready.then(registration => { 121 | registration.unregister().then(() => { 122 | window.location.reload(); 123 | }); 124 | }); 125 | } else { 126 | // Service worker found. Proceed as normal. 127 | registerValidSW(swUrl, config); 128 | } 129 | }) 130 | .catch(() => { 131 | console.log( 132 | 'No internet connection found. App is running in offline mode.' 133 | ); 134 | }); 135 | } 136 | 137 | export function unregister() { 138 | if ('serviceWorker' in navigator) { 139 | navigator.serviceWorker.ready.then(registration => { 140 | registration.unregister(); 141 | }); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /packages/preact-css-styled/src/demo/App.tsx: -------------------------------------------------------------------------------- 1 | import { Component, h } from 'preact'; 2 | import './App.css'; 3 | import styled from '../preact-css-styled'; 4 | 5 | const css = ` 6 | { 7 | position: relative; 8 | width: 100%; 9 | font-size: 0; 10 | background: #000; 11 | display: flex; 12 | flex-direction: column; 13 | } 14 | * { 15 | box-sizing: border-box; 16 | color: #fff; 17 | } 18 | .header-area, .scroll-area { 19 | width: 100%; 20 | position: relative; 21 | display: flex; 22 | -webkit-align-items: flex-start; 23 | align-items: flex-start; 24 | } 25 | .header-area { 26 | position: relative; 27 | z-index: 10; 28 | top: 0; 29 | height: 30px; 30 | min-height: 30px; 31 | } 32 | .header-area .keyframes { 33 | padding: 0px; 34 | } 35 | .header-area .properties-area, 36 | .header-area .keyframes-area, 37 | .header-area .values-area, 38 | .header-area .keyframes-scroll-area { 39 | height: 100%; 40 | } 41 | .header-area .keyframes-scroll-area { 42 | overflow: hidden; 43 | } 44 | .header-area .property, .header-area .value, .header-area .keyframes { 45 | height: 100%; 46 | } 47 | .header-area .property { 48 | line-height: 30px; 49 | } 50 | .value .add { 51 | text-align: center; 52 | color: #fff; 53 | line-height: 30px; 54 | font-weight: bold; 55 | font-size: 20px; 56 | cursor: pointer; 57 | } 58 | .header-area .keyframes-area::-webkit-scrollbar { 59 | display: none; 60 | } 61 | .header-area .keyframe-cursor { 62 | position: absolute; 63 | border-top: 10px solid #4af; 64 | border-left: 6px solid transparent; 65 | border-right: 6px solid transparent; 66 | width: 0; 67 | height: 0; 68 | bottom: 0; 69 | top: auto; 70 | background: none; 71 | cursor: pointer; 72 | } 73 | .control-area .keyframes { 74 | padding-left: 10px; 75 | } 76 | .play-control-area { 77 | position: absolute; 78 | top: 50%; 79 | left: 50%; 80 | transform: translate(-50%, -50%); 81 | } 82 | .play-control-area .control { 83 | position: relative; 84 | display: inline-block; 85 | vertical-align: middle; 86 | color: white; 87 | margin: 0px 15px; 88 | cursor: pointer; 89 | } 90 | .play { 91 | border-left: 14px solid white; 92 | border-top: 8px solid transparent; 93 | border-bottom: 8px solid transparent; 94 | } 95 | .pause { 96 | border-left: 4px solid #fff; 97 | border-right: 4px solid #fff; 98 | width: 14px; 99 | height: 16px; 100 | } 101 | .prev { 102 | border-right: 10px solid white; 103 | border-top: 6px solid transparent; 104 | border-bottom: 6px solid transparent; 105 | } 106 | .prev:before { 107 | position: absolute; 108 | content: ""; 109 | width: 3px; 110 | height: 10px; 111 | top: 0; 112 | right: 100%; 113 | transform: translate(0, -50%); 114 | background: white; 115 | } 116 | .next { 117 | border-left: 10px solid white; 118 | border-top: 6px solid transparent; 119 | border-bottom: 6px solid transparent; 120 | } 121 | .next:before { 122 | position: absolute; 123 | content: ""; 124 | width: 3px; 125 | height: 10px; 126 | top: 0; 127 | transform: translate(0, -50%); 128 | background: white; 129 | } 130 | .keytime { 131 | position: relative; 132 | display: inline-block; 133 | height: 100%; 134 | font-size: 13px; 135 | font-weight: bold; 136 | color: #777; 137 | } 138 | .keytime:last-child { 139 | max-width: 0px; 140 | } 141 | .keytime span { 142 | position: absolute; 143 | line-height: 1; 144 | bottom: 12px; 145 | display: inline-block; 146 | transform: translate(-50%); 147 | color: #eee; 148 | } 149 | .keytime .graduation { 150 | position: absolute; 151 | bottom: 0; 152 | width: 1px; 153 | height: 10px; 154 | background: #666; 155 | transform: translate(-50%); 156 | } 157 | .keytime .graduation.half { 158 | left: 50%; 159 | height: 7px; 160 | } 161 | .keytime .graduation.quarter { 162 | left: 25%; 163 | height: 5px; 164 | } 165 | .keytime .graduation.quarter3 { 166 | left: 75%; 167 | height: 5px; 168 | } 169 | .scroll-area { 170 | position: relative; 171 | width: 100%; 172 | height: calc(100% - 60px); 173 | overflow: auto; 174 | } 175 | .properties-area, .keyframes-area, .values-area { 176 | display: inline-block; 177 | position: relative; 178 | font-size: 16px; 179 | overflow: auto; 180 | } 181 | 182 | .properties-area::-webkit-scrollbar, .keyframes-area::-webkit-scrollbar { 183 | display: none; 184 | } 185 | .properties-area { 186 | width: 30%; 187 | max-width: 200px; 188 | box-sizing: border-box; 189 | } 190 | .values-area { 191 | width: 50px; 192 | min-width: 50px; 193 | display: inline-block; 194 | border-right: 1px solid #666; 195 | box-sizing: border-box; 196 | } 197 | .value input { 198 | appearance: none; 199 | -webkit-appearance: none; 200 | outline: none; 201 | position: relative; 202 | display: block; 203 | width: 100%; 204 | height: 100%; 205 | background: transparent; 206 | color: #4af; 207 | font-weight: bold; 208 | background: none; 209 | border: 0; 210 | box-sizing: border-box; 211 | text-align: center; 212 | } 213 | .value { 214 | 215 | } 216 | .alt .value input { 217 | cursor: ew-resize; 218 | } 219 | .value[data-object="1"] input { 220 | display: none; 221 | } 222 | .properties-scroll-area { 223 | display: inline-block; 224 | min-width: 100%; 225 | } 226 | .keyframes-area { 227 | flex: 1; 228 | } 229 | .keyframes-scroll-area { 230 | position: relative; 231 | min-width: 300px; 232 | } 233 | .keyframes, .property, .value { 234 | position: relative; 235 | height: 30px; 236 | line-height: 30px; 237 | border-bottom: 1px solid #555; 238 | box-sizing: border-box; 239 | white-space: nowrap; 240 | background: rgba(90, 90, 90, 0.7); 241 | z-index: 1; 242 | } 243 | 244 | .property { 245 | padding-left: 10px; 246 | box-sizing: border-box; 247 | font-size: 13px; 248 | font-weight: bold; 249 | color: #eee; 250 | } 251 | .property .remove { 252 | position: absolute; 253 | display: inline-block; 254 | cursor: pointer; 255 | width: 18px; 256 | height: 18px; 257 | top: 0; 258 | bottom: 0; 259 | right: 10px; 260 | margin: auto; 261 | border-radius: 50%; 262 | border: 2px solid #fff; 263 | vertical-align: middle; 264 | display: none; 265 | margin-left: 10px; 266 | box-sizing: border-box; 267 | } 268 | .property .remove:before, .property .remove:after { 269 | position: absolute; 270 | content: ""; 271 | width: 8px; 272 | height: 2px; 273 | border-radius: 1px; 274 | background: #fff; 275 | top: 0; 276 | left: 0; 277 | right: 0; 278 | bottom: 0; 279 | margin: auto; 280 | } 281 | .property .remove:before { 282 | transform: rotate(45deg); 283 | } 284 | .property .remove:after { 285 | transform: rotate(-45deg); 286 | } 287 | .property:hover .remove { 288 | display: inline-block; 289 | } 290 | 291 | [data-item="1"], [data-item="1"] .add { 292 | height: 30px; 293 | line-height: 30px; 294 | } 295 | .time-area { 296 | position: absolute; 297 | top: 0; 298 | left: 10px; 299 | font-size: 13px; 300 | color: #4af; 301 | line-height: 30px; 302 | font-weight: bold; 303 | height: 100%; 304 | line-height: 30px; 305 | border: 0; 306 | background: transparent; 307 | outline: 0; 308 | } 309 | .time-area:after { 310 | content: "s"; 311 | } 312 | .property .arrow { 313 | position: relative; 314 | display: inline-block; 315 | width: 20px; 316 | height: 25px; 317 | cursor: pointer; 318 | vertical-align: middle; 319 | } 320 | .property .arrow:after { 321 | content: ""; 322 | position: absolute; 323 | top: 0; 324 | right: 0; 325 | left: 0; 326 | bottom: 0; 327 | margin: auto; 328 | width: 0; 329 | height: 0; 330 | border-top: 6px solid #eee; 331 | border-left: 4px solid transparent; 332 | border-right: 4px solid transparent; 333 | } 334 | .property[data-fold="1"] .arrow:after { 335 | border-top: 4px solid transparent; 336 | border-bottom: 4px solid transparent; 337 | border-right: 0; 338 | border-left: 6px solid #eee; 339 | } 340 | .property[data-object="0"] .arrow { 341 | display: none; 342 | } 343 | .property.fold, .keyframes.fold, .value.fold { 344 | display: none; 345 | } 346 | .property.select, .value.select, .keyframes.select { 347 | background: rgba(120, 120, 120, 0.7); 348 | } 349 | .keyframes { 350 | 351 | } 352 | .keyframe-delay { 353 | position: absolute; 354 | top: 3px; 355 | bottom: 3px; 356 | left: 0; 357 | background: #4af; 358 | opacity: 0.2; 359 | z-index: 0; 360 | } 361 | .keyframe-group { 362 | position: absolute; 363 | top: 3px; 364 | bottom: 3px; 365 | left: 0; 366 | background: #4af; 367 | opacity: 0.6; 368 | border: 1px solid rgba(0, 0, 0, 0.2); 369 | border-left-color: rgba(255, 255, 255, 0.2); 370 | border-top-color: rgba(255, 255, 255, 0.2); 371 | z-index: 0; 372 | } 373 | .keyframe-line { 374 | position: absolute; 375 | height: 8px; 376 | top: 0; 377 | bottom: 0; 378 | margin: auto; 379 | background: #666; 380 | z-index: 0; 381 | } 382 | .keyframe { 383 | position: absolute; 384 | font-size: 0px; 385 | width: 12px; 386 | height: 12px; 387 | top: 0px; 388 | bottom: 0px; 389 | margin: auto; 390 | background: #fff; 391 | border: 2px solid #383838; 392 | border-radius: 2px; 393 | box-sizing: border-box; 394 | transform: translate(-50%) rotate(45deg); 395 | z-index: 1; 396 | cursor: pointer; 397 | } 398 | .keyframe[data-no="1"] { 399 | opacity: 0.2; 400 | } 401 | .select .keyframe { 402 | border-color: #555; 403 | } 404 | .keyframe.select { 405 | background: #4af; 406 | } 407 | .keyframes-container, .line-area { 408 | position: relative; 409 | width: calc(100% - 30px); 410 | left: 15px; 411 | height: 100%; 412 | } 413 | .line-area { 414 | position: absolute; 415 | top: 0; 416 | z-index: 0; 417 | } 418 | .keyframe-cursor { 419 | position: absolute; 420 | top: 0; 421 | z-index: 1; 422 | background: #4af; 423 | width: 1px; 424 | height: 100%; 425 | left: 15px; 426 | transform: translate(-50%); 427 | } 428 | .scroll-aare .keyframe-cursor { 429 | pointer-events: none; 430 | } 431 | .division-line { 432 | position: absolute; 433 | background: #333; 434 | width: 1px; 435 | height: 100%; 436 | transform: translate(-50%); 437 | }`; 438 | 439 | const Styler = styled("div", css); 440 | 441 | const App = () => { 442 | return ( 443 |