Skip to content

Commit

Permalink
♻️ Added type hints or plaoc
Browse files Browse the repository at this point in the history
  • Loading branch information
waterbang committed Jun 15, 2023
1 parent 243cd80 commit 1191fc6
Show file tree
Hide file tree
Showing 35 changed files with 150 additions and 60 deletions.
11 changes: 10 additions & 1 deletion desktop-dev/scripts/dnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ await dnt.build({
package: {
// package.json properties
name: "@dweb-browser/desktop-sdk",
version: Deno.args.filter((arg) => /^\d/.test(arg))[0],
version: Deno.args.filter((arg) => /^\d/.test(arg))[0] || "0.0.0",
description: "Dweb Browser Development Kit",
license: "MIT",
config: {
Expand Down Expand Up @@ -67,6 +67,15 @@ await dnt.build({
entry.writeJson(sourceMap);
}
}
const packageJson = JSON.parse(
fs.readFileSync("./electron/package.json", "utf-8")
);
packageJson.devDependencies.electron = packageJson.dependencies.electron;
delete packageJson.dependencies.electron;
fs.writeFileSync(
"./electron/package.json",
JSON.stringify(packageJson, null, 2)
);

/// 启动
new Deno.Command("pnpm", {
Expand Down
2 changes: 1 addition & 1 deletion plaoc/cli/helper/flags-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class BundleFlagHelper {
flags.mode === SERVE_MODE.LIVE ||
(flags.mode === undefined &&
bundleTarget !== undefined &&
/^http[s]:\/\//.test(bundleTarget))
/^http[s]{0,1}:\/\//.test(bundleTarget))
) {
const liveUrl = bundleTarget;
if (liveUrl === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion plaoc/cli/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { staticServe } from "./helper/http-static-helper.ts";

export const doServe = (args = Deno.args) => {
const flags = Flags.parse(args, {
string: ["port", "mode","dir"],
string: ["port", "mode"],
collect: ["metadata"],
default: {
port: 8096,
Expand Down
2 changes: 1 addition & 1 deletion plaoc/scripts/npm.client.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"mainExports": ".",
"buildToRootDir": "./build/client",
"name": "@dweb-browser/plaoc",
"version": "0.0.6",
"version": "0.0.8",
"lib": [
"es2021",
"dom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { BasePlugin } from "../base/BasePlugin.ts";
import { SupportedFormat } from "./barcode-scanning.type.ts";

export class BarcodeScannerPlugin extends BasePlugin {
readonly tagName = "dweb-barcode-scanning";

constructor() {
super("barcode-scanning.sys.dweb");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
} from "./barcode-scanning.type.ts";

export class HTMLDwebBarcodeScanningElement extends HTMLElement {
plugin = barcodeScannerPlugin;
static readonly tagName = "dweb-barcode-scanning";
readonly plugin = barcodeScannerPlugin;

private _video: HTMLVideoElement | null = null;
private _canvas: HTMLCanvasElement | null = null;
Expand Down Expand Up @@ -328,6 +329,11 @@ export class HTMLDwebBarcodeScanningElement extends HTMLElement {
}

customElements.define(
barcodeScannerPlugin.tagName,
HTMLDwebBarcodeScanningElement.tagName,
HTMLDwebBarcodeScanningElement
);
declare global {
interface HTMLElementTagNameMap{
[HTMLDwebBarcodeScanningElement.tagName]: HTMLDwebBarcodeScanningElement
}
}
1 change: 0 additions & 1 deletion plaoc/src/client/components/base/BasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fetchExtends } from "../../helper/$makeFetchExtends.ts";
import { createSignal } from "../../helper/createSignal.ts";

export abstract class BasePlugin {
abstract tagName: string;
static internal_url: string = globalThis.location?.href ?? "http://localhost";
static public_url: Promise<string> | string = "";
static internal_url_useable?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BasePlugin } from "../base/BasePlugin.ts";
import { BioetricsResult } from "./biometrics.type.ts";

export class BiometricsPlugin extends BasePlugin {
readonly tagName = "dweb-biometrics";
constructor() {
super("biometrics.sys.dweb");
}
Expand Down
10 changes: 8 additions & 2 deletions plaoc/src/client/components/biometrics/biometrics.wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { cacheGetter } from "../../helper/cacheGetter.ts";
import { biometricsPlugin } from "./biometrics.plugin.ts";

export class HTMLDwebBiometricsElement extends HTMLElement {
plugin = biometricsPlugin;
static readonly tagName = "dweb-biometrics";
readonly plugin = biometricsPlugin;

@cacheGetter()
get check() {
Expand All @@ -15,4 +16,9 @@ export class HTMLDwebBiometricsElement extends HTMLElement {
}
}

customElements.define(biometricsPlugin.tagName, HTMLDwebBiometricsElement);
customElements.define(HTMLDwebBiometricsElement.tagName, HTMLDwebBiometricsElement);
declare global {
interface HTMLElementTagNameMap{
[HTMLDwebBiometricsElement.tagName]: HTMLDwebBiometricsElement
}
}
1 change: 0 additions & 1 deletion plaoc/src/client/components/clipboard/clipboard.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BasePlugin } from "../base/BasePlugin.ts";
import type { ClipboardWriteOptions, ReadResult } from "./clipboard.type.ts";

export class ClipboardPlugin extends BasePlugin {
readonly tagName = "dweb-clipboard";
constructor() {
super("clipboard.sys.dweb");
}
Expand Down
11 changes: 10 additions & 1 deletion plaoc/src/client/components/clipboard/clipboard.wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cacheGetter } from "../../helper/cacheGetter.ts";
import { clipboardPlugin } from "./clipboard.plugin.ts";

export class HTMLDwebClipboardElement extends HTMLElement {
static readonly tagName = "dweb-clipboard";
readonly plugin = clipboardPlugin;

@cacheGetter()
Expand All @@ -15,4 +16,12 @@ export class HTMLDwebClipboardElement extends HTMLElement {
}
}

customElements.define(clipboardPlugin.tagName, HTMLDwebClipboardElement);
customElements.define(
HTMLDwebClipboardElement.tagName,
HTMLDwebClipboardElement
);
declare global {
interface HTMLElementTagNameMap {
[HTMLDwebClipboardElement.tagName]: HTMLDwebClipboardElement;
}
}
14 changes: 13 additions & 1 deletion plaoc/src/client/components/config/config.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
/// <reference lib="dom"/>
import { BasePlugin } from "../base/BasePlugin.ts";

export class ConfigPlugin extends BasePlugin {
readonly tagName = "dweb-config";
constructor() {
super("internal");
if (typeof location === "object") {
this.initConfig();
}
}
initConfig(href = location.href) {
const searchParams = new URL(href).searchParams;
const internalUrl = searchParams.get("X-Plaoc-Internal-Url");
const publicUrl = searchParams.get("X-Plaoc-Public-Url");

publicUrl && this.setPublicUrl(publicUrl);
internalUrl && this.setInternalUrl(internalUrl);
}

getInternalUrl() {
return BasePlugin.internal_url;
}
Expand Down
23 changes: 7 additions & 16 deletions plaoc/src/client/components/config/config.wc.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { configPlugin } from "./config.plugin.ts";

export class HTMLDwebConfigElement extends HTMLElement {
static readonly tagName = "dweb-config";
readonly plugin = configPlugin;
get public_url() {
return configPlugin.public_url;
}

connectedCallback() {
const searchParams = new URL(location.href).searchParams;
const internalUrl = searchParams.get("X-Plaoc-Internal-Url");
const publicUrl = searchParams.get("X-Plaoc-Public-Url");

publicUrl && configPlugin.setPublicUrl(publicUrl);
internalUrl && configPlugin.setInternalUrl(internalUrl);
}

getPublicUrl() {
return configPlugin.updatePublicUrl();
}
Expand All @@ -28,9 +19,9 @@ export class HTMLDwebConfigElement extends HTMLElement {
}
}

// <dweb-config/>
customElements.define(configPlugin.tagName, HTMLDwebConfigElement);
// <meta is="dweb-config"/>
// customElements.define(configPlugin.tagName, HTMLDwebConfigElement, {
// extends: "meta",
// });
customElements.define(HTMLDwebConfigElement.tagName, HTMLDwebConfigElement);
declare global {
interface HTMLElementTagNameMap {
[HTMLDwebConfigElement.tagName]: HTMLDwebConfigElement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
} from "./file-system.type.ts";

export class FileSystemPlugin extends BasePlugin {
readonly tagName = "dweb-file-system";
constructor() {
super("file.sys.dweb");
}
Expand Down
8 changes: 7 additions & 1 deletion plaoc/src/client/components/file-system/file-system.wc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fileSystemPlugin } from "./file-system.plugin.ts";

export class HTMLDwebFileSystemElement extends HTMLElement {
static readonly tagName = "dweb-file-system";
readonly plugin = fileSystemPlugin;

get writeFile() {
Expand All @@ -11,4 +12,9 @@ export class HTMLDwebFileSystemElement extends HTMLElement {
}
}

customElements.define(fileSystemPlugin.tagName, HTMLDwebFileSystemElement);
customElements.define(HTMLDwebFileSystemElement.tagName, HTMLDwebFileSystemElement);
declare global {
interface HTMLElementTagNameMap {
[HTMLDwebFileSystemElement.tagName]: HTMLDwebFileSystemElement;
}
}
1 change: 0 additions & 1 deletion plaoc/src/client/components/haptics/haptics.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
} from "./haptics.type.ts";

export class HapticsPlugin extends BasePlugin {
readonly tagName = "dweb-haptics";
constructor() {
super("haptics.sys.dweb");
}
Expand Down
8 changes: 7 additions & 1 deletion plaoc/src/client/components/haptics/haptics.wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cacheGetter } from "../../helper/cacheGetter.ts";
import { hapticsPlugin } from "./haptics.plugin.ts";

export class HTMLDwebHapticsElement extends HTMLElement {
static readonly tagName = "dweb-haptics";
readonly plugin = hapticsPlugin;

@cacheGetter()
Expand Down Expand Up @@ -45,4 +46,9 @@ export class HTMLDwebHapticsElement extends HTMLElement {
}
}

customElements.define(hapticsPlugin.tagName, HTMLDwebHapticsElement);
customElements.define(HTMLDwebHapticsElement.tagName, HTMLDwebHapticsElement);
declare global {
interface HTMLElementTagNameMap {
[HTMLDwebHapticsElement.tagName]: HTMLDwebHapticsElement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export class NavigationBarPlugin extends BarPlugin<
$NavigationBarState,
$NavigationBarWritableState
> {
readonly tagName = "dweb-navigation-bar";

constructor() {
super("navigation-bar.nativeui.browser.dweb");
}
Expand Down
11 changes: 9 additions & 2 deletions plaoc/src/client/components/navigation-bar/navigation-bar.wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export class HTMLDwebNavigationBarElement extends HTMLStateObserverElement<
$NavigationBarRawState,
$NavigationBarState
> {
static readonly tagName = "dweb-navigation-bar";
readonly plugin = navigationBarPlugin;
constructor() {
super(navigationBarPlugin.state);
}
readonly plugin = navigationBarPlugin;
@cacheGetter()
get setColor() {
return navigationBarPlugin.setColor;
Expand Down Expand Up @@ -61,6 +62,12 @@ export class HTMLDwebNavigationBarElement extends HTMLStateObserverElement<
}

customElements.define(
navigationBarPlugin.tagName,
HTMLDwebNavigationBarElement.tagName,
HTMLDwebNavigationBarElement
);

declare global {
interface HTMLElementTagNameMap {
[HTMLDwebNavigationBarElement.tagName]: HTMLDwebNavigationBarElement;
}
}
2 changes: 0 additions & 2 deletions plaoc/src/client/components/network/network.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const _network_status: Tkit = {
};

export class NetworkPlugin extends BaseEvent<keyof NetworkStatusMap> {
readonly tagName = "dweb-network";

constructor() {
super(_network_status);
if (typeof window !== "undefined") {
Expand Down
10 changes: 8 additions & 2 deletions plaoc/src/client/components/network/network.wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { cacheGetter } from "../../helper/cacheGetter.ts";
import { networkPlugin } from "./network.plugin.ts";

export class HTMLDwebNetworkElement extends HTMLElement {
plugin = networkPlugin;
static readonly tagName = "dweb-network";
readonly plugin = networkPlugin;

@cacheGetter()
get getStatus() {
Expand All @@ -16,4 +17,9 @@ export class HTMLDwebNetworkElement extends HTMLElement {
}
}

customElements.define(networkPlugin.tagName, HTMLDwebNetworkElement);
customElements.define(HTMLDwebNetworkElement.tagName, HTMLDwebNetworkElement);
declare global {
interface HTMLElementTagNameMap {
[HTMLDwebNetworkElement.tagName]: HTMLDwebNetworkElement;
}
}
1 change: 0 additions & 1 deletion plaoc/src/client/components/safe-area/safe-area.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class SafeAreaPlugin extends InsetsPlugin<
$SafeAreaState,
$SafeAreaWritableState
> {
readonly tagName = "dweb-safe-area";
constructor() {
super("safe-area.nativeui.browser.dweb");
}
Expand Down
10 changes: 9 additions & 1 deletion plaoc/src/client/components/safe-area/safe-area.wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class HTMLDwebSafeAreaElement extends HTMLStateObserverElement<
$SafeAreaRawState,
$SafeAreaState
> {
static readonly tagName = "dweb-safe-area";
readonly plugin = safeAreaPlugin;
constructor() {
super(safeAreaPlugin.state);
}
Expand All @@ -27,4 +29,10 @@ export class HTMLDwebSafeAreaElement extends HTMLStateObserverElement<
return safeAreaPlugin.getOverlay;
}
}
customElements.define(safeAreaPlugin.tagName, HTMLDwebSafeAreaElement);
customElements.define(HTMLDwebSafeAreaElement.tagName, HTMLDwebSafeAreaElement);

declare global {
interface HTMLElementTagNameMap {
[HTMLDwebSafeAreaElement.tagName]: HTMLDwebSafeAreaElement;
}
}
1 change: 0 additions & 1 deletion plaoc/src/client/components/share/share.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { bindThis } from "../../helper/bindThis.ts";
import { BasePlugin } from "../base/BasePlugin.ts";
import type { ShareOptions, ShareResult } from "./share.type.ts";
export class SharePlugin extends BasePlugin {
readonly tagName = "dweb-share";

constructor() {
super("share.sys.dweb");
Expand Down
8 changes: 7 additions & 1 deletion plaoc/src/client/components/share/share.wc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sharePlugin } from "./share.plugin.ts";

export class HTMLDwebShareElement extends HTMLElement {
static readonly tagName = "dweb-share";
readonly plugin = sharePlugin;

get canShare() {
Expand All @@ -11,4 +12,9 @@ export class HTMLDwebShareElement extends HTMLElement {
}
}

customElements.define(sharePlugin.tagName, HTMLDwebShareElement);
customElements.define(HTMLDwebShareElement.tagName, HTMLDwebShareElement);
declare global {
interface HTMLElementTagNameMap {
[HTMLDwebShareElement.tagName]: HTMLDwebShareElement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
} from "./splash-screen.type.ts";

export class SplashScreenPlugin extends BasePlugin {
readonly tagName = "dweb-splash-screen";
constructor() {
super("splash-screen.nativeui.browser.dweb");
}
Expand Down
Loading

0 comments on commit 1191fc6

Please sign in to comment.