This commit is contained in:
vorotamoroz 2022-07-07 13:52:39 +09:00
commit 05a0de7117
15 changed files with 3761 additions and 0 deletions

10
.editorconfig Normal file
View file

@ -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
.eslintignore Normal file
View file

@ -0,0 +1,2 @@
npm node_modules
build

23
.eslintrc Normal file
View file

@ -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
.gitignore vendored Normal file
View file

@ -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
.npmrc Normal file
View file

@ -0,0 +1 @@
tag-version-prefix=""

17
README.md Normal file
View file

@ -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
esbuild.config.mjs Normal file
View file

@ -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
main.ts Normal file
View file

@ -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
manifest.json Normal file
View file

@ -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
}

3372
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

24
package.json Normal file
View file

@ -0,0 +1,24 @@
{
"name": "ninja-cursor",
"version": "0.0.1",
"description": "The plugin which enhance cursor visiblity.",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "vorotamoroz",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.14.47",
"obsidian": "^0.15.4",
"tslib": "2.4.0",
"typescript": "4.7.4"
}
}

82
styles.css Normal file
View file

@ -0,0 +1,82 @@
.x-cursor {
position: absolute;
top: 0;
left: 0;
height: var(--cursor-height);
width: 8px;
display: inline-block;
user-select: none;
background: var(--text-normal);
transform: translate3d(var(--cursor-x2), var(--cursor-y2), 0);
opacity: 0;
pointer-events: none;
}
.x-cursor0 {
animation: a1 75ms cubic-bezier(0.34, 1.36, 0.64, 1) 0s both;
}
.x-cursor1 {
animation: a2 75ms cubic-bezier(0.34, 1.36, 0.64, 1) 0s both;
}
:root {
--cursor-x1: "0px";
--cursor-x2: "0px";
--cursor-y1: "0px";
--cursor-y2: "0px";
--cursor-height: 18px;
}
@keyframes a1 {
0% {
transform: translate3d(var(--cursor-x1), var(--cursor-y1), 0);
background-color: var(--text-normal);
opacity: 0;
}
4% {
opacity: 1;
}
80% {
opacity: 0.95;
}
90% {
transform: translate3d(var(--cursor-x2), var(--cursor-y2), 0);
background-color: var(--text-normal);
opacity: 0.9;
}
100% {
opacity: 0;
}
}
@keyframes a2 {
0% {
transform: translate3d(var(--cursor-x1), var(--cursor-y1), 0);
background-color: var(--text-normal);
opacity: 0;
}
4% {
opacity: 1;
}
80% {
opacity: 0.95;
}
90% {
transform: translate3d(var(--cursor-x2), var(--cursor-y2), 0);
background-color: var(--text-normal);
opacity: 0.9;
}
100% {
opacity: 0;
}
}

24
tsconfig.json Normal file
View file

@ -0,0 +1,24 @@
{
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
"target": "ES6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"strictNullChecks": true,
"lib": [
"DOM",
"ES5",
"ES6",
"ES7"
]
},
"include": [
"**/*.ts"
]
}

14
version-bump.mjs Normal file
View file

@ -0,0 +1,14 @@
import { readFileSync, writeFileSync } from "fs";
const targetVersion = process.env.npm_package_version;
// read minAppVersion from manifest.json and bump version to target version
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
const { minAppVersion } = manifest;
manifest.version = targetVersion;
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
// update versions.json with target version and minAppVersion from manifest.json
let versions = JSON.parse(readFileSync("versions.json", "utf8"));
versions[targetVersion] = minAppVersion;
writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));

4
versions.json Normal file
View file

@ -0,0 +1,4 @@
{
"1.0.0": "0.9.7",
"1.0.1": "0.12.0"
}