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

exmllent:0.1.0, handy-dora:0.1.0 and zebraw:0.1.0 #1510

Merged
merged 15 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
21 changes: 21 additions & 0 deletions packages/preview/exmllent/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2025] [Hong Jiarong]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions packages/preview/exmllent/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# eXMLlent

Pure typst implementation of converting XML Excel table to typst table.

## Quick Start

> [!NOTE]
> The current version only supports converting the XML **Excel** table to typst table. Not sure if it works for other XML tables (Numbers, Google Sheets, etc.). Pull requests are welcome!

Start by importing the package:

```typ
#import "src/lib.typ": worksheets-parser, worksheet-parser
hongjr03 marked this conversation as resolved.
Show resolved Hide resolved
```

Then you can use the `worksheets-parser` and `worksheet-parser` functions to convert your XML Excel table to typst table.

With `worksheets-parser` you can convert all worksheets in the XML file to typst tables. When `to-array` is set to `true`, the function will return an array of typst tables. Otherwise, it will return a sequence of tables. For the rest of the arguments, they will be passed to `worksheet-parser`.

```typ
#worksheets-parser(
xml-path: "/test-table.xml",
to-array: true, // default is false
// below args will be passed to worksheet-parser
with-table-styles: false,
with-table-alignment: false,
columns: (1fr, 1fr),
rows: 4em,
align: center+horizon,
stroke: yellow,
)
```

With `worksheet-parser` you can convert a specific worksheet in the XML file to a typst table. If `with-table-styles` is set to `true`, the function will use the **styles**(only column width and row height are supported for now) defined in the XML file. Otherwise, it will use the styles specified in the arguments and pass them to the table.

```typ
#worksheet-parser(
xml-path: "/test-table.xml",
worksheet: "Sheet2",
with-table-styles: false,
with-table-alignment: false,
// if with-table-styles is false, then below args will be passed to table
columns: (1fr, 1fr),
// rows: 4em,
align: center+horizon,
stroke: yellow,
)
```

Have fun!
1 change: 1 addition & 0 deletions packages/preview/exmllent/0.1.0/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import "parser.typ": worksheets-parser, worksheet-parser
198 changes: 198 additions & 0 deletions packages/preview/exmllent/0.1.0/parser.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#let xml-to-worksheets(xml-path) = {
let workbook = xml(xml-path).filter(e => if e.tag == "" { false } else { true }).first()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work as expected, because xml can only read files from the current package. The user of your package should call it and pass the resulting string as an argument to your function.

let worksheets = workbook.children.filter(e => if "tag" in e { e.tag == "Worksheet" } else { false })

let styles = workbook
.children
.find(e => "tag" in e and e.tag == "Styles")
.children
.filter(e => if type(e) == "string" { false } else { true })
.map(e => {
(
e.attrs.ID,
{
let attrs = e
.children
.filter(e => if type(e) == "string" { false } else { true })
.filter(e => e.tag == "Alignment")
.at(0)
.attrs
let style = ""
if "Horizontal" in attrs {
if style != "" {
style += "+ "
}
style += lower(attrs.Horizontal) + " "
}
if "Vertical" in attrs {
if style != "" {
style += "+ "
}
if attrs.Vertical == "Center" {
style += "horizon "
} else {
style += lower(attrs.Vertical) + " "
}
}
style
},
)
})
.to-dict()
(
worksheets: worksheets,
styles: styles,
)
}

/// Parse a named worksheet from an Excel file.
///
/// - xml-path (string): The path to the XML Excel file.
/// - worksheets (dictionary): Parsed worksheets from the XML Excel file. (Not available for users)
/// - styles (dictionary): Parsed styles from the XML Excel file. (Not available for users)
/// - worksheet (string): The name of the worksheet to be parsed.
/// - with-table-styles (boolean): If true, apply column width and row height to the table.
/// - with-table-alignment (boolean): If true, apply alignment to the table.
/// - default-row-height (string): The default row height.
/// - table-args (any): Arguments to be passed to table.
/// -> content
#let worksheet-parser(
xml-path: none,
worksheets: none,
styles: none,
worksheet: "Sheet1",
with-table-styles: true,
with-table-alignment: true,
default-row-height: "20pt",
..table-args,
) = {
let (worksheets, styles) = if xml-path != none {
xml-to-worksheets(xml-path)
} else {
(worksheets, styles)
}
let worksheet = worksheets.find(e => e.attrs.Name == worksheet)

let excel-table = worksheet
.children
.find(e => "tag" in e and e.tag == "Table")
.children
.filter(e => if type(e) == "string" { false } else { true }) // 去除换行符

let columns = excel-table
.map(e => if e.tag == "Column" {
eval(e.attrs.Width + "pt")
})
.filter(e => e != none)

let rows = excel-table
.map(e => if e.tag == "Row" {
eval(if "Height" in e.attrs {
e.attrs.Height + "pt"
} else {
default-row-height
})
})
.filter(e => e != none)

let cells = excel-table
.filter(e => e.tag == "Row")
.map(row => {
row
.children
.filter(e => if type(e) == "string" { false } else { true })
.map(c => {
let colspan = if "MergeAcross" in c.attrs {
eval(c.attrs.MergeAcross) + 1
} else {
1
}
let rowspan = if "MergeDown" in c.attrs {
eval(c.attrs.MergeDown) + 1
} else {
1
}
let content = c.children.at(0).children.at(0)

if "StyleID" not in c.attrs or not with-table-alignment {
table.cell(
colspan: colspan,
rowspan: rowspan,
content,
)
} else if with-table-alignment {
let styleId = c.attrs.StyleID
let style = if styleId != none { styles.at(styleId) } else {
styles.at("Default")
}
table.cell(
colspan: colspan,
rowspan: rowspan,
align: eval(style),
content,
)
} else {
table.cell(
colspan: colspan,
rowspan: rowspan,
content,
)
}
})
})
.flatten()

if with-table-styles {
table(
columns: columns,
rows: rows,
..cells
)
} else {
if columns.len() > 0 {
table(
columns: columns,
..table-args,
..cells
)
} else {
table(
..table-args,
..cells
)
}
}
}

