@things-factory/board-service 6.0.49 → 6.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/board-service",
3
- "version": "6.0.49",
3
+ "version": "6.0.52",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -36,5 +36,5 @@
36
36
  "devDependencies": {
37
37
  "@types/puppeteer": "^5.4.6"
38
38
  },
39
- "gitHead": "e107d6f692d008add950e000d2653bcbbd711a24"
39
+ "gitHead": "be223b9a3f3a093cba2f97110e109597c9f9b21f"
40
40
  }
@@ -1,11 +1,70 @@
1
1
  import { SelectQueryBuilder } from 'typeorm'
2
2
 
3
3
  import { Font } from '@things-factory/font-base'
4
- import { getRepository } from '@things-factory/shell'
4
+ import { Attachment } from '@things-factory/attachment-base'
5
+ import { getRepository, Domain } from '@things-factory/shell'
5
6
 
6
- export const fonts = async () => {
7
+ export const fonts = async (domain?: Domain) => {
7
8
  const qb: SelectQueryBuilder<Font> = await getRepository(Font).createQueryBuilder('FONT')
8
- return (await qb.select('name').distinct(true).where({ active: true }).getRawMany()).map(
9
- (f: { name: string }) => f.name
10
- )
9
+
10
+ const fonts = domain
11
+ ? await qb
12
+ .select('name')
13
+ .distinct(true)
14
+ .addSelect('provider')
15
+ .addSelect('id')
16
+ .addSelect('uri')
17
+ .where({ domain: { id: domain.id }, active: true })
18
+ .getRawMany()
19
+ : await qb.select('name').distinct(true).where({ active: true }).getRawMany()
20
+
21
+ var googleFonts = fonts.filter(({ provider }) => provider == 'google')
22
+ var customFonts = fonts.filter(({ provider }) => provider == 'custom')
23
+
24
+ var customFontCSS: string = ''
25
+
26
+ for (const font of customFonts) {
27
+ var files: Attachment = domain
28
+ ? await getRepository(Attachment).findBy({
29
+ domain: { id: domain.id },
30
+ refBy: font.id
31
+ })
32
+ : await getRepository(Attachment).findBy({
33
+ refBy: font.id
34
+ })
35
+
36
+ if (files && files.length > 0) {
37
+ customFontCSS += files
38
+ .map(file => {
39
+ const { name: filename, fullpath } = file
40
+ const bold = filename.toUpperCase().indexOf('BOLD') !== -1
41
+
42
+ return `@font-face {
43
+ font-family: '${font.name}';
44
+ src: local('${font.name}'), url(${fullpath});
45
+ font-weight: ${bold ? 'bold' : 'normal'};
46
+ }
47
+ `
48
+ })
49
+ .join('\n')
50
+ } else {
51
+ customFontCSS += `@font-face {
52
+ font-family: '${font.name}';
53
+ src: local('${font.name}')${font.uri ? `, url(${font.uri})` : ''};
54
+ }
55
+ `
56
+ }
57
+ }
58
+
59
+ return [
60
+ {
61
+ google: {
62
+ families: googleFonts.map(({ name }) => name)
63
+ },
64
+ custom: {
65
+ families: customFonts.map(({ name }) => name)
66
+ }
67
+ },
68
+ customFontCSS
69
+ ]
11
70
  }
@@ -95,7 +95,7 @@ async function initializeScenePage() {
95
95
  const url = `${protocol}://${host}:${port}${path}`
96
96
 
97
97
  const page = await browser.newPage()
98
- const fontsToUse = await fonts()
98
+ const [fontsToUse, fontStyles] = await fonts()
99
99
 
100
100
  await page.setRequestInterception(true)
101
101
  page.on('console', msg => {
@@ -111,7 +111,8 @@ async function initializeScenePage() {
111
111
  'Content-Type': 'application/json'
112
112
  },
113
113
  postData: JSON.stringify({
114
- fonts: fontsToUse
114
+ fonts: fontsToUse,
115
+ fontStyles
115
116
  })
116
117
  })
117
118
  } else {
@@ -24,7 +24,10 @@ export const pdf = async ({
24
24
  const { domain, user } = context.state
25
25
 
26
26
  var { model, base } = await headlessModel({ domain, id, model })
27
- model.fonts = await fonts()
27
+ const [fontsToUse, fontStyles] = await fonts(domain)
28
+
29
+ model.fonts = fontsToUse
30
+ model.fontStyles = fontStyles
28
31
 
29
32
  let { width, height } = model
30
33
 
@@ -25,7 +25,10 @@ export const screenshot = async ({
25
25
  const { domain, user } = context.state
26
26
 
27
27
  var { model, base } = await headlessModel({ domain, id, model })
28
- model.fonts = await fonts()
28
+ const [fontsToUse, fontStyles] = await fonts(domain)
29
+
30
+ model.fonts = fontsToUse
31
+ model.fontStyles = fontStyles
29
32
 
30
33
  var { width, height } = model
31
34
 
@@ -13,13 +13,16 @@ import { Board } from '../service/board/board'
13
13
 
14
14
  export const standaloneBoardServiceRouter = new Router()
15
15
 
16
- // for board headless
16
+ // for board headless-full
17
17
  standaloneBoardServiceRouter.get('/headless-full/:id', async (context, next) => {
18
18
  const { domain, user } = context.state
19
19
  const { id } = context.params
20
20
 
21
21
  const { model, base } = await headlessModel({ domain, id })
22
- model.fonts = await fonts()
22
+ const [fontsToUse, fontStyles] = await fonts(domain)
23
+
24
+ model.fonts = fontsToUse
25
+ model.fontStyles = fontStyles
23
26
 
24
27
  setAccessTokenCookie(context, await user.sign({ domain }))
25
28
 
@@ -32,7 +35,10 @@ standaloneBoardServiceRouter.get('/headless/:id', async (context, next) => {
32
35
  const { id } = context.params
33
36
 
34
37
  const { model, base } = await headlessModel({ domain, id })
35
- model.fonts = await fonts()
38
+ const [fontsToUse, fontStyles] = await fonts(domain)
39
+
40
+ model.fonts = fontsToUse
41
+ model.fontStyles = fontStyles
36
42
 
37
43
  setAccessTokenCookie(context, await user.sign({ domain }))
38
44
 
@@ -34,9 +34,19 @@
34
34
 
35
35
  <script>
36
36
  var model = <%- JSON.stringify(model) %>;
37
+
38
+ let style = document.head.querySelector('#custom-fonts')
39
+ if (!style) {
40
+ style = document.createElement('style')
41
+ style.id = 'custom-fonts'
42
+ document.head.appendChild(style)
43
+ }
44
+ style.innerHTML = model.fontStyles
45
+
37
46
  WebFont.load({
38
- google: {
39
- families: model.fonts || []
47
+ ...model.fonts,
48
+ fontactive: () => {
49
+ window.dispatchEvent(new CustomEvent('resize'))
40
50
  }
41
51
  })
42
52
  </script>
@@ -25,9 +25,19 @@
25
25
  <script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
26
26
  <script>
27
27
  var model = <%- JSON.stringify(model) %>;
28
+
29
+ let style = document.head.querySelector('#custom-fonts')
30
+ if (!style) {
31
+ style = document.createElement('style')
32
+ style.id = 'custom-fonts'
33
+ document.head.appendChild(style)
34
+ }
35
+ style.innerHTML = model.fontStyles
36
+
28
37
  WebFont.load({
29
- google: {
30
- families: model.fonts || []
38
+ ...model.fonts,
39
+ fontactive: () => {
40
+ window.dispatchEvent(new CustomEvent('resize'))
31
41
  }
32
42
  })
33
43
  </script>
@@ -23,9 +23,19 @@
23
23
  <script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
24
24
  <script>
25
25
  var model = <%- JSON.stringify(model) %>;
26
+
27
+ let style = document.head.querySelector('#custom-fonts')
28
+ if (!style) {
29
+ style = document.createElement('style')
30
+ style.id = 'custom-fonts'
31
+ document.head.appendChild(style)
32
+ }
33
+ style.innerHTML = model.fontStyles
34
+
26
35
  WebFont.load({
27
- google: {
28
- families: model.fonts || []
36
+ ...model.fonts,
37
+ fontactive: () => {
38
+ window.dispatchEvent(new CustomEvent('resize'))
29
39
  }
30
40
  })
31
41
  </script>