docyard 1.2.0 → 1.4.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -1
- data/lib/docyard/cli.rb +17 -0
- data/lib/docyard/components/aliases.rb +2 -0
- data/lib/docyard/components/processors/code_block_annotation_preprocessor.rb +149 -0
- data/lib/docyard/components/processors/code_block_processor.rb +21 -11
- data/lib/docyard/components/processors/variables_processor.rb +56 -0
- data/lib/docyard/components/support/code_block/annotation_list_parser.rb +84 -0
- data/lib/docyard/components/support/code_block/line_wrapper.rb +25 -1
- data/lib/docyard/components/support/code_block/patterns.rb +11 -0
- data/lib/docyard/config/schema/definition.rb +2 -1
- data/lib/docyard/config.rb +3 -1
- data/lib/docyard/deploy/adapters/base.rb +56 -0
- data/lib/docyard/deploy/adapters/cloudflare.rb +38 -0
- data/lib/docyard/deploy/adapters/github_pages.rb +60 -0
- data/lib/docyard/deploy/adapters/netlify.rb +37 -0
- data/lib/docyard/deploy/adapters/vercel.rb +36 -0
- data/lib/docyard/deploy/deployer.rb +95 -0
- data/lib/docyard/deploy/platform_detector.rb +32 -0
- data/lib/docyard/errors.rb +2 -0
- data/lib/docyard/rendering/markdown.rb +2 -0
- data/lib/docyard/templates/assets/css/components/code-annotation.css +265 -0
- data/lib/docyard/templates/assets/css/variables.css +2 -0
- data/lib/docyard/templates/assets/js/components/code-annotation.js +136 -0
- data/lib/docyard/templates/assets/js/hot-reload.js +1 -0
- data/lib/docyard/templates/partials/_code_block.html.erb +1 -1
- data/lib/docyard/version.rb +1 -1
- metadata +13 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tmpdir"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require_relative "base"
|
|
6
|
+
|
|
7
|
+
module Docyard
|
|
8
|
+
module Deploy
|
|
9
|
+
module Adapters
|
|
10
|
+
class GithubPages < Base
|
|
11
|
+
def platform_name
|
|
12
|
+
"GitHub Pages"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def cli_name
|
|
18
|
+
"gh"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def cli_install_hint
|
|
22
|
+
"https://cli.github.com"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def run_deploy
|
|
26
|
+
remote_url = fetch_remote_url
|
|
27
|
+
Dir.mktmpdir do |tmp|
|
|
28
|
+
prepare_deploy_dir(tmp)
|
|
29
|
+
push_to_gh_pages(tmp, remote_url)
|
|
30
|
+
end
|
|
31
|
+
build_pages_url(remote_url)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def fetch_remote_url
|
|
35
|
+
execute_command("git", "remote", "get-url", "origin").strip
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def prepare_deploy_dir(tmp)
|
|
39
|
+
FileUtils.cp_r("#{output_dir}/.", tmp)
|
|
40
|
+
execute_command("git", "-C", tmp, "init", "-b", "gh-pages")
|
|
41
|
+
execute_command("git", "-C", tmp, "add", ".")
|
|
42
|
+
execute_command("git", "-C", tmp, "commit", "-m", "Deploy via docyard")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def push_to_gh_pages(tmp, remote_url)
|
|
46
|
+
execute_command("git", "-C", tmp, "remote", "add", "origin", remote_url)
|
|
47
|
+
execute_command("git", "-C", tmp, "push", "--force", "origin", "gh-pages")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def build_pages_url(remote_url)
|
|
51
|
+
match = remote_url.match(%r{github\.com[:/]([^/]+)/([^/.]+)})
|
|
52
|
+
return nil unless match
|
|
53
|
+
|
|
54
|
+
owner, repo = match.captures
|
|
55
|
+
"https://#{owner}.github.io/#{repo}/"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module Docyard
|
|
6
|
+
module Deploy
|
|
7
|
+
module Adapters
|
|
8
|
+
class Netlify < Base
|
|
9
|
+
def platform_name
|
|
10
|
+
"Netlify"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def cli_name
|
|
16
|
+
"netlify"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cli_install_hint
|
|
20
|
+
"npm i -g netlify-cli"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run_deploy
|
|
24
|
+
args = ["netlify", "deploy", "--dir=#{output_dir}"]
|
|
25
|
+
args << "--prod" if production
|
|
26
|
+
output = execute_command(*args)
|
|
27
|
+
extract_url(output)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def extract_url(output)
|
|
31
|
+
pattern = production ? /Website URL:\s+(\S+)/ : /Website draft URL:\s+(\S+)/
|
|
32
|
+
output.match(pattern)&.captures&.first
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module Docyard
|
|
6
|
+
module Deploy
|
|
7
|
+
module Adapters
|
|
8
|
+
class Vercel < Base
|
|
9
|
+
def platform_name
|
|
10
|
+
"Vercel"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def cli_name
|
|
16
|
+
"vercel"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cli_install_hint
|
|
20
|
+
"npm i -g vercel"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run_deploy
|
|
24
|
+
args = ["vercel", output_dir, "--yes"]
|
|
25
|
+
args << "--prod" if production
|
|
26
|
+
output = execute_command(*args)
|
|
27
|
+
extract_url(output)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def extract_url(output)
|
|
31
|
+
output.strip.lines.last&.strip
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "platform_detector"
|
|
4
|
+
require_relative "adapters/vercel"
|
|
5
|
+
require_relative "adapters/netlify"
|
|
6
|
+
require_relative "adapters/cloudflare"
|
|
7
|
+
require_relative "adapters/github_pages"
|
|
8
|
+
|
|
9
|
+
module Docyard
|
|
10
|
+
module Deploy
|
|
11
|
+
class Deployer
|
|
12
|
+
ADAPTERS = {
|
|
13
|
+
"vercel" => Adapters::Vercel,
|
|
14
|
+
"netlify" => Adapters::Netlify,
|
|
15
|
+
"cloudflare" => Adapters::Cloudflare,
|
|
16
|
+
"github-pages" => Adapters::GithubPages
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
attr_reader :config, :platform, :production, :skip_build
|
|
20
|
+
|
|
21
|
+
def initialize(to: nil, production: true, skip_build: false)
|
|
22
|
+
@config = Config.new
|
|
23
|
+
@platform = to
|
|
24
|
+
@production = production
|
|
25
|
+
@skip_build = skip_build
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def deploy
|
|
29
|
+
print_header
|
|
30
|
+
ensure_build
|
|
31
|
+
adapter = resolve_adapter
|
|
32
|
+
print_deploy_info(adapter)
|
|
33
|
+
url = adapter.deploy
|
|
34
|
+
print_success(url)
|
|
35
|
+
true
|
|
36
|
+
rescue DeployError => e
|
|
37
|
+
print_error(e)
|
|
38
|
+
false
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def print_header
|
|
44
|
+
puts
|
|
45
|
+
puts " #{UI.bold('Docyard')} v#{VERSION}"
|
|
46
|
+
puts " Deploying..."
|
|
47
|
+
puts
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def ensure_build
|
|
51
|
+
return if skip_build
|
|
52
|
+
|
|
53
|
+
require_relative "../builder"
|
|
54
|
+
builder = Builder.new
|
|
55
|
+
raise DeployError, "Build failed" unless builder.build
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def resolve_adapter
|
|
59
|
+
name = platform || detect_platform
|
|
60
|
+
adapter_class = ADAPTERS[name]
|
|
61
|
+
raise DeployError, "Unknown platform: #{name}. Valid options: #{ADAPTERS.keys.join(', ')}" unless adapter_class
|
|
62
|
+
|
|
63
|
+
adapter_class.new(output_dir: config.build.output, production: production, config: config)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def detect_platform
|
|
67
|
+
detected = PlatformDetector.new.detect
|
|
68
|
+
return detected if detected
|
|
69
|
+
|
|
70
|
+
raise DeployError,
|
|
71
|
+
"Could not detect platform. Use --to to specify one: #{ADAPTERS.keys.join(', ')}"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def print_deploy_info(adapter)
|
|
75
|
+
environment = production ? "production" : "preview"
|
|
76
|
+
puts " #{UI.dim('Platform')} #{adapter.platform_name}"
|
|
77
|
+
puts " #{UI.dim('Environment')} #{environment}"
|
|
78
|
+
puts " #{UI.dim('Directory')} #{config.build.output}/"
|
|
79
|
+
puts
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def print_success(url)
|
|
83
|
+
puts " #{UI.success('Deployed successfully')}"
|
|
84
|
+
puts " #{url}" if url
|
|
85
|
+
puts
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def print_error(error)
|
|
89
|
+
puts " #{UI.error('Deploy failed')}"
|
|
90
|
+
puts " #{error.message}"
|
|
91
|
+
puts
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Docyard
|
|
4
|
+
module Deploy
|
|
5
|
+
class PlatformDetector
|
|
6
|
+
DETECTION_RULES = [
|
|
7
|
+
{ files: ["vercel.json"], dirs: [".vercel"], platform: "vercel" },
|
|
8
|
+
{ files: ["netlify.toml"], dirs: [".netlify"], platform: "netlify" },
|
|
9
|
+
{ files: ["wrangler.toml", "wrangler.jsonc"], dirs: [], platform: "cloudflare" },
|
|
10
|
+
{ files: [], dirs: [".github/workflows"], platform: "github-pages" }
|
|
11
|
+
].freeze
|
|
12
|
+
|
|
13
|
+
def initialize(project_root = Dir.pwd)
|
|
14
|
+
@project_root = project_root
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def detect
|
|
18
|
+
DETECTION_RULES.each do |rule|
|
|
19
|
+
return rule[:platform] if matches?(rule)
|
|
20
|
+
end
|
|
21
|
+
nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def matches?(rule)
|
|
27
|
+
rule[:files].any? { |f| File.exist?(File.join(@project_root, f)) } ||
|
|
28
|
+
rule[:dirs].any? { |d| Dir.exist?(File.join(@project_root, d)) }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/docyard/errors.rb
CHANGED
|
@@ -19,6 +19,7 @@ require_relative "../components/processors/include_processor"
|
|
|
19
19
|
require_relative "../components/processors/code_block_options_preprocessor"
|
|
20
20
|
require_relative "../components/processors/code_block_diff_preprocessor"
|
|
21
21
|
require_relative "../components/processors/code_block_focus_preprocessor"
|
|
22
|
+
require_relative "../components/processors/code_block_annotation_preprocessor"
|
|
22
23
|
require_relative "../components/processors/code_block_extended_fence_preprocessor"
|
|
23
24
|
require_relative "../components/processors/code_block_extended_fence_postprocessor"
|
|
24
25
|
require_relative "../components/processors/table_wrapper_processor"
|
|
@@ -29,6 +30,7 @@ require_relative "../components/processors/video_embed_processor"
|
|
|
29
30
|
require_relative "../components/processors/file_tree_processor"
|
|
30
31
|
require_relative "../components/processors/abbreviation_processor"
|
|
31
32
|
require_relative "../components/processors/tooltip_processor"
|
|
33
|
+
require_relative "../components/processors/variables_processor"
|
|
32
34
|
require_relative "../components/processors/table_of_contents_processor"
|
|
33
35
|
require_relative "../components/aliases"
|
|
34
36
|
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
.docyard-code-annotation {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
width: var(--code-annotation-size);
|
|
7
|
+
height: var(--code-annotation-size);
|
|
8
|
+
margin-left: var(--spacing-1);
|
|
9
|
+
padding: 0;
|
|
10
|
+
border: none;
|
|
11
|
+
border-radius: var(--radius-4xl);
|
|
12
|
+
background: none;
|
|
13
|
+
color: var(--primary);
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
vertical-align: middle;
|
|
16
|
+
opacity: 0.7;
|
|
17
|
+
transition: opacity 150ms ease, transform 150ms ease;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.docyard-code-annotation::before {
|
|
21
|
+
content: "";
|
|
22
|
+
position: absolute;
|
|
23
|
+
inset: -0.375em;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.docyard-code-annotation i[class*="ph-"] {
|
|
27
|
+
font-size: 1.25em;
|
|
28
|
+
vertical-align: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@media (hover: hover) {
|
|
32
|
+
.docyard-code-annotation:hover {
|
|
33
|
+
opacity: 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.docyard-code-annotation:active {
|
|
38
|
+
transform: scale(0.92);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.docyard-code-annotation.is-active {
|
|
42
|
+
opacity: 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.docyard-code-annotation:focus-visible {
|
|
46
|
+
opacity: 1;
|
|
47
|
+
outline: 1.5px solid var(--primary);
|
|
48
|
+
outline-offset: 1px;
|
|
49
|
+
border-radius: 2px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.docyard-code-block--has-annotations .docyard-code-line {
|
|
53
|
+
padding-right: calc(var(--code-annotation-size) + var(--spacing-1));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.docyard-code-annotation-popover {
|
|
57
|
+
position: absolute;
|
|
58
|
+
z-index: var(--z-tooltip);
|
|
59
|
+
width: max-content;
|
|
60
|
+
max-width: 24rem;
|
|
61
|
+
max-height: 20rem;
|
|
62
|
+
overflow-y: auto;
|
|
63
|
+
padding: var(--spacing-3) var(--spacing-4);
|
|
64
|
+
background: var(--popover);
|
|
65
|
+
color: oklch(from var(--popover-foreground) l c h / 85%);
|
|
66
|
+
border: 1px solid var(--border);
|
|
67
|
+
border-radius: var(--radius-lg);
|
|
68
|
+
box-shadow:
|
|
69
|
+
0 1px 2px oklch(from var(--foreground) l c h / 3%),
|
|
70
|
+
0 4px 12px oklch(from var(--foreground) l c h / 6%),
|
|
71
|
+
0 16px 32px -8px oklch(from var(--foreground) l c h / 8%);
|
|
72
|
+
pointer-events: none;
|
|
73
|
+
opacity: 0;
|
|
74
|
+
transform: translateY(4px) scale(0.96);
|
|
75
|
+
transform-origin: var(--arrow-left, 16px) top;
|
|
76
|
+
transition:
|
|
77
|
+
opacity 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
|
|
78
|
+
transform 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.docyard-code-annotation-popover.is-visible {
|
|
82
|
+
opacity: 1;
|
|
83
|
+
transform: translateY(0) scale(1);
|
|
84
|
+
pointer-events: auto;
|
|
85
|
+
transition:
|
|
86
|
+
opacity 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
|
|
87
|
+
transform 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.docyard-code-annotation-popover.is-above {
|
|
91
|
+
transform: translateY(-4px) scale(0.96);
|
|
92
|
+
transform-origin: var(--arrow-left, 16px) bottom;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.docyard-code-annotation-popover.is-above.is-visible {
|
|
96
|
+
transform: translateY(0) scale(1);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.docyard-code-annotation-popover::after {
|
|
100
|
+
content: "";
|
|
101
|
+
position: absolute;
|
|
102
|
+
top: -5px;
|
|
103
|
+
left: var(--arrow-left, 16px);
|
|
104
|
+
width: 9px;
|
|
105
|
+
height: 9px;
|
|
106
|
+
background: var(--popover);
|
|
107
|
+
border-top: 1px solid var(--border);
|
|
108
|
+
border-left: 1px solid var(--border);
|
|
109
|
+
border-radius: 1px 0 0 0;
|
|
110
|
+
transform: rotate(45deg);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.docyard-code-annotation-popover.is-above::after {
|
|
114
|
+
top: auto;
|
|
115
|
+
bottom: -5px;
|
|
116
|
+
border-top: none;
|
|
117
|
+
border-left: none;
|
|
118
|
+
border-bottom: 1px solid var(--border);
|
|
119
|
+
border-right: 1px solid var(--border);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.docyard-code-annotation-popover p {
|
|
123
|
+
margin: 0;
|
|
124
|
+
font-size: var(--text-sm);
|
|
125
|
+
line-height: var(--leading-relaxed);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.docyard-code-annotation-popover * + p,
|
|
129
|
+
.docyard-code-annotation-popover * + ul,
|
|
130
|
+
.docyard-code-annotation-popover * + ol,
|
|
131
|
+
.docyard-code-annotation-popover * + blockquote {
|
|
132
|
+
margin-top: var(--spacing-2);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.docyard-code-annotation-popover * + .table-wrapper,
|
|
136
|
+
.docyard-code-annotation-popover * + table {
|
|
137
|
+
margin-top: var(--spacing-2);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.docyard-code-annotation-popover ul,
|
|
141
|
+
.docyard-code-annotation-popover ol {
|
|
142
|
+
margin: 0;
|
|
143
|
+
padding-left: var(--spacing-6);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.docyard-code-annotation-popover ul {
|
|
147
|
+
list-style-type: disc;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.docyard-code-annotation-popover ol {
|
|
151
|
+
list-style-type: decimal;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.docyard-code-annotation-popover li {
|
|
155
|
+
margin: var(--spacing-1) 0;
|
|
156
|
+
padding-left: var(--spacing-1);
|
|
157
|
+
font-size: var(--text-sm);
|
|
158
|
+
line-height: var(--leading-relaxed);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.docyard-code-annotation-popover li::marker {
|
|
162
|
+
color: var(--muted-foreground);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.docyard-code-annotation-popover table {
|
|
166
|
+
width: 100%;
|
|
167
|
+
border-spacing: 0;
|
|
168
|
+
border-collapse: separate;
|
|
169
|
+
font-size: var(--text-sm);
|
|
170
|
+
margin: 0;
|
|
171
|
+
border: 1px solid var(--table-border);
|
|
172
|
+
border-radius: var(--radius-lg);
|
|
173
|
+
overflow: hidden;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.docyard-code-annotation-popover thead {
|
|
177
|
+
background-color: var(--table-header-bg);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.docyard-code-annotation-popover th {
|
|
181
|
+
padding: var(--spacing-2) var(--spacing-3);
|
|
182
|
+
text-align: left;
|
|
183
|
+
font-weight: var(--font-semibold);
|
|
184
|
+
font-size: var(--text-xs);
|
|
185
|
+
color: var(--popover-foreground);
|
|
186
|
+
vertical-align: middle;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.docyard-code-annotation-popover td {
|
|
190
|
+
padding: var(--spacing-2) var(--spacing-3);
|
|
191
|
+
font-size: var(--text-xs);
|
|
192
|
+
vertical-align: middle;
|
|
193
|
+
border-top: 1px solid var(--table-row-border);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.docyard-code-annotation-popover blockquote {
|
|
197
|
+
margin: 0;
|
|
198
|
+
padding-left: var(--spacing-6);
|
|
199
|
+
border-left: 4px solid var(--border);
|
|
200
|
+
color: var(--muted-foreground);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.docyard-code-annotation-popover blockquote p {
|
|
204
|
+
margin: var(--spacing-1) 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.docyard-code-annotation-popover code {
|
|
208
|
+
padding: 0.125rem 0.5rem;
|
|
209
|
+
background-color: oklch(from var(--muted) l c h / 80%);
|
|
210
|
+
color: var(--popover-foreground);
|
|
211
|
+
border-radius: var(--radius-sm);
|
|
212
|
+
font-size: 0.875em;
|
|
213
|
+
font-weight: var(--font-medium);
|
|
214
|
+
font-variant-ligatures: none;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.docyard-code-annotation-popover strong {
|
|
218
|
+
font-weight: var(--font-semibold);
|
|
219
|
+
color: var(--popover-foreground);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.docyard-code-annotation-popover a {
|
|
223
|
+
color: var(--popover-foreground);
|
|
224
|
+
font-weight: var(--font-semibold);
|
|
225
|
+
text-decoration: none;
|
|
226
|
+
border-bottom: 1px solid oklch(from var(--primary) l c h / 40%);
|
|
227
|
+
transition: border-bottom var(--transition-fast);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.docyard-code-annotation-popover a:hover {
|
|
231
|
+
border-bottom: 2px solid var(--primary);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@media (max-width: 640px) {
|
|
235
|
+
.docyard-code-annotation-popover {
|
|
236
|
+
max-width: 16rem;
|
|
237
|
+
padding: var(--spacing-2-5) var(--spacing-3);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.docyard-code-annotation-popover p,
|
|
241
|
+
.docyard-code-annotation-popover li {
|
|
242
|
+
font-size: var(--text-xs);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@media (prefers-reduced-motion: reduce) {
|
|
247
|
+
.docyard-code-annotation,
|
|
248
|
+
.docyard-code-annotation-popover {
|
|
249
|
+
transition: none;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.docyard-code-annotation:active {
|
|
253
|
+
transform: none;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.docyard-code-annotation-popover,
|
|
257
|
+
.docyard-code-annotation-popover.is-above {
|
|
258
|
+
transform: none;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.docyard-code-annotation-popover.is-visible,
|
|
262
|
+
.docyard-code-annotation-popover.is-above.is-visible {
|
|
263
|
+
transform: none;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -84,6 +84,8 @@
|
|
|
84
84
|
--callout-danger-background: rgba(254, 242, 242, 0.5);
|
|
85
85
|
--callout-danger-border: rgba(239, 68, 68, 0.2);
|
|
86
86
|
|
|
87
|
+
--code-annotation-size: 1.25em;
|
|
88
|
+
|
|
87
89
|
--code-block-bg: oklab(0 0 0 / 0.03);
|
|
88
90
|
--code-block-border: oklab(0 0 0 / 0.06);
|
|
89
91
|
--code-block-header-bg: oklab(0 0 0 / 0.02);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
var annotationPopover = null;
|
|
2
|
+
var activeAnnotationButton = null;
|
|
3
|
+
|
|
4
|
+
function initCodeAnnotations(root) {
|
|
5
|
+
if (typeof root === 'undefined') root = document;
|
|
6
|
+
var buttons = root.querySelectorAll('.docyard-code-annotation');
|
|
7
|
+
if (buttons.length === 0) return;
|
|
8
|
+
|
|
9
|
+
if (!annotationPopover) {
|
|
10
|
+
annotationPopover = document.createElement('div');
|
|
11
|
+
annotationPopover.className = 'docyard-code-annotation-popover';
|
|
12
|
+
document.body.appendChild(annotationPopover);
|
|
13
|
+
|
|
14
|
+
document.addEventListener('click', function(e) {
|
|
15
|
+
if (activeAnnotationButton &&
|
|
16
|
+
!annotationPopover.contains(e.target) &&
|
|
17
|
+
!e.target.closest('.docyard-code-annotation')) {
|
|
18
|
+
hideAnnotationPopover();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
document.addEventListener('keydown', function(e) {
|
|
23
|
+
if (e.key === 'Escape' && activeAnnotationButton) {
|
|
24
|
+
hideAnnotationPopover();
|
|
25
|
+
activeAnnotationButton.focus();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
buttons.forEach(function(button) {
|
|
31
|
+
if (button.hasAttribute('data-annotation-initialized')) return;
|
|
32
|
+
button.setAttribute('data-annotation-initialized', 'true');
|
|
33
|
+
|
|
34
|
+
button.addEventListener('click', function(e) {
|
|
35
|
+
e.stopPropagation();
|
|
36
|
+
if (activeAnnotationButton === button) {
|
|
37
|
+
hideAnnotationPopover();
|
|
38
|
+
} else {
|
|
39
|
+
showAnnotationPopover(button);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function setAnnotationIcon(button, name, animate) {
|
|
46
|
+
var icon = button.querySelector('i[class*="ph-"]');
|
|
47
|
+
if (!icon) return;
|
|
48
|
+
if (!animate) {
|
|
49
|
+
icon.className = 'ph ph-' + name;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
icon.style.transition = 'opacity 100ms ease, transform 100ms ease';
|
|
53
|
+
icon.style.opacity = '0';
|
|
54
|
+
icon.style.transform = 'scale(0.5)';
|
|
55
|
+
setTimeout(function() {
|
|
56
|
+
icon.className = 'ph ph-' + name;
|
|
57
|
+
icon.style.opacity = '1';
|
|
58
|
+
icon.style.transform = 'scale(1)';
|
|
59
|
+
}, 100);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function showAnnotationPopover(button) {
|
|
63
|
+
if (activeAnnotationButton) {
|
|
64
|
+
setAnnotationIcon(activeAnnotationButton, 'plus-circle', true);
|
|
65
|
+
activeAnnotationButton.classList.remove('is-active');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
activeAnnotationButton = button;
|
|
69
|
+
button.classList.add('is-active');
|
|
70
|
+
setAnnotationIcon(button, 'x-circle', true);
|
|
71
|
+
annotationPopover.innerHTML = button.getAttribute('data-annotation-content');
|
|
72
|
+
|
|
73
|
+
annotationPopover.classList.remove('is-above');
|
|
74
|
+
annotationPopover.style.visibility = 'hidden';
|
|
75
|
+
annotationPopover.classList.add('is-visible');
|
|
76
|
+
|
|
77
|
+
requestAnimationFrame(function() {
|
|
78
|
+
positionPopover(button);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function positionPopover(button) {
|
|
83
|
+
var rect = button.getBoundingClientRect();
|
|
84
|
+
var scrollX = window.scrollX;
|
|
85
|
+
var scrollY = window.scrollY;
|
|
86
|
+
var popoverRect = annotationPopover.getBoundingClientRect();
|
|
87
|
+
var gap = 6;
|
|
88
|
+
var padding = 12;
|
|
89
|
+
var viewportWidth = window.innerWidth;
|
|
90
|
+
var viewportHeight = window.innerHeight;
|
|
91
|
+
|
|
92
|
+
var left = rect.left + scrollX + (rect.width / 2) - (popoverRect.width / 2);
|
|
93
|
+
var spaceBelow = viewportHeight - rect.bottom;
|
|
94
|
+
var spaceAbove = rect.top;
|
|
95
|
+
var openAbove = spaceBelow < popoverRect.height + gap + padding && spaceAbove > spaceBelow;
|
|
96
|
+
|
|
97
|
+
var top;
|
|
98
|
+
if (openAbove) {
|
|
99
|
+
top = rect.top + scrollY - popoverRect.height - gap;
|
|
100
|
+
annotationPopover.classList.add('is-above');
|
|
101
|
+
} else {
|
|
102
|
+
top = rect.bottom + scrollY + gap;
|
|
103
|
+
annotationPopover.classList.remove('is-above');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (left < padding) {
|
|
107
|
+
left = padding;
|
|
108
|
+
} else if (left + popoverRect.width > viewportWidth - padding) {
|
|
109
|
+
left = viewportWidth - popoverRect.width - padding;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var arrowLeft = rect.left + scrollX + (rect.width / 2) - left;
|
|
113
|
+
annotationPopover.style.setProperty('--arrow-left', Math.max(12, Math.min(arrowLeft, popoverRect.width - 12)) + 'px');
|
|
114
|
+
annotationPopover.style.left = left + 'px';
|
|
115
|
+
annotationPopover.style.top = top + 'px';
|
|
116
|
+
annotationPopover.style.visibility = 'visible';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function hideAnnotationPopover() {
|
|
120
|
+
if (!annotationPopover) return;
|
|
121
|
+
if (activeAnnotationButton) {
|
|
122
|
+
setAnnotationIcon(activeAnnotationButton, 'plus-circle', true);
|
|
123
|
+
activeAnnotationButton.classList.remove('is-active');
|
|
124
|
+
}
|
|
125
|
+
annotationPopover.classList.remove('is-visible');
|
|
126
|
+
activeAnnotationButton = null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (document.readyState === 'loading') {
|
|
130
|
+
document.addEventListener('DOMContentLoaded', function() { initCodeAnnotations(); });
|
|
131
|
+
} else {
|
|
132
|
+
initCodeAnnotations();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
window.docyard = window.docyard || {};
|
|
136
|
+
window.docyard.initCodeAnnotations = initCodeAnnotations;
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
if (docyard.initAbbreviations) docyard.initAbbreviations(container);
|
|
60
60
|
if (docyard.initLightbox) docyard.initLightbox(container);
|
|
61
61
|
if (docyard.initTooltips) docyard.initTooltips(container);
|
|
62
|
+
if (docyard.initCodeAnnotations) docyard.initCodeAnnotations(container);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
function reloadContent() {
|