Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add support for text mints #411

Merged
merged 30 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9497134
feat: Add support for typed based nfts
kittypurrry Mar 28, 2024
a5f11b0
Some updates to display token's displayuri instead of artifact
kittypurrry Apr 7, 2024
3ddd0b6
Update Monotype art to use 'IBM Mono Plex' to be consistent with type…
kittypurrry Apr 7, 2024
8aa8566
Remove monaco
kittypurrry Apr 7, 2024
9baff04
Merge branch 'teia-community:main' into feat/typed-nft
kittypurrry Apr 8, 2024
4328cc0
Fix lint errors
kittypurrry Apr 13, 2024
1c48db3
Merge branch 'teia-community:main' into feat/typed-nft
kittypurrry Apr 14, 2024
8fef7bc
Fix some UI issues while minting - switching between preview and edit…
kittypurrry Apr 14, 2024
9616958
Minor UI updates for very long text mints
kittypurrry Apr 14, 2024
6424135
Some minor adjustments
kittypurrry Apr 16, 2024
4e81265
Replace UltimateTextToImage with canvas solution
kittypurrry Apr 21, 2024
629db11
Merge branch 'main' into feat/typed-nft
kittypurrry Apr 21, 2024
b219adf
chore: ♻️ apply format
melMass May 2, 2024
3b836bf
fix: ✨ minor edits
melMass May 2, 2024
c7feab5
Fix font issue for generated thumbnail and changed mono font to Iosevka
kittypurrry May 5, 2024
aaea30c
Add comments and refactor thumbnail generation a bit
kittypurrry May 5, 2024
5777d40
Update char length before ellipsis since text size can accomodate for…
kittypurrry May 5, 2024
25ab072
Merge branch 'main' into feat/typed-nft
melMass May 11, 2024
b993686
style: 💎 fix various styles issues
melMass May 11, 2024
dbcf13d
chore: 🧹 convert typed_art utils to ts
melMass May 11, 2024
324478f
refactor: 📦 image generation logic
melMass May 11, 2024
9f21675
fix: 🐛 issues reported by CI
melMass May 11, 2024
1ebe8a1
fix: preview generation
melMass May 20, 2024
45e243e
chore: 🧹 prefer const
melMass May 20, 2024
8934d88
hide scrollbars and add text feed to the menu
Zir0h May 26, 2024
f5afa3c
disable description in preview cards for text/plain tokens
Zir0h May 26, 2024
7190069
use overflow:scroll
Zir0h Jun 5, 2024
e15a53f
mess around with overflow / whitespace
Zir0h Jun 6, 2024
481c8cf
Merge branch 'main' into feat/typed-nft
Zir0h Jun 6, 2024
747143a
added padding
Zir0h Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: ✨ minor edits
melMass committed May 2, 2024

Verified

This commit was signed with the committer’s verified signature.
tacaswell Thomas A Caswell
commit 3b836bf74c3a5cdacb1ac3f082cb5a745b362e04
2 changes: 1 addition & 1 deletion src/components/preview/index.jsx
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ export const Preview = () => {
])

const { ignoreUriMap } = useSettings()
let token_tags = tags
const token_tags = tags
? tags === ''
? []
: tags.replace(/\s/g, '').split(',')
2 changes: 1 addition & 1 deletion src/pages/mint/fields.js
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ export const fields = [
watch: true,
enable_if: 'isTyped',
rules: {
required: 'There is no input.',
required: 'Typed art mints cannot be empty.',
},
},
{
167 changes: 82 additions & 85 deletions src/utils/mint.ts
Original file line number Diff line number Diff line change
@@ -120,100 +120,97 @@ export const generateTypedArtCoverImage = async (
txt: string,
monospace: boolean
) => {
let f = '16px Source Sans Pro'
if (monospace === true) f = '16px IBM Plex Mono'
const font = monospace ? 'IBM Plex Mono' : 'Source Sans Pro'
const cv_font = `16px ${font}`
if (txt.length === 0) {
return false
}
const createContext = function (width: number, height: number) {
const canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
return canvas.getContext('2d')
const ctx = canvas.getContext('2d')
if (!ctx) throw new Error('Could not create canvas context')
return ctx
}
const c: any = createContext(512, 512)
const c = createContext(512, 512)
c.filter = 'grayscale(100%)'
if (txt.length >= 0) {
let dize = []
const lines = txt.split('\n')
dize = lines
c.font = f
const x = 0
const y = 16
const lineheight = 16
const result = dize.reduce(
(r, e) => (c.measureText(r).width < c.measureText(e).width ? e : r),
''
)
if (result.length > 130) {
c.canvas.width = 512
c.canvas.height = 512
} else {
c.canvas.width = c.measureText(result).width
c.canvas.height = lineheight * dize.length + 12
}
c.fillStyle = 'transparent'
c.fillRect(0, 0, c.canvas.width, c.canvas.height)
c.font = f
c.filter = 'grayscale(100%)'
c.fillStyle = 'white'
if (c.canvas.width === 512) {
const s = lines[0].substring(0, 20)
c.fillText(s + '...', 16, 256)
} else {
for (let i = 0; i < lines.length; i++) {
c.fillText(lines[i], x, y + i * lineheight)
}
}
const ca: any = createContext(512, 512)
ca.fillStyle = 'transparent'
ca.fillRect(0, 0, 512, 512)
const cerceve: any = createContext(512, 512)
const cImage = new Image()
const img = new Image()
return new Promise((resolve, reject) => {
img.src = c.canvas.toDataURL('svg')
//console.log(img.src);
img.onload = function () {
ca.imageSmoothingEnabled = true
ca.width = 512
ca.height = 512
const hRatio = ca.width / img.width
const vRatio = ca.height / img.height
const ratio = Math.min(hRatio, vRatio)
const centerShift_x = (ca.width - img.width * ratio) / 2
const centerShift_y = (ca.height - img.height * ratio) / 2
ca.drawImage(
img,
0,
0,
img.width,
img.height,
centerShift_x,
centerShift_y,
img.width * ratio,
img.height * ratio
)
const t = ca.canvas.toDataURL('svg')
cImage.src = t
cImage.onload = async function () {
cerceve.fillStyle = 'transparent'
cerceve.fillRect(0, 0, 512, 512)
cerceve.drawImage(cImage, 0, 0, 512, 512, 16, 16, 512 - 16, 512 - 16)
const ctx = cerceve.canvas.toDataURL('svg')

resolve(
await fetch(ctx)
.then((res) => res.blob())
.then(
(blob) =>
new File([blob], 'Generated Cover.png', { type: 'image/png' })
)
)
}
}
})
let dize = []
const lines = txt.split('\n')
dize = lines
c.font = cv_font
const x = 0
const y = 16
const lineheight = 16
const result = dize.reduce(
(r, e) => (c.measureText(r).width < c.measureText(e).width ? e : r),
''
)
if (result.length > 130) {
c.canvas.width = 512
c.canvas.height = 512
} else {
console.log('Unable to generate cover!')
return false
c.canvas.width = c.measureText(result).width
c.canvas.height = lineheight * dize.length + 12
}
c.fillStyle = 'transparent'
c.fillRect(0, 0, c.canvas.width, c.canvas.height)
c.filter = 'grayscale(100%)'
c.fillStyle = 'white'
if (c.canvas.width === 512) {
const s = lines[0].substring(0, 20)
c.fillText(s + '...', 16, 256)
} else {
for (let i = 0; i < lines.length; i++) {
c.fillText(lines[i], x, y + i * lineheight)
}
}
const ca = createContext(512, 512)
ca.fillStyle = 'transparent'
ca.fillRect(0, 0, 512, 512)
const cerceve = createContext(512, 512)
const cImage = new Image()
const img = new Image()
return new Promise((resolve, reject) => {
img.src = c.canvas.toDataURL('svg')
img.onload = function () {
ca.imageSmoothingEnabled = true
ca.width = 512
ca.height = 512
const hRatio = ca.width / img.width
const vRatio = ca.height / img.height
const ratio = Math.min(hRatio, vRatio)
const centerShift_x = (ca.width - img.width * ratio) / 2
const centerShift_y = (ca.height - img.height * ratio) / 2
ca.drawImage(
img,
0,
0,
img.width,
img.height,
centerShift_x,
centerShift_y,
img.width * ratio,
img.height * ratio
)
const t = ca.canvas.toDataURL('svg')
cImage.src = t
cImage.onload = async function () {
cerceve.fillStyle = 'transparent'
cerceve.fillRect(0, 0, 512, 512)
cerceve.drawImage(cImage, 0, 0, 512, 512, 16, 16, 512 - 16, 512 - 16)
const ctx = cerceve.canvas.toDataURL('svg')
const res = await fetch(ctx)
const blob = await res.blob()
const file = new File([blob], 'Generated Cover.png', {
type: 'image/png',
})

resolve(file)
}
}
})
}

export const convertFileToFileForm = async (

Unchanged files with check annotations Beta

!id || !name ? ['/contract', id, name] : null,
async () => {
const result = await fetchCollabCreations(
name || id!,

Check warning on line 20 in src/components/collab/show/CollabDisplay.tsx

GitHub Actions / build (18)

Forbidden non-null assertion
name ? 'subjkt' : 'address'
)
<ListingRow
nft={nft}
key={listing.key}
rowId={listing.key!}

Check warning on line 167 in src/components/listings/index.tsx

GitHub Actions / build (18)

Forbidden non-null assertion
listing={listing}
// restricted={nft.restricted}
// address={address}