Skip to content

Commit

Permalink
スキャン機能取り敢えず完成!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
nakasyou committed Aug 27, 2023
1 parent 0fb5bf3 commit fe95013
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
40 changes: 28 additions & 12 deletions src/app/note/components/ImageNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,51 @@ import {
} from "@tabler/icons-react"
import { useEffect, useRef, useContext, useState } from "react"
import classNames from "classnames"
import { classListAddAll, classListRemoveAll } from "../utils/classListAll.ts"

export interface Props {
imageBlob: Blob
paths: string[]
}
export default (props: Props) => {
const userState = useContext(UserStateContext)
const blobUrl = URL.createObjectURL(props.imageBlob)

const [imageSize, setImageSize] = useState({
width: 1,
height: 1,
})

const image = new Image()
image.onload = () => {
setImageSize({
width: image.width,
height: image.height
})
}
image.src = blobUrl
const [blobUrl, setBlobUrl] = useState('')
useEffect(() => {
const blobUrl = URL.createObjectURL(props.imageBlob)
const image = new Image()
image.onload = () => {
setImageSize({
width: image.width,
height: image.height
})
}
setBlobUrl(blobUrl)
image.src = blobUrl
}, [])

return <div>
<div className='relative w-full h-screen'>
<img className='absolute top-0 w-full h-full object-contain' src={ blobUrl } alt='Scaned Image' />
<svg className='absolute top-0 w-full h-full object-contain' viewbox={ `0 0 ${imageSize.width} ${imageSize.height}` }>
<svg className='absolute top-0 w-full h-full object-contain' viewBox={ `0 0 ${imageSize.width} ${imageSize.height}` }>
{
props.paths.map((path, index) => {
return <path d={ path } key={ index } stroke="#f002" strokeWidth="20" fill="none" />
return <path d={ path } key={ index } stroke="#f002" strokeWidth="20" fill="none" onClick={(evt) => {
const pathElement: SVGPathElement = evt.target as SVGPathElement
const nextIsView = pathElement.dataset.isView !== 'true'
pathElement.dataset.isView = nextIsView.toString()
if (nextIsView) {
classListAddAll(pathElement, viewClasses)
classListRemoveAll(pathElement, hideClasses)
} else {
classListAddAll(pathElement, hideClasses)
classListRemoveAll(pathElement, viewClasses)
}
}}/>
})
}
</svg>
Expand Down
13 changes: 2 additions & 11 deletions src/app/note/components/TextNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TipTapPluginSheet } from "../utils/tiptap-plugin-sheet"
import { TiptapPluginImageNote } from "../utils/tiptap-plugin-imagenote"
import { UserStateContext } from "../index.tsx"
import { viewClasses, hideClasses } from '../const/sheetClasses.ts'

import { classListAddAll, classListRemoveAll } from "../utils/classListAll.ts"
import {
IconBold,
IconBoldOff,
Expand All @@ -27,16 +27,7 @@ export default (props: Props) => {
content: props.defaultContent,
})
props.setEditorState(editor)
const classListAddAll = (element: Element, classes: string[]) => {
for (const className of classes) {
element.classList.add(className)
}
}
const classListRemoveAll = (element: Element, classes: string[]) => {
for (const className of classes) {
element.classList.remove(className)
}
}

const viewEditorRef = useRef<HTMLDivElement>(null)
useEffect(() => {
for (const nanohaSheetElement of viewEditorRef?.current?.getElementsByClassName(
Expand Down
4 changes: 2 additions & 2 deletions src/app/note/const/sheetClasses.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const viewClasses = ['bg-red-100']
export const hideClasses = ['bg-red-500', 'text-transparent']
export const viewClasses = ['bg-red-100', 'stroke-[#f002]']
export const hideClasses = ['bg-red-500', 'text-transparent', 'stroke-[#f00]']
10 changes: 10 additions & 0 deletions src/app/note/utils/classListAll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const classListAddAll = (element: Element, classes: string[]) => {
for (const className of classes) {
element.classList.add(className)
}
}
export const classListRemoveAll = (element: Element, classes: string[]) => {
for (const className of classes) {
element.classList.remove(className)
}
}

0 comments on commit fe95013

Please sign in to comment.