print msg when png and layout in progress
This commit is contained in:
parent
9e65f72952
commit
579bbace03
4 changed files with 44 additions and 0 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
- `--browser` flag on CLI controls `BROWSER` environment variable for not opening browser in watch mode. [#1052](https://github.com/terrastruct/d2/pull/1052)
|
- `--browser` flag on CLI controls `BROWSER` environment variable for not opening browser in watch mode. [#1052](https://github.com/terrastruct/d2/pull/1052)
|
||||||
- `elk` layout containers no longer overlap the label with children. [#1055](https://github.com/terrastruct/d2/pull/1055)
|
- `elk` layout containers no longer overlap the label with children. [#1055](https://github.com/terrastruct/d2/pull/1055)
|
||||||
|
- Message emitted by CLI when a particular stage is taking a long time. [#1058](https://github.com/terrastruct/d2/pull/1058)
|
||||||
- `<title>` attribute of HTML in watch mode is the base file name, instead of the whole path. [#1054](https://github.com/terrastruct/d2/pull/1054)
|
- `<title>` attribute of HTML in watch mode is the base file name, instead of the whole path. [#1054](https://github.com/terrastruct/d2/pull/1054)
|
||||||
|
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
"oss.terrastruct.com/d2/d2themes"
|
"oss.terrastruct.com/d2/d2themes"
|
||||||
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
||||||
|
"oss.terrastruct.com/d2/lib/background"
|
||||||
"oss.terrastruct.com/d2/lib/imgbundler"
|
"oss.terrastruct.com/d2/lib/imgbundler"
|
||||||
ctxlog "oss.terrastruct.com/d2/lib/log"
|
ctxlog "oss.terrastruct.com/d2/lib/log"
|
||||||
"oss.terrastruct.com/d2/lib/pdf"
|
"oss.terrastruct.com/d2/lib/pdf"
|
||||||
|
|
@ -289,10 +290,17 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc
|
||||||
if sketch {
|
if sketch {
|
||||||
opts.FontFamily = go2.Pointer(d2fonts.HandDrawn)
|
opts.FontFamily = go2.Pointer(d2fonts.HandDrawn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancel := background.Repeat(func() {
|
||||||
|
ms.Log.Info.Printf("compiling & running layout algorithms...")
|
||||||
|
}, time.Second*5)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
diagram, g, err := d2lib.Compile(ctx, string(input), opts)
|
diagram, g, err := d2lib.Compile(ctx, string(input), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
cancel()
|
||||||
|
|
||||||
pluginInfo, err := plugin.Info(ctx)
|
pluginInfo, err := plugin.Info(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
28
lib/background/background.go
Normal file
28
lib/background/background.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package background
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func Repeat(do func(), interval time.Duration) (cancel func()) {
|
||||||
|
t := time.NewTicker(interval)
|
||||||
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer t.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-t.C:
|
||||||
|
do()
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
stopped := false
|
||||||
|
return func() {
|
||||||
|
if !stopped {
|
||||||
|
stopped = true
|
||||||
|
close(done)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
|
||||||
|
|
@ -13,6 +14,7 @@ import (
|
||||||
pngstruct "github.com/dsoprea/go-png-image-structure/v2"
|
pngstruct "github.com/dsoprea/go-png-image-structure/v2"
|
||||||
"github.com/playwright-community/playwright-go"
|
"github.com/playwright-community/playwright-go"
|
||||||
|
|
||||||
|
"oss.terrastruct.com/d2/lib/background"
|
||||||
"oss.terrastruct.com/d2/lib/version"
|
"oss.terrastruct.com/d2/lib/version"
|
||||||
"oss.terrastruct.com/util-go/xmain"
|
"oss.terrastruct.com/util-go/xmain"
|
||||||
)
|
)
|
||||||
|
|
@ -82,6 +84,11 @@ var genPNGScript string
|
||||||
const pngPrefix = "data:image/png;base64,"
|
const pngPrefix = "data:image/png;base64,"
|
||||||
|
|
||||||
func ConvertSVG(ms *xmain.State, page playwright.Page, svg []byte) ([]byte, error) {
|
func ConvertSVG(ms *xmain.State, page playwright.Page, svg []byte) ([]byte, error) {
|
||||||
|
cancel := background.Repeat(func() {
|
||||||
|
ms.Log.Info.Printf("converting to PNG...")
|
||||||
|
}, time.Second*5)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
encodedSVG := base64.StdEncoding.EncodeToString(svg)
|
encodedSVG := base64.StdEncoding.EncodeToString(svg)
|
||||||
pngInterface, err := page.Evaluate(genPNGScript, "data:image/svg+xml;charset=utf-8;base64,"+encodedSVG)
|
pngInterface, err := page.Evaluate(genPNGScript, "data:image/svg+xml;charset=utf-8;base64,"+encodedSVG)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue