jsonresume-theme-sidebar 0.2.2 → 0.2.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # jsonresume-theme-sidebar
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - eb7f950: use @jsonresume/core/ssr renderResumeDocument
8
+ - Updated dependencies [ff09f75]
9
+ - @jsonresume/core@0.3.1
10
+
3
11
  ## 0.2.2
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { renderToString } from "react-dom/server";
2
+ import { renderToStaticMarkup } from "react-dom/server";
3
3
  import o, { useRef, useContext, useState, useMemo, useEffect, useDebugValue, createElement, createContext } from "react";
4
4
  var __assign = function() {
5
5
  __assign = Object.assign || function __assign2(t) {
@@ -1300,6 +1300,66 @@ var vt = /^\s*<\/[a-z]/i, gt = (function() {
1300
1300
  "production" !== process.env.NODE_ENV && "undefined" != typeof navigator && "ReactNative" === navigator.product && console.warn("It looks like you've imported 'styled-components' on React Native.\nPerhaps you're looking to import 'styled-components/native'?\nRead more about this at https://www.styled-components.com/docs/basics#react-native");
1301
1301
  var wt = "__sc-".concat(f, "__");
1302
1302
  "production" !== process.env.NODE_ENV && "test" !== process.env.NODE_ENV && "undefined" != typeof window && (window[wt] || (window[wt] = 0), 1 === window[wt] && console.warn("It looks like there are several instances of 'styled-components' initialized in this application. This may cause dynamic styles to not render properly, errors during the rehydration process, a missing theme prop, and makes your application bigger without good reason.\n\nSee https://s-c.sh/2BAXzed for more info."), window[wt] += 1);
1303
+ const CSS_RESET = "<style>*,*::before,*::after{box-sizing:border-box}html,body{margin:0;padding:0}body{-webkit-font-smoothing:antialiased}</style>";
1304
+ const TOKENS_CSS_HREF = "https://unpkg.com/@jsonresume/core/dist/tokens.css";
1305
+ const FONTS_PRECONNECT = '<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>';
1306
+ function isHref(value) {
1307
+ return /^(https?:)?\/\//.test(value) || value.trim().startsWith("<link");
1308
+ }
1309
+ function familyParam(family) {
1310
+ const [name, ...rest] = String(family).split(":");
1311
+ const encodedName = name.trim().replace(/\s+/g, "+");
1312
+ return rest.length ? `${encodedName}:${rest.join(":")}` : encodedName;
1313
+ }
1314
+ function googleFontsLinks(families) {
1315
+ if (!Array.isArray(families) || families.length === 0) return "";
1316
+ const passthrough = [];
1317
+ const names = [];
1318
+ for (const entry of families) {
1319
+ if (entry == null || entry === "") continue;
1320
+ if (isHref(entry)) passthrough.push(entry);
1321
+ else names.push(entry);
1322
+ }
1323
+ const links = passthrough.map(
1324
+ (href) => href.trim().startsWith("<link") ? href : `<link href="${href}" rel="stylesheet">`
1325
+ );
1326
+ if (names.length > 0) {
1327
+ const query = names.map(familyParam).join("&family=");
1328
+ links.unshift(
1329
+ `<link href="https://fonts.googleapis.com/css2?family=${query}&display=swap" rel="stylesheet">`
1330
+ );
1331
+ }
1332
+ if (links.length === 0) return "";
1333
+ return FONTS_PRECONNECT + links.join("");
1334
+ }
1335
+ function renderResumeDocument(element, options = {}) {
1336
+ const {
1337
+ fonts,
1338
+ title,
1339
+ lang = "en",
1340
+ dir = "ltr",
1341
+ reset = false,
1342
+ head = "",
1343
+ headAfterStyles = "",
1344
+ includeTokensCss = true,
1345
+ bodyClass
1346
+ } = options;
1347
+ const sheet = new gt();
1348
+ let html;
1349
+ let styleTags;
1350
+ try {
1351
+ html = renderToStaticMarkup(sheet.collectStyles(element));
1352
+ styleTags = sheet.getStyleTags();
1353
+ } finally {
1354
+ sheet.seal();
1355
+ }
1356
+ const fontLinks = googleFontsLinks(fonts);
1357
+ const tokensLink = includeTokensCss ? `<link rel="stylesheet" href="${TOKENS_CSS_HREF}">` : "";
1358
+ const resetTag = reset ? CSS_RESET : "";
1359
+ const titleTag = title ? `<title>${title}</title>` : "";
1360
+ const bodyAttr = bodyClass ? ` class="${bodyClass}"` : "";
1361
+ return `<!DOCTYPE html><html lang="${lang}" dir="${dir}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">` + fontLinks + tokensLink + resetTag + head + styleTags + headAfterStyles + titleTag + `</head><body${bodyAttr}>${html}</body></html>`;
1362
+ }
1303
1363
  createContext({
1304
1364
  theme: "professional",
1305
1365
  setTheme: () => {
@@ -1453,7 +1513,6 @@ function safeUrl(url) {
1453
1513
  const trimmed = url.trim();
1454
1514
  const dangerousProtocols = /^(javascript|data|vbscript|file|about):/i;
1455
1515
  if (dangerousProtocols.test(trimmed)) {
1456
- console.warn(`[Security] Blocked dangerous URL: ${trimmed.slice(0, 50)}`);
1457
1516
  return null;
1458
1517
  }
1459
1518
  const safeProtocols = /^(https?|mailto|tel|sms|ftp):/i;
@@ -1469,7 +1528,6 @@ function safeUrl(url) {
1469
1528
  if (/^[a-z0-9][a-z0-9.-]+\.[a-z]{2,}$/i.test(trimmed)) {
1470
1529
  return `https://${trimmed}`;
1471
1530
  }
1472
- console.warn(`[Security] Uncertain URL safety: ${trimmed.slice(0, 50)}`);
1473
1531
  return trimmed;
1474
1532
  }
1475
1533
  function getLinkRel(url, openInNewTab = false) {
@@ -6373,13 +6431,7 @@ function render(resume, options = {}) {
6373
6431
  dir = "ltr",
6374
6432
  title = resume.basics?.name || "Resume"
6375
6433
  } = options;
6376
- const sheet = new gt();
6377
- try {
6378
- const html = renderToString(
6379
- sheet.collectStyles(/* @__PURE__ */ jsx(Resume, { resume }))
6380
- );
6381
- const styles = sheet.getStyleTags();
6382
- const designTokens = `
6434
+ const designTokens = `
6383
6435
  :root {
6384
6436
  --resume-font-sans: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
6385
6437
  --resume-color-sidebar: #1e3a52;
@@ -6388,7 +6440,7 @@ function render(resume, options = {}) {
6388
6440
  --resume-color-accent: #1e3a52;
6389
6441
  }
6390
6442
  `;
6391
- const globalStyles = `
6443
+ const globalStyles = `
6392
6444
  * {
6393
6445
  margin: 0;
6394
6446
  padding: 0;
@@ -6412,30 +6464,18 @@ function render(resume, options = {}) {
6412
6464
  }
6413
6465
  }
6414
6466
  `;
6415
- return `<!DOCTYPE html>
6416
- <html lang="${locale}" dir="${dir}">
6417
- <head>
6418
- <meta charset="UTF-8">
6419
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6420
- <title>${title}</title>
6421
-
6422
- <style>
6467
+ return renderResumeDocument(/* @__PURE__ */ jsx(Resume, { resume }), {
6468
+ head: `<style>
6423
6469
  ${designTokens}
6424
- </style>
6425
-
6426
- ${styles}
6427
-
6428
- <style>
6470
+ </style>`,
6471
+ headAfterStyles: `<style>
6429
6472
  ${globalStyles}
6430
- </style>
6431
- </head>
6432
- <body>
6433
- ${html}
6434
- </body>
6435
- </html>`;
6436
- } finally {
6437
- sheet.seal();
6438
- }
6473
+ </style>`,
6474
+ lang: locale,
6475
+ dir,
6476
+ title,
6477
+ includeTokensCss: false
6478
+ });
6439
6479
  }
6440
6480
  const index = { render };
6441
6481
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsonresume-theme-sidebar",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Two-column sidebar resume theme with dark sidebar and light main content - ATS-friendly",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "react": "^19.2.0",
29
29
  "react-dom": "^19.2.0",
30
30
  "styled-components": "^6.1.19",
31
- "@jsonresume/core": "0.3.0"
31
+ "@jsonresume/core": "0.3.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "vitest": "^1.6.0",
package/src/index.jsx CHANGED
@@ -1,5 +1,4 @@
1
- import { renderToString } from 'react-dom/server';
2
- import { ServerStyleSheet } from 'styled-components';
1
+ import { renderResumeDocument } from '@jsonresume/core/ssr';
3
2
  import Resume from './Resume.jsx';
4
3
 
5
4
  /**
@@ -17,16 +16,7 @@ export function render(resume, options = {}) {
17
16
  title = resume.basics?.name || 'Resume',
18
17
  } = options;
19
18
 
20
- const sheet = new ServerStyleSheet();
21
-
22
- try {
23
- const html = renderToString(
24
- sheet.collectStyles(<Resume resume={resume} />)
25
- );
26
-
27
- const styles = sheet.getStyleTags();
28
-
29
- const designTokens = `
19
+ const designTokens = `
30
20
  :root {
31
21
  --resume-font-sans: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
32
22
  --resume-color-sidebar: #1e3a52;
@@ -36,7 +26,7 @@ export function render(resume, options = {}) {
36
26
  }
37
27
  `;
38
28
 
39
- const globalStyles = `
29
+ const globalStyles = `
40
30
  * {
41
31
  margin: 0;
42
32
  padding: 0;
@@ -61,30 +51,18 @@ export function render(resume, options = {}) {
61
51
  }
62
52
  `;
63
53
 
64
- return `<!DOCTYPE html>
65
- <html lang="${locale}" dir="${dir}">
66
- <head>
67
- <meta charset="UTF-8">
68
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
69
- <title>${title}</title>
70
-
71
- <style>
54
+ return renderResumeDocument(<Resume resume={resume} />, {
55
+ head: `<style>
72
56
  ${designTokens}
73
- </style>
74
-
75
- ${styles}
76
-
77
- <style>
57
+ </style>`,
58
+ headAfterStyles: `<style>
78
59
  ${globalStyles}
79
- </style>
80
- </head>
81
- <body>
82
- ${html}
83
- </body>
84
- </html>`;
85
- } finally {
86
- sheet.seal();
87
- }
60
+ </style>`,
61
+ lang: locale,
62
+ dir,
63
+ title,
64
+ includeTokensCss: false,
65
+ });
88
66
  }
89
67
 
90
68
  export { Resume };