Skip to content

Commit c90108f

Browse files
committed
v1.0.0
Initial release
0 parents  commit c90108f

27 files changed

+14494
-0
lines changed

Diff for: .eslintrc.json

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"browser": true,
5+
"commonjs": true,
6+
"es2021": true,
7+
"node": true
8+
},
9+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
10+
"parser": "@typescript-eslint/parser",
11+
"parserOptions": {
12+
"ecmaVersion": 12
13+
},
14+
"plugins": ["@typescript-eslint"],
15+
"rules": {
16+
"@typescript-eslint/naming-convention": [
17+
"warn",
18+
{
19+
"selector": "function",
20+
"format": ["camelCase"]
21+
}
22+
],
23+
"@typescript-eslint/semi": "warn",
24+
"@typescript-eslint/ban-ts-comment": "off",
25+
"@typescript-eslint/no-non-null-assertion": "off",
26+
"semi": "off",
27+
"getter-return": "warn",
28+
"no-dupe-args": "warn",
29+
"no-dupe-else-if": "warn",
30+
"no-dupe-keys": "warn",
31+
"no-duplicate-case": "warn",
32+
"no-empty": "warn",
33+
"accessor-pairs": "warn",
34+
"array-callback-return": "warn",
35+
"block-scoped-var": "warn",
36+
"class-methods-use-this": "warn",
37+
"complexity": "warn",
38+
"consistent-return": "warn",
39+
"curly": "warn",
40+
"default-case": "warn",
41+
"default-case-last": "warn",
42+
"default-param-last": "warn",
43+
"dot-location": "off",
44+
"dot-notation": "warn",
45+
"eqeqeq": "warn",
46+
"grouped-accessor-pairs": "warn",
47+
"guard-for-in": "off",
48+
"max-classes-per-file": ["warn", 2],
49+
"no-alert": "warn",
50+
"no-caller": "warn",
51+
"no-case-declarations": "off",
52+
"no-constructor-return": "warn",
53+
"no-div-regex": "warn",
54+
"no-else-return": "warn",
55+
"no-empty-function": "warn",
56+
"no-empty-pattern": "warn",
57+
"no-eq-null": "warn",
58+
"no-eval": "warn",
59+
"no-extend-native": "off",
60+
"no-extra-bind": "warn",
61+
"no-extra-label": "warn",
62+
"no-fallthrough": "warn",
63+
"no-floating-decimal": "warn",
64+
"no-global-assign": "warn",
65+
"no-implicit-coercion": "warn",
66+
"no-implicit-globals": "warn",
67+
"no-implied-eval": "warn",
68+
"no-invalid-this": "off",
69+
"no-iterator": "warn",
70+
"no-labels": "warn",
71+
"no-lone-blocks": "warn",
72+
"no-loop-func": "warn",
73+
"no-magic-numbers": "off",
74+
"no-mixed-spaces-and-tabs": ["warn", "smart-tabs"],
75+
"no-multi-spaces": "warn",
76+
"no-multi-str": "warn",
77+
"no-new": "warn",
78+
"no-new-func": "warn",
79+
"no-new-wrappers": "warn",
80+
"no-octal": "warn",
81+
"no-octal-escape": "warn",
82+
"no-param-reassign": "warn",
83+
"no-proto": "warn",
84+
"no-redeclare": "off",
85+
"no-restricted-properties": "warn",
86+
"no-return-assign": "warn",
87+
"no-return-await": "warn",
88+
"no-script-url": "warn",
89+
"no-self-assign": "warn",
90+
"no-self-compare": "warn",
91+
"no-sequences": "warn",
92+
"no-throw-literal": "warn",
93+
"no-unmodified-loop-condition": "warn",
94+
"no-unused-expressions": "warn",
95+
"no-unused-labels": "warn",
96+
"no-useless-call": "warn",
97+
"no-useless-catch": "warn",
98+
"no-useless-concat": "warn",
99+
"no-useless-escape": "warn",
100+
"no-useless-return": "warn",
101+
"no-void": "warn",
102+
"no-warning-comments": "warn",
103+
"no-with": "warn",
104+
"prefer-named-capture-group": "warn",
105+
"prefer-promise-reject-errors": "off",
106+
"prefer-regex-literals": "warn",
107+
"radix": "warn",
108+
"require-await": "warn",
109+
"require-unicode-regexp": "off",
110+
"vars-on-top": "warn",
111+
"wrap-iife": "warn"
112+
}
113+
}

Diff for: .github/FUNDING.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [TopMarksDevelopment]
2+
custom: ['https://www.paypal.com/donate?hosted_button_id=5UFB62RB4AWNL']

Diff for: .github/workflows/publish.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish Package to npmjs
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
# Setup .npmrc file to publish to npm
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: '16.x'
14+
registry-url: 'https://registry.npmjs.org'
15+
- run: npm ci
16+
- run: npm publish --scope=@topmarksdevelopment --access public
17+
env:
18+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Diff for: .gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Compiled project
2+
lib/
3+
4+
# Dependency directories
5+
node_modules/
6+
7+
# TypeScript v1 declaration files
8+
typings/
9+
10+
# TypeScript cache
11+
*.tsbuildinfo
12+
13+
# Optional npm cache directory
14+
.npm
15+
16+
# Optional eslint cache
17+
.eslintcache

Diff for: .prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 80,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"tabWidth": 4
6+
}

