Skip to content

Commit

Permalink
style: update all sources, use tabs instead of spaces
Browse files Browse the repository at this point in the history
- update prettier config
- update all *.ts, *.json files
  • Loading branch information
postspectacular committed Jul 31, 2022
1 parent 0abc14a commit 2065c92
Show file tree
Hide file tree
Showing 3,050 changed files with 139,706 additions and 139,601 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
5 changes: 4 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"useTabs": true,
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"arrowParens": "always",
"endOfLine": "lf"
}
}
76 changes: 38 additions & 38 deletions examples/adaptive-threshold/package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
{
"name": "@example/adaptive-threshold",
"private": true,
"version": "0.0.1",
"description": "Interactive image processing (adaptive threshold)",
"repository": "https://github.com/thi-ng/umbrella",
"author": "Karsten Schmidt <[email protected]>",
"license": "Apache-2.0",
"scripts": {
"start": "vite --open",
"build": "tsc && vite build --base='./'",
"preview": "vite preview --host --open"
},
"dependencies": {
"@thi.ng/api": "workspace:^",
"@thi.ng/paths": "workspace:^",
"@thi.ng/pixel": "workspace:^",
"@thi.ng/rstream": "workspace:^",
"@thi.ng/transducers": "workspace:^",
"@thi.ng/transducers-hdom": "workspace:^"
},
"browser": {
"process": false,
"setTimeout": false,
"util": false
},
"thi.ng": {
"readme": [
"pixel",
"rstream",
"transducers",
"transducers-hdom"
],
"screenshot": "examples/adaptive-threshold.png"
},
"devDependencies": {
"typescript": "^4.7.4",
"vite": "^3.0.0"
}
"name": "@example/adaptive-threshold",
"private": true,
"version": "0.0.1",
"description": "Interactive image processing (adaptive threshold)",
"repository": "https://github.com/thi-ng/umbrella",
"author": "Karsten Schmidt <[email protected]>",
"license": "Apache-2.0",
"scripts": {
"start": "vite --open",
"build": "tsc && vite build --base='./'",
"preview": "vite preview --host --open"
},
"dependencies": {
"@thi.ng/api": "workspace:^",
"@thi.ng/paths": "workspace:^",
"@thi.ng/pixel": "workspace:^",
"@thi.ng/rstream": "workspace:^",
"@thi.ng/transducers": "workspace:^",
"@thi.ng/transducers-hdom": "workspace:^"
},
"browser": {
"process": false,
"setTimeout": false,
"util": false
},
"thi.ng": {
"readme": [
"pixel",
"rstream",
"transducers",
"transducers-hdom"
],
"screenshot": "examples/adaptive-threshold.png"
},
"devDependencies": {
"typescript": "^4.7.4",
"vite": "^3.0.0"
}
}
20 changes: 10 additions & 10 deletions examples/adaptive-threshold/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ export const SET_KERNEL_OFFSET = "set-kernel-offset";

// define all possible event structures/signatures
export interface EventTypeMap {
[SET_IMAGE]: [typeof SET_IMAGE, File];
[UPDATE_IMAGE]: [typeof UPDATE_IMAGE];
[SET_KERNEL_WIDTH]: [typeof SET_KERNEL_WIDTH, number];
[SET_KERNEL_OFFSET]: [typeof SET_KERNEL_OFFSET, number];
[SET_IMAGE]: [typeof SET_IMAGE, File];
[UPDATE_IMAGE]: [typeof UPDATE_IMAGE];
[SET_KERNEL_WIDTH]: [typeof SET_KERNEL_WIDTH, number];
[SET_KERNEL_OFFSET]: [typeof SET_KERNEL_OFFSET, number];
}

export type EventType = keyof EventTypeMap;

export type Event = Val1<EventTypeMap, EventType>;