/// Parse worksheets from an Excel file.
///
/// - xml-path (string): The path to the XML Excel file.
/// - to-array (boolean): If true, return an array of tables.
/// - args (any): Arguments to be passed to worksheet-parser.
/// -> content | array
#let worksheets-parser(
xml-path: none,
to-array: false,
..args,
) = {
let (worksheets, styles) = xml-to-worksheets(xml-path)
for worksheet in worksheets {
if to-array {
(
worksheet-parser(
worksheets: worksheets,
styles: styles,
worksheet: worksheet.attrs.Name,
..args,
),
)
} else {
worksheet-parser(
worksheets: worksheets,
styles: styles,
worksheet: worksheet.attrs.Name,
..args,
)
}
}
}
10 changes: 10 additions & 0 deletions packages/preview/exmllent/0.1.0/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "exmllent"
version = "0.1.0"
entrypoint = "lib.typ"
authors = ["hongjr03 <https://github.com/hongjr03>"]
description = "Pure typst implementation of converting XML Excel table to typst table."
license = "MIT"
repository = "https://github.com/hongjr03/typst-xml-table-parser"
categories = ["visualization", "utility"]
keywords = ["excel", "table"]
21 changes: 21 additions & 0 deletions packages/preview/mahjong-tiles/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Hong Jiarong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions packages/preview/mahjong-tiles/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Typst-Mahjong-Tiles

[riichi-hand-rs](https://github.com/m4tx/riichi-hand-rs) in Typst, powered by wasm.

## Usage

Start with `#import "src/lib.typ": mahjong`. Reminds that `mahjong_tiles.wasm` should be in the same directory as where `src/` is.

Parameters:

- `hand`: A string of tiles in the hand.
- `tile-set`: The tile set to use. Default is `"yellow-fluffy-stuff"`. `"red-fluffy-stuff"`, `"black-fluffy-stuff"`, `"martin-persson"` are also available.
<!-- - tile_gap: 0.2, group_gap: 1.0 / 4.0 -->
- `tile_gap`: The gap between tiles. Default is `0.0`.
- `group_gap`: The gap between groups. Default is `1.0 / 3.0`.
- `..args`: Other arguments to pass to the `image.decode()` fuction.

```typst
#mahjong("21w2www7w28p", tile-set: "martin-persson", alt: "majhong")
```

![21w2www7w28p](assets/21w2www7w28p.png)

```typst
#mahjong("2312936963s", alt: "majhong")
```

![2312936963s](assets/2312936963s.png)

## Credits

- [riichi-hand-rs](https://github.com/m4tx/riichi-hand-rs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if you could compress this file, to not bloat the repository too much. You can use oxipng for that (or any image editing program).

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/preview/mahjong-tiles/0.1.0/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import "mod.typ": mahjong
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/preview/mahjong-tiles/0.1.0/mod.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#let p = plugin("mahjong_tiles.wasm")

#let mahjong(hand, ..args, tile-set: "yellow-fluffy-stuff", tile_gap: 0.0, group_gap: 1.0 / 3.0) = image.decode(

Check warning on line 3 in packages/preview/mahjong-tiles/0.1.0/mod.typ

View check run for this annotation

Typst package check / @preview/mahjong-tiles:0.1.0

packages/preview/mahjong-tiles/0.1.0/mod.typ#L3

This argument seems to be part of public function. It is recommended to use kebab-case names.

Check warning on line 3 in packages/preview/mahjong-tiles/0.1.0/mod.typ

View check run for this annotation

Typst package check / @preview/mahjong-tiles:0.1.0

packages/preview/mahjong-tiles/0.1.0/mod.typ#L3

This argument seems to be part of public function. It is recommended to use kebab-case names.
p.mahjong(bytes(hand), bytes(tile-set), bytes(str(tile_gap)), bytes(str(group_gap))),
..args,
)
14 changes: 14 additions & 0 deletions packages/preview/mahjong-tiles/0.1.0/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "mahjong-tiles"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is too descriptive of what the package does. Could you please change it to something more unique?

version = "0.1.0"
entrypoint = "lib.typ"
authors = ["hongjr03 <https://github.com/hongjr03>"]
description = "Riichi-hand-rs but in Typst."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this description could be improved. I personally don't know what riichi-hand-rs is, and I believe a lot of people don't either. Something along the lines of "Render Mahjong tiles" would be better.

license = "MIT"
repository = "https://github.com/hongjr03/typst-mahjong-tiles"
keywords = [
"wasm",
"rust",
"mahjong",
"visualization",
]
21 changes: 21 additions & 0 deletions packages/preview/zebraw/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2024] [Hong Jiarong, et al.]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading