Initial commit
10
.editorconfig
Normal 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
|
||||
3
.eslintignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
node_modules/
|
||||
|
||||
main.js
|
||||
23
.eslintrc
Normal 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"
|
||||
}
|
||||
}
|
||||
34
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
name: Release Obsidian plugin
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "18.x"
|
||||
|
||||
- name: Build plugin
|
||||
run: |
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
- name: Create release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
tag="${GITHUB_REF#refs/tags/}"
|
||||
|
||||
gh release create "$tag" \
|
||||
--title="$tag" \
|
||||
--draft \
|
||||
main.js manifest.json
|
||||
22
.gitignore
vendored
Normal 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
|
|
@ -0,0 +1 @@
|
|||
tag-version-prefix=""
|
||||
7
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Changelog
|
||||
|
||||
## [1.0.0] - 2023-11-05
|
||||
|
||||
_🎉 First release._
|
||||
|
||||
[1.0.0]: https://github.com/noxonad/obsidian-barcode-generator/releases/tag/1.0.0
|
||||
165
LICENSE
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
72
README.md
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
Obsidian Barcode Generator
|
||||
==========================
|
||||
|
||||
A plugin for [obsidian](https://obsidian.md/) that generates and displays barcodes in different variations. It uses the [JsBarcode](https://github.com/lindell/JsBarcode) plugin to generate the barcode.
|
||||
|
||||
For a plugin that generates qr codes, you might check [this repository](https://github.com/rudimuc/obsidian-qrcode).
|
||||
|
||||
## Installation
|
||||
|
||||
### From Obsidian
|
||||
|
||||
You can activate this plugin within Obsidian by doing the following:
|
||||
|
||||
- Open Settings > Comunity Plugins;
|
||||
- Make sure the Restricted Mode is off;
|
||||
- Click on Browse community plugins;
|
||||
- Search for "Barcode";
|
||||
- Click Install;
|
||||
- Don't forget to enable it before using.
|
||||
|
||||
### Mobile
|
||||
|
||||
This plugin works on mobile as well. The installation processs is the same as on desktop.
|
||||
|
||||
### Manual Installation
|
||||
|
||||
You can download this plugin manually from the [latest releases](https://github.com/noxonad/obsidian-barcode-generator/releases). Copy the `main.js` and `manifest.json` into `<vault>/.obsidian/plugins/obsidian-barcode`. Then you can enable the plugin from `Comunity Plugins` in obsidian.
|
||||
|
||||
## Usage
|
||||
|
||||
For an insertion of the default barcode, you can use the following codeblock structure:
|
||||
````markdown
|
||||
```barcode
|
||||
content
|
||||
```
|
||||
````
|
||||
|
||||
If you want to select a specific type of barcode, you can type dash and then the barcode types:
|
||||
|
||||
````markdown
|
||||
```barcode-code128
|
||||
content
|
||||
```
|
||||
````
|
||||
|
||||
Note: after changing the options, the barcodes on the page won't be refreshed.
|
||||
|
||||
### Barcodes
|
||||
|
||||
As for now, the following barcodes are supported:
|
||||
| Codeblock | Name | Description | Image |
|
||||
| ------------------ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
|
||||
| barcode-code128 | Code 128 | Automatic selection of Code 128. It has a range of 30 characters or 60 digits. |  |
|
||||
| barcode-code128a | Code 128 A | Encodes ASCII characters 00 to 95 (0–9, A–Z and control codes), special characters, and FNC 1–4. |  |
|
||||
| barcode-code128b | Code 128 B | Encodes ASCII characters 32 to 127 (0–9, A–Z, a–z), special characters, and FNC 1–4. |  |
|
||||
| barcode-code128c | Code 128 C | 00–99 (encodes two digits with a single code point) and FNC1. |  |
|
||||
| barcode-ean13 | EAN-13 | Encodes 13 digits. Used in labeling products. The last digit is a checksum. If the last digit is not specified, it'll be automatically generated. |  |
|
||||
| barcode-upc | UPC | Encodes 12 digits. Used in labeling products. The last digit is a checksum. If the last digit is not specified, it'll be automatically generated. |  |
|
||||
| barcode-ean8 | EAN-8 | Encodes 8 ditis. The last digit is a checksum. If the last digit is not specified, it'll be automatically generated. |  |
|
||||
| barcode-ean5 | EAN 5 | Encodes 5 digits. |  |
|
||||
| barcode-ean2 | EAN 2 | Encodes 2 digits. |  |
|
||||
| barcode-code39 | Code 39 | Encodes numbers, uppercase letters and a number of special characters (`-`, `.`, `$`, `/`, `+`, `%`, and `space`) |  |
|
||||
| barcode-itf4 | ITF-14 | Encodes 14 digits. The last digit is a checksum. If the last digit is not specified, it'll be automatically generated. |  |
|
||||
| barcode-msi | MSI | Encodes digits. |  |
|
||||
| barcode-msi10 | MSI 10 | Encodes digits. The checksum modulo 10 is done automatically. |  |
|
||||
| barcode-msi11 | MSI 11 | Encodes digits. The checksum modulo 11 is done automatically. |  |
|
||||
| barcode-msi1010 | MSI 1010 | Encodes digits. The checksum modulo 1010 is done automatically. |  |
|
||||
| barcode-msi1110 | MSI 1110 | Encodes digits. The checksum modulo 1110 is done automatically. |  |
|
||||
| barcode-pharmacode | Pharmacode | Encodes numbers from 3 to 131070. |  |
|
||||
| barcode-codabar | Codabar | Encodes numbers and a number of special characters (`–`, `$`, `:`, `/`, `+`, `.`). You can set start and stop characters to `A`, `B`, `C` or `D` but if no start and stop character is defined `A` will be used. |  |
|
||||
|
||||
Note that some barcodes have certain limitation of the content, and if the provided contents doesn't match them, the barcode won't be displayed. For more details about the barcodes, you can check out [this resource](https://github.com/lindell/JsBarcode/wiki).
|
||||
48
esbuild.config.mjs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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");
|
||||
|
||||
const context = await esbuild.context({
|
||||
banner: {
|
||||
js: banner,
|
||||
},
|
||||
entryPoints: ["main.ts"],
|
||||
bundle: true,
|
||||
external: [
|
||||
"obsidian",
|
||||
"electron",
|
||||
"@codemirror/autocomplete",
|
||||
"@codemirror/collab",
|
||||
"@codemirror/commands",
|
||||
"@codemirror/language",
|
||||
"@codemirror/lint",
|
||||
"@codemirror/search",
|
||||
"@codemirror/state",
|
||||
"@codemirror/view",
|
||||
"@lezer/common",
|
||||
"@lezer/highlight",
|
||||
"@lezer/lr",
|
||||
...builtins],
|
||||
format: "cjs",
|
||||
target: "es2018",
|
||||
logLevel: "info",
|
||||
sourcemap: prod ? false : "inline",
|
||||
treeShaking: true,
|
||||
outfile: "main.js",
|
||||
});
|
||||
|
||||
if (prod) {
|
||||
await context.rebuild();
|
||||
process.exit(0);
|
||||
} else {
|
||||
await context.watch();
|
||||
}
|
||||
BIN
img/codabar.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
img/code128.png
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
img/code128a.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
img/code128b.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
img/code128c.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
img/code39.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
img/ean13.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
img/ean2.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
img/ean5.png
Normal file
|
After Width: | Height: | Size: 3 KiB |
BIN
img/ean8.png
Normal file
|
After Width: | Height: | Size: 4 KiB |
BIN
img/itf14.png
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
img/msi.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
img/msi10.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
img/msi1010.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
img/msi11.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
img/msi1110.png
Normal file
|
After Width: | Height: | Size: 8 KiB |
BIN
img/pharmacode.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
img/upc.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
10
manifest.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"id": "obsidian-barcode-generator",
|
||||
"name": "Barcode Generator",
|
||||
"version": "1.0.0",
|
||||
"minAppVersion": "0.9.0",
|
||||
"description": "A barcode generator for obsidian.",
|
||||
"author": "noxonad",
|
||||
"authorUrl": "https://github.com/noxonad",
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
2292
package-lock.json
generated
Normal file
30
package.json
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "obsidian-barcode-generator",
|
||||
"version": "1.0.0",
|
||||
"description": "Generates a barcode of your choice from your code block.",
|
||||
"main": "src/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": [
|
||||
"barcode",
|
||||
"obsidian"
|
||||
],
|
||||
"author": "noxoand",
|
||||
"license": "LGPL-3.0-only",
|
||||
"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.17.3",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsbarcode": "^3.11.5"
|
||||
}
|
||||
}
|
||||
38
src/main.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { Plugin } from 'obsidian';
|
||||
import { BarcodeSettingsTab, BarcodeSettings, DEFAULT_SETTINGS } from "settings"
|
||||
import { BARCODE_TAG_NAME } from 'processor/tags';
|
||||
import { SimpleBarcodeProcessor } from 'processor/simple';
|
||||
import { AdvancedBarcodeProcessor } from 'processor/advanced';
|
||||
|
||||
export default class Barcode extends Plugin {
|
||||
settings: BarcodeSettings;
|
||||
|
||||
async attachBarcodeProcessors() {
|
||||
// Attach simple barcode blocks
|
||||
new SimpleBarcodeProcessor(this).processBarcode(this.settings, this.settings.barcode_name);
|
||||
|
||||
// Attach barcode-* blocks
|
||||
for (const [code, _] of Object.entries(BARCODE_TAG_NAME)) {
|
||||
new AdvancedBarcodeProcessor(this).processBarcode(this.settings, `${this.settings.barcode_name}-${code.toLowerCase()}`);
|
||||
}
|
||||
}
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
||||
this.addSettingTab(new BarcodeSettingsTab(this.app, this));
|
||||
|
||||
this.attachBarcodeProcessors();
|
||||
}
|
||||
|
||||
onunload() {
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
}
|
||||
39
src/processor/advanced.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { BarcodeProcessor } from "./barcode.interface";
|
||||
import { BarcodeSettings } from "settings";
|
||||
import { BARCODE_TAG_NAME } from "./tags";
|
||||
import JsBarcode from "jsbarcode";
|
||||
import Barcode from "main";
|
||||
|
||||
export class AdvancedBarcodeProcessor implements BarcodeProcessor {
|
||||
barcode_app: Barcode;
|
||||
|
||||
constructor(app: Barcode) {
|
||||
this.barcode_app = app;
|
||||
}
|
||||
|
||||
public processBarcode(settings: BarcodeSettings, tag_name: string): void {
|
||||
this.barcode_app.registerMarkdownCodeBlockProcessor(tag_name, (content, el, _) => {
|
||||
const canvas = document.createElement('canvas');
|
||||
JsBarcode(canvas, content.trim(), {
|
||||
format: BARCODE_TAG_NAME[tag_name.split('-')[1]],
|
||||
width: settings.width,
|
||||
height: settings.height,
|
||||
displayValue: settings.displayValue,
|
||||
fontOptions: settings.fontOptions,
|
||||
font: settings.font,
|
||||
textAlign: settings.textAlign,
|
||||
textPosition: settings.textPosition,
|
||||
textMargin: settings.textMargin,
|
||||
fontSize: settings.fontSize,
|
||||
background: settings.background,
|
||||
lineColor: settings.lineColor,
|
||||
margin: settings.margin,
|
||||
marginTop: settings.marginTop,
|
||||
marginBottom: settings.marginBottom,
|
||||
marginLeft: settings.marginLeft,
|
||||
marginRight: settings.marginRight,
|
||||
});
|
||||
el.appendChild(canvas);
|
||||
});
|
||||
}
|
||||
}
|
||||
8
src/processor/barcode.interface.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { BarcodeSettings } from "settings";
|
||||
import Barcode from "main";
|
||||
|
||||
export interface BarcodeProcessor {
|
||||
barcode_app: Barcode;
|
||||
|
||||
processBarcode(settings: BarcodeSettings, tag_name: string): void;
|
||||
}
|
||||
40
src/processor/simple.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { BarcodeProcessor } from "./barcode.interface";
|
||||
import { BarcodeSettings } from "settings";
|
||||
import { MarkdownPreviewRenderer } from "obsidian";
|
||||
import JsBarcode from "jsbarcode";
|
||||
import Barcode from "main";
|
||||
|
||||
export class SimpleBarcodeProcessor implements BarcodeProcessor {
|
||||
barcode_app: Barcode;
|
||||
|
||||
constructor(app: Barcode) {
|
||||
this.barcode_app = app;
|
||||
}
|
||||
|
||||
public processBarcode(settings: BarcodeSettings, tag_name: string): void {
|
||||
MarkdownPreviewRenderer.unregisterPostProcessor(
|
||||
this.barcode_app.registerMarkdownCodeBlockProcessor(tag_name, (content, el, _) => {
|
||||
const canvas = document.createElement('canvas');
|
||||
JsBarcode(canvas, content.trim(), {
|
||||
format: settings.defaultFormat,
|
||||
width: settings.width,
|
||||
height: settings.height,
|
||||
displayValue: settings.displayValue,
|
||||
fontOptions: settings.fontOptions,
|
||||
font: settings.font,
|
||||
textAlign: settings.textAlign,
|
||||
textPosition: settings.textPosition,
|
||||
textMargin: settings.textMargin,
|
||||
fontSize: settings.fontSize,
|
||||
background: settings.background,
|
||||
lineColor: settings.lineColor,
|
||||
margin: settings.margin,
|
||||
marginTop: settings.marginTop,
|
||||
marginBottom: settings.marginBottom,
|
||||
marginLeft: settings.marginLeft,
|
||||
marginRight: settings.marginRight,
|
||||
});
|
||||
el.appendChild(canvas);
|
||||
}));
|
||||
}
|
||||
}
|
||||
41
src/processor/tags.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
export const BARCODE_TAG_NAME: Record<string, string> = {
|
||||
'code128': 'CODE128',
|
||||
'code128a': 'CODE128A',
|
||||
'code128b': 'CODE128B',
|
||||
'code128c': 'CODE128C',
|
||||
'ean13': 'EAN13',
|
||||
'upc': 'UPC',
|
||||
'ean8': 'EAN8',
|
||||
'ean5': 'EAN5',
|
||||
'ean2': 'EAN2',
|
||||
'code39': 'CODE39',
|
||||
'itf14': 'ITF14',
|
||||
'msi': 'MSI',
|
||||
'msi10': 'MSI10',
|
||||
'msi11': 'MSI11',
|
||||
'msi1010': 'MSI1010',
|
||||
'msi1110': 'MSI1110',
|
||||
'pharmacode': 'pharmacode',
|
||||
'codabar': 'codabar',
|
||||
};
|
||||
|
||||
export const BARCODE_SETTINGS_NAME: Record<string, string> = {
|
||||
'CODE128': 'Code 128',
|
||||
'CODE128A': 'Code 128 A',
|
||||
'CODE128B': 'Code 128 B',
|
||||
'CODE128C': 'Code 128 C',
|
||||
'EAN13': 'EAN-13',
|
||||
'UPC': 'UPC',
|
||||
'EAN8': 'EAN-8',
|
||||
'EAN5': 'EAN 5',
|
||||
'EAN2': 'EAN 2',
|
||||
'CODE39': 'Code 39',
|
||||
'ITF14': 'ITF-14',
|
||||
'MSI': 'MSI',
|
||||
'MSI10': 'MSI 10',
|
||||
'MSI11': 'MSI 11',
|
||||
'MSI1010': 'MSI 1010',
|
||||
'MSI1110': 'MSI 1110',
|
||||
'pharmacode': 'Pharmacode',
|
||||
'codabar': 'Codabar',
|
||||
};
|
||||
248
src/settings.ts
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
import Barcode from "main";
|
||||
import { BARCODE_SETTINGS_NAME } from "processor/tags";
|
||||
|
||||
export interface BarcodeSettings {
|
||||
barcode_name: string;
|
||||
defaultFormat: string;
|
||||
width: number;
|
||||
height: number;
|
||||
displayValue: boolean;
|
||||
fontOptions: string;
|
||||
font: string;
|
||||
textAlign: string;
|
||||
textPosition: string;
|
||||
textMargin: number;
|
||||
fontSize: number;
|
||||
background: string;
|
||||
lineColor: string;
|
||||
margin: number;
|
||||
marginTop: number;
|
||||
marginBottom: number;
|
||||
marginLeft: number;
|
||||
marginRight: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: BarcodeSettings = {
|
||||
barcode_name: "barcode",
|
||||
defaultFormat: "CODE128",
|
||||
width: 2,
|
||||
height: 100,
|
||||
displayValue: true,
|
||||
fontOptions: "",
|
||||
font: "monospace",
|
||||
textAlign: "center",
|
||||
textPosition: "bottom",
|
||||
textMargin: 2,
|
||||
fontSize: 20,
|
||||
background: "#fff",
|
||||
lineColor: "#000",
|
||||
margin: 10,
|
||||
marginTop: 0,
|
||||
marginBottom: 0,
|
||||
marginLeft: 0,
|
||||
marginRight: 0
|
||||
}
|
||||
|
||||
|
||||
export class BarcodeSettingsTab extends PluginSettingTab {
|
||||
plugin: Barcode;
|
||||
|
||||
constructor(app: App, plugin: Barcode) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private set_barcode_name(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Barcode name tag')
|
||||
.setDesc('Codeblock tag that will be used to determine if the code block is meant to be a barcode.')
|
||||
.addText(text => text
|
||||
.setPlaceholder('barcode')
|
||||
.setValue(this.plugin.settings.barcode_name)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.barcode_name = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_format(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Default format')
|
||||
.setDesc('Select the default barcode format (it will not affect pre-formatted or custom barcodes).')
|
||||
.addDropdown(compenent => compenent
|
||||
.addOptions(BARCODE_SETTINGS_NAME)
|
||||
.setValue(this.plugin.settings.defaultFormat)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.defaultFormat = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_background(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Background color')
|
||||
.addColorPicker(color => color
|
||||
.setValue(this.plugin.settings.background)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.background = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_line(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Line color')
|
||||
.addColorPicker(color => color
|
||||
.setValue(this.plugin.settings.lineColor)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.lineColor = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_text_display(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Display text')
|
||||
.addToggle(component => component
|
||||
.setValue(this.plugin.settings.displayValue)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.displayValue = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_font(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Font style')
|
||||
.addText(text => text
|
||||
.setPlaceholder('monospace')
|
||||
.setValue(this.plugin.settings.font)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.font = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_font_size(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Font size')
|
||||
.setDesc('Size of the font in pixels.')
|
||||
.addText(text => text
|
||||
.setPlaceholder('font size')
|
||||
.setValue(""+this.plugin.settings.fontSize)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.fontSize = +value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_text_align(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Text align')
|
||||
.setDesc('Horizontal position of the text in the barcode.')
|
||||
.addDropdown(compenent => compenent
|
||||
.addOption("left", "Left")
|
||||
.addOption("center", "Center")
|
||||
.addOption("right", "Right")
|
||||
.setValue(this.plugin.settings.textAlign)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.textAlign = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_text_position(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Text position')
|
||||
.setDesc('Vertical position of the text in the barcode.')
|
||||
.addDropdown(compenent => compenent
|
||||
.addOption("top", "Top")
|
||||
.addOption("bottom", "Bottom")
|
||||
.setValue(this.plugin.settings.textPosition)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.textPosition = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_width(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Barcode width')
|
||||
.addSlider(componenet => componenet
|
||||
.setLimits(1, 5, 1)
|
||||
.setValue(this.plugin.settings.width)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.width = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_height(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Barcode height')
|
||||
.addSlider(componenet => componenet
|
||||
.setLimits(25, 500, 1)
|
||||
.setValue(this.plugin.settings.height)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.height = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_margin(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Margin')
|
||||
.addSlider(componenet => componenet
|
||||
.setLimits(1, 20, 1)
|
||||
.setValue(this.plugin.settings.margin)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.margin = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
private set_text_margin(containerEl: HTMLElement) {
|
||||
new Setting(containerEl)
|
||||
.setName('Text margin')
|
||||
.addSlider(componenet => componenet
|
||||
.setLimits(1, 20, 1)
|
||||
.setValue(this.plugin.settings.textMargin)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.textMargin = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
display(): void {
|
||||
const {containerEl} = this;
|
||||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl("h1", { text: "Barcode Settings" });
|
||||
|
||||
// Function not working properly as you can't unregister
|
||||
// the markdown codeblock processor
|
||||
// Thus the default codeblock name will be static and match "barcode"
|
||||
// this.set_barcode_name(containerEl);
|
||||
|
||||
this.set_format(containerEl);
|
||||
this.set_background(containerEl);
|
||||
this.set_line(containerEl);
|
||||
|
||||
containerEl.createEl("h1", { text: "Text and Font" });
|
||||
|
||||
this.set_text_display(containerEl);
|
||||
this.set_font(containerEl);
|
||||
this.set_font_size(containerEl);
|
||||
this.set_text_align(containerEl);
|
||||
this.set_text_position(containerEl);
|
||||
|
||||
containerEl.createEl("h1", { text: "Size and Margins" });
|
||||
|
||||
this.set_width(containerEl);
|
||||
this.set_height(containerEl);
|
||||
this.set_margin(containerEl);
|
||||
this.set_text_margin(containerEl);
|
||||
}
|
||||
}
|
||||
25
tsconfig.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src/",
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"module": "ESNext",
|
||||
"target": "ES6",
|
||||
"allowJs": true,
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"isolatedModules": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strictNullChecks": true,
|
||||
"lib": [
|
||||
"DOM",
|
||||
"ES5",
|
||||
"ES6",
|
||||
"ES7"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
]
|
||||
}
|
||||
14
version-bump.mjs
Normal 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"));
|
||||
3
versions.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"1.0.0": "0.9.0"
|
||||
}
|
||||