Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtmrz committed Jul 7, 2022
0 parents commit 05a0de7
Show file tree
Hide file tree
Showing 15 changed files with 3,761 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
tab_width = 4
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm node_modules
build
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off"
}
}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# vscode
.vscode

# Intellij
*.iml
.idea

# npm
node_modules

# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.
main.js

# Exclude sourcemaps
*.map

# obsidian
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tag-version-prefix=""
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ninja cursor

The plugin which enhance cursor visiblity.

![ninjacursor](https://user-images.githubusercontent.com/45774780/177688736-8dacd265-d75f-4ca2-8201-aa8c0a8b7a84.gif)

Note : This is the clone implementation of the cool product that I saw on the twitter. But I missed to fav and forgot what is was. I will find that again, and obtain permission. But if you know something, please inform me!!!

## How to install

1. Install [Beta Reviewers Auto-update Tester](https://github.com/TfTHacker/obsidian42-brat)
2. Copy this repo's URL ([https://github.com/vrtmrz/ninja-cursor](https://github.com/vrtmrz/ninja-cursor))
3. Open command pallet, select `BRAT: Add a beta plugin for testing`
4. Paste copied URL into the opened dialog.
5. Press `Add Plugin` button.

License: MIT.
55 changes: 55 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'

const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === 'production');

esbuild.build({
banner: {
js: banner,
},
entryPoints: ['main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/closebrackets',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/comment',
'@codemirror/fold',
'@codemirror/gutter',
'@codemirror/highlight',
'@codemirror/history',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/matchbrackets',
'@codemirror/panel',
'@codemirror/rangeset',
'@codemirror/rectangular-selection',
'@codemirror/search',
'@codemirror/state',
'@codemirror/stream-parser',
'@codemirror/text',
'@codemirror/tooltip',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins],
format: 'cjs',
watch: !prod,
target: 'es2016',
logLevel: "info",
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
}).catch(() => process.exit(1));
101 changes: 101 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Plugin } from 'obsidian';


let lastPos: DOMRect | null = null;
let styleCount = 0;
export default class NinjaCursorPlugin extends Plugin {
cursorElement: HTMLSpanElement;

async onload() {
this.cursorElement = document.createElement("span");

document.body.appendChild(this.cursorElement);
const root = document.documentElement;
root.style.setProperty("--cursor-x1", `${0}`);
root.style.setProperty("--cursor-y1", `${0}`);
root.style.setProperty("--cursor-x2", `${0}`);
root.style.setProperty("--cursor-y2", `${0}`);
this.cursorElement.addClass("x-cursor");

const moveCursor = () => {
const selection = window.getSelection();
if (!selection) {
console.log("Could not find selection")
return;
}
const range = selection.getRangeAt(0);
let rect = range?.getBoundingClientRect()
if (!rect) {
console.log("Could not find range")
return;
}
if (rect.x == 0 && rect.y == 0) {
const textRange = document.createRange()
textRange.setStart(range.startContainer, range.startOffset)
textRange.setEndAfter(range.startContainer)
let textRect = textRange.getBoundingClientRect()
if (textRect.x == 0 && textRect.y == 0) {
textRange.setStart(range.endContainer, range.endOffset - 1)
textRange.setEnd(range.endContainer, range.endOffset)
const textRectx = textRange.getClientRects();
const txx = textRectx.item(textRectx.length - 1);
if (!txx) {
console.log("Could not found")
return;
}
textRect = txx;
textRect.x = txx.right;
textRect.y = txx.bottom - txx.height;
}

if (textRect.x == 0 && textRect.y == 0) {
return;
}
rect = textRect;
}
if (lastPos == null) {
lastPos = rect;
return;
}
if (lastPos.x == rect.x && lastPos.y == rect.y) {
return;
}
styleCount = (styleCount + 1) % 2;
root.style.setProperty("--cursor-height", `${rect.height}px`);
root.style.setProperty("--cursor-x1", `${lastPos.x}px`);
root.style.setProperty("--cursor-y1", `${lastPos.y}px`);
root.style.setProperty("--cursor-x2", `${rect.x}px`);
root.style.setProperty("--cursor-y2", `${rect.y}px`);
this.cursorElement.removeClass("x-cursor0");
this.cursorElement.removeClass("x-cursor1");
this.cursorElement.getAnimations().forEach((anim) => anim.cancel());

window.requestAnimationFrame((time) => {
window.requestAnimationFrame((time) => {
this.cursorElement.addClass(`x-cursor${styleCount}`);
lastPos = rect;
})
})
}
this.registerDomEvent(window, "keydown", (ev) => {
moveCursor();

})
this.registerDomEvent(window, "mousedown", () => {
moveCursor();
})
}


onunload() {
document.body.removeChild(this.cursorElement);
}

async loadSettings() {

}

async saveSettings() {

}
}
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "ninja-cursor",
"name": "Ninja Cursor",
"version": "0.0.1",
"minAppVersion": "0.12.0",
"description": "The plugin which enhance cursor visiblity.",
"author": "vorotamoroz",
"authorUrl": "https://github.com/vrtmrz/",
"isDesktopOnly": false
}
Loading

0 comments on commit 05a0de7

Please sign in to comment.