├── LICENSE
├── README.md
├── index.html
├── qss.js
└── tests
├── element-queries.html
└── index.html
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Tommy Hodgins
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # QSS
2 |
3 | **A Simple Query Syntax for CSS Element Queries**
4 |
5 | 
6 |
7 | The goal of QSS is to define a simple syntax for specifying element queries by adding a new ending part between a CSS selector list and the block of rules that help define the breakpoints when those rules are to apply.
8 |
9 | Normally in CSS you have something like this:
10 |
11 | ```css
12 | selectorList { block }
13 | ```
14 |
15 | We are going to add a new part for our query between the selector list and the block where we will store instructions for when the rule should apply.
16 |
17 | ```css
18 | selectorList { block }
19 | ```
20 |
21 | Because this exists as a new part between the selector list and the block of rules, if you have a list of selectors like `h1, h2, h3, h4, h5, h6 {}` you only need to add the query once after the selector list is complete, like `h1, h2, h3, h4, h5, h6 {}` rather than `h1 , h2 , h3 , …`.
22 |
23 | This document describes two different formats for expressing element queries for individual CSS rules, one using an `if`-based structure, and another that uses the `@` symbol to declare when it should apply.
24 |
25 | ## Phrase Formats
26 |
27 | ### 1) if <condition> <comparator> <breakpoint>
28 |
29 | - operator: `if`
30 | - condition: `width` | `height` | `characters` | `children` | `xscroll` | `yscroll`
31 | - comparator: `<` | `below` | `under` | `<=` | `max` | `==` | `equals` | `>=` | `min` | `>` | `above` | `over`
32 | - breakpoint: <number>
33 |
34 | #### Examples
35 |
36 | ```css
37 | div if width above 500 {}
38 | ```
39 |
40 | ```css
41 | input if characters under 1 {}
42 | ```
43 |
44 | ### 2) @ <comparator> <breakpoint> <condition>
45 |
46 | - operator: `@`
47 | - comparator: `<` | `below` | `under` | `<=` | `max` | `==` | `equals` | `>=` | `min` | `>` | `above` | `over`
48 | - breakpoint: <number>
49 | - condition: `width` | `height` | `characters` | `children` | `xscroll` | `yscroll`
50 |
51 | #### Examples
52 |
53 | ```css
54 | div @ above 500 width {}
55 | ```
56 |
57 | ```css
58 | input @ under 1 characters {}
59 | ```
60 |
61 | In both phrase formats the whitespace between tokens is optional, this means that if you prefer to think about these as `@above` or `@min` you can express them that way. The following should all equivalent:
62 |
63 | ```css
64 | div if width >= 500 {}
65 | div if width >=500 {}
66 | div if width min 500 {}
67 | div @min 500 width {}
68 | div@min500width{}
69 | div @ >=500 width {}
70 | ```
71 |
72 | ## How it works
73 |
74 | The queries parsed by QSS would be split into the following pieces:
75 |
76 | - selector list
77 | - rule block (or stylesheet?)
78 | - comparator
79 | - condition
80 | - breakpoint
81 |
82 | And these could also be used to construct Element Queries for other syntaxes like:
83 |
84 | - [EQCSS](https://github.com/eqcss/eqcss)
85 | - [Selectory](https://github.com/tomhodgins/cssplus#selectory-a-selector-resolver)
86 | - and using functions like the [container query mixin](https://gist.github.com/tomhodgins/fc42b334beaafc75a271b1ef7c8e33ee)
87 |
88 | Essentially QSS acts as a syntax to abstract away writing these: [Useful Tests for JS-powered Styling](https://codepen.io/tomhodgins/post/useful-tests-for-js-powered-styling)
89 |
90 | ## Plugin Usage
91 |
92 | This repository contains a working proof of concept of a plugin to parse and read QSS syntax. In order to use this plugin you just need to include QSS on the page where you want it to display:
93 |
94 | ```html
95 |
96 | ```
97 |
98 | Then you're able to add queries written in QSS syntax to your site using one of the following methods: a `
102 | ```
103 |
104 | ```html
105 |
106 | ```
107 |
108 | ```html
109 |
110 | ```
111 |
112 | ```html
113 |
114 | ```
115 |
116 | ## Links
117 |
118 | - Website: [tomhodgins.github.io/qss/](http://tomhodgins.github.io/qss/)
119 | - Element Query Demo: [tests/element-queries.html](http://tomhodgins.github.io/qss/tests/element-queries.html)
120 | - Test: [tests/](http://tomhodgins.github.io/qss/tests/)
121 | - [QSS Playground](https://codepen.io/tomhodgins/pen/zPzpVR)
122 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | QSS - A Simple Query Syntax
5 |
6 |
80 |
81 |
QSS
82 |
83 |
A Simple Query Syntax for CSS Element Queries
84 |
85 |
86 |
87 |
The goal of QSS is to define a simple syntax for specifying element queries by adding a new ending part between a CSS selector list and the block of rules that help define the breakpoints when those rules are to apply.
88 |
89 |
Normally in CSS you have something like this:
90 |
91 |
selectorList { block }
92 |
93 |
We are going to add a new part for our query between the selector list and the block where we will store instructions for when the rule should apply.
94 |
95 |
selectorList <query> { block }
96 |
97 |
Because this exists as a new part between the selector list and the block of rules, if you have a list of selectors like h1, h2, h3, h4, h5, h6 {} you only need to add the query once after the selector list is complete, like h1, h2, h3, h4, h5, h6 <query> {} rather than h1 <query>, h2 <query>, h3 <query>, ….
98 |
99 |
This document describes two different formats for expressing element queries for individual CSS rules, one using an if-based structure, and another that uses the @ symbol to declare when it should apply.
In both phrase formats the whitespace between tokens is optional, this means that if you prefer to think about these as @above or @min you can express them that way. The following should all equivalent:
134 |
135 |
div if width >= 500 {}
136 | div if width >=500 {}
137 | div if width min 500 {}
138 | div @min 500 width {}
139 | div@min500width{}
140 | div @ >=500 width {}
141 |
142 |
143 |
144 |
How it works
145 |
146 |
The queries parsed by QSS would be split into the following pieces:
147 |
148 |
149 |
selector list
150 |
rule block (or stylesheet?)
151 |
comparator
152 |
condition
153 |
breakpoint
154 |
155 |
156 |
And these could also be used to construct Element Queries for other syntaxes like:
This repository contains a working proof of concept of a plugin to parse and read QSS syntax. In order to use this plugin you just need to include QSS on the page where you want it to display:
169 |
170 |
<script src=qss.js></script>
171 |
172 |
Then you're able to add queries written in QSS syntax to your site using one of the following methods: a <style> tag, a <link> tag with type=text/qss set, or a <script> tag with a type of text/qss either inline or linked externally using a src="" attribute: