Skip to content

Commit

Permalink
update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
trusktr committed Oct 23, 2023
1 parent 12474fd commit b0bd844
Show file tree
Hide file tree
Showing 31 changed files with 990 additions and 1,016 deletions.
24 changes: 2 additions & 22 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,12 @@
root = true

[*]
indent_style = space
indent_size = 4
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.js]
indent_style = space
indent_size = 4

[Gruntfile.js]
indent_style = space
indent_size = 2

[grunt/*.js]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 2

[*.css]
[*.{md,yml}]
indent_style = space
indent_size = 2
54 changes: 27 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ name: tests
on: [push]

jobs:
build:
runs-on: ${{ matrix.operating-system }}
build:
runs-on: ${{ matrix.operating-system }}

strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v1
with:
submodules: 'recursive'
token: ${{ secrets.ACCESS_TOKEN }}
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: 17
- name: npm install, build, and test
# Note, we run bench and cov just to make sure they run successfully, but we're not doing anything with the results yet.
run: |
npm install
npm run clean
npm run build:parser
npm run build
npm run doc
npm run bench
npm test
npm run cov
env:
CI: true
steps:
- uses: actions/checkout@v1
with:
submodules: 'recursive'
token: ${{ secrets.ACCESS_TOKEN }}
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: 17
- name: npm install, build, and test
# Note, we run bench and cov just to make sure they run successfully, but we're not doing anything with the results yet.
run: |
npm install
npm run clean
npm run build:parser
npm run build
npm run doc
npm run bench
npm test
npm run cov
env:
CI: true
7 changes: 3 additions & 4 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export default {
useTabs: true,
tabWidth: 4,
semi: true,
semi: false,
singleQuote: true,
trailingComma: 'all',
bracketSpacing: false,
printWidth: 120,
arrowParens: 'avoid',

overrides: [{files: '*.md', options: {tabWidth: 2}}],
};
overrides: [{files: ['*.md', '*.yml'], options: {useTabs: false, tabWidth: 2}}],
}
18 changes: 9 additions & 9 deletions Gruntfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (grunt) {
dest: 'src/parser/parser.js',
options: {
wrapper: function (src, parser) {
return 'export default ' + parser + ';';
return 'export default ' + parser + ';'
},
},
},
Expand All @@ -17,7 +17,7 @@ module.exports = function (grunt) {
dest: 'src/parser/parserExt.js',
options: {
wrapper: function (src, parser) {
return 'export default ' + parser + ';';
return 'export default ' + parser + ';'
},
},
},
Expand Down Expand Up @@ -45,14 +45,14 @@ module.exports = function (grunt) {
dest: 'docs/AutoLayout.md',
},
},
});
})

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-jsdoc-to-markdown');
grunt.loadNpmTasks('grunt-peg');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-jsdoc-to-markdown')
grunt.loadNpmTasks('grunt-peg')
grunt.loadNpmTasks('grunt-contrib-concat')

// Tasks
grunt.registerTask('doc', ['concat', 'jsdoc2md']);
grunt.registerTask('parser', ['peg']);
};
grunt.registerTask('doc', ['concat', 'jsdoc2md'])
grunt.registerTask('parser', ['peg'])
}
4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
The MIT License (MIT)

Copyright (c) 2015 IjzerenHein
Copyright (c) 2021 Joseph Orbegoso Pea (http://github.com/trusktr)
Copyright (c) 2021 Lume

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
110 changes: 63 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ Auto layout is a system which lets you perform layout using mathematical relatio
```js
// Define the layout constraints using VFL syntax:
var constraints = AutoLayout.VisualFormat.parse(
[
'H:|[view1(==view2)]-10-[view2]|', // The horizontal aspect of the layout
'V:|[view1,view2]|', // The vertical aspect of the layout
],
{extended: true},
);
[
'H:|[view1(==view2)]-10-[view2]|', // The horizontal aspect of the layout
'V:|[view1,view2]|', // The vertical aspect of the layout
],
{extended: true},
)

// Create a view, uses the constraints to calculate the actual positioning and sizing of spaces in the layout:
var view = new AutoLayout.View({constraints: constraints});
view.setSize(400, 500);
var view = new AutoLayout.View({constraints: constraints})
view.setSize(400, 500)

// Access each space in the calculated layout:
console.log(view.subViews.view1); // {left: 0, top: 0, width: 195, height: 500}
console.log(view.subViews.view2); // {left: 205, top: 0, width: 195, height: 500}
console.log(view.subViews.view1) // {left: 0, top: 0, width: 195, height: 500}
console.log(view.subViews.view2) // {left: 205, top: 0, width: 195, height: 500}

// Finally apply the layout to your rendering system. Autolayout is not coupled to any particular rendering system.

// For example, position DOM elements where they should be:
const el1 = document.querySelector('.view1');
el1.style.transform = `transform(${view.subViews.view1.left}px, ${view.subViews.view1.top}px)`;
el1.style.width = view.subViews.view1.width + 'px';
el1.style.height = view.subViews.view1.height + 'px';
const el2 = document.querySelector('.view1');
el2.style.transform = `transform(${view.subViews.view2.left}px, ${view.subViews.view2.top}px)`;
el2.style.width = view.subViews.view2.width + 'px';
el2.style.height = view.subViews.view2.height + 'px';
const el1 = document.querySelector('.view1')
el1.style.transform = `transform(${view.subViews.view1.left}px, ${view.subViews.view1.top}px)`
el1.style.width = view.subViews.view1.width + 'px'
el1.style.height = view.subViews.view1.height + 'px'
const el2 = document.querySelector('.view1')
el2.style.transform = `transform(${view.subViews.view2.left}px, ${view.subViews.view2.top}px)`
el2.style.width = view.subViews.view2.width + 'px'
el2.style.height = view.subViews.view2.height + 'px'

// Or if you're in WebGL using Three.js, then apply values to your meshes:
mesh.postion.set(view.subViews.view2.left, -view.subViews.view2.top, 0);
mesh.scale.set(view.subViews.view2.width, view.subViews.view2.height, 1);
mesh.postion.set(view.subViews.view2.left, -view.subViews.view2.top, 0)
mesh.scale.set(view.subViews.view2.width, view.subViews.view2.height, 1)
```

Layouts can be previewed and debugged using the [Visual Format Editor](https://github.com/IjzerenHein/visualformat-editor):
Expand Down Expand Up @@ -76,29 +76,44 @@ Include the library in your HTML project:

```html
<script type="module">
import AutoLayout from '//unpkg.com/@lume/[email protected]/dist/AutoLayout.js?module';
// ...use AutoLayout here...
import AutoLayout from '//unpkg.com/@lume/[email protected]/dist/AutoLayout.js?module'
// ...use AutoLayout here...
</script>
```

Or when using a bundler like Webpack or Rollup, or [import maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap), use:

```js
import AutoLayout from '@lume/autolayout';
import AutoLayout from '@lume/autolayout'
// ...use AutoLayout here...
```

If you're using import maps, f.e. in a browser without a build, or in a JS
runtime like Deno, you'll need an importmap script that lists autolayout and its
dependency kiwi. F.e.:

```html
<script type="importmap">
{
"imports": {
"@lume/autolayout": "../../dist/AutoLayout.js",
"@lume/kiwi": "../node_modules/@lume/kiwi/dist/kiwi.js"
}
}
</script>
```

### Using the API

To parse VFL into constraints, use:

```javascript
try {
// The VFL can be either a string or an array of strings.
// strings may also contain '\n' which indicates that a new line of VFL will begin.
var constraints = AutoLayout.VisualFormat.parse(['|-[child(==child2)]-[child2]-|', 'V:|[child(==child2)]|']);
// The VFL can be either a string or an array of strings.
// strings may also contain '\n' which indicates that a new line of VFL will begin.
var constraints = AutoLayout.VisualFormat.parse(['|-[child(==child2)]-[child2]-|', 'V:|[child(==child2)]|'])
} catch (err) {
console.log('parse error: ' + err.toString());
console.log('parse error: ' + err.toString())
}
```

Expand All @@ -108,33 +123,33 @@ relations and variables. You can set the size of the view and other properties s
```javascript
// Create a view with a set of constraints
var view = new AutoLayout.View({
constraints: constraints, // initial constraints (optional)
width: 100, // initial width (optional)
height: 200, // initial height (optional)
spacing: 10, // spacing size to use (optional, default: 8)
});
constraints: constraints, // initial constraints (optional)
width: 100, // initial width (optional)
height: 200, // initial height (optional)
spacing: 10, // spacing size to use (optional, default: 8)
})

// get the size and position of the sub-views
for (var key in view.subViews) {
console.log(key + ': ' + view.subViews[key]);
// e.g. {
// name: 'child1',
// left: 20,
// top: 10,
// width: 70,
// height: 80
// }
console.log(key + ': ' + view.subViews[key])
// e.g. {
// name: 'child1',
// left: 20,
// top: 10,
// width: 70,
// height: 80
// }
}
```

By changing the size, the layout is re-evaluated and the subView's are updated:

```javascript
view.setSize(300, 600);
view.setSize(300, 600)

// get the new size & position of the sub-views
for (var key in view.subViews) {
console.log(key + ': ' + view.subViews[key]);
console.log(key + ': ' + view.subViews[key])
}
```

Expand Down Expand Up @@ -170,8 +185,8 @@ view.addConstraint({
Apple's Visual Format Language prefers good notation over completeness of expressibility. Because of this some useful constraints cannot be expressed by "Standard" VFL. LUME AutoLayout defines an extended syntax (superset of VFL) which you opt-in to use. To enable the extended syntax, set option `extended` to `true` when parsing the visual format:

```javascript
var evfl = '|-[view1(==50%)]';
var constraints = AutoLayout.VisualFormat.parse(evfl, {extended: true});
var evfl = '|-[view1(==50%)]'
var constraints = AutoLayout.VisualFormat.parse(evfl, {extended: true})
```

### Language features
Expand Down Expand Up @@ -370,16 +385,17 @@ feature complete is very welcome:

## Contribute

If you like this project and want to support it, show some love
and give it a star.
If you like this project and want to support it, show some love and give it a
star, try it and report any bugs, write new feature ideas, or even
open a pull request!

If you want to participate in development, drop me a line or just issue a pull request.
Also have a look at [CONTRIBUTING](./CONTRIBUTING.md).

## License

© 2015 Hein Rutjes
© 2021 Joseph Orbegoso Pea (http://github.com/trusktr)
© 2021 Lume

[![License](http://img.shields.io/:license-mit-blue.svg)](https://tldrlegal.com/license/mit-license)

Expand Down
2 changes: 1 addition & 1 deletion bench/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.js"></script>

<script type="module">
import './main.js';
import './main.js'
</script>
</body>
</html>
Loading

0 comments on commit b0bd844

Please sign in to comment.