export interface AppState {
srcImg?: FloatBuffer;
destImg?: FloatBuffer;
threshold: {
windowSize: number;
offset: number;
};
srcImg?: FloatBuffer;
destImg?: FloatBuffer;
threshold: {
windowSize: number;
offset: number;
};
}
112 changes: 56 additions & 56 deletions examples/adaptive-threshold/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { stream } from "@thi.ng/rstream/stream";
import { trace } from "@thi.ng/rstream/trace";
import type { Transducer } from "@thi.ng/transducers";
import {
type Event,
type EventType,
type EventTypeMap,
SET_IMAGE,
SET_KERNEL_OFFSET,
SET_KERNEL_WIDTH,
UPDATE_IMAGE,
type Event,
type EventType,
type EventTypeMap,
SET_IMAGE,
SET_KERNEL_OFFSET,
SET_KERNEL_WIDTH,
UPDATE_IMAGE,
} from "./api";
import { state } from "./state";
import { adaptiveThreshold } from "./threshold";
Expand All @@ -41,7 +41,7 @@ events.subscribe(eventProc);
/**
* Event dispatch function. Sends given event into the event stream.
*
* @param e -
* @param e -
*/
export const dispatch = (e: Event) => events.next(e);

Expand All @@ -51,69 +51,69 @@ export const dispatch = (e: Event) => events.next(e);
* The handler's subscription also includes an error handler to display
* errors in the console.
*
* @param id -
* @param handler -
* @param xform -
* @param id -
* @param handler -
* @param xform -
*/
export const defHandler = <E extends EventType>(
id: E,
handler: Fn<EventTypeMap[E], void>,
xform?: Transducer<Event, Event>
id: E,
handler: Fn<EventTypeMap[E], void>,
xform?: Transducer<Event, Event>
) => {
const sub: ISubscriber<Event> = {
next: <Fn<Event, void>>handler,
error: (e) => {
console.warn(e);
return false;
},
};
return xform
? eventProc.subscribeTopic(id, sub, { xform })
: eventProc.subscribeTopic(id, sub);
const sub: ISubscriber<Event> = {
next: <Fn<Event, void>>handler,
error: (e) => {
console.warn(e);
return false;
},
};
return xform
? eventProc.subscribeTopic(id, sub, { xform })
: eventProc.subscribeTopic(id, sub);
};

// event handlers

defHandler(SET_IMAGE, ([_, file]) => {
const reader = new FileReader();
reader.onload = async (e: any) => {
const img = new Image();
img.src = e.target.result;
await img.decode();
state.next(
setIn(
state.deref()!,
["srcImg"],
floatBufferFromImage(img, FLOAT_GRAY)
)
);
dispatch([UPDATE_IMAGE]);
};
reader.readAsDataURL(file);
const reader = new FileReader();
reader.onload = async (e: any) => {
const img = new Image();
img.src = e.target.result;
await img.decode();
state.next(
setIn(
state.deref()!,
["srcImg"],
floatBufferFromImage(img, FLOAT_GRAY)
)
);
dispatch([UPDATE_IMAGE]);
};
reader.readAsDataURL(file);
});

defHandler(UPDATE_IMAGE, () => {
const curr = state.deref()!;
// create & store threshold image in state
state.next(
setIn(
curr,
["destImg"],
adaptiveThreshold(
curr.srcImg!,
curr.threshold.windowSize,
curr.threshold.offset
)
)
);
const curr = state.deref()!;
// create & store threshold image in state
state.next(
setIn(
curr,
["destImg"],
adaptiveThreshold(
curr.srcImg!,
curr.threshold.windowSize,
curr.threshold.offset
)
)
);
});

defHandler(SET_KERNEL_WIDTH, ([_, width]) => {
state.next(setIn(state.deref()!, ["threshold", "windowSize"], width));
dispatch([UPDATE_IMAGE]);
state.next(setIn(state.deref()!, ["threshold", "windowSize"], width));
dispatch([UPDATE_IMAGE]);
});

defHandler(SET_KERNEL_OFFSET, ([_, offset]) => {
state.next(setIn(state.deref()!, ["threshold", "offset"], offset));
dispatch([UPDATE_IMAGE]);
state.next(setIn(state.deref()!, ["threshold", "offset"], offset));
dispatch([UPDATE_IMAGE]);
});
Loading

0 comments on commit 2065c92

Please sign in to comment.