soiz1 commited on
Commit
d4648ea
·
verified ·
1 Parent(s): 7a0e576

Upload folder using huggingface_hub

Browse files
.eslintignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /src/util.js
.eslintrc.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true,
5
+ "amd": true,
6
+ "commonjs": true
7
+ },
8
+ "extends": "eslint:recommended",
9
+ "rules": {
10
+ "indent": ["error", 2],
11
+ "quotes": ["error", "single"],
12
+ "no-extra-semi": "off"
13
+ },
14
+ "globals": {
15
+ "L": true
16
+ }
17
+ }
.github/FUNDING.yml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ko_fi: surunzi
2
+ open_collective: eruda
.github/workflows/main.yml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - 'master'
8
+ paths:
9
+ - 'src/**/*'
10
+
11
+ jobs:
12
+ ci:
13
+
14
+ runs-on: ubuntu-latest
15
+
16
+ strategy:
17
+ matrix:
18
+ node-version: [16.x]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Use Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v2
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ - run: npm i
27
+ - run: npm run ci
.github/workflows/publish.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Publish to NPM
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ release:
6
+ types: [created]
7
+
8
+ jobs:
9
+ publish:
10
+
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v2
16
+ - name: Setup Node
17
+ uses: actions/setup-node@v2
18
+ with:
19
+ node-version: '18.x'
20
+ registry-url: 'https://registry.npmjs.org'
21
+ - name: Build eruda-geolocation
22
+ run: |
23
+ npm i
24
+ npm run build
25
+ - name: Publish package on NPM
26
+ run: npm publish
27
+ env:
28
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ /node_modules/
2
+ eruda-geolocation.js
3
+ eruda-geolocation.js.map
4
+ package-lock.json
.prettierrc.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "singleQuote": true,
3
+ "tabWidth": 2,
4
+ "semi": false
5
+ }
CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ ## v2.1.0 (6 Aug 2024)
2
+
3
+ * fix: obsolete api
4
+
5
+ ## v2.0.0 (6 Jan 2020)
6
+
7
+ * feat: theme support
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018-present liriliri
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.
README.md CHANGED
@@ -1,10 +1,30 @@
1
- ---
2
- title: Eruda Geolocation
3
- emoji: 📉
4
- colorFrom: green
5
- colorTo: pink
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # eruda-geolocation
2
+
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![Build status][ci-image]][ci-url]
5
+ [![License][license-image]][npm-url]
6
+
7
+ [npm-image]: https://img.shields.io/npm/v/eruda-geolocation.svg
8
+ [npm-url]: https://npmjs.org/package/eruda-geolocation
9
+ [ci-image]: https://img.shields.io/github/actions/workflow/status/liriliri/eruda-geolocation/main.yml?branch=master&style=flat-square
10
+ [ci-url]: https://github.com/liriliri/eruda-geolocation/actions/workflows/main.yml
11
+ [license-image]: https://img.shields.io/npm/l/eruda-geolocation.svg
12
+
13
+ Eruda plugin for testing geolocation.
14
+
15
+ ## Demo
16
+
17
+ Browse it on your phone:
18
+ [https://eruda.liriliri.io/?plugin=geolocation](https://eruda.liriliri.io/?plugin=geolocation)
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install eruda-geolocation --save
24
+ ```
25
+
26
+ ```javascript
27
+ eruda.add(erudaGeolocation);
28
+ ```
29
+
30
+ Make sure Eruda is loaded before this plugin, otherwise won't work.
index.html ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
6
+ <title>Eruda-geolocation</title>
7
+ </head>
8
+ <body>
9
+ <script src="node_modules/eruda/eruda.js"></script>
10
+ <script>eruda.init({tool: []});</script>
11
+ <script src="assets/eruda-geolocation.js"></script>
12
+ <script>eruda.add(erudaGeolocation).show('geolocation').show();</script>
13
+ </body>
14
+ </html>
package.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "eruda-geolocation",
3
+ "version": "2.1.0",
4
+ "description": "Eruda plugin for testing geolocation",
5
+ "main": "eruda-geolocation.js",
6
+ "browserslist": [
7
+ "since 2015",
8
+ "not dead"
9
+ ],
10
+ "files": [
11
+ "eruda-geolocation.js",
12
+ "eruda-geolocation.js.map"
13
+ ],
14
+ "scripts": {
15
+ "dev": "webpack-dev-server --host 0.0.0.0 --mode development",
16
+ "build": "webpack --mode production",
17
+ "ci": "npm run lint && npm run build && npm run es5",
18
+ "lint": "eslint src/**/*.js",
19
+ "format": "lsla prettier \"src/*.{js,scss}\" \"*.json\" --write",
20
+ "es5": "es-check es5 eruda-geolocation.js"
21
+ },
22
+ "keywords": [
23
+ "eruda",
24
+ "plugin",
25
+ "geolocation"
26
+ ],
27
+ "author": "surunzi",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/liriliri/eruda-geolocation/issues"
31
+ },
32
+ "homepage": "https://github.com/liriliri/eruda-geolocation#readme",
33
+ "devDependencies": {
34
+ "@babel/core": "^7.21.3",
35
+ "@babel/plugin-transform-runtime": "^7.21.0",
36
+ "@babel/preset-env": "^7.20.2",
37
+ "autoprefixer": "^10.4.14",
38
+ "babel-loader": "^9.1.2",
39
+ "css-loader": "^3.4.2",
40
+ "eruda": "^3.2.0",
41
+ "es-check": "^7.2.1",
42
+ "eslint": "^8.57.0",
43
+ "licia": "^1.41.1",
44
+ "postcss": "^8.4.21",
45
+ "postcss-class-prefix": "^0.3.0",
46
+ "postcss-loader": "^7.0.2",
47
+ "sass": "^1.77.8",
48
+ "sass-loader": "^14.2.1",
49
+ "webpack": "^5.93.0",
50
+ "webpack-cli": "^5.1.4",
51
+ "webpack-dev-server": "^4.12.0"
52
+ }
53
+ }
src/index.js ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const loadJs = require('licia/loadJs')
2
+
3
+ module.exports = function (eruda) {
4
+ const { evalCss } = eruda.util
5
+
6
+ class Geolocation extends eruda.Tool {
7
+ constructor() {
8
+ super()
9
+ this.name = 'geolocation'
10
+ this._style = evalCss(require('./style.scss'))
11
+ }
12
+ init($el, container) {
13
+ super.init($el, container)
14
+ $el.html(
15
+ '<div id="eruda-map" class="eruda-map"></div><div class="eruda-info"></div>'
16
+ )
17
+
18
+ this._initMap()
19
+ this._$info = this._$el.find('.eruda-info')
20
+ }
21
+ show() {
22
+ super.show()
23
+
24
+ this.resetView()
25
+ }
26
+ resetView() {
27
+ if (!navigator.geolocation) return
28
+
29
+ navigator.geolocation.getCurrentPosition(
30
+ (position) => {
31
+ var coords = position.coords,
32
+ longitude = coords.longitude,
33
+ latitude = coords.latitude
34
+
35
+ this.setView(latitude, longitude)
36
+ },
37
+ (e) => {
38
+ this.setInfo(e.message)
39
+ }
40
+ )
41
+ }
42
+ setView(latitude, longitude) {
43
+ if (!this._map) return
44
+
45
+ this._map.setView([latitude, longitude], 12)
46
+
47
+ this.setInfo('latitude: ' + latitude + ' ' + 'longitude: ' + longitude)
48
+ }
49
+ setInfo(text) {
50
+ this._$info.text(text)
51
+ }
52
+ hide() {
53
+ super.hide()
54
+ }
55
+ destroy() {
56
+ super.destroy()
57
+ evalCss.remove(this._style)
58
+ }
59
+ _initMap() {
60
+ loadCss(
61
+ 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css',
62
+ this._$el.get(0)
63
+ )
64
+ loadJs('https://unpkg.com/leaflet@1.9.4/dist/leaflet.js', (isLoaded) => {
65
+ if (!isLoaded) return this.setInfo('Failed to init map')
66
+
67
+ this.setInfo('Map successfully initialized')
68
+
69
+ this._map = L.map(this._$el.find('#eruda-map').get(0), {
70
+ center: [39.9, 116.39],
71
+ zoom: 2,
72
+ })
73
+ L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {}).addTo(
74
+ this._map
75
+ )
76
+
77
+ this.resetView()
78
+ })
79
+ }
80
+ }
81
+
82
+ return new Geolocation()
83
+ }
84
+
85
+ function loadCss(src, container) {
86
+ const link = document.createElement('link')
87
+
88
+ link.rel = 'stylesheet'
89
+ link.type = 'text/css'
90
+ link.href = src
91
+
92
+ container = container || document.head
93
+ container.appendChild(link)
94
+ }
src/style.scss ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .geolocation {
2
+ position: relative;
3
+ .map {
4
+ position: absolute;
5
+ left: 0;
6
+ top: 0;
7
+ width: 100%;
8
+ height: 100%;
9
+ }
10
+ .info {
11
+ position: absolute;
12
+ bottom: 0;
13
+ left: 0;
14
+ background: var(--darker-background);
15
+ padding: 10px;
16
+ color: var(--foreground);
17
+ width: 100%;
18
+ border-top: 1px solid var(--border);
19
+ z-index: 1000;
20
+ }
21
+ }
webpack.config.js ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const autoprefixer = require('autoprefixer')
2
+ const postcss = require('postcss')
3
+ const webpack = require('webpack')
4
+ const path = require('path')
5
+ const pkg = require('./package.json')
6
+ const classPrefix = require('postcss-class-prefix')
7
+ const TerserPlugin = require('terser-webpack-plugin')
8
+
9
+ const banner = pkg.name + ' v' + pkg.version + ' ' + pkg.homepage
10
+
11
+ module.exports = (env, argv) => {
12
+ const config = {
13
+ devtool: 'source-map',
14
+ entry: './src/index.js',
15
+ devServer: {
16
+ static: {
17
+ directory: path.join(__dirname, './'),
18
+ },
19
+ port: 8080,
20
+ },
21
+ output: {
22
+ path: __dirname,
23
+ filename: 'eruda-geolocation.js',
24
+ publicPath: '/assets/',
25
+ library: ['erudaGeolocation'],
26
+ libraryTarget: 'umd',
27
+ },
28
+ module: {
29
+ rules: [
30
+ {
31
+ test: /\.js$/,
32
+ exclude: /node_modules/,
33
+ use: {
34
+ loader: 'babel-loader',
35
+ options: {
36
+ sourceType: 'unambiguous',
37
+ presets: ['@babel/preset-env'],
38
+ plugins: ['@babel/plugin-transform-runtime'],
39
+ },
40
+ },
41
+ },
42
+ {
43
+ test: /\.scss$/,
44
+ use: [
45
+ 'css-loader',
46
+ {
47
+ loader: 'postcss-loader',
48
+ options: {
49
+ postcssOptions: {
50
+ plugins: [
51
+ postcss.plugin('postcss-namespace', function () {
52
+ // Add '.dev-tools .tools ' to every selector.
53
+ return function (root) {
54
+ root.walkRules(function (rule) {
55
+ if (!rule.selectors) return rule
56
+
57
+ rule.selectors = rule.selectors.map(function (
58
+ selector
59
+ ) {
60
+ return '.dev-tools .tools ' + selector
61
+ })
62
+ })
63
+ }
64
+ }),
65
+ classPrefix('eruda-'),
66
+ autoprefixer,
67
+ ],
68
+ },
69
+ },
70
+ },
71
+ 'sass-loader',
72
+ ],
73
+ },
74
+ ],
75
+ },
76
+ plugins: [new webpack.BannerPlugin(banner)],
77
+ }
78
+
79
+ if (argv.mode === 'production') {
80
+ config.optimization = {
81
+ minimize: true,
82
+ minimizer: [
83
+ new TerserPlugin({
84
+ terserOptions: {
85
+ format: {
86
+ comments: false,
87
+ },
88
+ },
89
+ extractComments: false,
90
+ }),
91
+ ],
92
+ }
93
+ }
94
+
95
+ return config
96
+ }