Diff for: .vscode/launch.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug Jest Tests",
6+
"type": "node",
7+
"request": "launch",
8+
"runtimeArgs": [
9+
"--inspect-brk",
10+
"${workspaceRoot}/node_modules/jest/bin/jest.js",
11+
"--runInBand"
12+
],
13+
"console": "integratedTerminal",
14+
"internalConsoleOptions": "neverOpen",
15+
"skipFiles": ["${workspaceFolder}/node_modules/jest-circus/**/*.js"]
16+
}
17+
]
18+
}

Diff for: .vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.formatOnPaste": true,
4+
"editor.formatOnType": true
5+
}

Diff for: CHANGELOG.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!--
2+
Guiding Principles
3+
- Changelogs are for humans, not machines.
4+
- There should be an entry for every single version.
5+
- The same types of changes should be grouped.
6+
- Versions and sections should be linkable.
7+
- The latest version comes first.
8+
- The release date of each version is displayed.
9+
- Mention whether you follow Semantic Versioning.
10+
11+
Types of changes
12+
- Added for new features.
13+
- Changed for changes in existing functionality.
14+
- Deprecated for soon-to-be removed features.
15+
- Removed for now removed features.
16+
- Fixed for any bug fixes.
17+
- Security in case of vulnerabilities.
18+
- Breaking changes for break in new revision
19+
- Other for notable changes that do not
20+
-->
21+
22+
# Changelog
23+
24+
All notable changes to this project will be documented in this file.
25+
26+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
27+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
28+
29+
## [1.0.0] - 2022-12-12
30+
31+
**This was the first release**
32+
33+
<!-- [comp:1.0.1]: https://github.com/TopMarksDevelopment/JavaScript.Position/compare/v1.0.0...v1.0.1
34+
[1.0.1]: https://github.com/TopMarksDevelopment/JavaScript.Position/release/tag/v1.0.1 -->
35+
36+
[1.0.0]: https://github.com/TopMarksDevelopment/JavaScript.Position/release/tag/v1.0.0

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Top Marks Development Limited
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.

Diff for: README.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Position (A JavaScript package)
2+
3+
A small package to help position a floating element. This can be positioned relative to another element or to a mouse event.
4+
5+
### Links
6+
7+
- [Options](#options)
8+
- [Change log](./CHANGELOG.md)
9+
- [License (MIT)](./LICENSE)
10+
11+
## Usage
12+
13+
If you want to position an element to another fixed element then you can use the sample below
14+
15+
```TS
16+
return position(
17+
{
18+
anchor: document.getElementById("Anchor"),
19+
target: document.getElementById("Target"),
20+
my: "top center",
21+
at: "bottom center",
22+
}
23+
);
24+
```
25+
26+
If you'd rather position the element to the mouse's movement then you can use the sample below
27+
28+
> ⚠ It is recommended to debounce the below sample, just to prevent performance issues
29+
30+
```TS
31+
document.addEventListener("mousemove", function(mouse){
32+
const target = document.getElementById("Target"),
33+
pos = position(
34+
{
35+
anchor: mouse,
36+
target: target,
37+
my: "top center",
38+
at: "bottom center",
39+
}
40+
);
41+
42+
target.style.top = pos.top;
43+
target.style.left = pos.left;
44+
});
45+
```
46+
47+
## Options
48+
49+
### `my` - [`PositionAlignment`][pa]
50+
51+
The location on the `target` to position from
52+
53+
### `at` - [`PositionAlignment`][pa]
54+
55+
The location on the `anchor` to position against
56+
57+
### `anchor` - `HTMLElement` OR `MouseEvent`
58+
59+
The element or mouse event to anchor our target to
60+
61+
### `target` - `HTMLElement`
62+
63+
The target that we're going to be positioning
64+
65+
### `collision?` - [`PositionCollision`][pc]
66+
67+
How to handle collisions with the window edge
68+
69+
**Default:** `bestFit`
70+
71+
### `bestFitPreference?` - `horizontal` OR `vertical`
72+
73+
This is the preferred "best" direction when `collision = bestFit` and there is a "best fit" horizontally and vertically
74+
75+
**Default:** `horizontal`
76+
77+
### `defaults?` - `{ my, at }`
78+
79+
The fallback when only one property is supplied or the property supplied is invalid
80+
81+
**Default:** `{ my: "top center", at: "bottom center" }`
82+
83+
## Types
84+
85+
### The `PositionAlignment` type
86+
87+
The `PositionAlignment` will allow any of the below, plus a combination in the form `vertical horizontal` (e.g. `top center`, `bottom right` or `center left`)
88+
89+
- "top"
90+
- "bottom"
91+
- "center"
92+
- "left"
93+
- "right"
94+
95+
### The `PositionCollision` type
96+
97+
- `bestFit`
98+
- This will find the closest fit before trying to flip the element
99+
- `flipFit`
100+
- This will flip the element completely vertically and horizontally
101+
- `ignore`
102+
- This will just ignore any collisions and place the element exactly where you wanted it
103+
104+
[pa]: #The-PositionAlignment-type
105+
[pc]: #The-PositionCollision-type

Diff for: jest.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
transform: { '^.+\\.ts?$': 'ts-jest' },
3+
testEnvironment: 'jsdom',
4+
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
5+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
6+
verbose: true,
7+
};

0 commit comments

Comments
 (0)